- Timestamp:
- 08/10/08 11:08:07 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/SimpleEvaluator.cs
r396 r479 31 31 32 32 namespace HeuristicLab.StructureIdentification { 33 public class SimpleEvaluator : OperatorBase { 34 protected int treeSize; 35 protected double totalEvaluatedNodes; 36 private IEvaluator evaluator; 37 33 public class SimpleEvaluator : GPEvaluatorBase { 34 private ItemList values; 38 35 public SimpleEvaluator() 39 36 : base() { 40 AddVariableInfo(new VariableInfo("FunctionTree", "The function tree that should be evaluated", typeof(IFunctionTree), VariableKind.In));41 AddVariableInfo(new VariableInfo("TreeSize", "Size (number of nodes) of the tree to evaluate", typeof(IntData), VariableKind.In));42 AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In));43 AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In));44 AddVariableInfo(new VariableInfo("TotalEvaluatedNodes", "Number of evaluated nodes", typeof(DoubleData), VariableKind.In | VariableKind.Out));45 AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of training samples in dataset", typeof(IntData), VariableKind.In));46 AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "End index of training samples in dataset", typeof(IntData), VariableKind.In));47 37 AddVariableInfo(new VariableInfo("Values", "The values of the target variable as predicted by the model and the original value of the target variable", typeof(ItemList), VariableKind.New | VariableKind.Out)); 48 38 } 49 39 50 40 public override IOperation Apply(IScope scope) { 51 int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data; 52 Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true); 53 IFunctionTree functionTree = GetVariableValue<IFunctionTree>("FunctionTree", scope, true); 54 this.treeSize = scope.GetVariableValue<IntData>("TreeSize", false).Data; 55 this.totalEvaluatedNodes = scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data; 56 int trainingStart = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data; 57 int trainingEnd = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data; 58 59 ItemList values = GetVariableValue<ItemList>("Values", scope, false, false); 41 values = GetVariableValue<ItemList>("Values", scope, false, false); 60 42 if(values == null) { 61 43 values = new ItemList(); … … 67 49 } 68 50 values.Clear(); 69 if(evaluator == null) evaluator = functionTree.CreateEvaluator(dataset); 70 evaluator.ResetEvaluator(functionTree); 71 for(int sample = trainingStart; sample < trainingEnd; sample++) { 51 return base.Apply(scope); 52 } 53 54 public override double Evaluate(int start, int end) { 55 for(int sample = start; sample < end; sample++) { 72 56 ItemList row = new ItemList(); 73 row.Add(new DoubleData( evaluator.Evaluate(sample)));74 row.Add(new DoubleData( dataset.GetValue(sample, targetVariable)));57 row.Add(new DoubleData(GetEstimatedValue(sample))); 58 row.Add(new DoubleData(GetOriginalValue(sample))); 75 59 values.Add(row); 76 60 } 77 scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * (trainingEnd - trainingStart); 78 return null; 61 return double.NaN; 79 62 } 80 63 }
Note: See TracChangeset
for help on using the changeset viewer.