- Timestamp:
- 09/14/09 17:30:02 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 deleted
- 6 edited
- 1 copied
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/DefaultClassificationAlgorithmOperators.cs
r2344 r2351 37 37 subScopesProc.AddSubOperator(individualProc); 38 38 seq.AddSubOperator(subScopesProc); 39 AccuracyEvaluator trainingAccuracy = newAccuracyEvaluator();39 SimpleAccuracyEvaluator trainingAccuracy = new SimpleAccuracyEvaluator(); 40 40 trainingAccuracy.Name = "TrainingAccuracyEvaluator"; 41 41 trainingAccuracy.GetVariableInfo("Accuracy").ActualName = "TrainingAccuracy"; 42 trainingAccuracy.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 43 trainingAccuracy.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 42 trainingAccuracy.GetVariableInfo("Values").ActualName = "TrainingValues"; 44 43 45 AccuracyEvaluator validationAccuracy = newAccuracyEvaluator();44 SimpleAccuracyEvaluator validationAccuracy = new SimpleAccuracyEvaluator(); 46 45 validationAccuracy.Name = "ValidationAccuracyEvaluator"; 47 46 validationAccuracy.GetVariableInfo("Accuracy").ActualName = "ValidationAccuracy"; 48 validationAccuracy.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 49 validationAccuracy.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 47 validationAccuracy.GetVariableInfo("Values").ActualName = "ValidationValues"; 50 48 51 AccuracyEvaluator testAccuracy = newAccuracyEvaluator();49 SimpleAccuracyEvaluator testAccuracy = new SimpleAccuracyEvaluator(); 52 50 testAccuracy.Name = "TestAccuracyEvaluator"; 53 51 testAccuracy.GetVariableInfo("Accuracy").ActualName = "TestAccuracy"; 54 testAccuracy.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart"; 55 testAccuracy.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd"; 52 testAccuracy.GetVariableInfo("Values").ActualName = "TestValues"; 56 53 57 54 individualProc.AddSubOperator(trainingAccuracy); -
trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/HeuristicLab.GP.StructureIdentification.Classification-3.3.csproj
r2341 r2351 80 80 </ItemGroup> 81 81 <ItemGroup> 82 <Compile Include="AccuracyEvaluator.cs" />83 82 <Compile Include="ClassificationMeanSquaredErrorEvaluator.cs" /> 84 <Compile Include="ConfusionMatrixEvaluator.cs" />85 <Compile Include="TargetClassesCalculator.cs" />86 83 <Compile Include="DefaultClassificationAlgorithmOperators.cs" /> 87 84 <Compile Include="GPClassificationEvaluatorBase.cs" /> -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/DefaultStructureIdentificationOperators.cs
r2344 r2351 126 126 evaluatorInjector.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 127 127 128 #region simple evaluators 129 SimpleEvaluator trainingEvaluator = new SimpleEvaluator(); 130 trainingEvaluator.Name = "TrainingEvaluator"; 131 trainingEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 132 trainingEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 133 trainingEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues"; 134 trainingEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 135 SimpleEvaluator validationEvaluator = new SimpleEvaluator(); 136 validationEvaluator.Name = "ValidationEvaluator"; 137 validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 138 validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 139 validationEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues"; 140 validationEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 141 SimpleEvaluator testEvaluator = new SimpleEvaluator(); 142 testEvaluator.Name = "TestEvaluator"; 143 testEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart"; 144 testEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd"; 145 testEvaluator.GetVariableInfo("Values").ActualName = "TestValues"; 146 testEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 147 #endregion 128 148 #region MSE 129 MeanSquaredErrorEvaluator trainingMseEvaluator = new MeanSquaredErrorEvaluator();149 SimpleMSEEvaluator trainingMseEvaluator = new SimpleMSEEvaluator(); 130 150 trainingMseEvaluator.Name = "TrainingMseEvaluator"; 131 trainingMseEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";132 151 trainingMseEvaluator.GetVariableInfo("MSE").ActualName = "TrainingMSE"; 133 trainingMseEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 134 trainingMseEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 135 MeanSquaredErrorEvaluator validationMseEvaluator = new MeanSquaredErrorEvaluator(); 152 trainingMseEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues"; 153 SimpleMSEEvaluator validationMseEvaluator = new SimpleMSEEvaluator(); 136 154 validationMseEvaluator.Name = "ValidationMseEvaluator"; 137 validationMseEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";138 155 validationMseEvaluator.GetVariableInfo("MSE").ActualName = "ValidationMSE"; 139 validationMseEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 140 validationMseEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 141 MeanSquaredErrorEvaluator testMseEvaluator = new MeanSquaredErrorEvaluator(); 142 testMseEvaluator.Name = "TestMeanSquaredErrorEvaluator"; 143 testMseEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 156 validationMseEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues"; 157 SimpleMSEEvaluator testMseEvaluator = new SimpleMSEEvaluator(); 158 testMseEvaluator.Name = "TestMseEvaluator"; 144 159 testMseEvaluator.GetVariableInfo("MSE").ActualName = "TestMSE"; 145 testMseEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart"; 146 testMseEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd"; 160 testMseEvaluator.GetVariableInfo("Values").ActualName = "TestValues"; 147 161 #endregion 148 162 #region MAPE 149 MeanAbsolutePercentageErrorEvaluator trainingMapeEvaluator = newMeanAbsolutePercentageErrorEvaluator();163 SimpleMeanAbsolutePercentageErrorEvaluator trainingMapeEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator(); 150 164 trainingMapeEvaluator.Name = "TrainingMapeEvaluator"; 151 trainingMapeEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";152 165 trainingMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TrainingMAPE"; 153 trainingMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 154 trainingMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 155 MeanAbsolutePercentageErrorEvaluator validationMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator(); 156 validationMapeEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 166 trainingMapeEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues"; 167 SimpleMeanAbsolutePercentageErrorEvaluator validationMapeEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator(); 157 168 validationMapeEvaluator.Name = "ValidationMapeEvaluator"; 158 169 validationMapeEvaluator.GetVariableInfo("MAPE").ActualName = "ValidationMAPE"; 159 validationMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 160 validationMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 161 MeanAbsolutePercentageErrorEvaluator testMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator(); 162 testMapeEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 170 validationMapeEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues"; 171 SimpleMeanAbsolutePercentageErrorEvaluator testMapeEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator(); 163 172 testMapeEvaluator.Name = "TestMapeEvaluator"; 164 173 testMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TestMAPE"; 165 testMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart"; 166 testMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd"; 174 testMapeEvaluator.GetVariableInfo("Values").ActualName = "TestValues"; 167 175 #endregion 168 176 #region MAPRE 169 MeanAbsolutePercentageOfRangeErrorEvaluator trainingMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator(); 170 trainingMapreEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 177 SimpleMeanAbsolutePercentageOfRangeErrorEvaluator trainingMapreEvaluator = new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator(); 171 178 trainingMapreEvaluator.Name = "TrainingMapreEvaluator"; 172 179 trainingMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "TrainingMAPRE"; 173 trainingMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 174 trainingMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 175 MeanAbsolutePercentageOfRangeErrorEvaluator validationMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator(); 176 validationMapreEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 180 trainingMapreEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues"; 181 SimpleMeanAbsolutePercentageOfRangeErrorEvaluator validationMapreEvaluator = new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator(); 177 182 validationMapreEvaluator.Name = "ValidationMapreEvaluator"; 178 183 validationMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "ValidationMAPRE"; 179 validationMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 180 validationMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 181 MeanAbsolutePercentageOfRangeErrorEvaluator testMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator(); 182 testMapreEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 184 validationMapreEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues"; 185 SimpleMeanAbsolutePercentageOfRangeErrorEvaluator testMapreEvaluator = new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator(); 183 186 testMapreEvaluator.Name = "TestMapreEvaluator"; 184 187 testMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "TestMAPRE"; 185 testMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart"; 186 testMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd"; 188 testMapreEvaluator.GetVariableInfo("Values").ActualName = "TestValues"; 187 189 #endregion MAPRE 188 190 #region R2 189 CoefficientOfDeterminationEvaluator trainingR2Evaluator = new CoefficientOfDeterminationEvaluator(); 190 trainingR2Evaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 191 SimpleR2Evaluator trainingR2Evaluator = new SimpleR2Evaluator(); 191 192 trainingR2Evaluator.Name = "TrainingR2Evaluator"; 192 193 trainingR2Evaluator.GetVariableInfo("R2").ActualName = "TrainingR2"; 193 trainingR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 194 trainingR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 195 CoefficientOfDeterminationEvaluator validationR2Evaluator = new CoefficientOfDeterminationEvaluator(); 196 validationR2Evaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 194 trainingR2Evaluator.GetVariableInfo("Values").ActualName = "TrainingValues"; 195 SimpleR2Evaluator validationR2Evaluator = new SimpleR2Evaluator(); 197 196 validationR2Evaluator.Name = "ValidationR2Evaluator"; 198 197 validationR2Evaluator.GetVariableInfo("R2").ActualName = "ValidationR2"; 199 validationR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 200 validationR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 201 CoefficientOfDeterminationEvaluator testR2Evaluator = new CoefficientOfDeterminationEvaluator(); 202 testR2Evaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 198 validationR2Evaluator.GetVariableInfo("Values").ActualName = "ValidationValues"; 199 SimpleR2Evaluator testR2Evaluator = new SimpleR2Evaluator(); 203 200 testR2Evaluator.Name = "TestR2Evaluator"; 204 201 testR2Evaluator.GetVariableInfo("R2").ActualName = "TestR2"; 205 testR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart"; 206 testR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd"; 202 testR2Evaluator.GetVariableInfo("Values").ActualName = "TestValues"; 207 203 #endregion 208 204 #region VAF 209 VarianceAccountedForEvaluator trainingVAFEvaluator = new VarianceAccountedForEvaluator(); 210 trainingVAFEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 205 SimpleVarianceAccountedForEvaluator trainingVAFEvaluator = new SimpleVarianceAccountedForEvaluator(); 211 206 trainingVAFEvaluator.Name = "TrainingVAFEvaluator"; 212 207 trainingVAFEvaluator.GetVariableInfo("VAF").ActualName = "TrainingVAF"; 213 trainingVAFEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 214 trainingVAFEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 215 VarianceAccountedForEvaluator validationVAFEvaluator = new VarianceAccountedForEvaluator(); 216 validationVAFEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 208 trainingVAFEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues"; 209 SimpleVarianceAccountedForEvaluator validationVAFEvaluator = new SimpleVarianceAccountedForEvaluator(); 217 210 validationVAFEvaluator.Name = "ValidationVAFEvaluator"; 218 211 validationVAFEvaluator.GetVariableInfo("VAF").ActualName = "ValidationVAF"; 219 validationVAFEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 220 validationVAFEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 221 VarianceAccountedForEvaluator testVAFEvaluator = new VarianceAccountedForEvaluator(); 222 testVAFEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 212 validationVAFEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues"; 213 SimpleVarianceAccountedForEvaluator testVAFEvaluator = new SimpleVarianceAccountedForEvaluator(); 223 214 testVAFEvaluator.Name = "TestVAFEvaluator"; 224 215 testVAFEvaluator.GetVariableInfo("VAF").ActualName = "TestVAF"; 225 testVAFEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart"; 226 testVAFEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd"; 216 testVAFEvaluator.GetVariableInfo("Values").ActualName = "TestValues"; 227 217 #endregion 228 218 229 219 solutionProc.AddSubOperator(evaluatorInjector); 220 solutionProc.AddSubOperator(trainingEvaluator); 221 solutionProc.AddSubOperator(validationEvaluator); 222 solutionProc.AddSubOperator(testEvaluator); 230 223 solutionProc.AddSubOperator(trainingMseEvaluator); 231 224 solutionProc.AddSubOperator(validationMseEvaluator); -
trunk/sources/HeuristicLab.Modeling/3.2/HeuristicLab.Modeling-3.2.csproj
r2349 r2351 84 84 <Compile Include="AnalyzerModel.cs" /> 85 85 <Compile Include="BestSolutionStorer.cs" /> 86 <Compile Include="ClassificationProblemInjector.cs" /> 86 <Compile Include="SimpleAccuracyEvaluator.cs" /> 87 <Compile Include="SimpleConfusionMatrixEvaluator.cs" /> 87 88 <Compile Include="SimpleTheilInequalityCoefficientEvaluator.cs" /> 88 89 <Compile Include="SolutionExtractor.cs" /> … … 90 91 <Compile Include="IAnalyzerModel.cs" /> 91 92 <Compile Include="MatrixCreator.cs" /> 93 <Compile Include="TargetClassesCalculator.cs" /> 92 94 <Compile Include="VariableEvaluationImpactCalculator.cs" /> 93 95 <Compile Include="IPredictor.cs" /> -
trunk/sources/HeuristicLab.Modeling/3.2/SimpleAccuracyEvaluator.cs
r2348 r2351 24 24 using HeuristicLab.Data; 25 25 using HeuristicLab.DataAnalysis; 26 using System.Linq; 27 using HeuristicLab.Common; 26 28 27 namespace HeuristicLab.GP.StructureIdentification.Classification { 28 public class AccuracyEvaluator : GPClassificationEvaluatorBase { 29 private const double EPSILON = 1.0E-6; 29 namespace HeuristicLab.Modeling { 30 public class SimpleAccuracyEvaluator : SimpleEvaluatorBase { 31 public override string OutputVariableName { 32 get { 33 return "Accuracy"; 34 } 35 } 30 36 public override string Description { 31 37 get { … … 34 40 } 35 41 36 public AccuracyEvaluator() 37 : base() { 38 AddVariableInfo(new VariableInfo("Accuracy", "The total accuracy of the model (ratio of correctly classified instances to total number of instances)", typeof(DoubleData), VariableKind.New)); 42 public override double Evaluate(double[,] values) { 43 return Calculate(values); 39 44 } 40 45 41 public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) { 42 DoubleData accuracy = GetVariableValue<DoubleData>("Accuracy", scope, false, false); 43 if (accuracy == null) { 44 accuracy = new DoubleData(); 45 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Accuracy"), accuracy)); 46 } 46 public static double Calculate(double[,] values) { 47 int nSamples = values.GetLength(0); 48 int nCorrect = 0; 49 double[] classes = CalculateTargetClasses(values); 50 double[] thresholds = CalculateThresholds(classes); 47 51 48 int nSamples = end - start; 49 int nCorrect = 0; 50 for (int sample = start; sample < end; sample++) { 51 double est = evaluator.Evaluate(sample); 52 double origClass = dataset.GetValue(sample, targetVariable); 52 for (int sample = 0; sample < nSamples; sample++) { 53 double est = values[sample, 0]; 54 double origClass = values[sample, 1]; 53 55 double estClass = double.NaN; 54 56 // if estimation is lower than the smallest threshold value -> estimated class is the lower class … … 65 67 } 66 68 } 67 if ( Math.Abs(estClass - origClass) < EPSILON) nCorrect++;69 if (estClass.IsAlmost(origClass)) nCorrect++; 68 70 } 69 accuracy.Data = nCorrect / (double)nSamples; 71 return nCorrect / (double)nSamples; 72 } 73 74 public static double[] CalculateTargetClasses(double[,] values) { 75 int n = values.GetLength(0); 76 double[] original = new double[n]; 77 for (int i = 0; i < n; i++) original[i] = values[i, 1]; 78 return original.OrderBy(x => x).Distinct().ToArray(); 79 } 80 81 public static double[] CalculateThresholds(double[] targetClasses) { 82 double[] thresholds = new double[targetClasses.Length - 1]; 83 for (int i = 1; i < targetClasses.Length; i++) { 84 thresholds[i - 1] = (targetClasses[i - 1] + targetClasses[i]) / 2.0; 85 } 86 return thresholds; 70 87 } 71 88 } -
trunk/sources/HeuristicLab.Modeling/3.2/SimpleConfusionMatrixEvaluator.cs
r2348 r2351 23 23 using HeuristicLab.Data; 24 24 25 namespace HeuristicLab. GP.StructureIdentification.Classification{26 public class ConfusionMatrixEvaluator : GPClassificationEvaluatorBase {25 namespace HeuristicLab.Modeling { 26 public class SimpleConfusionMatrixEvaluator : OperatorBase { 27 27 public override string Description { 28 28 get { … … 31 31 } 32 32 33 public ConfusionMatrixEvaluator()33 public SimpleConfusionMatrixEvaluator() 34 34 : base() { 35 AddVariableInfo(new VariableInfo("Values", "Original and predicted target values generated by a model", typeof(DoubleMatrixData), VariableKind.In)); 35 36 AddVariableInfo(new VariableInfo("ConfusionMatrix", "The confusion matrix of the model", typeof(IntMatrixData), VariableKind.New)); 36 37 } 37 38 38 public override void Evaluate(IScope scope, ITreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) { 39 public override IOperation Apply(IScope scope) { 40 double[,] values = GetVariableValue<DoubleMatrixData>("Values", scope, true).Data; 41 int[,] confusionMatrix = Calculate(values); 39 42 IntMatrixData matrix = GetVariableValue<IntMatrixData>("ConfusionMatrix", scope, false, false); 40 43 if (matrix == null) { 41 matrix = new IntMatrixData( new int[classes.Length, classes.Length]);44 matrix = new IntMatrixData(confusionMatrix); 42 45 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("ConfusionMatrix"), matrix)); 43 46 } 44 47 45 int nSamples = end - start; 46 for (int sample = start; sample < end; sample++) { 47 double est = evaluator.Evaluate(sample); 48 double origClass = dataset.GetValue(sample, targetVariable); 48 return null; 49 } 50 51 public static int[,] Calculate(double[,] values) { 52 double[] classes = SimpleAccuracyEvaluator.CalculateTargetClasses(values); 53 double[] thresholds = SimpleAccuracyEvaluator.CalculateThresholds(classes); 54 int nSamples = values.GetLength(0); 55 int[,] confusionMatrix = new int[classes.Length, classes.Length]; 56 for (int sample = 0; sample < nSamples; sample++) { 57 double est = values[sample, 0]; 58 double origClass = values[sample, 1]; 49 59 int estClassIndex = -1; 50 60 // if estimation is lower than the smallest threshold value -> estimated class is the lower class … … 70 80 } 71 81 } 72 matrix.Data[origClassIndex, estClassIndex]++;82 confusionMatrix[origClassIndex, estClassIndex]++; 73 83 } 84 return confusionMatrix; 74 85 } 75 86 } -
trunk/sources/HeuristicLab.Modeling/3.2/TargetClassesCalculator.cs
r2348 r2351 26 26 using System.Linq; 27 27 28 namespace HeuristicLab. GP.StructureIdentification.Classification{28 namespace HeuristicLab.Modeling { 29 29 public class TargetClassesCalculator : OperatorBase { 30 30 … … 41 41 42 42 ItemList<DoubleData> classes = new ItemList<DoubleData>(); 43 foreach (double x in dataset.GetVariableValues(targetVariable).Distinct().OrderBy(v=>v)) {43 foreach (double x in dataset.GetVariableValues(targetVariable).Distinct().OrderBy(v => v)) { 44 44 classes.Add(new DoubleData(x)); 45 45 } -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/HeuristicLab.SupportVectorMachines-3.2.csproj
r2349 r2351 83 83 </ItemGroup> 84 84 <ItemGroup> 85 <Compile Include="SupportVectorClassification.cs" /> 85 86 <Compile Include="TimeSeriesSupportVectorRegression.cs" /> 86 87 <Compile Include="PredictorView.cs"> -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorClassification.cs
r2349 r2351 37 37 38 38 namespace HeuristicLab.SupportVectorMachines { 39 public class TimeSeriesSupportVectorRegression : SupportVectorRegression {39 public class SupportVectorClassification : SupportVectorRegression { 40 40 41 public override string Name { get { return "SupportVector Regression - Time Series Prognosis"; } }41 public override string Name { get { return "SupportVectorClassification"; } } 42 42 43 public int MaxTimeOffset { 44 get { return GetVariableInjector().GetVariable("MaxTimeOffset").GetValue<IntData>().Data; } 45 set { GetVariableInjector().GetVariable("MaxTimeOffset").GetValue<IntData>().Data = value; } 46 } 47 48 public int MinTimeOffset { 49 get { return GetVariableInjector().GetVariable("MinTimeOffset").GetValue<IntData>().Data; } 50 set { GetVariableInjector().GetVariable("MinTimeOffset").GetValue<IntData>().Data = value; } 51 } 52 53 public TimeSeriesSupportVectorRegression() 43 public SupportVectorClassification() 54 44 : base() { 55 MaxTimeOffset = 0; 56 MinTimeOffset = 0; 57 } 58 59 protected override IOperator CreateInitialization() { 60 SequentialProcessor seq = new SequentialProcessor(); 61 seq.Name = "Initialization"; 62 seq.AddSubOperator(CreateGlobalInjector()); 63 ProblemInjector probInjector = new ProblemInjector(); 64 seq.AddSubOperator(probInjector); 65 seq.AddSubOperator(new RandomInjector()); 66 67 return seq; 68 } 69 70 protected override VariableInjector CreateGlobalInjector() { 71 VariableInjector injector = base.CreateGlobalInjector(); 72 injector.AddVariable(new HeuristicLab.Core.Variable("MaxTimeOffset", new IntData())); 73 injector.AddVariable(new HeuristicLab.Core.Variable("MinTimeOffset", new IntData())); 74 return injector; 45 SvmType = "NU_SVC"; 46 CostList = new DoubleArrayData(new double[] { 1.0 }); 47 MaxCostIndex = 1; 75 48 } 76 49 … … 83 56 SequentialProcessor seqProc = new SequentialProcessor(); 84 57 85 SimpleTheilInequalityCoefficientEvaluator trainingTheilUCalculator = new SimpleTheilInequalityCoefficientEvaluator(); 86 trainingTheilUCalculator.GetVariableInfo("Values").ActualName = "TrainingValues"; 87 trainingTheilUCalculator.GetVariableInfo("TheilInequalityCoefficient").ActualName = "TrainingTheilInequalityCoefficient"; 88 SimpleTheilInequalityCoefficientEvaluator validationTheilUCalculator = new SimpleTheilInequalityCoefficientEvaluator(); 89 validationTheilUCalculator.GetVariableInfo("Values").ActualName = "ValidationValues"; 90 validationTheilUCalculator.GetVariableInfo("TheilInequalityCoefficient").ActualName = "ValidationTheilInequalityCoefficient"; 91 SimpleTheilInequalityCoefficientEvaluator testTheilUCalculator = new SimpleTheilInequalityCoefficientEvaluator(); 92 testTheilUCalculator.GetVariableInfo("Values").ActualName = "TestValues"; 93 testTheilUCalculator.GetVariableInfo("TheilInequalityCoefficient").ActualName = "TestTheilInequalityCoefficient"; 58 SupportVectorEvaluator trainingEvaluator = new SupportVectorEvaluator(); 59 trainingEvaluator.Name = "TrainingSimpleEvaluator"; 60 trainingEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 61 trainingEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 62 trainingEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues"; 94 63 95 seqProc.AddSubOperator(trainingTheilUCalculator); 96 seqProc.AddSubOperator(validationTheilUCalculator); 97 seqProc.AddSubOperator(testTheilUCalculator); 64 SimpleAccuracyEvaluator trainingAccuracyEvaluator = new SimpleAccuracyEvaluator(); 65 trainingAccuracyEvaluator.Name = "TrainingAccuracyEvaluator"; 66 trainingAccuracyEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues"; 67 trainingAccuracyEvaluator.GetVariableInfo("Accuracy").ActualName = "TrainingAccuracy"; 68 SimpleAccuracyEvaluator validationAccuracyEvaluator = new SimpleAccuracyEvaluator(); 69 validationAccuracyEvaluator.Name = "ValidationAccuracyEvaluator"; 70 validationAccuracyEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues"; 71 validationAccuracyEvaluator.GetVariableInfo("Accuracy").ActualName = "ValidationAccuracy"; 72 SimpleAccuracyEvaluator testAccuracyEvaluator = new SimpleAccuracyEvaluator(); 73 testAccuracyEvaluator.Name = "TestAccuracyEvaluator"; 74 testAccuracyEvaluator.GetVariableInfo("Values").ActualName = "TestValues"; 75 testAccuracyEvaluator.GetVariableInfo("Accuracy").ActualName = "TestAccuracy"; 76 77 SimpleConfusionMatrixEvaluator trainingConfusionMatrixEvaluator = new SimpleConfusionMatrixEvaluator(); 78 trainingConfusionMatrixEvaluator.Name = "TrainingConfusionMatrixEvaluator"; 79 trainingConfusionMatrixEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues"; 80 trainingConfusionMatrixEvaluator.GetVariableInfo("ConfusionMatrix").ActualName = "TrainingConfusionMatrix"; 81 SimpleConfusionMatrixEvaluator validationConfusionMatrixEvaluator = new SimpleConfusionMatrixEvaluator(); 82 validationConfusionMatrixEvaluator.Name = "ValidationConfusionMatrixEvaluator"; 83 validationConfusionMatrixEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues"; 84 validationConfusionMatrixEvaluator.GetVariableInfo("ConfusionMatrix").ActualName = "ValidationConfusionMatrix"; 85 SimpleConfusionMatrixEvaluator testConfusionMatrixEvaluator = new SimpleConfusionMatrixEvaluator(); 86 testConfusionMatrixEvaluator.Name = "TestConfusionMatrixEvaluator"; 87 testConfusionMatrixEvaluator.GetVariableInfo("Values").ActualName = "TestValues"; 88 testConfusionMatrixEvaluator.GetVariableInfo("ConfusionMatrix").ActualName = "TestConfusionMatrix"; 89 90 seqProc.AddSubOperator(trainingEvaluator); 91 seqProc.AddSubOperator(trainingAccuracyEvaluator); 92 seqProc.AddSubOperator(validationAccuracyEvaluator); 93 seqProc.AddSubOperator(testAccuracyEvaluator); 94 seqProc.AddSubOperator(trainingConfusionMatrixEvaluator); 95 seqProc.AddSubOperator(validationConfusionMatrixEvaluator); 96 seqProc.AddSubOperator(testConfusionMatrixEvaluator); 98 97 99 98 seq.AddSubOperator(seqSubScopeProc); … … 109 108 IAnalyzerModel model = base.CreateSVMModel(bestModelScope); 110 109 111 model.SetResult("Training TheilInequalityCoefficient", bestModelScope.GetVariableValue<DoubleData>("TrainingTheilInequalityCoefficient", false).Data);112 model.SetResult("Validation TheilInequalityCoefficient", bestModelScope.GetVariableValue<DoubleData>("ValidationTheilInequalityCoefficient", false).Data);113 model.SetResult("Test TheilInequalityCoefficient", bestModelScope.GetVariableValue<DoubleData>("TestTheilInequalityCoefficient", false).Data);110 model.SetResult("TrainingAccuracy", bestModelScope.GetVariableValue<DoubleData>("TrainingAccuracy", false).Data); 111 model.SetResult("ValidationAccuracy", bestModelScope.GetVariableValue<DoubleData>("ValidationAccuracy", false).Data); 112 model.SetResult("TestAccuracy", bestModelScope.GetVariableValue<DoubleData>("TestAccuracy", false).Data); 114 113 115 114 return model; -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorRegression.cs
r2349 r2351 105 105 get { return GetVariableInjector().GetVariable("MaxGammaIndex").GetValue<IntData>().Data; } 106 106 set { GetVariableInjector().GetVariable("MaxGammaIndex").GetValue<IntData>().Data = value; } 107 } 108 109 public string SvmType { 110 get { return GetVariableInjector().GetVariable("Type").GetValue<StringData>().Data; } 111 set { GetVariableInjector().GetVariable("Type").GetValue<StringData>().Data = value; } 107 112 } 108 113
Note: See TracChangeset
for help on using the changeset viewer.