-
Notifications
You must be signed in to change notification settings - Fork 0
/
CANT23.java
executable file
·144 lines (121 loc) · 4.08 KB
/
CANT23.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//This can either run as an applet in which case init is used
//or as an application, in which case main is used. The environment
//it runs from chooses (java debugger application web browser=applet)
//In Kawa 16/10/02
import java.io.*;
import java.util.*;
import java.applet.*;
import java.net.*; //for URL
public class CANT23 extends Applet{
public static String ExperimentXMLFile = "Param.xml";
public static CANTNet nullNet;
public static Hashtable nets;
public static boolean isRunning=false;
public static int CANTStep = 0;
public static int delayBetweenSteps = 20;
public static CANTExperiment experiment;
public static CANT23.WorkerThread workerThread;
public static void setRunning(boolean status) {isRunning = status;}
public static boolean isRandomInitialised = false;
//public static long seed=78266;//set your own seed
public static long seed = (long) (Math.random()*64000000); // set random seed
public static Random random;// use a random object instead of Math.random()
public static void main(String args[]){
System.out.println("Start CANT ");
initRandom();
makeNewSystem();
}
protected static void initRandom() {
if (!isRandomInitialised) {
isRandomInitialised = true;
random = new Random(seed);
System.err.println("Seed: " + seed);
}
else
random = new Random();
}
protected static void makeNewSystem() {
nullNet = new CANTNet();
nets = NetManager.readNets(ExperimentXMLFile,nullNet);
workerThread = new CANT23.WorkerThread();
initializeExperiment();
workerThread.start();
}
protected static void closeSystem() {
Enumeration eNum = nets.elements();
CANTNet net;
do {
net = (CANTNet)eNum.nextElement();
net.cantFrame.dispose();
}
while (eNum.hasMoreElements());
CANTStep=0;
}
public static void saveAllNets() {
System.out.println("save all nets");
Enumeration eNum = nets.elements();
while (eNum.hasMoreElements()) {
CANTNet net = (CANTNet)eNum.nextElement();
net.write();
}
}
//set up the experiment specific parameters.
private static void initializeExperiment() {
System.out.println("initialize Experiment ");
experiment = new CANTExperiment();
experiment.printExpName();
}
//run one step of the simulation.
public static synchronized void runOneStep() {
//System.out.println("CANT run one step");
if (experiment.trainingLength == CANTStep) experiment.switchToTest();
if (experiment.getInTest()) experiment.measure(CANTStep);
if (experiment.isEndEpoch(CANTStep))
experiment.endEpoch();
Enumeration eNum = nets.elements();
while (eNum.hasMoreElements()) {
CANTNet net = (CANTNet)eNum.nextElement();
net.runOneStep(CANTStep);
}
CANTStep++;
//System.out.println("Incremenet cantstep"+CANTStep);
if (experiment.experimentDone(CANTStep))
{
System.out.println("experiment Done"+CANTStep);
closeSystem();
makeNewSystem();
}
}
/*
public static void setConnectionToOther(CANTNet fromNet, int fromNeuronID, double weight,
String toNetName, int toNeuronID) {
CANTNet toNet;
toNet = (CANTNet)nets.get(toNetName);
fromNet.setConnectionToOther(fromNeuronID, weight, toNet, toNeuronID);
}
public static void reconnectFromOtherNets(CANTNet newNet) {
String toNetName = newNet.getName();
Enumeration enum = nets.elements();
while (enum.hasMoreElements()) {
CANTNet net =(CANTNet)enum.nextElement();
if (!net.getName().equals(toNetName) )
newNet.resetConnectionsFromOther(net);
}
}
*/
//embedded Thread class
public static class WorkerThread extends Thread{
public void run(){
//System.out.println("Thread ");
while(true){
if(isRunning){
runOneStep();
}
else{
try{sleep(delayBetweenSteps);}
catch(InterruptedException ie){ie.printStackTrace();}
}//else
}//while
}//run
}//WorkerThread class
}