Skip to content

Instantly share code, notes, and snippets.

@rubenfiszel
Created February 14, 2016 12:17
Show Gist options
  • Save rubenfiszel/b0cd983bb89ce4e12477 to your computer and use it in GitHub Desktop.
Save rubenfiszel/b0cd983bb89ce4e12477 to your computer and use it in GitHub Desktop.
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());
log.info("Load data....")
val iter = new GamesEpoch(batchSize, numEx, 5)
val h1 = 100
val h2 = 40
// val h3 = 40
val h4 = 40
log.info("Build model....")
val conf: MultiLayerConfiguration = new NeuralNetConfiguration.Builder()
.seed(seed)
.iterations(iterations)
// .miniBatch(false)
.learningRate(1e-3f)
// .momentum(0.6f)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
// .l1(1e-1).l2(2e-4)
.list(3)
.layer(0, new DenseLayer.Builder()
.nIn(50)
.nOut(h1)
.weightInit(WeightInit.RELU)
.activation("relu")
.updater(Updater.NESTEROVS)
.build()
)
.layer(1, new DenseLayer.Builder()
.nIn(h1)
.nOut(h2)
.weightInit(WeightInit.RELU)
.activation("relu")
.updater(Updater.NESTEROVS)
.build()
)
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.RMSE_XENT)
.nIn(h2)
.nOut(1)
.weightInit(WeightInit.XAVIER)
.activation("sigmoid")
.build()
)
.pretrain(false)
.backprop(true)
.build()
val model = new MultiLayerNetwork(conf)
model.init()
model.setListeners(new HistogramIterationListener(1), new ScoreIterationListener(listenerFreq))
log.info("Train model....")
model.fit(iter)
/*
log.info("Evaluate weights....")
model.getLayers.foreach { case (layer: org.deeplearning4j.nn.api.Layer) =>
val w: INDArray = layer.getParam(DefaultParamInitializer.WEIGHT_KEY)
log.info("Weights: " + w)
}*/
log.info("Eval data....")
val test = new GamesIterator(batchSize, numEx).next()
println(test.getLabels.data().asFloat().toList.take(10))
println(model.output(test.getFeatureMatrix, Layer.TrainingMode.TEST).data().asFloat().toList.take(10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment