-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
149 lines (121 loc) · 5.27 KB
/
Copy pathProgram.cs
File metadata and controls
149 lines (121 loc) · 5.27 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HyperModel
{
class Program
{
static void Main(string[] args)
{
// import relevant classes
NeuralNetworks.TDSimNetwork NN = new NeuralNetworks.TDSimNetwork();
NeuralNetworks.Network Controller = new NeuralNetworks.Network();
NeuralNetworks.NeuroEvo NE = new NeuralNetworks.NeuroEvo();
DataIO.DataExport DE = new DataIO.DataExport();
// data management stuff
NN.NumLinesToRemove = 2;
NN.NumPoints = 25;
NN.NumControlVars = 2;
NN.NumValidationPoints = 100;
// set network learning variables for learning model
NN.NumInputs = 21;
NN.NumHidden = 15;
NN.NumOutputs = 19;
NN.WeightInitSTD = 0.75;
NN.Eta = 0.1; //.25 // was most recently 0.2
NN.Episodes = 2500;
NN.Momentum = 0.7; //.5 // was most recently 0.7
NN.NumRestarts = 750;
NN.Shuffle = NeuralNetworks.ToggleShuffle.yes;
NN.NumMSEReportingPoints = NN.Episodes;
NN.DataExtension = "ColdAir";
// train network
//NN.TrainNetwork();
// import network and test it
NN.ImportTrainedNetwork();
// NN.TDSimNoControl(4);
// set simulation parameters: initial state, time steps, and desired setpoint
NN.InitialState = NN.Outputs[0];
NN.SimTimeSteps = 100;
//NN.SetPoint.Add(NN.Outputs[100]);
NN.SetPoint.Add(NN.Outputs[200]);
NN.SetPoint.Add (NN.Outputs [250]);
//NN.SetPoint.Add (NN.Outputs [150]);
//NN.SetPoint.Add (NN.Outputs [125]);
//NN.SetPoint.Add (NN.Outputs [175]);
//NN.SetPoint.Add (NN.Outputs [20]);
// // set neuroevolutionary parameters
// NE.NumInputs = NN.NumOutputs*2;
// NE.NumHidden = 15;
// NE.NumOutputs = 2;
// NE.WeightInitSTD = 2.0;
// NE.PopSize = 10;
// NE.MutateSTD = 1.0;
// NE.NumMutationsMatrix1 = 30;
// NE.NumMutationsMatrix2 =5;
// NE.Domain = NN;
// NE.Epochs = 1000;
// NE.StatRuns = 2;
// NE.FitType = NeuralNetworks.FitnessType.fStatic;
//
// // run neuroevolutionary control algorithms, and export data
// double[,] eaData = NE.StatRunsEA();
// DE.Export2DArray(eaData, "eaData");
//
// Controller = NE.BestNetwork;
//NE.BestNetwork.ExportController ();
//Controller.ExportController();
Controller.ImportController();
// pick a parameter to plot controlled var vs. desired setpoint
int parameterOfInterest = 4;
NN.VariableOfInterest = parameterOfInterest;
// simulate using learned controller, and export true vs. desired datapoints
//Desired set points for a sim
List<double[]> setPointTrajectory = new List<double[]>();
int step = NN.SimTimeSteps/2;
for (int i=0; i<step; i++)
{
setPointTrajectory.Add (NN.SetPoint [1]);
}
for (int i=step; i<2*step; i++)
{
setPointTrajectory.Add(NN.SetPoint[0]);
}
List<List<double[]>> allStateData = NN.TDSim_Act_Noise(Controller,setPointTrajectory);
double[,] neControlData = new double[NN.SimTimeSteps, 2];
double[,] noiseControlData = new double[NN.SimTimeSteps,2];
double[,] setPointData = new double[NN.SimTimeSteps, 2];
for (int i = 0; i < NN.SimTimeSteps; i++)
{
neControlData[i, 0] = Convert.ToDouble(i);
neControlData[i, 1] = allStateData[0][i][parameterOfInterest];
setPointData[i, 0] = Convert.ToDouble(i);
setPointData[i, 1] = setPointTrajectory[i][parameterOfInterest];
noiseControlData [i, 0] = Convert.ToDouble (i);
noiseControlData [i, 1] = allStateData [1] [1] [parameterOfInterest];
}
DE.Export2DArray(neControlData, "neControlData");
DE.Export2DArray (noiseControlData, "noiseControlData");
// DE.Export2DArray(setPointData, "setPointData");
/*
// simulate with sensor noise
List<double[]> allStateData_Noise = NN.TDSim_Noise(NE.BestNetwork);
double[,] neControlData_Noise = new double[NN.SimTimeSteps, 2];
//double[,] setPointData_Noise = new double[NN.SimTimeSteps, 2];
for (int i = 0; i < NN.SimTimeSteps; i++)
{
//neControlData_Noise[i, 0] = Convert.ToDouble(i);
// neControlData_Noise[i, 1] = allStateData_Noise[i][parameterOfInterest];
setPointData[i, 0] = Convert.ToDouble(i);
setPointData[i, 1] = NN.SetPoint[0][parameterOfInterest];
}
DE.Export2DArray(neControlData_Noise, "neControlData_with_Noise");
// DE.Export2DArray(setPointData_Noise, "setPointData");
*/
Console.WriteLine("Press ENTER to Continue...");
Console.ReadLine();
}
}
}