Changeset 4250
- Timestamp:
- 08/18/10 14:58:56 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs
r4128 r4250 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Linq; 25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; 27 26 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Analyzers;30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;32 27 using HeuristicLab.Optimization; 33 28 using HeuristicLab.Parameters; 34 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 35 using HeuristicLab.PluginInfrastructure;36 30 using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers; 37 using HeuristicLab.Problems.DataAnalysis.Symbolic;38 31 39 32 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic { … … 84 77 public SymbolicRegressionProblem() 85 78 : base() { 86 var evaluator = new SymbolicRegression ScaledMeanSquaredErrorEvaluator();87 Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the error of the regression model should be minimized.", (BoolValue)new BoolValue( false).AsReadOnly()));79 var evaluator = new SymbolicRegressionPearsonsRSquaredEvaluator(); 80 Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the error of the regression model should be minimized.", (BoolValue)new BoolValue(true))); 88 81 Parameters.Add(new ValueParameter<ISymbolicRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator)); 89 82 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic regression solutions for the problem.")); 90 83 91 evaluator.QualityParameter.ActualName = "Training MeanSquaredError";84 evaluator.QualityParameter.ActualName = "TrainingPearsonR2"; 92 85 93 86 InitializeOperators(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblemBase.cs
r4198 r4250 113 113 public ISymbolicExpressionGrammar FunctionTreeGrammar { 114 114 get { return (ISymbolicExpressionGrammar)FunctionTreeGrammarParameter.Value; } 115 private set { FunctionTreeGrammarParameter.Value = value; } 115 116 } 116 117 public override IEnumerable<IOperator> Operators { … … 190 191 MaxFunctionDefiningBranchesParameter.ValueChanged += new EventHandler(ArchitectureParameter_ValueChanged); 191 192 SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged); 193 FunctionTreeGrammarParameter.ValueChanged += new EventHandler(FunctionTreeGrammarParameter_ValueChanged); 192 194 } 193 195 … … 211 213 UpdateGrammar(); 212 214 } 213 protected virtual void OnGrammarChanged( EventArgs e) {}215 protected virtual void OnGrammarChanged() { UpdateGrammar(); } 214 216 protected virtual void OnOperatorsChanged(EventArgs e) { RaiseOperatorsChanged(e); } 215 217 protected virtual void OnSolutionCreatorChanged(EventArgs e) { … … 231 233 232 234 #region event handlers 235 private void FunctionTreeGrammarParameter_ValueChanged(object sender, EventArgs e) { 236 if (!(FunctionTreeGrammar is GlobalSymbolicExpressionGrammar)) 237 FunctionTreeGrammar = new GlobalSymbolicExpressionGrammar(FunctionTreeGrammar); 238 OnGrammarChanged(); 239 } 240 233 241 private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) { 234 242 OnSolutionCreatorChanged(e); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionSolution.cs
r4068 r4250 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols; 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic { … … 50 51 51 52 protected override void RecalculateEstimatedValues() { 52 estimatedValues = (from x in Model.GetEstimatedValues(ProblemData, 0, ProblemData.Dataset.Rows) 53 let boundedX = Math.Min(UpperEstimationLimit, Math.Max(LowerEstimationLimit, x)) 54 select double.IsNaN(boundedX) ? UpperEstimationLimit : boundedX).ToList(); 53 int minLag = 0; 54 var laggedTreeNodes = Model.SymbolicExpressionTree.IterateNodesPrefix().OfType<LaggedVariableTreeNode>(); 55 if (laggedTreeNodes.Any()) 56 minLag = laggedTreeNodes.Min(node => node.Lag); 57 IEnumerable<double> calculatedValues = 58 from x in Model.GetEstimatedValues(ProblemData, 0 - minLag, ProblemData.Dataset.Rows) 59 let boundedX = Math.Min(UpperEstimationLimit, Math.Max(LowerEstimationLimit, x)) 60 select double.IsNaN(boundedX) ? UpperEstimationLimit : boundedX; 61 estimatedValues = Enumerable.Repeat(double.NaN, Math.Abs(minLag)).Concat(calculatedValues).ToList(); 55 62 OnEstimatedValuesChanged(); 56 63 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisProblemData.cs
r4068 r4250 69 69 get { return (IValueParameter<Dataset>)Parameters["Dataset"]; } 70 70 } 71 72 71 public IValueParameter<StringValue> TargetVariableParameter { 73 72 get { return (IValueParameter<StringValue>)Parameters["TargetVariable"]; } 74 73 } 75 76 74 public IValueParameter<ICheckedItemList<StringValue>> InputVariablesParameter { 77 75 get { return (IValueParameter<ICheckedItemList<StringValue>>)Parameters["InputVariables"]; } 78 76 } 79 80 77 public IValueParameter<IntValue> TrainingSamplesStartParameter { 81 78 get { return (IValueParameter<IntValue>)Parameters["TrainingSamplesStart"]; } … … 109 106 if (TargetVariable != null) DeregisterStringValueEventHandlers(TargetVariable); 110 107 TargetVariableParameter.Value = value; 108 RegisterStringValueEventHandlers(TargetVariable); 111 109 } 112 110 } … … 119 117 if (InputVariables != null) DeregisterInputVariablesEventHandlers(); 120 118 InputVariablesParameter.Value = value; 119 RegisterInputVariablesEventHandlers(); 121 120 } 122 121 } … … 129 128 if (TrainingSamplesStart != null) DeregisterValueTypeEventHandlers(TrainingSamplesStart); 130 129 TrainingSamplesStartParameter.Value = value; 130 RegisterValueTypeEventHandlers(TrainingSamplesStart); 131 131 } 132 132 } … … 139 139 if (TrainingSamplesEnd != null) DeregisterValueTypeEventHandlers(TrainingSamplesEnd); 140 140 TrainingSamplesEndParameter.Value = value; 141 RegisterValueTypeEventHandlers(TrainingSamplesEnd); 141 142 } 142 143 } … … 149 150 if (TestSamplesStart != null) DeregisterValueTypeEventHandlers(TestSamplesStart); 150 151 TestSamplesStartParameter.Value = value; 152 RegisterValueTypeEventHandlers(TestSamplesStart); 151 153 } 152 154 } … … 159 161 if (TestSamplesEnd != null) DeregisterValueTypeEventHandlers(TestSamplesEnd); 160 162 TestSamplesEndParameter.Value = value; 163 RegisterValueTypeEventHandlers(TestSamplesEnd); 161 164 } 162 165 } … … 242 245 243 246 #region parameter value changed event handlers 244 void DatasetParameter_ValueChanged(object sender, EventArgs e) { 245 OnProblemDataChanged(EventArgs.Empty); 246 } 247 void InputVariablesParameter_ValueChanged(object sender, EventArgs e) { 248 RegisterInputVariablesEventHandlers(); 249 OnProblemDataChanged(EventArgs.Empty); 250 } 251 void TargetVariableParameter_ValueChanged(object sender, EventArgs e) { 252 if (TargetVariable != null) { 253 RegisterStringValueEventHandlers(TargetVariable); 254 OnProblemDataChanged(EventArgs.Empty); 255 } 256 } 257 void TrainingSamplesStartParameter_ValueChanged(object sender, EventArgs e) { 258 RegisterValueTypeEventHandlers(TrainingSamplesStart); 259 OnProblemDataChanged(EventArgs.Empty); 260 } 261 void TrainingSamplesEndParameter_ValueChanged(object sender, EventArgs e) { 262 RegisterValueTypeEventHandlers(TrainingSamplesEnd); 263 OnProblemDataChanged(EventArgs.Empty); 264 } 265 void TestSamplesStartParameter_ValueChanged(object sender, EventArgs e) { 266 RegisterValueTypeEventHandlers(TestSamplesStart); 267 OnProblemDataChanged(EventArgs.Empty); 268 } 269 void TestSamplesEndParameter_ValueChanged(object sender, EventArgs e) { 270 RegisterValueTypeEventHandlers(TestSamplesEnd); 247 private void DatasetParameter_ValueChanged(object sender, EventArgs e) { 248 OnProblemDataChanged(EventArgs.Empty); 249 } 250 private void InputVariablesParameter_ValueChanged(object sender, EventArgs e) { 251 OnProblemDataChanged(EventArgs.Empty); 252 } 253 private void TargetVariableParameter_ValueChanged(object sender, EventArgs e) { 254 if (TargetVariable != null) OnProblemDataChanged(EventArgs.Empty); 255 } 256 private void TrainingSamplesStartParameter_ValueChanged(object sender, EventArgs e) { 257 OnProblemDataChanged(EventArgs.Empty); 258 } 259 private void TrainingSamplesEndParameter_ValueChanged(object sender, EventArgs e) { 260 OnProblemDataChanged(EventArgs.Empty); 261 } 262 private void TestSamplesStartParameter_ValueChanged(object sender, EventArgs e) { 263 OnProblemDataChanged(EventArgs.Empty); 264 } 265 private void TestSamplesEndParameter_ValueChanged(object sender, EventArgs e) { 271 266 OnProblemDataChanged(EventArgs.Empty); 272 267 } … … 278 273 InputVariables.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_ItemsRemoved); 279 274 InputVariables.CheckedItemsChanged += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_CheckedItemsChanged); 280 foreach (var item in InputVariables) 275 foreach (var item in InputVariables) { 281 276 item.ValueChanged += new EventHandler(InputVariable_ValueChanged); 277 } 282 278 } 283 279 … … 295 291 OnProblemDataChanged(e); 296 292 } 297 298 293 private void InputVariables_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) { 299 294 foreach (var indexedItem in e.Items) … … 301 296 OnProblemDataChanged(e); 302 297 } 303 304 298 private void InputVariables_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) { 305 299 foreach (var indexedItem in e.Items) … … 307 301 OnProblemDataChanged(e); 308 302 } 309 310 303 private void InputVariables_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) { 311 304 foreach (var indexedItem in e.OldItems) … … 313 306 OnProblemDataChanged(e); 314 307 } 315 316 void InputVariable_ValueChanged(object sender, EventArgs e) {317 OnProblemDataChanged(e);318 } 308 private void InputVariable_ValueChanged(object sender, EventArgs e) { 309 OnProblemDataChanged(e); 310 } 311 319 312 #region helper 320 321 313 private void RegisterValueTypeEventHandlers<T>(ValueTypeValue<T> value) where T : struct { 322 314 value.ValueChanged += new EventHandler(value_ValueChanged); 323 315 } 324 325 316 private void DeregisterValueTypeEventHandlers<T>(ValueTypeValue<T> value) where T : struct { 326 317 value.ValueChanged -= new EventHandler(value_ValueChanged); 327 318 } 328 329 void value_ValueChanged(object sender, EventArgs e) {330 OnProblemDataChanged(e);331 }332 333 319 private void RegisterStringValueEventHandlers(StringValue value) { 334 320 value.ValueChanged += new EventHandler(value_ValueChanged); 335 321 } 336 337 322 private void DeregisterStringValueEventHandlers(StringValue value) { 338 323 value.ValueChanged -= new EventHandler(value_ValueChanged); 339 324 } 340 325 326 private void value_ValueChanged(object sender, EventArgs e) { 327 OnProblemDataChanged(e); 328 } 341 329 #endregion 342 330 #endregion
Note: See TracChangeset
for help on using the changeset viewer.