Changeset 3442 for trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3
- Timestamp:
- 04/20/10 15:49:22 (14 years ago)
- 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 36 36 [StorableClass] 37 37 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 38 72 #region properties 39 private Dataset dataset;40 [Storable]41 73 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 } 55 85 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 } 61 97 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 } 75 109 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 } 81 121 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 } 99 133 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 } 105 145 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 } 108 156 } 109 157 #endregion … … 111 159 public DataAnalysisProblemData() 112 160 : base() { 113 dataset = new Dataset();114 targetVariable = new StringValue();115 inputVariables = new ItemList<StringValue>();116 trainingSamplesStart = new IntValue();117 trainingSamplesEnd = new IntValue();118 va lidationSamplesStart = new IntValue();119 va lidationSamplesEnd = 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(); 122 170 } 123 171 … … 125 173 private DataAnalysisProblemData(bool deserializing) : base() { } 126 174 175 [StorableHook(HookType.AfterDeserialization)] 176 private void AfterDeserializationHook() { 177 RegisterEventHandlers(); 178 } 179 127 180 #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; 131 194 if (listeners != null) listeners(this, e); 132 195 } 133 196 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 139 291 #endregion 140 292 … … 147 299 TargetVariable = new StringValue(Dataset.VariableNames.First()); 148 300 InputVariables = new ItemList<StringValue>(Dataset.VariableNames.Skip(1).Select(s => new StringValue(s))); 301 int middle = (int)(csvFileParser.Rows * 0.5); 149 302 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); 152 305 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; 153 314 } 154 315 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisSolution.cs
r3431 r3442 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using System.Collections.Generic; 29 using System.Linq; 28 30 29 31 namespace HeuristicLab.Problems.DataAnalysis { … … 33 35 [Item("DataAnalysisSolution", "Represents a solution for a data analysis problem which can be visualized in the GUI.")] 34 36 [StorableClass] 35 public sealedclass DataAnalysisSolution : Item {37 public class DataAnalysisSolution : Item { 36 38 [Storable] 37 private I Predictor predictor;38 public I Predictor Predictor{39 get { return predictor; }39 private IModel model; 40 public IModel Model { 41 get { return model; } 40 42 set { 41 if ( predictor!= value) {42 predictor= value;43 On PredictorChanged();43 if (model != value) { 44 model = value; 45 OnModelChanged(); 44 46 } 45 47 } … … 52 54 set { 53 55 if (problemData != value) { 56 if (value == null) throw new ArgumentNullException(); 54 57 if (problemData != null) DeregisterProblemDataEvents(); 55 58 problemData = value; 56 if (problemData != null)RegisterProblemDataEvents();59 RegisterProblemDataEvents(); 57 60 OnProblemDataChanged(); 58 61 } 59 62 } 60 63 } 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 62 86 public DataAnalysisSolution() : base() { } 63 public DataAnalysisSolution(DataAnalysisProblemData problemData, I Predictor predictor)87 public DataAnalysisSolution(DataAnalysisProblemData problemData, IModel model) 64 88 : this() { 65 89 this.problemData = problemData; 66 this. predictor = predictor;90 this.model = model; 67 91 Initialize(); 68 92 } 93 69 94 [StorableConstructor] 70 95 private DataAnalysisSolution(bool deserializing) : base(deserializing) { } … … 75 100 } 76 101 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 77 121 public override IDeepCloneable Clone(Cloner cloner) { 78 122 DataAnalysisSolution clone = new DataAnalysisSolution(); 79 123 cloner.RegisterClonedObject(this, clone); 80 clone. predictor = (IPredictor)cloner.Clone(predictor);124 clone.model = (IModel)cloner.Clone(model); 81 125 clone.problemData = problemData; 82 126 clone.Initialize(); … … 85 129 86 130 #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; 90 135 if (changed != null) 91 136 changed(this, EventArgs.Empty); … … 93 138 public event EventHandler ProblemDataChanged; 94 139 private void OnProblemDataChanged() { 140 RecalculateEstimatedValues(); 95 141 var changed = ProblemDataChanged; 96 142 if (changed != null) … … 99 145 100 146 private void RegisterProblemDataEvents() { 101 ProblemData. DatasetChanged += new EventHandler(ProblemData_DataSetChanged);147 ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed); 102 148 } 103 149 private void DeregisterProblemDataEvents() { 104 ProblemData. DatasetChanged += new EventHandler(ProblemData_DataSetChanged);150 ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed); 105 151 } 106 152 107 private void ProblemData_ DataSetChanged(object sender, EventArgs e) {153 private void ProblemData_Changed(object sender, EventArgs e) { 108 154 OnProblemDataChanged(); 109 155 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Dataset.cs
r3431 r3442 36 36 public sealed class Dataset : NamedItem, IStringConvertibleMatrix { 37 37 public Dataset() 38 : this(new string[ 0], new double[,] { {} }) {38 : this(new string[1] { "y" }, new double[,] { { 0.0 } }) { 39 39 } 40 40 … … 45 45 throw new ArgumentException("Number of variable names doesn't match the number of columns of data"); 46 46 } 47 Data = data;48 this. VariableNames = variableNames;47 this.data = data; 48 this.variableNames = variableNames.ToArray(); 49 49 this.SortableView = false; 50 50 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj
r3408 r3442 93 93 <Compile Include="Evaluators\SimpleMSEEvaluator.cs" /> 94 94 <Compile Include="HeuristicLabProblemsDataAnalysisPlugin.cs" /> 95 <Compile Include="Interfaces\I Predictor.cs" />95 <Compile Include="Interfaces\IModel.cs" /> 96 96 <Compile Include="MatrixExtensions.cs" /> 97 97 <Compile Include="Properties\AssemblyInfo.cs" /> 98 98 <Compile Include="Symbolic\ArithmeticExpressionGrammar.cs" /> 99 99 <Compile Include="Symbolic\SimpleArithmeticExpressionEvaluator.cs" /> 100 <Compile Include="Symbolic\SymbolicSimplifier.cs" /> 100 101 <Compile Include="Symbolic\Symbols\Constant.cs" /> 101 102 <Compile Include="Symbolic\Symbols\ConstantTreeNode.cs" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Interfaces/IModel.cs
r3409 r3442 31 31 32 32 namespace HeuristicLab.Problems.DataAnalysis { 33 public interface I Predictor: IDeepCloneable {34 double Estimate(double[] xs);33 public interface IModel : IDeepCloneable { 34 double GetValue(double[] xs); 35 35 } 36 36 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/ArithmeticExpressionGrammar.cs
r3376 r3442 35 35 public class ArithmeticExpressionGrammar : DefaultSymbolicExpressionGrammar { 36 36 [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]47 37 private HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable variableSymbol; 48 38 … … 58 48 var div = new Division(); 59 49 var constant = new Constant(); 50 constant.MinValue = -20; 51 constant.MaxValue = 20; 60 52 variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable(); 61 53 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionEvaluator.cs
r3409 r3442 44 44 this.row = row; 45 45 pc = 0; 46 argument s.Clear();46 argumentStack.Clear(); 47 47 var estimatedValue = Evaluate(); 48 48 if (double.IsNaN(estimatedValue) || double.IsInfinity(estimatedValue)) yield return 0.0; … … 51 51 } 52 52 53 private List<double> arguments = new List<double>();53 private Stack<List<double>> argumentStack = new Stack<List<double>>(); 54 54 public double Evaluate() { 55 55 var currentInstr = code[pc++]; … … 85 85 case CodeSymbol.Call: { 86 86 // save current arguments 87 var oldArgs = new List<double>(arguments); 88 arguments.Clear(); 87 List<double> arguments = new List<double>(); 89 88 // evaluate sub-trees 90 89 for (int i = 0; i < currentInstr.nArguments; i++) { 91 90 arguments.Add(Evaluate()); 92 91 } 92 argumentStack.Push(arguments); 93 93 // save the pc 94 94 int nextPc = pc; … … 97 97 // evaluate the function 98 98 double v = Evaluate(); 99 argumentStack.Pop(); 99 100 // restore the pc => evaluation will continue at point after my subtrees 100 101 pc = nextPc; 101 // restore arguments102 arguments = oldArgs;103 102 return v; 104 103 } 105 104 case CodeSymbol.Arg: { 106 return argument s[currentInstr.iArg0];105 return argumentStack.Peek()[currentInstr.iArg0]; 107 106 } 108 107 case CodeSymbol.Dynamic: { -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/ConstantTreeNode.cs
r3376 r3442 34 34 get { return (Constant)base.Symbol; } 35 35 } 36 public override bool HasLocalParameters {37 get {38 return true;39 }40 }41 36 42 37 private double constantValue; … … 54 49 public ConstantTreeNode(Constant constantSymbol) : base(constantSymbol) { } 55 50 51 public override bool HasLocalParameters { 52 get { 53 return true; 54 } 55 } 56 56 public override void ResetLocalParameters(IRandom random) { 57 57 base.ResetLocalParameters(random); … … 63 63 return new ConstantTreeNode(this); 64 64 } 65 66 public override string ToString() { 67 return constantValue.ToString("E5"); 68 } 65 69 } 66 70 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Variable.cs
r3376 r3442 52 52 private List<string> variableNames; 53 53 [Storable] 54 public I Collection<string> VariableNames {54 public IEnumerable<string> VariableNames { 55 55 get { return variableNames; } 56 56 set { -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/VariableTreeNode.cs
r3376 r3442 56 56 public VariableTreeNode(Variable variableSymbol) : base(variableSymbol) { } 57 57 58 public override bool HasLocalParameters { 59 get { 60 return true; 61 } 62 } 63 58 64 public override void ResetLocalParameters(IRandom random) { 59 65 base.ResetLocalParameters(random); … … 68 74 return new VariableTreeNode(this); 69 75 } 76 77 public override string ToString() { 78 return weight.ToString("E5") + " * " + variableName; 79 } 70 80 } 71 81 }
Note: See TracChangeset
for help on using the changeset viewer.