Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2386


Ignore:
Timestamp:
09/24/09 13:09:50 (15 years ago)
Author:
mkommend
Message:

added mapping between ModelTypes and ModelingResults (ticket #755)

File:
1 edited

Legend:

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

    r2383 r2386  
    2727namespace HeuristicLab.Modeling {
    2828  public abstract class ModelingResultCalculators {
    29 
    30     public static readonly Dictionary<ModelingResult, Func<double[,], double>> Mapping;
     29    private static readonly Dictionary<ModelingResult, Func<double[,], double>> ClassificationModelingResults;
     30    private static readonly Dictionary<ModelingResult, Func<double[,], double>> RegressionModelingResults;
     31    private static readonly Dictionary<ModelingResult, Func<double[,], double>> TimeSeriesPrognosisModelingResults;
    3132
    3233    static ModelingResultCalculators() {
    33       Mapping = new Dictionary<ModelingResult, Func<double[,], double>>();
     34      RegressionModelingResults = new Dictionary<ModelingResult, Func<double[,], double>>();
    3435
    3536      //Mean squared errors
    36       Mapping[ModelingResult.TrainingMeanSquaredError] = SimpleMSEEvaluator.Calculate;
    37       Mapping[ModelingResult.ValidationMeanSquaredError] = SimpleMSEEvaluator.Calculate;
    38       Mapping[ModelingResult.TestMeanSquaredError] = SimpleMSEEvaluator.Calculate;
     37      RegressionModelingResults[ModelingResult.TrainingMeanSquaredError] = SimpleMSEEvaluator.Calculate;
     38      RegressionModelingResults[ModelingResult.ValidationMeanSquaredError] = SimpleMSEEvaluator.Calculate;
     39      RegressionModelingResults[ModelingResult.TestMeanSquaredError] = SimpleMSEEvaluator.Calculate;
    3940
    4041      //Normalized mean squared errors
    41       Mapping[ModelingResult.TrainingNormalizedMeanSquaredError] = SimpleNMSEEvaluator.Calculate;
    42       Mapping[ModelingResult.ValidationNormalizedMeanSquaredError] = SimpleNMSEEvaluator.Calculate;
    43       Mapping[ModelingResult.TestNormalizedMeanSquaredError] = SimpleNMSEEvaluator.Calculate;
     42      RegressionModelingResults[ModelingResult.TrainingNormalizedMeanSquaredError] = SimpleNMSEEvaluator.Calculate;
     43      RegressionModelingResults[ModelingResult.ValidationNormalizedMeanSquaredError] = SimpleNMSEEvaluator.Calculate;
     44      RegressionModelingResults[ModelingResult.TestNormalizedMeanSquaredError] = SimpleNMSEEvaluator.Calculate;
    4445
    4546      //Mean absolute percentage error
    46       Mapping[ModelingResult.TrainingMeanAbsolutePercentageError] = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate;
    47       Mapping[ModelingResult.ValidationMeanAbsolutePercentageError] = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate;
    48       Mapping[ModelingResult.TestMeanAbsolutePercentageError] = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate;
     47      RegressionModelingResults[ModelingResult.TrainingMeanAbsolutePercentageError] = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate;
     48      RegressionModelingResults[ModelingResult.ValidationMeanAbsolutePercentageError] = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate;
     49      RegressionModelingResults[ModelingResult.TestMeanAbsolutePercentageError] = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate;
    4950
    5051      //Mean absolute percentage of range error
    51       Mapping[ModelingResult.TrainingMeanAbsolutePercentageOfRangeError] = SimpleMeanAbsolutePercentageOfRangeErrorEvaluator.Calculate;
    52       Mapping[ModelingResult.ValidationMeanAbsolutePercentageOfRangeError] = SimpleMeanAbsolutePercentageOfRangeErrorEvaluator.Calculate;
    53       Mapping[ModelingResult.TestMeanAbsolutePercentageOfRangeError] = SimpleMeanAbsolutePercentageOfRangeErrorEvaluator.Calculate;
     52      RegressionModelingResults[ModelingResult.TrainingMeanAbsolutePercentageOfRangeError] = SimpleMeanAbsolutePercentageOfRangeErrorEvaluator.Calculate;
     53      RegressionModelingResults[ModelingResult.ValidationMeanAbsolutePercentageOfRangeError] = SimpleMeanAbsolutePercentageOfRangeErrorEvaluator.Calculate;
     54      RegressionModelingResults[ModelingResult.TestMeanAbsolutePercentageOfRangeError] = SimpleMeanAbsolutePercentageOfRangeErrorEvaluator.Calculate;
    5455
    5556      //Coefficient of determination
    56       Mapping[ModelingResult.TrainingCoefficientOfDetermination] = SimpleR2Evaluator.Calculate;
    57       Mapping[ModelingResult.ValidationCoefficientOfDetermination] = SimpleR2Evaluator.Calculate;
    58       Mapping[ModelingResult.TestCoefficientOfDetermination] = SimpleR2Evaluator.Calculate;
     57      RegressionModelingResults[ModelingResult.TrainingCoefficientOfDetermination] = SimpleR2Evaluator.Calculate;
     58      RegressionModelingResults[ModelingResult.ValidationCoefficientOfDetermination] = SimpleR2Evaluator.Calculate;
     59      RegressionModelingResults[ModelingResult.TestCoefficientOfDetermination] = SimpleR2Evaluator.Calculate;
    5960
    6061      //Variance accounted for
    61       Mapping[ModelingResult.TrainingVarianceAccountedFor] = SimpleVarianceAccountedForEvaluator.Calculate;
    62       Mapping[ModelingResult.ValidationVarianceAccountedFor] = SimpleVarianceAccountedForEvaluator.Calculate;
    63       Mapping[ModelingResult.TestVarianceAccountedFor] = SimpleVarianceAccountedForEvaluator.Calculate;
     62      RegressionModelingResults[ModelingResult.TrainingVarianceAccountedFor] = SimpleVarianceAccountedForEvaluator.Calculate;
     63      RegressionModelingResults[ModelingResult.ValidationVarianceAccountedFor] = SimpleVarianceAccountedForEvaluator.Calculate;
     64      RegressionModelingResults[ModelingResult.TestVarianceAccountedFor] = SimpleVarianceAccountedForEvaluator.Calculate;
    6465
    6566      //Accuracy
    66       Mapping[ModelingResult.TrainingAccuracy] = SimpleAccuracyEvaluator.Calculate;
    67       Mapping[ModelingResult.ValidationAccuracy] = SimpleAccuracyEvaluator.Calculate;
    68       Mapping[ModelingResult.TestAccuracy] = SimpleAccuracyEvaluator.Calculate;
     67      ClassificationModelingResults[ModelingResult.TrainingAccuracy] = SimpleAccuracyEvaluator.Calculate;
     68      ClassificationModelingResults[ModelingResult.ValidationAccuracy] = SimpleAccuracyEvaluator.Calculate;
     69      ClassificationModelingResults[ModelingResult.TestAccuracy] = SimpleAccuracyEvaluator.Calculate;
    6970
    7071      //Theil inequality
    71       Mapping[ModelingResult.TrainingTheilInequality] = SimpleTheilInequalityCoefficientEvaluator.Calculate;
    72       Mapping[ModelingResult.ValidationTheilInequality] = SimpleTheilInequalityCoefficientEvaluator.Calculate;
    73       Mapping[ModelingResult.TestTheilInequality] = SimpleTheilInequalityCoefficientEvaluator.Calculate;
     72      TimeSeriesPrognosisModelingResults[ModelingResult.TrainingTheilInequality] = SimpleTheilInequalityCoefficientEvaluator.Calculate;
     73      TimeSeriesPrognosisModelingResults[ModelingResult.ValidationTheilInequality] = SimpleTheilInequalityCoefficientEvaluator.Calculate;
     74      TimeSeriesPrognosisModelingResults[ModelingResult.TestTheilInequality] = SimpleTheilInequalityCoefficientEvaluator.Calculate;
    7475
    7576      //Directional symmetry
    76       Mapping[ModelingResult.TrainingDirectionalSymmetry] = SimpleDirectionalSymmetryEvaluator.Calculate;
    77       Mapping[ModelingResult.ValidationDirectionalSymmetry] = SimpleDirectionalSymmetryEvaluator.Calculate;
    78       Mapping[ModelingResult.TestDirectionalSymmetry] = SimpleDirectionalSymmetryEvaluator.Calculate;
     77      TimeSeriesPrognosisModelingResults[ModelingResult.TrainingDirectionalSymmetry] = SimpleDirectionalSymmetryEvaluator.Calculate;
     78      TimeSeriesPrognosisModelingResults[ModelingResult.ValidationDirectionalSymmetry] = SimpleDirectionalSymmetryEvaluator.Calculate;
     79      TimeSeriesPrognosisModelingResults[ModelingResult.TestDirectionalSymmetry] = SimpleDirectionalSymmetryEvaluator.Calculate;
    7980
    8081      //Weighted directional symmetry
    81       Mapping[ModelingResult.TrainingWeightedDirectionalSymmetry] = SimpleWeightedDirectionalSymmetryEvaluator.Calculate;
    82       Mapping[ModelingResult.ValidationWeightedDirectionalSymmetry] = SimpleWeightedDirectionalSymmetryEvaluator.Calculate;
    83       Mapping[ModelingResult.TestWeightedDirectionalSymmetry] = SimpleWeightedDirectionalSymmetryEvaluator.Calculate;
     82      TimeSeriesPrognosisModelingResults[ModelingResult.TrainingWeightedDirectionalSymmetry] = SimpleWeightedDirectionalSymmetryEvaluator.Calculate;
     83      TimeSeriesPrognosisModelingResults[ModelingResult.ValidationWeightedDirectionalSymmetry] = SimpleWeightedDirectionalSymmetryEvaluator.Calculate;
     84      TimeSeriesPrognosisModelingResults[ModelingResult.TestWeightedDirectionalSymmetry] = SimpleWeightedDirectionalSymmetryEvaluator.Calculate;
     85    }
     86
     87    public static Dictionary<ModelingResult, Func<double[,], double>> GetModelingResult(ModelType modelType) {
     88      IEnumerable<KeyValuePair<ModelingResult,Func<double[,],double>>> ret = new Dictionary<ModelingResult,Func<double[,],double>>();
     89      switch (modelType) {
     90        case ModelType.Regression:
     91          ret = ret.Union( RegressionModelingResults);
     92          break;
     93        case ModelType.Classification:
     94          ret = ret.Union(RegressionModelingResults);
     95          ret = ret.Union(ClassificationModelingResults);
     96          break;
     97        case ModelType.TimeSeriesPrognosis:
     98          ret = ret.Union(RegressionModelingResults);
     99          ret = ret.Union(TimeSeriesPrognosisModelingResults);
     100          break;
     101        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);
    84105    }
    85106  }
Note: See TracChangeset for help on using the changeset viewer.