#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Encodings.RealVectorEncoding; using HeuristicLab.Operators; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Problems.DataAnalysis; namespace HeuristicLab.Algorithms.DataAnalysis { [Item("NcaInitializer", "Base class for initializers for NCA.")] [StorableClass] public abstract class NcaInitializer : SingleSuccessorOperator, INcaInitializer { public ILookupParameter ProblemDataParameter { get { return (ILookupParameter)Parameters["ProblemData"]; } } public ILookupParameter DimensionsParameter { get { return (ILookupParameter)Parameters["Dimensions"]; } } public ILookupParameter NcaMatrixParameter { get { return (ILookupParameter)Parameters["NcaMatrix"]; } } [StorableConstructor] protected NcaInitializer(bool deserializing) : base(deserializing) { } protected NcaInitializer(NcaInitializer original, Cloner cloner) : base(original, cloner) { } public NcaInitializer() { Parameters.Add(new LookupParameter("ProblemData", "The classification problem data.")); Parameters.Add(new LookupParameter("Dimensions", "The number of dimensions to which the features should be pruned.")); Parameters.Add(new LookupParameter("NcaMatrix", "The coefficients of the matrix that need to be optimized. Note that the matrix is flattened.")); } public override IOperation Apply() { var problemData = ProblemDataParameter.ActualValue; var dimensions = DimensionsParameter.ActualValue.Value; var matrix = Initialize(problemData, dimensions); var attributes = matrix.GetLength(0); var result = new double[attributes * dimensions]; for (int i = 0; i < attributes; i++) for (int j = 0; j < dimensions; j++) result[i * dimensions + j] = matrix[i, j]; NcaMatrixParameter.ActualValue = new RealVector(result); return base.Apply(); } public abstract double[,] Initialize(IClassificationProblemData data, int dimensions); } }