This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Transfer Learning for Natural Language Processing (MEAP) and have Paul Azunre on-line!
See this thread for details.
Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Updating an Array List

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an array list made up of pairs of strings and integers (one of each in each pair)

I also have a .csv column vector with integer values which I wish to update the array list with

How do I accomplish that ?

Bob M

p.s. do I use the arraylist.set(.....) command and if so how do I reference the integer in the pair?
 
Marshal
Posts: 25436
65
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. You already have data in the list, so you just get the data out of the list and change it.

As for how you change it, I have no idea. I don't know what a "pair" is and how it's declared. It might be an array of two objects or a custom class written to contain a String and an integer. That class might not be mutable, which would mean you'd have to create a new instance of the class and put that back into the list. However that's all just speculation since we know nothing about this class. Do you not have the source code for it or anything?
 
Bob Matthews
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It is populated by

I was looking at
etc to populate the ArrayList and then
etc to update the contents
 
Ranch Foreman
Posts: 95
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just as an idea: Isn't a Map<String, Integer> better suited for your task?

//edit: spelling error
 
Bob Matthews
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ha....ha..........
I am a novice programmer, I don't know
 
Rancher
Posts: 3599
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bob,

In your case I think more fit MultiMap collection. https://guava.dev/releases/19.0/api/docs/com/google/common/collect/Multimap.html

If you need to keep order of the pairs (like in List) -- use LinkdListMultimap https://guava.dev/releases/19.0/api/docs/com/google/common/collect/LinkedListMultimap.html

Note: these are not standard Java API, it's third party API from google, you need extra step to add these collections to your project.

Why I do not recommend to use your design with Java.util.List: you will need to iterate whole list each time when you need to update a value.

HTH,
MZ
 
Bob Matthews
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why I do not recommend to use your design with Java.util.List: you will need to iterate whole list each time when you need to update a value.



Thank you but I would prefer to stay with ArrayList <String, Integer> or Map<String, Integer> if I can

I am following an example of code for dl4j and ArrayList<> is used further on in the code

I only need to update all the integers once

Bob M
 
Mikalai Zaikin
Rancher
Posts: 3599
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, you know your requirement better for sure.

I am fine with ArrayList<Pair> as long as it's not heavily used, because as I mentioned above -- the main drawback is the search efforts.

As for Map<String, Integer> -- 2 things to keep in mind:
1) ordering -- if it matters, use LinkedHashMap
2) key duplicates -- if it may occur, then to avoid limitation -- use some MultiMap from Guava (see above)
 
Bob Matthews
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your advice

Bob M
New Zealand
 
Bob Winter
Ranch Foreman
Posts: 95
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if List is used further on in the code I may suggest to stick to it to follow the example. Construct some wild spaghetti code isn't what a beginner should try to wire up.
 
Bob Matthews
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally all .csv files are correct BUT I now have the following error
which is odd since all my labels are in the range 0 thru 5

Exception in thread "main" java.lang.IllegalStateException: Cannot convert sequence writables to one-hot: class index 6 >= numClass (6). (Note that classes are zero-indexed, thus only values 0 to nClasses-1 are valid)
at org.deeplearning4j.datasets.datavec.RecordReaderMultiDataSetIterator.convertWritablesSequence(RecordReaderMultiDataSetIterator.java:693)
at org.deeplearning4j.datasets.datavec.RecordReaderMultiDataSetIterator.convertFeaturesOrLabels(RecordReaderMultiDataSetIterator.java:369)
at org.deeplearning4j.datasets.datavec.RecordReaderMultiDataSetIterator.nextMultiDataSet(RecordReaderMultiDataSetIterator.java:333)
at org.deeplearning4j.datasets.datavec.RecordReaderMultiDataSetIterator.next(RecordReaderMultiDataSetIterator.java:213)
at org.deeplearning4j.datasets.datavec.SequenceRecordReaderDataSetIterator.next(SequenceRecordReaderDataSetIterator.java:365)
at org.deeplearning4j.datasets.datavec.SequenceRecordReaderDataSetIterator.next(SequenceRecordReaderDataSetIterator.java:344)
at org.deeplearning4j.datasets.datavec.SequenceRecordReaderDataSetIterator.next(SequenceRecordReaderDataSetIterator.java:48)
at org.nd4j.linalg.dataset.api.preprocessor.AbstractDataSetNormalizer.fit(AbstractDataSetNormalizer.java:109)
at org.deeplearning4j.examples.recurrent.seqclassification.UCIExample_2.main(UCIExample_2.java:122)

Process finished with exit code 1

Bob M
 
Bartender
Posts: 7065
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at this line of code?
at org.deeplearning4j.examples.recurrent.seqclassification.UCIExample_2.main(UCIExample_2.java:122)
 
Bob Matthews
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes - that's the puzzler - line 122 is the middle line of code below



Bob M
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic