Skip to content

Commit d30923e

Browse files
author
Hugo Ferreira
committed
Initial commit
0 parents  commit d30923e

File tree

125 files changed

+36814
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+36814
-0
lines changed

build.sbt

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
// Eclipse plugin
3+
EclipseKeys.useProjectId := true
4+
EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.ManagedClasses
5+
EclipseKeys.executionEnvironment := Some(EclipseExecutionEnvironment.JavaSE18)
6+
EclipseKeys.withSource := true
7+
EclipseKeys.withJavadoc := true
8+
EclipseKeys.withBundledScalaContainers := false
9+
EclipseKeys.eclipseOutput := Some(".target")
10+
11+
name := "dl4jtest"
12+
13+
version := "0.1"
14+
15+
scalaVersion in ThisBuild := "2.12.0"
16+
//scalaVersion := "2.12.0"
17+
//scalaVersion := "2.11.8"
18+
19+
//resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
20+
//resolvers += "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
21+
//resolvers += "mvnrepository" at "http://mvnrepository.com/artifact/"
22+
//resolvers += "Maven Central" at "http://repo1.maven.org/maven2/"
23+
24+
//classpathTypes += "maven-plugin"
25+
26+
//libraryDependencies += "org.scala-lang" % "scala-library" % "2.12.0"
27+
28+
29+
libraryDependencies += "org.slf4j" % "slf4j-simple" % "1.7.21"
30+
31+
// Apache Common
32+
libraryDependencies += "org.apache.commons" % "commons-math3" % "3.6.1"
33+
34+
libraryDependencies += "org.knowm.xchart" % "xchart" % "3.2.1"
35+
36+
// http://bytedeco.org/
37+
libraryDependencies += "org.bytedeco" % "javacpp" % "1.2.4"
38+
libraryDependencies += "org.nd4j" % "canova-api" % "0.0.0.17"
39+
libraryDependencies += "org.nd4j" % "canova-nd4j-image" % "0.0.0.17"
40+
41+
// fails libraryDependencies += "org.nd4j" % "nd4j-native-platform" % "0.6.0" classifier "" classifier "linux-x86_64"
42+
//libraryDependencies += "org.nd4j" % "nd4j-native-platform" % "0.6.0"
43+
//libraryDependencies += "org.nd4j" % "nd4j-cuda-7.5-platform" % "0.6.0"
44+
libraryDependencies += "org.nd4j" % "nd4j-cuda-8.0-platform" % "0.6.0"
45+
//libraryDependencies += "org.nd4j" % "nd4j-jblas" % "0.4-rc3.6" not available
46+
//libraryDependencies += "org.nd4j" % "nd4j-netlib-blas" % "0.4-rc3.6" not available
47+
48+
// TODO
49+
// we want https://github.com/deeplearning4j/nd4s/tree/nd4s-0.6.0
50+
// https://github.com/deeplearning4j/nd4s/issues/82
51+
// git clone https://github.com/deeplearning4j/nd4s.git
52+
// cd nd4s/
53+
// git tag -l
54+
// git checkout tags/nd4s-0.6.0
55+
// or git checkout tags/<tag_name> -b <branch_name>
56+
// sbt
57+
// set scalaVersion := "2.12.0"
58+
// test:console
59+
// (1 to 9).asNDArray(3,3)
60+
libraryDependencies += "org.nd4j" % "nd4s_2.12.0-M3" % "0.4-rc3.8"
61+
//libraryDependencies += "org.nd4j" %% "nd4s" % "0.6.0"
62+
63+
libraryDependencies += "org.datavec" % "datavec-api" % "0.6.0"
64+
libraryDependencies += "org.datavec" % "datavec-data-image" % "0.6.0"
65+
libraryDependencies += "org.datavec" % "datavec-data-codec" % "0.6.0"
66+
libraryDependencies += "org.datavec" % "datavec-data-audio" % "0.6.0"
67+
//libraryDependencies += "org.datavec" % "datavec-nd4j-common" % "0.6.0" already loaded
68+
69+
libraryDependencies += "org.deeplearning4j" % "deeplearning4j-core" % "0.6.0"
70+
71+
72+
scalacOptions ++= Seq("-unchecked", "-deprecation")
73+

output/bimiodal_1.svg

Lines changed: 227 additions & 0 deletions
Loading

readme.txt

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
sbt eclipse
2+
reload
3+
eclipse with-source=true
4+
5+
6+
ND4J Examples
7+
..............
8+
sbt "run-main org.nd4j.examples.MatrixOperationExample"
9+
sbt "run-main org.nd4j.examples.Nd4jEx1_INDArrayBasics"
10+
sbt "run-main org.nd4j.examples.Nd4jEx2_CreatingINDArrays"
11+
sbt "run-main org.nd4j.examples.Nd4jEx3_GettingAndSettingSubsets"
12+
sbt "run-main org.nd4j.examples.Nd4jEx4_Ops"
13+
sbt "run-main org.nd4j.examples.Nd4jEx5_Accumulations"
14+
sbt "run-main org.nd4j.examples.Nd4jEx6_BooleanIndexing"
15+
16+
17+
Checking if OpenBLAS is working
18+
...................................
19+
20+
Instalation
21+
............
22+
sudo update-alternatives --list libblas.so
23+
/usr/lib/atlas-base/atlas/libblas.so
24+
/usr/lib/libblas/libblas.so
25+
/usr/lib/openblas-base/libblas.so
26+
root@gandalfix:/home/hmf# sudo update-alternatives --config libblas.so
27+
There are 3 choices for the alternative libblas.so (providing /usr/lib/libblas.so).
28+
29+
Selection Path Priority Status
30+
------------------------------------------------------------
31+
* 0 /usr/lib/openblas-base/libblas.so 40 auto mode
32+
1 /usr/lib/atlas-base/atlas/libblas.so 35 manual mode
33+
2 /usr/lib/libblas/libblas.so 10 manual mode
34+
3 /usr/lib/openblas-base/libblas.so 40 manual mode
35+
36+
Press <enter> to keep the current choice[*], or type selection number: 0
37+
38+
sudo update-alternatives --config libblas.so.3
39+
There are 3 choices for the alternative libblas.so.3 (providing /usr/lib/libblas.so.3).
40+
41+
Selection Path Priority Status
42+
------------------------------------------------------------
43+
* 0 /usr/lib/openblas-base/libblas.so.3 40 auto mode
44+
1 /usr/lib/atlas-base/atlas/libblas.so.3 35 manual mode
45+
2 /usr/lib/libblas/libblas.so.3 10 manual mode
46+
3 /usr/lib/openblas-base/libblas.so.3 40 manual mode
47+
48+
Press <enter> to keep the current choice[*], or type selection number: 0
49+
50+
sudo update-alternatives --config liblapack.so
51+
sudo update-alternatives --config liblapack.so.3
52+
53+
Checking with R
54+
...............
55+
Start R
56+
root@gandalfix:/home/hmf# ps aux | grep exec/R
57+
58+
Press <enter> to keep the current choice[*], or type selection number: 0
59+
root@gandalfix:/home/hmf# ps aux | grep exec/R
60+
hmf 19961 9.2 0.2 418792 36924 pts/18 Sl+ 17:55 0:00 /usr/lib/R/bin/exec/R
61+
root 19973 0.0 0.0 14232 1016 pts/19 S+ 17:55 0:00 grep --color=auto exec/R
62+
root@gandalfix:/home/hmf# lsof -p 19961 | grep 'blas\|lapack'
63+
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
64+
Output information may be incomplete.
65+
R 19961 hmf mem REG 8,2 6172176 18612834 /usr/lib/openblas-base/liblapack.so.3
66+
R 19961 hmf mem REG 8,2 31962416 18488605 /usr/lib/libopenblasp-r0.2.18.so
67+
R 19961 hmf mem REG 8,2 395528 18612831 /usr/lib/openblas-base/libblas.so.3
68+
69+
Checking with ND4J Examples
70+
.............................
71+
72+
sbt "run-main org.nd4j.examples.MatrixOperationExample"
73+
74+
(See the line referring to BLAS)
75+
76+
[info] Loading global plugins from /home/hmf/.sbt/0.13/plugins
77+
[info] Loading project definition from /home/hmf/tmp/dl4jtest/project
78+
[info] Set current project to dl4jtest (in build file:/home/hmf/tmp/dl4jtest/)
79+
[info] Running org.nd4j.examples.MatrixOperationExample
80+
[run-main-0] INFO org.nd4j.nativeblas.NativeOps - Number of threads used for NativeOps: 4
81+
[run-main-0] INFO org.nd4j.nativeblas.Nd4jBlas - Number of threads used for BLAS: 4
82+
[run-main-0] INFO org.reflections.Reflections - Reflections took 90 ms to scan 11 urls, producing 121 keys and 415 values
83+
[run-main-0] INFO org.reflections.Reflections - Reflections took 35 ms to scan 11 urls, producing 121 keys and 415 values
84+
[1.00, 2.00]
85+
[3.00, 4.00]
86+
[[1.00, 3.00],
87+
[2.00, 4.00]]
88+
[[3.00, 4.00],
89+
[5.00, 6.00]]
90+
Creating nd array with data type FLOAT
91+
11.00
92+
[13.00, 16.00]
93+
[[18.00, 22.00],
94+
[26.00, 32.00]]
95+
[[11.00, 25.00],
96+
[17.00, 39.00]]
97+
[[3.00, 6.00],
98+
[4.00, 8.00]]
99+
[5.00, 5.00]
100+
[success] Total time: 1 s, completed 15/nov/2016 10:43:35
101+
102+
103+
DL4J
104+
-----
105+
106+
Anomaly Detection
107+
.................
108+
109+
1. Autoencoder
110+
. https://github.com/deeplearning4j/dl4j-examples/blob/master/dl4j-examples/src/main/java/org/deeplearning4j/examples/feedforward/anomalydetection/MNISTAnomalyExample.java
111+
. sbt "run-main org.dl4j.examples.MNISTAnomalyExample"
112+
113+
114+
2. https://github.com/deeplearning4j/dl4j-examples/blob/master/dl4j-examples/src/main/java/org/deeplearning4j/examples/unsupervised/deepbelief/DeepAutoEncoderExample.java
115+
. sbt "run-main org.dl4j.examples.DeepAutoEncoderExample"
116+

sbtmkdirs.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
3+
#------------------------------------------------------------------------------
4+
# Name: sbtmkdirs
5+
# Purpose: Create an SBT project directory structure with a few simple options.
6+
# Author: Alvin Alexander, http://alvinalexander.com
7+
# Info: http://alvinalexander.com/sbtmkdirs
8+
# License: Creative Commons Attribution-ShareAlike 2.5 Generic
9+
# http://creativecommons.org/licenses/by-sa/2.5/
10+
#------------------------------------------------------------------------------
11+
declare -r TRUE=0
12+
declare -r FALSE=1
13+
14+
# takes a string and returns true if it seems to represent "yes"
15+
function isYes() {
16+
local x=$1
17+
[ $x = "y" ] && echo $TRUE; return
18+
[ $x = "Y" ] && echo $TRUE; return
19+
[ $x = "yes" ] && echo $TRUE; return
20+
echo $FALSE
21+
}
22+
23+
echo "This script creates an SBT project directory beneath the current directory."
24+
25+
while [ $TRUE ]; do
26+
27+
echo ""
28+
read -p "Directory/Project Name (MyFirstProject): " directoryName
29+
directoryName=${directoryName:-MyFirstProject}
30+
31+
read -p "Create .gitignore File? (Y/n): " createGitignore
32+
createGitignore=${createGitignore:-y}
33+
34+
read -p "Create README.md File? (Y/n): " createReadme
35+
createReadme=${createReadme:-y}
36+
37+
echo ""
38+
echo "-----------------------------------------------"
39+
echo "Directory/Project Name: $directoryName"
40+
echo "Create .gitignore File?: $createGitignore"
41+
echo "Create README.md File?: $createReadme"
42+
echo "-----------------------------------------------"
43+
read -p "Create Project? (Y/n): " createProject
44+
createProject=${createProject:-y}
45+
[ "$(isYes $createProject)" = "$TRUE" ] && break
46+
47+
done
48+
49+
mkdir -p ${directoryName}/src/{main,test}/{java,resources,scala}
50+
mkdir ${directoryName}/lib ${directoryName}/project ${directoryName}/target
51+
52+
# optional
53+
#mkdir -p ${directoryName}/src/main/config
54+
#mkdir -p ${directoryName}/src/{main,test}/{filters,assembly}
55+
#mkdir -p ${directoryName}/src/site
56+
57+
#---------------------------------
58+
# create an initial build.sbt file
59+
#---------------------------------
60+
echo "name := \"$directoryName\"
61+
62+
version := \"1.0\"
63+
64+
scalaVersion := \"2.11.7\"" > ${directoryName}/build.sbt
65+
66+
#------------------------------
67+
# create .gitignore, if desired
68+
#------------------------------
69+
if [ "$(isYes $createGitignore)" = "$TRUE" ]; then
70+
echo "bin/
71+
project/
72+
target/
73+
.cache
74+
.classpath
75+
.project
76+
.settings" > ${directoryName}/.gitignore
77+
fi
78+
79+
#-----------------------------
80+
# create README.me, if desired
81+
#-----------------------------
82+
if [ "$(isYes $createReadme)" = "$TRUE" ]; then
83+
touch ${directoryName}/README.md
84+
fi
85+
86+
echo ""
87+
echo "Project created. See the following URL for build.sbt examples:"
88+
echo "http://alvinalexander.com/scala/sbt-syntax-examples"
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package org.dl4j.examples;
2+
3+
import org.deeplearning4j.datasets.fetchers.MnistDataFetcher;
4+
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
5+
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
6+
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
7+
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
8+
import org.deeplearning4j.nn.conf.layers.OutputLayer;
9+
import org.deeplearning4j.nn.conf.layers.RBM;
10+
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
11+
import org.deeplearning4j.optimize.listeners.ScoreIterationListener;
12+
import org.nd4j.linalg.dataset.DataSet;
13+
import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
14+
import org.nd4j.linalg.lossfunctions.LossFunctions;
15+
import org.slf4j.Logger;
16+
import org.slf4j.LoggerFactory;
17+
18+
/**
19+
* ***** NOTE: This example has not been tuned. It requires additional work to produce sensible results *****
20+
*
21+
* @author Adam Gibson
22+
*/
23+
public class DeepAutoEncoderExample {
24+
25+
private static Logger log = LoggerFactory.getLogger(DeepAutoEncoderExample.class);
26+
27+
public static void main(String[] args) throws Exception {
28+
final int numRows = 28;
29+
final int numColumns = 28;
30+
int seed = 123;
31+
int numSamples = MnistDataFetcher.NUM_EXAMPLES;
32+
int batchSize = 1000;
33+
int iterations = 1;
34+
int listenerFreq = iterations/5;
35+
36+
log.info("Load data....");
37+
DataSetIterator iter = new MnistDataSetIterator(batchSize,numSamples,true);
38+
39+
log.info("Build model....");
40+
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
41+
.seed(seed)
42+
.iterations(iterations)
43+
.optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT)
44+
.list()
45+
.layer(0, new RBM.Builder().nIn(numRows * numColumns).nOut(1000).lossFunction(LossFunctions.LossFunction.RMSE_XENT).build())
46+
.layer(1, new RBM.Builder().nIn(1000).nOut(500).lossFunction(LossFunctions.LossFunction.RMSE_XENT).build())
47+
.layer(2, new RBM.Builder().nIn(500).nOut(250).lossFunction(LossFunctions.LossFunction.RMSE_XENT).build())
48+
.layer(3, new RBM.Builder().nIn(250).nOut(100).lossFunction(LossFunctions.LossFunction.RMSE_XENT).build())
49+
.layer(4, new RBM.Builder().nIn(100).nOut(30).lossFunction(LossFunctions.LossFunction.RMSE_XENT).build()) //encoding stops
50+
.layer(5, new RBM.Builder().nIn(30).nOut(100).lossFunction(LossFunctions.LossFunction.RMSE_XENT).build()) //decoding starts
51+
.layer(6, new RBM.Builder().nIn(100).nOut(250).lossFunction(LossFunctions.LossFunction.RMSE_XENT).build())
52+
.layer(7, new RBM.Builder().nIn(250).nOut(500).lossFunction(LossFunctions.LossFunction.RMSE_XENT).build())
53+
.layer(8, new RBM.Builder().nIn(500).nOut(1000).lossFunction(LossFunctions.LossFunction.RMSE_XENT).build())
54+
.layer(9, new OutputLayer.Builder(LossFunctions.LossFunction.MSE).activation("sigmoid").nIn(1000).nOut(numRows*numColumns).build())
55+
.pretrain(true).backprop(true)
56+
.build();
57+
58+
MultiLayerNetwork model = new MultiLayerNetwork(conf);
59+
model.init();
60+
61+
model.setListeners(new ScoreIterationListener(listenerFreq));
62+
63+
log.info("Train model....");
64+
while(iter.hasNext()) {
65+
DataSet next = iter.next();
66+
model.fit(new DataSet(next.getFeatureMatrix(),next.getFeatureMatrix()));
67+
}
68+
69+
70+
}
71+
72+
}

0 commit comments

Comments
 (0)