- Timestamp:
- 03/04/13 15:16:49 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/INcaInitializer.cs
r9270 r9272 31 31 /// <param name="dimensions">The amount of columns in the matrix</param> 32 32 /// <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); 34 34 } 35 35 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/LdaInitializer.cs
r9270 r9272 40 40 } 41 41 42 public override double[,] Initialize(IClassificationProblemData data, Scaling scaling,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 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); 59 49 60 50 var uniqueClasses = data.Dataset.GetDoubleValues(data.TargetVariable, data.TrainingIndices).Distinct().Count(); -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/NcaInitializer.cs
r9270 r9272 43 43 get { return (ILookupParameter<RealVector>)Parameters["NcaMatrix"]; } 44 44 } 45 public ILookupParameter<Scaling> ScalingParameter {46 get { return (ILookupParameter<Scaling>)Parameters["Scaling"]; }47 }48 45 49 46 [StorableConstructor] … … 54 51 Parameters.Add(new LookupParameter<IntValue>("Dimensions", "The number of dimensions to which the features should be pruned.")); 55 52 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."));57 53 } 58 54 59 55 public override IOperation Apply() { 60 56 var problemData = ProblemDataParameter.ActualValue; 61 var scaling = new Scaling(problemData.Dataset, problemData.AllowedInputVariables, problemData.TrainingIndices);62 57 63 58 var dimensions = DimensionsParameter.ActualValue.Value; 64 var matrix = Initialize(problemData, scaling,dimensions);59 var matrix = Initialize(problemData, dimensions); 65 60 var attributes = matrix.GetLength(0); 66 61 … … 70 65 result[i * dimensions + j] = matrix[i, j]; 71 66 72 ScalingParameter.ActualValue = scaling;73 67 NcaMatrixParameter.ActualValue = new RealVector(result); 74 68 return base.Apply(); 75 69 } 76 70 77 public abstract double[,] Initialize(IClassificationProblemData data, Scaling scaling,int dimensions);71 public abstract double[,] Initialize(IClassificationProblemData data, int dimensions); 78 72 } 79 73 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/PcaInitializer.cs
r9270 r9272 40 40 } 41 41 42 public override double[,] Initialize(IClassificationProblemData data, Scaling scaling,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 = AlglibUtil.Prepare AndScaleInputMatrix(data.Dataset, data.AllowedInputVariables, data.TrainingIndices, scaling);46 var pcaDs = AlglibUtil.PrepareInputMatrix(data.Dataset, data.AllowedInputVariables, data.TrainingIndices); 47 47 48 48 int info; -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/RandomInitializer.cs
r9270 r9272 48 48 } 49 49 50 public override double[,] Initialize(IClassificationProblemData data, Scaling scaling,int dimensions) {50 public override double[,] Initialize(IClassificationProblemData data, int dimensions) { 51 51 var attributes = data.AllowedInputVariables.Count(); 52 52
Note: See TracChangeset
for help on using the changeset viewer.