Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/03/09 17:48:50 (15 years ago)
Author:
gkronber
Message:

created a branch for #720

Location:
branches/gp-algorithms-refactoring-#720
Files:
7 added
10 copied

Legend:

Unmodified
Added
Removed
  • branches/gp-algorithms-refactoring-#720/sources/HeuristicLab.GP.Algorithms/3.2/AlgorithmBase.cs

    r2328 r2331  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
    27 using HeuristicLab.DataAnalysis;
    2827using HeuristicLab.Evolutionary;
    29 using HeuristicLab.GP.Interfaces;
    3028using HeuristicLab.Logging;
    31 using HeuristicLab.Modeling;
    3229using HeuristicLab.Operators;
    3330using HeuristicLab.Random;
    3431using HeuristicLab.Selection;
    35 using HeuristicLab.Operators.Programmable;
    36 
    37 namespace HeuristicLab.GP.StructureIdentification {
    38   public abstract class AlgorithmBase : ItemBase, IAlgorithm, IStochasticAlgorithm {
     32using HeuristicLab.GP.Operators;
     33
     34namespace HeuristicLab.GP.Algorithms {
     35  public abstract class AlgorithmBase : ItemBase {
    3936    public virtual string Name { get { return "GP"; } }
    4037    public virtual string Description { get { return "TODO"; } }
    41 
    42     public abstract Dataset Dataset { get; set; }
    43     public abstract int TargetVariable { get; set; }
    4438
    4539    public virtual double MutationRate {
     
    7165    }
    7266
    73     private IAnalyzerModel model;
    74     public virtual IAnalyzerModel Model {
    75       get {
    76         if (!engine.Terminated) throw new InvalidOperationException("The algorithm is still running. Wait until the algorithm is terminated to retrieve the result.");
    77         if (model == null) {
    78           IScope bestModelScope = engine.GlobalScope.SubScopes[0];
    79           model = CreateGPModel(bestModelScope);
    80         }
    81         return model;
    82       }
    83     }
    84 
    8567    public virtual int Elites {
    8668      get { return GetVariableInjector().GetVariable("Elites").GetValue<IntData>().Data; }
     
    10183      get { return GetVariableInjector().GetVariable("Parents").GetValue<IntData>().Data; }
    10284      set { GetVariableInjector().GetVariable("Parents").GetValue<IntData>().Data = value; }
    103     }
    104 
    105     public virtual bool UseEstimatedTargetValue {
    106       get { return GetVariableInjector().GetVariable("UseEstimatedTargetValue").GetValue<BoolData>().Data; }
    107       set { GetVariableInjector().GetVariable("UseEstimatedTargetValue").GetValue<BoolData>().Data = value; }
    10885    }
    10986
     
    128105      MaxTreeHeight = 10;
    129106      Parents = 2000;
    130       UseEstimatedTargetValue = false;
    131107    }
    132108
     
    141117
    142118      IOperator globalInjector = CreateGlobalInjector();
    143       IOperator treeEvaluatorInjector = new HL2TreeEvaluatorInjector();
    144119      IOperator initialization = CreateInitialization();
    145120      IOperator funLibInjector = CreateFunctionLibraryInjector();
     
    149124
    150125      IOperator treeCreator = CreateTreeCreator();
    151 
    152       MeanSquaredErrorEvaluator evaluator = new MeanSquaredErrorEvaluator();
    153       evaluator.GetVariableInfo("MSE").ActualName = "Quality";
    154       evaluator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    155       evaluator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    156       evaluator.Name = "Evaluator";
    157126
    158127      IOperator crossover = CreateCrossover();
     
    165134      seq.AddSubOperator(problemInjector);
    166135      seq.AddSubOperator(globalInjector);
    167       seq.AddSubOperator(treeEvaluatorInjector);
    168136      seq.AddSubOperator(funLibInjector);
    169137      seq.AddSubOperator(initialization);
    170138      seq.AddSubOperator(mainLoop);
    171139      seq.AddSubOperator(cleanUp);
    172       seq.AddSubOperator(CreateModelAnalysisOperator());
    173140
    174141      initialization.AddSubOperator(treeCreator);
    175       initialization.AddSubOperator(evaluator);
    176142
    177143      mainLoop.AddSubOperator(selector);
     
    185151    }
    186152
    187     protected internal virtual IOperator CreateModelAnalysisOperator() {
    188       CombinedOperator op = new CombinedOperator();
    189       SequentialProcessor seq = new SequentialProcessor();
    190       SolutionExtractor extractor = new SolutionExtractor();
    191       extractor.GetVariableInfo("Scope").ActualName = "BestValidationSolution";
    192       SequentialSubScopesProcessor seqSubScopeProc = new SequentialSubScopesProcessor();
    193       SequentialProcessor solutionProc = new SequentialProcessor();
    194 
    195       seq.AddSubOperator(extractor);
    196       seq.AddSubOperator(seqSubScopeProc);
    197       seqSubScopeProc.AddSubOperator(solutionProc);
    198 
    199       HL2TreeEvaluatorInjector evaluatorInjector = new HL2TreeEvaluatorInjector();
    200       evaluatorInjector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(1000.0)));
    201       evaluatorInjector.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    202 
    203       #region MSE
    204       MeanSquaredErrorEvaluator trainingMseEvaluator = new MeanSquaredErrorEvaluator();
    205       trainingMseEvaluator.Name = "TrainingMseEvaluator";
    206       trainingMseEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    207       trainingMseEvaluator.GetVariableInfo("MSE").ActualName = "TrainingMSE";
    208       trainingMseEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
    209       trainingMseEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
    210       MeanSquaredErrorEvaluator validationMseEvaluator = new MeanSquaredErrorEvaluator();
    211       validationMseEvaluator.Name = "ValidationMseEvaluator";
    212       validationMseEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    213       validationMseEvaluator.GetVariableInfo("MSE").ActualName = "ValidationMSE";
    214       validationMseEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    215       validationMseEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    216       MeanSquaredErrorEvaluator testMseEvaluator = new MeanSquaredErrorEvaluator();
    217       testMseEvaluator.Name = "TestMeanSquaredErrorEvaluator";
    218       testMseEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    219       testMseEvaluator.GetVariableInfo("MSE").ActualName = "TestMSE";
    220       testMseEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    221       testMseEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
    222       #endregion
    223       #region MAPE
    224       MeanAbsolutePercentageErrorEvaluator trainingMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator();
    225       trainingMapeEvaluator.Name = "TrainingMapeEvaluator";
    226       trainingMapeEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    227       trainingMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TrainingMAPE";
    228       trainingMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    229       trainingMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    230       MeanAbsolutePercentageErrorEvaluator validationMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator();
    231       validationMapeEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    232       validationMapeEvaluator.Name = "ValidationMapeEvaluator";
    233       validationMapeEvaluator.GetVariableInfo("MAPE").ActualName = "ValidationMAPE";
    234       validationMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    235       validationMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    236       MeanAbsolutePercentageErrorEvaluator testMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator();
    237       testMapeEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    238       testMapeEvaluator.Name = "TestMapeEvaluator";
    239       testMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TestMAPE";
    240       testMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    241       testMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
    242       #endregion
    243       #region MAPRE
    244       MeanAbsolutePercentageOfRangeErrorEvaluator trainingMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator();
    245       trainingMapreEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    246       trainingMapreEvaluator.Name = "TrainingMapreEvaluator";
    247       trainingMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "TrainingMAPRE";
    248       trainingMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    249       trainingMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    250       MeanAbsolutePercentageOfRangeErrorEvaluator validationMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator();
    251       validationMapreEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    252       validationMapreEvaluator.Name = "ValidationMapreEvaluator";
    253       validationMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "ValidationMAPRE";
    254       validationMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    255       validationMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    256       MeanAbsolutePercentageOfRangeErrorEvaluator testMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator();
    257       testMapreEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    258       testMapreEvaluator.Name = "TestMapreEvaluator";
    259       testMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "TestMAPRE";
    260       testMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    261       testMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
    262       #endregion MAPRE
    263       #region R2
    264       CoefficientOfDeterminationEvaluator trainingR2Evaluator = new CoefficientOfDeterminationEvaluator();
    265       trainingR2Evaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    266       trainingR2Evaluator.Name = "TrainingR2Evaluator";
    267       trainingR2Evaluator.GetVariableInfo("R2").ActualName = "TrainingR2";
    268       trainingR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    269       trainingR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    270       CoefficientOfDeterminationEvaluator validationR2Evaluator = new CoefficientOfDeterminationEvaluator();
    271       validationR2Evaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    272       validationR2Evaluator.Name = "ValidationR2Evaluator";
    273       validationR2Evaluator.GetVariableInfo("R2").ActualName = "ValidationR2";
    274       validationR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    275       validationR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    276       CoefficientOfDeterminationEvaluator testR2Evaluator = new CoefficientOfDeterminationEvaluator();
    277       testR2Evaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    278       testR2Evaluator.Name = "TestR2Evaluator";
    279       testR2Evaluator.GetVariableInfo("R2").ActualName = "TestR2";
    280       testR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    281       testR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
    282       #endregion
    283       #region VAF
    284       VarianceAccountedForEvaluator trainingVAFEvaluator = new VarianceAccountedForEvaluator();
    285       trainingVAFEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    286       trainingVAFEvaluator.Name = "TrainingVAFEvaluator";
    287       trainingVAFEvaluator.GetVariableInfo("VAF").ActualName = "TrainingVAF";
    288       trainingVAFEvaluator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    289       trainingVAFEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    290       VarianceAccountedForEvaluator validationVAFEvaluator = new VarianceAccountedForEvaluator();
    291       validationVAFEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    292       validationVAFEvaluator.Name = "ValidationVAFEvaluator";
    293       validationVAFEvaluator.GetVariableInfo("VAF").ActualName = "ValidationVAF";
    294       validationVAFEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    295       validationVAFEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    296       VarianceAccountedForEvaluator testVAFEvaluator = new VarianceAccountedForEvaluator();
    297       testVAFEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    298       testVAFEvaluator.Name = "TestVAFEvaluator";
    299       testVAFEvaluator.GetVariableInfo("VAF").ActualName = "TestVAF";
    300       testVAFEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    301       testVAFEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
    302       #endregion
    303 
    304       solutionProc.AddSubOperator(evaluatorInjector);
    305       solutionProc.AddSubOperator(trainingMseEvaluator);
    306       solutionProc.AddSubOperator(validationMseEvaluator);
    307       solutionProc.AddSubOperator(testMseEvaluator);
    308       solutionProc.AddSubOperator(trainingMapeEvaluator);
    309       solutionProc.AddSubOperator(validationMapeEvaluator);
    310       solutionProc.AddSubOperator(testMapeEvaluator);
    311       solutionProc.AddSubOperator(trainingMapreEvaluator);
    312       solutionProc.AddSubOperator(validationMapreEvaluator);
    313       solutionProc.AddSubOperator(testMapreEvaluator);
    314       solutionProc.AddSubOperator(trainingR2Evaluator);
    315       solutionProc.AddSubOperator(validationR2Evaluator);
    316       solutionProc.AddSubOperator(testR2Evaluator);
    317       solutionProc.AddSubOperator(trainingVAFEvaluator);
    318       solutionProc.AddSubOperator(validationVAFEvaluator);
    319       solutionProc.AddSubOperator(testVAFEvaluator);
    320 
    321       #region variable impacts
    322       // calculate and set variable impacts
    323       VariableNamesExtractor namesExtractor = new VariableNamesExtractor();
    324       namesExtractor.GetVariableInfo("VariableNames").ActualName = "InputVariableNames";
    325       PredictorBuilder predictorBuilder = new PredictorBuilder();
    326       predictorBuilder.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    327       predictorBuilder.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(1000.0)));
    328 
    329       VariableEvaluationImpactCalculator evaluationImpactCalculator = new VariableEvaluationImpactCalculator();
    330       evaluationImpactCalculator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    331       evaluationImpactCalculator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    332       VariableQualityImpactCalculator qualityImpactCalculator = new VariableQualityImpactCalculator();
    333       qualityImpactCalculator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    334       qualityImpactCalculator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    335 
    336       solutionProc.AddSubOperator(namesExtractor);
    337       solutionProc.AddSubOperator(predictorBuilder);
    338       solutionProc.AddSubOperator(evaluationImpactCalculator);
    339       solutionProc.AddSubOperator(qualityImpactCalculator);
    340       #endregion
    341 
    342       op.OperatorGraph.AddOperator(seq);
    343       op.OperatorGraph.InitialOperator = seq;
    344       return op;
    345     }
    346 
    347153    protected internal virtual IOperator CreateProblemInjector() {
    348154      return new EmptyOperator();
    349155    }
    350156
    351     protected internal abstract IOperator CreateSelector();
    352 
    353     protected internal abstract IOperator CreateCrossover();
     157    protected virtual IOperator CreateSelector() {
     158      return new EmptyOperator();
     159    }
     160
     161    protected virtual IOperator CreateCrossover() {
     162      return new StandardCrossOver();
     163    }
    354164
    355165    protected internal abstract IOperator CreateTreeCreator();
  • branches/gp-algorithms-refactoring-#720/sources/HeuristicLab.GP.Algorithms/3.2/OffSpringSelectionGpEditor.Designer.cs

    r2326 r2331  
    2020#endregion
    2121
    22 namespace HeuristicLab.GP.StructureIdentification {
     22namespace HeuristicLab.GP.Algorithms {
    2323  partial class OffspringSelectionGpEditor {
    2424    /// <summary>
  • branches/gp-algorithms-refactoring-#720/sources/HeuristicLab.GP.Algorithms/3.2/OffSpringSelectionGpEditor.cs

    r2326 r2331  
    2525using HeuristicLab.Core;
    2626
    27 namespace HeuristicLab.GP.StructureIdentification {
     27namespace HeuristicLab.GP.Algorithms {
    2828  public partial class OffspringSelectionGpEditor : EditorBase {
    2929    private ChooseOperatorDialog chooseOperatorDialog;
  • branches/gp-algorithms-refactoring-#720/sources/HeuristicLab.GP.Algorithms/3.2/OffspringSelectionGP.cs

    r2326 r2331  
    3030using HeuristicLab.Selection.OffspringSelection;
    3131
    32 namespace HeuristicLab.GP.StructureIdentification {
     32namespace HeuristicLab.GP.Algorithms {
    3333  public class OffspringSelectionGP : StandardGP {
    3434    public override string Name { get { return "OffspringSelectionGP"; } }
  • branches/gp-algorithms-refactoring-#720/sources/HeuristicLab.GP.Algorithms/3.2/StandardGP.cs

    r2328 r2331  
    2121
    2222using HeuristicLab.Core;
    23 using HeuristicLab.DataAnalysis;
    2423using HeuristicLab.Operators;
    2524using HeuristicLab.Selection;
    2625using HeuristicLab.Logging;
    2726using HeuristicLab.Data;
    28 using HeuristicLab.Operators.Programmable;
    29 using HeuristicLab.Modeling;
    3027using HeuristicLab.GP.Operators;
    3128
    32 namespace HeuristicLab.GP.StructureIdentification {
     29namespace HeuristicLab.GP.Algorithms {
    3330  public class StandardGP : AlgorithmBase, IEditable {
    3431
  • branches/gp-algorithms-refactoring-#720/sources/HeuristicLab.GP.Algorithms/3.2/StandardGpEditor.Designer.cs

    r2326 r2331  
    2020#endregion
    2121
    22 namespace HeuristicLab.GP.StructureIdentification {
     22namespace HeuristicLab.GP.Algorithms {
    2323  partial class StandardGpEditor {
    2424    /// <summary>
  • branches/gp-algorithms-refactoring-#720/sources/HeuristicLab.GP.Algorithms/3.2/StandardGpEditor.cs

    r2326 r2331  
    2525using HeuristicLab.PluginInfrastructure;
    2626
    27 namespace HeuristicLab.GP.StructureIdentification {
     27namespace HeuristicLab.GP.Algorithms {
    2828  public partial class StandardGpEditor : EditorBase {
    2929    private ChooseOperatorDialog chooseOperatorDialog;
Note: See TracChangeset for help on using the changeset viewer.