This repository has been archived by the owner on Jun 29, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
174 additions
and
119 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
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 |
---|---|---|
@@ -1,18 +1,20 @@ | ||
organization := "nl.uva.science.ilps" | ||
|
||
name := "ScalaRank" | ||
|
||
version := "1.0" | ||
|
||
scalaVersion := "2.11.8" | ||
|
||
|
||
libraryDependencies += "org.nd4j" % "nd4j-native-platform" % "0.6.0" % Test | ||
|
||
libraryDependencies += "org.nd4j" %% "nd4s" % "0.6.0" | ||
|
||
libraryDependencies += "org.deeplearning4j" % "deeplearning4j-core" % "0.6.0" | ||
|
||
libraryDependencies += "org.nd4j" % "nd4j-native-platform" % "0.6.0" | ||
|
||
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test" | ||
|
||
classpathTypes += "maven-plugin" | ||
|
||
|
||
parallelExecution in Test := false |
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
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
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
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,32 @@ | ||
package scalarank.ranker | ||
|
||
import org.nd4j.linalg.api.ndarray.INDArray | ||
import org.nd4j.linalg.factory.Nd4j | ||
import org.nd4s.Implicits._ | ||
|
||
/** | ||
* Test trait for checking gradient functions | ||
*/ | ||
trait GradientCheck { | ||
|
||
/** | ||
* Computes the gradient limit: lim h→0 (‖f(x+h) - f(x) - ∇f(x) · h‖ / ‖h‖) | ||
* | ||
* @param gradient The gradient (as a vector) | ||
* @param x The input to compute said gradient (as a vector) | ||
* @param function The function over which the gradient is computed | ||
* @return The limit | ||
*/ | ||
def gradientLimits(gradient: INDArray, x: INDArray, function: INDArray => INDArray): Array[Double] = { | ||
val rand = Nd4j.randn(x.rows, x.columns) | ||
Array(1e1, 1, 1e-1, 1e-2).map { ε => | ||
(0 until x.columns).map { i => | ||
val e = Nd4j.zeros(x.columns) | ||
e(i) = 1.0 | ||
val approximateGradient = (function(x + e * ε) - function(x - e * ε)) / (2*ε) | ||
Math.abs(approximateGradient(i) - gradient(i)) | ||
}.sum | ||
} | ||
} | ||
|
||
} |
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
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
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,14 @@ | ||
package scalarank.ranker | ||
|
||
import scalarank.metrics._ | ||
|
||
/** | ||
* Test specification for the Random ranker | ||
*/ | ||
class RandomRankerSpec extends RankerSpec { | ||
|
||
"A random ranker" should "report appropriate nDCG results on MQ2008 Fold 1" in { | ||
testRanker(new RandomRanker(42), ndcg, "nDCG") | ||
} | ||
|
||
} |
Oops, something went wrong.