-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
57 lines (50 loc) · 2.18 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import ann4j.*;
public class Main {
public static void main(String[] args) {
// Setting the output file to be output.txt and enabling command line logging
parameter.setOutputFile("output.txt", true);
// Setting the number of neurons in each layer.
parameter.setLayerArray(784, 32, 16, 16, 10);
// Setting the training file to be emnist-letters-train.csv and the file type to
// be mnist.
parameter.setTrainingFileReader("mnist_train.csv", "mnist");
// Setting the testing file to be emnist-letters-test.csv and the file type to
// be mnist.
parameter.setTestingFileReader("mnist_test.csv", "mnist");
// Setting the learning rate to 1.
parameter.setLearningRate(1);
// Setting the learning rate for the bias to 1.
parameter.setBiasLearningRate(1);
// Setting the epsillion value for the relevance propagation algorithm.
parameter.setEpsillion(0);
// Setting the batch size to 10.
parameter.setBatchsize(10);
// Setting the rectification function to be sigmoid.
parameter.setRectificationFunction("sigmoid");
// Creating a new instance of the Trainer class.
Trainer myTrainer = new Trainer();
// Training the network with 45000 samples for 10 epochs
myTrainer.train(45000, 10);
// Creating a new instance of the NeuronObserver class this class will observe
// the neurons and respond when every parameter is changed.
NeuronObserver myNeuronObserver = new NeuronObserver();
// Setting the model for the neuron observer.
myNeuronObserver.setModel(myTrainer.getLayerManager());
// Testing the network with 9990 samples.
myTrainer.test(9990);
// Adding the neuron at layer 1 and index 31 to be observed.
myNeuronObserver.addNeuronToBeObserved(1, 31);
// myTrainer.printConfusionMatrix();
myTrainer.test(2);
// It clears the neurons that are being observed.
myNeuronObserver.clear();
myNeuronObserver.addNeuronToBeObserved(2, 0);
myTrainer.test(2);
// xai algorithm for relevance propagation.
myTrainer.relevancePropagate(2, 3);
// xai algotithm for most significant input neurons
myTrainer.forwardPropagatewithExclusionInputLayerOnKSamples(2);
// It prints the parameters to the output file. //must be at end of file
parameter.display();
}
}