Changeset 16614 for branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/PGE.cs
- Timestamp:
- 02/19/19 05:05:24 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/PGE.cs
r16515 r16614 34 34 35 35 [DllImport("go-pge.dll", EntryPoint = "initTreeParams", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 36 public static extern void InitTreeParams(IntPtr roots, IntPtr nodes, IntPtr nonTrig, IntPtr leafs, IntPtr usableVars,int numUsableVars, int maxSize, int minSize, int maxDepth, int minDepth);36 public static extern void InitTreeParams(IntPtr roots, IntPtr nodes, IntPtr nonTrig, IntPtr leafs, int numUsableVars, int maxSize, int minSize, int maxDepth, int minDepth); 37 37 38 38 [DllImport("go-pge.dll", EntryPoint = "initProblem", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] … … 43 43 44 44 [DllImport("go-pge.dll", EntryPoint = "getStepResult", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 45 public static extern IntPtr GetStepResult(out int noBestPush, out int bestNewMinErr, out int bestlen1, out int bestlen2, out inttestscore, out int nCoeff);45 public static extern IntPtr GetStepResult(out int testscore, out int nCoeff); 46 46 47 47 [DllImport("go-pge.dll", EntryPoint = "getCoeffResult", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] … … 345 345 346 346 int numberOfUseableVariables = problemData.AllowedInputVariables.Count(); 347 IntPtr cUseableVars = GetUsableVars(numberOfUseableVariables);348 347 349 348 InitSearch(MaxGen, PgeRptEpoch, PgeRptCount, PgeArchiveCap, PeelCnt, EvalrCount, ZeroEpsilon, cInitMethod, cGrowMethod, sortType); 350 349 351 350 // cUsableVars: list of indices into independent variables 352 InitTreeParams(cRoots, cNodes, cNonTrig, cLeafs, cUseableVars, numberOfUseableVariables, MaxSize, MinSize, MaxDepth, MinDepth); 353 354 351 InitTreeParams(cRoots, cNodes, cNonTrig, cLeafs, numberOfUseableVariables, MaxSize, MinSize, MaxDepth, MinDepth); 352 355 353 InitProblem(cName, MaxIterations, HitRatio, 356 354 searchVar: 0, // SearchVar: index of dependent variables (this is always zero because we only have one target variable) … … 364 362 365 363 for (int iResult = 0; iResult < nResults; iResult++) { 366 int nobestpush = 0; //bool367 int bestNewMinError = 0; //bool368 int bestlen1 = 0;369 int bestlen2 = 0;370 364 int nCoeff = 0; 371 365 int testScore = 0; 372 366 373 IntPtr eqn = GetStepResult(out nobestpush, out bestNewMinError, out bestlen1, out bestlen2, outtestScore, out nCoeff);367 IntPtr eqn = GetStepResult(out testScore, out nCoeff); 374 368 string eqnStr = Marshal.PtrToStringAnsi(eqn); 375 369 … … 378 372 coeff[iCoeff] = GetCoeffResult(); 379 373 } 380 log.LogMessage("Push/Pop (" + iResult + ", " + bestlen1 + ", " + bestlen2 + ", " + testScore + ", noBestPush: " + (nobestpush > 0) + ", bestNewMin: " + (bestNewMinError > 0)+ ") " + eqnStr + " coeff: " + string.Join(" ", coeff));381 382 if (!string.IsNullOrEmpty(eqnStr) && (testScore < bestTestScore || bestNewMinError > 0)) {374 log.LogMessage("Push/Pop (" + iResult + ", " + testScore + ") " + eqnStr + " coeff: " + string.Join(" ", coeff)); 375 376 if (!string.IsNullOrEmpty(eqnStr) && (testScore < bestTestScore)) { 383 377 // update best quality 384 378 bestTestScore = testScore; … … 389 383 bestTestScoreRow.Values.Add(bestTestScoreResult.Value); // always add the current best test score to data row 390 384 curTestScoreRow.Values.Add(testScore); 391 len1Row.Values.Add(bestlen1);392 len2Row.Values.Add(bestlen2);393 385 } 394 386 … … 396 388 } 397 389 398 Marshal.FreeHGlobal(cUseableVars);399 390 Marshal.FreeHGlobal(trainData); 400 391 Marshal.FreeHGlobal(testData); … … 453 444 } 454 445 455 private static IntPtr GetUsableVars(int n) {456 long[] vars = new long[n];457 458 for (int i = 0; i < n; i++) {459 vars[i] = i;460 }461 462 IntPtr usableVars = Marshal.AllocHGlobal(sizeof(long) * n);463 Marshal.Copy(vars, 0, usableVars, n);464 465 return usableVars;466 }467 468 446 private static IntPtr GetData(IDataset ds, IEnumerable<string> variableNames, IEnumerable<int> rows, out int n) { 469 447
Note: See TracChangeset
for help on using the changeset viewer.