Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/06/10 01:56:04 (14 years ago)
Author:
swagner
Message:

Merged cloning refactoring branch back into trunk (#922)

Location:
trunk/sources
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources

  • trunk/sources/HeuristicLab.Problems.DataAnalysis

  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/SupportVectorMachineCrossValidationEvaluator.cs

    r4543 r4722  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
     25using HeuristicLab.Common;
    2426using HeuristicLab.Core;
    2527using HeuristicLab.Data;
     
    2931using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3032using SVM;
    31 using System.Collections.Generic;
    3233
    3334namespace HeuristicLab.Problems.DataAnalysis.SupportVectorMachine {
     
    126127    #endregion
    127128
     129    [StorableConstructor]
     130    protected SupportVectorMachineCrossValidationEvaluator(bool deserializing) : base(deserializing) { }
     131
     132    protected SupportVectorMachineCrossValidationEvaluator(SupportVectorMachineCrossValidationEvaluator original,
     133      Cloner cloner)
     134      : base(original, cloner) { }
    128135    public SupportVectorMachineCrossValidationEvaluator()
    129136      : base() {
     
    143150    }
    144151
     152    public override IDeepCloneable Clone(Cloner cloner) {
     153      return new SupportVectorMachineCrossValidationEvaluator(this, cloner);
     154    }
     155
    145156    public override IOperation Apply() {
    146157      double reductionRatio = 1.0; // TODO: make parameter
    147158      if (ActualSamplesParameter.ActualValue != null)
    148159        reductionRatio = ActualSamplesParameter.ActualValue.Value;
    149       IEnumerable<int> rows = 
     160      IEnumerable<int> rows =
    150161        Enumerable.Range(SamplesStart.Value, SamplesEnd.Value - SamplesStart.Value)
    151162        .Where(i => i < DataAnalysisProblemData.TestSamplesStart.Value || DataAnalysisProblemData.TestSamplesEnd.Value <= i);
     
    153164      // create a new DataAnalysisProblemData instance
    154165      DataAnalysisProblemData reducedProblemData = (DataAnalysisProblemData)DataAnalysisProblemData.Clone();
    155       reducedProblemData.Dataset = 
     166      reducedProblemData.Dataset =
    156167        CreateReducedDataset(RandomParameter.ActualValue, reducedProblemData.Dataset, rows, reductionRatio);
    157168      reducedProblemData.TrainingSamplesStart.Value = 0;
     
    170181
    171182    private Dataset CreateReducedDataset(IRandom random, Dataset dataset, IEnumerable<int> rowIndices, double reductionRatio) {
    172      
     183
    173184      // must not make a fink:
    174185      // => select n rows randomly from start..end
     
    191202      // take the first n indexes (selected n rowIndexes from start..end)
    192203      // now order by index
    193       int[] orderedRandomIndexes = 
     204      int[] orderedRandomIndexes =
    194205        rowIndexArr.Take(n)
    195206        .OrderBy(x => x)
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/SupportVectorMachineModel.cs

    r4543 r4722  
    3636  [StorableClass]
    3737  [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;
    4146    }
     47    public SupportVectorMachineModel() : base() { }
    4248
    4349    private SVM.Model model;
     
    131137
    132138    public override IDeepCloneable Clone(Cloner cloner) {
    133       SupportVectorMachineModel clone = (SupportVectorMachineModel)base.Clone(cloner);
    134       // beware we are only using a shallow copy here! (gkronber)
    135       clone.model = model;
    136       clone.rangeTransform = rangeTransform;
    137       return clone;
     139      return new SupportVectorMachineModel(this, cloner);
    138140    }
    139141
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/SupportVectorMachineModelCreator.cs

    r4543 r4722  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.Linq;
     25using HeuristicLab.Common;
    2326using HeuristicLab.Core;
    2427using HeuristicLab.Data;
     
    2730using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2831using SVM;
    29 using System.Collections.Generic;
    30 using System.Linq;
    3132
    3233namespace HeuristicLab.Problems.DataAnalysis.SupportVectorMachine {
     
    3637  [StorableClass]
    3738  [Item("SupportVectorMachineModelCreator", "Represents an operator that creates a support vector machine model.")]
    38   public class SupportVectorMachineModelCreator : SingleSuccessorOperator {
     39  public sealed class SupportVectorMachineModelCreator : SingleSuccessorOperator {
    3940    private const string DataAnalysisProblemDataParameterName = "DataAnalysisProblemData";
    4041    private const string SvmTypeParameterName = "SvmType";
     
    110111    #endregion
    111112
     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    }
    112119    public SupportVectorMachineModelCreator()
    113120      : base() {
     
    129136      int start = SamplesStart.Value;
    130137      int end = SamplesEnd.Value;
    131       IEnumerable<int> rows = 
    132         Enumerable.Range(start, end-start)
     138      IEnumerable<int> rows =
     139        Enumerable.Range(start, end - start)
    133140        .Where(i => i < DataAnalysisProblemData.TestSamplesStart.Value || DataAnalysisProblemData.TestSamplesEnd.Value <= i);
    134141
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/SupportVectorMachineModelEvaluator.cs

    r4543 r4722  
    2020#endregion
    2121
     22using System.Collections.Generic;
     23using System.Linq;
     24using HeuristicLab.Common;
    2225using HeuristicLab.Core;
    2326using HeuristicLab.Data;
     
    2629using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2730using SVM;
    28 using System.Collections.Generic;
    29 using System.Linq;
    3031
    3132namespace HeuristicLab.Problems.DataAnalysis.SupportVectorMachine {
     
    7071    }
    7172    #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    }
    7280    public SupportVectorMachineModelEvaluator()
    7381      : base() {
Note: See TracChangeset for help on using the changeset viewer.