I am interested in using Scala because it seems like a good way to parallelize operations. I need to design a machine learning algorithm that makes use of vector multiplication (as do many). I know how to do the algorithm, but what I want to make is a sparse vector implementation from HashMaps. Pretty much all vectors are stored as HashMaps[Int, Double] where the index of a given double in a vector is the integer that is the key.
Using a Pythonish psuedocode, <7, 6, 5, 4> ==> {1:7, 2:6, 3:5, 4:4}
I want to define a dot product function using either fold, reduce, map ... etc., but I DO NOT want to use the foldLeft, reduceLeft ... because I would like this to be potentially parallizable because my vectors can get up to 6000+ dimensions and, for dot products, order does not matter.
I have read MANY examples of foldLeft and reduceLeft, but I have yet to find out how to use HashMap.fold or HashMap.reduce.
I understand functional programming to a decent extent, but I don't understand the error messages in Scala. Here is a template of what I want more or less.
object NGramAnalysis {
def main(args: Array[String]) {
val mapped = HashMap(1->1.2, 5->2.4)
println(mapped.fold( .... What goes here ... )
}
}
Conclusion I want a solid example of using HashMap.fold NOT foldLeft and the same for HashMap.reduce
Thank you in advance. I have been struggling for a while.