Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/12/09 14:05:33 (15 years ago)
Author:
gkronber
Message:

Improved dispatching mechanism. #419 (Refactor CEDMA plugins).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs

    r1151 r1216  
    5757      };
    5858
    59       var dataSetBindings = store.Query("?DataSet <"+Ontology.PredicateInstanceOf.Uri+"> <"+Ontology.TypeDataSet.Uri+"> .");
     59      var dataSetBindings = store.Query("?DataSet <" + Ontology.PredicateInstanceOf.Uri + "> <" + Ontology.TypeDataSet.Uri + "> .");
    6060
    6161      // no datasets => do nothing
     
    6565      // find and select all results for this dataset
    6666      var dataSetEntity = (Entity)dataSetBindings.Last().Get("DataSet");
    67       var targetVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("TargetVariable");
    68       var modelVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("Model");
    69       var modelMAPE = new HeuristicLab.CEDMA.DB.Interfaces.Variable("ModelMAPE");
    70 
    71       var query = "<" + dataSetEntity.Uri + "> <" + Ontology.PredicateHasModel.Uri + "> ?Model ." + Environment.NewLine +
    72         "?Model <" + Ontology.TargetVariable.Uri + "> ?TargetVariable ." + Environment.NewLine +
    73         "?Model <" + Ontology.ValidationMeanAbsolutePercentageError.Uri + "> ?ModelMAPE .";
    74 
    75 
    76 
    77       var bindings = store.Query(query);
    7867      DataSet dataSet = new DataSet(store, dataSetEntity);
    79       double[] utilization = new double[dataSet.Problem.AllowedTargetVariables.Count];
    80       int i = 0;
    81       int totalN = bindings.Count();
    82       foreach (int targetVariable in dataSet.Problem.AllowedTargetVariables) {
    83         var targetVarBindings = bindings.Where(x => (int)((Literal)x.Get("TargetVariable")).Value == targetVariable);
    84         if (targetVarBindings.Count() == 0) {
    85           utilization[i++] = double.PositiveInfinity;
    86         } else {
    87           double averageMape = targetVarBindings.Average(x => (double)((Literal)x.Get("ModelMAPE")).Value);
    88           double n = targetVarBindings.Count();
    89           utilization[i++] = -averageMape + Math.Sqrt(Math.Log(totalN) / n) * 0.1;
    90         }
    91       }
    92       int[] idx = Enumerable.Range(0, utilization.Length).ToArray();
    93       Array.Sort(utilization, idx);
    94       int nConfigurations = utilization.Length;
    95       for (int j = nConfigurations - 1; j > nConfigurations * 0.8; j--) {
    96         int targetVariable = dataSet.Problem.AllowedTargetVariables[idx[j]];
    97         IEngine engine = CreateEngine(dataSet.Problem, targetVariable);
    98         if (engine != null) {
    99           QueueJob(new Execution(dataSetEntity, engine, targetVariable));
    100         }
     68      Random random = new Random();
     69      int targetVariable = dataSet.Problem.AllowedInputVariables[random.Next(0, dataSet.Problem.AllowedInputVariables.Count)];
     70      string targetVariableName = dataSet.Problem.GetVariableName(targetVariable);
     71      Execution exec = CreateExecution(dataSet.Problem, targetVariable);
     72      if (exec != null) {
     73        exec.DataSetEntity = dataSetEntity;
     74        exec.TargetVariable = targetVariableName;
     75        QueueJob(exec);
    10176      }
    10277    }
     
    12297    }
    12398
    124     private IEngine CreateEngine(Problem problem, int targetVariable) {
     99    private Execution CreateExecution(Problem problem, int targetVariable) {
    125100      switch (problem.LearningTask) {
    126101        case LearningTask.Classification: return null;
    127102        case LearningTask.Regression: {
    128             return CreateStandardGp(problem, targetVariable).Engine;
     103            return CreateStandardGpExecution(problem, targetVariable, 100, 10);
    129104          }
    130105        case LearningTask.TimeSeries: return null;
     
    134109    }
    135110
    136     private StandardGP CreateStandardGp(Problem problem, int targetVariable) {
     111    private Execution CreateStandardGpExecution(Problem problem, int targetVariable, int maxTreeSize, int maxTreeHeight) {
    137112      ProblemInjector probInjector = new ProblemInjector(problem);
    138113      probInjector.TargetVariable = targetVariable;
    139114      StandardGP sgp = new StandardGP();
    140115      sgp.SetSeedRandomly = true;
    141       sgp.MaxGenerations = 300;
    142       sgp.PopulationSize = 10000;
     116      sgp.MaxGenerations = 2;
     117      sgp.PopulationSize = 100;
    143118      sgp.Elites = 1;
    144119      sgp.ProblemInjector = probInjector;
    145       return sgp;
     120      sgp.MaxTreeHeight = maxTreeHeight;
     121      sgp.MaxTreeSize = maxTreeSize;
     122      Execution exec = new Execution(sgp.Engine);
     123      exec.Description = "StandardGP - Medium Complexity";
     124      return exec;
    146125    }
    147126  }
Note: See TracChangeset for help on using the changeset viewer.