Changeset 16197 for branches/2929_PrioritizedGrammarEnumeration
- Timestamp:
- 09/28/18 17:05:11 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/PGE.cs
r16196 r16197 18 18 public unsafe class PGE : BasicAlgorithm { 19 19 20 [DllImport("go-pge.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]21 public static extern void addTestData(IntPtr indepNames, IntPtr depndNames, IntPtr matrix, int nEntries);20 [DllImport("go-pge.dll", EntryPoint = "addTestData", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 21 public static extern void AddTestData(IntPtr indepNames, IntPtr depndNames, IntPtr matrix, int nEntries); 22 22 23 [DllImport("go-pge.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]24 public static extern void addTrainData(IntPtr indepNames, IntPtr depndNames, IntPtr matrix, int nEntries);23 [DllImport("go-pge.dll", EntryPoint = "addTrainData", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 24 public static extern void AddTrainData(IntPtr indepNames, IntPtr depndNames, IntPtr matrix, int nEntries); 25 25 26 [DllImport("go-pge.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]27 public static extern void initSearch(int maxGen, int pgeRptEpoch, int pgeRptCount, int pgeArchiveCap, int peelCnt, int evalrCount, double zeroEpsilon, IntPtr initMethod, IntPtr growMethod, int sortType);26 [DllImport("go-pge.dll", EntryPoint = "initSearch", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 27 public static extern void InitSearch(int maxGen, int pgeRptEpoch, int pgeRptCount, int pgeArchiveCap, int peelCnt, int evalrCount, double zeroEpsilon, IntPtr initMethod, IntPtr growMethod, int sortType); 28 28 29 [DllImport("go-pge.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]30 public static extern void initTreeParams(IntPtr Roots, IntPtr Nodes, IntPtr NonTrig, IntPtr Leafs, IntPtr UsableVars, int UsableVarsN, int MaxSize, int MinSize, int MaxDepth, int MinDepth);29 [DllImport("go-pge.dll", EntryPoint = "initTreeParams", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 30 public static extern void InitTreeParams(IntPtr Roots, IntPtr Nodes, IntPtr NonTrig, IntPtr Leafs, IntPtr UsableVars, int UsableVarsN, int MaxSize, int MinSize, int MaxDepth, int MinDepth); 31 31 32 [DllImport("go-pge.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]33 public static extern void initProblem(IntPtr Name, int MaxIter, double HitRatio, int SearchVar, IntPtr ProblemTypeString, int numProcs);32 [DllImport("go-pge.dll", EntryPoint = "initProblem", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 33 public static extern void InitProblem(IntPtr Name, int MaxIter, double HitRatio, int SearchVar, IntPtr ProblemTypeString, int numProcs); 34 34 35 [DllImport("go-pge.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]36 public static extern void stepW();35 [DllImport("go-pge.dll", EntryPoint = "stepW", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 36 public static extern void StepW(); 37 37 38 [DllImport("go-pge.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]39 public static extern IntPtr getStepResult(out Int64 nobestpush, out Int64 bestnewminerr, out Int64 bestlen1, out Int64 bestlen2, out Int64 testscore, out IntPtr coeff, out Int64 nCoeff);38 [DllImport("go-pge.dll", EntryPoint = "getStepResult", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 39 public static extern IntPtr GetStepResult(out Int64 nobestpush, out Int64 bestnewminerr, out Int64 bestlen1, out Int64 bestlen2, out Int64 testscore, out IntPtr coeff, out Int64 nCoeff); 40 40 41 41 public override Type ProblemType { get { return typeof(RegressionProblem); } } … … 285 285 } 286 286 287 // Persistence uses this ctor to improve deserialization efficiency. 288 // If we would use the default ctor instead this would completely initialize the object (e.g. creating parameters) 289 // even though the data is later overwritten by the stored data. 287 290 288 [StorableConstructor] 291 289 public PGE(bool deserializing) : base(deserializing) { } 292 290 293 // Each clonable item must have a cloning ctor (deep cloning, the cloner is used to handle cyclic object references) 294 public PGE(PGE original, Cloner cloner) : base(original, cloner) { 295 // Don't forget to call the cloning ctor of the base class 296 // TODO: if this class has fields then they need to be cloned here 291 292 public PGE(PGE original, Cloner cloner) : base(original, cloner) { 293 // nothing to clone 297 294 } 298 295 … … 303 300 protected override void Run(CancellationToken cancellationToken) { 304 301 302 // TODO: the following is potentially problematic for other go processes run on the same machine at the same time 305 303 Environment.SetEnvironmentVariable("GOGC", "off"); 306 304 Environment.SetEnvironmentVariable("GODEBUG", "cgocheck=0"); 307 305 Environment.SetEnvironmentVariable("CGO_ENABLED", "1"); 308 306 309 //Parameter310 int MaxIter = MaxIterations;311 string indepNames = IndependedNames;312 string depndNames = DependedNames;313 307 314 308 int nTrainData = 200; //Woher ? … … 321 315 string Name = "Korns_02"; 322 316 323 //Calcs324 int indepLen = indepNames.Split(' ').Length;325 int depLen = depndNames.Split(' ').Length;326 317 327 IntPtr TrainData = GetTrainData(indepLen, depLen, nTrainData);328 IntPtr TestData = GetTestData(indepLen, depLen, nTestData);318 int indepLen = IndependedNames.Split(' ').Length; 319 int depLen = DependedNames.Split(' ').Length; 329 320 330 IntPtr CindepNames = Marshal.StringToHGlobalAnsi(indepNames);331 IntPtr CdepndNames = Marshal.StringToHGlobalAnsi(depndNames);321 IntPtr trainData = GetTrainData(indepLen, depLen, nTrainData); 322 IntPtr testData = GetTestData(indepLen, depLen, nTestData); 332 323 333 IntPtr CinitMethod = Marshal.StringToHGlobalAnsi(InitMethod);334 IntPtr CgrowMethod = Marshal.StringToHGlobalAnsi(GrowMethod);324 IntPtr cIndepNames = Marshal.StringToHGlobalAnsi(IndependedNames); 325 IntPtr cDependentNames = Marshal.StringToHGlobalAnsi(DependedNames); 335 326 336 IntPtr Croots = Marshal.StringToHGlobalAnsi(Roots); 337 IntPtr Cnodes = Marshal.StringToHGlobalAnsi(Nodes); 338 IntPtr CnonTrig = Marshal.StringToHGlobalAnsi(NonTrig); 339 IntPtr Cleafs = Marshal.StringToHGlobalAnsi(Leafs); 327 IntPtr cInitMethod = Marshal.StringToHGlobalAnsi(InitMethod); 328 IntPtr cGrowMethod = Marshal.StringToHGlobalAnsi(GrowMethod); 340 329 341 IntPtr Cname = Marshal.StringToHGlobalAnsi(Name); 342 IntPtr CproblemTypeString = Marshal.StringToHGlobalAnsi(ProblemTypeString); 330 IntPtr cRoots = Marshal.StringToHGlobalAnsi(Roots); 331 IntPtr cNodes = Marshal.StringToHGlobalAnsi(Nodes); 332 IntPtr cNonTrig = Marshal.StringToHGlobalAnsi(NonTrig); 333 IntPtr cLeafs = Marshal.StringToHGlobalAnsi(Leafs); 334 335 IntPtr cName = Marshal.StringToHGlobalAnsi(Name); 336 IntPtr cProblemTypeString = Marshal.StringToHGlobalAnsi(ProblemTypeString); 343 337 344 338 345 Console.WriteLine("AddTrainData"); 346 addTestData(CindepNames, CdepndNames, TestData, nTestData); 339 AddTestData(cIndepNames, cDependentNames, testData, nTestData); 347 340 348 Console.WriteLine("AddTestData"); 349 addTrainData(CindepNames, CdepndNames, TrainData, nTrainData); 341 AddTrainData(cIndepNames, cDependentNames, trainData, nTrainData); 350 342 351 343 IntPtr UsableVars = GetUsableVars(NumberOfUseableVariables); 352 344 353 Console.WriteLine("InitSearch"); 354 initSearch(MaxGen, PgeRptEpoch, PgeRptCount, PgeArchiveCap, PeelCnt, EvalrCount, ZeroEpsilon, CinitMethod, CgrowMethod, SortType); 345 InitSearch(MaxGen, PgeRptEpoch, PgeRptCount, PgeArchiveCap, PeelCnt, EvalrCount, ZeroEpsilon, cInitMethod, cGrowMethod, SortType); 355 346 356 Console.WriteLine("InitTree"); 357 initTreeParams(Croots, Cnodes, CnonTrig, Cleafs, UsableVars, NumberOfUseableVariables, MaxSize, MinSize, MaxDepth, MinDepth); 347 InitTreeParams(cRoots, cNodes, cNonTrig, cLeafs, UsableVars, NumberOfUseableVariables, MaxSize, MinSize, MaxDepth, MinDepth); 358 348 359 Console.WriteLine("InitProblem"); 360 initProblem(Cname, MaxIter, HitRatio, SearchVar, CproblemTypeString, NumProcs); 349 InitProblem(cName, MaxIterations, HitRatio, SearchVar, cProblemTypeString, NumProcs); 361 350 362 Console.WriteLine("Finished Init");363 351 364 352 var curItersItem = new IntValue(); … … 368 356 Marshal.Copy(coeffmem, 0, Coeff, NumberOfUseableVariables); 369 357 370 for (int iter = 1; iter <= MaxIter ; iter++) {358 for (int iter = 1; iter <= MaxIterations; iter++) { 371 359 curItersItem.Value = iter; 372 360 373 361 Console.WriteLine("Step " + iter); 374 stepW();362 StepW(); 375 363 376 364 for (int iPeel = 0; iPeel < PeelCnt; iPeel++) { … … 382 370 Int64 TestScore = 0; 383 371 384 IntPtr eqn = getStepResult(out nobestpush, out bestnewminerr, out bestlen1, out bestlen2, out TestScore, out Coeff, out nCoeff);372 IntPtr eqn = GetStepResult(out nobestpush, out bestnewminerr, out bestlen1, out bestlen2, out TestScore, out Coeff, out nCoeff); 385 373 386 374 string eqnStr = Marshal.PtrToStringAnsi(eqn); … … 418 406 //Marshal.FreeHGlobal(CproblemTypeString); 419 407 //Marshal.FreeHGlobal(Cname); 420 Results.Add(new Result("Execution time", new TimeSpanValue(this.ExecutionTime))); 408 // done anyway? 409 // Results.Add(new Result("Execution time", new TimeSpanValue(this.ExecutionTime))); 421 410 } 422 411
Note: See TracChangeset
for help on using the changeset viewer.