I do not know how to approach the problem of finding out if two numbers are "similar"/close to each other, based on a dataset.
For example to find out if value 1 is similar to value 3, based on the dataset {1,2,3,4,5}.
What are some statistical approaches to solve this problem?
If I understand your question correctly, you can write a for loop. When passing the first number, you set a boolean to true. If this boolean in true, you will increase the 'simelar-factor'. You can end this loop when passing the second number using 'break'
Related
Right now, I am working on a chess engine, which stores each different representations of the board in 64bits, which I store in a long variable. Example:
private long wKing = 0b000000000000000000000000000000000000000000000000000000001000;
The problem is, I am when I go to print it out, I instead am given the value on the bit sequence(8), not the actual sequence. Here is my print statement:
System.out.println(wKing);
How can I print this out so that it gives me the sequence instead, so i can use it for testing and printing out a representation of the board in the future? Thank you.
You can use Long.toBinaryString.
System.out.println(Long.toBinaryString(wKing));
I have a Directed Acyclic Graph, arcs are Entities and Weights associated do each Arc are the PlanningVariables. I use:
#ValueRangeProvider(id = "bufferRange")
public CountableValueRange<Integer> getDelayRange() {
return ValueRangeFactory.createIntValueRange(1, 1000);
}
to assign values to my variables. Also, i've come across this issue:
Exhaustive Search in OptaPlanner does not work on very simple example, which is now solved by setting variables from int to Integer and checking null values in the score calculation.
Now the problem is that the solver seems not to be backtraking when assigning values. I've used a print to check values being attributed to each arc. In the beginning of the solving process i can see values being set to different arcs. But after some time attributions the solver stucks in assigning values to the same arc. Checking the prints I see the attributions going from 1 to 1000 and then starting again. Since all values from the domain are tested one time, why the solver does not backtrack instead of assigning the same values again?
I tested with all the <nodeExplorationType> options and created a class to use the <entitySorterManner> with the same results.
Thanks in advance.
I supose you are right Geoffrey, deactivated the log and let the program run for almost 48h and it came up with an answer. The way logs are printed mislead the analysis. Just for remark, if logger is deactivated the performance is considerably superior.
I have been thinking to solve any problem like 1+2*4-5 with user entering it and program to solve it. I've read some questions on this site about storing arithmetic operator and the solution says to check by using switch which can't be applied here. I would be thankful if anybody could suggest any idea of how to make it.
I had a similar exercise not long ago, but in the question it was stated that the seperation is a space. So the user input would be 1 + 2 * 4 - 5, and i solved it that way. I will give you some tips but not paste the whole code.
-you read the input as a String
-you can use the String.split() method to devide the String into the pieces you need and they will be put in an array.(in this case: strArray[0]='1',strArray[1]='+', etc)
-you will need a for-loop to go trough every String in the array:
-the decimals will need to be converted to integers with the Integer.parseInt() method.
-The + - * / will need to be put in switch-statement.
(be careful how you construct your loop, think about how many times you want to go trough it and what you need in each loop)
I hope these tips helped.
I'm making a chat responder for a game and i want know if there is a way you can compare two strings and see if they are approximatley equal to each other for example:
if someone typed:
"Strength level?"
it would do a function..
then if someone else typed:
"Str level?"
it would do that same function, but i want it so that if someone made a typo or something like that it would automatically detect what they're trying to type for example:
"Strength tlevel?"
would also make the function get called.
is what I'm asking here something simple or will it require me to make a big giant irritating function to check the Strings?
if you've been baffled by my explanation (Not really one of my strong points) then this is basically what I'm asking.
How can I check if two strings are similar to each other?
See this question and answer: Getting the closest string match
Using some heuristics and the Levenshtein distance algorithm, you can compute the similarity of two strings and take a guess at whether they're equal.
Your only option other than that would be a dictionary of accepted words similar to the one you're looking for.
You can use Levenshtein distance.
I believe you should use one of Edit distance algorithms to solve your problem. Here is for example Levenstein distance algorithm implementation in java. You may use it to compare words in the sentences and if sum of their edit distances would be less than for example 10% of sentence length consider them equals.
Perhaps what you need is a large dictionary for similar words and common spelling mistakes, for which you would use for each word to "translate" to one single entry or key.
This would be useful for custom words, so you could add "str" in the same key as "strength".
However, you could also make a few automated methods, i.e. when your word isn't found in the dictionary, to loop recursively for 1 letter difference (either missing or replaced) and can recurse into deeper levels, i.e. 2 missing letters etc.
I found a few projects that do text to phonemes translations, don't know which one is best
http://mary.dfki.de/
http://www2.eng.cam.ac.uk/~tpl/asp/source/Phoneme.java
http://java.dzone.com/announcements/announcing-phonemic-10
If you want to find similar word beginnings, you can use a stemmer. Stemmers reduce words to a common beginning. The most known algorithm if the Port Stemmer (http://tartarus.org/~martin/PorterStemmer).
Levenshtein, as pointed above, is great, but computational heavy for distances greater than one or two.
I asked a question How to get an Integer as result?
The suggested solution with decimalFormat works, but my problem is that I want my data not only to be presented as ##.0 but to be like this, because in the end of my program I use them. So I want to be exactly in that type; otherwise I get the wrong final number. Any ideas?
EDIT:
let me be more specific. i get 12,344 from my first calc, 14,4566 from my second and 18,5644 from my third.that makes a sum 45.365.Now,if i do then 12,3 , 14,4 and 18,5 the sum is 45.2...thats the point of my answer.i want to have 45.365 at the end and not 45.2
The problem seems to be a design issue with your app.
On the one hand, you want to display the results to the user with 1 digit after the decimal point.
In the other hand, you actually want to keep the extra precision and use it for follow-up calculations.
I would argue that this is a poor user interface model. IMO, the numbers that the user sees should be the numbers that go into the calculations. This means you should either:
show the user more digits after the DP in the first place (or at least give a visual indication that there are more digits), or
do the calculations using the rounded / truncated values ... as displayed to the user.
Once you have figured out a consistent user interface model, the required implementation approach should be much clearer to you.