private static void projectPCA( MemoryLocalFeatureList<FloatDSIFTKeypoint> loadDSIFT, PrincipalComponentAnalysis pca) { for (final FloatDSIFTKeypoint kp : loadDSIFT) { kp.descriptor = ArrayUtils.convertToFloat(pca.project(ArrayUtils.convertToDouble(kp.descriptor))); final int nf = kp.descriptor.length; kp.descriptor = Arrays.copyOf(kp.descriptor, nf + 2); kp.descriptor[nf] = (kp.x / 125f) - 0.5f; kp.descriptor[nf + 1] = (kp.y / 160f) - 0.5f; } loadDSIFT.resetVecLength(); }
private static void projectPCA( MemoryLocalFeatureList<FloatDSIFTKeypoint> loadDSIFT, PrincipalComponentAnalysis pca) { for (final FloatDSIFTKeypoint kp : loadDSIFT) { kp.descriptor = ArrayUtils.convertToFloat(pca.project(ArrayUtils.convertToDouble(kp.descriptor))); final int nf = kp.descriptor.length; kp.descriptor = Arrays.copyOf(kp.descriptor, nf + 2); kp.descriptor[nf] = (kp.x / 125f) - 0.5f; kp.descriptor[nf + 1] = (kp.y / 160f) - 0.5f; } loadDSIFT.resetVecLength(); }
@Override public void train(List<? extends IndependentPair<?, FImage>> data) { width = data.get(0).secondObject().width; height = data.get(0).secondObject().height; final Map<Object, List<double[]>> mapData = new HashMap<Object, List<double[]>>(); final List<double[]> listData = new ArrayList<double[]>(); for (final IndependentPair<?, FImage> item : data) { List<double[]> fvs = mapData.get(item.firstObject()); if (fvs == null) mapData.put(item.firstObject(), fvs = new ArrayList<double[]>()); final double[] fv = FImage2DoubleFV.INSTANCE.extractFeature(item.getSecondObject()).values; fvs.add(fv); listData.add(fv); } final PrincipalComponentAnalysis pca = new ThinSvdPrincipalComponentAnalysis(numComponents); pca.learnBasis(listData); final List<double[][]> ldaData = new ArrayList<double[][]>(mapData.size()); for (final Entry<?, List<double[]>> e : mapData.entrySet()) { final List<double[]> vecs = e.getValue(); final double[][] classData = new double[vecs.size()][]; for (int i = 0; i < classData.length; i++) { classData[i] = pca.project(vecs.get(i)); } ldaData.add(classData); } final LinearDiscriminantAnalysis lda = new LinearDiscriminantAnalysis(numComponents); lda.learnBasis(ldaData); basis = pca.getBasis().times(lda.getBasis()); mean = pca.getMean(); }
@Override public void train(List<? extends IndependentPair<?, FImage>> data) { width = data.get(0).secondObject().width; height = data.get(0).secondObject().height; final Map<Object, List<double[]>> mapData = new HashMap<Object, List<double[]>>(); final List<double[]> listData = new ArrayList<double[]>(); for (final IndependentPair<?, FImage> item : data) { List<double[]> fvs = mapData.get(item.firstObject()); if (fvs == null) mapData.put(item.firstObject(), fvs = new ArrayList<double[]>()); final double[] fv = FImage2DoubleFV.INSTANCE.extractFeature(item.getSecondObject()).values; fvs.add(fv); listData.add(fv); } final PrincipalComponentAnalysis pca = new ThinSvdPrincipalComponentAnalysis(numComponents); pca.learnBasis(listData); final List<double[][]> ldaData = new ArrayList<double[][]>(mapData.size()); for (final Entry<?, List<double[]>> e : mapData.entrySet()) { final List<double[]> vecs = e.getValue(); final double[][] classData = new double[vecs.size()][]; for (int i = 0; i < classData.length; i++) { classData[i] = pca.project(vecs.get(i)); } ldaData.add(classData); } final LinearDiscriminantAnalysis lda = new LinearDiscriminantAnalysis(numComponents); lda.learnBasis(ldaData); basis = pca.getBasis().times(lda.getBasis()); mean = pca.getMean(); }
descriptor = ArrayUtils.convertToFloat(pca.project(ArrayUtils.convertToDouble(descriptor)));
descriptor = ArrayUtils.convertToFloat(pca.project(ArrayUtils.convertToDouble(descriptor)));