Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/20/10 15:49:22 (14 years ago)
Author:
gkronber
Message:

Implemented views for DataAnalysisProblems and DataAnalysisSolutions. #938 (Data types and operators for regression problems)

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3
Files:
1 added
9 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisProblemData.cs

    r3376 r3442  
    3636  [StorableClass]
    3737  public class DataAnalysisProblemData : NamedItem {
     38    [Storable]
     39    private VariableCollection variables;
     40    public VariableCollection Variables {
     41      get { return variables; }
     42    }
     43
     44    #region variable properties
     45    public IVariable DatasetVariable {
     46      get { return variables["Dataset"]; }
     47    }
     48
     49    public IVariable TargetVariableVariable {
     50      get { return variables["TargetVariable"]; }
     51    }
     52
     53    public IVariable InputVariablesVariable {
     54      get { return variables["InputVariables"]; }
     55    }
     56
     57    public IVariable TrainingSamplesStartVariable {
     58      get { return variables["TrainingSamplesStart"]; }
     59    }
     60    public IVariable TrainingSamplesEndVariable {
     61      get { return variables["TrainingSamplesEnd"]; }
     62    }
     63
     64    public IVariable TestSamplesStartVariable {
     65      get { return variables["TestSamplesStart"]; }
     66    }
     67    public IVariable TestSamplesEndVariable {
     68      get { return variables["TestSamplesEnd"]; }
     69    }
     70    #endregion
     71
    3872    #region properties
    39     private Dataset dataset;
    40     [Storable]
    4173    public Dataset Dataset {
    42       get { return dataset; }
    43       set {
    44         if (dataset != value) {
    45           if (value == null) throw new ArgumentNullException();
    46           else {
    47             dataset = value;
    48             OnDatasetChanged(EventArgs.Empty);
    49           }
    50         }
    51       }
    52     }
    53     private StringValue targetVariable;
    54     [Storable]
     74      get { return (Dataset)DatasetVariable.Value; }
     75      set {
     76        if (value != Dataset) {
     77          if (value == null) throw new ArgumentNullException();
     78          if (Dataset != null) DeregisterDatasetEventHandlers();
     79          DatasetVariable.Value = value;
     80          RegisterDatasetEventHandlers();
     81          OnProblemDataChanged(EventArgs.Empty);
     82        }
     83      }
     84    }
    5585    public StringValue TargetVariable {
    56       get { return targetVariable; }
    57       set { targetVariable = value; }
    58     }
    59     private ItemList<StringValue> inputVariables;
    60     [Storable]
     86      get { return (StringValue)TargetVariableVariable.Value; }
     87      set {
     88        if (value != TargetVariableVariable) {
     89          if (value == null) throw new ArgumentNullException();
     90          if (TargetVariable != null) DeregisterStringValueEventHandlers(TargetVariable);
     91          TargetVariableVariable.Value = value;
     92          RegisterStringValueEventHandlers(TargetVariable);
     93          OnProblemDataChanged(EventArgs.Empty);
     94        }
     95      }
     96    }
    6197    public ItemList<StringValue> InputVariables {
    62       get { return inputVariables; }
    63       set {
    64         if (inputVariables != value) {
    65           if (value == null) throw new ArgumentNullException();
    66           else {
    67             inputVariables = value;
    68             OnInputVariablesChanged(EventArgs.Empty);
    69           }
    70         }
    71       }
    72     }
    73     private IntValue trainingSamplesStart;
    74     [Storable]
     98      get { return (ItemList<StringValue>)InputVariablesVariable.Value; }
     99      set {
     100        if (value != InputVariables) {
     101          if (value == null) throw new ArgumentNullException();
     102          if (InputVariables != null) DeregisterInputVariablesEventHandlers();
     103          InputVariablesVariable.Value = value;
     104          RegisterInputVariablesEventHandlers();
     105          OnProblemDataChanged(EventArgs.Empty);
     106        }
     107      }
     108    }
    75109    public IntValue TrainingSamplesStart {
    76       get { return trainingSamplesStart; }
    77       set { trainingSamplesStart = value; }
    78     }
    79     private IntValue trainingSamplesEnd;
    80     [Storable]
     110      get { return (IntValue)TrainingSamplesStartVariable.Value; }
     111      set {
     112        if (value != TrainingSamplesStart) {
     113          if (value == null) throw new ArgumentNullException();
     114          if (TrainingSamplesStart != null) DeregisterValueTypeEventHandlers(TrainingSamplesStart);
     115          TrainingSamplesStartVariable.Value = value;
     116          RegisterValueTypeEventHandlers(TrainingSamplesStart);
     117          OnProblemDataChanged(EventArgs.Empty);
     118        }
     119      }
     120    }
    81121    public IntValue TrainingSamplesEnd {
    82       get { return trainingSamplesEnd; }
    83       set { trainingSamplesEnd = value; }
    84     }
    85     private IntValue validationSamplesStart;
    86     [Storable]
    87     public IntValue ValidationSamplesStart {
    88       get { return validationSamplesStart; }
    89       set { validationSamplesStart = value; }
    90     }
    91     private IntValue validationSamplesEnd;
    92     [Storable]
    93     public IntValue ValidationSamplesEnd {
    94       get { return validationSamplesEnd; }
    95       set { validationSamplesEnd = value; }
    96     }
    97     private IntValue testSamplesStart;
    98     [Storable]
     122      get { return (IntValue)TrainingSamplesEndVariable.Value; }
     123      set {
     124        if (value != TrainingSamplesEnd) {
     125          if (value == null) throw new ArgumentNullException();
     126          if (TrainingSamplesEnd != null) DeregisterValueTypeEventHandlers(TrainingSamplesEnd);
     127          TrainingSamplesEndVariable.Value = value;
     128          RegisterValueTypeEventHandlers(TrainingSamplesEnd);
     129          OnProblemDataChanged(EventArgs.Empty);
     130        }
     131      }
     132    }
    99133    public IntValue TestSamplesStart {
    100       get { return testSamplesStart; }
    101       set { testSamplesStart = value; }
    102     }
    103     private IntValue testSamplesEnd;
    104     [Storable]
     134      get { return (IntValue)TestSamplesStartVariable.Value; }
     135      set {
     136        if (value != TestSamplesStart) {
     137          if (value == null) throw new ArgumentNullException();
     138          if (TestSamplesStart != null) DeregisterValueTypeEventHandlers(TestSamplesStart);
     139          TestSamplesStartVariable.Value = value;
     140          RegisterValueTypeEventHandlers(TestSamplesStart);
     141          OnProblemDataChanged(EventArgs.Empty);
     142        }
     143      }
     144    }
    105145    public IntValue TestSamplesEnd {
    106       get { return testSamplesEnd; }
    107       set { testSamplesEnd = value; }
     146      get { return (IntValue)TestSamplesEndVariable.Value; }
     147      set {
     148        if (value != TestSamplesEnd) {
     149          if (value == null) throw new ArgumentNullException();
     150          if (TestSamplesEnd != null) DeregisterValueTypeEventHandlers(TestSamplesEnd);
     151          TestSamplesEndVariable.Value = value;
     152          RegisterValueTypeEventHandlers(TestSamplesEnd);
     153          OnProblemDataChanged(EventArgs.Empty);
     154        }
     155      }
    108156    }
    109157    #endregion
     
    111159    public DataAnalysisProblemData()
    112160      : base() {
    113       dataset = new Dataset();
    114       targetVariable = new StringValue();
    115       inputVariables = new ItemList<StringValue>();
    116       trainingSamplesStart = new IntValue();
    117       trainingSamplesEnd = new IntValue();
    118       validationSamplesStart = new IntValue();
    119       validationSamplesEnd = new IntValue();
    120       testSamplesStart = new IntValue();
    121       testSamplesEnd = new IntValue();
     161      variables = new VariableCollection();
     162      variables.Add(new Variable("Dataset", new Dataset()));
     163      variables.Add(new Variable("InputVariables", new ItemList<StringValue>()));
     164      variables.Add(new Variable("TargetVariable", new StringValue()));
     165      variables.Add(new Variable("TrainingSamplesStart", new IntValue()));
     166      variables.Add(new Variable("TrainingSamplesEnd", new IntValue()));
     167      variables.Add(new Variable("TestSamplesStart", new IntValue()));
     168      variables.Add(new Variable("TestSamplesEnd", new IntValue()));
     169      RegisterEventHandlers();
    122170    }
    123171
     
    125173    private DataAnalysisProblemData(bool deserializing) : base() { }
    126174
     175    [StorableHook(HookType.AfterDeserialization)]
     176    private void AfterDeserializationHook() {
     177      RegisterEventHandlers();
     178    }
     179
    127180    #region events
    128     public event EventHandler InputVariablesChanged;
    129     protected virtual void OnInputVariablesChanged(EventArgs e) {
    130       var listeners = InputVariablesChanged;
     181    private void RegisterEventHandlers() {
     182      RegisterDatasetEventHandlers();
     183      RegisterInputVariablesEventHandlers();
     184      RegisterStringValueEventHandlers(TargetVariable);
     185      RegisterValueTypeEventHandlers(TrainingSamplesStart);
     186      RegisterValueTypeEventHandlers(TrainingSamplesEnd);
     187      RegisterValueTypeEventHandlers(TestSamplesStart);
     188      RegisterValueTypeEventHandlers(TestSamplesEnd);
     189    }
     190
     191    public event EventHandler ProblemDataChanged;
     192    protected virtual void OnProblemDataChanged(EventArgs e) {
     193      var listeners = ProblemDataChanged;
    131194      if (listeners != null) listeners(this, e);
    132195    }
    133196
    134     public event EventHandler DatasetChanged;
    135     protected virtual void OnDatasetChanged(EventArgs e) {
    136       EventHandler handler = DatasetChanged;
    137       if (handler != null) handler(this, e);
    138     }
     197
     198    private void RegisterValueTypeEventHandlers<T>(ValueTypeValue<T> value) where T : struct {
     199      value.ValueChanged += new EventHandler(value_ValueChanged);
     200    }
     201
     202    private void DeregisterValueTypeEventHandlers<T>(ValueTypeValue<T> value) where T : struct {
     203      value.ValueChanged -= new EventHandler(value_ValueChanged);
     204    }
     205
     206    void value_ValueChanged(object sender, EventArgs e) {
     207      OnProblemDataChanged(e);
     208    }
     209
     210    private void RegisterStringValueEventHandlers(StringValue value) {
     211      value.ValueChanged += new EventHandler(value_ValueChanged);
     212    }
     213
     214    private void DeregisterStringValueEventHandlers(StringValue value) {
     215      value.ValueChanged -= new EventHandler(value_ValueChanged);
     216    }
     217
     218    private void RegisterDatasetEventHandlers() {
     219      Dataset.DataChanged += new EventHandler<EventArgs<int, int>>(Dataset_DataChanged);
     220      Dataset.Reset += new EventHandler(Dataset_Reset);
     221      Dataset.ColumnNamesChanged += new EventHandler(Dataset_ColumnNamesChanged);
     222    }
     223
     224    private void DeregisterDatasetEventHandlers() {
     225      Dataset.DataChanged -= new EventHandler<EventArgs<int, int>>(Dataset_DataChanged);
     226      Dataset.Reset -= new EventHandler(Dataset_Reset);
     227      Dataset.ColumnNamesChanged -= new EventHandler(Dataset_ColumnNamesChanged);
     228    }
     229
     230    void Dataset_ColumnNamesChanged(object sender, EventArgs e) {
     231      OnProblemDataChanged(e);
     232    }
     233
     234    void Dataset_Reset(object sender, EventArgs e) {
     235      OnProblemDataChanged(e);
     236    }
     237
     238    void Dataset_DataChanged(object sender, EventArgs<int, int> e) {
     239      OnProblemDataChanged(e);
     240    }
     241
     242    private void RegisterInputVariablesEventHandlers() {
     243      InputVariables.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_CollectionReset);
     244      InputVariables.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_ItemsAdded);
     245      InputVariables.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_ItemsRemoved);
     246      InputVariables.ItemsReplaced += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_ItemsReplaced);
     247      foreach (var item in InputVariables)
     248        item.ValueChanged += new EventHandler(InputVariables_Value_ValueChanged);
     249    }
     250
     251    private void DeregisterInputVariablesEventHandlers() {
     252      InputVariables.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_CollectionReset);
     253      InputVariables.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_ItemsAdded);
     254      InputVariables.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_ItemsRemoved);
     255      InputVariables.ItemsReplaced -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_ItemsReplaced);
     256      foreach (var item in InputVariables) {
     257        item.ValueChanged -= new EventHandler(InputVariables_Value_ValueChanged);
     258      }
     259    }
     260
     261    void InputVariables_ItemsReplaced(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) {
     262      foreach (var indexedItem in e.OldItems)
     263        indexedItem.Value.ValueChanged -= new EventHandler(InputVariables_Value_ValueChanged);
     264      foreach (var indexedItem in e.Items)
     265        indexedItem.Value.ValueChanged += new EventHandler(InputVariables_Value_ValueChanged);
     266      OnProblemDataChanged(e);
     267    }
     268
     269    void InputVariables_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) {
     270      foreach (var indexedItem in e.Items)
     271        indexedItem.Value.ValueChanged -= new EventHandler(InputVariables_Value_ValueChanged);
     272      OnProblemDataChanged(e);
     273    }
     274
     275    void InputVariables_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) {
     276      foreach (var indexedItem in e.Items)
     277        indexedItem.Value.ValueChanged += new EventHandler(InputVariables_Value_ValueChanged);
     278      OnProblemDataChanged(e);
     279    }
     280
     281    void InputVariables_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) {
     282      foreach (var indexedItem in e.OldItems)
     283        indexedItem.Value.ValueChanged -= new EventHandler(InputVariables_Value_ValueChanged);
     284
     285      OnProblemDataChanged(e);
     286    }
     287    void InputVariables_Value_ValueChanged(object sender, EventArgs e) {
     288      OnProblemDataChanged(e);
     289    }
     290
    139291    #endregion
    140292
     
    147299      TargetVariable = new StringValue(Dataset.VariableNames.First());
    148300      InputVariables = new ItemList<StringValue>(Dataset.VariableNames.Skip(1).Select(s => new StringValue(s)));
     301      int middle = (int)(csvFileParser.Rows * 0.5);
    149302      TrainingSamplesStart = new IntValue(0);
    150       TrainingSamplesEnd = new IntValue(csvFileParser.Rows);
    151       TestSamplesStart = new IntValue(0);
     303      TrainingSamplesEnd = new IntValue(middle);
     304      TestSamplesStart = new IntValue(middle);
    152305      TestSamplesEnd = new IntValue(csvFileParser.Rows);
     306    }
     307
     308    public override IDeepCloneable Clone(Cloner cloner) {
     309      DataAnalysisProblemData clone = (DataAnalysisProblemData)base.Clone(cloner);
     310      clone.variables = (VariableCollection)variables.Clone(cloner);
     311
     312      clone.RegisterEventHandlers();
     313      return clone;
    153314    }
    154315  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisSolution.cs

    r3431 r3442  
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     28using System.Collections.Generic;
     29using System.Linq;
    2830
    2931namespace HeuristicLab.Problems.DataAnalysis {
     
    3335  [Item("DataAnalysisSolution", "Represents a solution for a data analysis problem which can be visualized in the GUI.")]
    3436  [StorableClass]
    35   public sealed class DataAnalysisSolution : Item {
     37  public class DataAnalysisSolution : Item {
    3638    [Storable]
    37     private IPredictor predictor;
    38     public IPredictor Predictor {
    39       get { return predictor; }
     39    private IModel model;
     40    public IModel Model {
     41      get { return model; }
    4042      set {
    41         if (predictor != value) {
    42           predictor = value;
    43           OnPredictorChanged();
     43        if (model != value) {
     44          model = value;
     45          OnModelChanged();
    4446        }
    4547      }
     
    5254      set {
    5355        if (problemData != value) {
     56          if (value == null) throw new ArgumentNullException();
    5457          if (problemData != null) DeregisterProblemDataEvents();
    5558          problemData = value;
    56           if (problemData != null) RegisterProblemDataEvents();
     59          RegisterProblemDataEvents();
    5760          OnProblemDataChanged();
    5861        }
    5962      }
    6063    }
    61    
     64
     65    private List<double> estimatedValues;
     66    public IEnumerable<double> EstimatedValues {
     67      get {
     68        return estimatedValues;
     69      }
     70    }
     71
     72    private List<double> estimatedTrainingValues;
     73    public IEnumerable<double> EstimatedTrainingValues {
     74      get {
     75        return estimatedTrainingValues;
     76      }
     77    }
     78
     79    private List<double> estimatedTestValues;
     80    public IEnumerable<double> EstimatedTestValues {
     81      get {
     82        return estimatedTestValues;
     83      }
     84    }
     85
    6286    public DataAnalysisSolution() : base() { }
    63     public DataAnalysisSolution(DataAnalysisProblemData problemData, IPredictor predictor)
     87    public DataAnalysisSolution(DataAnalysisProblemData problemData, IModel model)
    6488      : this() {
    6589      this.problemData = problemData;
    66       this.predictor = predictor;
     90      this.model = model;
    6791      Initialize();
    6892    }
     93
    6994    [StorableConstructor]
    7095    private DataAnalysisSolution(bool deserializing) : base(deserializing) { }
     
    75100    }
    76101
     102    private void RecalculateEstimatedValues() {
     103      estimatedValues = GetEstimatedValues(0, problemData.Dataset.Rows).ToList();
     104      int nTrainingValues = problemData.TrainingSamplesEnd.Value - problemData.TrainingSamplesStart.Value;
     105      estimatedTrainingValues = estimatedValues.Skip(problemData.TrainingSamplesStart.Value).Take(nTrainingValues).ToList();
     106      int nTestValues = problemData.TestSamplesEnd.Value - problemData.TestSamplesStart.Value;
     107      estimatedTestValues = estimatedValues.Skip(problemData.TestSamplesStart.Value).Take(nTestValues).ToList();
     108    }
     109
     110    private IEnumerable<double> GetEstimatedValues(int start, int end) {
     111      double[] xs = new double[ProblemData.InputVariables.Count];
     112      for (int row = 0; row < ProblemData.Dataset.Rows; row++) {
     113        for (int i = 0; i < xs.Length; i++) {
     114          var variableIndex = ProblemData.Dataset.GetVariableIndex(ProblemData.InputVariables[i].Value);
     115          xs[i] = ProblemData.Dataset[row, variableIndex];
     116        }
     117        yield return model.GetValue(xs);
     118      }
     119    }
     120
    77121    public override IDeepCloneable Clone(Cloner cloner) {
    78122      DataAnalysisSolution clone = new DataAnalysisSolution();
    79123      cloner.RegisterClonedObject(this, clone);
    80       clone.predictor = (IPredictor)cloner.Clone(predictor);
     124      clone.model = (IModel)cloner.Clone(model);
    81125      clone.problemData = problemData;
    82126      clone.Initialize();
     
    85129
    86130    #region Events
    87     public event EventHandler PredictorChanged;
    88     private void OnPredictorChanged() {
    89       var changed = PredictorChanged;
     131    public event EventHandler ModelChanged;
     132    private void OnModelChanged() {
     133      RecalculateEstimatedValues();
     134      var changed = ModelChanged;
    90135      if (changed != null)
    91136        changed(this, EventArgs.Empty);
     
    93138    public event EventHandler ProblemDataChanged;
    94139    private void OnProblemDataChanged() {
     140      RecalculateEstimatedValues();
    95141      var changed = ProblemDataChanged;
    96142      if (changed != null)
     
    99145
    100146    private void RegisterProblemDataEvents() {
    101       ProblemData.DatasetChanged += new EventHandler(ProblemData_DataSetChanged);
     147      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
    102148    }
    103149    private void DeregisterProblemDataEvents() {
    104       ProblemData.DatasetChanged += new EventHandler(ProblemData_DataSetChanged);
     150      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
    105151    }
    106152
    107     private void ProblemData_DataSetChanged(object sender, EventArgs e) {
     153    private void ProblemData_Changed(object sender, EventArgs e) {
    108154      OnProblemDataChanged();
    109155    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Dataset.cs

    r3431 r3442  
    3636  public sealed class Dataset : NamedItem, IStringConvertibleMatrix {
    3737    public Dataset()
    38       : this(new string[0], new double[,] { { } }) {
     38      : this(new string[1] { "y" }, new double[,] { { 0.0 } }) {
    3939    }
    4040
     
    4545        throw new ArgumentException("Number of variable names doesn't match the number of columns of data");
    4646      }
    47       Data = data;
    48       this.VariableNames = variableNames;
     47      this.data = data;
     48      this.variableNames = variableNames.ToArray();
    4949      this.SortableView = false;
    5050    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj

    r3408 r3442  
    9393    <Compile Include="Evaluators\SimpleMSEEvaluator.cs" />
    9494    <Compile Include="HeuristicLabProblemsDataAnalysisPlugin.cs" />
    95     <Compile Include="Interfaces\IPredictor.cs" />
     95    <Compile Include="Interfaces\IModel.cs" />
    9696    <Compile Include="MatrixExtensions.cs" />
    9797    <Compile Include="Properties\AssemblyInfo.cs" />
    9898    <Compile Include="Symbolic\ArithmeticExpressionGrammar.cs" />
    9999    <Compile Include="Symbolic\SimpleArithmeticExpressionEvaluator.cs" />
     100    <Compile Include="Symbolic\SymbolicSimplifier.cs" />
    100101    <Compile Include="Symbolic\Symbols\Constant.cs" />
    101102    <Compile Include="Symbolic\Symbols\ConstantTreeNode.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Interfaces/IModel.cs

    r3409 r3442  
    3131
    3232namespace HeuristicLab.Problems.DataAnalysis {
    33   public interface IPredictor : IDeepCloneable {
    34     double Estimate(double[] xs);
     33  public interface IModel : IDeepCloneable {
     34    double GetValue(double[] xs);
    3535  }
    3636}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/ArithmeticExpressionGrammar.cs

    r3376 r3442  
    3535  public class ArithmeticExpressionGrammar : DefaultSymbolicExpressionGrammar {
    3636    [Storable]
    37     private List<string> variableNames = new List<string>();
    38     public IEnumerable<string> VariableNames {
    39       get { return variableNames; }
    40       set {
    41         variableNames = new List<string>(value);
    42         variableSymbol.VariableNames = variableNames;
    43       }
    44     }
    45 
    46     [Storable]
    4737    private HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable variableSymbol;
    4838
     
    5848      var div = new Division();
    5949      var constant = new Constant();
     50      constant.MinValue = -20;
     51      constant.MaxValue = 20;
    6052      variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable();
    6153
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionEvaluator.cs

    r3409 r3442  
    4444        this.row = row;
    4545        pc = 0;
    46         arguments.Clear();
     46        argumentStack.Clear();
    4747        var estimatedValue = Evaluate();
    4848        if (double.IsNaN(estimatedValue) || double.IsInfinity(estimatedValue)) yield return 0.0;
     
    5151    }
    5252
    53     private List<double> arguments = new List<double>();
     53    private Stack<List<double>> argumentStack = new Stack<List<double>>();
    5454    public double Evaluate() {
    5555      var currentInstr = code[pc++];
     
    8585        case CodeSymbol.Call: {
    8686            // save current arguments
    87             var oldArgs = new List<double>(arguments);
    88             arguments.Clear();
     87            List<double> arguments = new List<double>();
    8988            // evaluate sub-trees
    9089            for (int i = 0; i < currentInstr.nArguments; i++) {
    9190              arguments.Add(Evaluate());
    9291            }
     92            argumentStack.Push(arguments);
    9393            // save the pc
    9494            int nextPc = pc;
     
    9797            // evaluate the function
    9898            double v = Evaluate();
     99            argumentStack.Pop();
    99100            // restore the pc => evaluation will continue at point after my subtrees 
    100101            pc = nextPc;
    101             // restore arguments
    102             arguments = oldArgs;
    103102            return v;
    104103          }
    105104        case CodeSymbol.Arg: {
    106             return arguments[currentInstr.iArg0];
     105            return argumentStack.Peek()[currentInstr.iArg0];
    107106          }
    108107        case CodeSymbol.Dynamic: {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/ConstantTreeNode.cs

    r3376 r3442  
    3434      get { return (Constant)base.Symbol; }
    3535    }
    36     public override bool HasLocalParameters {
    37       get {
    38         return true;
    39       }
    40     }
    4136
    4237    private double constantValue;
     
    5449    public ConstantTreeNode(Constant constantSymbol) : base(constantSymbol) { }
    5550
     51    public override bool HasLocalParameters {
     52      get {
     53        return true;
     54      }
     55    }
    5656    public override void ResetLocalParameters(IRandom random) {
    5757      base.ResetLocalParameters(random);
     
    6363      return new ConstantTreeNode(this);
    6464    }
     65
     66    public override string ToString() {
     67      return constantValue.ToString("E5");
     68    }
    6569  }
    6670}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Variable.cs

    r3376 r3442  
    5252    private List<string> variableNames;
    5353    [Storable]
    54     public ICollection<string> VariableNames {
     54    public IEnumerable<string> VariableNames {
    5555      get { return variableNames; }
    5656      set {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/VariableTreeNode.cs

    r3376 r3442  
    5656    public VariableTreeNode(Variable variableSymbol) : base(variableSymbol) { }
    5757
     58    public override bool HasLocalParameters {
     59      get {
     60        return true;
     61      }
     62    }
     63
    5864    public override void ResetLocalParameters(IRandom random) {
    5965      base.ResetLocalParameters(random);
     
    6874      return new VariableTreeNode(this);
    6975    }
     76
     77    public override string ToString() {
     78      return weight.ToString("E5") + " * " + variableName;
     79    }
    7080  }
    7181}
Note: See TracChangeset for help on using the changeset viewer.