Java, map 3 items - java

I need a structure to translate different enumerators (Integers) from one API to another one. The APIs are GL, DX9 and DX10.
The integers are not contiguous, that is we don't have all the values from 0 to 232
Example:
Given [GL, DX9, DX10]
one entry could be:
[COMPRESSED_RGB_S3TC_DXT1_EXT, D3DFMT_DXT1, DXGI_FORMAT_BC1_UNORM]
That is:
[33776, 827611204, 71]
I should be able to get every API enum from any other one. This means, for example, I have COMPRESSED_RGB_S3TC_DXT1_EXT and I want the DX10 equivalent or I have D3DFMT_DXT1 and I want the GL equivalent and so on..
I saw some option, like attaching different subkeys here or concatenating all of them in Strings like here, but they don't look very practical/elegant to me, is there a better option?

Related

Can I have a vector attribute in WEKA?

I am new to WEKA/machine learning and I am trying to create a model in which a single feature is a vector of 8 integers (ranging from 0-11) containing information of past choices. For example, [0,1,8,4,4,2,2,6] would mean that 0 was chosen in the last iteration, 1 was chosen two iterations ago, etc. Each choice has an impact on the next in this case and the order is important.
I was wondering if it is possible to represent this in WEKA as a feature. I am currently representing them as individual features but this does not make the relation or order between the values obvious and I was wondering if there is a better way to do it. Any input is appreciated, thanks!
Weka's ARFF format does not offer an attribute type that would allow you to encapsulate an ordered vector. Attributes are basically independent columns and the relational attribute type does not enforce an ordering either.
Your data sounds more like a time series. If that is the case, you could look a the time series support in Weka.
If your data does not represent a time series, then you may have to fall back on feature engineering. You can use the AddExpression filter for creating new attributes based on values from other attributes (e.g., difference between two attributes).
With the MultiFilter you can combine an arbitrary number of filters into a single one. Which you then can use in conjunction with the FilteredClassifier meta-classifier.

Data Structure choices based on requirements

I'm completely new to programming and to java in particular and I am trying to determine which data structure to use for a specific situation. Since I'm not familiar with Data Structures in general, I have no idea what structure does what and what the limitations are with each.
So I have a CSV file with a bunch of items on it, lets say Characters and matching Numbers. So my list looks like this:
A,1,B,2,B,3,C,4,D,5,E,6,E,7,E,8,E,9,F,10......etc.
I need to be able to read this in, and then:
1)display just the letters or just the numbers sorted alphabetically or numerically
2)search to see if an element is contained in either list.
3)search to see if an element pair (for example A - 1 or B-10) is contained in the matching list.
Think of it as an excel spreadsheet with two columns. I need to be able to sort by either column while maintaining the relationship and I need to be able to do an IF column A = some variable AND the corresponding column B contains some other variable, then do such and such.
I need to also be able to insert a pair into the original list at any location. So insert A into list 1 and insert 10 into list 2 but make sure they retain the relationship A-10.
I hope this makes sense and thank you for any help! I am working on purchasing a Data Structures in Java book to work through and trying to sign up for the class at our local college but its only offered every spring...
You could use two sorted Maps such as TreeMap.
One would map Characters to numbers (Map<Character,Number> or something similar). The other would perform the reverse mapping (Map<Number, Character>)
Let's look at your requirements:
1)display just the letters or just the numbers sorted alphabetically
or numerically
Just iterate over one of the maps. The iteration will be ordered.
2)search to see if an element is contained in either list.
Just check the corresponding map. Looking for a number? Check the Map whose keys are numbers.
3)search to see if an element pair (for example A - 1 or B-10) is
contained in the matching list.
Just get() the value for A from the Character map, and check whether that value is 10. If so, then A-10 exists. If there's no value, or the value is not 10, then A-10 doesn't exist.
When adding or removing elements you'd need to take care to modify both maps to keep them in sync.

Java Substitute Values In A Table

To save time on calculations, I am making a program that will use formula to calculate a value based on the data that the user inputs. The program will prompt the user for five double values: A, B, and C, D, and E. It will then multiply A by B and then find the corresponding value on a conversion table. It will do the same for C and D and plug in the corresponding values along with E in a formula to give the user the answer. My question is: How would I include the table of values I mentioned above into my program so that I can easily find the corresponding values? I'm thinking of hardcoding these values into hashmaps but that would take quite awhile. Is there a file format that stores similar types of data that would be optimal to the situation?
Store the values in CSV. Load the values into an custom object/class with a field for each column. Start by looping over the entire set of objects to find the correct value/range each time. If that does not perform well optimize by doing things like having multiple lists of references to the objects where each list is sorted by a different column-- use those sorted lists to quickly find the correct object.
I say "range" here, because I am assuming you are sometimes looking for doubles. If the result of your calculation tells you to look for 1.999999 you may actually have to look for that +/- some tolerance. For this same reason you wouldn't want to use doubles as the keys for a map.

Most efficient way to check if row exists in grid Java

All,
I am wondering what's the most efficient way to check if a row already exists in a List<Set<Foo>>. A Foo object has a key/value pair(as well as other fields which aren't applicable to this question). Each Set in the List is unique.
As an example:
List[
Set<Foo>[Foo_Key:A, Foo_Value:1][Foo_Key:B, Foo_Value:3][Foo_Key:C, Foo_Value:4]
Set<Foo>[Foo_Key:A, Foo_Value:1][Foo_Key:B, Foo_Value:2][Foo_Key:C, Foo_Value:4]
Set<Foo>[Foo_Key:A, Foo_Value:1][Foo_Key:B, Foo_Value:3][Foo_Key:C, Foo_Value:3]
]
I want to be able to check if a new Set (Ex: Set[Foo_Key:A, Foo_Value:1][Foo_Key:B, Foo_Value:3][Foo_Key:C, Foo_Value:4]) exists in the List.
Each Set could contain anywhere from 1-20 Foo objects. The List can contain anywhere from 1-100,000 Sets. Foo's are not guaranteed to be in the same order in each Set (so they will have to be pre-sorted for the correct order somehow, like a TreeSet)
Idea 1: Would it make more sense to turn this into a matrix? Where each column would be the Foo_Key and each row would contain a Foo_Value?
Ex:
A B C
-----
1 3 4
1 2 4
1 3 3
And then look for a row containing the new values?
Idea 2: Would it make more sense to create a hash of each Set and then compare it to the hash of a new Set?
Is there a more efficient way I'm not thinking of?
Thanks
If you use TreeSets for your Sets can't you just do list.contains(set) since a TreeSet will handle the equals check?
Also, consider using Guava's MultSet class.Multiset
I would recommend you use a less weird data structure. As for finding stuff: Generally Hashes or Sorting + Binary Searching or Trees are the ways to go, depending on how much insertion/deletion you expect. Read a book on basic data structures and algorithms instead of trying to re-invent the wheel.
Lastly: If this is not a purely academical question, Loop through the lists, and do the comparison. Most likely, that is acceptably fast. Even 100'000 entries will take a fraction of a second, and therefore not matter in 99% of all use cases.
I like to quote Knuth: Premature optimisation is the root of all evil.

Working with a giant matrix with Java

I hava read a related question here link text
It was suggested there to work with a giant file and then use RandomAccessFile.
My problem is that a matrix(consists of "0" and "1", not sparse) could be really huge. For example, a row size could be 10^10000. I need an efficient way to store such a matrix. Also, I need to work with such file (if I would store my matrix in it) in that way:
Say, I have a giant file which contains sequences of numbers. Numbers in a sequence are divided by ","(first number shows the raw number, remaining numbers show places in matrix where "1"s stay). Sequences are divided by symbol "|". In addition, there is a symbol "||" which divide all of sequences into two groups. (that is a view of two matrixes. May be it is not efficient, but I don't know the way to make it better. Do you have any ideas? =) ) I have to read, for example, 100 numbers from an each row from a first group (extract a submatrix) and determine by them which rows I need to read from the second group.
So I need the function seek(). Would it work with such a giant file?
I am a newbie. May be there are some efficient ways to store and read such a data?
There are about 10^80 atoms in the observable universe. So say you could store one bit in each atom, you need about 10^9920 universes about the same size as ours. Thats just to store one row.
How many rows were you condiering? You will need 10^9920 universes per row.
Hopefully you mean 10 000 entries and not 10^10000 Then you could use the BitSet class to store all in RAM (or you could use sth. like hadoop)

Categories