Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2388


Ignore:
Timestamp:
09/24/09 16:52:24 (15 years ago)
Author:
gkronber
Message:

Adapted ModelingResultCalculators to keep a mapping from ModelingResult to evaluators. Using mapping in DefaultOperators for data-modeling engines. #755

Location:
trunk/sources/HeuristicLab.Modeling/3.2
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Modeling/3.2/DefaultClassificationOperators.cs

    r2370 r2388  
    3333
    3434      SequentialProcessor seq = new SequentialProcessor();
    35       seq.AddSubOperator(DefaultRegressionOperators.CreatePostProcessingOperator());
    36 
    37       SimpleAccuracyEvaluator trainingAccuracy = new SimpleAccuracyEvaluator();
    38       trainingAccuracy.Name = "TrainingAccuracyEvaluator";
    39       trainingAccuracy.GetVariableInfo("Accuracy").ActualName = ModelingResult.TrainingAccuracy.ToString();
    40       trainingAccuracy.GetVariableInfo("Values").ActualName = "TrainingValues";
    41 
    42       SimpleAccuracyEvaluator validationAccuracy = new SimpleAccuracyEvaluator();
    43       validationAccuracy.Name = "ValidationAccuracyEvaluator";
    44       validationAccuracy.GetVariableInfo("Accuracy").ActualName = ModelingResult.ValidationAccuracy.ToString();
    45       validationAccuracy.GetVariableInfo("Values").ActualName = "ValidationValues";
    46 
    47       SimpleAccuracyEvaluator testAccuracy = new SimpleAccuracyEvaluator();
    48       testAccuracy.Name = "TestAccuracyEvaluator";
    49       testAccuracy.GetVariableInfo("Accuracy").ActualName = ModelingResult.TestAccuracy.ToString();
    50       testAccuracy.GetVariableInfo("Values").ActualName = "TestValues";
     35      seq.AddSubOperator(DefaultModelAnalyzerOperators.CreatePostProcessingOperator(ModelType.Classification));
    5136
    5237      SimpleConfusionMatrixEvaluator trainingConfusionMatrixEvaluator = new SimpleConfusionMatrixEvaluator();
     
    6348      testConfusionMatrixEvaluator.GetVariableInfo("ConfusionMatrix").ActualName = "TestConfusionMatrix";
    6449
    65       seq.AddSubOperator(trainingAccuracy);
    66       seq.AddSubOperator(validationAccuracy);
    67       seq.AddSubOperator(testAccuracy);
    6850      seq.AddSubOperator(trainingConfusionMatrixEvaluator);
    6951      seq.AddSubOperator(validationConfusionMatrixEvaluator);
     
    8163
    8264    public static IAnalyzerModel PopulateAnalyzerModel(IScope modelScope, IAnalyzerModel model) {
    83       DefaultRegressionOperators.PopulateAnalyzerModel(modelScope, model);
    84       model.ExtractResult(modelScope, ModelingResult.TrainingAccuracy);
    85       model.ExtractResult(modelScope, ModelingResult.ValidationAccuracy);
    86       model.ExtractResult(modelScope, ModelingResult.TestAccuracy);
    87       model.Type = ModelType.Classification;
    88       return model;
     65      return DefaultModelAnalyzerOperators.PopulateAnalyzerModel(modelScope, model, ModelType.Classification);
    8966    }
    9067  }
  • trunk/sources/HeuristicLab.Modeling/3.2/DefaultRegressionOperators.cs

    r2379 r2388  
    4444
    4545    public static IOperator CreatePostProcessingOperator() {
    46       CombinedOperator op = new CombinedOperator();
    47       op.Name = "Regression model analyser";
    48       SequentialProcessor seq = new SequentialProcessor();
    49       #region MSE
    50       SimpleMSEEvaluator trainingMseEvaluator = new SimpleMSEEvaluator();
    51       trainingMseEvaluator.Name = "TrainingMseEvaluator";
    52       trainingMseEvaluator.GetVariableInfo("MSE").ActualName = ModelingResult.TrainingMeanSquaredError.ToString();
    53       trainingMseEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
    54       SimpleMSEEvaluator validationMseEvaluator = new SimpleMSEEvaluator();
    55       validationMseEvaluator.Name = "ValidationMseEvaluator";
    56       validationMseEvaluator.GetVariableInfo("MSE").ActualName = ModelingResult.ValidationMeanSquaredError.ToString();
    57       validationMseEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
    58       SimpleMSEEvaluator testMseEvaluator = new SimpleMSEEvaluator();
    59       testMseEvaluator.Name = "TestMseEvaluator";
    60       testMseEvaluator.GetVariableInfo("MSE").ActualName = ModelingResult.TestMeanSquaredError.ToString();
    61       testMseEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
    62       #endregion
    63       #region NMSE
    64       SimpleNMSEEvaluator trainingNmseEvaluator = new SimpleNMSEEvaluator();
    65       trainingNmseEvaluator.Name = "TrainingNmseEvaluator";
    66       trainingNmseEvaluator.GetVariableInfo("NMSE").ActualName = ModelingResult.TrainingNormalizedMeanSquaredError.ToString();
    67       trainingNmseEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
    68       SimpleNMSEEvaluator validationNmseEvaluator = new SimpleNMSEEvaluator();
    69       validationNmseEvaluator.Name = "ValidationMseEvaluator";
    70       validationNmseEvaluator.GetVariableInfo("NMSE").ActualName = ModelingResult.ValidationNormalizedMeanSquaredError.ToString();
    71       validationNmseEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
    72       SimpleNMSEEvaluator testNmseEvaluator = new SimpleNMSEEvaluator();
    73       testNmseEvaluator.Name = "TestNmseEvaluator";
    74       testNmseEvaluator.GetVariableInfo("NMSE").ActualName = ModelingResult.TestNormalizedMeanSquaredError.ToString();
    75       testNmseEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
    76       #endregion
    77       #region MAPE
    78       SimpleMeanAbsolutePercentageErrorEvaluator trainingMapeEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator();
    79       trainingMapeEvaluator.Name = "TrainingMapeEvaluator";
    80       trainingMapeEvaluator.GetVariableInfo("MAPE").ActualName = ModelingResult.TrainingMeanAbsolutePercentageError.ToString();
    81       trainingMapeEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
    82       SimpleMeanAbsolutePercentageErrorEvaluator validationMapeEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator();
    83       validationMapeEvaluator.Name = "ValidationMapeEvaluator";
    84       validationMapeEvaluator.GetVariableInfo("MAPE").ActualName = ModelingResult.ValidationMeanAbsolutePercentageError.ToString();
    85       validationMapeEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
    86       SimpleMeanAbsolutePercentageErrorEvaluator testMapeEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator();
    87       testMapeEvaluator.Name = "TestMapeEvaluator";
    88       testMapeEvaluator.GetVariableInfo("MAPE").ActualName = ModelingResult.TestMeanAbsolutePercentageError.ToString();
    89       testMapeEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
    90       #endregion
    91       #region MAPRE
    92       SimpleMeanAbsolutePercentageOfRangeErrorEvaluator trainingMapreEvaluator = new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator();
    93       trainingMapreEvaluator.Name = "TrainingMapreEvaluator";
    94       trainingMapreEvaluator.GetVariableInfo("MAPRE").ActualName = ModelingResult.TrainingMeanAbsolutePercentageOfRangeError.ToString();
    95       trainingMapreEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
    96       SimpleMeanAbsolutePercentageOfRangeErrorEvaluator validationMapreEvaluator = new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator();
    97       validationMapreEvaluator.Name = "ValidationMapreEvaluator";
    98       validationMapreEvaluator.GetVariableInfo("MAPRE").ActualName = ModelingResult.ValidationMeanAbsolutePercentageOfRangeError.ToString();
    99       validationMapreEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
    100       SimpleMeanAbsolutePercentageOfRangeErrorEvaluator testMapreEvaluator = new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator();
    101       testMapreEvaluator.Name = "TestMapreEvaluator";
    102       testMapreEvaluator.GetVariableInfo("MAPRE").ActualName = ModelingResult.TestMeanAbsolutePercentageOfRangeError.ToString();
    103       testMapreEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
    104       #endregion MAPRE
    105       #region R2
    106       SimpleR2Evaluator trainingR2Evaluator = new SimpleR2Evaluator();
    107       trainingR2Evaluator.Name = "TrainingR2Evaluator";
    108       trainingR2Evaluator.GetVariableInfo("R2").ActualName = ModelingResult.TrainingCoefficientOfDetermination.ToString();
    109       trainingR2Evaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
    110       SimpleR2Evaluator validationR2Evaluator = new SimpleR2Evaluator();
    111       validationR2Evaluator.Name = "ValidationR2Evaluator";
    112       validationR2Evaluator.GetVariableInfo("R2").ActualName = ModelingResult.ValidationCoefficientOfDetermination.ToString();
    113       validationR2Evaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
    114       SimpleR2Evaluator testR2Evaluator = new SimpleR2Evaluator();
    115       testR2Evaluator.Name = "TestR2Evaluator";
    116       testR2Evaluator.GetVariableInfo("R2").ActualName = ModelingResult.TestCoefficientOfDetermination.ToString();
    117       testR2Evaluator.GetVariableInfo("Values").ActualName = "TestValues";
    118       #endregion
    119       #region VAF
    120       SimpleVarianceAccountedForEvaluator trainingVAFEvaluator = new SimpleVarianceAccountedForEvaluator();
    121       trainingVAFEvaluator.Name = "TrainingVAFEvaluator";
    122       trainingVAFEvaluator.GetVariableInfo("VAF").ActualName = ModelingResult.TrainingVarianceAccountedFor.ToString();
    123       trainingVAFEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
    124       SimpleVarianceAccountedForEvaluator validationVAFEvaluator = new SimpleVarianceAccountedForEvaluator();
    125       validationVAFEvaluator.Name = "ValidationVAFEvaluator";
    126       validationVAFEvaluator.GetVariableInfo("VAF").ActualName = ModelingResult.ValidationVarianceAccountedFor.ToString();
    127       validationVAFEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
    128       SimpleVarianceAccountedForEvaluator testVAFEvaluator = new SimpleVarianceAccountedForEvaluator();
    129       testVAFEvaluator.Name = "TestVAFEvaluator";
    130       testVAFEvaluator.GetVariableInfo("VAF").ActualName = ModelingResult.TestVarianceAccountedFor.ToString();
    131       testVAFEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
    132       #endregion
    133 
    134       seq.AddSubOperator(trainingMseEvaluator);
    135       seq.AddSubOperator(validationMseEvaluator);
    136       seq.AddSubOperator(testMseEvaluator);
    137       seq.AddSubOperator(trainingNmseEvaluator);
    138       seq.AddSubOperator(validationNmseEvaluator);
    139       seq.AddSubOperator(testNmseEvaluator);
    140       seq.AddSubOperator(trainingMapeEvaluator);
    141       seq.AddSubOperator(validationMapeEvaluator);
    142       seq.AddSubOperator(testMapeEvaluator);
    143       seq.AddSubOperator(trainingMapreEvaluator);
    144       seq.AddSubOperator(validationMapreEvaluator);
    145       seq.AddSubOperator(testMapreEvaluator);
    146       seq.AddSubOperator(trainingR2Evaluator);
    147       seq.AddSubOperator(validationR2Evaluator);
    148       seq.AddSubOperator(testR2Evaluator);
    149       seq.AddSubOperator(trainingVAFEvaluator);
    150       seq.AddSubOperator(validationVAFEvaluator);
    151       seq.AddSubOperator(testVAFEvaluator);
    152 
    153       #region variable impacts
    154       VariableEvaluationImpactCalculator evaluationImpactCalculator = new VariableEvaluationImpactCalculator();
    155       evaluationImpactCalculator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
    156       evaluationImpactCalculator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
    157       VariableQualityImpactCalculator qualityImpactCalculator = new VariableQualityImpactCalculator();
    158       qualityImpactCalculator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
    159       qualityImpactCalculator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
    160 
    161       seq.AddSubOperator(evaluationImpactCalculator);
    162       seq.AddSubOperator(qualityImpactCalculator);
    163       #endregion
    164 
    165       op.OperatorGraph.AddOperator(seq);
    166       op.OperatorGraph.InitialOperator = seq;
    167       return op;
     46      return DefaultModelAnalyzerOperators.CreatePostProcessingOperator(ModelType.Regression);
    16847    }
    16948
    17049    public static IAnalyzerModel PopulateAnalyzerModel(IScope modelScope, IAnalyzerModel model) {
    171       model.Predictor = modelScope.GetVariableValue<IPredictor>("Predictor", false);
    172       Dataset ds = modelScope.GetVariableValue<Dataset>("Dataset", true);
    173       model.Dataset = ds;
    174       model.TargetVariable = ds.GetVariableName(modelScope.GetVariableValue<IntData>("TargetVariable", true).Data);
    175       model.Type = ModelType.Regression;
    176       model.TrainingSamplesStart = modelScope.GetVariableValue<IntData>("TrainingSamplesStart", true).Data;
    177       model.TrainingSamplesEnd = modelScope.GetVariableValue<IntData>("TrainingSamplesEnd", true).Data;
    178       model.ValidationSamplesStart = modelScope.GetVariableValue<IntData>("ValidationSamplesStart", true).Data;
    179       model.ValidationSamplesEnd = modelScope.GetVariableValue<IntData>("ValidationSamplesEnd", true).Data;
    180       model.TestSamplesStart = modelScope.GetVariableValue<IntData>("TestSamplesStart", true).Data;
    181       model.TestSamplesEnd = modelScope.GetVariableValue<IntData>("TestSamplesEnd", true).Data;
    182 
    183       model.ExtractResult(modelScope, ModelingResult.TrainingMeanSquaredError);
    184       model.ExtractResult(modelScope, ModelingResult.ValidationMeanSquaredError);
    185       model.ExtractResult(modelScope, ModelingResult.TestMeanSquaredError);
    186       model.ExtractResult(modelScope, ModelingResult.TrainingNormalizedMeanSquaredError);
    187       model.ExtractResult(modelScope, ModelingResult.ValidationNormalizedMeanSquaredError);
    188       model.ExtractResult(modelScope, ModelingResult.TestNormalizedMeanSquaredError);
    189       model.ExtractResult(modelScope, ModelingResult.TrainingMeanAbsolutePercentageError);
    190       model.ExtractResult(modelScope, ModelingResult.ValidationMeanAbsolutePercentageError);
    191       model.ExtractResult(modelScope, ModelingResult.TestMeanAbsolutePercentageError);
    192       model.ExtractResult(modelScope, ModelingResult.TrainingMeanAbsolutePercentageOfRangeError);
    193       model.ExtractResult(modelScope, ModelingResult.ValidationMeanAbsolutePercentageOfRangeError);
    194       model.ExtractResult(modelScope, ModelingResult.TestMeanAbsolutePercentageOfRangeError);
    195       model.ExtractResult(modelScope, ModelingResult.TrainingCoefficientOfDetermination);
    196       model.ExtractResult(modelScope, ModelingResult.ValidationCoefficientOfDetermination);
    197       model.ExtractResult(modelScope, ModelingResult.TestCoefficientOfDetermination);
    198       model.ExtractResult(modelScope, ModelingResult.TrainingVarianceAccountedFor);
    199       model.ExtractResult(modelScope, ModelingResult.ValidationVarianceAccountedFor);
    200       model.ExtractResult(modelScope, ModelingResult.TestVarianceAccountedFor);
    201 
    202       ItemList evaluationImpacts = modelScope.GetVariableValue<ItemList>(ModelingResult.VariableEvaluationImpact.ToString(), false);
    203       ItemList qualityImpacts = modelScope.GetVariableValue<ItemList>(ModelingResult.VariableQualityImpact.ToString(), false);
    204       foreach (ItemList row in evaluationImpacts) {
    205         string variableName = ((StringData)row[0]).Data;
    206         double impact = ((DoubleData)row[1]).Data;
    207         model.SetVariableResult(ModelingResult.VariableEvaluationImpact, variableName, impact);
    208         model.AddInputVariable(variableName);
    209       }
    210       foreach (ItemList row in qualityImpacts) {
    211         string variableName = ((StringData)row[0]).Data;
    212         double impact = ((DoubleData)row[1]).Data;
    213         model.SetVariableResult(ModelingResult.VariableQualityImpact, variableName, impact);
    214         model.AddInputVariable(variableName);
    215       }
    216 
    217       return model;
     50      return DefaultModelAnalyzerOperators.PopulateAnalyzerModel(modelScope, model, ModelType.Regression);
    21851    }
    21952  }
  • trunk/sources/HeuristicLab.Modeling/3.2/DefaultTimeSeriesOperators.cs

    r2379 r2388  
    3939
    4040    public static IOperator CreatePostProcessingOperator() {
    41       CombinedOperator op = new CombinedOperator();
    42       op.Name = "Time series prognosis model analyzer";
    43 
    44       SequentialProcessor seq = new SequentialProcessor();
    45       seq.AddSubOperator(DefaultRegressionOperators.CreatePostProcessingOperator());
    46 
    47       #region theil inequality
    48       SimpleTheilInequalityCoefficientEvaluator trainingTheil = new SimpleTheilInequalityCoefficientEvaluator();
    49       trainingTheil.Name = "TrainingTheilInequalityEvaluator";
    50       trainingTheil.GetVariableInfo("Values").ActualName = "TrainingValues";
    51       trainingTheil.GetVariableInfo("TheilInequalityCoefficient").ActualName = ModelingResult.TrainingTheilInequality.ToString();
    52       SimpleTheilInequalityCoefficientEvaluator validationTheil = new SimpleTheilInequalityCoefficientEvaluator();
    53       validationTheil.Name = "ValidationTheilInequalityEvaluator";
    54       validationTheil.GetVariableInfo("Values").ActualName = "ValidationValues";
    55       validationTheil.GetVariableInfo("TheilInequalityCoefficient").ActualName = ModelingResult.ValidationTheilInequality.ToString();
    56       SimpleTheilInequalityCoefficientEvaluator testTheil = new SimpleTheilInequalityCoefficientEvaluator();
    57       testTheil.Name = "TestTheilInequalityEvaluator";
    58       testTheil.GetVariableInfo("Values").ActualName = "TestValues";
    59       testTheil.GetVariableInfo("TheilInequalityCoefficient").ActualName = ModelingResult.TestTheilInequality.ToString();
    60 
    61       seq.AddSubOperator(trainingTheil);
    62       seq.AddSubOperator(validationTheil);
    63       seq.AddSubOperator(testTheil);
    64       #endregion
    65 
    66       #region directional symmetry
    67       SimpleDirectionalSymmetryEvaluator trainingDS = new SimpleDirectionalSymmetryEvaluator();
    68       trainingDS.Name = "TrainingDirectionalSymmetryEvaluator";
    69       trainingDS.GetVariableInfo("Values").ActualName = "TrainingValues";
    70       trainingDS.GetVariableInfo("DirectionalSymmetry").ActualName = ModelingResult.TrainingDirectionalSymmetry.ToString();
    71       SimpleDirectionalSymmetryEvaluator validationDS = new SimpleDirectionalSymmetryEvaluator();
    72       validationDS.Name = "ValidationDirectionalSymmetryEvaluator";
    73       validationDS.GetVariableInfo("Values").ActualName = "ValidationValues";
    74       validationDS.GetVariableInfo("DirectionalSymmetry").ActualName = ModelingResult.ValidationDirectionalSymmetry.ToString();
    75       SimpleDirectionalSymmetryEvaluator testDS = new SimpleDirectionalSymmetryEvaluator();
    76       testDS.Name = "TestDirectionalSymmetryEvaluator";
    77       testDS.GetVariableInfo("Values").ActualName = "TestValues";
    78       testDS.GetVariableInfo("DirectionalSymmetry").ActualName = ModelingResult.TestDirectionalSymmetry.ToString();
    79 
    80       seq.AddSubOperator(trainingDS);
    81       seq.AddSubOperator(validationDS);
    82       seq.AddSubOperator(testDS);
    83       #endregion
    84 
    85       #region weighted directional symmetry
    86       SimpleWeightedDirectionalSymmetryEvaluator trainingWDS = new SimpleWeightedDirectionalSymmetryEvaluator();
    87       trainingWDS.Name = "TrainingWeightedDirectionalSymmetryEvaluator";
    88       trainingWDS.GetVariableInfo("Values").ActualName = "TrainingValues";
    89       trainingWDS.GetVariableInfo("WeightedDirectionalSymmetry").ActualName = ModelingResult.TrainingWeightedDirectionalSymmetry.ToString();
    90       SimpleWeightedDirectionalSymmetryEvaluator validationWDS = new SimpleWeightedDirectionalSymmetryEvaluator();
    91       validationWDS.Name = "ValidationWeightedDirectionalSymmetryEvaluator";
    92       validationWDS.GetVariableInfo("Values").ActualName = "ValidationValues";
    93       validationWDS.GetVariableInfo("WeightedDirectionalSymmetry").ActualName = ModelingResult.ValidationWeightedDirectionalSymmetry.ToString();
    94       SimpleWeightedDirectionalSymmetryEvaluator testWDS = new SimpleWeightedDirectionalSymmetryEvaluator();
    95       testWDS.Name = "TestWeightedDirectionalSymmetryEvaluator";
    96       testWDS.GetVariableInfo("Values").ActualName = "TestValues";
    97       testWDS.GetVariableInfo("WeightedDirectionalSymmetry").ActualName = ModelingResult.TestWeightedDirectionalSymmetry.ToString();
    98 
    99       seq.AddSubOperator(trainingWDS);
    100       seq.AddSubOperator(validationWDS);
    101       seq.AddSubOperator(testWDS);
    102       #endregion
    103 
    104       op.OperatorGraph.AddOperator(seq);
    105       op.OperatorGraph.InitialOperator = seq;
    106       return op;
     41      return DefaultModelAnalyzerOperators.CreatePostProcessingOperator(ModelType.TimeSeriesPrognosis);
    10742    }
    10843
    10944    public static IAnalyzerModel PopulateAnalyzerModel(IScope modelScope, IAnalyzerModel model) {
    110       DefaultRegressionOperators.PopulateAnalyzerModel(modelScope, model);
    111       model.ExtractResult(modelScope, ModelingResult.TrainingTheilInequality);
    112       model.ExtractResult(modelScope, ModelingResult.ValidationTheilInequality);
    113       model.ExtractResult(modelScope, ModelingResult.TestTheilInequality);
    114       model.ExtractResult(modelScope, ModelingResult.TrainingDirectionalSymmetry);
    115       model.ExtractResult(modelScope, ModelingResult.ValidationDirectionalSymmetry);
    116       model.ExtractResult(modelScope, ModelingResult.TestDirectionalSymmetry);
    117       model.ExtractResult(modelScope, ModelingResult.TrainingWeightedDirectionalSymmetry);
    118       model.ExtractResult(modelScope, ModelingResult.ValidationWeightedDirectionalSymmetry);
    119       model.ExtractResult(modelScope, ModelingResult.TestWeightedDirectionalSymmetry);
    120       model.Type = ModelType.TimeSeriesPrognosis;
    121       return model;
     45      return DefaultModelAnalyzerOperators.PopulateAnalyzerModel(modelScope, model, ModelType.TimeSeriesPrognosis);
    12246    }
    12347  }
  • trunk/sources/HeuristicLab.Modeling/3.2/HeuristicLab.Modeling-3.2.csproj

    r2383 r2388  
    8484    <Compile Include="AnalyzerModel.cs" />
    8585    <Compile Include="BestSolutionStorer.cs" />
     86    <Compile Include="DefaultModelAnalyzerOperators.cs" />
    8687    <Compile Include="Matrix.cs" />
    8788    <Compile Include="ModelingResultCalculators.cs" />
  • trunk/sources/HeuristicLab.Modeling/3.2/ModelingResultCalculators.cs

    r2387 r2388  
    2424using System.Linq;
    2525using System.Text;
     26using HeuristicLab.Core;
    2627
    2728namespace HeuristicLab.Modeling {
    2829  public abstract class ModelingResultCalculators {
     30    private enum DatasetPart { Training, Validation, Test };
     31
    2932    private static readonly Dictionary<ModelingResult, Func<double[,], double>> ClassificationModelingResults;
    3033    private static readonly Dictionary<ModelingResult, Func<double[,], double>> RegressionModelingResults;
    3134    private static readonly Dictionary<ModelingResult, Func<double[,], double>> TimeSeriesPrognosisModelingResults;
     35    private static readonly Dictionary<ModelingResult, IOperator> ClassificationModelingResultEvaluators;
     36    private static readonly Dictionary<ModelingResult, IOperator> RegressionModelingResultEvaluators;
     37    private static readonly Dictionary<ModelingResult, IOperator> TimeSeriesPrognosisModelingResultEvaluators;
     38
     39    private static readonly Dictionary<Type, IEnumerable<ModelingResult>> regressionResults =
     40      new Dictionary<Type, IEnumerable<ModelingResult>>() {
     41        { typeof(SimpleMSEEvaluator),
     42          new ModelingResult[] {
     43            ModelingResult.TrainingMeanSquaredError,
     44            ModelingResult.ValidationMeanSquaredError,
     45            ModelingResult.TestMeanSquaredError
     46          }},
     47        { typeof(SimpleNMSEEvaluator),
     48          new ModelingResult[] {
     49            ModelingResult.TrainingNormalizedMeanSquaredError,
     50            ModelingResult.ValidationNormalizedMeanSquaredError,
     51            ModelingResult.TestNormalizedMeanSquaredError
     52          }
     53        },
     54        { typeof(SimpleR2Evaluator),
     55          new ModelingResult[] {
     56            ModelingResult.TrainingCoefficientOfDetermination,
     57            ModelingResult.ValidationCoefficientOfDetermination,
     58            ModelingResult.TestCoefficientOfDetermination
     59          }
     60        },
     61        { typeof(SimpleVarianceAccountedForEvaluator),
     62          new ModelingResult[] {
     63            ModelingResult.TrainingVarianceAccountedFor,
     64            ModelingResult.ValidationVarianceAccountedFor,
     65            ModelingResult.TestVarianceAccountedFor
     66          }
     67        },
     68        { typeof(SimpleMeanAbsolutePercentageErrorEvaluator),
     69          new ModelingResult[] {
     70            ModelingResult.TrainingMeanAbsolutePercentageError,
     71            ModelingResult.ValidationMeanAbsolutePercentageError,
     72            ModelingResult.TestMeanAbsolutePercentageError
     73          }
     74        },
     75        { typeof(SimpleMeanAbsolutePercentageOfRangeErrorEvaluator),
     76          new ModelingResult[] {
     77            ModelingResult.TrainingMeanAbsolutePercentageOfRangeError,
     78            ModelingResult.ValidationMeanAbsolutePercentageOfRangeError,
     79            ModelingResult.TestMeanAbsolutePercentageOfRangeError
     80          }
     81        }
     82      };
     83
     84    private static readonly Dictionary<Type, IEnumerable<ModelingResult>> timeSeriesResults =
     85      new Dictionary<Type, IEnumerable<ModelingResult>>() {
     86        { typeof(SimpleTheilInequalityCoefficientEvaluator),
     87          new ModelingResult[] {
     88            ModelingResult.TrainingTheilInequality,
     89            ModelingResult.ValidationTheilInequality,
     90            ModelingResult.TestTheilInequality
     91          }
     92        },
     93        { typeof(SimpleDirectionalSymmetryEvaluator),
     94          new ModelingResult[] {
     95            ModelingResult.TrainingDirectionalSymmetry,
     96            ModelingResult.ValidationDirectionalSymmetry,
     97            ModelingResult.TestDirectionalSymmetry
     98          }
     99        },
     100        { typeof(SimpleWeightedDirectionalSymmetryEvaluator),
     101          new ModelingResult[] {
     102            ModelingResult.TrainingWeightedDirectionalSymmetry,
     103            ModelingResult.ValidationWeightedDirectionalSymmetry,
     104            ModelingResult.TestWeightedDirectionalSymmetry
     105          }
     106        }
     107      };
     108
     109    private static readonly Dictionary<Type, IEnumerable<ModelingResult>> classificationResults =
     110      new Dictionary<Type, IEnumerable<ModelingResult>>() {
     111        { typeof(SimpleAccuracyEvaluator),
     112          new ModelingResult[] {
     113            ModelingResult.TrainingAccuracy,
     114            ModelingResult.ValidationAccuracy,
     115            ModelingResult.TestAccuracy
     116          }
     117        }
     118      };
     119
    32120
    33121    static ModelingResultCalculators() {
    34122      RegressionModelingResults = new Dictionary<ModelingResult, Func<double[,], double>>();
     123      ClassificationModelingResults = new Dictionary<ModelingResult, Func<double[,], double>>();
     124      TimeSeriesPrognosisModelingResults = new Dictionary<ModelingResult, Func<double[,], double>>();
    35125
    36126      //Mean squared errors
     
    83173      TimeSeriesPrognosisModelingResults[ModelingResult.ValidationWeightedDirectionalSymmetry] = SimpleWeightedDirectionalSymmetryEvaluator.Calculate;
    84174      TimeSeriesPrognosisModelingResults[ModelingResult.TestWeightedDirectionalSymmetry] = SimpleWeightedDirectionalSymmetryEvaluator.Calculate;
     175
     176      #region result evaluators
     177
     178      RegressionModelingResultEvaluators = new Dictionary<ModelingResult, IOperator>();
     179      foreach (Type evaluatorT in regressionResults.Keys) {
     180        foreach (ModelingResult r in regressionResults[evaluatorT]) {
     181          RegressionModelingResultEvaluators[r] = CreateEvaluator(evaluatorT, r);
     182        }
     183      }
     184
     185      timeSeriesResults = CombineDictionaries(regressionResults, timeSeriesResults);
     186      TimeSeriesPrognosisModelingResultEvaluators = new Dictionary<ModelingResult, IOperator>();
     187      foreach (Type evaluatorT in timeSeriesResults.Keys) {
     188        foreach (ModelingResult r in timeSeriesResults[evaluatorT]) {
     189          TimeSeriesPrognosisModelingResultEvaluators[r] = CreateEvaluator(evaluatorT, r);
     190        }
     191      }
     192
     193      classificationResults = CombineDictionaries(regressionResults, classificationResults);
     194      ClassificationModelingResultEvaluators = new Dictionary<ModelingResult, IOperator>();
     195      foreach (Type evaluatorT in classificationResults.Keys) {
     196        foreach (ModelingResult r in classificationResults[evaluatorT]) {
     197          ClassificationModelingResultEvaluators[r] = CreateEvaluator(evaluatorT, r);
     198        }
     199      }
     200
     201      #endregion
    85202    }
    86203
    87204    public static Dictionary<ModelingResult, Func<double[,], double>> GetModelingResult(ModelType modelType) {
    88       IEnumerable<KeyValuePair<ModelingResult,Func<double[,],double>>> ret = new Dictionary<ModelingResult,Func<double[,],double>>();
    89205      switch (modelType) {
    90206        case ModelType.Regression:
    91           ret = ret.Union( RegressionModelingResults);
    92           break;
     207          return CombineDictionaries(RegressionModelingResults, new Dictionary<ModelingResult, Func<double[,], double>>());
    93208        case ModelType.Classification:
    94           ret = ret.Union(RegressionModelingResults);
    95           ret = ret.Union(ClassificationModelingResults);
    96           break;
     209          return CombineDictionaries(RegressionModelingResults, ClassificationModelingResults);
    97210        case ModelType.TimeSeriesPrognosis:
    98           ret = ret.Union(RegressionModelingResults);
    99           ret = ret.Union(TimeSeriesPrognosisModelingResults);
    100           break;
     211          return CombineDictionaries(RegressionModelingResults, ClassificationModelingResults);
    101212        default:
    102           throw new ArgumentException("Modeling result mapping for ModelType " + modelType + " not defined.");         
    103       }
    104       return ret.ToDictionary<KeyValuePair<ModelingResult, Func<double[,], double>>, ModelingResult, Func<double[,], double>>(x => x.Key, x => x.Value);
     213          throw new ArgumentException("Modeling result mapping for ModelType " + modelType + " not defined.");
     214      }
    105215    }
    106216
     
    113223        return TimeSeriesPrognosisModelingResults[modelingResult];
    114224      else
    115         throw new ArgumentException("Calculator for modeling reuslt " + modelingResult + " not defined.");
     225        throw new ArgumentException("Calculator for modeling result " + modelingResult + " not defined.");
     226    }
     227
     228    public static IOperator CreateModelingResultEvaluator(ModelingResult modelingResult) {
     229      IOperator opTemplate = null;
     230      if (RegressionModelingResultEvaluators.ContainsKey(modelingResult))
     231        opTemplate = RegressionModelingResultEvaluators[modelingResult];
     232      else if (ClassificationModelingResultEvaluators.ContainsKey(modelingResult))
     233        opTemplate = ClassificationModelingResultEvaluators[modelingResult];
     234      else if (TimeSeriesPrognosisModelingResultEvaluators.ContainsKey(modelingResult))
     235        opTemplate = TimeSeriesPrognosisModelingResultEvaluators[modelingResult];
     236      else
     237        throw new ArgumentException("Evaluator for modeling result " + modelingResult + " not defined.");
     238      return (IOperator)opTemplate.Clone();
     239    }
     240
     241    private static IOperator CreateEvaluator(Type evaluatorType, ModelingResult result) {
     242      SimpleEvaluatorBase evaluator = (SimpleEvaluatorBase)Activator.CreateInstance(evaluatorType);
     243      evaluator.GetVariableInfo("Values").ActualName = GetDatasetPart(result) + "Values";
     244      evaluator.GetVariableInfo(evaluator.OutputVariableName).ActualName = result.ToString();
     245      return evaluator;
     246    }
     247
     248    private static DatasetPart GetDatasetPart(ModelingResult result) {
     249      if (result.ToString().StartsWith("Training")) return DatasetPart.Training;
     250      else if (result.ToString().StartsWith("Validation")) return DatasetPart.Validation;
     251      else if (result.ToString().StartsWith("Test")) return DatasetPart.Test;
     252      else throw new ArgumentException("Can't determine dataset part of modeling result " + result + ".");
     253    }
     254
     255    private static Dictionary<T1, T2> CombineDictionaries<T1, T2>(
     256      Dictionary<T1, T2> x,
     257      Dictionary<T1, T2> y) {
     258      Dictionary<T1, T2> result = new Dictionary<T1, T2>(x);
     259      return x.Union(y).ToDictionary<KeyValuePair<T1, T2>, T1, T2>(p => p.Key, p => p.Value);
    116260    }
    117261  }
Note: See TracChangeset for help on using the changeset viewer.