/
GenerateTrainingSet.java
162 lines (134 loc) · 5.25 KB
/
GenerateTrainingSet.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package de.biomedical_imaging.ij.trajectory_classifier.help;
import java.util.ArrayList;
import de.biomedical_imaging.traJ.ExportTools;
import de.biomedical_imaging.traJ.Trajectory;
import de.biomedical_imaging.traJ.features.BoundednessFeature;
import de.biomedical_imaging.traJ.simulation.AbstractSimulator;
import de.biomedical_imaging.traJ.simulation.ActiveTransportSimulator;
import de.biomedical_imaging.traJ.simulation.AnomalousDiffusionWMSimulation;
import de.biomedical_imaging.traJ.simulation.CentralRandomNumberGenerator;
import de.biomedical_imaging.traJ.simulation.CombinedSimulator;
import de.biomedical_imaging.traJ.simulation.ConfinedDiffusionSimulator;
import de.biomedical_imaging.traJ.simulation.FreeDiffusionSimulator;
import de.biomedical_imaging.traJ.simulation.SimulationUtil;
public class GenerateTrainingSet {
/*
* This script generates training trajecotires
*
* There are 4 different diffusion modes:
* - Free diffusion
* - Subdiffusion
* - Confined diffusion
* - Directed motion
*
* For each trajectory:
* The signal to noise ratio is randomly choosen between 1 and 20
* For confined diffusion trajectories, the boundedness is choosen randomly between 1 and 8. W
with the given boundedness value a confinement radius is derived.
* For subdiffusion trajectories, alpha is choosen randomly between 0.7 and 0.3
* For directed motion, the ratio between active transport and diffusion is randomly choosen between 1 and 18.
*
*/
enum SIM_TYPE {
FREE,
ANOMALOUS,
CONFINED,
ACTIVE
}
private static CentralRandomNumberGenerator r;
public static void main(String[] args) {
final int MODE_TRAINING = 1;
final int MODE_TEST = 2;
final int MODE_VALIDATION = 3;
//General Parameters
int numberOfTracks = 0;
int seed = 0;
int MODE = MODE_TEST; // SELECT WHICH TYPE OF DATA YOU WANT TO GENERATE
String prefix = "";
switch (MODE) {
case MODE_TRAINING:
numberOfTracks = 5000;
seed = 22;
prefix = "training";
break;
case MODE_TEST:
numberOfTracks = 1000;
prefix = "test";
seed = 23;
break;
case MODE_VALIDATION:
numberOfTracks = 250;
prefix = "validation";
seed = 24;
break;
default:
break;
}
String path = "/home/thorsten/tracks_"+prefix+".RData";
r = CentralRandomNumberGenerator.getInstance();
r.setSeed(seed);
double diffusioncoefficient = 9.02; //[µm^2/s];
double timelag = 1.0/30; //s
int dimension = 2;
//Active transport / drift
double angleVelocity = Math.PI/4.0; //rad/s
SIM_TYPE[] types = SIM_TYPE.values();
ArrayList<Trajectory> trajectorys= new ArrayList<Trajectory>();
System.out.println("Generation of free, confined , subdiffsuion and active trajectories");
int tCounter = 0;
for (SIM_TYPE type : types) {
for(int i = 0 ; i < numberOfTracks; i++){
double tracklength = (1+r.nextDouble()*20);
int numberOfSteps = (int)(tracklength * 1/timelag);
double boundedness = 1 + r.nextDouble()*20;
double alpha = 0.3+r.nextDouble()*0.4; // 0.1 - 0.9
AbstractSimulator sim = null;
String typestring = "";
typestring += type.toString();
Trajectory t = null;
double diffusionToNoiseRatio = 1 + r.nextDouble()*8;
double sigmaPosNoise = 1;
switch (type) {
case FREE:
sim = new FreeDiffusionSimulator(diffusioncoefficient, timelag, dimension, numberOfSteps);
sigmaPosNoise = Math.sqrt(diffusioncoefficient*timelag)/diffusionToNoiseRatio;
break;
case CONFINED:
double radius_confined = Math.sqrt(BoundednessFeature.a(numberOfSteps)*diffusioncoefficient*timelag/(4*boundedness));
sim = new ConfinedDiffusionSimulator(diffusioncoefficient, timelag, radius_confined, dimension, numberOfSteps);
sigmaPosNoise = Math.sqrt(diffusioncoefficient*timelag)/diffusionToNoiseRatio;
break;
case ACTIVE:
double aToDRatio = 2 + r.nextDouble()*16; // 1- 18
double drift = Math.sqrt(aToDRatio*4*diffusioncoefficient/tracklength);
AbstractSimulator sim1 = new ActiveTransportSimulator(drift, angleVelocity, timelag, dimension, numberOfSteps);
AbstractSimulator sim2 = new FreeDiffusionSimulator(diffusioncoefficient, timelag, dimension, numberOfSteps);
sim = new CombinedSimulator(sim1, sim2);
sigmaPosNoise = Math.sqrt(diffusioncoefficient*timelag + drift*drift*timelag*timelag)/diffusionToNoiseRatio;
break;
case ANOMALOUS:
sim = new AnomalousDiffusionWMSimulation(diffusioncoefficient, timelag, dimension, 2000, alpha);
sigmaPosNoise = Math.sqrt(diffusioncoefficient*timelag)/diffusionToNoiseRatio;
break;
default:
break;
}
t = sim.generateTrajectory();
if(type==SIM_TYPE.ANOMALOUS){
t = t.subList(0, numberOfSteps+1);
}
t.setType(typestring);
trajectorys.add(t);
tCounter++;
if(tCounter%10 == 0){
System.out.println("T: "+ tCounter + " Type " + t.getType());
}
}
}
System.out.println("Tracks generated");
ExportTools.exportTrajectoriesAsRData(trajectorys, path, timelag);
trajectorys=null;
System.out.println("Export done");
System.out.println("Done!");
}
}