- Timestamp:
- 04/21/10 15:21:34 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisSolution.cs
r3452 r3462 35 35 [Item("DataAnalysisSolution", "Represents a solution for a data analysis problem which can be visualized in the GUI.")] 36 36 [StorableClass] 37 public class DataAnalysisSolution : Item { 38 [Storable] 39 private IModel model; 40 public IModel Model { 41 get { return model; } 42 set { 43 if (model != value) { 44 model = value; 45 OnModelChanged(); 46 } 47 } 48 } 49 37 public abstract class DataAnalysisSolution : Item { 50 38 [Storable] 51 39 private DataAnalysisProblemData problemData; … … 58 46 problemData = value; 59 47 RegisterProblemDataEvents(); 60 OnProblemDataChanged( );48 OnProblemDataChanged(EventArgs.Empty); 61 49 } 62 50 } 63 51 } 64 52 65 private List<double> estimatedValues; 66 public IEnumerable<double> EstimatedValues { 67 get { 68 return estimatedValues; 69 } 70 } 53 public abstract IEnumerable<double> EstimatedValues { get; } 54 public abstract IEnumerable<double> EstimatedTrainingValues { get; } 55 public abstract IEnumerable<double> EstimatedTestValues { get; } 71 56 72 private List<double> estimatedTrainingValues; 73 public IEnumerable<double> EstimatedTrainingValues { 74 get { 75 return estimatedTrainingValues; 76 } 77 } 78 79 private List<double> estimatedTestValues; 80 public IEnumerable<double> EstimatedTestValues { 81 get { 82 return estimatedTestValues; 83 } 84 } 85 86 public DataAnalysisSolution() : base() { } 87 public DataAnalysisSolution(DataAnalysisProblemData problemData, IModel model) 57 protected DataAnalysisSolution() : base() { } 58 protected DataAnalysisSolution(DataAnalysisProblemData problemData) 88 59 : this() { 89 60 this.problemData = problemData; 90 this.model = model;91 61 Initialize(); 92 62 } … … 98 68 private void Initialize() { 99 69 if (problemData != null) RegisterProblemDataEvents(); 100 if (problemData != null && model != null) RecalculateEstimatedValues();101 }102 103 private void RecalculateEstimatedValues() {104 estimatedValues = GetEstimatedValues(0, problemData.Dataset.Rows).ToList();105 int nTrainingValues = problemData.TrainingSamplesEnd.Value - problemData.TrainingSamplesStart.Value;106 estimatedTrainingValues = estimatedValues.Skip(problemData.TrainingSamplesStart.Value).Take(nTrainingValues).ToList();107 int nTestValues = problemData.TestSamplesEnd.Value - problemData.TestSamplesStart.Value;108 estimatedTestValues = estimatedValues.Skip(problemData.TestSamplesStart.Value).Take(nTestValues).ToList();109 }110 111 private IEnumerable<double> GetEstimatedValues(int start, int end) {112 double[] xs = new double[ProblemData.InputVariables.Count];113 for (int row = 0; row < ProblemData.Dataset.Rows; row++) {114 for (int i = 0; i < xs.Length; i++) {115 var variableIndex = ProblemData.Dataset.GetVariableIndex(ProblemData.InputVariables[i].Value);116 xs[i] = ProblemData.Dataset[row, variableIndex];117 }118 yield return model.GetValue(xs);119 }120 70 } 121 71 122 72 public override IDeepCloneable Clone(Cloner cloner) { 123 DataAnalysisSolution clone = new DataAnalysisSolution(); 124 cloner.RegisterClonedObject(this, clone); 125 clone.model = (IModel)cloner.Clone(model); 73 DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner); 74 // don't clone the problem data! 126 75 clone.problemData = problemData; 127 76 clone.Initialize(); … … 130 79 131 80 #region Events 132 public event EventHandler ModelChanged; 133 private void OnModelChanged() { 134 RecalculateEstimatedValues(); 135 var changed = ModelChanged; 136 if (changed != null) 137 changed(this, EventArgs.Empty); 138 } 139 public event EventHandler ProblemDataChanged; 140 private void OnProblemDataChanged() { 141 RecalculateEstimatedValues(); 142 var changed = ProblemDataChanged; 143 if (changed != null) 144 changed(this, EventArgs.Empty); 145 } 146 147 private void RegisterProblemDataEvents() { 81 protected virtual void RegisterProblemDataEvents() { 148 82 ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed); 149 83 } 150 pr ivatevoid DeregisterProblemDataEvents() {84 protected virtual void DeregisterProblemDataEvents() { 151 85 ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed); 152 86 } 153 87 154 88 private void ProblemData_Changed(object sender, EventArgs e) { 155 OnProblemDataChanged(); 89 OnProblemDataChanged(EventArgs.Empty); 90 } 91 92 public event EventHandler ProblemDataChanged; 93 protected virtual void OnProblemDataChanged(EventArgs e) { 94 var listeners = ProblemDataChanged; 95 if (listeners != null) 96 listeners(this, e); 97 } 98 99 public event EventHandler EstimatedValuesChanged; 100 protected virtual void OnEstimatedValuesChanged(EventArgs e) { 101 var listeners = EstimatedValuesChanged; 102 if (listeners != null) 103 listeners(this, e); 156 104 } 157 105 #endregion
Note: See TracChangeset
for help on using the changeset viewer.