Changeset 5275 for branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis
- Timestamp:
- 01/11/11 15:03:46 (12 years ago)
- Location:
- branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3
- Files:
-
- 2 added
- 1 deleted
- 63 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisProblem.cs
r4461 r5275 35 35 public class DataAnalysisProblem : ParameterizedNamedItem, IDataAnalysisProblem, IStorableContent { 36 36 private const string DataAnalysisProblemDataParameterName = "DataAnalysisProblemData"; 37 38 public string Filename { get; set; } 39 37 40 public override Image ItemImage { 38 41 get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; } 39 42 } 40 41 public string Filename { get; set; }42 43 43 44 #region Parameter Properties … … 54 55 [StorableConstructor] 55 56 protected DataAnalysisProblem(bool deserializing) : base(deserializing) { } 57 protected DataAnalysisProblem(DataAnalysisProblem original, Cloner cloner) 58 : base(original, cloner) { 59 RegisterParameterEvents(); 60 RegisterParameterValueEvents(); 61 } 62 56 63 public DataAnalysisProblem() 57 64 : base() { … … 62 69 63 70 [StorableHook(HookType.AfterDeserialization)] 64 private void AfterDeserialization Hook() {71 private void AfterDeserialization() { 65 72 RegisterParameterEvents(); 66 73 RegisterParameterValueEvents(); … … 90 97 91 98 public override IDeepCloneable Clone(Cloner cloner) { 92 DataAnalysisProblem clone = (DataAnalysisProblem)base.Clone(cloner); 93 clone.RegisterParameterEvents(); 94 clone.RegisterParameterValueEvents(); 95 return clone; 99 return new DataAnalysisProblem(this, cloner); 96 100 } 97 101 -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisProblemData.cs
r4457 r5275 34 34 [StorableClass] 35 35 public class DataAnalysisProblemData : ParameterizedNamedItem, IStorableContent { 36 private bool suppressEvents = false; 37 36 protected bool suppressEvents = false; 38 37 #region IStorableContent Members 39 38 public string Filename { get; set; } 40 39 #endregion 41 42 40 #region default data 43 41 // y = x^4 + x^3 + x^2 + x … … 71 69 #endregion 72 70 #region parameter properties 73 public IValueParameter<Dataset> DatasetParameter {74 get { return ( IValueParameter<Dataset>)Parameters["Dataset"]; }71 public ValueParameter<Dataset> DatasetParameter { 72 get { return (ValueParameter<Dataset>)Parameters["Dataset"]; } 75 73 } 76 74 public IValueParameter<StringValue> TargetVariableParameter { … … 92 90 get { return (IValueParameter<IntValue>)Parameters["TestSamplesEnd"]; } 93 91 } 92 public IValueParameter<PercentValue> ValidationPercentageParameter { 93 get { return (IValueParameter<PercentValue>)Parameters["ValidationPercentage"]; } 94 } 94 95 #endregion 95 96 96 97 #region properties 97 98 public Dataset Dataset { 98 get { return (Dataset)DatasetParameter.Value; }99 get { return DatasetParameter.Value; } 99 100 set { 100 101 if (value != Dataset) { … … 105 106 } 106 107 public StringValue TargetVariable { 107 get { return (StringValue)TargetVariableParameter.Value; }108 get { return TargetVariableParameter.Value; } 108 109 set { 109 110 if (value != TargetVariableParameter.Value) { … … 115 116 } 116 117 public ICheckedItemList<StringValue> InputVariables { 117 get { return (ICheckedItemList<StringValue>)InputVariablesParameter.Value; }118 get { return InputVariablesParameter.Value; } 118 119 set { 119 120 if (value != InputVariables) { … … 125 126 } 126 127 public IntValue TrainingSamplesStart { 127 get { return (IntValue)TrainingSamplesStartParameter.Value; }128 get { return TrainingSamplesStartParameter.Value; } 128 129 set { 129 130 if (value != TrainingSamplesStart) { … … 135 136 } 136 137 public IntValue TrainingSamplesEnd { 137 get { return (IntValue)TrainingSamplesEndParameter.Value; }138 get { return TrainingSamplesEndParameter.Value; } 138 139 set { 139 140 if (value != TrainingSamplesEnd) { … … 145 146 } 146 147 public IntValue TestSamplesStart { 147 get { return (IntValue)TestSamplesStartParameter.Value; }148 get { return TestSamplesStartParameter.Value; } 148 149 set { 149 150 if (value != TestSamplesStart) { … … 155 156 } 156 157 public IntValue TestSamplesEnd { 157 get { return (IntValue)TestSamplesEndParameter.Value; }158 get { return TestSamplesEndParameter.Value; } 158 159 set { 159 160 if (value != TestSamplesEnd) { … … 164 165 } 165 166 } 166 #endregion 167 167 public PercentValue ValidationPercentage { 168 get { return ValidationPercentageParameter.Value; } 169 set { 170 if (value != ValidationPercentage) { 171 if (value == null) throw new ArgumentNullException(); 172 if (value.Value < 0 || value.Value > 1) throw new ArgumentException("ValidationPercentage must be between 0 and 1."); 173 if (ValidationPercentage != null) DeregisterValueTypeEventHandlers(ValidationPercentage); 174 ValidationPercentageParameter.Value = value; 175 } 176 } 177 } 178 179 public IEnumerable<int> TrainingIndizes { 180 get { 181 return Enumerable.Range(TrainingSamplesStart.Value, TrainingSamplesEnd.Value - TrainingSamplesStart.Value) 182 .Where(i => i >= 0 && i < Dataset.Rows && (i < TestSamplesStart.Value || TestSamplesEnd.Value <= i)); 183 } 184 } 185 public IEnumerable<int> TestIndizes { 186 get { 187 return Enumerable.Range(TestSamplesStart.Value, TestSamplesEnd.Value - TestSamplesStart.Value) 188 .Where(i => i >= 0 && i < Dataset.Rows); 189 } 190 } 191 #endregion 192 193 [StorableConstructor] 194 protected DataAnalysisProblemData(bool deserializing) : base(deserializing) { } 195 protected DataAnalysisProblemData(DataAnalysisProblemData original, Cloner cloner) 196 : base(original, cloner) { 197 RegisterParameterEventHandlers(); 198 RegisterParameterValueEventHandlers(); 199 } 168 200 public DataAnalysisProblemData() 169 201 : base() { … … 181 213 Parameters.Add(new ValueParameter<IntValue>("TestSamplesStart", new IntValue(15))); 182 214 Parameters.Add(new ValueParameter<IntValue>("TestSamplesEnd", new IntValue(25))); 215 Parameters.Add(new ValueParameter<PercentValue>("ValidationPercentage", "The relative amount of the training samples that should be used as validation set.", new PercentValue(0.5))); 216 217 DatasetParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false; 183 218 RegisterParameterEventHandlers(); 184 219 RegisterParameterValueEventHandlers(); … … 187 222 public DataAnalysisProblemData(Dataset dataset, IEnumerable<string> inputVariables, string targetVariable, 188 223 int trainingSamplesStart, int trainingSamplesEnd, int testSamplesStart, int testSamplesEnd) { 189 var inputVariablesList = new CheckedItemList<StringValue>(inputVariables.Select(x => new StringValue(x)) );224 var inputVariablesList = new CheckedItemList<StringValue>(inputVariables.Select(x => new StringValue(x)).ToList()); 190 225 StringValue targetVariableValue = new StringValue(targetVariable); 191 226 var validTargetVariables = new ItemSet<StringValue>(); … … 201 236 Parameters.Add(new ValueParameter<IntValue>("TestSamplesStart", new IntValue(testSamplesStart))); 202 237 Parameters.Add(new ValueParameter<IntValue>("TestSamplesEnd", new IntValue(testSamplesEnd))); 238 Parameters.Add(new ValueParameter<PercentValue>("ValidationPercentage", "The relative amount of the training samples that should be used as validation set.", new PercentValue(0.5))); 239 240 DatasetParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false; 203 241 RegisterParameterEventHandlers(); 204 242 RegisterParameterValueEventHandlers(); 205 243 } 206 244 207 [StorableConstructor] 208 private DataAnalysisProblemData(bool deserializing) : base(deserializing) { } 245 public override IDeepCloneable Clone(Cloner cloner) { 246 return new DataAnalysisProblemData(this, cloner); 247 } 209 248 210 249 [StorableHook(HookType.AfterDeserialization)] 211 private void AfterDeserializationHook() { 250 private void AfterDeserialization() { 251 if (!Parameters.ContainsKey("ValidationPercentage")) 252 Parameters.Add(new ValueParameter<PercentValue>("ValidationPercentage", "The relative amount of the training samples that should be used as validation set.", new PercentValue(0.5))); 253 254 DatasetParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false; 212 255 RegisterParameterEventHandlers(); 213 256 RegisterParameterValueEventHandlers(); … … 217 260 public event EventHandler ProblemDataChanged; 218 261 protected virtual void OnProblemDataChanged(EventArgs e) { 219 if (!suppressEvents) { 262 if (TrainingSamplesStart.Value < 0) TrainingSamplesStart.Value = 0; 263 else if (TestSamplesStart.Value < 0) TestSamplesStart.Value = 0; 264 else if (TrainingSamplesEnd.Value > Dataset.Rows - 1) TrainingSamplesEnd.Value = Dataset.Rows - 1; 265 else if (TestSamplesEnd.Value > Dataset.Rows - 1) TestSamplesEnd.Value = Dataset.Rows - 1; 266 else if (TrainingSamplesStart.Value > TrainingSamplesEnd.Value) TrainingSamplesStart.Value = TestSamplesEnd.Value; 267 else if (TestSamplesStart.Value > TestSamplesEnd.Value) TestSamplesStart.Value = TestSamplesEnd.Value; 268 else if (ValidationPercentage.Value < 0) ValidationPercentage.Value = 0; 269 else if (ValidationPercentage.Value > 1) ValidationPercentage.Value = 1; 270 else if (!TrainingIndizes.Any()) throw new ArgumentException("No training samples are available."); 271 else if (!suppressEvents) { 220 272 var listeners = ProblemDataChanged; 221 273 if (listeners != null) listeners(this, e); … … 231 283 TestSamplesStartParameter.ValueChanged += new EventHandler(TestSamplesStartParameter_ValueChanged); 232 284 TestSamplesEndParameter.ValueChanged += new EventHandler(TestSamplesEndParameter_ValueChanged); 285 ValidationPercentageParameter.ValueChanged += new EventHandler(ValidationPercentageParameter_ValueChanged); 233 286 } 234 287 … … 240 293 RegisterValueTypeEventHandlers(TestSamplesStart); 241 294 RegisterValueTypeEventHandlers(TestSamplesEnd); 295 RegisterValueTypeEventHandlers(ValidationPercentage); 242 296 } 243 297 … … 271 325 private void TestSamplesEndParameter_ValueChanged(object sender, EventArgs e) { 272 326 RegisterValueTypeEventHandlers(TestSamplesEnd); 327 OnProblemDataChanged(EventArgs.Empty); 328 } 329 private void ValidationPercentageParameter_ValueChanged(object sender, EventArgs e) { 330 RegisterValueTypeEventHandlers(ValidationPercentage); 273 331 OnProblemDataChanged(EventArgs.Empty); 274 332 } … … 338 396 339 397 public virtual void ImportFromFile(string fileName) { 340 var csvFileParser = new CsvFileParser();398 var csvFileParser = new TableFileParser(); 341 399 csvFileParser.Parse(fileName); 342 400 suppressEvents = true; … … 352 410 InputVariables.SetItemCheckedState(variableNames.First(), false); 353 411 int middle = (int)(csvFileParser.Rows * 0.5); 412 TrainingSamplesEnd = new IntValue(middle); 354 413 TrainingSamplesStart = new IntValue(0); 355 T rainingSamplesEnd = new IntValue(middle);414 TestSamplesEnd = new IntValue(csvFileParser.Rows); 356 415 TestSamplesStart = new IntValue(middle); 357 TestSamplesEnd = new IntValue(csvFileParser.Rows);358 416 suppressEvents = false; 359 417 OnProblemDataChanged(EventArgs.Empty); 360 }361 362 public override IDeepCloneable Clone(Cloner cloner) {363 DataAnalysisProblemData clone = (DataAnalysisProblemData)base.Clone(cloner);364 clone.RegisterParameterEventHandlers();365 clone.RegisterParameterValueEventHandlers();366 return clone;367 418 } 368 419 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisSolution.cs
r4457 r5275 38 38 #endregion 39 39 40 40 [StorableConstructor] 41 protected DataAnalysisSolution(bool deserializing) : base(deserializing) { } 42 protected DataAnalysisSolution(DataAnalysisSolution original, Cloner cloner) 43 : base(original, cloner) { 44 problemData = (DataAnalysisProblemData)cloner.Clone(original.problemData); 45 model = (IDataAnalysisModel)cloner.Clone(original.model); 46 lowerEstimationLimit = original.lowerEstimationLimit; 47 upperEstimationLimit = original.upperEstimationLimit; 48 AfterDeserialization(); 49 } 41 50 protected DataAnalysisSolution() 42 51 : base() { } … … 47 56 this.lowerEstimationLimit = lowerEstimationLimit; 48 57 this.upperEstimationLimit = upperEstimationLimit; 49 Initialize();58 AfterDeserialization(); 50 59 } 51 60 52 [StorableConstructor]53 protected DataAnalysisSolution(bool deserializing) : base(deserializing) { }54 61 [StorableHook(HookType.AfterDeserialization)] 55 private void Initialize() {62 private void AfterDeserialization() { 56 63 if (problemData != null) 57 64 RegisterProblemDataEvents(); … … 134 141 public event EventHandler ProblemDataChanged; 135 142 protected virtual void OnProblemDataChanged() { 136 RecalculateEstimatedValues();137 143 var listeners = ProblemDataChanged; 138 144 if (listeners != null) … … 142 148 public event EventHandler ModelChanged; 143 149 protected virtual void OnModelChanged() { 144 EventHandler handler= ModelChanged;145 if ( handler!= null)146 handler(this, EventArgs.Empty);150 EventHandler listeners = ModelChanged; 151 if (listeners != null) 152 listeners(this, EventArgs.Empty); 147 153 } 148 154 … … 155 161 #endregion 156 162 157 public override IDeepCloneable Clone(Cloner cloner) {158 DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner);159 clone.problemData = (DataAnalysisProblemData)cloner.Clone(problemData);160 clone.model = (IDataAnalysisModel)cloner.Clone(model);161 clone.lowerEstimationLimit = lowerEstimationLimit;162 clone.upperEstimationLimit = upperEstimationLimit;163 clone.Initialize();164 165 return clone;166 }167 163 } 168 164 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/DataFormatException.cs
r4341 r5275 21 21 22 22 using System; 23 using System.Runtime.Serialization; 23 24 24 25 namespace HeuristicLab.Problems.DataAnalysis { 26 [Serializable] 25 27 public class DataFormatException : Exception { 26 28 private int line; … … 37 39 this.line = line; 38 40 } 41 42 public DataFormatException(SerializationInfo info, StreamingContext context) : base(info, context) { } 39 43 } 40 44 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Dataset.cs
r4341 r5275 32 32 [StorableClass] 33 33 public sealed class Dataset : NamedItem, IStringConvertibleMatrix { 34 // empty constructor for cloning35 private Dataset()36 : base() {37 }38 39 34 [StorableConstructor] 40 private Dataset(bool deserializing) 41 : base(deserializing) { 42 } 43 35 private Dataset(bool deserializing) : base(deserializing) { } 36 private Dataset(Dataset original, Cloner cloner) 37 : base(original, cloner) { 38 variableNames = original.variableNames; 39 data = original.data; 40 } 44 41 public Dataset(IEnumerable<string> variableNames, double[,] data) 45 42 : base() { … … 122 119 } 123 120 124 125 126 121 public string GetVariableName(int variableIndex) { 127 122 return variableNames[variableIndex]; … … 140 135 141 136 public override IDeepCloneable Clone(Cloner cloner) { 142 Dataset clone = (Dataset)base.Clone(cloner); 143 clone.variableNames = variableNames; 144 clone.data = data; 145 return clone; 137 return new Dataset(this, cloner); 146 138 } 147 139 … … 195 187 } 196 188 189 public event EventHandler ColumnsChanged; 190 private void OnColumnsChanged() { 191 var handler = ColumnsChanged; 192 if (handler != null) handler(this, EventArgs.Empty); 193 } 194 public event EventHandler RowsChanged; 195 private void OnRowsChanged() { 196 var handler = RowsChanged; 197 if (handler != null) handler(this, EventArgs.Empty); 198 } 197 199 public event EventHandler ColumnNamesChanged; 198 200 private void OnColumnNamesChanged() { 199 EventHandler handler= ColumnNamesChanged;200 if ( handler!= null)201 handler(this, EventArgs.Empty);201 EventHandler listeners = ColumnNamesChanged; 202 if (listeners != null) 203 listeners(this, EventArgs.Empty); 202 204 } 203 205 public event EventHandler RowNamesChanged; 204 206 private void OnRowNamesChanged() { 205 EventHandler handler= RowNamesChanged;206 if ( handler!= null)207 handler(this, EventArgs.Empty);207 EventHandler listeners = RowNamesChanged; 208 if (listeners != null) 209 listeners(this, EventArgs.Empty); 208 210 } 209 211 public event EventHandler SortableViewChanged; 210 212 private void OnSortableViewChanged() { 211 EventHandler handler= SortableViewChanged;212 if ( handler!= null)213 handler(this, EventArgs.Empty);213 EventHandler listeners = SortableViewChanged; 214 if (listeners != null) 215 listeners(this, EventArgs.Empty); 214 216 } 215 217 public event EventHandler<EventArgs<int, int>> ItemChanged; 216 218 private void OnItemChanged(int rowIndex, int columnIndex) { 217 if (ItemChanged != null) 218 ItemChanged(this, new EventArgs<int, int>(rowIndex, columnIndex)); 219 var listeners = ItemChanged; 220 if (listeners != null) 221 listeners(this, new EventArgs<int, int>(rowIndex, columnIndex)); 219 222 OnToStringChanged(); 220 223 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/OnlineCovarianceEvaluator.cs
r4233 r5275 25 25 public class OnlineCovarianceEvaluator : IOnlineEvaluator { 26 26 27 private double xMean, yMean, Cn;27 private double originalMean, estimatedMean, Cn; 28 28 private int n; 29 29 public double Covariance { … … 47 47 n = 0; 48 48 Cn = 0.0; 49 xMean = 0.0;50 yMean = 0.0;49 originalMean = 0.0; 50 estimatedMean = 0.0; 51 51 } 52 52 53 public void Add(double x, double y) {54 if (double.IsNaN( x) || double.IsInfinity(x) ||55 double.IsNaN( y) || double.IsInfinity(y)) {53 public void Add(double original, double estimated) { 54 if (double.IsNaN(estimated) || double.IsInfinity(estimated) || 55 double.IsNaN(original) || double.IsInfinity(original)) { 56 56 throw new ArgumentException("Covariance is not defined for series containing NaN or infinity elements"); 57 57 } else { 58 58 n++; 59 59 // online calculation of tMean 60 61 xMean = xMean + (x - xMean) / n; 62 double deltaY = y - yMean; // delta = (y - yMean(n-1)) 63 yMean = yMean + deltaY / n; 60 originalMean = originalMean + (original - originalMean) / n; 61 double delta = estimated - estimatedMean; // delta = (y - yMean(n-1)) 62 estimatedMean = estimatedMean + delta / n; 64 63 65 64 // online calculation of covariance 66 Cn = Cn + delta Y * (x - xMean); // C(n) = C(n-1) + (y - yMean(n-1)) (x - xMean(n))65 Cn = Cn + delta * (original - originalMean); // C(n) = C(n-1) + (y - yMean(n-1)) (t - tMean(n)) 67 66 } 68 67 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleEvaluator.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; 24 25 using HeuristicLab.Operators; 25 26 using HeuristicLab.Parameters; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 28 27 29 namespace HeuristicLab.Problems.DataAnalysis.Evaluators { … … 32 34 public ILookupParameter<DoubleMatrix> ValuesParameter { 33 35 get { return (ILookupParameter<DoubleMatrix>)Parameters["Values"]; } 36 } 37 [StorableConstructor] 38 protected SimpleEvaluator(bool deserializing) : base(deserializing) { } 39 protected SimpleEvaluator(SimpleEvaluator original, Cloner cloner) 40 : base(original, cloner) { 34 41 } 35 42 public SimpleEvaluator() -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleMSEEvaluator.cs
r4341 r5275 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Data; 27 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 30 29 31 namespace HeuristicLab.Problems.DataAnalysis.Evaluators { … … 34 36 } 35 37 38 [StorableConstructor] 39 protected SimpleMSEEvaluator(bool deserializing) : base(deserializing) { } 40 protected SimpleMSEEvaluator(SimpleMSEEvaluator original, Cloner cloner) 41 : base(original, cloner) { 42 } 43 public override IDeepCloneable Clone(Cloner cloner) { 44 return new SimpleMSEEvaluator(this, cloner); 45 } 36 46 public SimpleMSEEvaluator() { 37 47 Parameters.Add(new LookupParameter<DoubleValue>("MeanSquaredError", "The mean squared error of estimated values.")); -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleMeanAbsolutePercentageErrorEvaluator.cs
r4068 r5275 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Data; 27 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 30 29 31 namespace HeuristicLab.Problems.DataAnalysis.Evaluators { … … 33 35 } 34 36 37 [StorableConstructor] 38 protected SimpleMeanAbsolutePercentageErrorEvaluator(bool deserializing) : base(deserializing) { } 39 protected SimpleMeanAbsolutePercentageErrorEvaluator(SimpleMeanAbsolutePercentageErrorEvaluator original, Cloner cloner) 40 : base(original, cloner) { 41 } 35 42 public SimpleMeanAbsolutePercentageErrorEvaluator() { 36 43 Parameters.Add(new LookupParameter<PercentValue>("AverageRelativeError", "The average relative error of estimated values.")); … … 43 50 select values[i, ESTIMATION_INDEX]; 44 51 AverageRelativeErrorParameter.ActualValue = new PercentValue(Calculate(original, estimated)); 52 } 53 54 public override IDeepCloneable Clone(Cloner cloner) { 55 return new SimpleMeanAbsolutePercentageErrorEvaluator(this, cloner); 45 56 } 46 57 -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleMeanAbsolutePercentageOfRangeErrorEvaluator.cs
r4068 r5275 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 30 30 31 namespace HeuristicLab.Problems.DataAnalysis.Evaluators { … … 35 36 } 36 37 38 [StorableConstructor] 39 protected SimpleMeanAbsolutePercentageOfRangeErrorEvaluator(bool deserializing) : base(deserializing) { } 40 protected SimpleMeanAbsolutePercentageOfRangeErrorEvaluator(SimpleMeanAbsolutePercentageOfRangeErrorEvaluator original, Cloner cloner) 41 : base(original, cloner) { 42 } 37 43 public SimpleMeanAbsolutePercentageOfRangeErrorEvaluator() { 38 44 Parameters.Add(new LookupParameter<PercentValue>("AveragePercentageOfRangeError", "The average relative (percentage of range) error of estimated values.")); … … 45 51 select values[i, ESTIMATION_INDEX]; 46 52 AveragePercentageOfRangeErrorParameter.ActualValue = new PercentValue(Calculate(original, estimated)); 53 } 54 55 public override IDeepCloneable Clone(Cloner cloner) { 56 return new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator(this, cloner); 47 57 } 48 58 -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleNMSEEvaluator.cs
r4068 r5275 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Data; 27 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 30 29 31 namespace HeuristicLab.Problems.DataAnalysis.Evaluators { … … 34 36 } 35 37 38 [StorableConstructor] 39 protected SimpleNMSEEvaluator(bool deserializing) : base(deserializing) { } 40 protected SimpleNMSEEvaluator(SimpleNMSEEvaluator original, Cloner cloner) 41 : base(original, cloner) { 42 } 43 public override IDeepCloneable Clone(Cloner cloner) { 44 return new SimpleNMSEEvaluator(this, cloner); 45 } 36 46 public SimpleNMSEEvaluator() { 37 47 Parameters.Add(new LookupParameter<DoubleValue>("NormalizedMeanSquaredError", "The normalized mean squared error (divided by variance) of estimated values.")); -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleRSquaredEvaluator.cs
r4068 r5275 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Data; 27 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 30 29 31 namespace HeuristicLab.Problems.DataAnalysis.Evaluators { … … 32 34 get { return (ILookupParameter<DoubleValue>)Parameters["RSquared"]; } 33 35 } 34 36 [StorableConstructor] 37 protected SimpleRSquaredEvaluator(bool deserializing) : base(deserializing) { } 38 protected SimpleRSquaredEvaluator(SimpleRSquaredEvaluator original, Cloner cloner) 39 : base(original, cloner) { 40 } 41 public override IDeepCloneable Clone(Cloner cloner) { 42 return new SimpleRSquaredEvaluator(this, cloner); 43 } 35 44 public SimpleRSquaredEvaluator() { 36 45 Parameters.Add(new LookupParameter<DoubleValue>("RSquared", "The squared Pearson's Product Moment Correlation (R²) of estimated values and original values.")); -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleVarianceAccountedForEvaluator.cs
r4068 r5275 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 30 30 31 namespace HeuristicLab.Problems.DataAnalysis.Evaluators { … … 40 41 } 41 42 43 [StorableConstructor] 44 protected SimpleVarianceAccountedForEvaluator(bool deserializing) : base(deserializing) { } 45 protected SimpleVarianceAccountedForEvaluator(SimpleVarianceAccountedForEvaluator original, Cloner cloner) 46 : base(original, cloner) { 47 } 48 public override IDeepCloneable Clone(Cloner cloner) { 49 return new SimpleVarianceAccountedForEvaluator(this, cloner); 50 } 42 51 public SimpleVarianceAccountedForEvaluator() { 43 52 Parameters.Add(new LookupParameter<DoubleValue>("VarianceAccountedFor", "The variance of the original values accounted for by the estimated values (VAF(y,y') = 1 - var(y-y') / var(y) ).")); -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj
r5265 r5275 107 107 <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Common-3.3.dll</HintPath> 108 108 </Reference> 109 <Reference Include="HeuristicLab.Common.Resources-3.3"> 110 <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Common.Resources-3.3.dll</HintPath> 111 </Reference> 109 112 <Reference Include="HeuristicLab.Core-3.3"> 110 113 <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Core-3.3.dll</HintPath> … … 158 161 </ItemGroup> 159 162 <ItemGroup> 163 <Compile Include="Interfaces\ISingleObjectiveDataAnalysisProblem.cs" /> 164 <Compile Include="TableFileParser.cs" /> 160 165 <None Include="HeuristicLab.snk" /> 161 166 <None Include="HeuristicLabProblemsDataAnalysisPlugin.cs.frame" /> … … 166 171 <Compile Include="Evaluators\OnlineNormalizedMeanSquaredErrorEvaluator.cs" /> 167 172 <Compile Include="DataAnalysisSolution.cs" /> 168 <Compile Include="CsvFileParser.cs" />169 173 <Compile Include="DataAnalysisProblem.cs" /> 170 174 <Compile Include="DataAnalysisProblemData.cs" /> … … 269 273 SubWCRev "%25ProjectDir%25\" "%25ProjectDir%25\HeuristicLabProblemsDataAnalysisPlugin.cs.frame" "%25ProjectDir%25\HeuristicLabProblemsDataAnalysisPlugin.cs"</PreBuildEvent> 270 274 </PropertyGroup> 275 <PropertyGroup> 276 <PostBuildEvent> 277 </PostBuildEvent> 278 </PropertyGroup> 271 279 </Project> -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLabProblemsDataAnalysisPlugin.cs.frame
r4044 r5275 28 28 [Plugin("HeuristicLab.Problems.DataAnalysis","3.3.0.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Problems.DataAnalysis-3.3.dll", PluginFileType.Assembly)] 30 [PluginDependency("HeuristicLab.ALGLIB", " 2.5")]30 [PluginDependency("HeuristicLab.ALGLIB", "3.1")] 31 31 [PluginDependency("HeuristicLab.Collections", "3.3.0.0")] 32 32 [PluginDependency("HeuristicLab.Common", "3.3.0.0")] -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Interfaces/IDataAnalysisProblem.cs
r4068 r5275 24 24 namespace HeuristicLab.Problems.DataAnalysis { 25 25 public interface IDataAnalysisProblem : IProblem { 26 DataAnalysisProblemData DataAnalysisProblemData { get; } 26 27 } 27 28 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Operators/CovariantParsimonyPressure.cs
r5265 r5275 32 32 using HeuristicLab.Problems.DataAnalysis.Evaluators; 33 33 using HeuristicLab.Analysis; 34 using HeuristicLab.Common; 34 35 35 36 namespace HeuristicLab.Problems.DataAnalysis.Operators { … … 80 81 } 81 82 82 public CovariantParsimonyPressure(bool deserializing) : base(deserializing) { } 83 protected CovariantParsimonyPressure(bool deserializing) : base(deserializing) { } 84 protected CovariantParsimonyPressure(CovariantParsimonyPressure original, Cloner clone) : base(original, clone) { } 83 85 public CovariantParsimonyPressure() 84 86 : base() { … … 98 100 Parameters.Add(new ValueLookupParameter<BoolValue>("InvertComplexityAdaption")); 99 101 } 102 103 public override IDeepCloneable Clone(Cloner cloner) { 104 return new CovariantParsimonyPressure(this, cloner); 105 } 106 100 107 101 108 [StorableHook(Persistence.Default.CompositeSerializers.Storable.HookType.AfterDeserialization)] -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Operators/CovariantParsimonyPressureAdder.cs
r5265 r5275 32 32 using HeuristicLab.Problems.DataAnalysis.Evaluators; 33 33 using HeuristicLab.Analysis; 34 using HeuristicLab.Common; 34 35 35 36 namespace HeuristicLab.Problems.DataAnalysis.Operators { … … 66 67 67 68 [StorableConstructor] 68 public CovariantParsimonyPressureAdder(bool deserializing) : base(deserializing) { } 69 protected CovariantParsimonyPressureAdder(bool deserializing) : base(deserializing) { } 70 protected CovariantParsimonyPressureAdder(CovariantParsimonyPressureAdder original, Cloner cloner) : base(original, cloner) { } 69 71 public CovariantParsimonyPressureAdder() 70 72 : base() { … … 79 81 Parameters.Add(new ValueLookupParameter<BoolValue>("ApplyParsimonyPressure")); 80 82 } 81 83 public override IDeepCloneable Clone(Cloner cloner) { 84 return new CovariantParsimonyPressureAdder(this, cloner); 85 } 82 86 [StorableHook(Persistence.Default.CompositeSerializers.Storable.HookType.AfterDeserialization)] 83 87 private void AfterDeserialization() { -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Operators/DynOpEqComparator.cs
r5265 r5275 30 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 31 31 using System.Collections.Generic; 32 using HeuristicLab.Common; 32 33 33 34 namespace HeuristicLab.Problems.DataAnalysis.Operators { … … 81 82 } 82 83 84 [StorableConstructor] 85 protected DynOpEqComparator(bool deserializing) : base(deserializing) { } 86 protected DynOpEqComparator(DynOpEqComparator original, Cloner cloner) 87 : base(original, cloner) { 88 } 83 89 public DynOpEqComparator() 84 90 : base() { … … 100 106 } 101 107 108 public override IDeepCloneable Clone(Cloner cloner) { 109 return new DynOpEqComparator(this, cloner); 110 } 102 111 public override IOperation Apply() { 103 112 if (ResultParameter.ActualValue == null || ResultParameter.ActualValue.Value == true) { -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Operators/DynOpEqHistogramInitializer.cs
r5265 r5275 30 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 31 31 using System.Collections.Generic; 32 using HeuristicLab.Common; 32 33 33 34 namespace HeuristicLab.Problems.DataAnalysis.Operators { … … 63 64 } 64 65 66 [StorableConstructor] 67 protected DynOpEqHistogramInitializer(bool deserializing) : base(deserializing) { } 68 protected DynOpEqHistogramInitializer(DynOpEqHistogramInitializer original, Cloner cloner) 69 : base(original, cloner) { 70 } 65 71 public DynOpEqHistogramInitializer() 66 72 : base() { … … 75 81 Parameters.Add(new LookupParameter<BoolValue>("Maximization")); 76 82 } 77 83 public override IDeepCloneable Clone(Cloner cloner) { 84 return new DynOpEqHistogramInitializer(this, cloner); 85 } 78 86 public override IOperation Apply() { 79 87 if (BinCapacityParameter.ActualValue == null) { -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Operators/DynamicDepthLimitComparator.cs
r5265 r5275 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 31 using HeuristicLab.Common; 31 32 32 33 namespace HeuristicLab.Problems.DataAnalysis.Operators { … … 65 66 } 66 67 68 [StorableConstructor] 69 protected DynamicDepthLimitComparator(bool deserializing) : base(deserializing) { } 70 protected DynamicDepthLimitComparator(DynamicDepthLimitComparator original, Cloner cloner) 71 : base(original, cloner) { 72 } 73 67 74 public DynamicDepthLimitComparator() 68 75 : base() { … … 77 84 Parameters.Add(new ValueParameter<DoubleValue>("cLower", "", new DoubleValue(0.03))); 78 85 Parameters.Add(new ValueParameter<DoubleValue>("cRaise", "", new DoubleValue(0.015))); 86 } 87 88 public override IDeepCloneable Clone(Cloner cloner) { 89 return new DynamicDepthLimitComparator(this, cloner); 79 90 } 80 91 -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Operators/DynamicDepthLimitInitializer.cs
r5265 r5275 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 31 using HeuristicLab.Common; 31 32 32 33 namespace HeuristicLab.Problems.DataAnalysis.Operators { … … 41 42 } 42 43 44 [StorableConstructor] 45 protected DynamicDepthLimitInitializer(bool deserializing) : base(deserializing) { } 46 protected DynamicDepthLimitInitializer(DynamicDepthLimitInitializer original, Cloner cloner) 47 : base(original, cloner) { 48 } 43 49 public DynamicDepthLimitInitializer() 44 50 : base() { 45 51 Parameters.Add(new ValueLookupParameter<IntValue>("DynamicDepthLimit", "The current depth limit.")); 46 52 Parameters.Add(new ValueLookupParameter<IntValue>("InitialDepthLimit", "The initial depth limit.")); 53 } 54 public override IDeepCloneable Clone(Cloner cloner) { 55 return new DynamicDepthLimitInitializer(this, cloner); 47 56 } 48 57 -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Operators/WeightedParentsQualityVarianceComparator.cs
r5265 r5275 28 28 using HeuristicLab.Parameters; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Common; 30 31 31 32 namespace HeuristicLab.Problems.DataAnalysis.Operators { … … 61 62 } 62 63 64 [StorableConstructor] 65 protected WeightedParentsQualityVarianceComparator(bool deserializing) : base(deserializing) { } 66 protected WeightedParentsQualityVarianceComparator(WeightedParentsQualityVarianceComparator original, Cloner cloner) 67 : base(original, cloner) { 68 } 63 69 public WeightedParentsQualityVarianceComparator() 64 70 : base() { … … 75 81 Parameters.Add(new ScopeTreeLookupParameter<IntValue>("RightSideSamples", "The number of samples used to calculate the quality of the parent.")); 76 82 } 77 83 public override IDeepCloneable Clone(Cloner cloner) { 84 return new WeightedParentsQualityVarianceComparator(this, cloner); 85 } 78 86 public override IOperation Apply() { 79 87 double leftQuality = LeftSideParameter.ActualValue.Value; … … 114 122 double stat = (xmean - ymean) / Math.Sqrt(xvar / n + yvar / m); 115 123 double c = xvar / n / (xvar / n + yvar / m); 116 double df = (n - 1) * (m - 1) / ((m - 1) * AP.Math.Sqr(c) + (n - 1) * (1 - AP.Math.Sqr(c)));124 double df = (n - 1) * (m - 1) / ((m - 1) * alglib.math.sqr(c) + (n - 1) * (1 - alglib.math.sqr(c))); 117 125 if ((double)(stat) > (double)(0)) 118 p = 1 - 0.5 * ibetaf.incompletebeta(df / 2, 0.5, df / (df + AP.Math.Sqr(stat)));126 p = 1 - 0.5 * alglib.ibetaf.incompletebeta(df / 2, 0.5, df / (df + alglib.math.sqr(stat))); 119 127 else 120 p = 0.5 * ibetaf.incompletebeta(df / 2, 0.5, df / (df + AP.Math.Sqr(stat)));128 p = 0.5 * alglib.ibetaf.incompletebeta(df / 2, 0.5, df / (df + alglib.math.sqr(stat))); 121 129 double bothtails = 2 * Math.Min(p, 1 - p); 122 130 double lefttail = p; -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/ParameterAdjustmentProblem/SupportVectorMachineParameterAdjustmentBestSolutionAnalyzer.cs
r4068 r5275 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 31 using HeuristicLab.Problems.DataAnalysis.Evaluators; 32 using HeuristicLab.Common; 32 33 33 34 namespace HeuristicLab.Problems.DataAnalysis.SupportVectorMachine.ParameterAdjustmentProblem { … … 89 90 90 91 #endregion 91 92 [StorableConstructor] 93 protected SupportVectorMachineParameterAdjustmentBestSolutionAnalyzer(bool deserializing) : base(deserializing) { } 94 protected SupportVectorMachineParameterAdjustmentBestSolutionAnalyzer(SupportVectorMachineParameterAdjustmentBestSolutionAnalyzer original, Cloner cloner) 95 : base(original, cloner) { 96 } 92 97 public SupportVectorMachineParameterAdjustmentBestSolutionAnalyzer() 93 98 : base() { … … 103 108 Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the best support vector solution should be stored.")); 104 109 } 105 110 public override IDeepCloneable Clone(Cloner cloner) { 111 return new SupportVectorMachineParameterAdjustmentBestSolutionAnalyzer(this, cloner); 112 } 106 113 public override IOperation Apply() { 107 114 var points = ParameterVectorParameter.ActualValue; … … 124 131 if (bestModel == null) { 125 132 bestModel = SupportVectorMachineModelCreator.TrainModel(DataAnalysisProblemData, 126 DataAnalysisProblemData.Training SamplesStart.Value, DataAnalysisProblemData.TrainingSamplesEnd.Value,133 DataAnalysisProblemData.TrainingIndizes, 127 134 SvmType.Value, KernelType.Value, cost, nu, gamma, 0.0); 128 135 BestSolutionParameter.ActualValue = bestModel; … … 153 160 if (BestSolutionQualityParameter.ActualValue.Value > bestQuality) { 154 161 bestModel = SupportVectorMachineModelCreator.TrainModel(DataAnalysisProblemData, 155 DataAnalysisProblemData.Training SamplesStart.Value, DataAnalysisProblemData.TrainingSamplesEnd.Value,162 DataAnalysisProblemData.TrainingIndizes, 156 163 SvmType.Value, KernelType.Value, cost, nu, gamma, 0.0); 157 164 BestSolutionParameter.ActualValue = bestModel; -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/ParameterAdjustmentProblem/SupportVectorMachineParameterAdjustmentEvaluator.cs
r4068 r5275 28 28 using HeuristicLab.Parameters; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Common; 30 31 31 32 namespace HeuristicLab.Problems.DataAnalysis.SupportVectorMachine.ParameterAdjustmentProblem { … … 107 108 } 108 109 #endregion 109 110 [StorableConstructor] 111 protected SupportVectorMachineParameterAdjustmentEvaluator(bool deserializing) : base(deserializing) { } 112 protected SupportVectorMachineParameterAdjustmentEvaluator(SupportVectorMachineParameterAdjustmentEvaluator original, Cloner cloner) 113 : base(original, cloner) { 114 } 110 115 public SupportVectorMachineParameterAdjustmentEvaluator() 111 116 : base() { … … 130 135 evaluator.Successor = null; 131 136 } 137 public override IDeepCloneable Clone(Cloner cloner) { 138 return new SupportVectorMachineParameterAdjustmentEvaluator(this, cloner); 139 } 132 140 133 141 public override IOperation Apply() { -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/ParameterAdjustmentProblem/SupportVectorMachineParameterAdjustmentProblem.cs
r4118 r5275 130 130 [StorableConstructor] 131 131 private SupportVectorMachineParameterAdjustmentProblem(bool deserializing) : base(deserializing) { } 132 private SupportVectorMachineParameterAdjustmentProblem(SupportVectorMachineParameterAdjustmentProblem original, Cloner cloner) 133 : base(original, cloner) { 134 operators = original.operators.Where(x => IsNotFieldReferenced(x)).Select(x => (IOperator)cloner.Clone(x)).ToList(); 135 strategyVectorCreator = (StdDevStrategyVectorCreator)cloner.Clone(original.strategyVectorCreator); 136 operators.Add(strategyVectorCreator); 137 strategyVectorCrossover = (StdDevStrategyVectorCrossover)cloner.Clone(original.strategyVectorCrossover); 138 operators.Add(strategyVectorCrossover); 139 strategyVectorManipulator = (StdDevStrategyVectorManipulator)cloner.Clone(original.strategyVectorManipulator); 140 operators.Add(strategyVectorManipulator); 141 AttachEventHandlers(); 142 } 132 143 public SupportVectorMachineParameterAdjustmentProblem() 133 144 : base() { … … 167 178 168 179 public override IDeepCloneable Clone(Cloner cloner) { 169 SupportVectorMachineParameterAdjustmentProblem clone = (SupportVectorMachineParameterAdjustmentProblem)base.Clone(cloner); 170 clone.operators = operators.Where(x => IsNotFieldReferenced(x)).Select(x => (IOperator)cloner.Clone(x)).ToList(); 171 clone.strategyVectorCreator = (StdDevStrategyVectorCreator)cloner.Clone(strategyVectorCreator); 172 clone.operators.Add(clone.strategyVectorCreator); 173 clone.strategyVectorCrossover = (StdDevStrategyVectorCrossover)cloner.Clone(strategyVectorCrossover); 174 clone.operators.Add(strategyVectorCrossover); 175 clone.strategyVectorManipulator = (StdDevStrategyVectorManipulator)cloner.Clone(strategyVectorManipulator); 176 clone.operators.Add(strategyVectorManipulator); 177 clone.AttachEventHandlers(); 178 return clone; 179 } 180 180 return new SupportVectorMachineParameterAdjustmentProblem(this, cloner); 181 } 181 182 private bool IsNotFieldReferenced(IOperator x) { 182 183 return !(x == strategyVectorCreator -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/SupportVectorMachineCrossValidationEvaluator.cs
r4068 r5275 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; 25 27 using HeuristicLab.Data; … … 125 127 #endregion 126 128 129 [StorableConstructor] 130 protected SupportVectorMachineCrossValidationEvaluator(bool deserializing) : base(deserializing) { } 131 132 protected SupportVectorMachineCrossValidationEvaluator(SupportVectorMachineCrossValidationEvaluator original, 133 Cloner cloner) 134 : base(original, cloner) { } 127 135 public SupportVectorMachineCrossValidationEvaluator() 128 136 : base() { … … 142 150 } 143 151 152 public override IDeepCloneable Clone(Cloner cloner) { 153 return new SupportVectorMachineCrossValidationEvaluator(this, cloner); 154 } 155 144 156 public override IOperation Apply() { 145 double reductionRatio = 1.0; 157 double reductionRatio = 1.0; // TODO: make parameter 146 158 if (ActualSamplesParameter.ActualValue != null) 147 159 reductionRatio = ActualSamplesParameter.ActualValue.Value; 148 149 int reducedRows = (int)((SamplesEnd.Value - SamplesStart.Value) * reductionRatio); 160 IEnumerable<int> rows = 161 Enumerable.Range(SamplesStart.Value, SamplesEnd.Value - SamplesStart.Value) 162 .Where(i => i < DataAnalysisProblemData.TestSamplesStart.Value || DataAnalysisProblemData.TestSamplesEnd.Value <= i); 163 164 // create a new DataAnalysisProblemData instance 150 165 DataAnalysisProblemData reducedProblemData = (DataAnalysisProblemData)DataAnalysisProblemData.Clone(); 151 reducedProblemData.Dataset = CreateReducedDataset(RandomParameter.ActualValue, reducedProblemData.Dataset, reductionRatio, SamplesStart.Value, SamplesEnd.Value); 166 reducedProblemData.Dataset = 167 CreateReducedDataset(RandomParameter.ActualValue, reducedProblemData.Dataset, rows, reductionRatio); 168 reducedProblemData.TrainingSamplesStart.Value = 0; 169 reducedProblemData.TrainingSamplesEnd.Value = reducedProblemData.Dataset.Rows; 170 reducedProblemData.TestSamplesStart.Value = reducedProblemData.Dataset.Rows; 171 reducedProblemData.TestSamplesEnd.Value = reducedProblemData.Dataset.Rows; 172 reducedProblemData.ValidationPercentage.Value = 0; 152 173 153 174 double quality = PerformCrossValidation(reducedProblemData, 154 SamplesStart.Value, SamplesStart.Value + reducedRows,155 175 SvmType.Value, KernelType.Value, 156 176 Cost.Value, Nu.Value, Gamma.Value, Epsilon.Value, NumberOfFolds.Value); … … 160 180 } 161 181 162 private Dataset CreateReducedDataset(IRandom random, Dataset dataset, double reductionRatio, int start, int end) {163 int n = (int)((end - start) * reductionRatio); 182 private Dataset CreateReducedDataset(IRandom random, Dataset dataset, IEnumerable<int> rowIndices, double reductionRatio) { 183 164 184 // must not make a fink: 165 185 // => select n rows randomly from start..end … … 168 188 169 189 // all possible rowIndexes from start..end 170 int[] rowIndexes = Enumerable.Range(start, end - start).ToArray(); 190 int[] rowIndexArr = rowIndices.ToArray(); 191 int n = (int)Math.Max(1.0, rowIndexArr.Length * reductionRatio); 171 192 172 193 // knuth shuffle 173 for (int i = rowIndex es.Length - 1; i > 0; i--) {194 for (int i = rowIndexArr.Length - 1; i > 0; i--) { 174 195 int j = random.Next(0, i); 175 196 // swap 176 int tmp = rowIndex es[i];177 rowIndex es[i] = rowIndexes[j];178 rowIndex es[j] = tmp;197 int tmp = rowIndexArr[i]; 198 rowIndexArr[i] = rowIndexArr[j]; 199 rowIndexArr[j] = tmp; 179 200 } 180 201 181 202 // take the first n indexes (selected n rowIndexes from start..end) 182 203 // now order by index 183 var orderedRandomIndexes = rowIndexes.Take(n).OrderBy(x => x).ToArray(); 184 185 // now build a dataset collecting the rows from orderedRandomIndexes into the dataset starting at index start 186 double[,] reducedData = dataset.GetClonedData(); 204 int[] orderedRandomIndexes = 205 rowIndexArr.Take(n) 206 .OrderBy(x => x) 207 .ToArray(); 208 209 // now build a dataset containing only rows from orderedRandomIndexes 210 double[,] reducedData = new double[n, dataset.Columns]; 187 211 for (int i = 0; i < n; i++) { 188 212 for (int column = 0; column < dataset.Columns; column++) { 189 reducedData[ start +i, column] = dataset[orderedRandomIndexes[i], column];213 reducedData[i, column] = dataset[orderedRandomIndexes[i], column]; 190 214 } 191 215 } … … 198 222 double cost, double nu, double gamma, double epsilon, 199 223 int nFolds) { 200 return PerformCrossValidation(problemData, problemData.Training SamplesStart.Value, problemData.TrainingSamplesEnd.Value, svmType, kernelType, cost, nu, gamma, epsilon, nFolds);224 return PerformCrossValidation(problemData, problemData.TrainingIndizes, svmType, kernelType, cost, nu, gamma, epsilon, nFolds); 201 225 } 202 226 203 227 public static double PerformCrossValidation( 204 228 DataAnalysisProblemData problemData, 205 int start, int end,229 IEnumerable<int> rowIndices, 206 230 string svmType, string kernelType, 207 231 double cost, double nu, double gamma, double epsilon, … … 221 245 222 246 223 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(problemData, start, end);247 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(problemData, rowIndices); 224 248 SVM.RangeTransform rangeTransform = SVM.RangeTransform.Compute(problem); 225 249 SVM.Problem scaledProblem = Scaling.Scale(rangeTransform, problem); -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/SupportVectorMachineModel.cs
r4068 r5275 36 36 [StorableClass] 37 37 [Item("SupportVectorMachineModel", "Represents a support vector machine model.")] 38 public class SupportVectorMachineModel : NamedItem, IDataAnalysisModel { 39 public SupportVectorMachineModel() 40 : base() { 38 public sealed class SupportVectorMachineModel : NamedItem, IDataAnalysisModel { 39 [StorableConstructor] 40 private SupportVectorMachineModel(bool deserializing) : base(deserializing) { } 41 private SupportVectorMachineModel(SupportVectorMachineModel original, Cloner cloner) 42 : base(original, cloner) { 43 // only using a shallow copy here! (gkronber) 44 this.model = original.model; 45 this.rangeTransform = original.rangeTransform; 41 46 } 47 public SupportVectorMachineModel() : base() { } 42 48 43 49 private SVM.Model model; … … 72 78 73 79 public IEnumerable<double> GetEstimatedValues(DataAnalysisProblemData problemData, int start, int end) { 74 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(problemData, start, end);80 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(problemData, Enumerable.Range(start, end - start)); 75 81 SVM.Problem scaledProblem = Scaling.Scale(RangeTransform, problem); 76 82 77 83 return (from row in Enumerable.Range(0, scaledProblem.Count) 78 select SVM.Prediction.Predict(Model, scaledProblem.X[row])).ToList(); 84 select SVM.Prediction.Predict(Model, scaledProblem.X[row])) 85 .ToList(); 79 86 } 80 87 … … 130 137 131 138 public override IDeepCloneable Clone(Cloner cloner) { 132 SupportVectorMachineModel clone = (SupportVectorMachineModel)base.Clone(cloner); 133 // beware we are only using a shallow copy here! (gkronber) 134 clone.model = model; 135 clone.rangeTransform = rangeTransform; 136 return clone; 139 return new SupportVectorMachineModel(this, cloner); 137 140 } 138 141 -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/SupportVectorMachineModelCreator.cs
r4068 r5275 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Core; 24 27 using HeuristicLab.Data; … … 34 37 [StorableClass] 35 38 [Item("SupportVectorMachineModelCreator", "Represents an operator that creates a support vector machine model.")] 36 public class SupportVectorMachineModelCreator : SingleSuccessorOperator {39 public sealed class SupportVectorMachineModelCreator : SingleSuccessorOperator { 37 40 private const string DataAnalysisProblemDataParameterName = "DataAnalysisProblemData"; 38 41 private const string SvmTypeParameterName = "SvmType"; … … 108 111 #endregion 109 112 113 [StorableConstructor] 114 private SupportVectorMachineModelCreator(bool deserializing) : base(deserializing) { } 115 private SupportVectorMachineModelCreator(SupportVectorMachineModelCreator original, Cloner cloner) : base(original, cloner) { } 116 public override IDeepCloneable Clone(Cloner cloner) { 117 return new SupportVectorMachineModelCreator(this, cloner); 118 } 110 119 public SupportVectorMachineModelCreator() 111 120 : base() { … … 125 134 126 135 public override IOperation Apply() { 136 int start = SamplesStart.Value; 137 int end = SamplesEnd.Value; 138 IEnumerable<int> rows = 139 Enumerable.Range(start, end - start) 140 .Where(i => i < DataAnalysisProblemData.TestSamplesStart.Value || DataAnalysisProblemData.TestSamplesEnd.Value <= i); 141 127 142 SupportVectorMachineModel model = TrainModel(DataAnalysisProblemData, 128 SamplesStart.Value, SamplesEnd.Value,143 rows, 129 144 SvmType.Value, KernelType.Value, 130 145 Cost.Value, Nu.Value, Gamma.Value, Epsilon.Value); … … 138 153 string svmType, string kernelType, 139 154 double cost, double nu, double gamma, double epsilon) { 140 return TrainModel(problemData, problemData.Training SamplesStart.Value, problemData.TrainingSamplesEnd.Value, svmType, kernelType, cost, nu, gamma, epsilon);155 return TrainModel(problemData, problemData.TrainingIndizes, svmType, kernelType, cost, nu, gamma, epsilon); 141 156 } 142 157 143 158 public static SupportVectorMachineModel TrainModel( 144 159 DataAnalysisProblemData problemData, 145 int start, int end,160 IEnumerable<int> trainingIndizes, 146 161 string svmType, string kernelType, 147 162 double cost, double nu, double gamma, double epsilon) { … … 160 175 161 176 162 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(problemData, start, end);177 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(problemData, trainingIndizes); 163 178 SVM.RangeTransform rangeTransform = SVM.RangeTransform.Compute(problem); 164 179 SVM.Problem scaledProblem = Scaling.Scale(rangeTransform, problem); -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/SupportVectorMachineModelEvaluator.cs
r4068 r5275 20 20 #endregion 21 21 22 using System.Collections.Generic; 23 using System.Linq; 24 using HeuristicLab.Common; 22 25 using HeuristicLab.Core; 23 26 using HeuristicLab.Data; … … 68 71 } 69 72 #endregion 73 74 [StorableConstructor] 75 protected SupportVectorMachineModelEvaluator(bool deserializing) : base(deserializing) { } 76 protected SupportVectorMachineModelEvaluator(SupportVectorMachineModelEvaluator original, Cloner cloner) : base(original, cloner) { } 77 public override IDeepCloneable Clone(Cloner cloner) { 78 return new SupportVectorMachineModelEvaluator(this, cloner); 79 } 70 80 public SupportVectorMachineModelEvaluator() 71 81 : base() { … … 80 90 int start = SamplesStart.Value; 81 91 int end = SamplesEnd.Value; 92 IEnumerable<int> rows = 93 Enumerable.Range(start, end - start) 94 .Where(i => i < DataAnalysisProblemData.TestSamplesStart.Value || DataAnalysisProblemData.TestSamplesEnd.Value <= i); 82 95 83 ValuesParameter.ActualValue = new DoubleMatrix(Evaluate(SupportVectorMachineModel, DataAnalysisProblemData, start, end));96 ValuesParameter.ActualValue = new DoubleMatrix(Evaluate(SupportVectorMachineModel, DataAnalysisProblemData, rows)); 84 97 return base.Apply(); 85 98 } 86 99 87 public static double[,] Evaluate(SupportVectorMachineModel model, DataAnalysisProblemData problemData, int start, int end) {88 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(problemData, start, end);100 public static double[,] Evaluate(SupportVectorMachineModel model, DataAnalysisProblemData problemData, IEnumerable<int> rowIndices) { 101 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(problemData, rowIndices); 89 102 SVM.Problem scaledProblem = model.RangeTransform.Scale(problem); 90 103 … … 92 105 93 106 double[,] values = new double[scaledProblem.Count, 2]; 107 var rowEnumerator = rowIndices.GetEnumerator(); 94 108 for (int i = 0; i < scaledProblem.Count; i++) { 95 values[i, 0] = problemData.Dataset[start + i, targetVariableIndex]; 109 rowEnumerator.MoveNext(); 110 values[i, 0] = problemData.Dataset[rowEnumerator.Current, targetVariableIndex]; 96 111 values[i, 1] = SVM.Prediction.Predict(model.Model, scaledProblem.X[i]); 97 112 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/SupportVectorMachineUtil.cs
r4068 r5275 29 29 /// </summary> 30 30 /// <param name="problemData">The problem data to transform</param> 31 /// <param name="start">The index of the first row of <paramref name="problemData"/> to copy to the output.</param> 32 /// <param name="end">The last of the first row of <paramref name="problemData"/> to copy to the output.</param> 31 /// <param name="rowIndices">The rows of the dataset that should be contained in the resulting SVM-problem</param> 33 32 /// <returns>A problem data type that can be used to train a support vector machine.</returns> 34 public static SVM.Problem CreateSvmProblem(DataAnalysisProblemData problemData, int start, int end) { 35 int rowCount = end - start; 36 var targetVector = problemData.Dataset.GetVariableValues(problemData.TargetVariable.Value, start, end); 33 public static SVM.Problem CreateSvmProblem(DataAnalysisProblemData problemData, IEnumerable<int> rowIndices) { 34 double[] targetVector = 35 problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable.Value, rowIndices) 36 .ToArray(); 37 37 38 38 SVM.Node[][] nodes = new SVM.Node[targetVector.Length][]; 39 39 List<SVM.Node> tempRow; 40 40 int maxNodeIndex = 0; 41 for (int row = 0; row < rowCount; row++) { 41 int svmProblemRowIndex = 0; 42 foreach (int row in rowIndices) { 42 43 tempRow = new List<SVM.Node>(); 43 44 foreach (var inputVariable in problemData.InputVariables.CheckedItems) { 44 45 int col = problemData.Dataset.GetVariableIndex(inputVariable.Value.Value); 45 double value = problemData.Dataset[ start +row, col];46 double value = problemData.Dataset[row, col]; 46 47 if (!double.IsNaN(value)) { 47 int nodeIndex = col + 1; // make sure the smallest nodeIndex = 148 int nodeIndex = col + 1; // make sure the smallest nodeIndex is 1 (libSVM convention) 48 49 tempRow.Add(new SVM.Node(nodeIndex, value)); 49 50 if (nodeIndex > maxNodeIndex) maxNodeIndex = nodeIndex; 50 51 } 51 52 } 52 nodes[ row] = tempRow.OrderBy(x => x.Index).ToArray(); // make sure the values are sorted by node index53 nodes[svmProblemRowIndex++] = tempRow.OrderBy(x => x.Index).ToArray(); // make sure the values are sorted by node index 53 54 } 54 55 -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/ArithmeticExpressionGrammar.cs
r4341 r5275 21 21 22 22 using System.Collections.Generic; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 30 31 [Item("ArithmeticExpressionGrammar", "Represents a grammar for functional expressions using only arithmetic operations.")] 31 32 public class ArithmeticExpressionGrammar : DefaultSymbolicExpressionGrammar { 33 34 [StorableConstructor] 35 protected ArithmeticExpressionGrammar(bool deserializing) : base(deserializing) { } 36 protected ArithmeticExpressionGrammar(ArithmeticExpressionGrammar original, Cloner cloner) : base(original, cloner) { } 32 37 public ArithmeticExpressionGrammar() 33 38 : base() { 34 39 Initialize(); 35 40 } 36 37 [StorableConstructor]38 protected ArithmeticExpressionGrammar(bool deserializing) : base(deserializing) {}41 public override IDeepCloneable Clone(Cloner cloner) { 42 return new ArithmeticExpressionGrammar(this, cloner); 43 } 39 44 40 45 private void Initialize() { -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/BasicExpressionGrammar.cs
r4193 r5275 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 27 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols; 28 using HeuristicLab.Common; 28 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 29 30 [StorableClass] … … 33 34 private HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable variableSymbol; 34 35 36 [StorableConstructor] 37 protected BasicExpressionGrammar(bool deserializing) : base(deserializing) { } 38 protected BasicExpressionGrammar(BasicExpressionGrammar original, Cloner cloner) 39 : base(original, cloner) { 40 foreach (var symb in Symbols) { 41 var varSym = symb as HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable; 42 if (varSym != null) this.variableSymbol = varSym; 43 break; 44 } 45 } 35 46 public BasicExpressionGrammar() 36 47 : base() { … … 38 49 } 39 50 40 [StorableConstructor] 41 protected BasicExpressionGrammar(bool deserializing) : base(deserializing) { } 51 public override IDeepCloneable Clone(Cloner cloner) { 52 return new BasicExpressionGrammar(this, cloner); 53 } 42 54 43 55 private void Initialize() { -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/FullFunctionalExpressionGrammar.cs
r4341 r5275 21 21 22 22 using System.Collections.Generic; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 30 31 [Item("FullFunctionalExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")] 31 32 public class FullFunctionalExpressionGrammar : DefaultSymbolicExpressionGrammar { 33 [StorableConstructor] 34 protected FullFunctionalExpressionGrammar(bool deserializing) : base(deserializing) { } 35 protected FullFunctionalExpressionGrammar(FullFunctionalExpressionGrammar original, Cloner cloner) : base(original, cloner) { } 32 36 public FullFunctionalExpressionGrammar() 33 37 : base() { 34 38 Initialize(); 35 39 } 36 [StorableConstructor] 37 protected FullFunctionalExpressionGrammar(bool deserializing) : base(deserializing) { } 40 41 public override IDeepCloneable Clone(Cloner cloner) { 42 return new FullFunctionalExpressionGrammar(this, cloner); 43 } 38 44 39 45 private void Initialize() { -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionInterpreter.cs
r4193 r5275 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 32 33 [StorableClass] 33 34 [Item("SimpleArithmeticExpressionInterpreter", "Interpreter for arithmetic symbolic expression trees including function calls.")] 34 // not thread safe! 35 public class SimpleArithmeticExpressionInterpreter : NamedItem, ISymbolicExpressionTreeInterpreter { 35 public sealed class SimpleArithmeticExpressionInterpreter : NamedItem, ISymbolicExpressionTreeInterpreter { 36 36 private class OpCodes { 37 37 public const byte Add = 1; … … 65 65 public const byte Constant = 20; 66 66 public const byte Arg = 21; 67 public const byte Differential = 22;68 67 } 69 68 … … 90 89 { typeof(Constant), OpCodes.Constant }, 91 90 { typeof(Argument), OpCodes.Arg }, 92 { typeof(DifferentialVariable), OpCodes.Differential},93 91 }; 94 92 private const int ARGUMENT_STACK_SIZE = 1024; 95 93 96 private Dataset dataset;97 private int row;98 private Instruction[] code;99 private int pc;100 private double[] argumentStack = new double[ARGUMENT_STACK_SIZE];101 private int argStackPointer;102 103 94 public override bool CanChangeName { 104 95 get { return false; } … … 108 99 } 109 100 101 [StorableConstructor] 102 private SimpleArithmeticExpressionInterpreter(bool deserializing) : base(deserializing) { } 103 private SimpleArithmeticExpressionInterpreter(SimpleArithmeticExpressionInterpreter original, Cloner cloner) : base(original, cloner) { } 104 public override IDeepCloneable Clone(Cloner cloner) { 105 return new SimpleArithmeticExpressionInterpreter(this, cloner); 106 } 107 110 108 public SimpleArithmeticExpressionInterpreter() 111 109 : base() { … … 113 111 114 112 public IEnumerable<double> GetSymbolicExpressionTreeValues(SymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) { 115 this.dataset = dataset;116 113 var compiler = new SymbolicExpressionTreeCompiler(); 117 compiler.AddInstructionPostProcessingHook(PostProcessInstruction); 118 code = compiler.Compile(tree, MapSymbolToOpCode); 119 foreach (var row in rows) { 120 this.row = row; 121 pc = 0; 122 argStackPointer = 0; 123 yield return Evaluate(); 124 } 125 } 126 127 private Instruction PostProcessInstruction(Instruction instr) { 128 if (instr.opCode == OpCodes.Variable) { 129 var variableTreeNode = instr.dynamicNode as VariableTreeNode; 130 instr.iArg0 = (ushort)dataset.GetVariableIndex(variableTreeNode.VariableName); 131 } else if (instr.opCode == OpCodes.LagVariable) { 132 var variableTreeNode = instr.dynamicNode as LaggedVariableTreeNode; 133 instr.iArg0 = (ushort)dataset.GetVariableIndex(variableTreeNode.VariableName); 134 } else if (instr.opCode == OpCodes.Differential) { 135 var variableTreeNode = instr.dynamicNode as DifferentialVariableTreeNode; 136 instr.iArg0 = (ushort)dataset.GetVariableIndex(variableTreeNode.VariableName); 137 } 138 return instr; 114 Instruction[] code = compiler.Compile(tree, MapSymbolToOpCode); 115 116 for (int i = 0; i < code.Length; i++) { 117 Instruction instr = code[i]; 118 if (instr.opCode == OpCodes.Variable) { 119 var variableTreeNode = instr.dynamicNode as VariableTreeNode; 120 instr.iArg0 = (ushort)dataset.GetVariableIndex(variableTreeNode.VariableName); 121 code[i] = instr; 122 } else if (instr.opCode == OpCodes.LagVariable) { 123 var variableTreeNode = instr.dynamicNode as LaggedVariableTreeNode; 124 instr.iArg0 = (ushort)dataset.GetVariableIndex(variableTreeNode.VariableName); 125 code[i] = instr; 126 } 127 } 128 129 double[] argumentStack = new double[ARGUMENT_STACK_SIZE]; 130 foreach (var rowEnum in rows) { 131 int row = rowEnum; 132 int pc = 0; 133 int argStackPointer = 0; 134 yield return Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 135 } 136 } 137 138 private double Evaluate(Dataset dataset, ref int row, Instruction[] code, ref int pc, double[] argumentStack, ref int argStackPointer) { 139 Instruction currentInstr = code[pc++]; 140 switch (currentInstr.opCode) { 141 case OpCodes.Add: { 142 double s = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 143 for (int i = 1; i < currentInstr.nArguments; i++) { 144 s += Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 145 } 146 return s; 147 } 148 case OpCodes.Sub: { 149 double s = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 150 for (int i = 1; i < currentInstr.nArguments; i++) { 151 s -= Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 152 } 153 if (currentInstr.nArguments == 1) s = -s; 154 return s; 155 } 156 case OpCodes.Mul: { 157 double p = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 158 for (int i = 1; i < currentInstr.nArguments; i++) { 159 p *= Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 160 } 161 return p; 162 } 163 case OpCodes.Div: { 164 double p = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 165 for (int i = 1; i < currentInstr.nArguments; i++) { 166 p /= Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 167 } 168 if (currentInstr.nArguments == 1) p = 1.0 / p; 169 return p; 170 } 171 case OpCodes.Average: { 172 double sum = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 173 for (int i = 1; i < currentInstr.nArguments; i++) { 174 sum += Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 175 } 176 return sum / currentInstr.nArguments; 177 } 178 case OpCodes.Cos: { 179 return Math.Cos(Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer)); 180 } 181 case OpCodes.Sin: { 182 return Math.Sin(Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer)); 183 } 184 case OpCodes.Tan: { 185 return Math.Tan(Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer)); 186 } 187 case OpCodes.Exp: { 188 return Math.Exp(Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer)); 189 } 190 case OpCodes.Log: { 191 return Math.Log(Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer)); 192 } 193 case OpCodes.IfThenElse: { 194 double condition = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 195 double result; 196 if (condition > 0.0) { 197 result = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); SkipBakedCode(code, ref pc); 198 } else { 199 SkipBakedCode(code, ref pc); result = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 200 } 201 return result; 202 } 203 case OpCodes.AND: { 204 double result = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 205 for (int i = 1; i < currentInstr.nArguments; i++) { 206 if (result <= 0.0) SkipBakedCode(code, ref pc); 207 else { 208 result = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 209 } 210 } 211 return result <= 0.0 ? -1.0 : 1.0; 212 } 213 case OpCodes.OR: { 214 double result = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 215 for (int i = 1; i < currentInstr.nArguments; i++) { 216 if (result > 0.0) SkipBakedCode(code, ref pc); 217 else { 218 result = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 219 } 220 } 221 return result > 0.0 ? 1.0 : -1.0; 222 } 223 case OpCodes.NOT: { 224 return -Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 225 } 226 case OpCodes.GT: { 227 double x = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 228 double y = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 229 if (x > y) return 1.0; 230 else return -1.0; 231 } 232 case OpCodes.LT: { 233 double x = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 234 double y = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 235 if (x < y) return 1.0; 236 else return -1.0; 237 } 238 case OpCodes.Call: { 239 // evaluate sub-trees 240 // push on argStack in reverse order 241 for (int i = 0; i < currentInstr.nArguments; i++) { 242 argumentStack[argStackPointer + currentInstr.nArguments - i] = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 243 } 244 argStackPointer += currentInstr.nArguments; 245 246 // save the pc 247 int nextPc = pc; 248 // set pc to start of function 249 pc = currentInstr.iArg0; 250 // evaluate the function 251 double v = Evaluate(dataset, ref row, code, ref pc, argumentStack, ref argStackPointer); 252 253 // decrease the argument stack pointer by the number of arguments pushed 254 // to set the argStackPointer back to the original location 255 argStackPointer -= currentInstr.nArguments; 256 257 // restore the pc => evaluation will continue at point after my subtrees 258 pc = nextPc; 259 return v; 260 } 261 case OpCodes.Arg: { 262 return argumentStack[argStackPointer - currentInstr.iArg0]; 263 } 264 case OpCodes.Variable: { 265 var variableTreeNode = currentInstr.dynamicNode as VariableTreeNode; 266 return dataset[row, currentInstr.iArg0] * variableTreeNode.Weight; 267 } 268 case OpCodes.LagVariable: { 269 var laggedVariableTreeNode = currentInstr.dynamicNode as LaggedVariableTreeNode; 270 int actualRow = row + laggedVariableTreeNode.Lag; 271 if (actualRow < 0 || actualRow >= dataset.Rows) throw new ArgumentException("Out of range access to dataset row: " + row); 272 return dataset[actualRow, currentInstr.iArg0] * laggedVariableTreeNode.Weight; 273 } 274 case OpCodes.Constant: { 275 var constTreeNode = currentInstr.dynamicNode as ConstantTreeNode; 276 return constTreeNode.Value; 277 } 278 default: throw new NotSupportedException(); 279 } 139 280 } 140 281 … … 146 287 } 147 288 148 private double Evaluate() {149 Instruction currentInstr = code[pc++];150 switch (currentInstr.opCode) {151 case OpCodes.Add: {152 double s = Evaluate();153 for (int i = 1; i < currentInstr.nArguments; i++) {154 s += Evaluate();155 }156 return s;157 }158 case OpCodes.Sub: {159 double s = Evaluate();160 for (int i = 1; i < currentInstr.nArguments; i++) {161 s -= Evaluate();162 }163 if (currentInstr.nArguments == 1) s = -s;164 return s;165 }166 case OpCodes.Mul: {167 double p = Evaluate();168 for (int i = 1; i < currentInstr.nArguments; i++) {169 p *= Evaluate();170 }171 return p;172 }173 case OpCodes.Div: {174 double p = Evaluate();175 for (int i = 1; i < currentInstr.nArguments; i++) {176 p /= Evaluate();177 }178 if (currentInstr.nArguments == 1) p = 1.0 / p;179 return p;180 }181 case OpCodes.Average: {182 double sum = Evaluate();183 for (int i = 1; i < currentInstr.nArguments; i++) {184 sum += Evaluate();185 }186 return sum / currentInstr.nArguments;187 }188 case OpCodes.Cos: {189 return Math.Cos(Evaluate());190 }191 case OpCodes.Sin: {192 return Math.Sin(Evaluate());193 }194 case OpCodes.Tan: {195 return Math.Tan(Evaluate());196 }197 case OpCodes.Exp: {198 return Math.Exp(Evaluate());199 }200 case OpCodes.Log: {201 return Math.Log(Evaluate());202 }203 case OpCodes.IfThenElse: {204 double condition = Evaluate();205 double result;206 if (condition > 0.0) {207 result = Evaluate(); SkipBakedCode();208 } else {209 SkipBakedCode(); result = Evaluate();210 }211 return result;212 }213 case OpCodes.AND: {214 double result = Evaluate();215 for (int i = 1; i < currentInstr.nArguments; i++) {216 if (result <= 0.0) SkipBakedCode();217 else {218 result = Evaluate();219 }220 }221 return result <= 0.0 ? -1.0 : 1.0;222 }223 case OpCodes.OR: {224 double result = Evaluate();225 for (int i = 1; i < currentInstr.nArguments; i++) {226 if (result > 0.0) SkipBakedCode();227 else {228 result = Evaluate();229 }230 }231 return result > 0.0 ? 1.0 : -1.0;232 }233 case OpCodes.NOT: {234 return -Evaluate();235 }236 case OpCodes.GT: {237 double x = Evaluate();238 double y = Evaluate();239 if (x > y) return 1.0;240 else return -1.0;241 }242 case OpCodes.LT: {243 double x = Evaluate();244 double y = Evaluate();245 if (x < y) return 1.0;246 else return -1.0;247 }248 case OpCodes.Call: {249 // evaluate sub-trees250 // push on argStack in reverse order251 for (int i = 0; i < currentInstr.nArguments; i++) {252 argumentStack[argStackPointer + currentInstr.nArguments - i] = Evaluate();253 }254 argStackPointer += currentInstr.nArguments;255 256 // save the pc257 int nextPc = pc;258 // set pc to start of function259 pc = currentInstr.iArg0;260 // evaluate the function261 double v = Evaluate();262 263 // decrease the argument stack pointer by the number of arguments pushed264 // to set the argStackPointer back to the original location265 argStackPointer -= currentInstr.nArguments;266 267 // restore the pc => evaluation will continue at point after my subtrees268 pc = nextPc;269 return v;270 }271 case OpCodes.Arg: {272 return argumentStack[argStackPointer - currentInstr.iArg0];273 }274 case OpCodes.Variable: {275 var variableTreeNode = currentInstr.dynamicNode as VariableTreeNode;276 return dataset[row, currentInstr.iArg0] * variableTreeNode.Weight;277 }278 case OpCodes.LagVariable: {279 var lagVariableTreeNode = currentInstr.dynamicNode as LaggedVariableTreeNode;280 int actualRow = row + lagVariableTreeNode.Lag;281 if (actualRow < 0 || actualRow >= dataset.Rows) throw new ArgumentException("Out of range access to dataset row: " + row);282 return dataset[actualRow, currentInstr.iArg0] * lagVariableTreeNode.Weight;283 }284 case OpCodes.Differential: {285 var diffTreeNode = currentInstr.dynamicNode as DifferentialVariableTreeNode;286 if (row < 2 || row >= dataset.Rows - 2) throw new ArgumentException("Out of range access to dataset row: " + row);287 return (-dataset[row + 2, currentInstr.iArg0] + 8 * dataset[row + 1, currentInstr.iArg0] - 8 * dataset[row - 1, currentInstr.iArg0] + dataset[row - 2, currentInstr.iArg0]) * (1.0/12.0) * diffTreeNode.Weight;288 }289 290 case OpCodes.Constant: {291 var constTreeNode = currentInstr.dynamicNode as ConstantTreeNode;292 return constTreeNode.Value;293 }294 default: throw new NotSupportedException();295 }296 }297 298 289 // skips a whole branch 299 pr otected void SkipBakedCode() {290 private void SkipBakedCode(Instruction[] code, ref int pc) { 300 291 int i = 1; 301 292 while (i > 0) { -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SymbolicSimplifier.cs
r4554 r5275 354 354 while (sum.SubTrees.Count > 0) sum.RemoveSubTree(0); 355 355 var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>() 356 where node.Symbol.Name == "Variable"357 356 group node by node.VariableName into g 358 357 select g; 359 var unchangedSubTrees = subtrees.Where(t => t.Symbol.Name != "Variable");358 var unchangedSubTrees = subtrees.Where(t => !(t is VariableTreeNode)); 360 359 361 360 foreach (var variableNodeGroup in groupedVarNodes) { … … 430 429 while (prod.SubTrees.Count > 0) prod.RemoveSubTree(0); 431 430 var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>() 432 where node.Symbol.Name == "Variable"433 431 group node by node.VariableName into g 434 432 orderby g.Count() 435 433 select g; 436 434 var constantProduct = (from node in subtrees.OfType<VariableTreeNode>() 437 where node.Symbol.Name == "Variable"438 435 select node.Weight) 439 436 .Concat(from node in subtrees.OfType<ConstantTreeNode>() … … 443 440 444 441 var unchangedSubTrees = from tree in subtrees 445 where !(tree is VariableTreeNode && tree.Symbol.Name == "Variable")442 where !(tree is VariableTreeNode) 446 443 where !(tree is ConstantTreeNode) 447 444 select tree; … … 485 482 } else if (IsAddition(x)) { 486 483 // (x0 + x1 + .. + xn) * -1 => (-x0 + -x1 + .. + -xn) 487 foreach (var subTree in x.SubTrees) { 488 Negate(subTree); 489 } 484 for (int i = 0; i < x.SubTrees.Count; i++) 485 x.SubTrees[i] = Negate(x.SubTrees[i]); 490 486 } else if (IsMultiplication(x) || IsDivision(x)) { 491 487 // x0 * x1 * .. * xn * -1 => x0 * x1 * .. * -xn 492 Negate(x.SubTrees.Last()); // last is maybe a constant, prefer to negate the constant488 x.SubTrees[x.SubTrees.Count - 1] = Negate(x.SubTrees.Last()); // last is maybe a constant, prefer to negate the constant 493 489 } else { 494 490 // any other function -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Addition.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("Addition", "Symbol that represents the + operator.")] 28 29 public sealed class Addition : Symbol { 30 [StorableConstructor] 31 private Addition(bool deserializing) : base(deserializing) { } 32 private Addition(Addition original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new Addition(this, cloner); 35 } 29 36 public Addition() : base("Addition", "Symbol that represents the + operator.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/And.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("And", "Symbol that represents the boolean AND operator.")] 28 29 public sealed class And : Symbol { 30 [StorableConstructor] 31 private And(bool deserializing) : base(deserializing) { } 32 private And(And original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new And(this, cloner); 35 } 29 36 public And() : base("And", "Symbol that represents the boolean AND operator.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Average.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("Average", "Symbol that represents the average (arithmetic mean) function.")] 28 29 public sealed class Average : Symbol { 30 [StorableConstructor] 31 private Average(bool deserializing) : base(deserializing) { } 32 private Average(Average original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new Average(this, cloner); 35 } 29 36 public Average() : base("Average", "Symbol that represents the average (arithmetic mean) function.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Constant.cs
r4068 r5275 54 54 } 55 55 [Storable] 56 private double manipulator Nu;57 public double Manipulator Nu {58 get { return manipulator Nu; }56 private double manipulatorMu; 57 public double ManipulatorMu { 58 get { return manipulatorMu; } 59 59 set { 60 if (value != manipulator Nu) {61 manipulator Nu = value;60 if (value != manipulatorMu) { 61 manipulatorMu = value; 62 62 OnChanged(EventArgs.Empty); 63 63 } … … 77 77 } 78 78 #endregion 79 [StorableConstructor] 80 private Constant(bool deserializing) : base(deserializing) { } 81 private Constant(Constant original, Cloner cloner) 82 : base(original, cloner) { 83 minValue = original.minValue; 84 maxValue = original.maxValue; 85 manipulatorMu = original.manipulatorMu; 86 manipulatorSigma = original.manipulatorSigma; 87 } 79 88 public Constant() 80 89 : base("Constant", "Represents a constant value.") { 81 manipulator Nu = 0.0;90 manipulatorMu = 0.0; 82 91 manipulatorSigma = 1.0; 83 92 minValue = -20.0; … … 90 99 91 100 public override IDeepCloneable Clone(Cloner cloner) { 92 Constant clone = (Constant)base.Clone(cloner); 93 clone.minValue = minValue; 94 clone.maxValue = maxValue; 95 clone.manipulatorNu = manipulatorNu; 96 clone.manipulatorSigma = manipulatorSigma; 97 return clone; 101 return new Constant(this, cloner); 98 102 } 99 103 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/ConstantTreeNode.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 39 } 39 40 40 private ConstantTreeNode() : base() { } 41 [StorableConstructor] 42 private ConstantTreeNode(bool deserializing) : base(deserializing) { } 41 43 42 // copy constructor 43 private ConstantTreeNode(ConstantTreeNode original) 44 : base(original) { 44 private ConstantTreeNode(ConstantTreeNode original, Cloner cloner) 45 : base(original, cloner) { 45 46 constantValue = original.constantValue; 46 47 } 47 48 49 private ConstantTreeNode() : base() { } 48 50 public ConstantTreeNode(Constant constantSymbol) : base(constantSymbol) { } 49 51 … … 61 63 public override void ShakeLocalParameters(IRandom random, double shakingFactor) { 62 64 base.ShakeLocalParameters(random, shakingFactor); 63 double x = NormalDistributedRandom.NextDouble(random, Symbol.Manipulator Nu, Symbol.ManipulatorSigma);65 double x = NormalDistributedRandom.NextDouble(random, Symbol.ManipulatorMu, Symbol.ManipulatorSigma); 64 66 Value = Value + x * shakingFactor; 65 67 } 66 68 67 public override object Clone() {68 return new ConstantTreeNode(this );69 public override IDeepCloneable Clone(Cloner cloner) { 70 return new ConstantTreeNode(this, cloner); 69 71 } 70 72 -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Cosine.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("Cosine", "Symbol that represents the cosine function.")] 28 29 public sealed class Cosine : Symbol { 30 [StorableConstructor] 31 private Cosine(bool deserializing) : base(deserializing) { } 32 private Cosine(Cosine original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new Cosine(this, cloner); 35 } 29 36 public Cosine() : base("Cosine", "Symbol that represents the cosine function.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/DifferentialVariable.cs
r4193 r5275 28 28 [Item("DifferentialVariable", "Represents the differential of a variable value.")] 29 29 public sealed class DifferentialVariable : Variable { 30 [StorableConstructor] 31 private DifferentialVariable(bool deserializing) : base(deserializing) { } 32 private DifferentialVariable(DifferentialVariable original, Cloner cloner) 33 : base(original, cloner) { 34 } 30 35 public DifferentialVariable() 31 36 : base("DifferentialVariable", "Represents the differential of a variable value.") { … … 35 40 return new DifferentialVariableTreeNode(this); 36 41 } 37 38 42 public override IDeepCloneable Clone(Cloner cloner) { 39 DifferentialVariable clone = (DifferentialVariable)base.Clone(cloner); 40 return clone; 43 return new DifferentialVariable(this, cloner); 41 44 } 42 45 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/DifferentialVariableTreeNode.cs
r4193 r5275 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 using HeuristicLab.Common; 25 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols { 26 27 [StorableClass] … … 30 31 } 31 32 33 [StorableConstructor] 34 protected DifferentialVariableTreeNode(bool deserializing) : base(deserializing) { } 35 protected DifferentialVariableTreeNode(DifferentialVariableTreeNode original, Cloner cloner) 36 : base(original, cloner) { 37 } 32 38 private DifferentialVariableTreeNode() { } 33 34 // copy constructor35 private DifferentialVariableTreeNode(DifferentialVariableTreeNode original)36 : base(original) {37 }38 39 39 40 public DifferentialVariableTreeNode(DifferentialVariable differentialSymbol) : base(differentialSymbol) { } 40 41 41 42 42 public override object Clone() {43 return new DifferentialVariableTreeNode(this );43 public override IDeepCloneable Clone(Cloner cloner) { 44 return new DifferentialVariableTreeNode(this, cloner); 44 45 } 45 46 46 } 47 47 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Division.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("Division", "Symbol that represents the / operator.")] 28 29 public sealed class Division : Symbol { 30 [StorableConstructor] 31 private Division(bool deserializing) : base(deserializing) { } 32 private Division(Division original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new Division(this, cloner); 35 } 29 36 public Division() : base("Division", "Symbol that represents the / operator.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Exponential.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("Exponential", "Symbol that represents the exponential function.")] 28 29 public sealed class Exponential : Symbol { 30 [StorableConstructor] 31 private Exponential(bool deserializing) : base(deserializing) { } 32 private Exponential(Exponential original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new Exponential(this, cloner); 35 } 29 36 public Exponential() : base("Exponential", "Symbol that represents the exponential function.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/GreaterThan.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("GreaterThan", "Symbol that represents a greater than relation.")] 28 29 public sealed class GreaterThan : Symbol { 30 [StorableConstructor] 31 private GreaterThan(bool deserializing) : base(deserializing) { } 32 private GreaterThan(GreaterThan original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new GreaterThan(this, cloner); 35 } 29 36 public GreaterThan() : base("GreaterThan", "Symbol that represents a greater than relation.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/IfThenElse.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("IfThenElse", "Symbol that represents a conditional operator.")] 28 29 public sealed class IfThenElse : Symbol { 30 [StorableConstructor] 31 private IfThenElse(bool deserializing) : base(deserializing) { } 32 private IfThenElse(IfThenElse original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new IfThenElse(this, cloner); 35 } 29 36 public IfThenElse() : base("IfThenElse", "Symbol that represents a conditional operator.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/LaggedVariable.cs
r4068 r5275 40 40 set { maxLag = value; } 41 41 } 42 [StorableConstructor] 43 private LaggedVariable(bool deserializing) : base(deserializing) { } 44 private LaggedVariable(LaggedVariable original, Cloner cloner) 45 : base(original, cloner) { 46 minLag = original.minLag; 47 maxLag = original.maxLag; 48 } 42 49 public LaggedVariable() 43 50 : base("LaggedVariable", "Represents a variable value with a time offset.") { … … 50 57 51 58 public override IDeepCloneable Clone(Cloner cloner) { 52 LaggedVariable clone = (LaggedVariable)base.Clone(cloner); 53 clone.minLag = minLag; 54 clone.maxLag = maxLag; 55 return clone; 59 return new LaggedVariable(this, cloner); 56 60 } 57 61 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/LaggedVariableTreeNode.cs
r4068 r5275 21 21 22 22 using System; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 36 37 } 37 38 38 private LaggedVariableTreeNode() { } 39 40 // copy constructor 41 private LaggedVariableTreeNode(LaggedVariableTreeNode original) 42 : base(original) { 39 [StorableConstructor] 40 private LaggedVariableTreeNode(bool deserializing) : base(deserializing) { } 41 private LaggedVariableTreeNode(LaggedVariableTreeNode original, Cloner cloner) 42 : base(original, cloner) { 43 43 lag = original.lag; 44 44 } 45 private LaggedVariableTreeNode() { } 45 46 46 47 public LaggedVariableTreeNode(LaggedVariable variableSymbol) : base(variableSymbol) { } … … 62 63 } 63 64 64 65 public override object Clone() { 66 return new LaggedVariableTreeNode(this); 65 public override IDeepCloneable Clone(Cloner cloner) { 66 return new LaggedVariableTreeNode(this, cloner); 67 67 } 68 68 -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/LessThan.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("LessThan", "Symbol that represents a less than relation.")] 28 29 public sealed class LessThan : Symbol { 30 [StorableConstructor] 31 private LessThan(bool deserializing) : base(deserializing) { } 32 private LessThan(LessThan original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new LessThan(this, cloner); 35 } 29 36 public LessThan() : base("LessThan", "Symbol that represents a less than relation.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Logarithm.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("Logarithm", "Symbol that represents the logarithm function.")] 28 29 public sealed class Logarithm : Symbol { 30 [StorableConstructor] 31 private Logarithm(bool deserializing) : base(deserializing) { } 32 private Logarithm(Logarithm original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new Logarithm(this, cloner); 35 } 29 36 public Logarithm() : base("Logarithm", "Symbol that represents the logarithm function.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Multiplication.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("Multiplication", "Symbol that represents the * operator.")] 28 29 public sealed class Multiplication : Symbol { 30 [StorableConstructor] 31 private Multiplication(bool deserializing) : base(deserializing) { } 32 private Multiplication(Multiplication original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new Multiplication(this, cloner); 35 } 29 36 public Multiplication() : base("Multiplication", "Symbol that represents the * operator.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Not.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("Not", "Symbol that represents the boolean NOT operator.")] 28 29 public sealed class Not : Symbol { 30 [StorableConstructor] 31 private Not(bool deserializing) : base(deserializing) { } 32 private Not(Not original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new Not(this, cloner); 35 } 29 36 public Not() : base("Not", "Symbol that represents the boolean NOT operator.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Or.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("Or", "Symbol that represents the boolean OR operator.")] 28 29 public sealed class Or : Symbol { 30 [StorableConstructor] 31 private Or(bool deserializing) : base(deserializing) { } 32 private Or(Or original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new Or(this, cloner); 35 } 29 36 public Or() : base("Or", "Symbol that represents the boolean OR operator.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Sine.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("Sine", "Symbol that represents the sine function.")] 28 29 public sealed class Sine : Symbol { 30 [StorableConstructor] 31 private Sine(bool deserializing) : base(deserializing) { } 32 private Sine(Sine original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new Sine(this, cloner); 35 } 29 36 public Sine() : base("Sine", "Symbol that represents the sine function.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Subtraction.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("Subtraction", "Symbol that represents the - operator.")] 28 29 public sealed class Subtraction : Symbol { 30 [StorableConstructor] 31 private Subtraction(bool deserializing) : base(deserializing) { } 32 private Subtraction(Subtraction original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new Subtraction(this, cloner); 35 } 29 36 public Subtraction() : base("Subtraction", "Symbol that represents the - operator.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Tangent.cs
r4068 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 27 28 [Item("Tangent", "Symbol that represents the tangent trigonometric function.")] 28 29 public sealed class Tangent : Symbol { 30 [StorableConstructor] 31 private Tangent(bool deserializing) : base(deserializing) { } 32 private Tangent(Tangent original, Cloner cloner) : base(original, cloner) { } 33 public override IDeepCloneable Clone(Cloner cloner) { 34 return new Tangent(this, cloner); 35 } 29 36 public Tangent() : base("Tangent", "Symbol that represents the tangent trigonometric function.") { } 30 37 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Variable.cs
r4068 r5275 33 33 #region Properties 34 34 [Storable] 35 private double weight Nu;36 public double Weight Nu {37 get { return weight Nu; }35 private double weightMu; 36 public double WeightMu { 37 get { return weightMu; } 38 38 set { 39 if (value != weight Nu) {40 weight Nu = value;39 if (value != weightMu) { 40 weightMu = value; 41 41 OnChanged(EventArgs.Empty); 42 42 } … … 56 56 } 57 57 [Storable] 58 private double weightManipulator Nu;59 public double WeightManipulator Nu {60 get { return weightManipulator Nu; }58 private double weightManipulatorMu; 59 public double WeightManipulatorMu { 60 get { return weightManipulatorMu; } 61 61 set { 62 if (value != weightManipulator Nu) {63 weightManipulator Nu = value;62 if (value != weightManipulatorMu) { 63 weightManipulatorMu = value; 64 64 OnChanged(EventArgs.Empty); 65 65 } … … 90 90 } 91 91 #endregion 92 [StorableConstructor] 93 protected Variable(bool deserializing) : base(deserializing) { 94 variableNames = new List<string>(); 95 } 96 protected Variable(Variable original, Cloner cloner) 97 : base(original, cloner) { 98 weightMu = original.weightMu; 99 weightSigma = original.weightSigma; 100 variableNames = new List<string>(original.variableNames); 101 weightManipulatorMu = original.weightManipulatorMu; 102 weightManipulatorSigma = original.weightManipulatorSigma; 103 } 92 104 public Variable() : this("Variable", "Represents a variable value.") { } 93 105 public Variable(string name, string description) 94 106 : base(name, description) { 95 weight Nu = 1.0;107 weightMu = 1.0; 96 108 weightSigma = 1.0; 97 weightManipulator Nu = 0.0;109 weightManipulatorMu = 0.0; 98 110 weightManipulatorSigma = 1.0; 99 111 variableNames = new List<string>(); … … 105 117 106 118 public override IDeepCloneable Clone(Cloner cloner) { 107 Variable clone = (Variable)base.Clone(cloner); 108 clone.weightNu = weightNu; 109 clone.weightSigma = weightSigma; 110 clone.variableNames = new List<string>(variableNames); 111 clone.weightManipulatorNu = weightManipulatorNu; 112 clone.weightManipulatorSigma = weightManipulatorSigma; 113 return clone; 119 return new Variable(this, cloner); 114 120 } 115 121 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/VariableTreeNode.cs
r4220 r5275 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 using HeuristicLab.Common;24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 44 44 } 45 45 46 47 protected VariableTreeNode() { } 48 49 // copy constructor 50 protected VariableTreeNode(VariableTreeNode original) 51 : base(original) { 46 [StorableConstructor] 47 protected VariableTreeNode(bool deserializing) : base(deserializing) { } 48 protected VariableTreeNode(VariableTreeNode original, Cloner cloner) 49 : base(original, cloner) { 52 50 weight = original.weight; 53 51 variableName = original.variableName; 54 52 } 55 53 protected VariableTreeNode() { } 56 54 public VariableTreeNode(Variable variableSymbol) : base(variableSymbol) { } 57 55 … … 64 62 public override void ResetLocalParameters(IRandom random) { 65 63 base.ResetLocalParameters(random); 66 weight = NormalDistributedRandom.NextDouble(random, Symbol.Weight Nu, Symbol.WeightSigma);64 weight = NormalDistributedRandom.NextDouble(random, Symbol.WeightMu, Symbol.WeightSigma); 67 65 variableName = Symbol.VariableNames.SelectRandom(random); 68 66 } … … 70 68 public override void ShakeLocalParameters(IRandom random, double shakingFactor) { 71 69 base.ShakeLocalParameters(random, shakingFactor); 72 double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulator Nu, Symbol.WeightManipulatorSigma);70 double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu, Symbol.WeightManipulatorSigma); 73 71 weight = weight + x * shakingFactor; 74 72 variableName = Symbol.VariableNames.SelectRandom(random); 75 73 } 76 74 77 78 public override object Clone() { 79 return new VariableTreeNode(this); 75 public override IDeepCloneable Clone(Cloner cloner) { 76 return new VariableTreeNode(this, cloner); 80 77 } 81 78 -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/VariableFrequencyAnalyser.cs
r4125 r5275 22 22 using System.Collections.Generic; 23 23 using System.Linq; 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Data; … … 61 62 } 62 63 #endregion 64 [StorableConstructor] 65 protected VariableFrequencyAnalyser(bool deserializing) : base(deserializing) { } 66 protected VariableFrequencyAnalyser(VariableFrequencyAnalyser original, Cloner cloner) 67 : base(original, cloner) { 68 } 63 69 public VariableFrequencyAnalyser() 64 70 : base() { … … 69 75 70 76 public override IOperation Apply() { 71 var inputVariables = DataAnalysisProblemData.InputVariables. Select(x => x.Value);77 var inputVariables = DataAnalysisProblemData.InputVariables.CheckedItems.Select(x => x.Value.Value); 72 78 if (VariableFrequencies == null) { 73 79 VariableFrequencies = new DoubleMatrix(0, 1, inputVariables); … … 80 86 VariableFrequencies[lastRowIndex, columnIndex] = pair.Value; 81 87 } 82 return null;88 return base.Apply(); 83 89 } 84 90 -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Tests/HeuristicLab.Problems.DataAnalysis.Tests-3.3.csproj
r5265 r5275 102 102 </PropertyGroup> 103 103 <ItemGroup> 104 <Reference Include="ALGLIB-3.1.0"> 105 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\ALGLIB-3.1.0.dll</HintPath> 106 </Reference> 107 <Reference Include="HeuristicLab.ALGLIB-3.1.0"> 108 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.ALGLIB-3.1.0.dll</HintPath> 109 </Reference> 110 <Reference Include="HeuristicLab.Common-3.3"> 111 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Common-3.3.dll</HintPath> 112 </Reference> 113 <Reference Include="HeuristicLab.Core-3.3"> 114 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Core-3.3.dll</HintPath> 115 </Reference> 116 <Reference Include="HeuristicLab.Data-3.3"> 117 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Data-3.3.dll</HintPath> 118 </Reference> 119 <Reference Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3"> 120 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3.dll</HintPath> 121 </Reference> 122 <Reference Include="HeuristicLab.Operators-3.3"> 123 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Operators-3.3.dll</HintPath> 124 </Reference> 125 <Reference Include="HeuristicLab.Optimization-3.3"> 126 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Optimization-3.3.dll</HintPath> 127 </Reference> 128 <Reference Include="HeuristicLab.Random-3.3"> 129 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Random-3.3.dll</HintPath> 130 </Reference> 104 131 <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> 105 132 <Reference Include="System" /> -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Tests/StatisticCalculatorsTest.cs
r4459 r5275 77 77 double tmp = 0; 78 78 79 alglib. descriptivestatistics.calculatemoments(refxs, n, ref mean_alglib, ref variance_alglib, ref tmp, ref tmp);79 alglib.basestat.samplemoments(xs, n, ref mean_alglib, ref variance_alglib, ref tmp, ref tmp); 80 80 81 81 var calculator = new OnlineMeanAndVarianceCalculator(); … … 108 108 double[] xs = x.ToArray(); 109 109 double[] ys = y.ToArray(); 110 double r2_alglib = alglib. correlation.pearsoncorrelation(ref xs, refys, n);110 double r2_alglib = alglib.pearsoncorr2(xs, ys, n); 111 111 r2_alglib *= r2_alglib; 112 112
Note: See TracChangeset
for help on using the changeset viewer.