Changeset 4341
- Timestamp:
- 08/30/10 10:04:03 (14 years ago)
- Location:
- branches/DataAnalysis
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis
-
Property
svn:mergeinfo
set to
/trunk/sources merged eligible
-
Property
svn:mergeinfo
set to
-
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj
r4271 r4341 127 127 </Compile> 128 128 <Compile Include="Symbolic\Analyzers\SymbolicRegressionSolutionLinearScaler.cs" /> 129 <Compile Include="Symbolic\Analyzers\SymbolicRegressionTournamentPruning.cs" /> 129 <Compile Include="Symbolic\Analyzers\SymbolicRegressionTournamentPruning.cs"> 130 <SubType>Code</SubType> 131 </Compile> 130 132 <Compile Include="Symbolic\Analyzers\SymbolicRegressionVariableFrequencyAnalyzer.cs" /> 131 133 <Compile Include="Symbolic\Analyzers\ValidationBestScaledSymbolicRegressionSolutionAnalyzer.cs" /> -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs
r4128 r4341 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(); -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblemBase.cs
r4225 r4341 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); … … 287 295 operators = new List<IOperator>(); 288 296 operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>().OfType<IOperator>()); 289 operators.Add(new SymbolicRegressionTournamentPruning());290 297 operators.Add(new SymbolicRegressionVariableFrequencyAnalyzer()); 291 298 operators.Add(new MinAverageMaxSymbolicExpressionTreeSizeAnalyzer()); -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionSolution.cs
r4068 r4341 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 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisProblemData.cs
r4068 r4341 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"]; } … … 204 201 205 202 [StorableConstructor] 206 private DataAnalysisProblemData(bool deserializing) : base( ) { }203 private DataAnalysisProblemData(bool deserializing) : base(deserializing) { } 207 204 208 205 [StorableHook(HookType.AfterDeserialization)] … … 242 239 243 240 #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) {241 private void DatasetParameter_ValueChanged(object sender, EventArgs e) { 242 OnProblemDataChanged(EventArgs.Empty); 243 } 244 private void InputVariablesParameter_ValueChanged(object sender, EventArgs e) { 248 245 RegisterInputVariablesEventHandlers(); 249 246 OnProblemDataChanged(EventArgs.Empty); 250 247 } 251 void TargetVariableParameter_ValueChanged(object sender, EventArgs e) {248 private void TargetVariableParameter_ValueChanged(object sender, EventArgs e) { 252 249 if (TargetVariable != null) { 253 250 RegisterStringValueEventHandlers(TargetVariable); … … 255 252 } 256 253 } 257 void TrainingSamplesStartParameter_ValueChanged(object sender, EventArgs e) {254 private void TrainingSamplesStartParameter_ValueChanged(object sender, EventArgs e) { 258 255 RegisterValueTypeEventHandlers(TrainingSamplesStart); 259 256 OnProblemDataChanged(EventArgs.Empty); 260 257 } 261 void TrainingSamplesEndParameter_ValueChanged(object sender, EventArgs e) {258 private void TrainingSamplesEndParameter_ValueChanged(object sender, EventArgs e) { 262 259 RegisterValueTypeEventHandlers(TrainingSamplesEnd); 263 260 OnProblemDataChanged(EventArgs.Empty); 264 261 } 265 void TestSamplesStartParameter_ValueChanged(object sender, EventArgs e) {262 private void TestSamplesStartParameter_ValueChanged(object sender, EventArgs e) { 266 263 RegisterValueTypeEventHandlers(TestSamplesStart); 267 264 OnProblemDataChanged(EventArgs.Empty); 268 265 } 269 void TestSamplesEndParameter_ValueChanged(object sender, EventArgs e) {266 private void TestSamplesEndParameter_ValueChanged(object sender, EventArgs e) { 270 267 RegisterValueTypeEventHandlers(TestSamplesEnd); 271 268 OnProblemDataChanged(EventArgs.Empty); … … 278 275 InputVariables.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_ItemsRemoved); 279 276 InputVariables.CheckedItemsChanged += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_CheckedItemsChanged); 280 foreach (var item in InputVariables) 277 foreach (var item in InputVariables) { 281 278 item.ValueChanged += new EventHandler(InputVariable_ValueChanged); 279 } 282 280 } 283 281 … … 295 293 OnProblemDataChanged(e); 296 294 } 297 298 295 private void InputVariables_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) { 299 296 foreach (var indexedItem in e.Items) … … 301 298 OnProblemDataChanged(e); 302 299 } 303 304 300 private void InputVariables_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) { 305 301 foreach (var indexedItem in e.Items) … … 307 303 OnProblemDataChanged(e); 308 304 } 309 310 305 private void InputVariables_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) { 311 306 foreach (var indexedItem in e.OldItems) … … 313 308 OnProblemDataChanged(e); 314 309 } 315 316 void InputVariable_ValueChanged(object sender, EventArgs e) {317 OnProblemDataChanged(e);318 } 310 private void InputVariable_ValueChanged(object sender, EventArgs e) { 311 OnProblemDataChanged(e); 312 } 313 319 314 #region helper 320 321 315 private void RegisterValueTypeEventHandlers<T>(ValueTypeValue<T> value) where T : struct { 322 316 value.ValueChanged += new EventHandler(value_ValueChanged); 323 317 } 324 325 318 private void DeregisterValueTypeEventHandlers<T>(ValueTypeValue<T> value) where T : struct { 326 319 value.ValueChanged -= new EventHandler(value_ValueChanged); 327 320 } 328 329 void value_ValueChanged(object sender, EventArgs e) {330 OnProblemDataChanged(e);331 }332 333 321 private void RegisterStringValueEventHandlers(StringValue value) { 334 322 value.ValueChanged += new EventHandler(value_ValueChanged); 335 323 } 336 337 324 private void DeregisterStringValueEventHandlers(StringValue value) { 338 325 value.ValueChanged -= new EventHandler(value_ValueChanged); 339 326 } 340 327 328 private void value_ValueChanged(object sender, EventArgs e) { 329 OnProblemDataChanged(e); 330 } 341 331 #endregion 342 332 #endregion -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/ArithmeticExpressionGrammar.cs
r4068 r4341 30 30 [Item("ArithmeticExpressionGrammar", "Represents a grammar for functional expressions using only arithmetic operations.")] 31 31 public class ArithmeticExpressionGrammar : DefaultSymbolicExpressionGrammar { 32 [Storable]33 private HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable variableSymbol;34 35 32 public ArithmeticExpressionGrammar() 36 33 : base() { … … 49 46 constant.MinValue = -20; 50 47 constant.MaxValue = 20; 51 var iableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable();48 var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable(); 52 49 53 50 var allSymbols = new List<Symbol>() { add, sub, mul, div, constant, variableSymbol }; -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/FullFunctionalExpressionGrammar.cs
r4068 r4341 30 30 [Item("FullFunctionalExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")] 31 31 public class FullFunctionalExpressionGrammar : DefaultSymbolicExpressionGrammar { 32 [Storable]33 private HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable variableSymbol;34 35 32 public FullFunctionalExpressionGrammar() 36 33 : base() { … … 60 57 constant.MinValue = -20; 61 58 constant.MaxValue = 20; 62 variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable(); 59 var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable(); 60 var laggedVariable = new LaggedVariable(); 61 laggedVariable.InitialFrequency = 0.0; 63 62 64 var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, constant, variableSymbol };63 var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, constant, variableSymbol, laggedVariable }; 65 64 var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, not }; 66 65 var binaryFunctionSymbols = new List<Symbol>() { gt, lt }; 67 66 var functionSymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or }; 67 var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable }; 68 68 69 69 foreach (var symb in allSymbols) … … 83 83 } 84 84 85 foreach (var terminalSymbol in terminalSymbols) { 86 SetMinSubtreeCount(terminalSymbol, 0); 87 SetMaxSubtreeCount(terminalSymbol, 0); 88 } 89 85 90 SetMinSubtreeCount(@if, 3); 86 91 SetMaxSubtreeCount(@if, 3); 87 SetMinSubtreeCount(constant, 0); 88 SetMaxSubtreeCount(constant, 0); 89 SetMinSubtreeCount(variableSymbol, 0); 90 SetMaxSubtreeCount(variableSymbol, 0); 92 91 93 92 94 // allow each symbol as child of the start symbol
Note: See TracChangeset
for help on using the changeset viewer.