Commit acab277e by Michal Balazia

### distance map

parent 07d6abac
File deleted
 package algorithms; import Jama.EigenvalueDecomposition; import Jama.Matrix; import objects.Template; public class Classifier1NNNareshKumarMS extends Classifier { public Classifier1NNNareshKumarMS() { DecisionKNN decision = new DecisionKNN(1); decision.setDistanceTemplates(new DistanceTemplatesNareshKumarMS()); setDecision(decision); } public final class DistanceTemplatesNareshKumarMS extends DistanceTemplates { public DistanceTemplatesNareshKumarMS() { } @Override public String getDescription() { return "NareshKumarMS"; } @Override public double getDistance(Template template1, Template template2) { double sum = 0.0; double[] generalizedEigenvalues = new EigenvalueDecomposition(getCovarianceMatrix(template2).inverse().times(getCovarianceMatrix(template1))).getRealEigenvalues(); for (int l = 0; l < generalizedEigenvalues.length; l++) { sum += Math.pow(Math.log(Math.abs(generalizedEigenvalues[l])), 2); } return Math.sqrt(sum); } private Matrix getCovarianceMatrix(Template template) { Matrix matrix = template.getMatrix(); int rows = matrix.getRowDimension(); int columns = matrix.getColumnDimension(); Matrix covarianceMatrix = new Matrix(columns, columns); for (int r = 0; r < rows; r++) { Matrix d = matrix.getMatrix(r, r, 0, columns - 1); Matrix u = getDistanceTemplatesMatrix().getMatrix(r, r, 0, columns - 1); Matrix diff = d.minus(u); covarianceMatrix.plusEquals((diff.transpose().times(diff)).times((double) 1 / (rows - 1))); } return covarianceMatrix; } } } package algorithms; public class Classifier1NNNareshKumarMS extends Classifier { public Classifier1NNNareshKumarMS() { DecisionKNN decision = new DecisionKNN(1); decision.setDistanceTemplates(new DistanceTemplatesNareshKumarMS()); setDecision(decision); } }
 ... ... @@ -39,8 +39,15 @@ public class ClassifierTransform1NNMMCMahalanobis extends ClassifierTransform { double[] column = (getMeanMatrix(samplesOfClass).minus(meanSampleMatrix)).times(Math.sqrt((double) samplesOfClass.size() / numberOfSamples)).getColumnPackedCopy(); Upsilon.setMatrix(0, dimension - 1, c, c, new Matrix(column, column.length)); } SingularValueDecomposition svdChi = new SingularValueDecomposition(Chi); Matrix Omega = svdChi.getU(); SingularValueDecomposition svdChi; Matrix Omega; if (dimension < numberOfSamples) { svdChi = new SingularValueDecomposition(Chi.transpose()); Omega = svdChi.getV().transpose(); } else { svdChi = new SingularValueDecomposition(Chi); Omega = svdChi.getU(); } Matrix ThetaInverseSquareRoot = svdChi.getS(); int dim = Math.min(ThetaInverseSquareRoot.getRowDimension(), ThetaInverseSquareRoot.getColumnDimension()); for (int d = 0; d < dim; d++) { ... ...
 package algorithms; import java.util.List; import objects.Template; public abstract class Clustering extends Retriever { public Clustering() { } public abstract List> cluster(List
 package algorithms; import java.util.ArrayList; import java.util.List; import objects.Template; public class ClusteringAgglomerativeHierarchical extends Clustering { private final int k; private final double d; public ClusteringAgglomerativeHierarchical(int k) { this.k = k; this.d = Double.MAX_VALUE; } public ClusteringAgglomerativeHierarchical(double d) { this.k = Integer.MAX_VALUE; this.d = d; } @Override public List> cluster(List
 package algorithms; import java.util.ArrayList; import java.util.List; import java.util.Random; import objects.Template; public class ClusteringKmeans extends Clustering { private final int k; public ClusteringKmeans(int k) { this.k = k; } @Override public List> cluster(List
 package algorithms; import java.util.List; import objects.Template; public abstract class Decision extends Retriever { private List gallery; public Decision() { } public List getGallery() { return gallery; } public void setGallery(List gallery) { this.gallery = gallery; } public abstract String getDescription(); public abstract void importGallery(List
 package algorithms; import java.util.ArrayList; import java.util.List; import java.util.Random; import objects.Template; public class DecisionRandom extends Decision { @Override public String getDescription() { return "random"; } @Override public void importGallery(List
 package algorithms; import java.util.List; import libsvm.svm; import libsvm.svm_model; import libsvm.svm_node; import libsvm.svm_parameter; import libsvm.svm_problem; import objects.Template; public class DecisionSVM extends Decision { @Override public String getDescription() { return "SVM"; } @Override public void importGallery(List