You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sr...@apache.org on 2010/08/17 19:34:19 UTC
svn commit: r986405 [5/6] - in /mahout/trunk: buildtools/
buildtools/src/main/resources/
core/src/main/java/org/apache/mahout/cf/taste/eval/
core/src/main/java/org/apache/mahout/cf/taste/hadoop/
core/src/main/java/org/apache/mahout/cf/taste/hadoop/item...
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java Tue Aug 17 17:34:14 2010
@@ -58,16 +58,19 @@ public class HebbianSolver {
/**
* Creates a new HebbianSolver
*
- * @param updater {@link EigenUpdater} used to do the actual work of iteratively updating the current "best guess"
- * singular vector one data-point presentation at a time.
- * @param verifier {@link SingularVectorVerifier } an object which perpetually tries to check how close to
- * convergence the current singular vector is (typically is a {@link org.apache.mahout.math.decomposer.AsyncEigenVerifier } which does this
- * in the background in another thread, while the main thread continues to converge)
+ * @param updater
+ * {@link EigenUpdater} used to do the actual work of iteratively updating the current "best guess"
+ * singular vector one data-point presentation at a time.
+ * @param verifier
+ * {@link SingularVectorVerifier } an object which perpetually tries to check how close to
+ * convergence the current singular vector is (typically is a
+ * {@link org.apache.mahout.math.decomposer.AsyncEigenVerifier } which does this
+ * in the background in another thread, while the main thread continues to converge)
* @param convergenceTarget a small "epsilon" value which tells the solver how small you want the cosine of the
- * angle between a proposed eigenvector and that same vector after being multiplied by the (square of the) input
- * corpus
+ * angle between a proposed eigenvector and that same vector after being multiplied by the (square of the) input
+ * corpus
* @param maxPassesPerEigen a cutoff which tells the solver after how many times of checking for convergence (done
- * by the verifier) should the solver stop trying, even if it has not reached the convergenceTarget.
+ * by the verifier) should the solver stop trying, even if it has not reached the convergenceTarget.
*/
public HebbianSolver(EigenUpdater updater,
SingularVectorVerifier verifier,
@@ -81,17 +84,20 @@ public class HebbianSolver {
/**
* Creates a new HebbianSolver with maxPassesPerEigen = Integer.MAX_VALUE (i.e. keep on iterating until
- * convergenceTarget is reached). <b>Not recommended</b> unless only looking for the first few (5, maybe 10?) singular
+ * convergenceTarget is reached). <b>Not recommended</b> unless only looking for
+ * the first few (5, maybe 10?) singular
* vectors, as small errors which compound early on quickly put a minimum error on subsequent vectors.
*
- * @param updater {@link EigenUpdater} used to do the actual work of iteratively updating the current "best guess"
- * singular vector one data-point presentation at a time.
- * @param verifier {@link org.apache.mahout.math.decomposer.SingularVectorVerifier } an object which perpetually tries to check how close to
- * convergence the current singular vector is (typically is a {@link org.apache.mahout.math.decomposer.AsyncEigenVerifier } which does this
- * in the background in another thread, while the main thread continues to converge)
+ * @param updater {@link EigenUpdater} used to do the actual work of iteratively updating the current "best guess"
+ * singular vector one data-point presentation at a time.
+ * @param verifier {@link org.apache.mahout.math.decomposer.SingularVectorVerifier }
+ * an object which perpetually tries to check how close to
+ * convergence the current singular vector is (typically is a
+ * {@link org.apache.mahout.math.decomposer.AsyncEigenVerifier } which does this
+ * in the background in another thread, while the main thread continues to converge)
* @param convergenceTarget a small "epsilon" value which tells the solver how small you want the cosine of the
- * angle between a proposed eigenvector and that same vector after being multiplied by the (square of the) input
- * corpus
+ * angle between a proposed eigenvector and that same vector after being multiplied by the (square of the) input
+ * corpus
*/
public HebbianSolver(EigenUpdater updater,
SingularVectorVerifier verifier,
@@ -105,13 +111,14 @@ public class HebbianSolver {
/**
* <b>This is the recommended constructor to use if you're not sure</b>
* Creates a new HebbianSolver with the default {@link HebbianUpdater } to do the updating work, and the default
- * {@link org.apache.mahout.math.decomposer.AsyncEigenVerifier } to check for convergence in a (single) background thread.
+ * {@link org.apache.mahout.math.decomposer.AsyncEigenVerifier } to check for convergence in a
+ * (single) background thread.
*
* @param convergenceTarget a small "epsilon" value which tells the solver how small you want the cosine of the
- * angle between a proposed eigenvector and that same vector after being multiplied by the (square of the) input
- * corpus
+ * angle between a proposed eigenvector and that same vector after being multiplied by the (square of the) input
+ * corpus
* @param maxPassesPerEigen a cutoff which tells the solver after how many times of checking for convergence (done
- * by the verifier) should the solver stop trying, even if it has not reached the convergenceTarget.
+ * by the verifier) should the solver stop trying, even if it has not reached the convergenceTarget.
*/
public HebbianSolver(double convergenceTarget, int maxPassesPerEigen) {
this(new HebbianUpdater(),
@@ -122,13 +129,15 @@ public class HebbianSolver {
/**
* Creates a new HebbianSolver with the default {@link HebbianUpdater } to do the updating work, and the default
- * {@link org.apache.mahout.math.decomposer.AsyncEigenVerifier } to check for convergence in a (single) background thread, with
- * maxPassesPerEigen set to Integer.MAX_VALUE. <b>Not recommended</b> unless only looking for the first few (5, maybe 10?) singular
+ * {@link org.apache.mahout.math.decomposer.AsyncEigenVerifier } to check for convergence in a (single)
+ * background thread, with
+ * maxPassesPerEigen set to Integer.MAX_VALUE. <b>Not recommended</b> unless only looking
+ * for the first few (5, maybe 10?) singular
* vectors, as small errors which compound early on quickly put a minimum error on subsequent vectors.
*
* @param convergenceTarget a small "epsilon" value which tells the solver how small you want the cosine of the
- * angle between a proposed eigenvector and that same vector after being multiplied by the (square of the) input
- * corpus
+ * angle between a proposed eigenvector and that same vector after being multiplied by the (square of the) input
+ * corpus
*/
public HebbianSolver(double convergenceTarget) {
this(convergenceTarget, Integer.MAX_VALUE);
@@ -136,7 +145,8 @@ public class HebbianSolver {
/**
* Creates a new HebbianSolver with the default {@link HebbianUpdater } to do the updating work, and the default
- * {@link org.apache.mahout.math.decomposer.AsyncEigenVerifier } to check for convergence in a (single) background thread, with
+ * {@link org.apache.mahout.math.decomposer.AsyncEigenVerifier } to check for convergence in a (single)
+ * background thread, with
* convergenceTarget set to 0, which means that the solver will not really care about convergence as a loop-exiting
* criterion (but will be checking for convergence anyways, so it will be logged and singular values will be
* saved).
@@ -151,9 +161,9 @@ public class HebbianSolver {
/**
* Primary singular vector solving method.
*
- * @param corpus input matrix to find singular vectors of. Needs not be symmetric, should probably be sparse (in
- * fact the input vectors are not mutated, and accessed only via dot-products and sums, so they should be
- * {@link org.apache.mahout.math.SequentialAccessSparseVector }
+ * @param corpus input matrix to find singular vectors of. Needs not be symmetric, should probably be sparse (in
+ * fact the input vectors are not mutated, and accessed only via dot-products and sums, so they should be
+ * {@link org.apache.mahout.math.SequentialAccessSparseVector }
* @param desiredRank the number of singular vectors to find (in roughly decreasing order by singular value)
* @return the final {@link TrainingState } of the solver, after desiredRank singular vectors (and approximate
* singular values) have been found.
@@ -248,7 +258,7 @@ public class HebbianSolver {
*
* @param currentPseudoEigen the purported singular vector whose convergence is being checked
* @param corpus the corpus to check against
- * @param state contains the previous eigens, various other solving state {@see TrainingState }
+ * @param state contains the previous eigens, various other solving state {@link TrainingState}
* @return true if <em>either</em> we have converged, <em>or</em> maxPassesPerEigen has been exceeded.
*/
protected boolean hasNotConverged(Vector currentPseudoEigen,
@@ -329,4 +339,5 @@ public class HebbianSolver {
new Object[] {finalState.getCurrentEigens().size()[AbstractMatrix.ROW], time, outputDir});
}
+
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosSolver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosSolver.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosSolver.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosSolver.java Tue Aug 17 17:34:14 2010
@@ -200,7 +200,7 @@ public class LanczosSolver {
if (v == null) {
v = new DenseVector(vector.size()).plus(vector);
} else {
- v.assign(vector, plus);
+ v.assign(vector, PLUS);
}
}
v.assign(div(v.norm(2)));
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/function/Functions.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/Functions.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/function/Functions.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/function/Functions.java Tue Aug 17 17:34:14 2010
@@ -109,35 +109,35 @@ public class Functions {
* <H3>Unary functions</H3>
*/
/** Function that returns <tt>Math.abs(a)</tt>. */
- public static final UnaryFunction abs = new UnaryFunction() {
+ public static final UnaryFunction ABS = new UnaryFunction() {
public double apply(double a) {
return Math.abs(a);
}
};
/** Function that returns <tt>Math.acos(a)</tt>. */
- public static final UnaryFunction acos = new UnaryFunction() {
+ public static final UnaryFunction ACOS = new UnaryFunction() {
public double apply(double a) {
return Math.acos(a);
}
};
/** Function that returns <tt>Math.asin(a)</tt>. */
- public static final UnaryFunction asin = new UnaryFunction() {
+ public static final UnaryFunction ASIN = new UnaryFunction() {
public double apply(double a) {
return Math.asin(a);
}
};
/** Function that returns <tt>Math.atan(a)</tt>. */
- public static final UnaryFunction atan = new UnaryFunction() {
+ public static final UnaryFunction ATAN = new UnaryFunction() {
public double apply(double a) {
return Math.atan(a);
}
};
/** Function that returns <tt>Math.ceil(a)</tt>. */
- public static final UnaryFunction ceil = new UnaryFunction() {
+ public static final UnaryFunction CEIL = new UnaryFunction() {
public double apply(double a) {
return Math.ceil(a);
@@ -145,7 +145,7 @@ public class Functions {
};
/** Function that returns <tt>Math.cos(a)</tt>. */
- public static final UnaryFunction cos = new UnaryFunction() {
+ public static final UnaryFunction COS = new UnaryFunction() {
public double apply(double a) {
return Math.cos(a);
@@ -153,7 +153,7 @@ public class Functions {
};
/** Function that returns <tt>Math.exp(a)</tt>. */
- public static final UnaryFunction exp = new UnaryFunction() {
+ public static final UnaryFunction EXP = new UnaryFunction() {
public double apply(double a) {
return Math.exp(a);
@@ -161,7 +161,7 @@ public class Functions {
};
/** Function that returns <tt>Math.floor(a)</tt>. */
- public static final UnaryFunction floor = new UnaryFunction() {
+ public static final UnaryFunction FLOOR = new UnaryFunction() {
public double apply(double a) {
return Math.floor(a);
@@ -169,7 +169,7 @@ public class Functions {
};
/** Function that returns its argument. */
- public static final UnaryFunction identity = new UnaryFunction() {
+ public static final UnaryFunction IDENTITY = new UnaryFunction() {
public double apply(double a) {
return a;
@@ -177,7 +177,7 @@ public class Functions {
};
/** Function that returns <tt>1.0 / a</tt>. */
- public static final UnaryFunction inv = new UnaryFunction() {
+ public static final UnaryFunction INV = new UnaryFunction() {
public double apply(double a) {
return 1.0 / a;
@@ -185,7 +185,7 @@ public class Functions {
};
/** Function that returns <tt>Math.log(a)</tt>. */
- public static final UnaryFunction logarithm = new UnaryFunction() {
+ public static final UnaryFunction LOGARITHM = new UnaryFunction() {
public double apply(double a) {
return Math.log(a);
@@ -193,7 +193,7 @@ public class Functions {
};
/** Function that returns <tt>Math.log(a) / Math.log(2)</tt>. */
- public static final UnaryFunction log2 = new UnaryFunction() {
+ public static final UnaryFunction LOG2 = new UnaryFunction() {
public double apply(double a) {
return Math.log(a) * 1.4426950408889634;
@@ -201,7 +201,7 @@ public class Functions {
};
/** Function that returns <tt>-a</tt>. */
- public static final UnaryFunction negate = new UnaryFunction() {
+ public static final UnaryFunction NEGATE = new UnaryFunction() {
public double apply(double a) {
return -a;
@@ -209,7 +209,7 @@ public class Functions {
};
/** Function that returns <tt>Math.rint(a)</tt>. */
- public static final UnaryFunction rint = new UnaryFunction() {
+ public static final UnaryFunction RINT = new UnaryFunction() {
public double apply(double a) {
return Math.rint(a);
@@ -217,7 +217,7 @@ public class Functions {
};
/** Function that returns <tt>a < 0 ? -1 : a > 0 ? 1 : 0</tt>. */
- public static final UnaryFunction sign = new UnaryFunction() {
+ public static final UnaryFunction SIGN = new UnaryFunction() {
public double apply(double a) {
return a < 0 ? -1 : a > 0 ? 1 : 0;
@@ -225,7 +225,7 @@ public class Functions {
};
/** Function that returns <tt>Math.sin(a)</tt>. */
- public static final UnaryFunction sin = new UnaryFunction() {
+ public static final UnaryFunction SIN = new UnaryFunction() {
public double apply(double a) {
return Math.sin(a);
@@ -233,7 +233,7 @@ public class Functions {
};
/** Function that returns <tt>Math.sqrt(a)</tt>. */
- public static final UnaryFunction sqrt = new UnaryFunction() {
+ public static final UnaryFunction SQRT = new UnaryFunction() {
public double apply(double a) {
return Math.sqrt(a);
@@ -241,7 +241,7 @@ public class Functions {
};
/** Function that returns <tt>a * a</tt>. */
- public static final UnaryFunction square = new UnaryFunction() {
+ public static final UnaryFunction SQUARE = new UnaryFunction() {
public double apply(double a) {
return a * a;
@@ -249,7 +249,7 @@ public class Functions {
};
/** Function that returns <tt>Math.tan(a)</tt>. */
- public static final UnaryFunction tan = new UnaryFunction() {
+ public static final UnaryFunction TAN = new UnaryFunction() {
public double apply(double a) {
return Math.tan(a);
@@ -262,7 +262,7 @@ public class Functions {
*/
/** Function that returns <tt>Math.atan2(a,b)</tt>. */
- public static final BinaryFunction atan2 = new BinaryFunction() {
+ public static final BinaryFunction ATAN2 = new BinaryFunction() {
public double apply(double a, double b) {
return Math.atan2(a, b);
@@ -270,7 +270,7 @@ public class Functions {
};
/** Function that returns <tt>a < b ? -1 : a > b ? 1 : 0</tt>. */
- public static final BinaryFunction compare = new BinaryFunction() {
+ public static final BinaryFunction COMPARE = new BinaryFunction() {
public double apply(double a, double b) {
return a < b ? -1 : a > b ? 1 : 0;
@@ -278,7 +278,7 @@ public class Functions {
};
/** Function that returns <tt>a / b</tt>. */
- public static final BinaryFunction div = new BinaryFunction() {
+ public static final BinaryFunction DIV = new BinaryFunction() {
public double apply(double a, double b) {
return a / b;
@@ -286,7 +286,7 @@ public class Functions {
};
/** Function that returns <tt>a == b ? 1 : 0</tt>. */
- public static final BinaryFunction equals = new BinaryFunction() {
+ public static final BinaryFunction EQUALS = new BinaryFunction() {
public double apply(double a, double b) {
return a == b ? 1 : 0;
@@ -294,7 +294,7 @@ public class Functions {
};
/** Function that returns <tt>a > b ? 1 : 0</tt>. */
- public static final BinaryFunction greater = new BinaryFunction() {
+ public static final BinaryFunction GREATER = new BinaryFunction() {
public double apply(double a, double b) {
return a > b ? 1 : 0;
@@ -302,7 +302,7 @@ public class Functions {
};
/** Function that returns <tt>Math.IEEEremainder(a,b)</tt>. */
- public static final BinaryFunction IEEEremainder = new BinaryFunction() {
+ public static final BinaryFunction IEEE_REMAINDER = new BinaryFunction() {
public double apply(double a, double b) {
return Math.IEEEremainder(a, b);
@@ -310,7 +310,7 @@ public class Functions {
};
/** Function that returns <tt>a == b</tt>. */
- public static final DoubleDoubleProcedure isEqual = new DoubleDoubleProcedure() {
+ public static final DoubleDoubleProcedure IS_EQUAL = new DoubleDoubleProcedure() {
public boolean apply(double a, double b) {
return a == b;
@@ -318,7 +318,7 @@ public class Functions {
};
/** Function that returns <tt>a < b</tt>. */
- public static final DoubleDoubleProcedure isLess = new DoubleDoubleProcedure() {
+ public static final DoubleDoubleProcedure IS_LESS = new DoubleDoubleProcedure() {
public boolean apply(double a, double b) {
return a < b;
@@ -326,7 +326,7 @@ public class Functions {
};
/** Function that returns <tt>a > b</tt>. */
- public static final DoubleDoubleProcedure isGreater = new DoubleDoubleProcedure() {
+ public static final DoubleDoubleProcedure IS_GREATER = new DoubleDoubleProcedure() {
public boolean apply(double a, double b) {
return a > b;
@@ -334,7 +334,7 @@ public class Functions {
};
/** Function that returns <tt>a < b ? 1 : 0</tt>. */
- public static final BinaryFunction less = new BinaryFunction() {
+ public static final BinaryFunction LESS = new BinaryFunction() {
public double apply(double a, double b) {
return a < b ? 1 : 0;
@@ -342,7 +342,7 @@ public class Functions {
};
/** Function that returns <tt>Math.log(a) / Math.log(b)</tt>. */
- public static final BinaryFunction lg = new BinaryFunction() {
+ public static final BinaryFunction LG = new BinaryFunction() {
public double apply(double a, double b) {
return Math.log(a) / Math.log(b);
@@ -350,7 +350,7 @@ public class Functions {
};
/** Function that returns <tt>Math.max(a,b)</tt>. */
- public static final BinaryFunction max = new BinaryFunction() {
+ public static final BinaryFunction MAX = new BinaryFunction() {
public double apply(double a, double b) {
return Math.max(a, b);
@@ -358,7 +358,7 @@ public class Functions {
};
/** Function that returns <tt>Math.min(a,b)</tt>. */
- public static final BinaryFunction min = new BinaryFunction() {
+ public static final BinaryFunction MIN = new BinaryFunction() {
public double apply(double a, double b) {
return Math.min(a, b);
@@ -366,7 +366,7 @@ public class Functions {
};
/** Function that returns <tt>a - b</tt>. */
- public static final BinaryFunction minus = plusMult(-1);
+ public static final BinaryFunction MINUS = plusMult(-1);
/*
new BinaryFunction() {
public final double apply(double a, double b) { return a - b; }
@@ -374,7 +374,7 @@ public class Functions {
*/
/** Function that returns <tt>a % b</tt>. */
- public static final BinaryFunction mod = new BinaryFunction() {
+ public static final BinaryFunction MOD = new BinaryFunction() {
public double apply(double a, double b) {
return a % b;
@@ -382,7 +382,7 @@ public class Functions {
};
/** Function that returns <tt>a * b</tt>. */
- public static final BinaryFunction mult = new BinaryFunction() {
+ public static final BinaryFunction MULT = new BinaryFunction() {
public double apply(double a, double b) {
return a * b;
@@ -390,7 +390,7 @@ public class Functions {
};
/** Function that returns <tt>a + b</tt>. */
- public static final BinaryFunction plus = new BinaryFunction() {
+ public static final BinaryFunction PLUS = new BinaryFunction() {
public double apply(double a, double b) {
return a + b;
@@ -398,7 +398,7 @@ public class Functions {
};
/** Function that returns <tt>Math.abs(a) + Math.abs(b)</tt>. */
- public static final BinaryFunction plusAbs = new BinaryFunction() {
+ public static final BinaryFunction PLUS_ABS = new BinaryFunction() {
public double apply(double a, double b) {
return Math.abs(a) + Math.abs(b);
@@ -406,7 +406,7 @@ public class Functions {
};
/** Function that returns <tt>Math.pow(a,b)</tt>. */
- public static final BinaryFunction pow = new BinaryFunction() {
+ public static final BinaryFunction POW = new BinaryFunction() {
public double apply(double a, double b) {
return Math.pow(a, b);
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/function/VectorFunctions.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/VectorFunctions.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/function/VectorFunctions.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/function/VectorFunctions.java Tue Aug 17 17:34:14 2010
@@ -44,7 +44,7 @@ public class VectorFunctions {
public static VectorFunction max() {
return new VectorFunction() {
public double apply(Vector f) {
- return f.aggregate(Functions.max, Functions.identity);
+ return f.aggregate(Functions.MAX, Functions.IDENTITY);
}
};
}
@@ -52,7 +52,7 @@ public class VectorFunctions {
public static VectorFunction min() {
return new VectorFunction() {
public double apply(Vector f) {
- return f.aggregate(Functions.min, Functions.identity);
+ return f.aggregate(Functions.MIN, Functions.IDENTITY);
}
};
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Descriptive.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Descriptive.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Descriptive.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Descriptive.java Tue Aug 17 17:34:14 2010
@@ -215,7 +215,6 @@ public class Descriptive {
* as follows <ul> <li><tt>inOut[0] = Double.POSITIVE_INFINITY</tt> as the old minimum. <li><tt>inOut[1]
* = Double.NEGATIVE_INFINITY</tt> as the old maximum. <li><tt>inOut[2] = 0.0</tt> as the old sum.
* <li><tt>inOut[3] = 0.0</tt> as the old sum of squares. </ul>
- * @return the updated values filled into the <tt>inOut</tt> array.
*/
public static void incrementalUpdate(DoubleArrayList data, int from, int to, double[] inOut) {
checkRangeFromTo(from, to, data.size());
@@ -289,7 +288,6 @@ public class Descriptive {
* <tt>Sum(data[i]<sup>fromSumIndex+1</sup>)</tt>. <li>... <li><tt>sumOfPowers[toSumIndex-fromSumIndex]</tt>
* is the old <tt>Sum(data[i]<sup>toSumIndex</sup>)</tt>. </ul> If no data sequence elements have
* so far been recorded set all old values of the sums to <tt>0.0</tt>.
- * @return the updated values filled into the <tt>sumOfPowers</tt> array.
*/
public static void incrementalUpdateSumsOfPowers(DoubleArrayList data, int from, int to, int fromSumIndex,
int toSumIndex, double[] sumOfPowers) {
@@ -402,7 +400,6 @@ public class Descriptive {
* <li><tt>inOut[1]</tt> is the old sum of squares. </ul> If no data sequence elements have so far been
* recorded set the values as follows <ul> <li><tt>inOut[0] = 0.0</tt> as the old sum. <li><tt>inOut[1]
* = 0.0</tt> as the old sum of squares. </ul>
- * @return the updated values filled into the <tt>inOut</tt> array.
*/
public static void incrementalWeightedUpdate(DoubleArrayList data, DoubleArrayList weights, int from, int to,
double[] inOut) {
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/UnknownDoubleQuantileEstimator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/UnknownDoubleQuantileEstimator.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/UnknownDoubleQuantileEstimator.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/UnknownDoubleQuantileEstimator.java Tue Aug 17 17:34:14 2010
@@ -197,9 +197,15 @@ class UnknownDoubleQuantileEstimator ext
/** Returns a String representation of the receiver. */
public String toString() {
- StringBuffer buf = new StringBuffer(super.toString());
+ StringBuilder buf = new StringBuilder(super.toString());
buf.setLength(buf.length() - 1);
- return buf + ", h=" + currentTreeHeight + ", hStartSampling=" + treeHeightStartingSampling +
- ", precomputeEpsilon=" + precomputeEpsilon + ')';
+ buf.append(", h=");
+ buf.append(currentTreeHeight);
+ buf.append(", hStartSampling=");
+ buf.append(treeHeightStartingSampling);
+ buf.append(", precomputeEpsilon=");
+ buf.append(precomputeEpsilon);
+ buf.append(')');
+ return buf.toString();
}
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/Utils.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/Utils.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/Utils.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/Utils.java Tue Aug 17 17:34:14 2010
@@ -9,14 +9,13 @@ It is provided "as is" without expressed
package org.apache.mahout.math.jet.stat.quantile;
/** Holds some utility methods shared by different quantile finding implementations. */
-class Utils {
+final class Utils {
private Utils() {
}
/** Similar to Math.ceil(value), but adjusts small numerical rounding errors +- epsilon. */
public static long epsilonCeiling(double value) {
- double epsilon = 0.0000001;
- return (long) Math.ceil(value - epsilon);
+ return (long) Math.ceil(value - 0.0000001);
}
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleFactory1D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleFactory1D.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleFactory1D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleFactory1D.java Tue Aug 17 17:34:14 2010
@@ -45,7 +45,7 @@ public class DoubleFactory1D extends Per
/** Constructs a matrix with cells having ascending values. For debugging purposes. Example: <tt>0 1 2</tt> */
public DoubleMatrix1D ascending(int size) {
- return descending(size).assign(Functions.chain(Functions.negate, Functions.minus(size)));
+ return descending(size).assign(Functions.chain(Functions.NEGATE, Functions.minus(size)));
}
/** Constructs a matrix with cells having descending values. For debugging purposes. Example: <tt>2 1 0</tt> */
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleFactory2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleFactory2D.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleFactory2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleFactory2D.java Tue Aug 17 17:34:14 2010
@@ -176,7 +176,7 @@ public class DoubleFactory2D extends Per
* </pre>
*/
public DoubleMatrix2D ascending(int rows, int columns) {
- return descending(rows, columns).assign(Functions.chain(Functions.negate, Functions.minus(columns * rows)));
+ return descending(rows, columns).assign(Functions.chain(Functions.NEGATE, Functions.minus(columns * rows)));
}
/**
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleFactory3D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleFactory3D.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleFactory3D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleFactory3D.java Tue Aug 17 17:34:14 2010
@@ -30,7 +30,7 @@ public class DoubleFactory3D extends Per
/** Constructs a matrix with cells having ascending values. For debugging purposes. */
public DoubleMatrix3D ascending(int slices, int rows, int columns) {
return descending(slices, rows, columns)
- .assign(Functions.chain(Functions.negate, Functions.minus(slices * rows * columns)));
+ .assign(Functions.chain(Functions.NEGATE, Functions.minus(slices * rows * columns)));
}
/** Constructs a matrix with cells having descending values. For debugging purposes. */
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java Tue Aug 17 17:34:14 2010
@@ -237,7 +237,7 @@ public abstract class DoubleMatrix1D ext
int[] nonZeroElements = nonZeroIndexes.elements();
// specialized for speed
- if (function == Functions.mult) { // x[i] = x[i] * y[i]
+ if (function == Functions.MULT) { // x[i] = x[i] * y[i]
int j = 0;
for (int index = nonZeroIndexes.size(); --index >= 0;) {
int i = nonZeroElements[index];
@@ -858,6 +858,6 @@ public abstract class DoubleMatrix1D ext
if (size() == 0) {
return 0;
}
- return aggregate(Functions.plus, Functions.identity);
+ return aggregate(Functions.PLUS, Functions.IDENTITY);
}
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java Tue Aug 17 17:34:14 2010
@@ -980,6 +980,6 @@ public abstract class DoubleMatrix2D ext
if (size() == 0) {
return 0;
}
- return aggregate(Functions.plus, Functions.identity);
+ return aggregate(Functions.PLUS, Functions.IDENTITY);
}
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix3D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix3D.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix3D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix3D.java Tue Aug 17 17:34:14 2010
@@ -988,6 +988,6 @@ public abstract class DoubleMatrix3D ext
if (size() == 0) {
return 0;
}
- return aggregate(Functions.plus, Functions.identity);
+ return aggregate(Functions.PLUS, Functions.IDENTITY);
}
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/doublealgo/Statistic.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/doublealgo/Statistic.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/doublealgo/Statistic.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/doublealgo/Statistic.java Tue Aug 17 17:34:14 2010
@@ -25,15 +25,15 @@ public class Statistic {
/** Euclidean distance function; <tt>Sqrt(Sum( (x[i]-y[i])^2 ))</tt>. */
public static final VectorVectorFunction EUCLID = new VectorVectorFunction() {
public double apply(DoubleMatrix1D a, DoubleMatrix1D b) {
- return Math.sqrt(a.aggregate(b, Functions.plus, Functions.chain(Functions.square, Functions.minus)));
+ return Math.sqrt(a.aggregate(b, Functions.PLUS, Functions.chain(Functions.SQUARE, Functions.MINUS)));
}
};
/** Bray-Curtis distance function; <tt>Sum( abs(x[i]-y[i]) ) / Sum( x[i]+y[i] )</tt>. */
public static final VectorVectorFunction BRAY_CURTIS = new VectorVectorFunction() {
public double apply(DoubleMatrix1D a, DoubleMatrix1D b) {
- return a.aggregate(b, Functions.plus, Functions.chain(Functions.abs, Functions.minus)) /
- a.aggregate(b, Functions.plus, Functions.plus);
+ return a.aggregate(b, Functions.PLUS, Functions.chain(Functions.ABS, Functions.MINUS)) /
+ a.aggregate(b, Functions.PLUS, Functions.PLUS);
}
};
@@ -46,21 +46,21 @@ public class Statistic {
};
public double apply(DoubleMatrix1D a, DoubleMatrix1D b) {
- return a.aggregate(b, Functions.plus, fun);
+ return a.aggregate(b, Functions.PLUS, fun);
}
};
/** Maximum distance function; <tt>Max( abs(x[i]-y[i]) )</tt>. */
public static final VectorVectorFunction MAXIMUM = new VectorVectorFunction() {
public double apply(DoubleMatrix1D a, DoubleMatrix1D b) {
- return a.aggregate(b, Functions.max, Functions.chain(Functions.abs, Functions.minus));
+ return a.aggregate(b, Functions.MAX, Functions.chain(Functions.ABS, Functions.MINUS));
}
};
/** Manhattan distance function; <tt>Sum( abs(x[i]-y[i]) )</tt>. */
public static final VectorVectorFunction MANHATTAN = new VectorVectorFunction() {
public double apply(DoubleMatrix1D a, DoubleMatrix1D b) {
- return a.aggregate(b, Functions.plus, Functions.chain(Functions.abs, Functions.minus));
+ return a.aggregate(b, Functions.PLUS, Functions.chain(Functions.ABS, Functions.MINUS));
}
};
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/doublealgo/Transform.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/doublealgo/Transform.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/doublealgo/Transform.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/doublealgo/Transform.java Tue Aug 17 17:34:14 2010
@@ -28,7 +28,7 @@ public class Transform extends Persisten
* @return <tt>A</tt> (for convenience only).
*/
public static DoubleMatrix1D abs(DoubleMatrix1D A) {
- return A.assign(Functions.abs);
+ return A.assign(Functions.ABS);
}
/**
@@ -38,7 +38,7 @@ public class Transform extends Persisten
* @return <tt>A</tt> (for convenience only).
*/
public static DoubleMatrix2D abs(DoubleMatrix2D A) {
- return A.assign(Functions.abs);
+ return A.assign(Functions.ABS);
}
/**
@@ -60,7 +60,7 @@ public class Transform extends Persisten
* @return <tt>A</tt> (for convenience only).
*/
public static DoubleMatrix1D div(DoubleMatrix1D A, DoubleMatrix1D B) {
- return A.assign(B, Functions.div);
+ return A.assign(B, Functions.DIV);
}
/**
@@ -82,7 +82,7 @@ public class Transform extends Persisten
* @return <tt>A</tt> (for convenience only).
*/
public static DoubleMatrix2D div(DoubleMatrix2D A, DoubleMatrix2D B) {
- return A.assign(B, Functions.div);
+ return A.assign(B, Functions.DIV);
}
/**
@@ -104,7 +104,7 @@ public class Transform extends Persisten
* @return <tt>A</tt> (for convenience only).
*/
public static DoubleMatrix2D equals(DoubleMatrix2D A, DoubleMatrix2D B) {
- return A.assign(B, Functions.equals);
+ return A.assign(B, Functions.EQUALS);
}
/**
@@ -126,7 +126,7 @@ public class Transform extends Persisten
* @return <tt>A</tt> (for convenience only).
*/
public static DoubleMatrix2D greater(DoubleMatrix2D A, DoubleMatrix2D B) {
- return A.assign(B, Functions.greater);
+ return A.assign(B, Functions.GREATER);
}
/**
@@ -148,7 +148,7 @@ public class Transform extends Persisten
* @return <tt>A</tt> (for convenience only).
*/
public static DoubleMatrix2D less(DoubleMatrix2D A, DoubleMatrix2D B) {
- return A.assign(B, Functions.less);
+ return A.assign(B, Functions.LESS);
}
/**
@@ -170,7 +170,7 @@ public class Transform extends Persisten
* @return <tt>A</tt> (for convenience only).
*/
public static DoubleMatrix1D minus(DoubleMatrix1D A, DoubleMatrix1D B) {
- return A.assign(B, Functions.minus);
+ return A.assign(B, Functions.MINUS);
}
/**
@@ -192,7 +192,7 @@ public class Transform extends Persisten
* @return <tt>A</tt> (for convenience only).
*/
public static DoubleMatrix2D minus(DoubleMatrix2D A, DoubleMatrix2D B) {
- return A.assign(B, Functions.minus);
+ return A.assign(B, Functions.MINUS);
}
/**
@@ -238,7 +238,7 @@ public class Transform extends Persisten
* @return <tt>A</tt> (for convenience only).
*/
public static DoubleMatrix1D mult(DoubleMatrix1D A, DoubleMatrix1D B) {
- return A.assign(B, Functions.mult);
+ return A.assign(B, Functions.MULT);
}
/**
@@ -260,7 +260,7 @@ public class Transform extends Persisten
* @return <tt>A</tt> (for convenience only).
*/
public static DoubleMatrix2D mult(DoubleMatrix2D A, DoubleMatrix2D B) {
- return A.assign(B, Functions.mult);
+ return A.assign(B, Functions.MULT);
}
/**
@@ -300,7 +300,7 @@ public class Transform extends Persisten
* @return <tt>A</tt> (for convenience only).
*/
public static DoubleMatrix1D plus(DoubleMatrix1D A, DoubleMatrix1D B) {
- return A.assign(B, Functions.plus);
+ return A.assign(B, Functions.PLUS);
}
/**
@@ -322,7 +322,7 @@ public class Transform extends Persisten
* @return <tt>A</tt> (for convenience only).
*/
public static DoubleMatrix2D plus(DoubleMatrix2D A, DoubleMatrix2D B) {
- return A.assign(B, Functions.plus);
+ return A.assign(B, Functions.PLUS);
}
/**
@@ -368,7 +368,7 @@ public class Transform extends Persisten
* @return <tt>A</tt> (for convenience only).
*/
public static DoubleMatrix1D pow(DoubleMatrix1D A, DoubleMatrix1D B) {
- return A.assign(B, Functions.pow);
+ return A.assign(B, Functions.POW);
}
/**
@@ -390,6 +390,6 @@ public class Transform extends Persisten
* @return <tt>A</tt> (for convenience only).
*/
public static DoubleMatrix2D pow(DoubleMatrix2D A, DoubleMatrix2D B) {
- return A.assign(B, Functions.pow);
+ return A.assign(B, Functions.POW);
}
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix1D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix1D.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix1D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix1D.java Tue Aug 17 17:34:14 2010
@@ -242,13 +242,13 @@ public class DenseDoubleMatrix1D extends
int otherIndex = other.index(0);
// specialized for speed
- if (function == Functions.mult) { // x[i] = x[i] * y[i]
+ if (function == Functions.MULT) { // x[i] = x[i] * y[i]
for (int k = size; --k >= 0;) {
elems[index] *= otherElems[otherIndex];
index += s;
otherIndex += ys;
}
- } else if (function == Functions.div) { // x[i] = x[i] / y[i]
+ } else if (function == Functions.DIV) { // x[i] = x[i] / y[i]
for (int k = size; --k >= 0;) {
elems[index] /= otherElems[otherIndex];
index += s;
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java Tue Aug 17 17:34:14 2010
@@ -295,7 +295,7 @@ public class DenseDoubleMatrix2D extends
int index = index(0, 0);
// specialized for speed
- if (function == Functions.mult) { // x[i] = x[i] * y[i]
+ if (function == Functions.MULT) { // x[i] = x[i] * y[i]
for (int row = rows; --row >= 0;) {
for (int i = index, j = otherIndex, column = columns; --column >= 0;) {
elems[i] *= otherElems[j];
@@ -305,7 +305,7 @@ public class DenseDoubleMatrix2D extends
index += rs;
otherIndex += ors;
}
- } else if (function == Functions.div) { // x[i] = x[i] / y[i]
+ } else if (function == Functions.DIV) { // x[i] = x[i] / y[i]
for (int row = rows; --row >= 0;) {
for (int i = index, j = otherIndex, column = columns; --column >= 0;) {
elems[i] /= otherElems[j];
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/RCDoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/RCDoubleMatrix2D.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/RCDoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/RCDoubleMatrix2D.java Tue Aug 17 17:34:14 2010
@@ -204,7 +204,7 @@ public class RCDoubleMatrix2D extends Wr
return this;
}
- if (function == Functions.mult) { // x[i] = x[i] * y[i]
+ if (function == Functions.MULT) { // x[i] = x[i] * y[i]
int[] idx = indexes.elements();
double[] vals = values.elements();
@@ -221,7 +221,7 @@ public class RCDoubleMatrix2D extends Wr
return this;
}
- if (function == Functions.div) { // x[i] = x[i] / y[i]
+ if (function == Functions.DIV) { // x[i] = x[i] / y[i]
int[] idx = indexes.elements();
double[] vals = values.elements();
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java Tue Aug 17 17:34:14 2010
@@ -196,7 +196,7 @@ public class SparseDoubleMatrix2D extend
return this;
}
- if (function == Functions.mult) { // x[i] = x[i] * y[i]
+ if (function == Functions.MULT) { // x[i] = x[i] * y[i]
this.elements.forEachPair(
new IntDoubleProcedure() {
public boolean apply(int key, double value) {
@@ -212,7 +212,7 @@ public class SparseDoubleMatrix2D extend
);
}
- if (function == Functions.div) { // x[i] = x[i] / y[i]
+ if (function == Functions.DIV) { // x[i] = x[i] / y[i]
this.elements.forEachPair(
new IntDoubleProcedure() {
public boolean apply(int key, double value) {
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/TridiagonalDoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/TridiagonalDoubleMatrix2D.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/TridiagonalDoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/TridiagonalDoubleMatrix2D.java Tue Aug 17 17:34:14 2010
@@ -32,7 +32,8 @@ class TridiagonalDoubleMatrix2D extends
private final double[] values;
/*
- * The startIndexes and number of non zeros: {lowerStart, diagonalStart, upperStart, values.length, lowerNonZeros, diagonalNonZeros, upperNonZeros}.
+ * The startIndexes and number of non zeros:
+ * {lowerStart, diagonalStart, upperStart, values.length, lowerNonZeros, diagonalNonZeros, upperNonZeros}.
* lowerStart = 0
* diagonalStart = lowerStart + lower.length
* upperStart = diagonalStart + diagonal.length
@@ -203,7 +204,7 @@ class TridiagonalDoubleMatrix2D extends
return this;
}
- if (function == Functions.mult) { // x[i] = x[i] * y[i]
+ if (function == Functions.MULT) { // x[i] = x[i] * y[i]
forEachNonZero(
new IntIntDoubleFunction() {
public double apply(int i, int j, double value) {
@@ -215,7 +216,7 @@ class TridiagonalDoubleMatrix2D extends
return this;
}
- if (function == Functions.div) { // x[i] = x[i] / y[i]
+ if (function == Functions.DIV) { // x[i] = x[i] / y[i]
forEachNonZero(
new IntIntDoubleFunction() {
public double apply(int i, int j, double value) {
@@ -453,10 +454,10 @@ class TridiagonalDoubleMatrix2D extends
}
@Override
- public DoubleMatrix2D zMult(DoubleMatrix2D B, DoubleMatrix2D C, final double alpha, double beta,
+ public DoubleMatrix2D zMult(DoubleMatrix2D b, DoubleMatrix2D c, final double alpha, double beta,
final boolean transposeA, boolean transposeB) {
if (transposeB) {
- B = B.viewDice();
+ b = b.viewDice();
}
int m = rows;
int n = columns;
@@ -464,37 +465,36 @@ class TridiagonalDoubleMatrix2D extends
m = columns;
n = rows;
}
- int p = B.columns;
- boolean ignore = (C == null);
- if (C == null) {
- C = new DenseDoubleMatrix2D(m, p);
+ int p = b.columns;
+ boolean ignore = c == null;
+ if (ignore) {
+ c = new DenseDoubleMatrix2D(m, p);
}
- if (B.rows != n) {
- throw new IllegalArgumentException("Matrix2D inner dimensions must agree:" + toStringShort() + ", " +
- (transposeB ? B.viewDice() : B).toStringShort());
+ if (b.rows != n) {
+ throw new IllegalArgumentException("Matrix2D inner dimensions must agree:"
+ + toStringShort() + ", " + (transposeB ? b.viewDice() : b).toStringShort());
}
- if (C.rows != m || C.columns != p) {
- throw new IllegalArgumentException(
- "Incompatibel result matrix: " + toStringShort() + ", " + (transposeB ? B.viewDice() : B).toStringShort() +
- ", " + C.toStringShort());
+ if (c.rows != m || c.columns != p) {
+ throw new IllegalArgumentException("Incompatibel result matrix: " + toStringShort()
+ + ", " + (transposeB ? b.viewDice() : b).toStringShort() + ", " + c.toStringShort());
}
- if (this == C || B == C) {
+ if (this == c || b == c) {
throw new IllegalArgumentException("Matrices must not be identical");
}
if (!ignore) {
- C.assign(Functions.mult(beta));
+ c.assign(Functions.mult(beta));
}
// cache views
- final DoubleMatrix1D[] Brows = new DoubleMatrix1D[n];
+ final DoubleMatrix1D[] bRows = new DoubleMatrix1D[n];
for (int i = n; --i >= 0;) {
- Brows[i] = B.viewRow(i);
+ bRows[i] = b.viewRow(i);
}
- final DoubleMatrix1D[] Crows = new DoubleMatrix1D[m];
+ final DoubleMatrix1D[] cRows = new DoubleMatrix1D[m];
for (int i = m; --i >= 0;) {
- Crows[i] = C.viewRow(i);
+ cRows[i] = c.viewRow(i);
}
final PlusMult fun = PlusMult.plusMult(0);
@@ -503,16 +503,16 @@ class TridiagonalDoubleMatrix2D extends
new IntIntDoubleFunction() {
public double apply(int i, int j, double value) {
fun.setMultiplicator(value * alpha);
- if (!transposeA) {
- Crows[i].assign(Brows[j], fun);
+ if (transposeA) {
+ cRows[j].assign(bRows[i], fun);
} else {
- Crows[j].assign(Brows[i], fun);
+ cRows[i].assign(bRows[j], fun);
}
return value;
}
}
);
- return C;
+ return c;
}
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Algebra.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Algebra.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Algebra.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Algebra.java Tue Aug 17 17:34:14 2010
@@ -10,13 +10,8 @@ package org.apache.mahout.math.matrix.li
import org.apache.mahout.math.GenericPermuting;
import org.apache.mahout.math.PersistentObject;
-import org.apache.mahout.math.Sorting;
import org.apache.mahout.math.Swapper;
-import org.apache.mahout.math.bitvector.QuickBitVector;
import org.apache.mahout.math.function.BinaryFunction;
-import org.apache.mahout.math.function.Functions;
-import org.apache.mahout.math.function.IntComparator;
-import org.apache.mahout.math.list.ObjectArrayList;
import org.apache.mahout.math.matrix.DoubleFactory2D;
import org.apache.mahout.math.matrix.DoubleMatrix1D;
import org.apache.mahout.math.matrix.DoubleMatrix2D;
@@ -71,11 +66,6 @@ public class Algebra extends PersistentO
setProperty(new Property(tolerance));
}
- /** Constructs and returns the cholesky-decomposition of the given matrix. */
- private static CholeskyDecomposition chol(DoubleMatrix2D matrix) {
- return new CholeskyDecomposition(matrix);
- }
-
/**
* Returns a copy of the receiver. The attached property object is also copied. Hence, the property object of the copy
* is mutable.
@@ -87,11 +77,6 @@ public class Algebra extends PersistentO
return new Algebra(property.tolerance());
}
- /** Returns the condition of matrix <tt>A</tt>, which is the ratio of largest to smallest singular value. */
- public static double cond(DoubleMatrix2D A) {
- return svd(A).cond();
- }
-
/**
* Returns the determinant of matrix <tt>A</tt>.
*
@@ -101,11 +86,6 @@ public class Algebra extends PersistentO
return lu(A).det();
}
- /** Constructs and returns the Eigenvalue-decomposition of the given matrix. */
- private static EigenvalueDecomposition eig(DoubleMatrix2D matrix) {
- return new EigenvalueDecomposition(matrix);
- }
-
/** Returns sqrt(a^2 + b^2) without under/overflow. */
protected static double hypot(double a, double b) {
double r;
@@ -121,168 +101,12 @@ public class Algebra extends PersistentO
return r;
}
- /** Returns sqrt(a^2 + b^2) without under/overflow. */
- private static BinaryFunction hypotFunction() {
- return new BinaryFunction() {
- public double apply(double a, double b) {
- return hypot(a, b);
- }
- };
- }
-
- /**
- * Returns the inverse or pseudo-inverse of matrix <tt>A</tt>.
- *
- * @return a new independent matrix; inverse(matrix) if the matrix is square, pseudoinverse otherwise.
- */
- public DoubleMatrix2D inverse(DoubleMatrix2D A) {
- if (Property.isSquare(A) && property.isDiagonal(A)) {
- DoubleMatrix2D inv = A.copy();
- boolean isNonSingular = Diagonal.inverse(inv);
- if (!isNonSingular) {
- throw new IllegalArgumentException("A is singular.");
- }
- return inv;
- }
- return solve(A, DoubleFactory2D.dense.identity(A.rows()));
- }
-
/** Constructs and returns the LU-decomposition of the given matrix. */
private static LUDecomposition lu(DoubleMatrix2D matrix) {
return new LUDecomposition(matrix);
}
/**
- * Inner product of two vectors; <tt>Sum(x[i] * y[i])</tt>. Also known as dot product. <br> Equivalent to
- * <tt>x.zDotProduct(y)</tt>.
- *
- * @param x the first source vector.
- * @param y the second source matrix.
- * @return the inner product.
- * @throws IllegalArgumentException if <tt>x.size() != y.size()</tt>.
- */
- public static double mult(DoubleMatrix1D x, DoubleMatrix1D y) {
- return x.zDotProduct(y);
- }
-
- /**
- * Linear algebraic matrix-vector multiplication; <tt>z = A * y</tt>. <tt>z[i] = Sum(A[i,j] * y[j]), i=0..A.rows()-1,
- * j=0..y.size()-1</tt>.
- *
- * @param A the source matrix.
- * @param y the source vector.
- * @return <tt>z</tt>; a new vector with <tt>z.size()==A.rows()</tt>.
- * @throws IllegalArgumentException if <tt>A.columns() != y.size()</tt>.
- */
- public static DoubleMatrix1D mult(DoubleMatrix2D A, DoubleMatrix1D y) {
- return A.zMult(y, null);
- }
-
- /**
- * Linear algebraic matrix-matrix multiplication; <tt>C = A x B</tt>. <tt>C[i,j] = Sum(A[i,k] * B[k,j]),
- * k=0..n-1</tt>. <br> Matrix shapes: <tt>A(m x n), B(n x p), C(m x p)</tt>.
- *
- * @param A the first source matrix.
- * @param B the second source matrix.
- * @return <tt>C</tt>; a new matrix holding the results, with <tt>C.rows()=A.rows(), C.columns()==B.columns()</tt>.
- * @throws IllegalArgumentException if <tt>B.rows() != A.columns()</tt>.
- */
- public static DoubleMatrix2D mult(DoubleMatrix2D A, DoubleMatrix2D B) {
- return A.zMult(B, null);
- }
-
- /**
- * Outer product of two vectors; Sets <tt>A[i,j] = x[i] * y[j]</tt>.
- *
- * @param x the first source vector.
- * @param y the second source vector.
- * @param A the matrix to hold the results. Set this parameter to <tt>null</tt> to indicate that a new result matrix
- * shall be constructed.
- * @return A (for convenience only).
- * @throws IllegalArgumentException if <tt>A.rows() != x.size() || A.columns() != y.size()</tt>.
- */
- public static DoubleMatrix2D multOuter(DoubleMatrix1D x, DoubleMatrix1D y, DoubleMatrix2D A) {
- int rows = x.size();
- int columns = y.size();
- if (A == null) {
- A = x.like2D(rows, columns);
- }
- if (A.rows() != rows || A.columns() != columns) {
- throw new IllegalArgumentException();
- }
-
- for (int row = rows; --row >= 0;) {
- A.viewRow(row).assign(y);
- }
-
- for (int column = columns; --column >= 0;) {
- A.viewColumn(column).assign(x, Functions.mult);
- }
- return A;
- }
-
- /** Returns the one-norm of vector <tt>x</tt>, which is <tt>Sum(abs(x[i]))</tt>. */
- public static double norm1(DoubleMatrix1D x) {
- if (x.size() == 0) {
- return 0;
- }
- return x.aggregate(Functions.plus, Functions.abs);
- }
-
- /** Returns the one-norm of matrix <tt>A</tt>, which is the maximum absolute column sum. */
- public static double norm1(DoubleMatrix2D A) {
- double max = 0;
- for (int column = A.columns(); --column >= 0;) {
- max = Math.max(max, norm1(A.viewColumn(column)));
- }
- return max;
- }
-
- /** Returns the two-norm (aka <i>euclidean norm</i>) of vector <tt>x</tt>; equivalent to <tt>mult(x,x)</tt>. */
- public static double norm2(DoubleMatrix1D x) {
- return mult(x, x);
- }
-
- /** Returns the two-norm of matrix <tt>A</tt>, which is the maximum singular value; obtained from SVD. */
- public static double norm2(DoubleMatrix2D A) {
- return svd(A).norm2();
- }
-
- /** Returns the Frobenius norm of matrix <tt>A</tt>, which is <tt>Sqrt(Sum(A[i,j]<sup>2</sup>))</tt>. */
- public static double normF(DoubleMatrix2D A) {
- if (A.size() == 0) {
- return 0;
- }
- return A.aggregate(hypotFunction(), Functions.identity);
- }
-
- /** Returns the infinity norm of vector <tt>x</tt>, which is <tt>Max(abs(x[i]))</tt>. */
- public static double normInfinity(DoubleMatrix1D x) {
- // fix for bug reported by T.J.Hunt@open.ac.uk
- if (x.size() == 0) {
- return 0;
- }
- return x.aggregate(Functions.max, Functions.abs);
-// if (x.size()==0) return 0;
-// return x.aggregate(Functions.plus,org.apache.mahout.math.function.Functions.abs);
-// double max = 0;
-// for (int i = x.size(); --i >= 0; ) {
-// max = Math.max(max, x.getQuick(i));
-// }
-// return max;
- }
-
- /** Returns the infinity norm of matrix <tt>A</tt>, which is the maximum absolute row sum. */
- public static double normInfinity(DoubleMatrix2D A) {
- double max = 0;
- for (int row = A.rows(); --row >= 0;) {
- //max = Math.max(max, normInfinity(A.viewRow(row)));
- max = Math.max(max, norm1(A.viewRow(row)));
- }
- return max;
- }
-
- /**
* Modifies the given vector <tt>A</tt> such that it is permuted as specified; Useful for pivoting. Cell <tt>A[i]</tt>
* will go into cell <tt>A[indexes[i]]</tt>. <p> <b>Example:</b>
* <pre>
@@ -416,86 +240,6 @@ public class Algebra extends PersistentO
}
/**
- * Linear algebraic matrix power; <tt>B = A<sup>k</sup> <==> B = A*A*...*A</tt>. <ul> <li><tt>p >= 1: B =
- * A*A*...*A</tt>.</li> <li><tt>p == 0: B = identity matrix</tt>.</li> <li><tt>p < 0: B =
- * pow(inverse(A),-p)</tt>.</li> </ul> Implementation: Based on logarithms of 2, memory usage minimized.
- *
- * @param A the source matrix; must be square; stays unaffected by this operation.
- * @param p the exponent, can be any number.
- * @return <tt>B</tt>, a newly constructed result matrix; storage-independent of <tt>A</tt>.
- * @throws IllegalArgumentException if <tt>!property().isSquare(A)</tt>.
- */
- public DoubleMatrix2D pow(DoubleMatrix2D A, int p) {
- // matrix multiplication based on log2 method: A*A*....*A is slow, ((A * A)^2)^2 * ... is faster
- // allocates two auxiliary matrices as work space
-
- // Could be replaced by parallel matrix mult libary
- // Was: for parallel matrix mult; if not initialized defaults to sequential blas
- Blas blas = SeqBlas.seqBlas;
-
- Property.checkSquare(A);
- if (p < 0) {
- A = inverse(A);
- p = -p;
- }
- if (p == 0) {
- return DoubleFactory2D.dense.identity(A.rows());
- }
- DoubleMatrix2D T = A.like(); // temporary
- if (p == 1) {
- return T.assign(A);
- } // safes one auxiliary matrix allocation
- if (p == 2) {
- blas.dgemm(false, false, 1, A, A, 0, T); // mult(A,A); // safes one auxiliary matrix allocation
- return T;
- }
-
- int k = QuickBitVector.mostSignificantBit(p); // index of highest bit in state "true"
-
- /*
- this is the naive version:
- DoubleMatrix2D B = A.copy();
- for (int i=0; i<p-1; i++) {
- B = mult(B,A);
- }
- return B;
- */
-
- // here comes the optimized version:
- //org.apache.mahout.math.Timer timer = new Timer().start();
-
- int i = 0;
- while (i <= k && (p & (1 << i)) == 0) { // while (bit i of p == false)
- // A = mult(A,A); would allocate a lot of temporary memory
- blas.dgemm(false, false, 1, A, A, 0, T); // A.zMult(A,T);
- DoubleMatrix2D swap = A;
- A = T;
- T = swap; // swap A with T
- i++;
- }
-
- DoubleMatrix2D B = A.copy();
- i++;
- for (; i <= k; i++) {
- // A = mult(A,A); would allocate a lot of temporary memory
- blas.dgemm(false, false, 1, A, A, 0, T); // A.zMult(A,T);
- DoubleMatrix2D swap = A;
- A = T;
- T = swap; // swap A with T
-
- if ((p & (1 << i)) != 0) { // if (bit i of p == true)
- // B = mult(B,A); would allocate a lot of temporary memory
- blas.dgemm(false, false, 1, B, A, 0, T); // B.zMult(A,T);
- swap = B;
- B = T;
- T = swap; // swap B with T
- }
- }
- //timer.stop().display();
- return B;
- }
-
- /**
* Returns the property object attached to this Algebra, defining tolerance.
*
* @return the Property object.
@@ -510,11 +254,6 @@ public class Algebra extends PersistentO
return new QRDecomposition(matrix);
}
- /** Returns the effective numerical rank of matrix <tt>A</tt>, obtained from Singular Value Decomposition. */
- public static int rank(DoubleMatrix2D A) {
- return svd(A).rank();
- }
-
/**
* Attaches the given property object to this Algebra, defining tolerance.
*
@@ -545,472 +284,6 @@ public class Algebra extends PersistentO
}
/**
- * Solves X*A = B, which is also A'*X' = B'.
- *
- * @return X; a new independent matrix; solution if A is square, least squares solution otherwise.
- */
- public static DoubleMatrix2D solveTranspose(DoubleMatrix2D A, DoubleMatrix2D B) {
- return solve(transpose(A), transpose(B));
- }
-
- /**
- * Copies the columns of the indicated rows into a new sub matrix. <tt>sub[0..rowIndexes.length-1,0..columnTo-columnFrom]
- * = A[rowIndexes(:),columnFrom..columnTo]</tt>; The returned matrix is <i>not backed</i> by this matrix, so changes
- * in the returned matrix are <i>not reflected</i> in this matrix, and vice-versa.
- *
- * @param A the source matrix to copy from.
- * @param rowIndexes the indexes of the rows to copy. May be unsorted.
- * @param columnFrom the index of the first column to copy (inclusive).
- * @param columnTo the index of the last column to copy (inclusive).
- * @return a new sub matrix; with <tt>sub.rows()==rowIndexes.length; sub.columns()==columnTo-columnFrom+1</tt>.
- * @throws IndexOutOfBoundsException if <tt>columnFrom<0 || columnTo-columnFrom+1<0 || columnTo+1>matrix.columns() ||
- * for any row=rowIndexes[i]: row < 0 || row >= matrix.rows()</tt>.
- */
- private static DoubleMatrix2D subMatrix(DoubleMatrix2D A, int[] rowIndexes, int columnFrom, int columnTo) {
- int width = columnTo - columnFrom + 1;
- int rows = A.rows();
- A = A.viewPart(0, columnFrom, rows, width);
- DoubleMatrix2D sub = A.like(rowIndexes.length, width);
-
- for (int r = rowIndexes.length; --r >= 0;) {
- int row = rowIndexes[r];
- if (row < 0 || row >= rows) {
- throw new IndexOutOfBoundsException("Illegal Index");
- }
- sub.viewRow(r).assign(A.viewRow(row));
- }
- return sub;
- }
-
- /**
- * Copies the rows of the indicated columns into a new sub matrix. <tt>sub[0..rowTo-rowFrom,0..columnIndexes.length-1]
- * = A[rowFrom..rowTo,columnIndexes(:)]</tt>; The returned matrix is <i>not backed</i> by this matrix, so changes in
- * the returned matrix are <i>not reflected</i> in this matrix, and vice-versa.
- *
- * @param A the source matrix to copy from.
- * @param rowFrom the index of the first row to copy (inclusive).
- * @param rowTo the index of the last row to copy (inclusive).
- * @param columnIndexes the indexes of the columns to copy. May be unsorted.
- * @return a new sub matrix; with <tt>sub.rows()==rowTo-rowFrom+1; sub.columns()==columnIndexes.length</tt>.
- * @throws IndexOutOfBoundsException if <tt>rowFrom<0 || rowTo-rowFrom+1<0 || rowTo+1>matrix.rows() || for any
- * col=columnIndexes[i]: col < 0 || col >= matrix.columns()</tt>.
- */
- private static DoubleMatrix2D subMatrix(DoubleMatrix2D A, int rowFrom, int rowTo, int[] columnIndexes) {
- if (rowTo - rowFrom >= A.rows()) {
- throw new IndexOutOfBoundsException("Too many rows");
- }
- int height = rowTo - rowFrom + 1;
- int columns = A.columns();
- A = A.viewPart(rowFrom, 0, height, columns);
- DoubleMatrix2D sub = A.like(height, columnIndexes.length);
-
- for (int c = columnIndexes.length; --c >= 0;) {
- int column = columnIndexes[c];
- if (column < 0 || column >= columns) {
- throw new IndexOutOfBoundsException("Illegal Index");
- }
- sub.viewColumn(c).assign(A.viewColumn(column));
- }
- return sub;
- }
-
- /**
- * Constructs and returns a new <i>sub-range view</i> which is the sub matrix <tt>A[fromRow..toRow,fromColumn..toColumn]</tt>.
- * The returned matrix is backed by this matrix, so changes in the returned matrix are reflected in this matrix, and
- * vice-versa. Use idioms like <tt>result = subMatrix(...).copy()</tt> to generate an independent sub matrix.
- *
- * @param A the source matrix.
- * @param fromRow The index of the first row (inclusive).
- * @param toRow The index of the last row (inclusive).
- * @param fromColumn The index of the first column (inclusive).
- * @param toColumn The index of the last column (inclusive).
- * @return a new sub-range view.
- * @throws IndexOutOfBoundsException if <tt>fromColumn<0 || toColumn-fromColumn+1<0 || toColumn>=A.columns() ||
- * fromRow<0 || toRow-fromRow+1<0 || toRow>=A.rows()</tt>
- */
- public static DoubleMatrix2D subMatrix(DoubleMatrix2D A, int fromRow, int toRow, int fromColumn, int toColumn) {
- return A.viewPart(fromRow, fromColumn, toRow - fromRow + 1, toColumn - fromColumn + 1);
- }
-
- /** Constructs and returns the SingularValue-decomposition of the given matrix. */
- private static SingularValueDecomposition svd(DoubleMatrix2D matrix) {
- return new SingularValueDecomposition(matrix);
- }
-
- /**
- * Returns a String with (propertyName, propertyValue) pairs. Useful for debugging or to quickly get the rough
- * picture. For example,
- * <pre>
- * cond : 14.073264490042144
- * det : Illegal operation or error: Matrix must be square.
- * norm1 : 0.9620244354009628
- * norm2 : 3.0
- * normF : 1.304841791648992
- * normInfinity : 1.5406551198102534
- * rank : 3
- * trace : 0
- * </pre>
- */
- public static String toString(DoubleMatrix2D matrix) {
- final ObjectArrayList<String> names = new ObjectArrayList<String>();
- final ObjectArrayList<String> values = new ObjectArrayList<String>();
-
- // determine properties
- names.add("cond");
- String unknown = "Illegal operation or error: ";
- try {
- values.add(String.valueOf(cond(matrix)));
- }
- catch (IllegalArgumentException exc) {
- values.add(unknown + exc.getMessage());
- }
-
- names.add("det");
- try {
- values.add(String.valueOf(det(matrix)));
- }
- catch (IllegalArgumentException exc) {
- values.add(unknown + exc.getMessage());
- }
-
- names.add("norm1");
- try {
- values.add(String.valueOf(norm1(matrix)));
- }
- catch (IllegalArgumentException exc) {
- values.add(unknown + exc.getMessage());
- }
-
- names.add("norm2");
- try {
- values.add(String.valueOf(norm2(matrix)));
- }
- catch (IllegalArgumentException exc) {
- values.add(unknown + exc.getMessage());
- }
-
- names.add("normF");
- try {
- values.add(String.valueOf(normF(matrix)));
- }
- catch (IllegalArgumentException exc) {
- values.add(unknown + exc.getMessage());
- }
-
- names.add("normInfinity");
- try {
- values.add(String.valueOf(normInfinity(matrix)));
- }
- catch (IllegalArgumentException exc) {
- values.add(unknown + exc.getMessage());
- }
-
- names.add("rank");
- try {
- values.add(String.valueOf(rank(matrix)));
- }
- catch (IllegalArgumentException exc) {
- values.add(unknown + exc.getMessage());
- }
-
- names.add("trace");
- try {
- values.add(String.valueOf(trace(matrix)));
- }
- catch (IllegalArgumentException exc) {
- values.add(unknown + exc.getMessage());
- }
-
-
- // sort ascending by property name
- IntComparator comp = new IntComparator() {
- public int compare(int a, int b) {
- return Property.get(names, a).compareTo(Property.get(names, b));
- }
- };
- Swapper swapper = new Swapper() {
- public void swap(int a, int b) {
- String tmp = names.get(a);
- names.set(a, names.get(b));
- names.set(b, tmp);
- tmp = values.get(a);
- values.set(a, values.get(b));
- values.set(b, tmp);
- }
- };
- Sorting.quickSort(0, names.size(), comp, swapper);
-
- // determine padding for nice formatting
- int maxLength = 0;
- for (int i = 0; i < names.size(); i++) {
- int length = (names.get(i)).length();
- maxLength = Math.max(length, maxLength);
- }
-
- // finally, format properties
- StringBuilder buf = new StringBuilder();
- for (int i = 0; i < names.size(); i++) {
- String name = names.get(i);
- buf.append(name);
- buf.append(Property.blanks(maxLength - name.length()));
- buf.append(" : ");
- buf.append(values.get(i));
- if (i < names.size() - 1) {
- buf.append('\n');
- }
- }
-
- return buf.toString();
- }
-
- /**
- * Returns the results of <tt>toString(A)</tt> and additionally the results of all sorts of decompositions applied to
- * the given matrix. Useful for debugging or to quickly get the rough picture. For example,
- * <pre>
- * A = 3 x 3 matrix
- * 249 66 68
- * 104 214 108
- * 144 146 293
- *
- * cond : 3.931600417472078
- * det : 9638870.0
- * norm1 : 497.0
- * norm2 : 473.34508217011404
- * normF : 516.873292016525
- * normInfinity : 583.0
- * rank : 3
- * trace : 756.0
- *
- * density : 1.0
- * isDiagonal : false
- * isDiagonallyDominantByColumn : true
- * isDiagonallyDominantByRow : true
- * isIdentity : false
- * isLowerBidiagonal : false
- * isLowerTriangular : false
- * isNonNegative : true
- * isOrthogonal : false
- * isPositive : true
- * isSingular : false
- * isSkewSymmetric : false
- * isSquare : true
- * isStrictlyLowerTriangular : false
- * isStrictlyTriangular : false
- * isStrictlyUpperTriangular : false
- * isSymmetric : false
- * isTriangular : false
- * isTridiagonal : false
- * isUnitTriangular : false
- * isUpperBidiagonal : false
- * isUpperTriangular : false
- * isZero : false
- * lowerBandwidth : 2
- * semiBandwidth : 3
- * upperBandwidth : 2
- *
- * -----------------------------------------------------------------------------
- * LUDecompositionQuick(A) --> isNonSingular(A), det(A), pivot, L, U, inverse(A)
- * -----------------------------------------------------------------------------
- * isNonSingular = true
- * det = 9638870.0
- * pivot = [0, 1, 2]
- *
- * L = 3 x 3 matrix
- * 1 0 0
- * 0.417671 1 0
- * 0.578313 0.57839 1
- *
- * U = 3 x 3 matrix
- * 249 66 68
- * 0 186.433735 79.598394
- * 0 0 207.635819
- *
- * inverse(A) = 3 x 3 matrix
- * 0.004869 -0.000976 -0.00077
- * -0.001548 0.006553 -0.002056
- * -0.001622 -0.002786 0.004816
- *
- * -----------------------------------------------------------------
- * QRDecomposition(A) --> hasFullRank(A), H, Q, R, pseudo inverse(A)
- * -----------------------------------------------------------------
- * hasFullRank = true
- *
- * H = 3 x 3 matrix
- * 1.814086 0 0
- * 0.34002 1.903675 0
- * 0.470797 0.428218 2
- *
- * Q = 3 x 3 matrix
- * -0.814086 0.508871 0.279845
- * -0.34002 -0.808296 0.48067
- * -0.470797 -0.296154 -0.831049
- *
- * R = 3 x 3 matrix
- * -305.864349 -195.230337 -230.023539
- * 0 -182.628353 467.703164
- * 0 0 -309.13388
- *
- * pseudo inverse(A) = 3 x 3 matrix
- * 0.006601 0.001998 -0.005912
- * -0.005105 0.000444 0.008506
- * -0.000905 -0.001555 0.002688
- *
- * --------------------------------------------------------------------------
- * CholeskyDecomposition(A) --> isSymmetricPositiveDefinite(A), L, inverse(A)
- * --------------------------------------------------------------------------
- * isSymmetricPositiveDefinite = false
- *
- * L = 3 x 3 matrix
- * 15.779734 0 0
- * 6.590732 13.059948 0
- * 9.125629 6.573948 12.903724
- *
- * inverse(A) = Illegal operation or error: Matrix is not symmetric positive definite.
- *
- * ---------------------------------------------------------------------
- * EigenvalueDecomposition(A) --> D, V, realEigenvalues, imagEigenvalues
- * ---------------------------------------------------------------------
- * realEigenvalues = 1 x 3 matrix
- * 462.796507 172.382058 120.821435
- * imagEigenvalues = 1 x 3 matrix
- * 0 0 0
- *
- * D = 3 x 3 matrix
- * 462.796507 0 0
- * 0 172.382058 0
- * 0 0 120.821435
- *
- * V = 3 x 3 matrix
- * -0.398877 -0.778282 0.094294
- * -0.500327 0.217793 -0.806319
- * -0.768485 0.66553 0.604862
- *
- * ---------------------------------------------------------------------
- * SingularValueDecomposition(A) --> cond(A), rank(A), norm2(A), U, S, V
- * ---------------------------------------------------------------------
- * cond = 3.931600417472078
- * rank = 3
- * norm2 = 473.34508217011404
- *
- * U = 3 x 3 matrix
- * 0.46657 -0.877519 0.110777
- * 0.50486 0.161382 -0.847982
- * 0.726243 0.45157 0.51832
- *
- * S = 3 x 3 matrix
- * 473.345082 0 0
- * 0 169.137441 0
- * 0 0 120.395013
- *
- * V = 3 x 3 matrix
- * 0.577296 -0.808174 0.116546
- * 0.517308 0.251562 -0.817991
- * 0.631761 0.532513 0.563301
- * </pre>
- */
- public static String toVerboseString(DoubleMatrix2D matrix) {
-/*
- StringBuffer buf = new StringBuffer();
- String unknown = "Illegal operation or error: ";
- String constructionException = "Illegal operation or error upon construction: ";
-
- buf.append("------------------------------------------------------------------\n");
- buf.append("LUDecomposition(A) --> isNonSingular, det, pivot, L, U, inverse(A)\n");
- buf.append("------------------------------------------------------------------\n");
-*/
-
- StringBuilder buf = new StringBuilder();
-
- buf.append("A = ");
- buf.append(matrix);
-
- buf.append("\n\n").append(toString(matrix));
- buf.append("\n\n").append(Property.DEFAULT.toString(matrix));
-
- LUDecomposition lu = null;
- String constructionException = "Illegal operation or error upon construction of ";
- try {
- lu = new LUDecomposition(matrix);
- }
- catch (IllegalArgumentException exc) {
- buf.append("\n\n").append(constructionException).append(" LUDecomposition: ").append(exc.getMessage());
- }
- if (lu != null) {
- buf.append("\n\n").append(lu.toString());
- }
-
- QRDecomposition qr = null;
- try {
- qr = new QRDecomposition(matrix);
- }
- catch (IllegalArgumentException exc) {
- buf.append("\n\n").append(constructionException).append(" QRDecomposition: ").append(exc.getMessage());
- }
- if (qr != null) {
- buf.append("\n\n").append(qr.toString());
- }
-
- CholeskyDecomposition chol = null;
- try {
- chol = new CholeskyDecomposition(matrix);
- }
- catch (IllegalArgumentException exc) {
- buf.append("\n\n").append(constructionException).append(" CholeskyDecomposition: ").append(exc.getMessage());
- }
- if (chol != null) {
- buf.append("\n\n").append(chol.toString());
- }
-
- EigenvalueDecomposition eig = null;
- try {
- eig = new EigenvalueDecomposition(matrix);
- }
- catch (IllegalArgumentException exc) {
- buf.append("\n\n").append(constructionException).append(" EigenvalueDecomposition: ").append(exc.getMessage());
- }
- if (eig != null) {
- buf.append("\n\n").append(eig.toString());
- }
-
- SingularValueDecomposition svd = null;
- try {
- svd = new SingularValueDecomposition(matrix);
- }
- catch (IllegalArgumentException exc) {
- buf.append("\n\n").append(constructionException).append(" SingularValueDecomposition: ").append(exc.getMessage());
- }
- if (svd != null) {
- buf.append("\n\n").append(svd.toString());
- }
-
- return buf.toString();
- }
-
- /** Returns the sum of the diagonal elements of matrix <tt>A</tt>; <tt>Sum(A[i,i])</tt>. */
- public static double trace(DoubleMatrix2D A) {
- double sum = 0;
- for (int i = Math.min(A.rows(), A.columns()); --i >= 0;) {
- sum += A.getQuick(i, i);
- }
- return sum;
- }
-
- /**
- * Constructs and returns a new view which is the transposition of the given matrix <tt>A</tt>. Equivalent to {@link
- * DoubleMatrix2D#viewDice A.viewDice()}. This is a zero-copy transposition, taking O(1), i.e. constant time. The
- * returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and
- * vice-versa. Use idioms like <tt>result = transpose(A).copy()</tt> to generate an independent matrix. <p>
- * <b>Example:</b> <table border="0"> <tr nowrap> <td valign="top">2 x 3 matrix: <br> 1, 2, 3<br> 4, 5, 6 </td>
- * <td>transpose ==></td> <td valign="top">3 x 2 matrix:<br> 1, 4 <br> 2, 5 <br> 3, 6</td> <td>transpose ==></td> <td
- * valign="top">2 x 3 matrix: <br> 1, 2, 3<br> 4, 5, 6 </td> </tr> </table>
- *
- * @return a new transposed view.
- */
- public static DoubleMatrix2D transpose(DoubleMatrix2D A) {
- return A.viewDice();
- }
-
- /**
* Modifies the matrix to be a lower trapezoidal matrix.
*
* @return <tt>A</tt> (for convenience only).
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java Tue Aug 17 17:34:14 2010
@@ -45,7 +45,6 @@ public class EigenvalueDecomposition imp
* methods of the returned decomposition object. Checks for symmetry, then constructs the eigenvalue decomposition.
*
* @param A A square matrix.
- * @return A decomposition object to access <tt>D</tt> and <tt>V</tt>.
* @throws IllegalArgumentException if <tt>A</tt> is not square.
*/
public EigenvalueDecomposition(DoubleMatrix2D A) {
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecomposition.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecomposition.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecomposition.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecomposition.java Tue Aug 17 17:34:14 2010
@@ -32,7 +32,6 @@ public class LUDecomposition implements
* of the returned decomposition object.
*
* @param A Rectangular matrix
- * @return Structure to access L, U and piv.
*/
public LUDecomposition(DoubleMatrix2D A) {
quick = new LUDecompositionQuick(0); // zero tolerance for compatibility with Jama
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java Tue Aug 17 17:34:14 2010
@@ -9,10 +9,7 @@ It is provided "as is" without expressed
package org.apache.mahout.math.matrix.linalg;
import org.apache.mahout.math.PersistentObject;
-import org.apache.mahout.math.Sorting;
-import org.apache.mahout.math.Swapper;
import org.apache.mahout.math.function.Functions;
-import org.apache.mahout.math.function.IntComparator;
import org.apache.mahout.math.list.ObjectArrayList;
import org.apache.mahout.math.matrix.DoubleFactory2D;
import org.apache.mahout.math.matrix.DoubleMatrix1D;
@@ -21,9 +18,7 @@ import org.apache.mahout.math.matrix.Dou
import org.apache.mahout.math.matrix.impl.AbstractFormatter;
import org.apache.mahout.math.matrix.impl.AbstractMatrix2D;
-import java.util.ArrayList;
import java.util.Formatter;
-import java.util.List;
import java.util.TreeMap;
/** @deprecated until unit tests are in place. Until this time, this class/interface is unsupported. */
@@ -328,8 +323,8 @@ public class Property extends Persistent
a.setQuick(i, i, 0);
}
for (int i = min; --i >= 0;) {
- double rowSum = a.viewRow(i).aggregate(Functions.plus, Functions.abs);
- double colSum = a.viewColumn(i).aggregate(Functions.plus, Functions.abs);
+ double rowSum = a.viewRow(i).aggregate(Functions.PLUS, Functions.ABS);
+ double colSum = a.viewColumn(i).aggregate(Functions.PLUS, Functions.ABS);
a.setQuick(i, i, Math.max(rowSum, colSum) + i + 1);
}
}
@@ -369,7 +364,7 @@ public class Property extends Persistent
for (int i = min; --i >= 0;) {
double diag = Math.abs(a.getQuick(i, i));
diag += diag;
- if (diag <= a.viewColumn(i).aggregate(Functions.plus, Functions.abs)) {
+ if (diag <= a.viewColumn(i).aggregate(Functions.PLUS, Functions.ABS)) {
return false;
}
}
@@ -388,7 +383,7 @@ public class Property extends Persistent
for (int i = min; --i >= 0;) {
double diag = Math.abs(a.getQuick(i, i));
diag += diag;
- if (diag <= a.viewRow(i).aggregate(Functions.plus, Functions.abs)) {
+ if (diag <= a.viewRow(i).aggregate(Functions.PLUS, Functions.ABS)) {
return false;
}
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/QRDecomposition.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/QRDecomposition.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/QRDecomposition.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/QRDecomposition.java Tue Aug 17 17:34:14 2010
@@ -45,8 +45,6 @@ public class QRDecomposition implements
* can be retrieved via instance methods of the returned decomposition object.
*
* @param A A rectangular matrix.
- * @return a decomposition object to access <tt>R</tt> and the Householder vectors <tt>H</tt>, and to compute
- * <tt>Q</tt>.
* @throws IllegalArgumentException if <tt>A.rows() < A.columns()</tt>.
*/
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/stats/LogLikelihood.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/stats/LogLikelihood.java?rev=986405&r1=986404&r2=986405&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/stats/LogLikelihood.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/stats/LogLikelihood.java Tue Aug 17 17:34:14 2010
@@ -76,8 +76,7 @@ public final class LogLikelihood {
/**
* Calculate the Root Log-likelihood ratio for two events.
- *
- * @see #logLikelihoodRatio(int, int, int, int);
+ * See {@link #logLikelihoodRatio(int, int, int, int)}.
* @param k11 The number of times the two events occurred together
* @param k12 The number of times the second event occurred WITHOUT the first event
@@ -92,7 +91,7 @@ public final class LogLikelihood {
public static double rootLogLikelihoodRatio(int k11, int k12, int k21, int k22) {
double llr = logLikelihoodRatio(k11, k12, k21, k22);
double sqrt = Math.sqrt(llr);
- if (((double) k11 / (k11+k12)) < ((double) k21 / (k21+k22))) {
+ if (((double) k11 / (k11 + k12)) < ((double) k21 / (k21 + k22))) {
sqrt = -sqrt;
}
return sqrt;