Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9272


Ignore:
Timestamp:
03/04/13 15:16:49 (10 years ago)
Author:
abeham
Message:

#1913: removed scaling of data

Location:
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/INcaInitializer.cs

    r9270 r9272  
    3131    /// <param name="dimensions">The amount of columns in the matrix</param>
    3232    /// <returns>The matrix that projects the input variables into a lower dimensional space.</returns>
    33     double[,] Initialize(IClassificationProblemData data, Scaling scaling, int dimensions);
     33    double[,] Initialize(IClassificationProblemData data, int dimensions);
    3434  }
    3535}
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/LdaInitializer.cs

    r9270 r9272  
    4040    }
    4141
    42     public override double[,] Initialize(IClassificationProblemData data, Scaling scaling, int dimensions) {
     42    public override double[,] Initialize(IClassificationProblemData data, int dimensions) {
    4343      var instances = data.TrainingIndices.Count();
    4444      var attributes = data.AllowedInputVariables.Count();
    4545
    46       var ldaDs = new double[instances, attributes + 1];
    47       int j = 0;
    48       foreach (var a in data.AllowedInputVariables) {
    49         int i = 0;
    50         var sv = scaling.GetScaledValues(data.Dataset, a, data.TrainingIndices);
    51         foreach (var v in sv) {
    52           ldaDs[i++, j] = v;
    53         }
    54         j++;
    55       }
    56       j = 0;
    57       foreach (var tv in data.Dataset.GetDoubleValues(data.TargetVariable, data.TrainingIndices))
    58         ldaDs[j++, attributes] = tv;
     46      var ldaDs = AlglibUtil.PrepareInputMatrix(data.Dataset,
     47                                                data.AllowedInputVariables.Concat(data.TargetVariable.ToEnumerable()),
     48                                                data.TrainingIndices);
    5949
    6050      var uniqueClasses = data.Dataset.GetDoubleValues(data.TargetVariable, data.TrainingIndices).Distinct().Count();
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/NcaInitializer.cs

    r9270 r9272  
    4343      get { return (ILookupParameter<RealVector>)Parameters["NcaMatrix"]; }
    4444    }
    45     public ILookupParameter<Scaling> ScalingParameter {
    46       get { return (ILookupParameter<Scaling>)Parameters["Scaling"]; }
    47     }
    4845
    4946    [StorableConstructor]
     
    5451      Parameters.Add(new LookupParameter<IntValue>("Dimensions", "The number of dimensions to which the features should be pruned."));
    5552      Parameters.Add(new LookupParameter<RealVector>("NcaMatrix", "The coefficients of the matrix that need to be optimized. Note that the matrix is flattened."));
    56       Parameters.Add(new LookupParameter<Scaling>("Scaling", "Each dataset is scaled and the information is stored in a scaling object."));
    5753    }
    5854
    5955    public override IOperation Apply() {
    6056      var problemData = ProblemDataParameter.ActualValue;
    61       var scaling = new Scaling(problemData.Dataset, problemData.AllowedInputVariables, problemData.TrainingIndices);
    6257
    6358      var dimensions = DimensionsParameter.ActualValue.Value;
    64       var matrix = Initialize(problemData, scaling, dimensions);
     59      var matrix = Initialize(problemData, dimensions);
    6560      var attributes = matrix.GetLength(0);
    6661
     
    7065          result[i * dimensions + j] = matrix[i, j];
    7166
    72       ScalingParameter.ActualValue = scaling;
    7367      NcaMatrixParameter.ActualValue = new RealVector(result);
    7468      return base.Apply();
    7569    }
    7670
    77     public abstract double[,] Initialize(IClassificationProblemData data, Scaling scaling, int dimensions);
     71    public abstract double[,] Initialize(IClassificationProblemData data, int dimensions);
    7872  }
    7973}
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/PcaInitializer.cs

    r9270 r9272  
    4040    }
    4141
    42     public override double[,] Initialize(IClassificationProblemData data, Scaling scaling, int dimensions) {
     42    public override double[,] Initialize(IClassificationProblemData data, int dimensions) {
    4343      var instances = data.TrainingIndices.Count();
    4444      var attributes = data.AllowedInputVariables.Count();
    4545
    46       var pcaDs = AlglibUtil.PrepareAndScaleInputMatrix(data.Dataset, data.AllowedInputVariables, data.TrainingIndices, scaling);
     46      var pcaDs = AlglibUtil.PrepareInputMatrix(data.Dataset, data.AllowedInputVariables, data.TrainingIndices);
    4747
    4848      int info;
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/RandomInitializer.cs

    r9270 r9272  
    4848    }
    4949
    50     public override double[,] Initialize(IClassificationProblemData data, Scaling scaling, int dimensions) {
     50    public override double[,] Initialize(IClassificationProblemData data, int dimensions) {
    5151      var attributes = data.AllowedInputVariables.Count();
    5252
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/ModelCreation/NcaModelCreator.cs

    r9270 r9272  
    5555    }
    5656
    57     public ILookupParameter<Scaling> ScalingParameter {
    58       get { return (ILookupParameter<Scaling>)Parameters["Scaling"]; }
    59     }
    60 
    6157    public ILookupParameter<INcaModel> NcaModelParameter {
    6258      get { return (ILookupParameter<INcaModel>)Parameters["NcaModel"]; }
     
    7268      Parameters.Add(new LookupParameter<RealVector>("NcaMatrixGradients", "The gradients from the matrix that is being optimized."));
    7369      Parameters.Add(new LookupParameter<IClassificationProblemData>("ProblemData", "The classification problem data."));
    74       Parameters.Add(new LookupParameter<Scaling>("Scaling", "The scaling of the dataset."));
    7570      Parameters.Add(new LookupParameter<INcaModel>("NcaModel", "The NCA model that should be created."));
    7671    }
     
    9186        }
    9287
    93       var scaling = ScalingParameter.ActualValue;
    9488      var problemData = ProblemDataParameter.ActualValue;
    95       NcaModelParameter.ActualValue = new NcaModel(k, matrix, problemData.Dataset, problemData.TrainingIndices, problemData.TargetVariable, problemData.AllowedInputVariables, scaling, problemData.ClassValues.ToArray());
     89      NcaModelParameter.ActualValue = new NcaModel(k, matrix, problemData.Dataset, problemData.TrainingIndices, problemData.TargetVariable, problemData.AllowedInputVariables, problemData.ClassValues.ToArray());
    9690      return base.Apply();
    9791    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaGradientCalculator.cs

    r9270 r9272  
    6565      get { return (ILookupParameter<IClassificationProblemData>)Parameters["ProblemData"]; }
    6666    }
    67 
    68     public ILookupParameter<Scaling> ScalingParameter {
    69       get { return (ILookupParameter<Scaling>)Parameters["Scaling"]; }
    70     }
    7167    #endregion
    7268
     
    8379      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the current matrix."));
    8480      Parameters.Add(new LookupParameter<IClassificationProblemData>("ProblemData", "The classification problem data."));
    85       Parameters.Add(new LookupParameter<Scaling>("Scaling", "The scaling of the dataset."));
    8681    }
    8782
     
    9287    public override IOperation Apply() {
    9388      var problemData = ProblemDataParameter.ActualValue;
    94       var scaling = ScalingParameter.ActualValue;
    9589      var dimensions = DimensionsParameter.ActualValue.Value;
    9690      var neighborSamples = NeighborSamplesParameter.ActualValue.Value;
     
    10498      }
    10599
    106       var data = AlglibUtil.PrepareAndScaleInputMatrix(problemData.Dataset, problemData.AllowedInputVariables,
    107                                                        problemData.TrainingIndices, scaling);
     100      var data = AlglibUtil.PrepareInputMatrix(problemData.Dataset, problemData.AllowedInputVariables,
     101                                               problemData.TrainingIndices);
    108102      var classes = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices).ToArray();
    109103
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaModel.cs

    r8528 r9272  
    3333
    3434    [Storable]
    35     private Scaling scaling;
    36     [Storable]
    3735    private double[,] transformationMatrix;
    3836    public double[,] TransformationMatrix {
     
    5250    protected NcaModel(NcaModel original, Cloner cloner)
    5351      : base(original, cloner) {
    54       this.scaling = cloner.Clone(original.scaling);
    5552      this.transformationMatrix = (double[,])original.transformationMatrix.Clone();
    5653      this.allowedInputVariables = (string[])original.allowedInputVariables.Clone();
     
    5956      this.classValues = (double[])original.classValues.Clone();
    6057    }
    61     public NcaModel(int k, double[,] transformationMatrix, Dataset dataset, IEnumerable<int> rows, string targetVariable, IEnumerable<string> allowedInputVariables, Scaling scaling, double[] classValues) {
     58    public NcaModel(int k, double[,] transformationMatrix, Dataset dataset, IEnumerable<int> rows, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues) {
    6259      Name = ItemName;
    6360      Description = ItemDescription;
    64       this.scaling = scaling;
    6561      this.transformationMatrix = (double[,])transformationMatrix.Clone();
    6662      this.allowedInputVariables = allowedInputVariables.ToArray();
     
    9086
    9187    public double[,] Reduce(Dataset dataset, IEnumerable<int> rows) {
    92       var scaledData = AlglibUtil.PrepareAndScaleInputMatrix(dataset, allowedInputVariables, rows, scaling);
     88      var data = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
     89
    9390      var targets = dataset.GetDoubleValues(targetVariable, rows).ToArray();
    94       var result = new double[scaledData.GetLength(0), transformationMatrix.GetLength(1) + 1];
    95       for (int i = 0; i < scaledData.GetLength(0); i++)
    96         for (int j = 0; j < scaledData.GetLength(1); j++) {
     91      var result = new double[data.GetLength(0), transformationMatrix.GetLength(1) + 1];
     92      for (int i = 0; i < data.GetLength(0); i++)
     93        for (int j = 0; j < data.GetLength(1); j++) {
    9794          for (int x = 0; x < transformationMatrix.GetLength(1); x++) {
    98             result[i, x] += scaledData[i, j] * transformationMatrix[j, x];
     95            result[i, x] += data[i, j] * transformationMatrix[j, x];
    9996          }
    10097          result[i, transformationMatrix.GetLength(1)] = targets[i];
Note: See TracChangeset for help on using the changeset viewer.