Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/19/20 19:07:40 (4 years ago)
Author:
fbaching
Message:

#1837: merged changes from trunk

  • apply changes from Attic release to all SlidingWindow specific code files (replace StorableClass with StorableType)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionModel.cs

    r9587 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HEAL.Attic;
    2728
    2829namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    3031  /// Represents a symbolic regression model
    3132  /// </summary>
    32   [StorableClass]
     33  [StorableType("2739C33E-4DDB-4285-9DFB-C056D900B2F2")]
    3334  [Item(Name = "Symbolic Regression Model", Description = "Represents a symbolic regression model.")]
    3435  public class SymbolicRegressionModel : SymbolicDataAnalysisModel, ISymbolicRegressionModel {
    35 
     36    [Storable]
     37    private string targetVariable;
     38    public string TargetVariable {
     39      get { return targetVariable; }
     40      set {
     41        if (string.IsNullOrEmpty(value) || targetVariable == value) return;
     42        targetVariable = value;
     43        OnTargetVariableChanged(this, EventArgs.Empty);
     44      }
     45    }
    3646
    3747    [StorableConstructor]
    38     protected SymbolicRegressionModel(bool deserializing) : base(deserializing) { }
    39     protected SymbolicRegressionModel(SymbolicRegressionModel original, Cloner cloner) : base(original, cloner) { }
     48    protected SymbolicRegressionModel(StorableConstructorFlag _) : base(_) {
     49      targetVariable = string.Empty;
     50    }
    4051
    41     public SymbolicRegressionModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     52    protected SymbolicRegressionModel(SymbolicRegressionModel original, Cloner cloner)
     53      : base(original, cloner) {
     54      this.targetVariable = original.targetVariable;
     55    }
     56
     57    public SymbolicRegressionModel(string targetVariable, ISymbolicExpressionTree tree,
     58      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    4259      double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue)
    43       : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) { }
     60      : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) {
     61      this.targetVariable = targetVariable;
     62    }
    4463
    4564    public override IDeepCloneable Clone(Cloner cloner) {
     
    4766    }
    4867
    49     public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) {
     68    public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    5069      return Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows)
    5170        .LimitToRange(LowerEstimationLimit, UpperEstimationLimit);
     
    6281      Scale(problemData, problemData.TargetVariable);
    6382    }
     83
     84    public virtual bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) {
     85      return RegressionModel.IsProblemDataCompatible(this, problemData, out errorMessage);
     86    }
     87
     88    public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {
     89      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     90      var regressionProblemData = problemData as IRegressionProblemData;
     91      if (regressionProblemData == null)
     92        throw new ArgumentException("The problem data is not compatible with this symbolic regression model. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     93      return IsProblemDataCompatible(regressionProblemData, out errorMessage);
     94    }
     95
     96    #region events
     97    public event EventHandler TargetVariableChanged;
     98    private void OnTargetVariableChanged(object sender, EventArgs args) {
     99      var changed = TargetVariableChanged;
     100      if (changed != null)
     101        changed(sender, args);
     102    }
     103    #endregion
    64104  }
    65105}
Note: See TracChangeset for help on using the changeset viewer.