All of the math i did is written here LSTM1.docx
run the file LstmGui/dist/LstmGui.jar
double[] settings = {
1, // activate weights with random value 0
0, // minimum random weight activation 1
1, // maximum random weight activation 2
1, // activate biases with random value 3
0, // minimum random bias activation 4
1, // maximum random bias activation 5
1, // activation function 1 = sigmoid 6
1, // error function 1 = quadratic 7
0.005, // learning rate 8
0, // softmax output 9
0, // output results to file output.json 10
0, // Graph data 11
10, // graph every n epochs 12
};
An array the size of layer count, wich consists of neuron vectors
neurons[ layer ][ this_layer ]
An array the size of layer count -1. Here there are stored synapses matrices that connect from this layer, to the next one.
neurons[ layer ][ this_layer ][ next_layer ]
create a network with 4 layers, sizes: 3,2,2,3
Mlp testMlp = new Mlp(new int[]{3,2,2,3});
testMlp.settings[3] = 0;
testMlp.randomlySetWeights();
testMlp.forward(new double[]{1,0,1});
double[] out = testMlp.neurons[testMlp.neurons.length-1];
double[] out = testMlp.eval(new double[]{1,0,1});
double[] targetOutput = new double[]{1,1,0};
testMlp.backpropagate(targetOutput);
double[] exampleInput = new double[]{1,0,1};
double[] targetOutput = new double[]{1,1,0};
testMlp.backpropagate(exampleInput,targetOutput);
lets make it learn XOR
inputs outputs
[[0,0], -> [[0],
[0,1], -> [1],
[1,0], -> [1],
[1,1]] -> [0]]
1000 epochs, 100 iterations per training example
testMlp1.learn(new double[][]{{0,0}, {0,1}, {1,0}, {1,1}}, new double[][]{{0}, {1}, {1}, {0}}, 1000, 100);
This is a graphing library which is kinda bad.
you can create the Graph object empty or with data
Graph testGraph = new Graph();
or
Graph testGraph = new Graph(new double[]{5,5,4,4,4,3,3,3,3,2,2,2,2,2,1,1,1,1,1});
testGraph.showGraph("graph title");
You can add data and the graph will update
You can add data as a Point
object:
testGraph.addData(new Point(19,10));
or as a value
testGraph.addData(10);
or as an array of any of the two
DataManager is made, to convert from meaningfull data, to Lstm trainable data
char[] vocabulary = DataManager.buildCharVocab("test sentence1. Test sentence2");
//TODO check if posible
String[] testData = new String[]{"test sentence1", "Test sentence2"};
char[][][] data = DataManager.stringToInCharExpChar(testData);
char[] vocabulary = DataManager.buildCharVocab("test sentence1. Test sentence2");
double[][][] testTestData = DataManager.vectorifyChar(vocabulary, data[0]);
double[][][] testExpData = DataManager.vectorifyChar(vocabulary, data[1]);
char[] outChar = DataManager.vectorToChar(out, vocabulary);
This object is an abstract lstm cell with 4 gates
int inputSize = 2;
int outputSize = 3;
LstmCell cell1 = new LstmCell(inputSize, outputSize);
Made for orchestraiting and training an lstmcell
LstmChain chain = new LstmChain(cell1);
// example data [0,0,1] -> [0,1,0]
// [0,1,0] -> [1,0,0]
double[][] testTestData = new double[][]{{0,0,1},{0,1,0}};
double[][] testExpData = new double[][]{{0,1,0},{1,0,0}};
chain.learn(testTestData, testExpData, 10000, 100);
double[][] out = chain.forwardWithVectorify([0,0,1], 1000);