- Timestamp:
- 07/28/08 18:46:02 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Functions/BakedFunctionTree.cs
r363 r396 48 48 class BakedFunctionTree : ItemBase, IFunctionTree { 49 49 private List<LightWeightFunction> linearRepresentation; 50 internal List<LightWeightFunction> LinearRepresentation { 51 get { 52 FlattenVariables(); 53 FlattenTrees(); 54 return linearRepresentation; 55 } 56 } 50 57 private bool treesExpanded = false; 51 58 private List<IFunctionTree> subTrees; 52 59 private bool variablesExpanded = false; 53 60 private List<IVariable> variables; 61 private BakedTreeEvaluator evaluator; 54 62 55 63 public BakedFunctionTree() { … … 262 270 } 263 271 264 public void PrepareEvaluation(Dataset dataset) { 265 FlattenVariables(); 266 FlattenTrees(); 267 BakedTreeEvaluator.ResetEvaluator(dataset, linearRepresentation); 268 } 269 270 public double Evaluate(int sampleIndex) { 271 return BakedTreeEvaluator.Evaluate(sampleIndex); 272 } 273 272 public IEvaluator CreateEvaluator(Dataset dataset) { 273 return new BakedTreeEvaluator(dataset); 274 } 274 275 275 276 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { -
trunk/sources/HeuristicLab.Functions/BakedTreeEvaluator.cs
r365 r396 29 29 30 30 namespace HeuristicLab.Functions { 31 internal static class BakedTreeEvaluator {31 internal class BakedTreeEvaluator : IEvaluator { 32 32 private const int MAX_TREE_SIZE = 4096; 33 33 … … 40 40 } 41 41 42 private static Instr[] codeArr; 43 private static int PC; 44 private static Dataset dataset; 45 private static int sampleIndex; 46 47 48 static BakedTreeEvaluator() { 42 private Instr[] codeArr; 43 private int PC; 44 private Dataset dataset; 45 private int sampleIndex; 46 47 48 public BakedTreeEvaluator(Dataset dataset) { 49 this.dataset = dataset; 49 50 codeArr = new Instr[MAX_TREE_SIZE]; 50 51 for(int i = 0; i < MAX_TREE_SIZE; i++) { … … 53 54 } 54 55 55 public static void ResetEvaluator(Dataset dataset, List<LightWeightFunction> linearRepresentation) { 56 public void ResetEvaluator(IFunctionTree functionTree) { 57 List<LightWeightFunction> linearRepresentation = ((BakedFunctionTree)functionTree).LinearRepresentation; 56 58 int i = 0; 57 BakedTreeEvaluator.dataset = dataset;58 59 foreach(LightWeightFunction f in linearRepresentation) { 59 60 TranslateToInstr(f, codeArr[i++]); … … 61 62 } 62 63 63 private staticInstr TranslateToInstr(LightWeightFunction f, Instr instr) {64 private Instr TranslateToInstr(LightWeightFunction f, Instr instr) { 64 65 instr.arity = f.arity; 65 66 instr.symbol = EvaluatorSymbolTable.MapFunction(f.functionType); … … 79 80 } 80 81 81 internal static double Evaluate(int sampleIndex) {82 public double Evaluate(int sampleIndex) { 82 83 PC = 0; 83 BakedTreeEvaluator.sampleIndex = sampleIndex;84 this.sampleIndex = sampleIndex; 84 85 return EvaluateBakedCode(); 85 86 } 86 87 87 private staticdouble EvaluateBakedCode() {88 private double EvaluateBakedCode() { 88 89 Instr currInstr = codeArr[PC++]; 89 90 switch(currInstr.symbol) { -
trunk/sources/HeuristicLab.Functions/HeuristicLab.Functions.csproj
r365 r396 58 58 <Compile Include="Differential.cs" /> 59 59 <Compile Include="GreaterThan.cs" /> 60 <Compile Include="IEvaluator.cs" /> 60 61 <Compile Include="IfThenElse.cs"> 61 62 <SubType>Code</SubType> -
trunk/sources/HeuristicLab.Functions/IFunctionTree.cs
r363 r396 40 40 void RemoveSubTree(int index); 41 41 42 void PrepareEvaluation(Dataset dataset); 43 double Evaluate(int sampleIndex); 42 IEvaluator CreateEvaluator(Dataset dataset); 44 43 } 45 44 } -
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/CoefficientOfDeterminationEvaluator.cs
r367 r396 49 49 double originalDeviationTotalSumOfSquares = 0.0; 50 50 double targetMean = dataset.GetMean(targetVariable, trainingStart, trainingEnd); 51 functionTree.PrepareEvaluation(dataset);52 51 for(int sample = trainingStart; sample < trainingEnd; sample++) { 53 double estimated = functionTree.Evaluate(sample);52 double estimated = evaluator.Evaluate(sample); 54 53 double original = dataset.GetValue(sample, targetVariable); 55 54 if(!double.IsNaN(original) && !double.IsInfinity(original)) { -
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/EarlyStoppingMeanSquaredErrorEvaluator.cs
r367 r396 60 60 double errorsSquaredSum = 0; 61 61 double targetMean = dataset.GetMean(targetVariable, trainingStart, trainingEnd); 62 functionTree.PrepareEvaluation(dataset);63 62 for(int sample = trainingStart; sample < trainingEnd; sample++) { 64 double estimated = functionTree.Evaluate(sample);63 double estimated = evaluator.Evaluate(sample); 65 64 double original = dataset.GetValue(sample, targetVariable); 66 65 if(double.IsNaN(estimated) || double.IsInfinity(estimated)) { -
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/GPEvaluatorBase.cs
r363 r396 35 35 protected int treeSize; 36 36 protected double totalEvaluatedNodes; 37 protected IEvaluator evaluator; 37 38 38 39 public GPEvaluatorBase() … … 56 57 this.treeSize = scope.GetVariableValue<IntData>("TreeSize", false).Data; 57 58 this.totalEvaluatedNodes = scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data; 59 if(evaluator == null) evaluator = functionTree.CreateEvaluator(dataset); 60 evaluator.ResetEvaluator(functionTree); 58 61 double result = Evaluate(scope, functionTree, targetVariable, dataset); 59 62 -
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MCCEvaluator.cs
r367 r396 58 58 double negative = 0; 59 59 double targetMean = dataset.GetMean(targetVariable, trainingStart, trainingEnd); 60 functionTree.PrepareEvaluation(dataset);61 60 for(int sample = trainingStart; sample < trainingEnd; sample++) { 62 double est = functionTree.Evaluate(sample);61 double est = evaluator.Evaluate(sample); 63 62 double orig = dataset.GetValue(sample, targetVariable); 64 63 if(double.IsNaN(est) || double.IsInfinity(est)) { -
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MeanAbsolutePercentageErrorEvaluator.cs
r395 r396 47 47 int trainingEnd = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data; 48 48 double errorsSum = 0.0; 49 functionTree.PrepareEvaluation(dataset);50 49 for(int sample = trainingStart; sample < trainingEnd; sample++) { 51 double estimated = functionTree.Evaluate(sample);50 double estimated = evaluator.Evaluate(sample); 52 51 double original = dataset.GetValue(sample, targetVariable); 53 52 if(!double.IsNaN(original) && !double.IsInfinity(original)) { -
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MeanSquaredErrorEvaluator.cs
r367 r396 59 59 } 60 60 } 61 62 functionTree.PrepareEvaluation(dataset);63 61 for(int sample = trainingStart; sample < trainingEnd; sample++) { 64 double estimated = functionTree.Evaluate(sample);62 double estimated = evaluator.Evaluate(sample); 65 63 double original = dataset.GetValue(sample, targetVariable); 66 64 if(double.IsNaN(estimated) || double.IsInfinity(estimated)) { -
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/SimpleEvaluator.cs
r363 r396 34 34 protected int treeSize; 35 35 protected double totalEvaluatedNodes; 36 private IEvaluator evaluator; 36 37 37 38 public SimpleEvaluator() … … 66 67 } 67 68 values.Clear(); 68 functionTree.PrepareEvaluation(dataset); 69 if(evaluator == null) evaluator = functionTree.CreateEvaluator(dataset); 70 evaluator.ResetEvaluator(functionTree); 69 71 for(int sample = trainingStart; sample < trainingEnd; sample++) { 70 72 ItemList row = new ItemList(); 71 row.Add(new DoubleData( functionTree.Evaluate(sample)));73 row.Add(new DoubleData(evaluator.Evaluate(sample))); 72 74 row.Add(new DoubleData(dataset.GetValue(sample, targetVariable))); 73 75 values.Add(row); -
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/TheilInequalityCoefficientEvaluator.cs
r395 r396 51 51 double estimatedSquaredSum = 0.0; 52 52 double originalSquaredSum = 0.0; 53 functionTree.PrepareEvaluation(dataset);54 53 for(int sample = trainingStart; sample < trainingEnd; sample++) { 55 54 double prevValue = 0.0; 56 55 if(difference) prevValue = dataset.GetValue(sample - 1, targetVariable); 57 double estimatedChange = functionTree.Evaluate(sample) - prevValue;56 double estimatedChange = evaluator.Evaluate(sample) - prevValue; 58 57 double originalChange = dataset.GetValue(sample, targetVariable) - prevValue; 59 58 if(!double.IsNaN(originalChange) && !double.IsInfinity(originalChange)) { -
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/VarianceAccountedForEvaluator.cs
r367 r396 59 59 double[] originalTargetVariableValues = new double[trainingEnd-trainingStart]; 60 60 double targetMean = dataset.GetMean(targetVariable, trainingStart, trainingEnd); 61 functionTree.PrepareEvaluation(dataset);62 61 for(int sample = trainingStart; sample < trainingEnd; sample++) { 63 double estimated = functionTree.Evaluate(sample);62 double estimated = evaluator.Evaluate(sample); 64 63 double original = dataset.GetValue(sample, targetVariable); 65 64 if(!double.IsNaN(original) && !double.IsInfinity(original)) {
Note: See TracChangeset
for help on using the changeset viewer.