/** * Default constructor, using an {@link SvdPrincipalComponentAnalysis}. */ public FeatureVectorPCA() { this.inner = new SvdPrincipalComponentAnalysis(); }
/** * Construct a {@link PointDistributionModel} from the given data and * {@link Constraint}. * * @param constraint * @param data */ public PointDistributionModel(Constraint constraint, List<PointList> data) { this.constraint = constraint; // align mean = GeneralisedProcrustesAnalysis.alignPoints(data, 5, 10); // build data matrix final Matrix m = buildDataMatrix(data); // perform pca this.pc = new SvdPrincipalComponentAnalysis(); pc.learnBasis(m); numComponents = this.pc.getEigenValues().length; }
@Override public void train(double[][] data) { if (ns instanceof TrainableNormaliser) ((TrainableNormaliser) ns).train(data); final double[][] normData = ns.normalise(data); final SvdPrincipalComponentAnalysis pca = new SvdPrincipalComponentAnalysis(ndims); pca.learnBasisNorm(new Matrix(normData)); transform = pca.getBasis(); final double[] weight = pca.getEigenValues(); final double[][] td = transform.getArray(); for (int c = 0; c < weight.length; c++) weight[c] = 1 / Math.sqrt(weight[c] + eps); for (int r = 0; r < td.length; r++) for (int c = 0; c < td[0].length; c++) td[r][c] = td[r][c] * weight[c]; }
@Override public void train(double[][] data) { ns.normalise(data); final double[][] normData = ns.normalise(data); final SvdPrincipalComponentAnalysis pca = new SvdPrincipalComponentAnalysis(); pca.learnBasisNorm(new Matrix(normData)); transform = pca.getBasis().copy(); final double[] weight = pca.getEigenValues(); final double[][] td = transform.getArray(); for (int c = 0; c < weight.length; c++) weight[c] = 1 / Math.sqrt(weight[c] + eps); for (int r = 0; r < td.length; r++) for (int c = 0; c < td[0].length; c++) td[r][c] = td[r][c] * weight[c]; transform = transform.times(pca.getBasis().transpose()); } }