Changeset 14294


Ignore:
Timestamp:
09/20/16 17:14:41 (3 years ago)
Author:
bburlacu
Message:

#2672: Add cloning constructors.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/ClassificationPerformanceMeasuresCalculator.cs

    r14293 r14294  
    3333    }
    3434
    35     // private constructor used internally by the Clone() method
    36     private ClassificationPerformanceMeasuresCalculator(ClassificationPerformanceMeasuresCalculator other) {
    37       // copy everything including the errorState
    38       positiveClassName = other.positiveClassName;
    39       positiveClassValue = other.positiveClassValue;
    40       truePositiveCount = other.truePositiveCount;
    41       falsePositiveCount = other.falsePositiveCount;
    42       trueNegativeCount = other.trueNegativeCount;
    43       falseNegativeCount = other.falseNegativeCount;
    44       errorState = other.errorState;
     35    protected ClassificationPerformanceMeasuresCalculator(ClassificationPerformanceMeasuresCalculator original, Cloner cloner = null) {
     36      positiveClassName = original.positiveClassName;
     37      positiveClassValue = original.positiveClassValue;
     38      truePositiveCount = original.truePositiveCount;
     39      falsePositiveCount = original.falsePositiveCount;
     40      trueNegativeCount = original.trueNegativeCount;
     41      falseNegativeCount = original.falseNegativeCount;
     42      errorState = original.errorState;
    4543    }
    4644
     
    158156      var clone = cloner.GetClone(this);
    159157      if (clone == null) {
    160         clone = (IDeepCloneable)this.Clone();
     158        clone = new ClassificationPerformanceMeasuresCalculator(this);
    161159        cloner.RegisterClonedObject(this, clone);
    162160      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineAccuracyCalculator.cs

    r14293 r14294  
    4040
    4141    // private constructor used internally by the Clone() method
    42     private OnlineAccuracyCalculator(OnlineAccuracyCalculator other) {
     42    protected OnlineAccuracyCalculator(OnlineAccuracyCalculator other, Cloner cloner = null) {
    4343      correctlyClassified = other.correctlyClassified;
    4444      n = other.n;
     
    106106      var clone = cloner.GetClone(this);
    107107      if (clone == null) {
    108         clone = (IDeepCloneable)this.Clone();
     108        clone = new OnlineAccuracyCalculator(this);
    109109        cloner.RegisterClonedObject(this, clone);
    110110      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineBoundedMeanSquaredErrorCalculator.cs

    r14293 r14294  
    4545    }
    4646
    47     // private constructor used internally by the Clone() method
    48     private OnlineBoundedMeanSquaredErrorCalculator(OnlineBoundedMeanSquaredErrorCalculator other) {
    49       LowerBound = other.LowerBound;
    50       UpperBound = other.UpperBound;
    51       n = other.n;
    52       errorSum = other.errorSum;
    53       errorState = other.ErrorState;
     47    protected OnlineBoundedMeanSquaredErrorCalculator(OnlineBoundedMeanSquaredErrorCalculator original, Cloner cloner = null) {
     48      LowerBound = original.LowerBound;
     49      UpperBound = original.UpperBound;
     50      n = original.n;
     51      errorSum = original.errorSum;
     52      errorState = original.ErrorState;
    5453    }
    5554
     
    115114      var clone = cloner.GetClone(this);
    116115      if (clone == null) {
    117         clone = (IDeepCloneable)this.Clone();
     116        clone = new OnlineBoundedMeanSquaredErrorCalculator(this);
    118117        cloner.RegisterClonedObject(this, clone);
    119118      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineCovarianceCalculator.cs

    r14293 r14294  
    3939    }
    4040
    41     // private constructor used internally by the Clone() method
    42     private OnlineCovarianceCalculator(OnlineCovarianceCalculator other) : this() {
     41    protected OnlineCovarianceCalculator(OnlineCovarianceCalculator other, Cloner cloner = null) {
    4342      Cn = other.Cn;
    4443      xMean = other.xMean;
     
    113112      var clone = cloner.GetClone(this);
    114113      if (clone == null) {
    115         clone = (IDeepCloneable)this.Clone();
     114        clone = new OnlineCovarianceCalculator(this);
    116115        cloner.RegisterClonedObject(this, clone);
    117116      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineDirectionalSymmetryCalculator.cs

    r14293 r14294  
    4141    }
    4242
    43     // private constructor used internally by the Clone() method
    44     private OnlineDirectionalSymmetryCalculator(OnlineDirectionalSymmetryCalculator other) {
     43    protected OnlineDirectionalSymmetryCalculator(OnlineDirectionalSymmetryCalculator other, Cloner cloner = null) {
    4544      n = other.n;
    4645      nCorrect = other.nCorrect;
     
    132131      var clone = cloner.GetClone(this);
    133132      if (clone == null) {
    134         clone = (IDeepCloneable)this.Clone();
     133        clone = new OnlineDirectionalSymmetryCalculator(this);
    135134        cloner.RegisterClonedObject(this, clone);
    136135      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineLinearScalingParameterCalculator.cs

    r14293 r14294  
    6666    }
    6767
    68     // private constructor used internally by the Clone() method
    69     private OnlineLinearScalingParameterCalculator(OnlineMeanAndVarianceCalculator targetMeanCalculator, OnlineMeanAndVarianceCalculator originalMeanAndVarianceCalculator, OnlineCovarianceCalculator originalTargetCovarianceCalculator) {
    70       this.targetMeanCalculator = targetMeanCalculator;
    71       this.originalMeanAndVarianceCalculator = originalMeanAndVarianceCalculator;
    72       this.originalTargetCovarianceCalculator = originalTargetCovarianceCalculator;
     68    protected OnlineLinearScalingParameterCalculator(OnlineLinearScalingParameterCalculator other, Cloner cloner) {
     69      targetMeanCalculator = (OnlineMeanAndVarianceCalculator)other.targetMeanCalculator.Clone(cloner);
     70      originalMeanAndVarianceCalculator = (OnlineMeanAndVarianceCalculator)other.originalMeanAndVarianceCalculator.Clone(cloner);
     71      originalTargetCovarianceCalculator = (OnlineCovarianceCalculator)other.originalTargetCovarianceCalculator.Clone(cloner);
    7372      // do not reset the calculators here
    7473    }
     
    129128    // IDeepCloneable interface members
    130129    public object Clone() {
    131       var targetMeanCalculatorClone = (OnlineMeanAndVarianceCalculator)targetMeanCalculator.Clone();
    132       var originalMeanAndVarianceCalculatorClone = (OnlineMeanAndVarianceCalculator)originalMeanAndVarianceCalculator.Clone();
    133       var originalTargetCovarianceCalculatorClone = (OnlineCovarianceCalculator)originalTargetCovarianceCalculator.Clone();
    134       return new OnlineLinearScalingParameterCalculator(targetMeanCalculatorClone, originalMeanAndVarianceCalculatorClone, originalTargetCovarianceCalculatorClone);
     130      var cloner = new Cloner();
     131      return new OnlineLinearScalingParameterCalculator(this, cloner);
    135132    }
    136133
     
    138135      var clone = cloner.GetClone(this);
    139136      if (clone == null) {
    140         var targetMeanCalculatorClone = (OnlineMeanAndVarianceCalculator)targetMeanCalculator.Clone(cloner);
    141         var originalMeanAndVarianceCalculatorClone = (OnlineMeanAndVarianceCalculator)originalMeanAndVarianceCalculator.Clone(cloner);
    142         var originalTargetCovarianceCalculatorClone = (OnlineCovarianceCalculator)originalTargetCovarianceCalculator.Clone(cloner);
    143         clone = new OnlineLinearScalingParameterCalculator(targetMeanCalculatorClone, originalMeanAndVarianceCalculatorClone, originalTargetCovarianceCalculatorClone);
     137        clone = new OnlineLinearScalingParameterCalculator(this, cloner);
    144138        cloner.RegisterClonedObject(this, clone);
    145139      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMaxAbsoluteErrorCalculator.cs

    r14293 r14294  
    3939    }
    4040
    41     // private constructor used internally by the Clone() method
    42     private OnlineMaxAbsoluteErrorCalculator(OnlineMaxAbsoluteErrorCalculator other) {
     41    protected OnlineMaxAbsoluteErrorCalculator(OnlineMaxAbsoluteErrorCalculator other, Cloner cloner = null) {
    4342      mae = other.mae;
    4443      n = other.n;
     
    105104      var clone = cloner.GetClone(this);
    106105      if (clone == null) {
    107         clone = (IDeepCloneable)this.Clone();
     106        clone = new OnlineMaxAbsoluteErrorCalculator(this);
    108107        cloner.RegisterClonedObject(this, clone);
    109108      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAbsoluteErrorCalculator.cs

    r14293 r14294  
    3939    }
    4040
    41     private OnlineMeanAbsoluteErrorCalculator(OnlineMeanAbsoluteErrorCalculator other) {
     41    protected OnlineMeanAbsoluteErrorCalculator(OnlineMeanAbsoluteErrorCalculator other, Cloner cloner = null) {
    4242      sae = other.sae;
    4343      n = other.n;
     
    103103      var clone = cloner.GetClone(this);
    104104      if (clone == null) {
    105         clone = (IDeepCloneable)this.Clone();
     105        clone = new OnlineMeanAbsoluteErrorCalculator(this);
    106106        cloner.RegisterClonedObject(this, clone);
    107107      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAbsolutePercentageErrorCalculator.cs

    r14293 r14294  
    3939    }
    4040
    41     // private constructor used internally by the Clone() method
    42     private OnlineMeanAbsolutePercentageErrorCalculator(OnlineMeanAbsolutePercentageErrorCalculator other) {
     41    protected OnlineMeanAbsolutePercentageErrorCalculator(OnlineMeanAbsolutePercentageErrorCalculator other, Cloner cloner = null) {
    4342      sre = other.sre;
    4443      n = other.n;
     
    105104      var clone = cloner.GetClone(this);
    106105      if (clone == null) {
    107         clone = (IDeepCloneable)this.Clone();
     106        clone = new OnlineMeanAbsolutePercentageErrorCalculator(this);
    108107        cloner.RegisterClonedObject(this, clone);
    109108      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAndVarianceCalculator.cs

    r14293 r14294  
    6767    }
    6868
    69     private OnlineMeanAndVarianceCalculator(OnlineMeanAndVarianceCalculator other) : this() {
     69    protected OnlineMeanAndVarianceCalculator(OnlineMeanAndVarianceCalculator other, Cloner cloner = null) {
    7070      m_oldS = other.m_oldS;
    7171      m_oldM = other.m_oldM;
     
    126126      var clone = cloner.GetClone(this);
    127127      if (clone == null) {
    128         clone = (IDeepCloneable)this.Clone();
     128        clone = new OnlineMeanAndVarianceCalculator(this);
    129129        cloner.RegisterClonedObject(this, clone);
    130130      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanErrorCalculator.cs

    r14293 r14294  
    3737    }
    3838
    39     private OnlineMeanErrorCalculator(OnlineMeanAndVarianceCalculator meanAndVarianceCalculator) {
    40       this.meanAndVarianceCalculator = meanAndVarianceCalculator;
     39    protected OnlineMeanErrorCalculator(OnlineMeanErrorCalculator other, Cloner cloner) {
     40      meanAndVarianceCalculator = (OnlineMeanAndVarianceCalculator)other.meanAndVarianceCalculator.Clone(cloner);
    4141    }
    4242
     
    8282    // IDeepCloneable members
    8383    public object Clone() {
    84       var meanAndVarianceCalculatorClone = (OnlineMeanAndVarianceCalculator)meanAndVarianceCalculator.Clone();
    85       return new OnlineMeanErrorCalculator(meanAndVarianceCalculatorClone);
     84      var cloner = new Cloner();
     85      return new OnlineMeanErrorCalculator(this, cloner);
    8686    }
    8787
     
    8989      var clone = cloner.GetClone(this);
    9090      if (clone == null) {
    91         var meanAndVarianceCalculatorClone = (OnlineMeanAndVarianceCalculator)meanAndVarianceCalculator.Clone(cloner);
    92         clone = new OnlineMeanErrorCalculator(meanAndVarianceCalculatorClone);
     91        clone = new OnlineMeanErrorCalculator(this, cloner);
    9392        cloner.RegisterClonedObject(this, clone);
    9493      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanSquaredErrorCalculator.cs

    r14293 r14294  
    3939    }
    4040
    41     // private constructor used internally by the Clone() method
    42     private OnlineMeanSquaredErrorCalculator(OnlineMeanSquaredErrorCalculator other) {
     41    protected OnlineMeanSquaredErrorCalculator(OnlineMeanSquaredErrorCalculator other, Cloner cloner = null) {
    4342      sse = other.sse;
    4443      n = other.n;
     
    104103      var clone = cloner.GetClone(this);
    105104      if (clone == null) {
    106         clone = (IDeepCloneable)this.Clone();
     105        clone = new OnlineMeanSquaredErrorCalculator(this);
    107106        cloner.RegisterClonedObject(this, clone);
    108107      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineNormalizedMeanSquaredErrorCalculator.cs

    r14293 r14294  
    4343    }
    4444
    45     // private constructor used internally by the Clone() method
    46     public OnlineNormalizedMeanSquaredErrorCalculator(OnlineMeanAndVarianceCalculator meanSquaredErrorCalculator, OnlineMeanAndVarianceCalculator originalVarianceCalculator) {
    47       this.meanSquaredErrorCalculator = meanSquaredErrorCalculator;
    48       this.originalVarianceCalculator = originalVarianceCalculator;
     45    protected OnlineNormalizedMeanSquaredErrorCalculator(OnlineNormalizedMeanSquaredErrorCalculator other, Cloner cloner) {
     46      meanSquaredErrorCalculator = (OnlineMeanAndVarianceCalculator)other.meanSquaredErrorCalculator.Clone(cloner);
     47      originalVarianceCalculator = (OnlineMeanAndVarianceCalculator)originalVarianceCalculator.Clone(cloner);
    4948    }
    5049
     
    102101    // IDeepCloneable members
    103102    public object Clone() {
    104       var meanSquaredErrorCalculatorClone = (OnlineMeanAndVarianceCalculator)meanSquaredErrorCalculator.Clone();
    105       var originalVarianceCalculatorClone = (OnlineMeanAndVarianceCalculator)originalVarianceCalculator.Clone();
    106       return new OnlineNormalizedMeanSquaredErrorCalculator(meanSquaredErrorCalculatorClone, originalVarianceCalculatorClone);
     103      var cloner = new Cloner();
     104      return new OnlineNormalizedMeanSquaredErrorCalculator(this, cloner);
    107105    }
    108106
     
    110108      var clone = cloner.GetClone(this);
    111109      if (clone == null) {
    112         var meanSquaredErrorCalculatorClone = (OnlineMeanAndVarianceCalculator)meanSquaredErrorCalculator.Clone(cloner);
    113         var originalVarianceCalculatorClone = (OnlineMeanAndVarianceCalculator)originalVarianceCalculator.Clone(cloner);
    114         clone = new OnlineNormalizedMeanSquaredErrorCalculator(meanSquaredErrorCalculatorClone, originalVarianceCalculatorClone);
     110        clone = new OnlineNormalizedMeanSquaredErrorCalculator(this, cloner);
    115111        cloner.RegisterClonedObject(this, clone);
    116112      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlinePearsonsRCalculator.cs

    r14293 r14294  
    4747    public OnlinePearsonsRCalculator() { }
    4848
    49     // private constructor used internally by the Clone() method
    50     private OnlinePearsonsRCalculator(OnlineCovarianceCalculator covCalculator, OnlineMeanAndVarianceCalculator sxCalculator, OnlineMeanAndVarianceCalculator syCalculator) {
    51       this.covCalculator = covCalculator;
    52       this.sxCalculator = sxCalculator;
    53       this.syCalculator = syCalculator;
     49    protected OnlinePearsonsRCalculator(OnlinePearsonsRCalculator other, Cloner cloner) {
     50      covCalculator = (OnlineCovarianceCalculator)other.covCalculator.Clone(cloner);
     51      sxCalculator = (OnlineMeanAndVarianceCalculator)other.sxCalculator.Clone(cloner);
     52      syCalculator = (OnlineMeanAndVarianceCalculator)other.syCalculator.Clone(cloner);
    5453    }
    5554
     
    101100    // IDeepCloneable members
    102101    public object Clone() {
    103       var covCalculatorClone = (OnlineCovarianceCalculator)covCalculator.Clone();
    104       var sxCalculatorClone = (OnlineMeanAndVarianceCalculator)sxCalculator.Clone();
    105       var syCalculatorClone = (OnlineMeanAndVarianceCalculator)syCalculator.Clone();
    106       return new OnlinePearsonsRCalculator(covCalculatorClone, sxCalculatorClone, syCalculatorClone);
     102      var cloner = new Cloner();
     103      return new OnlinePearsonsRCalculator(this, cloner);
    107104    }
    108105
     
    110107      var clone = cloner.GetClone(this);
    111108      if (clone == null) {
    112         var covCalculatorClone = (OnlineCovarianceCalculator)covCalculator.Clone(cloner);
    113         var sxCalculatorClone = (OnlineMeanAndVarianceCalculator)sxCalculator.Clone(cloner);
    114         var syCalculatorClone = (OnlineMeanAndVarianceCalculator)syCalculator.Clone(cloner);
    115         clone = new OnlinePearsonsRCalculator(covCalculatorClone, sxCalculatorClone, syCalculatorClone);
     109        clone = new OnlinePearsonsRCalculator(this, cloner);
    116110        cloner.RegisterClonedObject(this, clone);
    117111      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlinePearsonsRSquaredCalculator.cs

    r14293 r14294  
    3838    public OnlinePearsonsRSquaredCalculator() { }
    3939
    40     private OnlinePearsonsRSquaredCalculator(OnlinePearsonsRCalculator rCalculator) {
    41       this.rCalculator = rCalculator;
     40    protected OnlinePearsonsRSquaredCalculator(OnlinePearsonsRSquaredCalculator other, Cloner cloner) {
     41      this.rCalculator = (OnlinePearsonsRCalculator)other.rCalculator.Clone(cloner);
    4242    }
    4343
     
    6666    // IDeepCloneable members
    6767    public object Clone() {
    68       var rCalculatorClone = (OnlinePearsonsRCalculator)rCalculator.Clone();
    69       return new OnlinePearsonsRSquaredCalculator(rCalculatorClone);
     68      var cloner = new Cloner();
     69      return new OnlinePearsonsRSquaredCalculator(this, cloner);
    7070    }
    7171
     
    7373      var clone = cloner.GetClone(this);
    7474      if (clone == null) {
    75         var rCalculatorClone = (OnlinePearsonsRCalculator)rCalculator.Clone(cloner);
    76         clone = new OnlinePearsonsRSquaredCalculator(rCalculatorClone);
     75        clone = new OnlinePearsonsRSquaredCalculator(this, cloner);
    7776        cloner.RegisterClonedObject(this, clone);
    7877      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineTheilsUStatisticCalculator.cs

    r14293 r14294  
    4646    }
    4747
    48     // private constructor used internally by the Clone() method
    49     private OnlineTheilsUStatisticCalculator(OnlineMeanAndVarianceCalculator squaredErrorMeanCalculator, OnlineMeanAndVarianceCalculator unbiasedEstimatorMeanCalculator) {
    50       this.squaredErrorMeanCalculator = squaredErrorMeanCalculator;
    51       this.unbiasedEstimatorMeanCalculator = unbiasedEstimatorMeanCalculator;
     48    protected OnlineTheilsUStatisticCalculator(OnlineTheilsUStatisticCalculator other, Cloner cloner) {
     49      squaredErrorMeanCalculator = (OnlineMeanAndVarianceCalculator)other.squaredErrorMeanCalculator.Clone(cloner);
     50      unbiasedEstimatorMeanCalculator = (OnlineMeanAndVarianceCalculator)other.unbiasedEstimatorMeanCalculator.Clone(cloner);
    5251    }
    5352
     
    135134    // IDeepCloneable members
    136135    public object Clone() {
    137       var squaredErrorMeanCalculatorClone = (OnlineMeanAndVarianceCalculator)squaredErrorMeanCalculator.Clone();
    138       var unbiasedEstimatorMeanCalculatorClone = (OnlineMeanAndVarianceCalculator)unbiasedEstimatorMeanCalculator.Clone();
    139       return new OnlineTheilsUStatisticCalculator(squaredErrorMeanCalculatorClone, unbiasedEstimatorMeanCalculatorClone);
     136      var cloner = new Cloner();
     137      return new OnlineTheilsUStatisticCalculator(this, cloner);
    140138    }
    141139
     
    143141      var clone = cloner.GetClone(this);
    144142      if (clone == null) {
    145         var squaredErrorMeanCalculatorClone = (OnlineMeanAndVarianceCalculator)squaredErrorMeanCalculator.Clone(cloner);
    146         var unbiasedEstimatorMeanCalculatorClone = (OnlineMeanAndVarianceCalculator)unbiasedEstimatorMeanCalculator.Clone(cloner);
    147         clone = new OnlineTheilsUStatisticCalculator(squaredErrorMeanCalculatorClone, unbiasedEstimatorMeanCalculatorClone);
     143        clone = new OnlineTheilsUStatisticCalculator(this, cloner);
    148144        cloner.RegisterClonedObject(this, clone);
    149145      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineWeightedDirectionalSymmetryCalculator.cs

    r14293 r14294  
    4242    }
    4343
    44     // private constructor used internally by the Clone() method
    45     private OnlineWeightedDirectionalSymmetryCalculator(OnlineWeightedDirectionalSymmetryCalculator other) {
     44    protected OnlineWeightedDirectionalSymmetryCalculator(OnlineWeightedDirectionalSymmetryCalculator other, Cloner cloner = null) {
    4645      n = other.n;
    4746      correctSum = other.correctSum;
     
    135134      var clone = cloner.GetClone(this);
    136135      if (clone == null) {
    137         clone = (IDeepCloneable)this.Clone();
     136        clone = new OnlineWeightedDirectionalSymmetryCalculator(this);
    138137        cloner.RegisterClonedObject(this, clone);
    139138      }
Note: See TracChangeset for help on using the changeset viewer.