Skip to content

Instantly share code, notes, and snippets.

View rubenfiszel's full-sized avatar

Ruben Fiszel rubenfiszel

View GitHub Profile
@rubenfiszel
rubenfiszel / permutations.scala
Last active August 29, 2015 14:08
Find all permutations of a Number in Scala with memoization (optimal)
def remove(num: Int, list: List[Int]) = list diff List(num)
var mem: Map[List[Int], List[List[Int]]] = Map()
def permutations(l:List[Int]):List[List[Int]] =
if (l.length == 1) List(l)
else {
if (mem.contains(l)) mem(l)
else {
val r = l.flatMap(x=> permutations(remove(x, l)).map(y=> x::y))
val conf: MultiLayerConfiguration = new NeuralNetConfiguration.Builder()
.seed(seed)
.iterations(iterations)
.learningRate(1e-1f)
.optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT)
// .l1(1e-1).l2(2e-4)
// .useDropConnect(true)
.list(3)
.layer(0, new DenseLayer.Builder()
.nIn(50)
val iterations = 500
val seed = 456
val listenerFreq = 1
val batchSize = 100
val numEx = 5000
val server = UiServer.getInstance();
log.info("Started on port " + server.getPort());
log.info("Load data....")
val iterations = 500
val seed = 456
val listenerFreq = 1
val batchSize = 100
val numEx = 5000
val server = UiServer.getInstance();
log.info("Started on port " + server.getPort());
log.info("Load data....")
val iterations = 1
val seed = 456
val listenerFreq = 1
val batchSize = 100
val numEx = 5000
val server = UiServer.getInstance();
log.info("Started on port " + server.getPort());
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
libraryDependencies ++= Seq(
"org.deeplearning4j" % "deeplearning4j-core" % "0.4-rc3.9-SNAPSHOT",
"org.deeplearning4j" % "deeplearning4j-ui" % "0.4-rc3.9-SNAPSHOT",
"org.nd4j" % "nd4j-x86" % "0.4-rc3.9-SNAPSHOT"
)
[error] (run-main-0) java.lang.ArrayIndexOutOfBoundsException: 960
java.lang.ArrayIndexOutOfBoundsException: 960
at org.nd4j.linalg.api.buffer.BaseDataBuffer.put(BaseDataBuffer.java:869)
at org.nd4j.linalg.api.buffer.BaseDataBuffer.put(BaseDataBuffer.java:860)
at org.nd4j.linalg.api.buffer.BaseDataBuffer.copyAtStride(BaseDataBuffer.java:441)
at org.nd4j.linalg.api.ndarray.BaseNDArray.assign(BaseNDArray.java:1025)
at org.nd4j.linalg.api.ndarray.BaseNDArray.reshape(BaseNDArray.java:3198)
at org.nd4j.linalg.api.ndarray.BaseNDArray.reshape(BaseNDArray.java:3238)
at ccup.GameFetcher$.normalizeInput(GameFetcher.scala:60)
at ccup.GameFetcher2.fetch(GameFetcher.scala:103)
java.lang.IllegalStateException: Invalid data transform; features and labels do not have equal rows. First was 1 labels was 100
at org.nd4j.linalg.dataset.DataSet.<init>(DataSet.java:85)
at org.nd4j.linalg.dataset.DataSet.<init>(DataSet.java:73)
at ccup.GameFetcher2.fetch(GameFetcher.scala:110)
at org.deeplearning4j.datasets.iterator.BaseDatasetIterator.next(BaseDatasetIterator.java:56)
at org.deeplearning4j.datasets.iterator.BaseDatasetIterator.next(BaseDatasetIterator.java:33)
at org.deeplearning4j.nn.graph.ComputationGraph.fit(ComputationGraph.java:467)
at ccup.SelfPlay$.train2(SelfPlay.scala:320)
at ccup.SoloGame$.delayedEndpoint$ccup$SoloGame$1(SoloGame.scala:14)
at ccup.SoloGame$delayedInit$body.apply(SoloGame.scala:6)
java.lang.IllegalStateException: Unable to get number of of rows for a non 2d matrix
at org.nd4j.linalg.api.ndarray.BaseNDArray.rows(BaseNDArray.java:3411)
at org.nd4j.linalg.api.ndarray.BaseNDArray.mmul(BaseNDArray.java:2321)
at org.deeplearning4j.nn.layers.BaseLayer.preOutput(BaseLayer.java:327)
at org.deeplearning4j.nn.layers.BaseLayer.activate(BaseLayer.java:338)
at org.deeplearning4j.nn.layers.BaseLayer.activate(BaseLayer.java:358)
at org.deeplearning4j.nn.graph.vertex.impl.LayerVertex.doForward(LayerVertex.java:87)
at org.deeplearning4j.nn.graph.ComputationGraph.feedForward(ComputationGraph.java:738)
at org.deeplearning4j.nn.graph.ComputationGraph.computeGradientAndScore(ComputationGraph.java:663)
at org.deeplearning4j.optimize.solvers.BaseOptimizer.gradientAndScore(BaseOptimizer.java:150)
name := "codecup"
version := "0.3"
scalaVersion := "2.11.7"
scalacOptions += "-deprecation"
scalacOptions += "-unchecked"