Changeset 2043 for trunk/sources/HeuristicLab.SupportVectorMachines/3.2/VariableQualityImpactCalculator.cs
- Timestamp:
- 06/15/09 16:46:25 (15 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/VariableQualityImpactCalculator.cs
r2042 r2043 29 29 using System.Linq; 30 30 31 namespace HeuristicLab. GP.StructureIdentification{31 namespace HeuristicLab.SupportVectorMachines { 32 32 public class VariableQualityImpactCalculator : HeuristicLab.Modeling.VariableQualityImpactCalculator { 33 33 34 34 public VariableQualityImpactCalculator() 35 35 : base() { 36 AddVariableInfo(new VariableInfo("TreeEvaluator", "The evaluator that should be used to evaluate the expression tree", typeof(ITreeEvaluator), VariableKind.In)); 37 AddVariableInfo(new VariableInfo("FunctionTree", "The function tree that should be evaluated", typeof(IFunctionTree), VariableKind.In)); 38 AddVariableInfo(new VariableInfo("TreeSize", "Size (number of nodes) of the tree to evaluate", typeof(IntData), VariableKind.In)); 39 AddVariableInfo(new VariableInfo("PunishmentFactor", "Punishment factor for invalid estimations", typeof(DoubleData), VariableKind.In)); 36 AddVariableInfo(new VariableInfo("SVMModel", "The model that should be evaluated", typeof(SVMModel), VariableKind.In)); 40 37 } 41 38 42 protected override double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, int start, int end) { 43 ITreeEvaluator evaluator = GetVariableValue<ITreeEvaluator>("TreeEvaluator", scope, true); 44 IFunctionTree tree = GetVariableValue<IFunctionTree>("FunctionTree", scope, true); 45 double punishmentFactor = GetVariableValue<DoubleData>("PunishmentFactor", scope, true).Data; 46 evaluator.PrepareForEvaluation(dataset, targetVariable, start, end, punishmentFactor, tree); 39 protected override double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end) { 40 SVMModel model = GetVariableValue<SVMModel>("SVMModel", scope, true); 41 SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures, targetVariable, start, end); 42 SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, model.RangeTransform); 47 43 48 double[,] result = new double[end - start,2];49 for (int i = start; i < end; i++) {50 result[i - start, 0] = dataset.GetValue(i, targetVariable);51 result[i - start,1] = evaluator.Evaluate(i);44 double[,] values = new double[end - start, 2]; 45 for (int i = 0; i < end - start; i++) { 46 values[i, 0] = SVM.Prediction.Predict(model.Model, scaledProblem.X[i]); 47 values[i, 1] = dataset.GetValue(start + i,targetVariable); 52 48 } 53 49 54 return HeuristicLab.Modeling.SimpleMSEEvaluator.Calculate( result);50 return HeuristicLab.Modeling.SimpleMSEEvaluator.Calculate(values); 55 51 } 56 52 }
Note: See TracChangeset
for help on using the changeset viewer.