Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/15/09 14:01:47 (15 years ago)
Author:
gkronber
Message:

Moved common (not algorithm specific) model analyzer code (same operator tree in all regression/classification/time-series-prognosis engines) to HL.Modeling. #625, #705, #739.

Location:
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/DefaultStructureIdentificationOperators.cs

    r2351 r2356  
    3030
    3131namespace HeuristicLab.GP.StructureIdentification {
    32   public static class DefaultStructureIdentificationAlgorithmOperators {
     32  public static class DefaultStructureIdentificationOperators {
    3333    public static IOperator CreateFunctionLibraryInjector() {
    3434      CombinedOperator op = new CombinedOperator();
     
    3737      seq.AddSubOperator(new FunctionLibraryInjector());
    3838      seq.AddSubOperator(new HL3TreeEvaluatorInjector());
    39       op.OperatorGraph.AddOperator(seq);
    40       op.OperatorGraph.InitialOperator = seq;
    41       return op;
    42     }
    43 
    44     public static IOperator CreateProblemInjector() {
    45       CombinedOperator op = new CombinedOperator();
    46       op.Name = "ProblemInjector";
    47       SequentialProcessor seq = new SequentialProcessor();
    48 
    49       seq.AddSubOperator(new ProblemInjector());
    50       DatasetShuffler shuffler = new DatasetShuffler();
    51       shuffler.GetVariableInfo("ShuffleStart").ActualName = "TrainingSamplesStart";
    52       shuffler.GetVariableInfo("ShuffleEnd").ActualName = "TrainingSamplesEnd";
    53       seq.AddSubOperator(shuffler);
    5439      op.OperatorGraph.AddOperator(seq);
    5540      op.OperatorGraph.InitialOperator = seq;
     
    10590    }
    10691
    107     public static IOperator CreatePostProcessingOperator() {
    108       CombinedOperator op = new CombinedOperator();
    109       op.Name = "ModelAnalyser";
     92
     93    public static IOperator CreatePreparationForPostProcessingOperator() {
    11094      SequentialProcessor seq = new SequentialProcessor();
    11195      LeftReducer cleanUp = new LeftReducer();
     
    145129      testEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
    146130      testEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    147       #endregion
    148       #region MSE
    149       SimpleMSEEvaluator trainingMseEvaluator = new SimpleMSEEvaluator();
    150       trainingMseEvaluator.Name = "TrainingMseEvaluator";
    151       trainingMseEvaluator.GetVariableInfo("MSE").ActualName = "TrainingMSE";
    152       trainingMseEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
    153       SimpleMSEEvaluator validationMseEvaluator = new SimpleMSEEvaluator();
    154       validationMseEvaluator.Name = "ValidationMseEvaluator";
    155       validationMseEvaluator.GetVariableInfo("MSE").ActualName = "ValidationMSE";
    156       validationMseEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
    157       SimpleMSEEvaluator testMseEvaluator = new SimpleMSEEvaluator();
    158       testMseEvaluator.Name = "TestMseEvaluator";
    159       testMseEvaluator.GetVariableInfo("MSE").ActualName = "TestMSE";
    160       testMseEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
    161       #endregion
    162       #region MAPE
    163       SimpleMeanAbsolutePercentageErrorEvaluator trainingMapeEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator();
    164       trainingMapeEvaluator.Name = "TrainingMapeEvaluator";
    165       trainingMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TrainingMAPE";
    166       trainingMapeEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
    167       SimpleMeanAbsolutePercentageErrorEvaluator validationMapeEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator();
    168       validationMapeEvaluator.Name = "ValidationMapeEvaluator";
    169       validationMapeEvaluator.GetVariableInfo("MAPE").ActualName = "ValidationMAPE";
    170       validationMapeEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
    171       SimpleMeanAbsolutePercentageErrorEvaluator testMapeEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator();
    172       testMapeEvaluator.Name = "TestMapeEvaluator";
    173       testMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TestMAPE";
    174       testMapeEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
    175       #endregion
    176       #region MAPRE
    177       SimpleMeanAbsolutePercentageOfRangeErrorEvaluator trainingMapreEvaluator = new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator();
    178       trainingMapreEvaluator.Name = "TrainingMapreEvaluator";
    179       trainingMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "TrainingMAPRE";
    180       trainingMapreEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
    181       SimpleMeanAbsolutePercentageOfRangeErrorEvaluator validationMapreEvaluator = new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator();
    182       validationMapreEvaluator.Name = "ValidationMapreEvaluator";
    183       validationMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "ValidationMAPRE";
    184       validationMapreEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
    185       SimpleMeanAbsolutePercentageOfRangeErrorEvaluator testMapreEvaluator = new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator();
    186       testMapreEvaluator.Name = "TestMapreEvaluator";
    187       testMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "TestMAPRE";
    188       testMapreEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
    189       #endregion MAPRE
    190       #region R2
    191       SimpleR2Evaluator trainingR2Evaluator = new SimpleR2Evaluator();
    192       trainingR2Evaluator.Name = "TrainingR2Evaluator";
    193       trainingR2Evaluator.GetVariableInfo("R2").ActualName = "TrainingR2";
    194       trainingR2Evaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
    195       SimpleR2Evaluator validationR2Evaluator = new SimpleR2Evaluator();
    196       validationR2Evaluator.Name = "ValidationR2Evaluator";
    197       validationR2Evaluator.GetVariableInfo("R2").ActualName = "ValidationR2";
    198       validationR2Evaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
    199       SimpleR2Evaluator testR2Evaluator = new SimpleR2Evaluator();
    200       testR2Evaluator.Name = "TestR2Evaluator";
    201       testR2Evaluator.GetVariableInfo("R2").ActualName = "TestR2";
    202       testR2Evaluator.GetVariableInfo("Values").ActualName = "TestValues";
    203       #endregion
    204       #region VAF
    205       SimpleVarianceAccountedForEvaluator trainingVAFEvaluator = new SimpleVarianceAccountedForEvaluator();
    206       trainingVAFEvaluator.Name = "TrainingVAFEvaluator";
    207       trainingVAFEvaluator.GetVariableInfo("VAF").ActualName = "TrainingVAF";
    208       trainingVAFEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
    209       SimpleVarianceAccountedForEvaluator validationVAFEvaluator = new SimpleVarianceAccountedForEvaluator();
    210       validationVAFEvaluator.Name = "ValidationVAFEvaluator";
    211       validationVAFEvaluator.GetVariableInfo("VAF").ActualName = "ValidationVAF";
    212       validationVAFEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
    213       SimpleVarianceAccountedForEvaluator testVAFEvaluator = new SimpleVarianceAccountedForEvaluator();
    214       testVAFEvaluator.Name = "TestVAFEvaluator";
    215       testVAFEvaluator.GetVariableInfo("VAF").ActualName = "TestVAF";
    216       testVAFEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
    217       #endregion
    218 
    219131      solutionProc.AddSubOperator(evaluatorInjector);
    220132      solutionProc.AddSubOperator(trainingEvaluator);
    221133      solutionProc.AddSubOperator(validationEvaluator);
    222134      solutionProc.AddSubOperator(testEvaluator);
    223       solutionProc.AddSubOperator(trainingMseEvaluator);
    224       solutionProc.AddSubOperator(validationMseEvaluator);
    225       solutionProc.AddSubOperator(testMseEvaluator);
    226       solutionProc.AddSubOperator(trainingMapeEvaluator);
    227       solutionProc.AddSubOperator(validationMapeEvaluator);
    228       solutionProc.AddSubOperator(testMapeEvaluator);
    229       solutionProc.AddSubOperator(trainingMapreEvaluator);
    230       solutionProc.AddSubOperator(validationMapreEvaluator);
    231       solutionProc.AddSubOperator(testMapreEvaluator);
    232       solutionProc.AddSubOperator(trainingR2Evaluator);
    233       solutionProc.AddSubOperator(validationR2Evaluator);
    234       solutionProc.AddSubOperator(testR2Evaluator);
    235       solutionProc.AddSubOperator(trainingVAFEvaluator);
    236       solutionProc.AddSubOperator(validationVAFEvaluator);
    237       solutionProc.AddSubOperator(testVAFEvaluator);
     135      #endregion
    238136
    239137      #region variable impacts
     
    244142      predictorBuilder.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    245143
    246       VariableEvaluationImpactCalculator evaluationImpactCalculator = new VariableEvaluationImpactCalculator();
    247       evaluationImpactCalculator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
    248       evaluationImpactCalculator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
    249       VariableQualityImpactCalculator qualityImpactCalculator = new VariableQualityImpactCalculator();
    250       qualityImpactCalculator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
    251       qualityImpactCalculator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
    252 
    253144      solutionProc.AddSubOperator(namesExtractor);
    254145      solutionProc.AddSubOperator(predictorBuilder);
    255       solutionProc.AddSubOperator(evaluationImpactCalculator);
    256       solutionProc.AddSubOperator(qualityImpactCalculator);
    257146      #endregion
    258147
    259       op.OperatorGraph.AddOperator(seq);
    260       op.OperatorGraph.InitialOperator = seq;
    261       return op;
     148      return seq;
    262149    }
    263150
    264     public static IAnalyzerModel CreateGPModel(IScope bestModelScope) {
    265       IAnalyzerModel model = new AnalyzerModel();
    266       model.Predictor = bestModelScope.GetVariableValue<IPredictor>("Predictor", true);
    267       Dataset ds = bestModelScope.GetVariableValue<Dataset>("Dataset", true);
    268       model.Dataset = ds;
    269       model.TargetVariable = ds.GetVariableName(bestModelScope.GetVariableValue<IntData>("TargetVariable", true).Data);
    270       model.TrainingSamplesStart = bestModelScope.GetVariableValue<IntData>("TrainingSamplesStart", true).Data;
    271       model.TrainingSamplesEnd = bestModelScope.GetVariableValue<IntData>("TrainingSamplesEnd", true).Data;
    272       model.ValidationSamplesStart = bestModelScope.GetVariableValue<IntData>("ValidationSamplesStart", true).Data;
    273       model.ValidationSamplesEnd = bestModelScope.GetVariableValue<IntData>("ValidationSamplesEnd", true).Data;
    274       model.TestSamplesStart = bestModelScope.GetVariableValue<IntData>("TestSamplesStart", true).Data;
    275       model.TestSamplesEnd = bestModelScope.GetVariableValue<IntData>("TestSamplesEnd", true).Data;
    276 
    277       model.SetResult("TrainingMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("TrainingMSE", false).Data);
    278       model.SetResult("ValidationMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("ValidationMSE", false).Data);
    279       model.SetResult("TestMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("TestMSE", false).Data);
    280       model.SetResult("TrainingCoefficientOfDetermination", bestModelScope.GetVariableValue<DoubleData>("TrainingR2", false).Data);
    281       model.SetResult("ValidationCoefficientOfDetermination", bestModelScope.GetVariableValue<DoubleData>("ValidationR2", false).Data);
    282       model.SetResult("TestCoefficientOfDetermination", bestModelScope.GetVariableValue<DoubleData>("TestR2", false).Data);
    283       model.SetResult("TrainingMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("TrainingMAPE", false).Data);
    284       model.SetResult("ValidationMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("ValidationMAPE", false).Data);
    285       model.SetResult("TestMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("TestMAPE", false).Data);
    286       model.SetResult("TrainingMeanAbsolutePercentageOfRangeError", bestModelScope.GetVariableValue<DoubleData>("TrainingMAPRE", false).Data);
    287       model.SetResult("ValidationMeanAbsolutePercentageOfRangeError", bestModelScope.GetVariableValue<DoubleData>("ValidationMAPRE", false).Data);
    288       model.SetResult("TestMeanAbsolutePercentageOfRangeError", bestModelScope.GetVariableValue<DoubleData>("TestMAPRE", false).Data);
    289       model.SetResult("TrainingVarianceAccountedFor", bestModelScope.GetVariableValue<DoubleData>("TrainingVAF", false).Data);
    290       model.SetResult("ValidationVarianceAccountedFor", bestModelScope.GetVariableValue<DoubleData>("ValidationVAF", false).Data);
    291       model.SetResult("TestVarianceAccountedFor", bestModelScope.GetVariableValue<DoubleData>("TestVAF", false).Data);
    292 
    293       model.SetMetaData("EvaluatedSolutions", bestModelScope.GetVariableValue<DoubleData>("EvaluatedSolutions", true).Data);
    294       IGeneticProgrammingModel gpModel = bestModelScope.GetVariableValue<IGeneticProgrammingModel>("FunctionTree", true);
     151    public static void PopulateAnalyzerModel(IScope bestModelScope, IAnalyzerModel model) {
     152      model.SetMetaData("EvaluatedSolutions", bestModelScope.GetVariableValue<DoubleData>("EvaluatedSolutions", false).Data);
     153      IGeneticProgrammingModel gpModel = bestModelScope.GetVariableValue<IGeneticProgrammingModel>("FunctionTree", false);
    295154      model.SetMetaData("TreeSize", gpModel.Size);
    296155      model.SetMetaData("TreeHeight", gpModel.Height);
    297 
    298       ItemList evaluationImpacts = bestModelScope.GetVariableValue<ItemList>("VariableEvaluationImpacts", false);
    299       ItemList qualityImpacts = bestModelScope.GetVariableValue<ItemList>("VariableQualityImpacts", false);
    300       foreach (ItemList row in evaluationImpacts) {
    301         string variableName = ((StringData)row[0]).Data;
    302         double impact = ((DoubleData)row[1]).Data;
    303         model.SetVariableEvaluationImpact(variableName, impact);
    304         model.AddInputVariable(variableName);
    305       }
    306       foreach (ItemList row in qualityImpacts) {
    307         string variableName = ((StringData)row[0]).Data;
    308         double impact = ((DoubleData)row[1]).Data;
    309         model.SetVariableQualityImpact(variableName, impact);
    310         model.AddInputVariable(variableName);
    311       }
    312 
    313       return model;
    314156    }
    315157  }
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/OffspringSelectionGP.cs

    r2344 r2356  
    7777
    7878    protected override IOperator CreateFunctionLibraryInjector() {
    79       return DefaultStructureIdentificationAlgorithmOperators.CreateFunctionLibraryInjector();
     79      return DefaultStructureIdentificationOperators.CreateFunctionLibraryInjector();
    8080    }
    8181
    8282    protected override IOperator CreateProblemInjector() {
    83       return DefaultStructureIdentificationAlgorithmOperators.CreateProblemInjector();
     83      return DefaultRegressionOperators.CreateProblemInjector();
    8484    }
    8585
    8686    protected override IOperator CreateInitialPopulationEvaluator() {
    87       return DefaultStructureIdentificationAlgorithmOperators.CreateInitialPopulationEvaluator();
     87      return DefaultStructureIdentificationOperators.CreateInitialPopulationEvaluator();
    8888    }
    8989
    9090    protected override IOperator CreateEvaluationOperator() {
    91       return DefaultStructureIdentificationAlgorithmOperators.CreateEvaluator();
     91      return DefaultStructureIdentificationOperators.CreateEvaluator();
    9292    }
    9393
    9494
    9595    protected override IOperator CreateGenerationStepHook() {
    96       return DefaultStructureIdentificationAlgorithmOperators.CreateGenerationStepHook();
     96      return DefaultStructureIdentificationOperators.CreateGenerationStepHook();
    9797    }
    9898
     
    133133
    134134    protected override IOperator CreatePostProcessingOperator() {
    135       return DefaultStructureIdentificationAlgorithmOperators.CreatePostProcessingOperator();
     135      CombinedOperator op = new CombinedOperator();
     136      op.Name = "ModelAnalyser";
     137      SequentialProcessor seq = new SequentialProcessor();
     138      seq.AddSubOperator(DefaultStructureIdentificationOperators.CreatePreparationForPostProcessingOperator());
     139
     140      UniformSequentialSubScopesProcessor subScopesProc = new UniformSequentialSubScopesProcessor();
     141      SequentialProcessor solutionProc = new SequentialProcessor();
     142      solutionProc.AddSubOperator(CreateModelAnalyzerOperator());
     143
     144      subScopesProc.AddSubOperator(solutionProc);
     145      seq.AddSubOperator(subScopesProc);
     146
     147      op.OperatorGraph.AddOperator(seq);
     148      op.OperatorGraph.InitialOperator = seq;
     149      return op;
     150    }
     151
     152    protected virtual IOperator CreateModelAnalyzerOperator() {
     153      return DefaultRegressionOperators.CreatePostProcessingOperator();
    136154    }
    137155
     
    148166    protected virtual IAnalyzerModel CreateGPModel() {
    149167      IScope bestModelScope = Engine.GlobalScope.SubScopes[0];
    150       IAnalyzerModel model = DefaultStructureIdentificationAlgorithmOperators.CreateGPModel(bestModelScope);
    151       model.SetMetaData("SelectionPressure", bestModelScope.GetVariableValue<DoubleData>("SelectionPressure", true).Data);
     168      var model = new AnalyzerModel();
     169
     170      model.SetMetaData("SelectionPressure", bestModelScope.GetVariableValue<DoubleData>("SelectionPressure", false).Data);
     171      DefaultStructureIdentificationOperators.PopulateAnalyzerModel(bestModelScope, model);
     172      DefaultRegressionOperators.PopulateAnalyzerModel(bestModelScope, model);
     173
    152174      return model;
    153175    }
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/StandardGP.cs

    r2344 r2356  
    7878
    7979    protected override IOperator CreateFunctionLibraryInjector() {
    80       return DefaultStructureIdentificationAlgorithmOperators.CreateFunctionLibraryInjector();
     80      return DefaultStructureIdentificationOperators.CreateFunctionLibraryInjector();
    8181    }
    8282
    8383    protected override IOperator CreateProblemInjector() {
    84       return DefaultStructureIdentificationAlgorithmOperators.CreateProblemInjector();
     84      return DefaultRegressionOperators.CreateProblemInjector();
    8585    }
    8686
    8787    protected override IOperator CreateInitialPopulationEvaluator() {
    88       return DefaultStructureIdentificationAlgorithmOperators.CreateInitialPopulationEvaluator();
     88      return DefaultStructureIdentificationOperators.CreateInitialPopulationEvaluator();
    8989    }
    9090
    9191    protected override IOperator CreateEvaluationOperator() {
    92       return DefaultStructureIdentificationAlgorithmOperators.CreateEvaluator();
     92      return DefaultStructureIdentificationOperators.CreateEvaluator();
    9393    }
    9494
    9595
    9696    protected override IOperator CreateGenerationStepHook() {
    97       return DefaultStructureIdentificationAlgorithmOperators.CreateGenerationStepHook();
     97      return DefaultStructureIdentificationOperators.CreateGenerationStepHook();
    9898    }
    9999
     
    132132
    133133    protected override IOperator CreatePostProcessingOperator() {
    134       return DefaultStructureIdentificationAlgorithmOperators.CreatePostProcessingOperator();
     134      CombinedOperator op = new CombinedOperator();
     135      op.Name = "ModelAnalyser";
     136      SequentialProcessor seq = new SequentialProcessor();
     137      seq.AddSubOperator(DefaultStructureIdentificationOperators.CreatePreparationForPostProcessingOperator());
     138
     139      UniformSequentialSubScopesProcessor subScopesProc = new UniformSequentialSubScopesProcessor();
     140      SequentialProcessor solutionProc = new SequentialProcessor();
     141      solutionProc.AddSubOperator(CreateModelAnalyzerOperator());
     142
     143      subScopesProc.AddSubOperator(solutionProc);
     144      seq.AddSubOperator(subScopesProc);
     145
     146      op.OperatorGraph.AddOperator(seq);
     147      op.OperatorGraph.InitialOperator = seq;
     148      return op;
     149    }
     150
     151    protected virtual IOperator CreateModelAnalyzerOperator() {
     152      return DefaultRegressionOperators.CreatePostProcessingOperator();
    135153    }
    136154
     
    147165    protected virtual IAnalyzerModel CreateGPModel() {
    148166      IScope bestModelScope = Engine.GlobalScope.SubScopes[0];
    149       IAnalyzerModel model = DefaultStructureIdentificationAlgorithmOperators.CreateGPModel(bestModelScope);
     167      IAnalyzerModel model = new AnalyzerModel();
     168      DefaultStructureIdentificationOperators.PopulateAnalyzerModel(bestModelScope, model);
     169      DefaultRegressionOperators.PopulateAnalyzerModel(bestModelScope, model);
    150170      return model;
    151171    }
Note: See TracChangeset for help on using the changeset viewer.