As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I am new to this kind of computing. I don't know what are the existing distance functions that are helpful to calculate the distance between to double sets(arrays). Can some one suggest me at-least 10 distance functions so that i can select few among them which suits best for my problem domain. I just want to calculate the distance between two sets for my scientific approach to the problem domain. I also want to know whether i have to implement them manually or any java API that covers most distance functions? Suggestions can help me to minimize my effort and save my time..:)
Providing you with code is not really going to help. What you need to do is to read up on the mathematics of the the various measures of distance, and figure out which is most appropriate based on that knowledge.
You could start by reading the Wikipedia page on Distance and the linked pages and resources.
Only when you've decide on an appropriate measure do you need to go looking for code. In a lot of cases, it is probably simplest to implement the measure yourself.
Alternatively, if you want us to provide sensible suggestions of measures that are appropriate to your problem domain, tell us what the problem domain is.
Are we talking about statistical distance between two samples? If so, there is an abundance of methods, each one suiting a different problem.
If your problem domain is simple, subtracting the sample means (averages) could suffice. For more complex data, the Earth Movers' Distance is common, though newer and more robust methods (such as kernel functions) are available.
Coding is the least of your problems. You must provide a more accurate definition of your problem before I can further assist you.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Edit:
Once again, thanks to those who commented and answered. Agreed, not the best question in the world, but I needed a little push to get past this obstacle in my mind. What I have taken with me in particular is that the return type is an important part of the method signature.
One of the important aspects of clean coding is picking good names for your classes, variables and methods.
Following what I have read in literature and online, I would try and pick names that are, firstly, as descriptive (and therefore unambiguous) as possible, and secondly, as concise as possible.
I am for my own amusement and learning writing a chess game in java, and I have stumbled upon a method that I simply can't figure out how to name in a satisfactory way. The method lives on my ISquare interface and is intended to bring me back a list of pieces that are currently attacking that square.
To be fully descriptive the name should indicate that the method returns a collection of pieces, arguably even a list, and that the pieces are attacking this square instance. One could argue that the latter is implied by where the method lives, but I'm not too sure about that.
The most descriptive name I can think of is probably in violation of every single other naming convention, and obviously won't do:
List<IPiece> giveMeTheListOfPiecesThatThisSquareIsUnderAttackBy();
These two alternatives show that the method relates to the current instance, but seem to hint that the result is of a boolean nature:
List<IPiece> isUnderAttackByPieces();
List<IPiece> underAttackByPieces();
The next one is descriptive about the return type, but not explicit about what the pieces are attacking:
List<IPiece> getAttackingPieces();
This one might satisfy my criteria, but intuitively I would say that using the words "This" and "Square" doesn't look very good:
List<IPiece> piecesAttackingThisSquare();
Currently I have settled with underAttackByPieces(), but as described above that doesn't quite nail it.
Any help you can offer will be most appreciated!
I would settle with getAttackingPieces. Since it's a method of ISquare, I think it is clear enough what is under attack. You can be more explicit in the method's Javadoc comment.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am thinking about externalizing some conditions instead of implementing them in java so that I can easily change them later as needed.
For example, I need to check if certain keys exist in a given map and if the values of certain keys in a map equal to something.
I was thinking about using spring's expression language, but since we are already using velocity templates, I thought maybe it is a good candidate.
Any idea? Thanks.
You can easily use the #if/#else, #foreach and other condition functionality of velocity to do business logic as part of the velocity template rendering.
However I usually try to separate business logic from rendering in velocity for a number of reasons:
Complexity: The Velocity template can become hard to read, especially
if the target output itself requires complex resulting layout. If you
add additional business logic to the mix, it quickly becomes
impossible to read for anybody else (or for yourself after a few
months of not looking at it constantly)
Testability: It's harder to test Velocity templates, there's
better support for unit/integration testing of Java code
Functionality: Velocity is not a full programming language by
design, so you will miss some things sooner or later and a macro
simply is not a function, e.g. variables by default have global
scope, ... You are bound to run into some of these if you make
your templates big and complex.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I'm doing some text mining in web pages. Currently I'm working with Java, but maybe there is more appropriate languages to do what I want.
Example of some things I want to do:
Determine the char type of a word based on it parts (letter, digit, symbols, etc.) as Alphabetic, Number, Alphanumeric, Symbol, etc.(there is more types).
Discover stop words based on statistics.
Discover some gramatical class (verb, noun, preposition, conjuntion) based on statistics and some logics.
I was thinking about using Prolog and R (I don't know much about these languages), but I don't know if they are good for this or maybe, another language more appropriate.
Which can I use? Good libs for Java are welcome too.
python.!
They have a HELL-LOTTA libraries in this area.
but, i've got no knowledge about prologue and R.. but definitely py is LOT better than java in text mining, and AI stuff...
I highly recommend Perl. It has a lot of text-processing features, web search and parsing, and a large etc. Take a look at the available modules (>23.000 and growing) at CPAN.
I think Apache Solr and Nutch provides you the framework for that and on top of that you can extend it for your requirements.
Java has some basic support, but nothing like the above two products, they are awesome!
HTML Unit might give you some good APIs for fetching web pages, and traversing over elements in DOM by XPath. I have used it for sometime to perform simple to more complex operations.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
I know that is Collections.sort() method in Java but I think quicksort is worth to remember and try.
My work target is general Java: web, database access, integration, not game developer, scientific application or another one that depends on advanced algorithms.
Which algorithms should I learn to pass without stress Java developer interview?
Fizz Buzz
I usually don't care, if a developer knows the basic algorithms by heart. I do care, if he is capabale of understanding requirements and translating them in correct, testable and understandable pieces of code.
Ah, and I do care if he knows how to implement the most common design patterns. And he should know when and how to use collections, threads and - String#split - it's amazing how many "developers" don't know how to read and process a simple csv file.
Although I fully agree with Joachim comment, I would go for : collection selection. This is not an algorithm per se, but rather a good view of which collection is good for which purpose :
sorted content with constant lookup time ? TreeSet !
mapped data with memorization of insertion order ? LinkedHashMap !
using that, and some knowledge of design patterns behind collections, you will far too often reply to algorithms questions using the knuth answer (or the subtle variation : as long as Sun developpers implemented it correctly, I only have to choose wisely).
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
What are good resource to read up on for implementing numerical algorithms in pure java?
I know nothing about the interactions of the JVM & GC, and would love to learn more.
I enjoyed Object Oriented Implementation of Numerical Methods by Didier Besset. To be honest I use C++ almost exclusively but found this book interesting and fun nonetheless. It doesn't always use the best algorithm for the job, however.
I would also point you towards Matrix Computations by Golub & Van Loan. Not about Java by any means, but a mandatory text for anybody working in this area.
Pick up a copy of Numerical Recipes in C++. NR doesn't always contain the best algorithms for the problems it tackles, it's a pedagogical text not a library of optimized code. But the explanations are generally good and the range of topics is wide. By picking up the C++ version you can learn some Java while you translate the code. Also pick up a good book on the basics of floating-point arithmetic and numerical analysis.
Numerics: http://math.nist.gov/javanumerics/
GC intro: http://www.ibm.com/developerworks/java/library/j-jtp11253/
Java Number Cruncher is a good start. I don't think it deals with GC issues, though. Anyway, floating point precision issues are quite likely more relevant in numerical algorithms, usually. The book does demonstrate that doubles can actually be inferior to floats in some cases.
Apache Commons Math has some nice linear algebra libraries, among other things.
Linear algebra is the basis for lots of serious numerical work (e.g., finite difference, finite element, and boundary element formulations for problems in solid and fluid mechanics and heat transfer). AFAIK, most of that work is still done by commercial and in-house packages written in FORTRAN. Java and even C++ and C were not considered performant enough for such things back when I did them for a living. I'd be surprised if that has changed.