Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4022 for trunk/sources


Ignore:
Timestamp:
07/09/10 17:01:36 (14 years ago)
Author:
gkronber
Message:

Worked on symbolic regression classes to prepare for time series prognosis plugin. #1081

Location:
trunk/sources
Files:
4 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Compiler/SymbolicExpressionTreeCompiler.cs

    r3747 r4022  
    3737      List<Instruction> code = new List<Instruction>();
    3838      entryPoint.Clear();
    39       // compile main body
    40       code.AddRange(Compile(tree.Root.SubTrees[0].SubTrees[0], opCodeMapper));
    41       // compile branches
     39      // compile main body branches
     40      foreach (var branch in tree.Root.SubTrees[0].SubTrees) {
     41        code.AddRange(Compile(branch, opCodeMapper));
     42      }     
     43      // compile function branches
    4244      var functionBranches = from node in tree.IterateNodesPrefix()
    4345                             where node.Symbol is Defun
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer.cs

    r3996 r4022  
    246246
    247247      #region validation best model
    248       int targetVariableIndex = ProblemData.Dataset.GetVariableIndex(ProblemData.TargetVariable.Value);
     248      string targetVariable = ProblemData.TargetVariable.Value;
    249249      int validationStart = ValidiationSamplesStart.Value;
    250250      int validationEnd = ValidationSamplesEnd.Value;
     
    257257      OnlineMeanSquaredErrorEvaluator mseEvaluator = new OnlineMeanSquaredErrorEvaluator();
    258258      foreach (var scaledTree in scaledTrees) {
    259         mseEvaluator.Reset();
    260         IEnumerable<double> estimatedValidationValues = SymbolicExpressionTreeInterpreter.GetSymbolicExpressionTreeValues(scaledTree, ProblemData.Dataset, Enumerable.Range(validationStart, validationEnd - validationStart));
    261         IEnumerable<double> originalValidationValues = ProblemData.Dataset.GetEnumeratedVariableValues(targetVariableIndex, validationStart, validationEnd);
    262         var estimatedEnumerator = estimatedValidationValues.GetEnumerator();
    263         var originalEnumerator = originalValidationValues.GetEnumerator();
    264         while (estimatedEnumerator.MoveNext() & originalEnumerator.MoveNext()) {
    265           double estimated = estimatedEnumerator.Current;
    266           if (double.IsNaN(estimated)) estimated = upperEstimationLimit;
    267           else estimated = Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, estimated));
    268           mseEvaluator.Add(originalEnumerator.Current, estimated);
    269         }
    270         double validationMse = mseEvaluator.MeanSquaredError;
     259        double validationMse = SymbolicRegressionMeanSquaredErrorEvaluator.Calculate(SymbolicExpressionTreeInterpreter, scaledTree,
     260          lowerEstimationLimit, upperEstimationLimit,
     261          ProblemData.Dataset, targetVariable,
     262          validationStart, validationEnd);
     263
    271264        if (validationMse < bestValidationMse) {
    272265          bestValidationMse = validationMse;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/HeuristicLab.Problems.DataAnalysis.Views-3.3.csproj

    r3975 r4022  
    172172      <DependentUpon>ConstantView.cs</DependentUpon>
    173173    </Compile>
     174    <Compile Include="Symbolic\Symbols\LaggedVariableView.cs">
     175      <SubType>UserControl</SubType>
     176    </Compile>
     177    <Compile Include="Symbolic\Symbols\LaggedVariableView.Designer.cs">
     178      <DependentUpon>LaggedVariableView.cs</DependentUpon>
     179    </Compile>
    174180    <Compile Include="Symbolic\Symbols\VariableView.cs">
    175181      <SubType>UserControl</SubType>
     
    252258      <Name>HeuristicLab.Problems.DataAnalysis-3.3</Name>
    253259    </ProjectReference>
     260  </ItemGroup>
     261  <ItemGroup>
     262    <EmbeddedResource Include="Symbolic\Symbols\LaggedVariableView.resx">
     263      <DependentUpon>LaggedVariableView.cs</DependentUpon>
     264    </EmbeddedResource>
    254265  </ItemGroup>
    255266  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisProblemData.cs

    r3933 r4022  
    3939    #region default data
    4040    // y = x^4 + x^3 + x^2 + x
    41     private readonly double[,] kozaF1 = new double[,] {
     41    private static double[,] kozaF1 = new double[,] {
    4242{2.017885919, -1.449165046},
    4343{1.30060506,  -1.344523885},
     
    185185    }
    186186
     187    public DataAnalysisProblemData(Dataset dataset, IEnumerable<string> inputVariables, string targetVariable,
     188      int trainingSamplesStart, int trainingSamplesEnd, int testSamplesStart, int testSamplesEnd) {
     189      var inputVariablesList = new CheckedItemList<StringValue>(inputVariables.Select(x => new StringValue(x)));
     190      StringValue targetVariableValue = new StringValue(targetVariable);
     191      var validTargetVariables = new ItemSet<StringValue>();
     192      foreach (var variable in dataset.VariableNames)
     193        if (variable != targetVariable)
     194          validTargetVariables.Add(new StringValue(variable));
     195      validTargetVariables.Add(targetVariableValue);
     196      Parameters.Add(new ValueParameter<Dataset>("Dataset", dataset));
     197      Parameters.Add(new ValueParameter<ICheckedItemList<StringValue>>("InputVariables", inputVariablesList.AsReadOnly()));
     198      Parameters.Add(new ConstrainedValueParameter<StringValue>("TargetVariable", validTargetVariables, targetVariableValue));
     199      Parameters.Add(new ValueParameter<IntValue>("TrainingSamplesStart", new IntValue(trainingSamplesStart)));
     200      Parameters.Add(new ValueParameter<IntValue>("TrainingSamplesEnd", new IntValue(trainingSamplesEnd)));
     201      Parameters.Add(new ValueParameter<IntValue>("TestSamplesStart", new IntValue(testSamplesStart)));
     202      Parameters.Add(new ValueParameter<IntValue>("TestSamplesEnd", new IntValue(testSamplesEnd)));
     203      RegisterParameterEventHandlers();
     204      RegisterParameterValueEventHandlers();
     205    }
    187206
    188207    [StorableConstructor]
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/OnlineMeanAbsolutePercentageErrorEvaluator.cs

    r3996 r4022  
    4747    }
    4848
    49     #region IPairedEnumerableEvaluator Members
     49    #region IOnlineEvaluator Members
     50    public double Value {
     51      get { return MeanAbsolutePercentageError; }
     52    }
    5053    public void Reset() {
    5154      n = 0;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/OnlineMeanSquaredErrorEvaluator.cs

    r3996 r4022  
    4848
    4949    #region IOnlineEvaluator Members
     50    public double Value {
     51      get { return MeanSquaredError; }
     52    }
    5053    public void Reset() {
    5154      n = 0;
     
    5659      if (double.IsNaN(estimated) || double.IsInfinity(estimated) ||
    5760          double.IsNaN(original) || double.IsInfinity(original)) {
    58             throw new ArgumentException("Mean squared error is not defined for NaN or infinity elements");
     61        throw new ArgumentException("Mean squared error is not defined for NaN or infinity elements");
    5962      } else {
    6063        double error = estimated - original;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/OnlinePearsonsRSquaredEvaluator.cs

    r3996 r4022  
    6161
    6262    #region IOnlineEvaluator Members
     63    public double Value {
     64      get { return RSquared; }
     65    }
    6366    public void Reset() {
    6467      sum_sq_x = 0.0;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleNMSEEvaluator.cs

    r3462 r4022  
    5050
    5151    public static double Calculate(IEnumerable<double> original, IEnumerable<double> estimated) {
    52       double mse = SimpleMSEEvaluator.Calculate(original, estimated);
    53       return mse / original.Variance();
     52      OnlineNormalizedMeanSquaredErrorEvaluator nmseEvaluator = new OnlineNormalizedMeanSquaredErrorEvaluator();
     53      var originalEnumerator = original.GetEnumerator();
     54      var estimatedEnumerator = estimated.GetEnumerator();
     55      while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
     56        nmseEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
     57      }
     58      if (originalEnumerator.MoveNext() || estimatedEnumerator.MoveNext()) {
     59        throw new ArgumentException("Number of elements in original and estimated enumerations doesn't match.");
     60      }
     61      return nmseEvaluator.NormalizedMeanSquaredError;
    5462    }
    5563  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj

    r3999 r4022  
    8484    <None Include="HeuristicLabProblemsDataAnalysisPlugin.cs.frame" />
    8585    <None Include="Properties\AssemblyInfo.frame" />
     86    <Compile Include="Evaluators\OnlineMeanAndVarianceCalculator.cs" />
     87    <Compile Include="Evaluators\OnlineNormalizedMeanSquaredErrorEvaluator.cs" />
    8688    <Compile Include="DataAnalysisSolution.cs" />
    8789    <Compile Include="CsvFileParser.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Interfaces/IOnlineEvaluator.cs

    r3996 r4022  
    2828namespace HeuristicLab.Problems.DataAnalysis {
    2929  public interface IOnlineEvaluator {
     30    double Value { get; }
    3031    void Reset();
    3132    void Add(double original, double estimated);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionInterpreter.cs

    r3996 r4022  
    2121
    2222using System;
     23using System.Linq;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2425using HeuristicLab.Common;
     
    9798    private Instruction[] code;
    9899    private int pc;
     100    private double[] argumentStack = new double[ARGUMENT_STACK_SIZE];
     101    private int argStackPointer;
    99102
    100103    public override bool CanChangeName {
     
    140143    }
    141144
    142     private double[] argumentStack = new double[ARGUMENT_STACK_SIZE];
    143     private int argStackPointer;
    144 
    145     public double Evaluate() {
    146       var currentInstr = code[pc++];
     145    private double Evaluate() {
     146      Instruction currentInstr = code[pc++];
    147147      switch (currentInstr.opCode) {
    148148        case OpCodes.Add: {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/LaggedVariable.cs

    r3993 r4022  
    3434  [StorableClass]
    3535  [Item("LaggedVariable", "Represents a variable value with a time offset.")]
    36   public sealed class LaggedVariable : Symbol {
    37     #region Properties
    38     [Storable]
    39     private double weightNu;
    40     public double WeightNu {
    41       get { return weightNu; }
    42       set { weightNu = value; }
    43     }
    44     [Storable]
    45     private double weightSigma;
    46     public double WeightSigma {
    47       get { return weightSigma; }
    48       set {
    49         if (weightSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
    50         weightSigma = value;
    51       }
    52     }
    53     [Storable]
    54     private double weightManipulatorNu;
    55     public double WeightManipulatorNu {
    56       get { return weightManipulatorNu; }
    57       set { weightManipulatorNu = value; }
    58     }
    59     [Storable]
    60     private double weightManipulatorSigma;
    61     public double WeightManipulatorSigma {
    62       get { return weightManipulatorSigma; }
    63       set {
    64         if (weightManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
    65         weightManipulatorSigma = value;
    66       }
    67     }
    68     private List<string> variableNames;
    69     [Storable]
    70     public IEnumerable<string> VariableNames {
    71       get { return variableNames; }
    72       set {
    73         if (value == null) throw new ArgumentNullException();
    74         variableNames.Clear();
    75         variableNames.AddRange(value);
    76       }
    77     }
     36  public sealed class LaggedVariable : Variable {
     37    //#region Properties
     38    //[Storable]
     39    //private double weightNu;
     40    //public double WeightNu {
     41    //  get { return weightNu; }
     42    //  set { weightNu = value; }
     43    //}
     44    //[Storable]
     45    //private double weightSigma;
     46    //public double WeightSigma {
     47    //  get { return weightSigma; }
     48    //  set {
     49    //    if (weightSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
     50    //    weightSigma = value;
     51    //  }
     52    //}
     53    //[Storable]
     54    //private double weightManipulatorNu;
     55    //public double WeightManipulatorNu {
     56    //  get { return weightManipulatorNu; }
     57    //  set { weightManipulatorNu = value; }
     58    //}
     59    //[Storable]
     60    //private double weightManipulatorSigma;
     61    //public double WeightManipulatorSigma {
     62    //  get { return weightManipulatorSigma; }
     63    //  set {
     64    //    if (weightManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
     65    //    weightManipulatorSigma = value;
     66    //  }
     67    //}
     68    //private List<string> variableNames;
     69    //[Storable]
     70    //public IEnumerable<string> VariableNames {
     71    //  get { return variableNames; }
     72    //  set {
     73    //    if (value == null) throw new ArgumentNullException();
     74    //    variableNames.Clear();
     75    //    variableNames.AddRange(value);
     76    //  }
     77    //}
    7878    [Storable]
    7979    private int minLag;
     
    8888      set { maxLag = value; }
    8989    }
    90     #endregion
     90    //#endregion
    9191    public LaggedVariable()
    9292      : base("LaggedVariable", "Represents a variable value with a time offset.") {
    93       weightNu = 1.0;
    94       weightSigma = 1.0;
    95       weightManipulatorNu = 0.0;
    96       weightManipulatorSigma = 1.0;
    97       variableNames = new List<string>();
    98       minLag = 0; maxLag = 0;
     93      //weightNu = 1.0;
     94      //weightSigma = 1.0;
     95      //weightManipulatorNu = 0.0;
     96      //weightManipulatorSigma = 1.0;
     97      //variableNames = new List<string>();
     98      minLag = -1; maxLag = -1;
    9999    }
    100100
     
    105105    public override IDeepCloneable Clone(Cloner cloner) {
    106106      LaggedVariable clone = (LaggedVariable)base.Clone(cloner);
    107       clone.weightNu = weightNu;
    108       clone.weightSigma = weightSigma;
    109       clone.variableNames = new List<string>(variableNames);
    110       clone.weightManipulatorNu = weightManipulatorNu;
    111       clone.weightManipulatorSigma = weightManipulatorSigma;
     107      //clone.weightNu = weightNu;
     108      //clone.weightSigma = weightSigma;
     109      //clone.variableNames = new List<string>(variableNames);
     110      //clone.weightManipulatorNu = weightManipulatorNu;
     111      //clone.weightManipulatorSigma = weightManipulatorSigma;
    112112      clone.minLag = minLag;
    113113      clone.maxLag = maxLag;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/LaggedVariableTreeNode.cs

    r3997 r4022  
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols {
    3131  [StorableClass]
    32   public sealed class LaggedVariableTreeNode : SymbolicExpressionTreeTerminalNode {
     32  public sealed class LaggedVariableTreeNode : VariableTreeNode {
    3333    public new LaggedVariable Symbol {
    3434      get { return (LaggedVariable)base.Symbol; }
    35     }
    36     [Storable]
    37     private double weight;
    38     public double Weight {
    39       get { return weight; }
    40       set { weight = value; }
    41     }
    42     [Storable]
    43     private string variableName;
    44     public string VariableName {
    45       get { return variableName; }
    46       set { variableName = value; }
    4735    }
    4836    [Storable]
     
    5846    private LaggedVariableTreeNode(LaggedVariableTreeNode original)
    5947      : base(original) {
    60       weight = original.weight;
    61       variableName = original.variableName;
    6248      lag = original.lag;
    6349    }
     
    7359    public override void ResetLocalParameters(IRandom random) {
    7460      base.ResetLocalParameters(random);
    75       weight = NormalDistributedRandom.NextDouble(random, Symbol.WeightNu, Symbol.WeightSigma);
    76       variableName = Symbol.VariableNames.SelectRandom(random);
    7761      lag = random.Next(Symbol.MinLag, Symbol.MaxLag + 1);
    7862    }
     
    8064    public override void ShakeLocalParameters(IRandom random, double shakingFactor) {
    8165      base.ShakeLocalParameters(random, shakingFactor);
    82       double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorNu, Symbol.WeightManipulatorSigma);
    83       weight = weight + x * shakingFactor;
    84       variableName = Symbol.VariableNames.SelectRandom(random);
    85       lag = lag + random.Next(-1, 2);
     66      lag = Math.Min(Symbol.MaxLag, Math.Max(Symbol.MinLag, lag + random.Next(-1, 2)));
    8667    }
    8768
     
    9273
    9374    public override string ToString() {
    94       return weight.ToString("E4") + " " + variableName + " (t" + (lag > 0 ? "+" : "") + lag + ")";
     75      return base.ToString() +
     76        " (t" + (lag > 0 ? "+" : "") + lag + ")";
    9577    }
    9678  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Variable.cs

    r3993 r4022  
    3434  [StorableClass]
    3535  [Item("Variable", "Represents a variable value.")]
    36   public sealed class Variable : Symbol {
     36  public class Variable : Symbol {
    3737    #region Properties
    3838    [Storable]
     
    9494    }
    9595    #endregion
    96     public Variable()
    97       : base("Variable", "Represents a variable value.") {
     96    public Variable() : this("Variable", "Represents a variable value.") { }
     97    public Variable(string name, string description)
     98      : base(name, description) {
    9899      weightNu = 1.0;
    99100      weightSigma = 1.0;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/VariableTreeNode.cs

    r3997 r4022  
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols {
    3131  [StorableClass]
    32   public sealed class VariableTreeNode : SymbolicExpressionTreeTerminalNode {
     32  public class VariableTreeNode : SymbolicExpressionTreeTerminalNode {
    3333    public new Variable Symbol {
    3434      get { return (Variable)base.Symbol; }
     
    4848
    4949
    50     private VariableTreeNode() { }
     50    protected VariableTreeNode() { }
    5151
    5252    // copy constructor
    53     private VariableTreeNode(VariableTreeNode original)
     53    protected VariableTreeNode(VariableTreeNode original)
    5454      : base(original) {
    5555      weight = original.weight;
Note: See TracChangeset for help on using the changeset viewer.