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() { ... ... @@ -11,39 +7,4 @@ public class Classifier1NNNareshKumarMS extends Classifier { 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; } } }
 ... ... @@ -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++) { ... ...
 ... ... @@ -3,9 +3,9 @@ package algorithms; import java.util.List; import objects.Template; public abstract class Clustering extends Retriever { public abstract class Clusterer extends Retriever { public Clustering() { public Clusterer() { } public abstract List> cluster(List
 ... ... @@ -4,17 +4,17 @@ import java.util.ArrayList; import java.util.List; import objects.Template; public class ClusteringAgglomerativeHierarchical extends Clustering { public class ClustererAgglomerativeHierarchical extends Clusterer { private final int k; private final double d; public ClusteringAgglomerativeHierarchical(int k) { public ClustererAgglomerativeHierarchical(int k) { this.k = k; this.d = Double.MAX_VALUE; } public ClusteringAgglomerativeHierarchical(double d) { public ClustererAgglomerativeHierarchical(double d) { this.k = Integer.MAX_VALUE; this.d = d; } ... ...
 ... ... @@ -5,11 +5,11 @@ import java.util.List; import java.util.Random; import objects.Template; public class ClusteringKmeans extends Clustering { public class ClustererKmeans extends Clusterer { private final int k; public ClusteringKmeans(int k) { public ClustererKmeans(int k) { this.k = k; } ... ...
 ... ... @@ -7,9 +7,6 @@ public abstract class Decision extends Retriever { private List gallery; public Decision() { } public List getGallery() { return gallery; } ... ...
 package algorithms; import java.util.ArrayList; import java.util.List; import java.util.Random; import objects.Template; ... ... @@ -14,16 +13,12 @@ public class DecisionRandom extends Decision { @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
 package algorithms; import Jama.Matrix; import java.io.Serializable; import objects.Template; public abstract class DistanceTemplates implements Serializable { private Matrix distanceTemplatesMatrix; public DistanceTemplates() { } public Matrix getDistanceTemplatesMatrix() { return distanceTemplatesMatrix; } public void setDistanceTemplatesMatrix(Matrix distanceTemplatesMatrix) { this.distanceTemplatesMatrix = distanceTemplatesMatrix; } public abstract String getDescription(); public abstract double getDistance(Template template1, Template template2); ... ...
 ... ... @@ -5,9 +5,15 @@ import objects.Template; public final class DistanceTemplatesMahalanobis extends DistanceTemplates { private Matrix totalScatterMatrix; public DistanceTemplatesMahalanobis() { } public void setTotalScatterMatrix(Matrix totalScatterMatrix) { this.totalScatterMatrix = totalScatterMatrix; } @Override public String getDescription() { return "Mahalanobis"; ... ... @@ -16,6 +22,6 @@ public final class DistanceTemplatesMahalanobis extends DistanceTemplates { @Override public double getDistance(Template template1, Template template2) { Matrix diff = template1.getMatrix().minus(template2.getMatrix()); return Math.sqrt(diff.transpose().times(getDistanceTemplatesMatrix()).times(diff).get(0, 0)); return Math.sqrt(diff.transpose().times(totalScatterMatrix).times(diff).get(0, 0)); } }
 package algorithms; import Jama.EigenvalueDecomposition; import Jama.Matrix; import objects.Template; public final class DistanceTemplatesNareshKumarMS extends DistanceTemplates { private Matrix meanMatrix; public DistanceTemplatesNareshKumarMS() { } public void setMeanMatrix(Matrix meanMatrix) { this.meanMatrix = meanMatrix; } @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 = meanMatrix.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 methods; package algorithms; import Jama.Matrix; import algorithms.Classifier; import algorithms.MotionLoader; import executor.MotionLoader; import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; ... ...
 package methods; package algorithms; import algorithms.Classifier; import algorithms.MotionLoaderJointCoordinates; import executor.MotionLoaderJointCoordinates; import java.util.ArrayList; import java.util.List; import objects.Feature; ... ...
 package methods; package algorithms; import algorithms.Classifier; import algorithms.MotionLoaderJointCoordinates; import executor.MotionLoaderJointCoordinates; import java.util.ArrayList; import java.util.List; import objects.Axis; ... ...
 package methods; package algorithms; import algorithms.Classifier; import algorithms.MotionLoaderJointCoordinates; import executor.MotionLoaderJointCoordinates; import java.util.ArrayList; import java.util.List; import objects.Feature; ... ...
 package methods; package algorithms; import algorithms.Classifier; import algorithms.MotionLoaderJointCoordinates; import executor.MotionLoaderJointCoordinates; import java.util.ArrayList; import java.util.List; import objects.Axis; ... ...
 package methods; package algorithms; import algorithms.Classifier; import algorithms.MotionLoaderJointCoordinates; import executor.MotionLoaderJointCoordinates; import java.util.ArrayList; import java.util.List; import objects.Axis; ... ...
 package methods; package algorithms; import algorithms.Classifier; import algorithms.MotionLoaderJointCoordinates; import executor.MotionLoaderJointCoordinates; import java.util.ArrayList; import java.util.List; import objects.Axis; ... ...
 package methods; package algorithms; import algorithms.Classifier; import algorithms.MotionLoaderJointCoordinates; import executor.MotionLoaderJointCoordinates; import java.util.ArrayList; import java.util.List; import objects.Axis; import objects.Feature; import objects.Motion; import objects.MotionJointCoordinates; import objects.Sample; public class MethodJiangS extends Method { ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!