Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/testinit.c @ 16533

Last change on this file since 16533 was 16533, checked in by hmaislin, 5 years ago

#2929: Added Powershell testscript to compare results

File size: 13.0 KB
RevLine 
[16533]1#include "pge.h"
2#include <stdlib.h>
3#include <stdio.h>
4#include <string.h>
5
6void readTainData(char *path) {
7 
8}
9
10int main() {
11 
12  putenv("GOGC=off");
13  putenv("GODEBUG=cgocheck=0");
14  putenv("CGO_ENABLED=1");
15 
16   
17  /****** TrainData ******/
18   
19  GoInt indepLen = 1; //2 exists too    //culms
20  GoInt depLen = 2;             //culms
21  GoInt nEntries = 25;            //lines
22  int nCulm = indepLen + depLen;
23     
24  GoFloat64 *trainMatrix = (GoFloat64 *)malloc(nEntries * (indepLen + depLen) * sizeof(GoFloat64));
25 
26  printf("AddTrainData\n");
27 
28  /****** TestData ******/
29 
30  GoInt TindepLen = indepLen; //2 exists too    //culms
31  GoInt TdepLen = depLen;             //culms
32  GoInt TnEntries = 25;           //lines
33  nCulm = TindepLen + TdepLen;
34 
35  GoFloat64 *testMatrix = (GoFloat64 *)malloc(TnEntries * (TindepLen + TdepLen) * sizeof(GoFloat64));
36 
37  printf("AddTestData\n");
38  //AddTrainData(TindepNames, TdepndNames, TtrainMatrix, TnEntries);
39 
40trainMatrix[0 * nCulm + 0] = (GoFloat64) -5.000000;
41trainMatrix[0 * nCulm + 1] = (GoFloat64) -5.000000;
42trainMatrix[0 * nCulm + 2] = (GoFloat64) 1.996805 ;
43trainMatrix[1 * nCulm + 0] = (GoFloat64) -4.600000 ;
44trainMatrix[1 * nCulm + 1] = (GoFloat64) -5.000000;
45trainMatrix[1 * nCulm + 2] = (GoFloat64)1.996174 ;
46trainMatrix[2 * nCulm + 0] = (GoFloat64)-4.200000 ;
47trainMatrix[2 * nCulm + 1] = (GoFloat64)-5.000000 ;
48trainMatrix[2 * nCulm + 2] = (GoFloat64)1.995199 ;
49trainMatrix[3 * nCulm + 0] = (GoFloat64)-3.800000 ;
50trainMatrix[3 * nCulm + 1] = (GoFloat64)-5.000000 ;
51trainMatrix[3 * nCulm + 2] = (GoFloat64)1.993630 ;
52trainMatrix[4 * nCulm + 0] = (GoFloat64)-3.400000 ;
53trainMatrix[4 * nCulm + 1] = (GoFloat64)-5.000000 ;
54trainMatrix[4 * nCulm + 2] = (GoFloat64)1.990975 ;
55trainMatrix[5 * nCulm + 0] = (GoFloat64)-3.000000 ;
56trainMatrix[5 * nCulm + 1] = (GoFloat64)-5.000000 ;
57trainMatrix[5 * nCulm + 2] = (GoFloat64)1.986207 ;
58trainMatrix[6 * nCulm + 0] = (GoFloat64)-2.600000 ;
59trainMatrix[6 * nCulm + 1] = (GoFloat64)-5.000000 ;
60trainMatrix[6 * nCulm + 2] = (GoFloat64)1.976988 ;
61trainMatrix[7 * nCulm + 0] = (GoFloat64)-2.200000 ;
62trainMatrix[7 * nCulm + 1] = (GoFloat64)-5.000000 ;
63trainMatrix[7 * nCulm + 2] = (GoFloat64)1.957462 ;
64trainMatrix[8 * nCulm + 0] = (GoFloat64)-1.800000 ;
65trainMatrix[8 * nCulm + 1] = (GoFloat64)-5.000000 ;
66trainMatrix[8 * nCulm + 2] = (GoFloat64)1.911428 ;
67trainMatrix[9 * nCulm + 0] = (GoFloat64)-1.400000 ;
68trainMatrix[9 * nCulm + 1] = (GoFloat64)-5.000000 ;
69trainMatrix[9 * nCulm + 2] = (GoFloat64)1.791859 ;
70trainMatrix[10 * nCulm + 0] = (GoFloat64)-1.000000 ;
71trainMatrix[10 * nCulm + 1] = (GoFloat64)-5.000000 ;
72trainMatrix[10 * nCulm + 2] = (GoFloat64)1.498403 ;
73trainMatrix[11 * nCulm + 0] = (GoFloat64)-0.600000 ;
74trainMatrix[11 * nCulm + 1] = (GoFloat64)-5.000000 ;
75trainMatrix[11 * nCulm + 2] = (GoFloat64)1.113133 ;
76trainMatrix[12 * nCulm + 0] = (GoFloat64)-0.200000 ;
77trainMatrix[12 * nCulm + 1] = (GoFloat64)-5.000000 ;
78trainMatrix[12 * nCulm + 2] = (GoFloat64)1.000000 ;
79trainMatrix[13 * nCulm + 0] = (GoFloat64)0.200000 ;
80trainMatrix[13 * nCulm + 1] = (GoFloat64)-5.000000 ;
81trainMatrix[13 * nCulm + 2] = (GoFloat64)1.000000 ;
82trainMatrix[14 * nCulm + 0] = (GoFloat64)0.600000 ;
83trainMatrix[14 * nCulm + 1] = (GoFloat64)-5.000000 ;
84trainMatrix[14 * nCulm + 2] = (GoFloat64)1.113133 ;
85trainMatrix[15 * nCulm + 0] = (GoFloat64)1.000000 ;
86trainMatrix[15 * nCulm + 1] = (GoFloat64)-5.000000 ;
87trainMatrix[15 * nCulm + 2] = (GoFloat64)1.498403 ;
88trainMatrix[16 * nCulm + 0] = (GoFloat64)1.400000 ;
89trainMatrix[16 * nCulm + 1] = (GoFloat64)-5.000000 ;
90trainMatrix[16 * nCulm + 2] = (GoFloat64)1.791859 ;
91trainMatrix[17 * nCulm + 0] = (GoFloat64)1.800000 ;
92trainMatrix[17 * nCulm + 1] = (GoFloat64)-5.000000 ;
93trainMatrix[17 * nCulm + 2] = (GoFloat64)1.911428 ;
94trainMatrix[18 * nCulm + 0] = (GoFloat64)2.200000 ;
95trainMatrix[18 * nCulm + 1] = (GoFloat64)-5.000000 ;
96trainMatrix[18 * nCulm + 2] = (GoFloat64)1.957462 ;
97trainMatrix[19 * nCulm + 0] = (GoFloat64)2.600000 ;
98trainMatrix[19 * nCulm + 1] = (GoFloat64)-5.000000 ;
99trainMatrix[19 * nCulm + 2] = (GoFloat64)1.976988 ;
100trainMatrix[20 * nCulm + 0] = (GoFloat64)3.000000 ;
101trainMatrix[20 * nCulm + 1] = (GoFloat64)-5.000000 ;
102trainMatrix[20 * nCulm + 2] = (GoFloat64)1.986207 ;
103trainMatrix[21 * nCulm + 0] = (GoFloat64)3.400000 ;
104trainMatrix[21 * nCulm + 1] = (GoFloat64)-5.000000 ;
105trainMatrix[21 * nCulm + 2] = (GoFloat64)1.990975 ;
106trainMatrix[22 * nCulm + 0] = (GoFloat64)3.800000 ;
107trainMatrix[22 * nCulm + 1] = (GoFloat64)-5.000000 ;
108trainMatrix[22 * nCulm + 2] = (GoFloat64)1.993630 ;
109trainMatrix[23 * nCulm + 0] = (GoFloat64)4.200000 ;
110trainMatrix[23 * nCulm + 1] = (GoFloat64)-5.000000 ;
111trainMatrix[23 * nCulm + 2] = (GoFloat64)1.995199 ;
112trainMatrix[24 * nCulm + 0] = (GoFloat64)4.600000 ;
113trainMatrix[24 * nCulm + 1] = (GoFloat64)-5.000000;
114trainMatrix[24 * nCulm + 2] = (GoFloat64)1.996174;
115 
116testMatrix[0 * nCulm + 0] = (GoFloat64) -5.000000;
117testMatrix[0 * nCulm + 1] = (GoFloat64) -5.000000;
118testMatrix[0 * nCulm + 2] = (GoFloat64) 1.996805 ;
119testMatrix[1 * nCulm + 0] = (GoFloat64) -4.600000 ;
120testMatrix[1 * nCulm + 1] = (GoFloat64) -5.000000;
121testMatrix[1 * nCulm + 2] = (GoFloat64)1.996174 ;
122testMatrix[2 * nCulm + 0] = (GoFloat64)-4.200000 ;
123testMatrix[2 * nCulm + 1] = (GoFloat64)-5.000000 ;
124testMatrix[2 * nCulm + 2] = (GoFloat64)1.995199 ;
125testMatrix[3 * nCulm + 0] = (GoFloat64)-3.800000 ;
126testMatrix[3 * nCulm + 1] = (GoFloat64)-5.000000 ;
127testMatrix[3 * nCulm + 2] = (GoFloat64)1.993630 ;
128testMatrix[4 * nCulm + 0] = (GoFloat64)-3.400000 ;
129testMatrix[4 * nCulm + 1] = (GoFloat64)-5.000000 ;
130testMatrix[4 * nCulm + 2] = (GoFloat64)1.990975 ;
131testMatrix[5 * nCulm + 0] = (GoFloat64)-3.000000 ;
132testMatrix[5 * nCulm + 1] = (GoFloat64)-5.000000 ;
133testMatrix[5 * nCulm + 2] = (GoFloat64)1.986207 ;
134testMatrix[6 * nCulm + 0] = (GoFloat64)-2.600000 ;
135testMatrix[6 * nCulm + 1] = (GoFloat64)-5.000000 ;
136testMatrix[6 * nCulm + 2] = (GoFloat64)1.976988 ;
137testMatrix[7 * nCulm + 0] = (GoFloat64)-2.200000 ;
138testMatrix[7 * nCulm + 1] = (GoFloat64)-5.000000 ;
139testMatrix[7 * nCulm + 2] = (GoFloat64)1.957462 ;
140testMatrix[8 * nCulm + 0] = (GoFloat64)-1.800000 ;
141testMatrix[8 * nCulm + 1] = (GoFloat64)-5.000000 ;
142testMatrix[8 * nCulm + 2] = (GoFloat64)1.911428 ;
143testMatrix[9 * nCulm + 0] = (GoFloat64)-1.400000 ;
144testMatrix[9 * nCulm + 1] = (GoFloat64)-5.000000 ;
145testMatrix[9 * nCulm + 2] = (GoFloat64)1.791859 ;
146testMatrix[10 * nCulm + 0] = (GoFloat64)-1.000000 ;
147testMatrix[10 * nCulm + 1] = (GoFloat64)-5.000000 ;
148testMatrix[10 * nCulm + 2] = (GoFloat64)1.498403 ;
149testMatrix[11 * nCulm + 0] = (GoFloat64)-0.600000 ;
150testMatrix[11 * nCulm + 1] = (GoFloat64)-5.000000 ;
151testMatrix[11 * nCulm + 2] = (GoFloat64)1.113133 ;
152testMatrix[12 * nCulm + 0] = (GoFloat64)-0.200000 ;
153testMatrix[12 * nCulm + 1] = (GoFloat64)-5.000000 ;
154testMatrix[12 * nCulm + 2] = (GoFloat64)1.000000 ;
155testMatrix[13 * nCulm + 0] = (GoFloat64)0.200000 ;
156testMatrix[13 * nCulm + 1] = (GoFloat64)-5.000000 ;
157testMatrix[13 * nCulm + 2] = (GoFloat64)1.000000 ;
158testMatrix[14 * nCulm + 0] = (GoFloat64)0.600000 ;
159testMatrix[14 * nCulm + 1] = (GoFloat64)-5.000000 ;
160testMatrix[14 * nCulm + 2] = (GoFloat64)1.113133 ;
161testMatrix[15 * nCulm + 0] = (GoFloat64)1.000000 ;
162testMatrix[15 * nCulm + 1] = (GoFloat64)-5.000000 ;
163testMatrix[15 * nCulm + 2] = (GoFloat64)1.498403 ;
164testMatrix[16 * nCulm + 0] = (GoFloat64)1.400000 ;
165testMatrix[16 * nCulm + 1] = (GoFloat64)-5.000000 ;
166testMatrix[16 * nCulm + 2] = (GoFloat64)1.791859 ;
167testMatrix[17 * nCulm + 0] = (GoFloat64)1.800000 ;
168testMatrix[17 * nCulm + 1] = (GoFloat64)-5.000000 ;
169testMatrix[17 * nCulm + 2] = (GoFloat64)1.911428 ;
170testMatrix[18 * nCulm + 0] = (GoFloat64)2.200000 ;
171testMatrix[18 * nCulm + 1] = (GoFloat64)-5.000000 ;
172testMatrix[18 * nCulm + 2] = (GoFloat64)1.957462 ;
173testMatrix[19 * nCulm + 0] = (GoFloat64)2.600000 ;
174testMatrix[19 * nCulm + 1] = (GoFloat64)-5.000000 ;
175testMatrix[19 * nCulm + 2] = (GoFloat64)1.976988 ;
176testMatrix[20 * nCulm + 0] = (GoFloat64)3.000000 ;
177testMatrix[20 * nCulm + 1] = (GoFloat64)-5.000000 ;
178testMatrix[20 * nCulm + 2] = (GoFloat64)1.986207 ;
179  testMatrix[21 * nCulm + 0] = (GoFloat64)3.400000 ;
180      testMatrix[21 * nCulm + 1] = (GoFloat64)-5.000000 ;
181        testMatrix[21 * nCulm + 2] = (GoFloat64)1.990975 ;
182  testMatrix[22 * nCulm + 0] = (GoFloat64)3.800000 ;
183    testMatrix[22 * nCulm + 1] = (GoFloat64)-5.000000 ;
184      testMatrix[22 * nCulm + 2] = (GoFloat64)1.993630 ;
185  testMatrix[23 * nCulm + 0] = (GoFloat64)4.200000 ;
186    testMatrix[23 * nCulm + 1] = (GoFloat64)-5.000000 ;
187testMatrix[23 * nCulm + 2] = (GoFloat64)1.995199 ;
188testMatrix[24 * nCulm + 0] = (GoFloat64)4.600000 ;
189testMatrix[24 * nCulm + 1] = (GoFloat64)-5.000000;
190testMatrix[24 * nCulm + 2] = (GoFloat64)1.996174;
191 
192 
193 
194  AddTestData("X Y", "F", testMatrix, TnEntries);
195  AddTrainData("X Y", "F", trainMatrix, nEntries);
196  /****** InitSearch ******/
197 
198    GoInt UsableVarsLen = 2;
199    GoInt *UsableVarsData = malloc(sizeof(GoInt) * UsableVarsLen);
200    UsableVarsData[0] = 0;
201    UsableVarsData[1] = 1;
202    //UsableVarsData[2] = 2;
203    //UsableVarsData[3] = 3;
204    //UsableVarsData[4] = 4;
205 
206  //TestSlice(UsableVarsData, UsableVarsLen);
207 
208  GoInt *UsableVars = UsableVarsData; //{ .data = UsableVarsData, .len = UsableVarsLen, .cap = UsableVarsLen };   //GoSlice was type
209
210
211  //func InitSearch(maxGen int, pgeRptEpoch int, pgeRptCount int, pgeArchiveCap int, peelCnt int, evalrCount int, zeroEpsilon float64, initMethod string, growMethod string, sortType int)
212 
213  GoInt MaxGen = 2000;
214  GoInt PgeRptEpoch = 1;
215  GoInt PgeRptCount = 1;
216  GoInt PgeArchiveCap = 256;
217 
218  GoInt PeelCnt = 3;
219
220  GoFloat64 ZeroEpsilon = 0.00001;
221  GoInt EvalrCount = 2; //vorhernull?!
222 
223  char *InitMethod = "method1"; //{ .p = "method1", .n = strlen("method1") };
224  char *GrowMethod = "method1"; //{ .p = "method1", .n = strlen("method1") };
225 
226  int SortType = 0;
227 
228  InitSearch(MaxGen, PgeRptEpoch, PgeRptCount, PgeArchiveCap, PeelCnt, EvalrCount, ZeroEpsilon, InitMethod, GrowMethod, SortType);
229  printf("InitSearch\n");
230 
231 
232  /****** InitTreeParams ******/
233
234  //func InitTreeParams(Roots string, Nodes string, NonTrig string, Leafs string, UsableVars []int, MaxSize int, MinSize int, MaxDepth int, MinDepth int)
235  char *Roots = "Add"; //{ .p = "Add", .n = strlen("Add") };
236  char *Nodes = "Add Mul Div Sin Cos Exp Log Sqrt"; //{ .p = "Add Mul", .n = strlen("Add Mul") };
237  //char *Nodes = "Add Mul";
238  char *NonTrig = "Add Mul Div Exp Log"; //{ .p = "Add Mul", .n = strlen("Add Mul") };
239  //char *NonTrig = "Add Mul";
240  char *Leafs = "Var ConstantF"; //{ .p = "Var ConstantF", .n = strlen("Var ConstantF") };
241  GoInt MaxSize = 50;
242  GoInt MinSize = 4;
243  GoInt MaxDepth = 6;
244  GoInt MinDepth = 1;
245 
246  InitTreeParams(Roots, Nodes, NonTrig, Leafs, UsableVars, UsableVarsLen, MaxSize, MinSize, MaxDepth, MinDepth);
247  printf("InitTreeParams\n");
248 
249  /****** InitProblem ******/
250
251  //func InitProblem(Name string, MaxIter int, HitRatio float64, SearchVar int, UsableVars []int, ProblemTypeString string, numProcs int)
252  char *Name = "Korns_02"; //{ .p = "Korns_02", .n = strlen("Korns_02") };
253  GoInt MaxIter = 5000;
254  GoFloat64 HitRatio = 0.01;
255  GoInt SearchVar = 0;
256
257  char *ProblemTypeString = "benchmark"; //{ .p = "benchmark", .n = strlen("benchmark") }; //real not working/implementated | diffeq is implementated
258  GoInt numProcs = 12;
259 
260  printf("InitProblem\n");
261  fflush(stdout);
262  InitProblem(Name, MaxIter, HitRatio, SearchVar, ProblemTypeString, numProcs);
263 
264  printf("******************************** Finished Init **********************************\n");
265 
266  /****** Run ******/
267
268  //GoInt maxi = GetMaxIterW();
269  //printf("GetMaxIter: %d\n", maxi);
270  //fflush(stdout);
271
272  //EvaluateW();
273  //printf("EvaluateW\n");
274 
275    //LoopW();
276  //printf("LoopW\n");
277 
278
279  //MaxIter = 5;
280  for (int fs1 = 1; fs1 <= MaxIter; fs1++) {   
281    printf("******************************** StepW: %d **********************************\n", fs1);
282    GoInt nresults = StepW();
283   
284    for (int ires = 0; ires < nresults; ires++) {
285     
286      GoInt nobestpush = 0;
287      GoInt bestnewminerr = 0;
288      GoInt bestlen1 = 0;
289      GoInt bestlen2 = 0;
290      GoInt testscore = 0;
291      GoInt ncoeff = 0;
292     
293      char* stepRes = GetStepResult(&nobestpush, &bestnewminerr, &bestlen1, &bestlen2, &testscore, &ncoeff);     
294   
295      GoFloat64 *coeff = (GoFloat64 *)malloc(UsableVarsLen * sizeof(GoFloat64));
296     
297      for(int icoeff = 0; icoeff < UsableVarsLen; icoeff++) {
298        coeff[icoeff] = 0;
299      }
300     
301      //printf("C: No best push\n");
302      printf("C: push/pop (%d,%d) %s\n", bestlen1, bestlen2, stepRes);
303      for(int icoeff = 0; icoeff < ncoeff; icoeff++){
304        GoFloat64 coeffVal = GetCoeffResult();
305        printf("C: coeff vals: %f\n", coeffVal);
306      }
307      if (bestnewminerr) {
308        //printf("C: Best New Min Error\n");
309      }
310      printf("C: TestScore %f\n", testscore);
311 
312    }
313    fflush(stdout);
314  }
315 
316  return 0;
317 
318  fflush(stdout);
319 
320  //CleanW();
321  //printf("CleanW\n");
322  fflush(stdout);
323 
324  printf("Run Start\n");
325  fflush(stdout);
326  //RunW();
327  fflush(stdout);
328  printf("Run Ende\n");
329 
330  // !!!!!!!!!!!!!! FREE DATA !!!!!!!!!!!!!!!!!!!!!
331 
332  return 0;
333}
Note: See TracBrowser for help on using the repository browser.