Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/26/19 00:20:12 (5 years ago)
Author:
hmaislin
Message:

#2929: Reorganized folder structure for make script, removed explicit marshalling, erased go-side logging

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/PGE.cs

    r16614 r16620  
    2525
    2626    [DllImport("go-pge.dll", EntryPoint = "addTestData", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    27     public static extern void AddTestData(IntPtr indepNames, IntPtr depndNames, IntPtr matrix, int nEntries);
     27    public static extern void AddTestData([MarshalAs(UnmanagedType.AnsiBStr)] string indepNames, [MarshalAs(UnmanagedType.AnsiBStr)] string depndNames, double[] matrix, int nEntries);
    2828
    2929    [DllImport("go-pge.dll", EntryPoint = "addTrainData", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    30     public static extern void AddTrainData(IntPtr indepNames, IntPtr depndNames, IntPtr matrix, int nEntries);
     30    public static extern void AddTrainData([MarshalAs(UnmanagedType.AnsiBStr)] string indepNames, [MarshalAs(UnmanagedType.AnsiBStr)] string depndNames, double[] matrix, int nEntries);
    3131
    3232    [DllImport("go-pge.dll", EntryPoint = "initSearch", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    33     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);
     33    public static extern void InitSearch(int maxGen, int pgeRptEpoch, int pgeRptCount, int pgeArchiveCap, int peelCnt, int evalrCount, double zeroEpsilon, [MarshalAs(UnmanagedType.AnsiBStr)] string initMethod, [MarshalAs(UnmanagedType.AnsiBStr)] string growMethod, int sortType);
    3434
    3535    [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, int numUsableVars, int maxSize, int minSize, int maxDepth, int minDepth);
     36    public static extern void InitTreeParams([MarshalAs(UnmanagedType.AnsiBStr)] string roots, [MarshalAs(UnmanagedType.AnsiBStr)] string nodes, [MarshalAs(UnmanagedType.AnsiBStr)] string nonTrig, [MarshalAs(UnmanagedType.AnsiBStr)] string leafs, int numUsableVars, int maxSize, int minSize, int maxDepth, int minDepth);
    3737
    3838    [DllImport("go-pge.dll", EntryPoint = "initProblem", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    39     public static extern void InitProblem(IntPtr name, int maxIter, double hitRatio, int searchVar, IntPtr ProblemTypeString, int numProcs);
     39    public static extern void InitProblem([MarshalAs(UnmanagedType.AnsiBStr)] string name, int maxIter, double hitRatio, int searchVar, [MarshalAs(UnmanagedType.AnsiBStr)] string ProblemTypeString, int numProcs);
    4040
    4141    [DllImport("go-pge.dll", EntryPoint = "stepW", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
     
    303303
    304304      //Constants
    305       int sortType = 0; // TODO what's sort type?
     305      int sortType = 0; // TODO what's sort type? //
     306      //1 = PESORT_PARETO_TRN_ERR
     307      //0 = PESORT_PARETO_TST_ERR
     308
    306309      string problemTypeString = "benchmark";
    307310      int numProc = 12;
     
    312315      var variables = problemData.AllowedInputVariables.Concat(new string[] { problemData.TargetVariable });
    313316      // no idea why the following are IntPtr, this should not be necessary for marshalling, it should be ok to just send the double[,]
    314       int nTrainData;
    315       int nTestData;
    316       IntPtr trainData = GetData(problemData.Dataset, variables, problemData.TrainingIndices, out nTrainData);
    317       IntPtr testData = GetData(problemData.Dataset, variables, problemData.TestIndices, out nTestData);
    318 
    319       nTrainData = Problem.ProblemData.TrainingPartition.Size;
    320       nTestData = Problem.ProblemData.TestPartition.Size;
     317     
     318      double[] trainData = GetData(problemData.Dataset, variables, problemData.TrainingIndices);
     319      double[] testData = GetData(problemData.Dataset, variables, problemData.TestIndices);
     320
     321      int nTrainData = Problem.ProblemData.TrainingPartition.Size;
     322      int nTestData = Problem.ProblemData.TestPartition.Size;
    321323
    322324      if (problemData.AllowedInputVariables.Any(iv => iv.Contains(" ")))
     
    325327      var inputVariableNames = string.Join(" ", problemData.AllowedInputVariables);
    326328
    327       IntPtr cIndepNames = Marshal.StringToHGlobalAnsi(inputVariableNames);
    328       IntPtr cDependentNames = Marshal.StringToHGlobalAnsi(problemData.TargetVariable);
    329       // Dependent- and Independentnames are the variables from the test/train data, e.g. from "Korns_02.trn" indep: x y z v w  dep: f(xs)
    330 
    331       IntPtr cInitMethod = Marshal.StringToHGlobalAnsi(InitMethod);
    332       IntPtr cGrowMethod = Marshal.StringToHGlobalAnsi(GrowMethod);
    333 
    334       IntPtr cRoots = Marshal.StringToHGlobalAnsi(Roots);
    335       IntPtr cNodes = Marshal.StringToHGlobalAnsi(Nodes);
    336       IntPtr cNonTrig = Marshal.StringToHGlobalAnsi(NonTrig);
    337       IntPtr cLeafs = Marshal.StringToHGlobalAnsi(Leafs);
    338 
    339       IntPtr cName = Marshal.StringToHGlobalAnsi(problemName);
    340       IntPtr cProblemTypeString = Marshal.StringToHGlobalAnsi(problemTypeString);
    341 
    342 
    343       AddTestData(cIndepNames, cDependentNames, testData, nTestData);
    344       AddTrainData(cIndepNames, cDependentNames, trainData, nTrainData);
     329      AddTestData(inputVariableNames, problemData.TargetVariable, testData, nTestData);
     330      AddTrainData(inputVariableNames, problemData.TargetVariable, trainData, nTrainData);
    345331
    346332      int numberOfUseableVariables = problemData.AllowedInputVariables.Count();
    347333
    348       InitSearch(MaxGen, PgeRptEpoch, PgeRptCount, PgeArchiveCap, PeelCnt, EvalrCount, ZeroEpsilon, cInitMethod, cGrowMethod, sortType);
     334      InitSearch(MaxGen, PgeRptEpoch, PgeRptCount, PgeArchiveCap, PeelCnt, EvalrCount, ZeroEpsilon, InitMethod, GrowMethod, sortType);
    349335
    350336      // cUsableVars: list of indices into independent variables
    351       InitTreeParams(cRoots, cNodes, cNonTrig, cLeafs, numberOfUseableVariables, MaxSize, MinSize, MaxDepth, MinDepth);
    352 
    353       InitProblem(cName, MaxIterations, HitRatio,
     337      InitTreeParams(Roots, Nodes, NonTrig, Leafs, numberOfUseableVariables, MaxSize, MinSize, MaxDepth, MinDepth);
     338
     339      InitProblem(Name, MaxIterations, HitRatio,
    354340        searchVar: 0,  // SearchVar: index of dependent variables (this is always zero because we only have one target variable)
    355         ProblemTypeString: cProblemTypeString, numProcs: numProc);
     341        ProblemTypeString: problemTypeString, numProcs: numProc);
    356342
    357343      var bestTestScore = int.MaxValue;
     
    387373        if (cancellationToken.IsCancellationRequested) break;
    388374      }
    389 
    390       Marshal.FreeHGlobal(trainData);
    391       Marshal.FreeHGlobal(testData);
    392 
    393       Marshal.FreeHGlobal(cIndepNames);
    394       Marshal.FreeHGlobal(cDependentNames);
    395 
    396       Marshal.FreeHGlobal(cInitMethod);
    397       Marshal.FreeHGlobal(cGrowMethod);
    398 
    399       Marshal.FreeHGlobal(cRoots);
    400       Marshal.FreeHGlobal(cNodes);
    401       Marshal.FreeHGlobal(cNonTrig);
    402       Marshal.FreeHGlobal(cLeafs);
    403 
    404       Marshal.FreeHGlobal(cName);
    405       Marshal.FreeHGlobal(cProblemTypeString);
    406375
    407376      // Results.Add(new Result("Execution time", new TimeSpanValue(this.ExecutionTime)));
     
    444413    }
    445414
    446     private static IntPtr GetData(IDataset ds, IEnumerable<string> variableNames, IEnumerable<int> rows, out int n) {
    447 
     415    private static double[] GetData(IDataset ds, IEnumerable<string> variableNames, IEnumerable<int> rows) {
    448416      var dim = variableNames.Count();
    449417      double[] val = new double[rows.Count() * dim];
     
    457425        r++;
    458426      }
    459 
    460       n = val.Length;
    461 
    462       // TODO: seems strange to marshal this explicitly, we can just send the data over to PGE
    463       IntPtr data = Marshal.AllocHGlobal(sizeof(double) * val.Length);
    464       Marshal.Copy(val, 0, data, val.Length);
    465 
    466       return data;
     427      return val;
    467428    }
    468429  }
Note: See TracChangeset for help on using the changeset viewer.