Changeset 10553 for branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/PcaInitializer.cs
- Timestamp:
- 03/05/14 17:30:38 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/PcaInitializer.cs
r8471 r10553 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 29 29 [Item("PCA", "Initializes the matrix by performing a principal components analysis.")] 30 30 [StorableClass] 31 public sealed class P CAInitializer : Item, INCAInitializer {31 public sealed class PcaInitializer : NcaInitializer { 32 32 33 33 [StorableConstructor] 34 private P CAInitializer(bool deserializing) : base(deserializing) { }35 private P CAInitializer(PCAInitializer original, Cloner cloner) : base(original, cloner) { }36 public P CAInitializer() : base() { }34 private PcaInitializer(bool deserializing) : base(deserializing) { } 35 private PcaInitializer(PcaInitializer original, Cloner cloner) : base(original, cloner) { } 36 public PcaInitializer() : base() { } 37 37 38 38 public override IDeepCloneable Clone(Cloner cloner) { 39 return new P CAInitializer(this, cloner);39 return new PcaInitializer(this, cloner); 40 40 } 41 41 42 public double[] Initialize(IClassificationProblemData data, int dimensions) {42 public override double[,] Initialize(IClassificationProblemData data, int dimensions) { 43 43 var instances = data.TrainingIndices.Count(); 44 44 var attributes = data.AllowedInputVariables.Count(); 45 45 46 var pcaDs = new double[instances, attributes]; 47 int col = 0; 48 foreach (var variable in data.AllowedInputVariables) { 49 int row = 0; 50 foreach (var value in data.Dataset.GetDoubleValues(variable, data.TrainingIndices)) { 51 pcaDs[row, col] = value; 52 row++; 53 } 54 col++; 55 } 46 var pcaDs = AlglibUtil.PrepareInputMatrix(data.Dataset, data.AllowedInputVariables, data.TrainingIndices); 56 47 57 48 int info; … … 60 51 alglib.pcabuildbasis(pcaDs, instances, attributes, out info, out varianceValues, out matrix); 61 52 62 var result = new double[attributes * dimensions]; 63 for (int i = 0; i < attributes; i++) 64 for (int j = 0; j < dimensions; j++) 65 result[i * dimensions + j] = matrix[i, j]; 66 67 return result; 53 return matrix; 68 54 } 69 55
Note: See TracChangeset
for help on using the changeset viewer.