This repository has been archived by the owner on Oct 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from karlhigley/fix/minhash-bands
Fix signature element grouping in `BandingCollisionStrategy`
- Loading branch information
Showing
2 changed files
with
57 additions
and
3 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
53 changes: 53 additions & 0 deletions
53
src/test/scala/com/github/karlhigley/spark/neighbors/CollisionStrategySuite.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,53 @@ | ||
package com.github.karlhigley.spark.neighbors | ||
|
||
import org.scalatest.FunSuite | ||
|
||
import org.apache.spark.rdd.RDD | ||
import org.apache.spark.mllib.linalg.SparseVector | ||
|
||
class CollisionStrategySuite extends FunSuite with TestSparkContext { | ||
val numPoints = 1000 | ||
val dimensions = 100 | ||
val density = 0.5 | ||
|
||
var points: RDD[(Long, SparseVector)] = _ | ||
|
||
override def beforeAll() { | ||
super.beforeAll() | ||
val localPoints = TestHelpers.generateRandomPoints(numPoints, dimensions, density) | ||
points = sc.parallelize(localPoints).zipWithIndex.map(_.swap) | ||
} | ||
|
||
test("SimpleCollisionStrategy produces the correct number of tuples") { | ||
val ann = | ||
new ANN(dimensions, "cosine") | ||
.setTables(1) | ||
.setSignatureLength(8) | ||
|
||
val model = ann.train(points) | ||
|
||
val hashTables = model.hashTables | ||
val collidable = model.collisionStrategy(hashTables) | ||
|
||
assert(collidable.count() == numPoints) | ||
} | ||
|
||
test("BandingCollisionStrategy produces the correct number of tuples") { | ||
val numBands = 4 | ||
|
||
val ann = | ||
new ANN(dimensions, "jaccard") | ||
.setTables(1) | ||
.setSignatureLength(8) | ||
.setBands(numBands) | ||
.setPrimeModulus(739) | ||
|
||
val model = ann.train(points) | ||
|
||
val hashTables = model.hashTables | ||
val collidable = model.collisionStrategy(hashTables) | ||
|
||
assert(collidable.count() == numPoints * numBands) | ||
} | ||
|
||
} |