Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4341 for branches/DataAnalysis


Ignore:
Timestamp:
08/30/10 10:04:03 (14 years ago)
Author:
gkronber
Message:

Merged changesets from revisions r4249, r4250, r4251, r4291, r4295 from trunk into data analysis exploration #1142.

Location:
branches/DataAnalysis
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis

  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj

    r4271 r4341  
    127127    </Compile>
    128128    <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>
    130132    <Compile Include="Symbolic\Analyzers\SymbolicRegressionVariableFrequencyAnalyzer.cs" />
    131133    <Compile Include="Symbolic\Analyzers\ValidationBestScaledSymbolicRegressionSolutionAnalyzer.cs" />
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs

    r4128 r4341  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
    2726using 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;
    3227using HeuristicLab.Optimization;
    3328using HeuristicLab.Parameters;
    3429using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    35 using HeuristicLab.PluginInfrastructure;
    3630using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers;
    37 using HeuristicLab.Problems.DataAnalysis.Symbolic;
    3831
    3932namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
     
    8477    public SymbolicRegressionProblem()
    8578      : base() {
    86       var evaluator = new SymbolicRegressionScaledMeanSquaredErrorEvaluator();
    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)));
    8881      Parameters.Add(new ValueParameter<ISymbolicRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator));
    8982      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic regression solutions for the problem."));
    9083
    91       evaluator.QualityParameter.ActualName = "TrainingMeanSquaredError";
     84      evaluator.QualityParameter.ActualName = "TrainingPearsonR2";
    9285
    9386      InitializeOperators();
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblemBase.cs

    r4225 r4341  
    113113    public ISymbolicExpressionGrammar FunctionTreeGrammar {
    114114      get { return (ISymbolicExpressionGrammar)FunctionTreeGrammarParameter.Value; }
     115      private set { FunctionTreeGrammarParameter.Value = value; }
    115116    }
    116117    public override IEnumerable<IOperator> Operators {
     
    190191      MaxFunctionDefiningBranchesParameter.ValueChanged += new EventHandler(ArchitectureParameter_ValueChanged);
    191192      SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
     193      FunctionTreeGrammarParameter.ValueChanged += new EventHandler(FunctionTreeGrammarParameter_ValueChanged);
    192194    }
    193195
     
    211213      UpdateGrammar();
    212214    }
    213     protected virtual void OnGrammarChanged(EventArgs e) { }
     215    protected virtual void OnGrammarChanged() { UpdateGrammar(); }
    214216    protected virtual void OnOperatorsChanged(EventArgs e) { RaiseOperatorsChanged(e); }
    215217    protected virtual void OnSolutionCreatorChanged(EventArgs e) {
     
    231233
    232234    #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
    233241    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
    234242      OnSolutionCreatorChanged(e);
     
    287295      operators = new List<IOperator>();
    288296      operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>().OfType<IOperator>());
    289       operators.Add(new SymbolicRegressionTournamentPruning());
    290297      operators.Add(new SymbolicRegressionVariableFrequencyAnalyzer());
    291298      operators.Add(new MinAverageMaxSymbolicExpressionTreeSizeAnalyzer());
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionSolution.cs

    r4068 r4341  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
    2829
    2930namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
     
    5051
    5152    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();
    5562      OnEstimatedValuesChanged();
    5663    }
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisProblemData.cs

    r4068 r4341  
    6969      get { return (IValueParameter<Dataset>)Parameters["Dataset"]; }
    7070    }
    71 
    7271    public IValueParameter<StringValue> TargetVariableParameter {
    7372      get { return (IValueParameter<StringValue>)Parameters["TargetVariable"]; }
    7473    }
    75 
    7674    public IValueParameter<ICheckedItemList<StringValue>> InputVariablesParameter {
    7775      get { return (IValueParameter<ICheckedItemList<StringValue>>)Parameters["InputVariables"]; }
    7876    }
    79 
    8077    public IValueParameter<IntValue> TrainingSamplesStartParameter {
    8178      get { return (IValueParameter<IntValue>)Parameters["TrainingSamplesStart"]; }
     
    204201
    205202    [StorableConstructor]
    206     private DataAnalysisProblemData(bool deserializing) : base() { }
     203    private DataAnalysisProblemData(bool deserializing) : base(deserializing) { }
    207204
    208205    [StorableHook(HookType.AfterDeserialization)]
     
    242239
    243240    #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) {
    248245      RegisterInputVariablesEventHandlers();
    249246      OnProblemDataChanged(EventArgs.Empty);
    250247    }
    251     void TargetVariableParameter_ValueChanged(object sender, EventArgs e) {
     248    private void TargetVariableParameter_ValueChanged(object sender, EventArgs e) {
    252249      if (TargetVariable != null) {
    253250        RegisterStringValueEventHandlers(TargetVariable);
     
    255252      }
    256253    }
    257     void TrainingSamplesStartParameter_ValueChanged(object sender, EventArgs e) {
     254    private void TrainingSamplesStartParameter_ValueChanged(object sender, EventArgs e) {
    258255      RegisterValueTypeEventHandlers(TrainingSamplesStart);
    259256      OnProblemDataChanged(EventArgs.Empty);
    260257    }
    261     void TrainingSamplesEndParameter_ValueChanged(object sender, EventArgs e) {
     258    private void TrainingSamplesEndParameter_ValueChanged(object sender, EventArgs e) {
    262259      RegisterValueTypeEventHandlers(TrainingSamplesEnd);
    263260      OnProblemDataChanged(EventArgs.Empty);
    264261    }
    265     void TestSamplesStartParameter_ValueChanged(object sender, EventArgs e) {
     262    private void TestSamplesStartParameter_ValueChanged(object sender, EventArgs e) {
    266263      RegisterValueTypeEventHandlers(TestSamplesStart);
    267264      OnProblemDataChanged(EventArgs.Empty);
    268265    }
    269     void TestSamplesEndParameter_ValueChanged(object sender, EventArgs e) {
     266    private void TestSamplesEndParameter_ValueChanged(object sender, EventArgs e) {
    270267      RegisterValueTypeEventHandlers(TestSamplesEnd);
    271268      OnProblemDataChanged(EventArgs.Empty);
     
    278275      InputVariables.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_ItemsRemoved);
    279276      InputVariables.CheckedItemsChanged += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_CheckedItemsChanged);
    280       foreach (var item in InputVariables)
     277      foreach (var item in InputVariables) {
    281278        item.ValueChanged += new EventHandler(InputVariable_ValueChanged);
     279      }
    282280    }
    283281
     
    295293      OnProblemDataChanged(e);
    296294    }
    297 
    298295    private void InputVariables_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) {
    299296      foreach (var indexedItem in e.Items)
     
    301298      OnProblemDataChanged(e);
    302299    }
    303 
    304300    private void InputVariables_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) {
    305301      foreach (var indexedItem in e.Items)
     
    307303      OnProblemDataChanged(e);
    308304    }
    309 
    310305    private void InputVariables_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) {
    311306      foreach (var indexedItem in e.OldItems)
     
    313308      OnProblemDataChanged(e);
    314309    }
    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
    319314    #region helper
    320 
    321315    private void RegisterValueTypeEventHandlers<T>(ValueTypeValue<T> value) where T : struct {
    322316      value.ValueChanged += new EventHandler(value_ValueChanged);
    323317    }
    324 
    325318    private void DeregisterValueTypeEventHandlers<T>(ValueTypeValue<T> value) where T : struct {
    326319      value.ValueChanged -= new EventHandler(value_ValueChanged);
    327320    }
    328 
    329     void value_ValueChanged(object sender, EventArgs e) {
    330       OnProblemDataChanged(e);
    331     }
    332 
    333321    private void RegisterStringValueEventHandlers(StringValue value) {
    334322      value.ValueChanged += new EventHandler(value_ValueChanged);
    335323    }
    336 
    337324    private void DeregisterStringValueEventHandlers(StringValue value) {
    338325      value.ValueChanged -= new EventHandler(value_ValueChanged);
    339326    }
    340327
     328    private void value_ValueChanged(object sender, EventArgs e) {
     329      OnProblemDataChanged(e);
     330    }
    341331    #endregion
    342332    #endregion
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/ArithmeticExpressionGrammar.cs

    r4068 r4341  
    3030  [Item("ArithmeticExpressionGrammar", "Represents a grammar for functional expressions using only arithmetic operations.")]
    3131  public class ArithmeticExpressionGrammar : DefaultSymbolicExpressionGrammar {
    32     [Storable]
    33     private HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable variableSymbol;
    34 
    3532    public ArithmeticExpressionGrammar()
    3633      : base() {
     
    4946      constant.MinValue = -20;
    5047      constant.MaxValue = 20;
    51       variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable();
     48      var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable();
    5249
    5350      var allSymbols = new List<Symbol>() { add, sub, mul, div, constant, variableSymbol };
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/FullFunctionalExpressionGrammar.cs

    r4068 r4341  
    3030  [Item("FullFunctionalExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")]
    3131  public class FullFunctionalExpressionGrammar : DefaultSymbolicExpressionGrammar {
    32     [Storable]
    33     private HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable variableSymbol;
    34 
    3532    public FullFunctionalExpressionGrammar()
    3633      : base() {
     
    6057      constant.MinValue = -20;
    6158      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;
    6362
    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 };
    6564      var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, not };
    6665      var binaryFunctionSymbols = new List<Symbol>() { gt, lt };
    6766      var functionSymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or };
     67      var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable };
    6868
    6969      foreach (var symb in allSymbols)
     
    8383      }
    8484
     85      foreach (var terminalSymbol in terminalSymbols) {
     86        SetMinSubtreeCount(terminalSymbol, 0);
     87        SetMaxSubtreeCount(terminalSymbol, 0);
     88      }
     89
    8590      SetMinSubtreeCount(@if, 3);
    8691      SetMaxSubtreeCount(@if, 3);
    87       SetMinSubtreeCount(constant, 0);
    88       SetMaxSubtreeCount(constant, 0);
    89       SetMinSubtreeCount(variableSymbol, 0);
    90       SetMaxSubtreeCount(variableSymbol, 0);
     92
    9193
    9294      // allow each symbol as child of the start symbol
Note: See TracChangeset for help on using the changeset viewer.