- Timestamp:
- 01/02/10 18:10:15 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.GP.StructureIdentification.ConditionalEvaluation/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification.ConditionalEvaluation/3.3/ConditionalEvaluatorBase.cs
r2577 r2578 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.DataAnalysis; 29 using HeuristicLab.GP.Interfaces; 30 using HeuristicLab.Modeling; 29 31 30 32 namespace HeuristicLab.GP.StructureIdentification.ConditionalEvaluation { … … 40 42 } 41 43 42 public override void Evaluate(IScope scope, I TreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end) {44 public override void Evaluate(IScope scope, IFunctionTree tree, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end) { 43 45 int maxTimeOffset = GetVariableValue<IntData>("MaxTimeOffset", scope, true).Data; 44 46 int minTimeOffset = GetVariableValue<IntData>("MinTimeOffset", scope, true).Data; 45 47 int conditionVariable = GetVariableValue<IntData>("ConditionVariable", scope, true).Data; 46 48 47 int skippedSampels = 0; 49 var rows = from row in Enumerable.Range(start, end - start) 50 // check if condition variable is true between sample - minTimeOffset and sample - maxTimeOffset 51 // => select rows where the value of the condition variable is different from zero in the whole range 52 where (from neighbour in Enumerable.Range(row + minTimeOffset, maxTimeOffset - minTimeOffset) 53 let value = dataset.GetValue(neighbour, conditionVariable) 54 where value == 0 55 select neighbour).Any() == false 56 select row; 57 48 58 // store original and estimated values in a double array 49 double[,] values = new double[end - start, 2]; 50 for (int sample = start; sample < end; sample++) { 51 // check if condition variable is true between sample - minTimeOffset and sample - maxTimeOffset 52 bool skip = false; 53 for (int checkIndex = sample + minTimeOffset; checkIndex <= sample + maxTimeOffset && !skip; checkIndex++) { 54 if (dataset.GetValue(checkIndex, conditionVariable) == 0) { 55 skip = true; 56 skippedSampels++; 57 } 58 } 59 if (!skip) { 60 double original = dataset.GetValue(sample, targetVariable); 61 double estimated = evaluator.Evaluate(sample); 62 63 values[sample - start - skippedSampels, 0] = estimated; 64 values[sample - start - skippedSampels, 1] = original; 65 } 66 } 67 //needed because otherwise the array is too large and therefore the sample count is incorrect during calculation 68 ResizeArray(ref values, 2, end - start - skippedSampels); 69 59 double[,] values = Matrix<double>.Create( 60 evaluator.Evaluate(dataset, tree, rows).ToArray(), 61 (from row in rows select dataset.GetValue(row, targetVariable)).ToArray()); 70 62 71 63 // calculate quality value … … 78 70 } 79 71 qualityData.Data = quality; 80 scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data -= skippedSampels; 81 } 82 83 84 private void ResizeArray(ref double[,] original, int cols, int rows) { 85 double[,] newArray = new double[rows, cols]; 86 Array.Copy(original, newArray, cols * rows); 87 original = newArray; 72 scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data -= (end - start) - rows.Count(); 88 73 } 89 74 -
trunk/sources/HeuristicLab.GP.StructureIdentification.ConditionalEvaluation/3.3/ConditionalSimpleEvaluator.cs
r2577 r2578 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.DataAnalysis; 29 using HeuristicLab.GP.Interfaces; 29 30 30 31 namespace HeuristicLab.GP.StructureIdentification.ConditionalEvaluation { … … 38 39 } 39 40 40 public override void Evaluate(IScope scope, I TreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end) {41 public override void Evaluate(IScope scope, IFunctionTree tree, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end) { 41 42 ItemList values = GetVariableValue<ItemList>("Values", scope, false, false); 42 43 if (values == null) { … … 53 54 int minTimeOffset = GetVariableValue<IntData>("MinTimeOffset", scope, true).Data; 54 55 int conditionVariable = GetVariableValue<IntData>("ConditionVariable", scope, true).Data; 55 int skippedSampels = 0;56 56 57 for (int sample = start; sample < end; sample++) { 58 // check if condition variable is true between sample - minTimeOffset and sample - maxTimeOffset 59 bool skip = false; 60 for (int checkIndex = sample + minTimeOffset; checkIndex <= sample + maxTimeOffset && !skip ; checkIndex++) { 61 if (dataset.GetValue(checkIndex, conditionVariable) == 0) { 62 skip = true; 63 skippedSampels++; 64 } 65 } 66 if (!skip) { 67 ItemList row = new ItemList(); 68 double estimated = evaluator.Evaluate(sample); 69 double original = dataset.GetValue(sample, targetVariable); 70 71 row.Add(new DoubleData(estimated)); 72 row.Add(new DoubleData(original)); 73 values.Add(row); 74 } 57 var rows = from row in Enumerable.Range(start, end - start) 58 // check if condition variable is true between sample - minTimeOffset and sample - maxTimeOffset 59 // => select rows where the value of the condition variable is different from zero in the whole range 60 where (from neighbour in Enumerable.Range(row + minTimeOffset, maxTimeOffset - minTimeOffset) 61 let value = dataset.GetValue(neighbour, conditionVariable) 62 where value == 0 63 select neighbour).Any() == false 64 select row; 65 66 67 double[] estimatedValues = evaluator.Evaluate(dataset, tree, rows).ToArray(); 68 double[] originalValues = (from row in rows select dataset.GetValue(row, targetVariable)).ToArray(); 69 for (int i = 0; i < rows.Count(); i++) { 70 ItemList row = new ItemList(); 71 row.Add(new DoubleData(estimatedValues[i])); 72 row.Add(new DoubleData(originalValues[i])); 73 values.Add(row); 75 74 } 76 scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data -= skippedSampels; 75 76 scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data -= (end - start) - rows.Count(); 77 77 } 78 78 }
Note: See TracChangeset
for help on using the changeset viewer.