List of usage examples for org.apache.commons.math3.linear RealVector getEntry
public abstract double getEntry(int index) throws OutOfRangeException;
From source file:org.lambda3.indra.core.function.CityBlockRelatednessFunction.java
@Override public double sim(RealVector r1, RealVector r2, boolean sparse) { if (r1.getDimension() != r2.getDimension()) { return 0; }/*from www . j a va 2s . com*/ double sum = 0.0; for (int i = 0; i < r1.getDimension(); ++i) { sum += Math.abs((r1.getEntry(i) - r2.getEntry(i))); } double result = 1 / (1 + (sum == Double.NaN ? 0 : sum)); return Math.abs(result); }
From source file:org.lambda3.indra.core.function.DiceRelatednessFunction.java
@Override public double sim(RealVector r1, RealVector r2, boolean sparse) { if (r1.getDimension() != r2.getDimension()) { return 0; }/*from w ww .j av a 2 s.c o m*/ double min = 0.0; double sum = 0.0; for (int i = 0; i < r1.getDimension(); ++i) { if (r1.getEntry(i) > r2.getEntry(i)) { min += r2.getEntry(i); } else { min += r1.getEntry(i); } sum += r1.getEntry(i) + r2.getEntry(i); } if (sum == 0) { return 0; } double result = 2 * min / sum; return Math.abs(result); }
From source file:org.lambda3.indra.core.function.Jaccard2RelatednessFunction.java
@Override public double sim(RealVector r1, RealVector r2, boolean sparse) { if (r1.getDimension() != r2.getDimension()) { return 0; }/*from w ww. j a va 2 s. c om*/ double min = 0.0; double max = 0.0; for (int i = 0; i < r1.getDimension(); ++i) { if (r1.getEntry(i) > r2.getEntry(i)) { min += r2.getEntry(i); max += r1.getEntry(i); } else { min += r1.getEntry(i); max += r2.getEntry(i); } } if (max == 0) { return 0; } return Math.abs(min / max); }
From source file:org.lambda3.indra.core.function.JensenShannonRelatednessFunction.java
@Override public double sim(RealVector r1, RealVector r2, boolean sparse) { if (r1.getDimension() != r2.getDimension()) { return 0; }/* w w w.j a v a 2s . c om*/ double divergence = 0.0; double avr = 0.0; for (int i = 0; i < r1.getDimension(); ++i) { avr = (r1.getEntry(i) + r2.getEntry(i)) / 2; if (r1.getEntry(i) > 0.0 && avr > 0.0) { divergence += r1.getEntry(i) * Math.log(r1.getEntry(i) / avr); } } for (int i = 0; i < r2.getDimension(); ++i) { avr = (r1.getEntry(i) + r2.getEntry(i)) / 2; if (r2.getEntry(i) > 0.0 && avr > 0.0) { divergence += r1.getEntry(i) * Math.log(r2.getEntry(i) / avr); } } double result = 1 - (divergence / (2 * Math.sqrt(2 * Math.log(2)))); return Math.abs(result); }
From source file:org.lambda3.indra.core.impl.AlphaSkewClient.java
@Override protected double sim(RealVector r1, RealVector r2, boolean sparse) { if (r1.getDimension() != r2.getDimension()) { return 0; }/*from ww w .ja v a 2s . co m*/ double alpha = 0.99; double divergence = 0.0; for (int i = 0; i < r1.getDimension(); ++i) { if (r1.getEntry(i) > 0.0 && r2.getEntry(i) > 0.0) { divergence += r1.getEntry(i) * Math.log(r1.getEntry(i) / ((1 - alpha) * r1.getEntry(i) + alpha * r2.getEntry(i))); } } double result = (1 - (divergence / Math.sqrt(2 * Math.log(2)))); return Math.abs(result); }
From source file:org.lambda3.indra.core.impl.ChebyshevClient.java
@Override protected double sim(RealVector r1, RealVector r2, boolean sparse) { if (r1.getDimension() != r2.getDimension()) { return 0; }//from w w w .j ava 2 s. com double max = 0; double tmp; for (int i = 0; i < r1.getDimension(); ++i) { tmp = Math.abs((r1.getEntry(i) - r2.getEntry(i))); max = (tmp > max ? tmp : max); } double result = 1 / (1 + (max == Double.NaN ? 0 : max)); return Math.abs(result); }
From source file:org.lambda3.indra.core.impl.CityBlockClient.java
@Override protected double sim(RealVector r1, RealVector r2, boolean sparse) { if (r1.getDimension() != r2.getDimension()) { return 0; }//ww w. j a v a 2 s .com double sum = 0.0; for (int i = 0; i < r1.getDimension(); ++i) { sum += Math.abs((r1.getEntry(i) - r2.getEntry(i))); } double result = 1 / (1 + (sum == Double.NaN ? 0 : sum)); return Math.abs(result); }
From source file:org.lambda3.indra.core.impl.DiceClient.java
@Override protected double sim(RealVector r1, RealVector r2, boolean sparse) { if (r1.getDimension() != r2.getDimension()) { return 0; }//w w w. j av a2s. c om double min = 0.0; double sum = 0.0; for (int i = 0; i < r1.getDimension(); ++i) { if (r1.getEntry(i) > r2.getEntry(i)) { min += r2.getEntry(i); } else { min += r1.getEntry(i); } sum += r1.getEntry(i) + r2.getEntry(i); } if (sum == 0) { return 0; } double result = 2 * min / sum; return Math.abs(result); }
From source file:org.lambda3.indra.core.impl.Jaccard2Client.java
@Override protected double sim(RealVector r1, RealVector r2, boolean sparse) { if (r1.getDimension() != r2.getDimension()) { return 0; }//w w w . j av a 2 s. c o m double min = 0.0; double max = 0.0; for (int i = 0; i < r1.getDimension(); ++i) { if (r1.getEntry(i) > r2.getEntry(i)) { min += r2.getEntry(i); max += r1.getEntry(i); } else { min += r1.getEntry(i); max += r2.getEntry(i); } } if (max == 0) { return 0; } return Math.abs(min / max); }
From source file:org.lambda3.indra.core.impl.JensenShannonClient.java
@Override protected double sim(RealVector r1, RealVector r2, boolean sparse) { if (r1.getDimension() != r2.getDimension()) { return 0; }/* ww w. jav a 2 s.co m*/ double divergence = 0.0; double avr = 0.0; for (int i = 0; i < r1.getDimension(); ++i) { avr = (r1.getEntry(i) + r2.getEntry(i)) / 2; if (r1.getEntry(i) > 0.0 && avr > 0.0) { divergence += r1.getEntry(i) * Math.log(r1.getEntry(i) / avr); } } for (int i = 0; i < r2.getDimension(); ++i) { avr = (r1.getEntry(i) + r2.getEntry(i)) / 2; if (r2.getEntry(i) > 0.0 && avr > 0.0) { divergence += r1.getEntry(i) * Math.log(r2.getEntry(i) / avr); } } double result = 1 - (divergence / (2 * Math.sqrt(2 * Math.log(2)))); return Math.abs(result); }