Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/01/10 17:58:03 (14 years ago)
Author:
gkronber
Message:

Worked on support vector regression operators and views. #1009

File:
1 edited

Legend:

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

    r3710 r3884  
    3636  [StorableClass]
    3737  public abstract class DataAnalysisSolution : NamedItem {
     38    protected DataAnalysisSolution()
     39      : base() { }
     40    protected DataAnalysisSolution(DataAnalysisProblemData problemData) : this(problemData, double.NegativeInfinity, double.PositiveInfinity) { }
     41    protected DataAnalysisSolution(DataAnalysisProblemData problemData, double lowerEstimationLimit, double upperEstimationLimit)
     42      : this() {
     43      this.problemData = problemData;
     44      this.lowerEstimationLimit = lowerEstimationLimit;
     45      this.upperEstimationLimit = upperEstimationLimit;
     46      Initialize();
     47    }
     48
     49    [StorableConstructor]
     50    private DataAnalysisSolution(bool deserializing) : base(deserializing) { }
     51    [StorableHook(HookType.AfterDeserialization)]
     52    private void Initialize() {
     53      if (problemData != null) RegisterProblemDataEvents();
     54    }
     55
    3856    [Storable]
    3957    private DataAnalysisProblemData problemData;
     
    4361        if (problemData != value) {
    4462          if (value == null) throw new ArgumentNullException();
     63          if (model != null && problemData != null && !problemData.InputVariables.Select(c => c.Value).SequenceEqual(
     64            value.InputVariables.Select(c => c.Value)))
     65            throw new ArgumentException("Could not set new problem data with different structure");
     66
    4567          if (problemData != null) DeregisterProblemDataEvents();
    4668          problemData = value;
    4769          RegisterProblemDataEvents();
    48           OnProblemDataChanged(EventArgs.Empty);
     70          OnProblemDataChanged();
    4971        }
    5072      }
    5173    }
     74
     75    [Storable]
     76    private IDataAnalysisModel model;
     77    public IDataAnalysisModel Model {
     78      get { return model; }
     79      set {
     80        if (model != value) {
     81          if (value == null) throw new ArgumentNullException();
     82          model = value;
     83          OnModelChanged();
     84        }
     85      }
     86    }
     87
    5288    [Storable]
    5389    private double lowerEstimationLimit;
     
    5793        if (lowerEstimationLimit != value) {
    5894          lowerEstimationLimit = value;
    59           OnEstimatedValuesChanged(EventArgs.Empty);
     95          RecalculateEstimatedValues();
    6096        }
    6197      }
     
    69105        if (upperEstimationLimit != value) {
    70106          upperEstimationLimit = value;
    71           OnEstimatedValuesChanged(EventArgs.Empty);
     107          RecalculateEstimatedValues();
    72108        }
    73109      }
     
    77113    public abstract IEnumerable<double> EstimatedTrainingValues { get; }
    78114    public abstract IEnumerable<double> EstimatedTestValues { get; }
    79 
    80     protected DataAnalysisSolution() : base() {
    81       Name = ItemName;
    82       Description = ItemDescription;
    83     }
    84     protected DataAnalysisSolution(DataAnalysisProblemData problemData) : this(problemData, double.NegativeInfinity, double.PositiveInfinity) { }
    85     protected DataAnalysisSolution(DataAnalysisProblemData problemData, double lowerEstimationLimit, double upperEstimationLimit)
    86       : this() {
    87       this.problemData = problemData;
    88       this.lowerEstimationLimit = lowerEstimationLimit;
    89       this.upperEstimationLimit = upperEstimationLimit;
    90       Initialize();
    91     }
    92 
    93     [StorableConstructor]
    94     private DataAnalysisSolution(bool deserializing) : base(deserializing) { }
    95 
    96     [StorableHook(HookType.AfterDeserialization)]
    97     private void Initialize() {
    98       if (problemData != null) RegisterProblemDataEvents();
    99     }
    100 
    101     public override IDeepCloneable Clone(Cloner cloner) {
    102       DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner);
    103       // don't clone the problem data!
    104       clone.problemData = problemData;
    105       clone.lowerEstimationLimit = lowerEstimationLimit;
    106       clone.upperEstimationLimit = upperEstimationLimit;
    107       clone.Initialize();
    108       return clone;
    109     }
     115    protected abstract void RecalculateEstimatedValues();
    110116
    111117    #region Events
     
    116122      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
    117123    }
    118 
    119124    private void ProblemData_Changed(object sender, EventArgs e) {
    120       OnProblemDataChanged(EventArgs.Empty);
     125      OnProblemDataChanged();
    121126    }
    122127
    123128    public event EventHandler ProblemDataChanged;
    124     protected virtual void OnProblemDataChanged(EventArgs e) {
     129    protected virtual void OnProblemDataChanged() {
     130      RecalculateEstimatedValues();
    125131      var listeners = ProblemDataChanged;
    126132      if (listeners != null)
    127         listeners(this, e);
     133        listeners(this, EventArgs.Empty);
     134    }
     135
     136    public event EventHandler ModelChanged;
     137    protected virtual void OnModelChanged() {
     138      RecalculateEstimatedValues();
     139      EventHandler handler = ModelChanged;
     140      if (handler != null)
     141        handler(this, EventArgs.Empty);
    128142    }
    129143
    130144    public event EventHandler EstimatedValuesChanged;
    131     protected virtual void OnEstimatedValuesChanged(EventArgs e) {
     145    protected virtual void OnEstimatedValuesChanged() {
    132146      var listeners = EstimatedValuesChanged;
    133147      if (listeners != null)
    134         listeners(this, e);
     148        listeners(this, EventArgs.Empty);
    135149    }
    136150    #endregion
     151
     152    public override IDeepCloneable Clone(Cloner cloner) {
     153      DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner);
     154      // don't clone the problem data!
     155      clone.problemData = problemData;
     156      clone.Model = (IDataAnalysisModel)cloner.Clone(model);
     157      clone.lowerEstimationLimit = lowerEstimationLimit;
     158      clone.upperEstimationLimit = upperEstimationLimit;
     159      clone.Initialize();
     160      return clone;
     161    }
    137162  }
    138163}
Note: See TracChangeset for help on using the changeset viewer.