Changeset 2977 for trunk/sources
- Timestamp:
- 03/09/10 09:40:52 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 added
- 2 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/DefaultStructureIdentificationOperators.cs
r2722 r2977 39 39 SequentialProcessor seq = new SequentialProcessor(); 40 40 seq.AddSubOperator(new DefaultFunctionLibraryInjector()); 41 seq.AddSubOperator(new ScalingTreeEvaluatorInjector());41 seq.AddSubOperator(new HL3TreeEvaluatorInjector()); 42 42 op.OperatorGraph.AddOperator(seq); 43 43 op.OperatorGraph.InitialOperator = seq; … … 46 46 47 47 public static IOperator CreateInitialPopulationEvaluator() { 48 MeanSquaredErrorEvaluator eval = new MeanSquaredErrorEvaluator(); 49 eval.Name = "Evaluator"; 50 eval.GetVariableInfo("MSE").ActualName = "Quality"; 48 CombinedOperator combinedOp = new CombinedOperator(); 49 combinedOp.Name = "Evaluator"; 50 SequentialProcessor seq = new SequentialProcessor(); 51 52 SimpleEvaluator eval = new SimpleEvaluator(); 53 eval.GetVariableInfo("Values").ActualName = "TrainingValues"; 51 54 eval.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart"; 52 55 eval.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd"; 53 return eval; 56 57 LinearScaler scaler = new LinearScaler(); 58 scaler.GetVariableInfo("Values").ActualName = "TrainingValues"; 59 60 SimpleMSEEvaluator mseEval = new SimpleMSEEvaluator(); 61 mseEval.GetVariableInfo("Values").ActualName = "TrainingValues"; 62 mseEval.GetVariableInfo("MSE").ActualName = "Quality"; 63 64 seq.AddSubOperator(eval); 65 seq.AddSubOperator(scaler); 66 seq.AddSubOperator(mseEval); 67 combinedOp.OperatorGraph.AddOperator(seq); 68 combinedOp.OperatorGraph.InitialOperator = seq; 69 return combinedOp; 54 70 } 55 71 … … 70 86 UniformSequentialSubScopesProcessor subScopesProc = new UniformSequentialSubScopesProcessor(); 71 87 SequentialProcessor individualProc = new SequentialProcessor(); 72 MeanSquaredErrorEvaluator validationEvaluator = new MeanSquaredErrorEvaluator();88 SimpleEvaluator validationEvaluator = new SimpleEvaluator(); 73 89 validationEvaluator.Name = "ValidationEvaluator"; 74 validationEvaluator.GetVariableInfo(" MSE").ActualName = "ValidationQuality";90 validationEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues"; 75 91 validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 76 92 validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 77 93 LinearScaler validationScaler = new LinearScaler(); 94 validationScaler.GetVariableInfo("Values").ActualName = "ValidationValues"; 95 SimpleMSEEvaluator mseEval = new SimpleMSEEvaluator(); 96 mseEval.GetVariableInfo("Values").ActualName = "ValidationValues"; 97 mseEval.GetVariableInfo("MSE").ActualName = "ValidationQuality"; 78 98 individualProc.AddSubOperator(validationEvaluator); 99 individualProc.AddSubOperator(validationScaler); 100 individualProc.AddSubOperator(mseEval); 79 101 80 102 Counter bestValidationSolutionAgeCounter = new Counter(); … … 127 149 seqSubScopeProc.AddSubOperator(solutionProc); 128 150 129 ScalingTreeEvaluatorInjector evaluatorInjector = new ScalingTreeEvaluatorInjector();130 evaluatorInjector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(1000.0)));131 evaluatorInjector.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";132 133 151 #region simple evaluators 134 152 SimpleEvaluator trainingEvaluator = new SimpleEvaluator(); … … 137 155 trainingEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 138 156 trainingEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues"; 139 trainingEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";140 157 SimpleEvaluator validationEvaluator = new SimpleEvaluator(); 141 158 validationEvaluator.Name = "ValidationEvaluator"; … … 143 160 validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 144 161 validationEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues"; 145 validationEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";146 162 SimpleEvaluator testEvaluator = new SimpleEvaluator(); 147 163 testEvaluator.Name = "TestEvaluator"; … … 149 165 testEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd"; 150 166 testEvaluator.GetVariableInfo("Values").ActualName = "TestValues"; 151 testEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator"; 152 solutionProc.AddSubOperator(evaluatorInjector); 167 168 LinearScaler trainingScaler = new LinearScaler(); 169 trainingScaler.GetVariableInfo("Values").ActualName = "TrainingValues"; 170 171 LinearScaler validationScaler = new LinearScaler(); 172 validationScaler.GetVariableInfo("Values").ActualName = "ValidationValues"; 173 174 LinearScaler testScaler = new LinearScaler(); 175 testEvaluator.GetVariableInfo("Values").ActualName = "TestValues"; 176 153 177 solutionProc.AddSubOperator(trainingEvaluator); 154 178 solutionProc.AddSubOperator(validationEvaluator); 155 179 solutionProc.AddSubOperator(testEvaluator); 180 solutionProc.AddSubOperator(trainingScaler); 181 solutionProc.AddSubOperator(validationScaler); 182 solutionProc.AddSubOperator(testScaler); 156 183 #endregion 157 184 … … 171 198 172 199 NodeBasedVariableImpactCalculator nodeImpactCalculator = new NodeBasedVariableImpactCalculator(); 173 nodeImpactCalculator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";174 200 nodeImpactCalculator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 175 201 nodeImpactCalculator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/HeuristicLab.GP.StructureIdentification-3.3.csproj
r2843 r2977 88 88 <Compile Include="LinearScalingPredictorBuilder.cs" /> 89 89 <Compile Include="Evaluators\VariableFrequencyBasedImpactCalculator.cs" /> 90 <Compile Include="ScalingTreeEvaluator.cs" />91 <Compile Include="ScalingTreeEvaluatorInjector.cs" />92 90 <Compile Include="Evaluators\TreeComplexityEvaluator.cs" /> 93 91 <Compile Include="FunctionLibraryInjectors\ArithmeticFunctionLibraryInjector.cs" /> -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/LinearScalingPredictorBuilder.cs
r2722 r2977 35 35 : base() { 36 36 AddVariableInfo(new VariableInfo("FunctionTree", "The function tree", typeof(IGeneticProgrammingModel), VariableKind.In)); 37 AddVariableInfo(new VariableInfo("PunishmentFactor", "The punishment factor limits the estimated values to a certain range", typeof(DoubleData), VariableKind.In)); 38 AddVariableInfo(new VariableInfo("Dataset", "The dataset", typeof(Dataset), VariableKind.In)); 39 AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of training set", typeof(DoubleData), VariableKind.In)); 40 AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "End index of training set", typeof(DoubleData), VariableKind.In)); 41 AddVariableInfo(new VariableInfo("TargetVariable", "Name of the target variable", typeof(StringData), VariableKind.In)); 37 AddVariableInfo(new VariableInfo("Beta", "Beta parameter for linear scaling as calculated by LinearScaler", typeof(DoubleData), VariableKind.In)); 38 AddVariableInfo(new VariableInfo("Alpha", "Alpha parameter for linear scaling as calculated by LinearScaler", typeof(DoubleData), VariableKind.In)); 39 AddVariableInfo(new VariableInfo("UpperEstimationLimit", "Upper limit for estimated value (optional)", typeof(DoubleData), VariableKind.In)); 40 AddVariableInfo(new VariableInfo("LowerEstimationLimit", "Lower limit for estimated value (optional)", typeof(DoubleData), VariableKind.In)); 42 41 AddVariableInfo(new VariableInfo("Predictor", "The predictor combines the function tree and the evaluator and can be used to generate estimated values", typeof(IPredictor), VariableKind.New)); 43 42 } … … 49 48 public override IOperation Apply(IScope scope) { 50 49 IGeneticProgrammingModel model = GetVariableValue<IGeneticProgrammingModel>("FunctionTree", scope, true); 51 double punishmentFactor = GetVariableValue<DoubleData>("PunishmentFactor", scope, true).Data; 52 Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true); 53 int start = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data; 54 int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data; 55 string targetVariable = GetVariableValue<StringData>("TargetVariable", scope, true).Data; 56 IPredictor predictor = CreatePredictor(model, punishmentFactor, dataset, targetVariable, start, end); 50 //double punishmentFactor = GetVariableValue<DoubleData>("PunishmentFactor", scope, true).Data; 51 //Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true); 52 //int start = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data; 53 //int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data; 54 //string targetVariable = GetVariableValue<StringData>("TargetVariable", scope, true).Data; 55 double alpha = GetVariableValue<DoubleData>("Alpha", scope, true).Data; 56 double beta = GetVariableValue<DoubleData>("Beta", scope, true).Data; 57 DoubleData lowerLimit = GetVariableValue<DoubleData>("LowerEstimationLimit", scope, true, false); 58 DoubleData upperLimit = GetVariableValue<DoubleData>("UpperEstimationLimit", scope, true, false); 59 IPredictor predictor; 60 if (lowerLimit == null || upperLimit == null) 61 predictor = CreatePredictor(model, beta, alpha, double.NegativeInfinity, double.PositiveInfinity); 62 else 63 predictor = CreatePredictor(model, beta, alpha, lowerLimit.Data, upperLimit.Data); 57 64 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Predictor"), predictor)); 58 65 return null; 59 66 } 60 67 61 public static IPredictor CreatePredictor(IGeneticProgrammingModel model, double punishmentFactor, 62 Dataset dataset, string targetVariable, int start, int end) { 63 return CreatePredictor(model, punishmentFactor, dataset, dataset.GetVariableIndex(targetVariable), start, end); 64 } 65 66 67 public static IPredictor CreatePredictor(IGeneticProgrammingModel model, double punishmentFactor, 68 Dataset dataset, int targetVariable, int start, int end) { 68 public static IPredictor CreatePredictor(IGeneticProgrammingModel model, double beta, double alpha, double lowerLimit, double upperLimit) { 69 69 70 70 var evaluator = new HL3TreeEvaluator(); 71 // evaluate for all rows 72 evaluator.PrepareForEvaluation(dataset, model.FunctionTree); 73 var result = from row in Enumerable.Range(start, end - start) 74 let y = evaluator.Evaluate(row) 75 let y_ = dataset.GetValue(row, targetVariable) 76 select new { Row = row, Estimation = y, Target = y_ }; 77 78 // calculate alpha and beta on the subset of rows with valid values 79 var filteredResult = result.Where(x => IsValidValue(x.Target) && IsValidValue(x.Estimation)); 80 var target = filteredResult.Select(x => x.Target); 81 var estimation = filteredResult.Select(x => x.Estimation); 82 double a, b; 83 if (filteredResult.Count() > 2) { 84 double tMean = target.Sum() / target.Count(); 85 double xMean = estimation.Sum() / estimation.Count(); 86 double sumXT = 0; 87 double sumXX = 0; 88 foreach (var r in result) { 89 double x = r.Estimation; 90 double t = r.Target; 91 sumXT += (x - xMean) * (t - tMean); 92 sumXX += (x - xMean) * (x - xMean); 93 } 94 b = sumXT / sumXX; 95 a = tMean - b * xMean; 96 } else { 97 b = 1.0; 98 a = 0.0; 99 } 100 double mean = dataset.GetMean(targetVariable, start, end); 101 double range = dataset.GetRange(targetVariable, start, end); 102 double minEstimatedValue = mean - punishmentFactor * range; 103 double maxEstimatedValue = mean + punishmentFactor * range; 104 evaluator.LowerEvaluationLimit = minEstimatedValue; 105 evaluator.UpperEvaluationLimit = maxEstimatedValue; 106 var resultModel = new GeneticProgrammingModel(MakeSum(MakeProduct(model.FunctionTree, b), a)); 107 return new Predictor(evaluator, resultModel, minEstimatedValue, maxEstimatedValue); 71 evaluator.LowerEvaluationLimit = lowerLimit; 72 evaluator.UpperEvaluationLimit = upperLimit; 73 var resultModel = new GeneticProgrammingModel(MakeSum(MakeProduct(model.FunctionTree, beta), alpha)); 74 return new Predictor(evaluator, resultModel, lowerLimit, upperLimit); 108 75 } 109 110 private static bool IsValidValue(double d) {111 return !double.IsInfinity(d) && !double.IsNaN(d);112 }113 114 76 115 77 private static IFunctionTree MakeSum(IFunctionTree tree, double x) { … … 134 96 return constX; 135 97 } 136 137 private static void CalculateScalingParameters(IEnumerable<double> xs, IEnumerable<double> ys, out double k, out double d) {138 if (xs.Count() != ys.Count()) throw new ArgumentException();139 double xMean = xs.Sum() / xs.Count();140 double yMean = ys.Sum() / ys.Count();141 142 var yEnumerator = ys.GetEnumerator();143 var xEnumerator = xs.GetEnumerator();144 145 double sumXY = 0.0;146 double sumXX = 0.0;147 while (xEnumerator.MoveNext() && yEnumerator.MoveNext()) {148 sumXY += (xEnumerator.Current - xMean) * (yEnumerator.Current - yMean);149 sumXX += (xEnumerator.Current - xMean) * (xEnumerator.Current - xMean);150 }151 152 k = sumXY / sumXX;153 d = yMean - k * xMean;154 }155 98 } 156 99 } -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/OffspringSelectionGPRegression.cs
r2566 r2977 198 198 VariableInjector injector = base.CreateGlobalInjector(); 199 199 injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData())); 200 // NB: LowerEstimationLimit and UpperEstimationLimit should replace the direct use of PunishmentFactor in the algorithm (gkronber 9 March, 2010) 201 injector.AddVariable(new HeuristicLab.Core.Variable("LowerEstimationLimit", new DoubleData(double.NegativeInfinity))); 202 injector.AddVariable(new HeuristicLab.Core.Variable("UpperEstimationLimit", new DoubleData(double.PositiveInfinity))); 200 203 injector.AddVariable(new HeuristicLab.Core.Variable("BestValidationSolutionAge", new IntData())); 201 204 injector.AddVariable(new HeuristicLab.Core.Variable("MaxBestValidationSolutionAge", new IntData())); -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/StandardGPRegression.cs
r2566 r2977 41 41 public virtual string TargetVariable { 42 42 get { return ProblemInjector.GetVariableValue<StringData>("TargetVariable", null, false).Data; } 43 set { ProblemInjector.GetVariableValue<StringData>("TargetVariable", null, false).Data = value; } 43 set { 44 ProblemInjector.GetVariableValue<StringData>("TargetVariable", null, false).Data = value; 45 } 44 46 } 45 47 46 48 public virtual Dataset Dataset { 47 49 get { return ProblemInjector.GetVariableValue<Dataset>("Dataset", null, false); } 48 set { ProblemInjector.GetVariable("Dataset").Value = value; } 50 set { 51 ProblemInjector.GetVariable("Dataset").Value = value; 52 } 49 53 } 50 54 … … 101 105 public virtual double PunishmentFactor { 102 106 get { return GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data; } 103 set { GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data = value; } 107 set { 108 GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data = value; 109 } 110 } 111 112 public virtual double UpperEstimationLimit { 113 get { return GetVariableInjector().GetVariable("UpperEstimationLimit").GetValue<DoubleData>().Data; } 114 set { GetVariableInjector().GetVariable("UpperEstimationLimit").GetValue<DoubleData>().Data = value; } 115 } 116 public virtual double LowerEstimationLimit { 117 get { return GetVariableInjector().GetVariable("LowerEstimationLimit").GetValue<DoubleData>().Data; } 118 set { GetVariableInjector().GetVariable("LowerEstimationLimit").GetValue<DoubleData>().Data = value; } 104 119 } 105 120 … … 193 208 VariableInjector injector = base.CreateGlobalInjector(); 194 209 injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData())); 210 // NB: LowerEstimationLimit and UpperEstimationLimit should replace the direct use of PunishmentFactor in the algorithm (gkronber 9 March, 2010) 211 injector.AddVariable(new HeuristicLab.Core.Variable("LowerEstimationLimit", new DoubleData(double.NegativeInfinity))); 212 injector.AddVariable(new HeuristicLab.Core.Variable("UpperEstimationLimit", new DoubleData(double.PositiveInfinity))); 195 213 injector.AddVariable(new HeuristicLab.Core.Variable("BestValidationSolutionAge", new IntData())); 196 214 injector.AddVariable(new HeuristicLab.Core.Variable("MaxBestValidationSolutionAge", new IntData())); … … 235 253 236 254 IOperator combinedTerminationCriterion = AlgorithmBase.CombineTerminationCriterions(base.CreateTerminationCondition(), bestSolutionAge); 237 255 238 256 terminationCritertion.OperatorGraph.AddOperator(combinedTerminationCriterion); 239 257 terminationCritertion.OperatorGraph.InitialOperator = combinedTerminationCriterion; -
trunk/sources/HeuristicLab.Modeling/3.2/HeuristicLab.Modeling-3.2.csproj
r2808 r2977 84 84 <Compile Include="AnalyzerModel.cs" /> 85 85 <Compile Include="BestSolutionStorer.cs" /> 86 <Compile Include="LinearScaler.cs" /> 86 87 <Compile Include="SimpleStableCorrelationCoefficientEvaluator.cs" /> 87 88 <Compile Include="SimplePearsonCorrelationCoefficientEvaluator.cs" /> -
trunk/sources/HeuristicLab.Modeling/3.2/SimpleEvaluatorBase.cs
r2357 r2977 9 9 namespace HeuristicLab.Modeling { 10 10 public abstract class SimpleEvaluatorBase : OperatorBase { 11 p rotectedconst int ORIGINAL_INDEX = 0;12 p rotectedconst int ESTIMATION_INDEX = 1;11 public const int ORIGINAL_INDEX = 0; 12 public const int ESTIMATION_INDEX = 1; 13 13 14 14 public virtual string OutputVariableName {
Note: See TracChangeset
for help on using the changeset viewer.