Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial optimisation: reduce number of passes
- Loading branch information
Showing
3 changed files
with
99 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/scala/pl/edu/icm/sparkling_ferns/FernBuilder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package pl.edu.icm.sparkling_ferns | ||
|
||
import breeze.numerics._ | ||
import org.apache.spark.mllib.linalg.Vector | ||
import org.apache.spark.rdd.RDD | ||
|
||
/** | ||
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) | ||
*/ | ||
class FernBuilder(featureIndices: List[Int], binarisers: List[FeatureBinariser]) extends Serializable { | ||
def toIndex(featureVector: Vector): Int = { | ||
val features = featureVector.toArray | ||
val selected = featureIndices.map(features) | ||
|
||
Fern.toPointIndex(selected, binarisers) | ||
} | ||
|
||
|
||
|
||
def build(counts: Array[((Double, Int), Long)], labels: Array[Double]): FernModel = { | ||
val numFeatures = featureIndices.length | ||
val numDistinctPoints = 1 << numFeatures | ||
val scores = Fern.computeScores(counts, numDistinctPoints, labels) | ||
new FernModel(labels, featureIndices, binarisers, scores) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters