Changeset 2722
- Timestamp:
- 01/29/10 15:22:18 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/OffspringSelectionGPTimeSeriesPrognosis.cs
r2577 r2722 56 56 funLibInjector.GetVariable("Differentials").Value = new BoolData(true); 57 57 seq.AddSubOperator(funLibInjector); 58 seq.AddSubOperator(new HL3TreeEvaluatorInjector());58 seq.AddSubOperator(new ScalingTreeEvaluatorInjector()); 59 59 op.OperatorGraph.AddOperator(seq); 60 60 op.OperatorGraph.InitialOperator = seq; -
trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/StandardGPTimeSeriesPrognosis.cs
r2577 r2722 56 56 funLibInjector.GetVariable("Differentials").Value = new BoolData(true); 57 57 seq.AddSubOperator(funLibInjector); 58 seq.AddSubOperator(new HL3TreeEvaluatorInjector());58 seq.AddSubOperator(new ScalingTreeEvaluatorInjector()); 59 59 op.OperatorGraph.AddOperator(seq); 60 60 op.OperatorGraph.InitialOperator = seq; -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/DefaultStructureIdentificationOperators.cs
r2683 r2722 39 39 SequentialProcessor seq = new SequentialProcessor(); 40 40 seq.AddSubOperator(new DefaultFunctionLibraryInjector()); 41 seq.AddSubOperator(new HL3TreeEvaluatorInjector());41 seq.AddSubOperator(new ScalingTreeEvaluatorInjector()); 42 42 op.OperatorGraph.AddOperator(seq); 43 43 op.OperatorGraph.InitialOperator = seq; … … 127 127 seqSubScopeProc.AddSubOperator(solutionProc); 128 128 129 HL3TreeEvaluatorInjector evaluatorInjector = new HL3TreeEvaluatorInjector();129 ScalingTreeEvaluatorInjector evaluatorInjector = new ScalingTreeEvaluatorInjector(); 130 130 evaluatorInjector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(1000.0))); 131 131 evaluatorInjector.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; … … 160 160 VariableNamesExtractor namesExtractor = new VariableNamesExtractor(); 161 161 namesExtractor.GetVariableInfo("VariableNames").ActualName = "InputVariableNames"; 162 PredictorBuilder predictorBuilder = new PredictorBuilder(); 163 predictorBuilder.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 162 LinearScalingPredictorBuilder predictorBuilder = new LinearScalingPredictorBuilder(); 164 163 165 164 solutionProc.AddSubOperator(namesExtractor); -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/HeuristicLab.GP.StructureIdentification-3.3.csproj
r2682 r2722 85 85 <Compile Include="BaseClasses\FunctionTreeBase.cs" /> 86 86 <Compile Include="BaseClasses\TreeEvaluatorBase.cs" /> 87 <Compile Include="LinearScalingPredictorBuilder.cs" /> 87 88 <Compile Include="Evaluators\VariableFrequencyBasedImpactCalculator.cs" /> 88 89 <Compile Include="ScalingTreeEvaluator.cs" /> -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Predictor.cs
r2619 r2722 52 52 53 53 public override IEnumerable<double> Predict(Dataset input, int start, int end) { 54 if (input == null) throw new ArgumentNullException(); 55 if (start < 0 || end <= start) throw new ArgumentException("start must be larger than zero and strictly smaller than end"); 56 if (end > input.Rows) throw new ArgumentOutOfRangeException("number of rows in input is smaller then end"); 54 57 treeEvaluator.UpperEvaluationLimit = UpperPredictionLimit; 55 58 treeEvaluator.LowerEvaluationLimit = LowerPredictionLimit; 56 59 57 if (start < 0 || end <= start) throw new ArgumentException("start must be larger than zero and strictly smaller than end");58 if (end > input.Rows) throw new ArgumentOutOfRangeException("number of rows in input is smaller then end");59 60 return treeEvaluator.Evaluate(input, functionTree.FunctionTree, Enumerable.Range(start, end - start)); 60 61 } -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/ScalingTreeEvaluator.cs
r2640 r2722 51 51 this.sampleIndex = sampleIndex; 52 52 double estimation = EvaluateBakedCode(); 53 if (double.IsPositiveInfinity(estimation)) estimation = UpperEvaluationLimit;54 else if (double.IsNegativeInfinity(estimation)) estimation = LowerEvaluationLimit;55 else if (double.IsNaN(estimation)) estimation = UpperEvaluationLimit;53 //if (double.IsPositiveInfinity(estimation)) estimation = UpperEvaluationLimit; 54 //else if (double.IsNegativeInfinity(estimation)) estimation = LowerEvaluationLimit; 55 //else if (double.IsNaN(estimation)) estimation = UpperEvaluationLimit; 56 56 return estimation; 57 57 } 58 58 59 59 public override IEnumerable<double> Evaluate(Dataset dataset, IFunctionTree tree, IEnumerable<int> rows) { 60 double[] result = base.Evaluate(dataset, tree, rows).ToArray();61 60 int targetVariableIndex = dataset.GetVariableIndex(targetVariable); 62 double tMean = dataset.GetMean(targetVariableIndex); 63 double xMean = Statistics.Mean(result); 64 double sumXT = 0; 65 double sumXX = 0; 66 for (int i = 0; i < result.Length; i++) { 67 double x = result[i]; 68 double t = dataset.GetValue(rows.ElementAt(i), targetVariableIndex); 69 sumXT += (x - xMean) * (t - tMean); 70 sumXX += (x - xMean) * (x - xMean); 61 // evaluate for all rows 62 PrepareForEvaluation(dataset, tree); 63 var result = (from row in rows 64 let y = Evaluate(row) 65 let y_ = dataset.GetValue(row, targetVariableIndex) 66 select new { Row = row, Estimation = y, Target = y_ }).ToArray(); 67 68 // calculate alpha and beta on the subset of rows with valid values 69 var filteredResult = result.Where(x => IsValidValue(x.Target) && IsValidValue(x.Estimation)); 70 var target = filteredResult.Select(x => x.Target); 71 var estimation = filteredResult.Select(x => x.Estimation); 72 double a, b; 73 if (filteredResult.Count() > 2) { 74 double tMean = target.Sum() / target.Count(); 75 double xMean = estimation.Sum() / estimation.Count(); 76 double sumXT = 0; 77 double sumXX = 0; 78 foreach (var r in result) { 79 double x = r.Estimation; 80 double t = r.Target; 81 sumXT += (x - xMean) * (t - tMean); 82 sumXX += (x - xMean) * (x - xMean); 83 } 84 b = sumXT / sumXX; 85 a = tMean - b * xMean; 86 } else { 87 b = 1.0; 88 a = 0.0; 71 89 } 72 double b = sumXT / sumXX; 73 double a = tMean - b * xMean; 74 for (int i = 0; i < result.Length; i++) { 75 double scaledResult = result[i] * b + a; 76 scaledResult = Math.Min(Math.Max(scaledResult, LowerEvaluationLimit), UpperEvaluationLimit); 77 if (double.IsNaN(scaledResult)) scaledResult = UpperEvaluationLimit; 78 result[i] = scaledResult; 79 } 80 return result; 90 // return scaled results 91 return from r in result 92 let scaledR = Math.Min(Math.Max(r.Estimation * b + a, LowerEvaluationLimit), UpperEvaluationLimit) 93 select double.IsNaN(scaledR) ? UpperEvaluationLimit : scaledR; 94 } 95 96 private bool IsValidValue(double d) { 97 return !double.IsInfinity(d) && !double.IsNaN(d); 81 98 } 82 99
Note: See TracChangeset
for help on using the changeset viewer.