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 2009/11/25 04:31:49 UTC
svn commit: r883972 [2/10] - in /lucene/mahout/trunk:
core/src/main/java/org/apache/mahout/fpm/pfpgrowth/
matrix/src/main/java/org/apache/mahout/jet/math/
matrix/src/main/java/org/apache/mahout/jet/random/
matrix/src/main/java/org/apache/mahout/jet/ran...
Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/Functions.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/Functions.java?rev=883972&r1=883971&r2=883972&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/Functions.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/Functions.java Wed Nov 25 03:31:47 2009
@@ -111,37 +111,37 @@
is often acceptable.
<center>
<table border cellpadding="3" cellspacing="0" align="center">
- <tr valign="middle" bgcolor="#33CC66" nowrap align="center">
- <td nowrap colspan="7"> <font size="+2">Iteration Performance [million function
- evaluations per second]</font><br>
- <font size="-1">Pentium Pro 200 Mhz, SunJDK 1.2.2, NT, java -classic,
- </font></td>
- </tr>
- <tr valign="middle" bgcolor="#66CCFF" nowrap align="center">
- <td nowrap bgcolor="#FF9966" rowspan="2"> </td>
- <td bgcolor="#FF9966" colspan="2">
- <p> 30000000 iterations</p>
- </td>
- <td bgcolor="#FF9966" colspan="2"> 3000000 iterations (10 times less)</td>
- <td bgcolor="#FF9966" colspan="2"> </td>
- </tr>
- <tr valign="middle" bgcolor="#66CCFF" nowrap align="center">
- <td bgcolor="#FF9966"> <tt>F.plus</tt></td>
- <td bgcolor="#FF9966"><tt>a+b</tt></td>
- <td bgcolor="#FF9966"> <tt>F.chain(F.abs,F.chain(F.plus,F.sin,F.chain(F.square,F.cos)))</tt></td>
- <td bgcolor="#FF9966"> <tt>Math.abs(Math.sin(a) + Math.pow(Math.cos(b),2))</tt></td>
- <td bgcolor="#FF9966"> </td>
- <td bgcolor="#FF9966"> </td>
- </tr>
- <tr valign="middle" bgcolor="#66CCFF" nowrap align="center">
- <td nowrap bgcolor="#FF9966"> </td>
- <td nowrap>10.8</td>
- <td nowrap>29.6</td>
- <td nowrap>0.43</td>
- <td nowrap>0.35</td>
- <td nowrap> </td>
- <td nowrap> </td>
- </tr>
+ <tr valign="middle" bgcolor="#33CC66" nowrap align="center">
+ <td nowrap colspan="7"> <font size="+2">Iteration Performance [million function
+ evaluations per second]</font><br>
+ <font size="-1">Pentium Pro 200 Mhz, SunJDK 1.2.2, NT, java -classic,
+ </font></td>
+ </tr>
+ <tr valign="middle" bgcolor="#66CCFF" nowrap align="center">
+ <td nowrap bgcolor="#FF9966" rowspan="2"> </td>
+ <td bgcolor="#FF9966" colspan="2">
+ <p> 30000000 iterations</p>
+ </td>
+ <td bgcolor="#FF9966" colspan="2"> 3000000 iterations (10 times less)</td>
+ <td bgcolor="#FF9966" colspan="2"> </td>
+ </tr>
+ <tr valign="middle" bgcolor="#66CCFF" nowrap align="center">
+ <td bgcolor="#FF9966"> <tt>F.plus</tt></td>
+ <td bgcolor="#FF9966"><tt>a+b</tt></td>
+ <td bgcolor="#FF9966"> <tt>F.chain(F.abs,F.chain(F.plus,F.sin,F.chain(F.square,F.cos)))</tt></td>
+ <td bgcolor="#FF9966"> <tt>Math.abs(Math.sin(a) + Math.pow(Math.cos(b),2))</tt></td>
+ <td bgcolor="#FF9966"> </td>
+ <td bgcolor="#FF9966"> </td>
+ </tr>
+ <tr valign="middle" bgcolor="#66CCFF" nowrap align="center">
+ <td nowrap bgcolor="#FF9966"> </td>
+ <td nowrap>10.8</td>
+ <td nowrap>29.6</td>
+ <td nowrap>0.43</td>
+ <td nowrap>0.35</td>
+ <td nowrap> </td>
+ <td nowrap> </td>
+ </tr>
</table></center>
@@ -153,437 +153,437 @@
*/
@Deprecated
public class Functions extends Object {
- /**
- Little trick to allow for "aliasing", that is, renaming this class.
- Writing code like
- <p>
- <tt>Functions.chain(Functions.plus,Functions.sin,Functions.chain(Functions.square,Functions.cos));</tt>
- <p>
- is a bit awkward, to say the least.
- Using the aliasing you can instead write
- <p>
- <tt>Functions F = Functions.functions; <br>
- F.chain(F.plus,F.sin,F.chain(F.square,F.cos));</tt>
- */
- public static final Functions functions = new Functions();
-
- /*****************************
- * <H3>Unary functions</H3>
- *****************************/
- /**
- * Function that returns <tt>Math.abs(a)</tt>.
- */
- public static final DoubleFunction abs = new DoubleFunction() {
- public final double apply(double a) { return Math.abs(a); }
- };
-
- /**
- * Function that returns <tt>Math.acos(a)</tt>.
- */
- public static final DoubleFunction acos = new DoubleFunction() {
- public final double apply(double a) { return Math.acos(a); }
- };
-
- /**
- * Function that returns <tt>com.imsl.math.Sfun.acosh(a)</tt>.
- */
- /*
- public static final DoubleFunction acosh = new DoubleFunction() {
- public final double apply(double a) { return Sfun.acosh(a); }
- };
- */
-
- /**
- * Function that returns <tt>Math.asin(a)</tt>.
- */
- public static final DoubleFunction asin = new DoubleFunction() {
- public final double apply(double a) { return Math.asin(a); }
- };
-
- /**
- * Function that returns <tt>com.imsl.math.Sfun.asinh(a)</tt>.
- */
- /*
- public static final DoubleFunction asinh = new DoubleFunction() {
- public final double apply(double a) { return Sfun.asinh(a); }
- };
- */
-
- /**
- * Function that returns <tt>Math.atan(a)</tt>.
- */
- public static final DoubleFunction atan = new DoubleFunction() {
- public final double apply(double a) { return Math.atan(a); }
- };
-
- /**
- * Function that returns <tt>com.imsl.math.Sfun.atanh(a)</tt>.
- */
- /*
- public static final DoubleFunction atanh = new DoubleFunction() {
- public final double apply(double a) { return Sfun.atanh(a); }
- };
- */
-
- /**
- * Function that returns <tt>Math.ceil(a)</tt>.
- */
- public static final DoubleFunction ceil = new DoubleFunction() {
- public final double apply(double a) { return Math.ceil(a); }
- };
-
- /**
- * Function that returns <tt>Math.cos(a)</tt>.
- */
- public static final DoubleFunction cos = new DoubleFunction() {
- public final double apply(double a) { return Math.cos(a); }
- };
-
- /**
- * Function that returns <tt>com.imsl.math.Sfun.cosh(a)</tt>.
- */
- /*
- public static final DoubleFunction cosh = new DoubleFunction() {
- public final double apply(double a) { return Sfun.cosh(a); }
- };
- */
-
- /**
- * Function that returns <tt>com.imsl.math.Sfun.cot(a)</tt>.
- */
- /*
- public static final DoubleFunction cot = new DoubleFunction() {
- public final double apply(double a) { return Sfun.cot(a); }
- };
- */
-
- /**
- * Function that returns <tt>com.imsl.math.Sfun.erf(a)</tt>.
- */
- /*
- public static final DoubleFunction erf = new DoubleFunction() {
- public final double apply(double a) { return Sfun.erf(a); }
- };
- */
-
- /**
- * Function that returns <tt>com.imsl.math.Sfun.erfc(a)</tt>.
- */
- /*
- public static final DoubleFunction erfc = new DoubleFunction() {
- public final double apply(double a) { return Sfun.erfc(a); }
- };
- */
-
- /**
- * Function that returns <tt>Math.exp(a)</tt>.
- */
- public static final DoubleFunction exp = new DoubleFunction() {
- public final double apply(double a) { return Math.exp(a); }
- };
-
- /**
- * Function that returns <tt>Math.floor(a)</tt>.
- */
- public static final DoubleFunction floor = new DoubleFunction() {
- public final double apply(double a) { return Math.floor(a); }
- };
-
- /**
- * Function that returns <tt>com.imsl.math.Sfun.gamma(a)</tt>.
- */
- /*
- public static final DoubleFunction gamma = new DoubleFunction() {
- public final double apply(double a) { return Sfun.gamma(a); }
- };
- */
-
- /**
- * Function that returns its argument.
- */
- public static final DoubleFunction identity = new DoubleFunction() {
- public final double apply(double a) { return a; }
- };
-
- /**
- * Function that returns <tt>1.0 / a</tt>.
- */
- public static final DoubleFunction inv = new DoubleFunction() {
- public final double apply(double a) { return 1.0 / a; }
- };
-
- /**
- * Function that returns <tt>Math.log(a)</tt>.
- */
- public static final DoubleFunction log = new DoubleFunction() {
- public final double apply(double a) { return Math.log(a); }
- };
-
- /**
- * Function that returns <tt>com.imsl.math.Sfun.log10(a)</tt>.
- */
- /*
- public static final DoubleFunction log10 = new DoubleFunction() {
- public final double apply(double a) { return Sfun.log10(a); }
- };
- */
-
- /**
- * Function that returns <tt>Math.log(a) / Math.log(2)</tt>.
- */
- public static final DoubleFunction log2 = new DoubleFunction() {
- // 1.0 / Math.log(2) == 1.4426950408889634
- public final double apply(double a) { return Math.log(a) * 1.4426950408889634; }
- };
-
- /**
- * Function that returns <tt>com.imsl.math.Sfun.logGamma(a)</tt>.
- */
- /*
- public static final DoubleFunction logGamma = new DoubleFunction() {
- public final double apply(double a) { return Sfun.logGamma(a); }
- };
- */
-
- /**
- * Function that returns <tt>-a</tt>.
- */
- public static final DoubleFunction neg = new DoubleFunction() {
- public final double apply(double a) { return -a; }
- };
-
- /**
- * Function that returns <tt>Math.rint(a)</tt>.
- */
- public static final DoubleFunction rint = new DoubleFunction() {
- public final double apply(double a) { return Math.rint(a); }
- };
-
- /**
- * Function that returns <tt>a < 0 ? -1 : a > 0 ? 1 : 0</tt>.
- */
- public static final DoubleFunction sign = new DoubleFunction() {
- public final double apply(double a) { return a < 0 ? -1 : a > 0 ? 1 : 0; }
- };
-
- /**
- * Function that returns <tt>Math.sin(a)</tt>.
- */
- public static final DoubleFunction sin = new DoubleFunction() {
- public final double apply(double a) { return Math.sin(a); }
- };
-
- /**
- * Function that returns <tt>com.imsl.math.Sfun.sinh(a)</tt>.
- */
- /*
- public static final DoubleFunction sinh = new DoubleFunction() {
- public final double apply(double a) { return Sfun.sinh(a); }
- };
- */
-
- /**
- * Function that returns <tt>Math.sqrt(a)</tt>.
- */
- public static final DoubleFunction sqrt = new DoubleFunction() {
- public final double apply(double a) { return Math.sqrt(a); }
- };
-
- /**
- * Function that returns <tt>a * a</tt>.
- */
- public static final DoubleFunction square = new DoubleFunction() {
- public final double apply(double a) { return a * a; }
- };
-
- /**
- * Function that returns <tt>Math.tan(a)</tt>.
- */
- public static final DoubleFunction tan = new DoubleFunction() {
- public final double apply(double a) { return Math.tan(a); }
- };
-
- /**
- * Function that returns <tt>com.imsl.math.Sfun.tanh(a)</tt>.
- */
- /*
- public static final DoubleFunction tanh = new DoubleFunction() {
- public final double apply(double a) { return Sfun.tanh(a); }
- };
- */
-
- /**
- * Function that returns <tt>Math.toDegrees(a)</tt>.
- */
- /*
- public static final DoubleFunction toDegrees = new DoubleFunction() {
- public final double apply(double a) { return Math.toDegrees(a); }
- };
- */
-
- /**
- * Function that returns <tt>Math.toRadians(a)</tt>.
- */
- /*
- public static final DoubleFunction toRadians = new DoubleFunction() {
- public final double apply(double a) { return Math.toRadians(a); }
- };
- */
-
-
-
- /*****************************
- * <H3>Binary functions</H3>
- *****************************/
-
- /**
- * Function that returns <tt>Math.atan2(a,b)</tt>.
- */
- public static final DoubleDoubleFunction atan2 = new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return Math.atan2(a,b); }
- };
-
- /**
- * Function that returns <tt>com.imsl.math.Sfun.logBeta(a,b)</tt>.
- */
- /*
- public static final DoubleDoubleFunction logBeta = new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return Sfun.logBeta(a,b); }
- };
- */
-
-
- /**
- * Function that returns <tt>a < b ? -1 : a > b ? 1 : 0</tt>.
- */
- public static final DoubleDoubleFunction compare = new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return a < b ? -1 : a > b ? 1 : 0; }
- };
-
- /**
- * Function that returns <tt>a / b</tt>.
- */
- public static final DoubleDoubleFunction div = new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return a / b; }
- };
-
- /**
- * Function that returns <tt>a == b ? 1 : 0</tt>.
- */
- public static final DoubleDoubleFunction equals = new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return a == b ? 1 : 0; }
- };
-
- /**
- * Function that returns <tt>a > b ? 1 : 0</tt>.
- */
- public static final DoubleDoubleFunction greater = new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return a > b ? 1 : 0; }
- };
-
- /**
- * Function that returns <tt>Math.IEEEremainder(a,b)</tt>.
- */
- public static final DoubleDoubleFunction IEEEremainder = new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return Math.IEEEremainder(a,b); }
- };
-
- /**
- * Function that returns <tt>a == b</tt>.
- */
- public static final DoubleDoubleProcedure isEqual = new DoubleDoubleProcedure() {
- public final boolean apply(double a, double b) { return a == b; }
- };
-
- /**
- * Function that returns <tt>a < b</tt>.
- */
- public static final DoubleDoubleProcedure isLess = new DoubleDoubleProcedure() {
- public final boolean apply(double a, double b) { return a < b; }
- };
-
- /**
- * Function that returns <tt>a > b</tt>.
- */
- public static final DoubleDoubleProcedure isGreater = new DoubleDoubleProcedure() {
- public final boolean apply(double a, double b) { return a > b; }
- };
-
- /**
- * Function that returns <tt>a < b ? 1 : 0</tt>.
- */
- public static final DoubleDoubleFunction less = new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return a < b ? 1 : 0; }
- };
-
- /**
- * Function that returns <tt>Math.log(a) / Math.log(b)</tt>.
- */
- public static final DoubleDoubleFunction lg = new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return Math.log(a) / Math.log(b); }
- };
-
- /**
- * Function that returns <tt>Math.max(a,b)</tt>.
- */
- public static final DoubleDoubleFunction max = new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return Math.max(a,b); }
- };
-
- /**
- * Function that returns <tt>Math.min(a,b)</tt>.
- */
- public static final DoubleDoubleFunction min = new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return Math.min(a,b); }
- };
-
- /**
- * Function that returns <tt>a - b</tt>.
- */
- public static final DoubleDoubleFunction minus = plusMult(-1);
- /*
- new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return a - b; }
- };
- */
-
- /**
- * Function that returns <tt>a % b</tt>.
- */
- public static final DoubleDoubleFunction mod = new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return a % b; }
- };
-
- /**
- * Function that returns <tt>a * b</tt>.
- */
- public static final DoubleDoubleFunction mult = new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return a * b; }
- };
-
- /**
- * Function that returns <tt>a + b</tt>.
- */
- public static final DoubleDoubleFunction plus = plusMult(1);
- /*
- new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return a + b; }
- };
- */
-
- /**
- * Function that returns <tt>Math.abs(a) + Math.abs(b)</tt>.
- */
- public static final DoubleDoubleFunction plusAbs = new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return Math.abs(a) + Math.abs(b); }
- };
-
- /**
- * Function that returns <tt>Math.pow(a,b)</tt>.
- */
- public static final DoubleDoubleFunction pow = new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return Math.pow(a,b); }
- };
+ /**
+ Little trick to allow for "aliasing", that is, renaming this class.
+ Writing code like
+ <p>
+ <tt>Functions.chain(Functions.plus,Functions.sin,Functions.chain(Functions.square,Functions.cos));</tt>
+ <p>
+ is a bit awkward, to say the least.
+ Using the aliasing you can instead write
+ <p>
+ <tt>Functions F = Functions.functions; <br>
+ F.chain(F.plus,F.sin,F.chain(F.square,F.cos));</tt>
+ */
+ public static final Functions functions = new Functions();
+
+ /*****************************
+ * <H3>Unary functions</H3>
+ *****************************/
+ /**
+ * Function that returns <tt>Math.abs(a)</tt>.
+ */
+ public static final DoubleFunction abs = new DoubleFunction() {
+ public final double apply(double a) { return Math.abs(a); }
+ };
+
+ /**
+ * Function that returns <tt>Math.acos(a)</tt>.
+ */
+ public static final DoubleFunction acos = new DoubleFunction() {
+ public final double apply(double a) { return Math.acos(a); }
+ };
+
+ /**
+ * Function that returns <tt>com.imsl.math.Sfun.acosh(a)</tt>.
+ */
+ /*
+ public static final DoubleFunction acosh = new DoubleFunction() {
+ public final double apply(double a) { return Sfun.acosh(a); }
+ };
+ */
+
+ /**
+ * Function that returns <tt>Math.asin(a)</tt>.
+ */
+ public static final DoubleFunction asin = new DoubleFunction() {
+ public final double apply(double a) { return Math.asin(a); }
+ };
+
+ /**
+ * Function that returns <tt>com.imsl.math.Sfun.asinh(a)</tt>.
+ */
+ /*
+ public static final DoubleFunction asinh = new DoubleFunction() {
+ public final double apply(double a) { return Sfun.asinh(a); }
+ };
+ */
+
+ /**
+ * Function that returns <tt>Math.atan(a)</tt>.
+ */
+ public static final DoubleFunction atan = new DoubleFunction() {
+ public final double apply(double a) { return Math.atan(a); }
+ };
+
+ /**
+ * Function that returns <tt>com.imsl.math.Sfun.atanh(a)</tt>.
+ */
+ /*
+ public static final DoubleFunction atanh = new DoubleFunction() {
+ public final double apply(double a) { return Sfun.atanh(a); }
+ };
+ */
+
+ /**
+ * Function that returns <tt>Math.ceil(a)</tt>.
+ */
+ public static final DoubleFunction ceil = new DoubleFunction() {
+ public final double apply(double a) { return Math.ceil(a); }
+ };
+
+ /**
+ * Function that returns <tt>Math.cos(a)</tt>.
+ */
+ public static final DoubleFunction cos = new DoubleFunction() {
+ public final double apply(double a) { return Math.cos(a); }
+ };
+
+ /**
+ * Function that returns <tt>com.imsl.math.Sfun.cosh(a)</tt>.
+ */
+ /*
+ public static final DoubleFunction cosh = new DoubleFunction() {
+ public final double apply(double a) { return Sfun.cosh(a); }
+ };
+ */
+
+ /**
+ * Function that returns <tt>com.imsl.math.Sfun.cot(a)</tt>.
+ */
+ /*
+ public static final DoubleFunction cot = new DoubleFunction() {
+ public final double apply(double a) { return Sfun.cot(a); }
+ };
+ */
+
+ /**
+ * Function that returns <tt>com.imsl.math.Sfun.erf(a)</tt>.
+ */
+ /*
+ public static final DoubleFunction erf = new DoubleFunction() {
+ public final double apply(double a) { return Sfun.erf(a); }
+ };
+ */
+
+ /**
+ * Function that returns <tt>com.imsl.math.Sfun.erfc(a)</tt>.
+ */
+ /*
+ public static final DoubleFunction erfc = new DoubleFunction() {
+ public final double apply(double a) { return Sfun.erfc(a); }
+ };
+ */
+
+ /**
+ * Function that returns <tt>Math.exp(a)</tt>.
+ */
+ public static final DoubleFunction exp = new DoubleFunction() {
+ public final double apply(double a) { return Math.exp(a); }
+ };
+
+ /**
+ * Function that returns <tt>Math.floor(a)</tt>.
+ */
+ public static final DoubleFunction floor = new DoubleFunction() {
+ public final double apply(double a) { return Math.floor(a); }
+ };
+
+ /**
+ * Function that returns <tt>com.imsl.math.Sfun.gamma(a)</tt>.
+ */
+ /*
+ public static final DoubleFunction gamma = new DoubleFunction() {
+ public final double apply(double a) { return Sfun.gamma(a); }
+ };
+ */
+
+ /**
+ * Function that returns its argument.
+ */
+ public static final DoubleFunction identity = new DoubleFunction() {
+ public final double apply(double a) { return a; }
+ };
+
+ /**
+ * Function that returns <tt>1.0 / a</tt>.
+ */
+ public static final DoubleFunction inv = new DoubleFunction() {
+ public final double apply(double a) { return 1.0 / a; }
+ };
+
+ /**
+ * Function that returns <tt>Math.log(a)</tt>.
+ */
+ public static final DoubleFunction log = new DoubleFunction() {
+ public final double apply(double a) { return Math.log(a); }
+ };
+
+ /**
+ * Function that returns <tt>com.imsl.math.Sfun.log10(a)</tt>.
+ */
+ /*
+ public static final DoubleFunction log10 = new DoubleFunction() {
+ public final double apply(double a) { return Sfun.log10(a); }
+ };
+ */
+
+ /**
+ * Function that returns <tt>Math.log(a) / Math.log(2)</tt>.
+ */
+ public static final DoubleFunction log2 = new DoubleFunction() {
+ // 1.0 / Math.log(2) == 1.4426950408889634
+ public final double apply(double a) { return Math.log(a) * 1.4426950408889634; }
+ };
+
+ /**
+ * Function that returns <tt>com.imsl.math.Sfun.logGamma(a)</tt>.
+ */
+ /*
+ public static final DoubleFunction logGamma = new DoubleFunction() {
+ public final double apply(double a) { return Sfun.logGamma(a); }
+ };
+ */
+
+ /**
+ * Function that returns <tt>-a</tt>.
+ */
+ public static final DoubleFunction neg = new DoubleFunction() {
+ public final double apply(double a) { return -a; }
+ };
+
+ /**
+ * Function that returns <tt>Math.rint(a)</tt>.
+ */
+ public static final DoubleFunction rint = new DoubleFunction() {
+ public final double apply(double a) { return Math.rint(a); }
+ };
+
+ /**
+ * Function that returns <tt>a < 0 ? -1 : a > 0 ? 1 : 0</tt>.
+ */
+ public static final DoubleFunction sign = new DoubleFunction() {
+ public final double apply(double a) { return a < 0 ? -1 : a > 0 ? 1 : 0; }
+ };
+
+ /**
+ * Function that returns <tt>Math.sin(a)</tt>.
+ */
+ public static final DoubleFunction sin = new DoubleFunction() {
+ public final double apply(double a) { return Math.sin(a); }
+ };
+
+ /**
+ * Function that returns <tt>com.imsl.math.Sfun.sinh(a)</tt>.
+ */
+ /*
+ public static final DoubleFunction sinh = new DoubleFunction() {
+ public final double apply(double a) { return Sfun.sinh(a); }
+ };
+ */
+
+ /**
+ * Function that returns <tt>Math.sqrt(a)</tt>.
+ */
+ public static final DoubleFunction sqrt = new DoubleFunction() {
+ public final double apply(double a) { return Math.sqrt(a); }
+ };
+
+ /**
+ * Function that returns <tt>a * a</tt>.
+ */
+ public static final DoubleFunction square = new DoubleFunction() {
+ public final double apply(double a) { return a * a; }
+ };
+
+ /**
+ * Function that returns <tt>Math.tan(a)</tt>.
+ */
+ public static final DoubleFunction tan = new DoubleFunction() {
+ public final double apply(double a) { return Math.tan(a); }
+ };
+
+ /**
+ * Function that returns <tt>com.imsl.math.Sfun.tanh(a)</tt>.
+ */
+ /*
+ public static final DoubleFunction tanh = new DoubleFunction() {
+ public final double apply(double a) { return Sfun.tanh(a); }
+ };
+ */
+
+ /**
+ * Function that returns <tt>Math.toDegrees(a)</tt>.
+ */
+ /*
+ public static final DoubleFunction toDegrees = new DoubleFunction() {
+ public final double apply(double a) { return Math.toDegrees(a); }
+ };
+ */
+
+ /**
+ * Function that returns <tt>Math.toRadians(a)</tt>.
+ */
+ /*
+ public static final DoubleFunction toRadians = new DoubleFunction() {
+ public final double apply(double a) { return Math.toRadians(a); }
+ };
+ */
+
+
+
+ /*****************************
+ * <H3>Binary functions</H3>
+ *****************************/
+
+ /**
+ * Function that returns <tt>Math.atan2(a,b)</tt>.
+ */
+ public static final DoubleDoubleFunction atan2 = new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return Math.atan2(a,b); }
+ };
+
+ /**
+ * Function that returns <tt>com.imsl.math.Sfun.logBeta(a,b)</tt>.
+ */
+ /*
+ public static final DoubleDoubleFunction logBeta = new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return Sfun.logBeta(a,b); }
+ };
+ */
+
+
+ /**
+ * Function that returns <tt>a < b ? -1 : a > b ? 1 : 0</tt>.
+ */
+ public static final DoubleDoubleFunction compare = new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return a < b ? -1 : a > b ? 1 : 0; }
+ };
+
+ /**
+ * Function that returns <tt>a / b</tt>.
+ */
+ public static final DoubleDoubleFunction div = new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return a / b; }
+ };
+
+ /**
+ * Function that returns <tt>a == b ? 1 : 0</tt>.
+ */
+ public static final DoubleDoubleFunction equals = new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return a == b ? 1 : 0; }
+ };
+
+ /**
+ * Function that returns <tt>a > b ? 1 : 0</tt>.
+ */
+ public static final DoubleDoubleFunction greater = new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return a > b ? 1 : 0; }
+ };
+
+ /**
+ * Function that returns <tt>Math.IEEEremainder(a,b)</tt>.
+ */
+ public static final DoubleDoubleFunction IEEEremainder = new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return Math.IEEEremainder(a,b); }
+ };
+
+ /**
+ * Function that returns <tt>a == b</tt>.
+ */
+ public static final DoubleDoubleProcedure isEqual = new DoubleDoubleProcedure() {
+ public final boolean apply(double a, double b) { return a == b; }
+ };
+
+ /**
+ * Function that returns <tt>a < b</tt>.
+ */
+ public static final DoubleDoubleProcedure isLess = new DoubleDoubleProcedure() {
+ public final boolean apply(double a, double b) { return a < b; }
+ };
+
+ /**
+ * Function that returns <tt>a > b</tt>.
+ */
+ public static final DoubleDoubleProcedure isGreater = new DoubleDoubleProcedure() {
+ public final boolean apply(double a, double b) { return a > b; }
+ };
+
+ /**
+ * Function that returns <tt>a < b ? 1 : 0</tt>.
+ */
+ public static final DoubleDoubleFunction less = new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return a < b ? 1 : 0; }
+ };
+
+ /**
+ * Function that returns <tt>Math.log(a) / Math.log(b)</tt>.
+ */
+ public static final DoubleDoubleFunction lg = new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return Math.log(a) / Math.log(b); }
+ };
+
+ /**
+ * Function that returns <tt>Math.max(a,b)</tt>.
+ */
+ public static final DoubleDoubleFunction max = new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return Math.max(a,b); }
+ };
+
+ /**
+ * Function that returns <tt>Math.min(a,b)</tt>.
+ */
+ public static final DoubleDoubleFunction min = new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return Math.min(a,b); }
+ };
+
+ /**
+ * Function that returns <tt>a - b</tt>.
+ */
+ public static final DoubleDoubleFunction minus = plusMult(-1);
+ /*
+ new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return a - b; }
+ };
+ */
+
+ /**
+ * Function that returns <tt>a % b</tt>.
+ */
+ public static final DoubleDoubleFunction mod = new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return a % b; }
+ };
+
+ /**
+ * Function that returns <tt>a * b</tt>.
+ */
+ public static final DoubleDoubleFunction mult = new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return a * b; }
+ };
+
+ /**
+ * Function that returns <tt>a + b</tt>.
+ */
+ public static final DoubleDoubleFunction plus = plusMult(1);
+ /*
+ new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return a + b; }
+ };
+ */
+
+ /**
+ * Function that returns <tt>Math.abs(a) + Math.abs(b)</tt>.
+ */
+ public static final DoubleDoubleFunction plusAbs = new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return Math.abs(a) + Math.abs(b); }
+ };
+
+ /**
+ * Function that returns <tt>Math.pow(a,b)</tt>.
+ */
+ public static final DoubleDoubleFunction pow = new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return Math.pow(a,b); }
+ };
/**
* Makes this class non instantiable, but still let's others inherit from it.
*/
@@ -593,9 +593,9 @@
* <tt>a</tt> is a variable, <tt>from</tt> and <tt>to</tt> are fixed.
*/
public static DoubleFunction between(final double from, final double to) {
- return new DoubleFunction() {
- public final double apply(double a) { return (from<=a && a<=to) ? 1 : 0; }
- };
+ return new DoubleFunction() {
+ public final double apply(double a) { return (from<=a && a<=to) ? 1 : 0; }
+ };
}
/**
* Constructs a unary function from a binary function with the first operand (argument) fixed to the given constant <tt>c</tt>.
@@ -605,9 +605,9 @@
* @return the unary function <tt>function(c,var)</tt>.
*/
public static DoubleFunction bindArg1(final DoubleDoubleFunction function, final double c) {
- return new DoubleFunction() {
- public final double apply(double var) { return function.apply(c,var); }
- };
+ return new DoubleFunction() {
+ public final double apply(double var) { return function.apply(c,var); }
+ };
}
/**
* Constructs a unary function from a binary function with the second operand (argument) fixed to the given constant <tt>c</tt>.
@@ -617,9 +617,9 @@
* @return the unary function <tt>function(var,c)</tt>.
*/
public static DoubleFunction bindArg2(final DoubleDoubleFunction function, final double c) {
- return new DoubleFunction() {
- public final double apply(double var) { return function.apply(var,c); }
- };
+ return new DoubleFunction() {
+ public final double apply(double var) { return function.apply(var,c); }
+ };
}
/**
* Constructs the function <tt>f( g(a), h(b) )</tt>.
@@ -630,9 +630,9 @@
* @return the binary function <tt>f( g(a), h(b) )</tt>.
*/
public static DoubleDoubleFunction chain(final DoubleDoubleFunction f, final DoubleFunction g, final DoubleFunction h) {
- return new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return f.apply(g.apply(a), h.apply(b)); }
- };
+ return new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return f.apply(g.apply(a), h.apply(b)); }
+ };
}
/**
* Constructs the function <tt>g( h(a,b) )</tt>.
@@ -642,9 +642,9 @@
* @return the unary function <tt>g( h(a,b) )</tt>.
*/
public static DoubleDoubleFunction chain(final DoubleFunction g, final DoubleDoubleFunction h) {
- return new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return g.apply(h.apply(a,b)); }
- };
+ return new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return g.apply(h.apply(a,b)); }
+ };
}
/**
* Constructs the function <tt>g( h(a) )</tt>.
@@ -654,299 +654,299 @@
* @return the unary function <tt>g( h(a) )</tt>.
*/
public static DoubleFunction chain(final DoubleFunction g, final DoubleFunction h) {
- return new DoubleFunction() {
- public final double apply(double a) { return g.apply(h.apply(a)); }
- };
+ return new DoubleFunction() {
+ public final double apply(double a) { return g.apply(h.apply(a)); }
+ };
}
/**
* Constructs a function that returns <tt>a < b ? -1 : a > b ? 1 : 0</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleFunction compare(final double b) {
- return new DoubleFunction() {
- public final double apply(double a) { return a < b ? -1 : a > b ? 1 : 0; }
- };
+ return new DoubleFunction() {
+ public final double apply(double a) { return a < b ? -1 : a > b ? 1 : 0; }
+ };
}
/**
* Constructs a function that returns the constant <tt>c</tt>.
*/
public static DoubleFunction constant(final double c) {
- return new DoubleFunction() {
- public final double apply(double a) { return c; }
- };
+ return new DoubleFunction() {
+ public final double apply(double a) { return c; }
+ };
}
/**
* Demonstrates usage of this class.
*/
public static void demo1() {
- org.apache.mahout.jet.math.Functions F = org.apache.mahout.jet.math.Functions.functions;
- double a = 0.5;
- double b = 0.2;
- double v = Math.sin(a) + Math.pow(Math.cos(b),2);
- System.out.println(v);
- DoubleDoubleFunction f = F.chain(F.plus,F.sin,F.chain(F.square,F.cos));
- //DoubleDoubleFunction f = F.chain(plus,sin,F.chain(square,cos));
- System.out.println(f.apply(a,b));
- DoubleDoubleFunction g = new DoubleDoubleFunction() {
- public final double apply(double x, double y) { return Math.sin(x) + Math.pow(Math.cos(y),2); }
- };
- System.out.println(g.apply(a,b));
- DoubleFunction m = F.plus(3);
- DoubleFunction n = F.plus(4);
- System.out.println(m.apply(0));
- System.out.println(n.apply(0));
+ org.apache.mahout.jet.math.Functions F = org.apache.mahout.jet.math.Functions.functions;
+ double a = 0.5;
+ double b = 0.2;
+ double v = Math.sin(a) + Math.pow(Math.cos(b),2);
+ System.out.println(v);
+ DoubleDoubleFunction f = F.chain(F.plus,F.sin,F.chain(F.square,F.cos));
+ //DoubleDoubleFunction f = F.chain(plus,sin,F.chain(square,cos));
+ System.out.println(f.apply(a,b));
+ DoubleDoubleFunction g = new DoubleDoubleFunction() {
+ public final double apply(double x, double y) { return Math.sin(x) + Math.pow(Math.cos(y),2); }
+ };
+ System.out.println(g.apply(a,b));
+ DoubleFunction m = F.plus(3);
+ DoubleFunction n = F.plus(4);
+ System.out.println(m.apply(0));
+ System.out.println(n.apply(0));
}
/**
* Benchmarks and demonstrates usage of trivial and complex functions.
*/
public static void demo2(int size) {
- org.apache.mahout.jet.math.Functions F = org.apache.mahout.jet.math.Functions.functions;
- System.out.println("\n\n");
- double a = 0.0;
- double b = 0.0;
- double v = Math.abs(Math.sin(a) + Math.pow(Math.cos(b),2));
- //double v = Math.sin(a) + Math.pow(Math.cos(b),2);
- //double v = a + b;
- System.out.println(v);
-
- //DoubleDoubleFunction f = F.chain(F.plus,F.identity,F.identity);
- DoubleDoubleFunction f = F.chain(F.abs,F.chain(F.plus,F.sin,F.chain(F.square,F.cos)));
- //DoubleDoubleFunction f = F.chain(F.plus,F.sin,F.chain(F.square,F.cos));
- //DoubleDoubleFunction f = F.plus;
-
- System.out.println(f.apply(a,b));
- DoubleDoubleFunction g = new DoubleDoubleFunction() {
- public final double apply(double x, double y) { return Math.abs(Math.sin(x) + Math.pow(Math.cos(y),2)); }
- //public final double apply(double x, double y) { return x+y; }
- };
- System.out.println(g.apply(a,b));
-
- // emptyLoop
- org.apache.mahout.matrix.Timer emptyLoop = new org.apache.mahout.matrix.Timer().start();
- a = 0; b = 0;
- double sum = 0;
- for (int i=size; --i >= 0; ) {
- sum += a;
- a++;
- b++;
- }
- emptyLoop.stop().display();
- System.out.println("empty sum="+sum);
-
- org.apache.mahout.matrix.Timer timer = new org.apache.mahout.matrix.Timer().start();
- a = 0; b = 0;
- sum = 0;
- for (int i=size; --i >= 0; ) {
- sum += Math.abs(Math.sin(a) + Math.pow(Math.cos(b),2));
- //sum += a + b;
- a++; b++;
- }
- timer.stop().display();
- System.out.println("evals / sec = "+size / timer.minus(emptyLoop).seconds());
- System.out.println("sum="+sum);
-
- timer.reset().start();
- a = 0; b = 0;
- sum = 0;
- for (int i=size; --i >= 0; ) {
- sum += f.apply(a,b);
- a++; b++;
- }
- timer.stop().display();
- System.out.println("evals / sec = "+size / timer.minus(emptyLoop).seconds());
- System.out.println("sum="+sum);
-
- timer.reset().start();
- a = 0; b = 0;
- sum = 0;
- for (int i=size; --i >= 0; ) {
- sum += g.apply(a,b);
- a++; b++;
- }
- timer.stop().display();
- System.out.println("evals / sec = "+size / timer.minus(emptyLoop).seconds());
- System.out.println("sum="+sum);
-
+ org.apache.mahout.jet.math.Functions F = org.apache.mahout.jet.math.Functions.functions;
+ System.out.println("\n\n");
+ double a = 0.0;
+ double b = 0.0;
+ double v = Math.abs(Math.sin(a) + Math.pow(Math.cos(b),2));
+ //double v = Math.sin(a) + Math.pow(Math.cos(b),2);
+ //double v = a + b;
+ System.out.println(v);
+
+ //DoubleDoubleFunction f = F.chain(F.plus,F.identity,F.identity);
+ DoubleDoubleFunction f = F.chain(F.abs,F.chain(F.plus,F.sin,F.chain(F.square,F.cos)));
+ //DoubleDoubleFunction f = F.chain(F.plus,F.sin,F.chain(F.square,F.cos));
+ //DoubleDoubleFunction f = F.plus;
+
+ System.out.println(f.apply(a,b));
+ DoubleDoubleFunction g = new DoubleDoubleFunction() {
+ public final double apply(double x, double y) { return Math.abs(Math.sin(x) + Math.pow(Math.cos(y),2)); }
+ //public final double apply(double x, double y) { return x+y; }
+ };
+ System.out.println(g.apply(a,b));
+
+ // emptyLoop
+ org.apache.mahout.matrix.Timer emptyLoop = new org.apache.mahout.matrix.Timer().start();
+ a = 0; b = 0;
+ double sum = 0;
+ for (int i=size; --i >= 0; ) {
+ sum += a;
+ a++;
+ b++;
+ }
+ emptyLoop.stop().display();
+ System.out.println("empty sum="+sum);
+
+ org.apache.mahout.matrix.Timer timer = new org.apache.mahout.matrix.Timer().start();
+ a = 0; b = 0;
+ sum = 0;
+ for (int i=size; --i >= 0; ) {
+ sum += Math.abs(Math.sin(a) + Math.pow(Math.cos(b),2));
+ //sum += a + b;
+ a++; b++;
+ }
+ timer.stop().display();
+ System.out.println("evals / sec = "+size / timer.minus(emptyLoop).seconds());
+ System.out.println("sum="+sum);
+
+ timer.reset().start();
+ a = 0; b = 0;
+ sum = 0;
+ for (int i=size; --i >= 0; ) {
+ sum += f.apply(a,b);
+ a++; b++;
+ }
+ timer.stop().display();
+ System.out.println("evals / sec = "+size / timer.minus(emptyLoop).seconds());
+ System.out.println("sum="+sum);
+
+ timer.reset().start();
+ a = 0; b = 0;
+ sum = 0;
+ for (int i=size; --i >= 0; ) {
+ sum += g.apply(a,b);
+ a++; b++;
+ }
+ timer.stop().display();
+ System.out.println("evals / sec = "+size / timer.minus(emptyLoop).seconds());
+ System.out.println("sum="+sum);
+
}
/**
* Constructs a function that returns <tt>a / b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleFunction div(final double b) {
- return mult(1 / b);
+ return mult(1 / b);
}
/**
* Constructs a function that returns <tt>a == b ? 1 : 0</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleFunction equals(final double b) {
- return new DoubleFunction() {
- public final double apply(double a) { return a == b ? 1 : 0; }
- };
+ return new DoubleFunction() {
+ public final double apply(double a) { return a == b ? 1 : 0; }
+ };
}
/**
* Constructs a function that returns <tt>a > b ? 1 : 0</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleFunction greater(final double b) {
- return new DoubleFunction() {
- public final double apply(double a) { return a > b ? 1 : 0; }
- };
+ return new DoubleFunction() {
+ public final double apply(double a) { return a > b ? 1 : 0; }
+ };
}
/**
* Constructs a function that returns <tt>Math.IEEEremainder(a,b)</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleFunction IEEEremainder(final double b) {
- return new DoubleFunction() {
- public final double apply(double a) { return Math.IEEEremainder(a,b); }
- };
+ return new DoubleFunction() {
+ public final double apply(double a) { return Math.IEEEremainder(a,b); }
+ };
}
/**
* Constructs a function that returns <tt>from<=a && a<=to</tt>.
* <tt>a</tt> is a variable, <tt>from</tt> and <tt>to</tt> are fixed.
*/
public static DoubleProcedure isBetween(final double from, final double to) {
- return new DoubleProcedure() {
- public final boolean apply(double a) { return from<=a && a<=to; }
- };
+ return new DoubleProcedure() {
+ public final boolean apply(double a) { return from<=a && a<=to; }
+ };
}
/**
* Constructs a function that returns <tt>a == b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleProcedure isEqual(final double b) {
- return new DoubleProcedure() {
- public final boolean apply(double a) { return a==b; }
- };
+ return new DoubleProcedure() {
+ public final boolean apply(double a) { return a==b; }
+ };
}
/**
* Constructs a function that returns <tt>a > b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleProcedure isGreater(final double b) {
- return new DoubleProcedure() {
- public final boolean apply(double a) { return a > b; }
- };
+ return new DoubleProcedure() {
+ public final boolean apply(double a) { return a > b; }
+ };
}
/**
* Constructs a function that returns <tt>a < b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleProcedure isLess(final double b) {
- return new DoubleProcedure() {
- public final boolean apply(double a) { return a < b; }
- };
+ return new DoubleProcedure() {
+ public final boolean apply(double a) { return a < b; }
+ };
}
/**
* Constructs a function that returns <tt>a < b ? 1 : 0</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleFunction less(final double b) {
- return new DoubleFunction() {
- public final double apply(double a) { return a < b ? 1 : 0; }
- };
+ return new DoubleFunction() {
+ public final double apply(double a) { return a < b ? 1 : 0; }
+ };
}
/**
* Constructs a function that returns <tt><tt>Math.log(a) / Math.log(b)</tt></tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleFunction lg(final double b) {
- return new DoubleFunction() {
- private final double logInv = 1 / Math.log(b); // cached for speed
- public final double apply(double a) { return Math.log(a) * logInv; }
- };
+ return new DoubleFunction() {
+ private final double logInv = 1 / Math.log(b); // cached for speed
+ public final double apply(double a) { return Math.log(a) * logInv; }
+ };
}
/**
* Tests various methods of this class.
*/
protected static void main(String args[]) {
- int size = Integer.parseInt(args[0]);
- demo2(size);
- //demo1();
+ int size = Integer.parseInt(args[0]);
+ demo2(size);
+ //demo1();
}
/**
* Constructs a function that returns <tt>Math.max(a,b)</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleFunction max(final double b) {
- return new DoubleFunction() {
- public final double apply(double a) { return Math.max(a,b); }
- };
+ return new DoubleFunction() {
+ public final double apply(double a) { return Math.max(a,b); }
+ };
}
/**
* Constructs a function that returns <tt>Math.min(a,b)</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleFunction min(final double b) {
- return new DoubleFunction() {
- public final double apply(double a) { return Math.min(a,b); }
- };
+ return new DoubleFunction() {
+ public final double apply(double a) { return Math.min(a,b); }
+ };
}
/**
* Constructs a function that returns <tt>a - b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleFunction minus(final double b) {
- return plus(-b);
+ return plus(-b);
}
/**
* Constructs a function that returns <tt>a - b*constant</tt>.
* <tt>a</tt> and <tt>b</tt> are variables, <tt>constant</tt> is fixed.
*/
public static DoubleDoubleFunction minusMult(final double constant) {
- return plusMult(-constant);
+ return plusMult(-constant);
}
/**
* Constructs a function that returns <tt>a % b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleFunction mod(final double b) {
- return new DoubleFunction() {
- public final double apply(double a) { return a % b; }
- };
+ return new DoubleFunction() {
+ public final double apply(double a) { return a % b; }
+ };
}
/**
* Constructs a function that returns <tt>a * b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleFunction mult(final double b) {
- return new Mult(b);
- /*
- return new DoubleFunction() {
- public final double apply(double a) { return a * b; }
- };
- */
+ return new Mult(b);
+ /*
+ return new DoubleFunction() {
+ public final double apply(double a) { return a * b; }
+ };
+ */
}
/**
* Constructs a function that returns <tt>a + b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleFunction plus(final double b) {
- return new DoubleFunction() {
- public final double apply(double a) { return a + b; }
- };
+ return new DoubleFunction() {
+ public final double apply(double a) { return a + b; }
+ };
}
/**
* Constructs a function that returns <tt>a + b*constant</tt>.
* <tt>a</tt> and <tt>b</tt> are variables, <tt>constant</tt> is fixed.
*/
public static DoubleDoubleFunction plusMult(double constant) {
- return new PlusMult(constant);
- /*
- return new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return a + b*constant; }
- };
- */
+ return new PlusMult(constant);
+ /*
+ return new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return a + b*constant; }
+ };
+ */
}
/**
* Constructs a function that returns <tt>Math.pow(a,b)</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static DoubleFunction pow(final double b) {
- return new DoubleFunction() {
- public final double apply(double a) { return Math.pow(a,b); }
- };
+ return new DoubleFunction() {
+ public final double apply(double a) { return Math.pow(a,b); }
+ };
}
/**
* Constructs a function that returns a new uniform random number in the open unit interval <code>(0.0,1.0)</code> (excluding 0.0 and 1.0).
@@ -957,7 +957,7 @@
* Thus, if you are not happy with the default, just pass your favourite random generator to function evaluating methods.
*/
public static DoubleFunction random() {
- return new org.apache.mahout.jet.random.engine.MersenneTwister(new java.util.Date());
+ return new org.apache.mahout.jet.random.engine.MersenneTwister(new java.util.Date());
}
/**
* Constructs a function that returns the number rounded to the given precision; <tt>Math.rint(a/precision)*precision</tt>.
@@ -968,9 +968,9 @@
* </pre>
*/
public static DoubleFunction round(final double precision) {
- return new DoubleFunction() {
- public final double apply(double a) { return Math.rint(a/precision)*precision; }
- };
+ return new DoubleFunction() {
+ public final double apply(double a) { return Math.rint(a/precision)*precision; }
+ };
}
/**
* Constructs a function that returns <tt>function.apply(b,a)</tt>, i.e. applies the function with the first operand as second operand and the second operand as first operand.
@@ -979,8 +979,8 @@
* @return the binary function <tt>function(b,a)</tt>.
*/
public static DoubleDoubleFunction swapArgs(final DoubleDoubleFunction function) {
- return new DoubleDoubleFunction() {
- public final double apply(double a, double b) { return function.apply(b,a); }
- };
+ return new DoubleDoubleFunction() {
+ public final double apply(double a, double b) { return function.apply(b,a); }
+ };
}
}
Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/IntFunctions.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/IntFunctions.java?rev=883972&r1=883971&r2=883972&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/IntFunctions.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/IntFunctions.java Wed Nov 25 03:31:47 2009
@@ -26,230 +26,230 @@
*/
@Deprecated
public class IntFunctions extends Object {
- /**
- Little trick to allow for "aliasing", that is, renaming this class.
- Writing code like
- <p>
- <tt>IntFunctions.chain(IntFunctions.plus,IntFunctions.mult(3),IntFunctions.chain(IntFunctions.square,IntFunctions.div(2)));</tt>
- <p>
- is a bit awkward, to say the least.
- Using the aliasing you can instead write
- <p>
- <tt>IntFunctions F = IntFunctions.intFunctions; <br>
- F.chain(F.plus,F.mult(3),F.chain(F.square,F.div(2)));</tt>
- <p>
- */
- public static final IntFunctions intFunctions = new IntFunctions();
-
- /*****************************
- * <H3>Unary functions</H3>
- *****************************/
- /**
- * Function that returns <tt>Math.abs(a) == (a < 0) ? -a : a</tt>.
- */
- public static final IntFunction abs = new IntFunction() {
- public final int apply(int a) { return (a < 0) ? -a : a; }
- };
-
- /**
- * Function that returns <tt>a--</tt>.
- */
- public static final IntFunction dec = new IntFunction() {
- public final int apply(int a) { return a--; }
- };
-
- /**
- * Function that returns <tt>(int) Arithmetic.factorial(a)</tt>.
- */
- public static final IntFunction factorial = new IntFunction() {
- public final int apply(int a) { return (int) Arithmetic.factorial(a); }
- };
-
- /**
- * Function that returns its argument.
- */
- public static final IntFunction identity = new IntFunction() {
- public final int apply(int a) { return a; }
- };
-
- /**
- * Function that returns <tt>a++</tt>.
- */
- public static final IntFunction inc = new IntFunction() {
- public final int apply(int a) { return a++; }
- };
-
- /**
- * Function that returns <tt>-a</tt>.
- */
- public static final IntFunction neg = new IntFunction() {
- public final int apply(int a) { return -a; }
- };
-
- /**
- * Function that returns <tt>~a</tt>.
- */
- public static final IntFunction not = new IntFunction() {
- public final int apply(int a) { return ~a; }
- };
-
- /**
- * Function that returns <tt>a < 0 ? -1 : a > 0 ? 1 : 0</tt>.
- */
- public static final IntFunction sign = new IntFunction() {
- public final int apply(int a) { return a < 0 ? -1 : a > 0 ? 1 : 0; }
- };
-
- /**
- * Function that returns <tt>a * a</tt>.
- */
- public static final IntFunction square = new IntFunction() {
- public final int apply(int a) { return a * a; }
- };
-
+ /**
+ Little trick to allow for "aliasing", that is, renaming this class.
+ Writing code like
+ <p>
+ <tt>IntFunctions.chain(IntFunctions.plus,IntFunctions.mult(3),IntFunctions.chain(IntFunctions.square,IntFunctions.div(2)));</tt>
+ <p>
+ is a bit awkward, to say the least.
+ Using the aliasing you can instead write
+ <p>
+ <tt>IntFunctions F = IntFunctions.intFunctions; <br>
+ F.chain(F.plus,F.mult(3),F.chain(F.square,F.div(2)));</tt>
+ <p>
+ */
+ public static final IntFunctions intFunctions = new IntFunctions();
+
+ /*****************************
+ * <H3>Unary functions</H3>
+ *****************************/
+ /**
+ * Function that returns <tt>Math.abs(a) == (a < 0) ? -a : a</tt>.
+ */
+ public static final IntFunction abs = new IntFunction() {
+ public final int apply(int a) { return (a < 0) ? -a : a; }
+ };
+
+ /**
+ * Function that returns <tt>a--</tt>.
+ */
+ public static final IntFunction dec = new IntFunction() {
+ public final int apply(int a) { return a--; }
+ };
+
+ /**
+ * Function that returns <tt>(int) Arithmetic.factorial(a)</tt>.
+ */
+ public static final IntFunction factorial = new IntFunction() {
+ public final int apply(int a) { return (int) Arithmetic.factorial(a); }
+ };
+
+ /**
+ * Function that returns its argument.
+ */
+ public static final IntFunction identity = new IntFunction() {
+ public final int apply(int a) { return a; }
+ };
+
+ /**
+ * Function that returns <tt>a++</tt>.
+ */
+ public static final IntFunction inc = new IntFunction() {
+ public final int apply(int a) { return a++; }
+ };
+
+ /**
+ * Function that returns <tt>-a</tt>.
+ */
+ public static final IntFunction neg = new IntFunction() {
+ public final int apply(int a) { return -a; }
+ };
+
+ /**
+ * Function that returns <tt>~a</tt>.
+ */
+ public static final IntFunction not = new IntFunction() {
+ public final int apply(int a) { return ~a; }
+ };
+
+ /**
+ * Function that returns <tt>a < 0 ? -1 : a > 0 ? 1 : 0</tt>.
+ */
+ public static final IntFunction sign = new IntFunction() {
+ public final int apply(int a) { return a < 0 ? -1 : a > 0 ? 1 : 0; }
+ };
+
+ /**
+ * Function that returns <tt>a * a</tt>.
+ */
+ public static final IntFunction square = new IntFunction() {
+ public final int apply(int a) { return a * a; }
+ };
+
- /*****************************
- * <H3>Binary functions</H3>
- *****************************/
-
- /**
- * Function that returns <tt>a & b</tt>.
- */
- public static final IntIntFunction and = new IntIntFunction() {
- public final int apply(int a, int b) { return a & b; }
- };
-
- /**
- * Function that returns <tt>a < b ? -1 : a > b ? 1 : 0</tt>.
- */
- public static final IntIntFunction compare = new IntIntFunction() {
- public final int apply(int a, int b) { return a < b ? -1 : a > b ? 1 : 0; }
- };
-
- /**
- * Function that returns <tt>a / b</tt>.
- */
- public static final IntIntFunction div = new IntIntFunction() {
- public final int apply(int a, int b) { return a / b; }
- };
-
- /**
- * Function that returns <tt>a == b ? 1 : 0</tt>.
- */
- public static final IntIntFunction equals = new IntIntFunction() {
- public final int apply(int a, int b) { return a == b ? 1 : 0; }
- };
-
- /**
- * Function that returns <tt>a == b</tt>.
- */
- public static final IntIntProcedure isEqual = new IntIntProcedure() {
- public final boolean apply(int a, int b) { return a == b; }
- };
-
- /**
- * Function that returns <tt>a < b</tt>.
- */
- public static final IntIntProcedure isLess = new IntIntProcedure() {
- public final boolean apply(int a, int b) { return a < b; }
- };
-
- /**
- * Function that returns <tt>a > b</tt>.
- */
- public static final IntIntProcedure isGreater = new IntIntProcedure() {
- public final boolean apply(int a, int b) { return a > b; }
- };
-
- /**
- * Function that returns <tt>Math.max(a,b)</tt>.
- */
- public static final IntIntFunction max = new IntIntFunction() {
- public final int apply(int a, int b) { return (a >= b) ? a : b; }
- };
-
- /**
- * Function that returns <tt>Math.min(a,b)</tt>.
- */
- public static final IntIntFunction min = new IntIntFunction() {
- public final int apply(int a, int b) { return (a <= b) ? a : b; }
- };
-
- /**
- * Function that returns <tt>a - b</tt>.
- */
- public static final IntIntFunction minus = new IntIntFunction() {
- public final int apply(int a, int b) { return a - b; }
- };
-
- /**
- * Function that returns <tt>a % b</tt>.
- */
- public static final IntIntFunction mod = new IntIntFunction() {
- public final int apply(int a, int b) { return a % b; }
- };
-
- /**
- * Function that returns <tt>a * b</tt>.
- */
- public static final IntIntFunction mult = new IntIntFunction() {
- public final int apply(int a, int b) { return a * b; }
- };
-
- /**
- * Function that returns <tt>a | b</tt>.
- */
- public static final IntIntFunction or = new IntIntFunction() {
- public final int apply(int a, int b) { return a | b; }
- };
-
- /**
- * Function that returns <tt>a + b</tt>.
- */
- public static final IntIntFunction plus = new IntIntFunction() {
- public final int apply(int a, int b) { return a + b; }
- };
-
- /**
- * Function that returns <tt>(int) Math.pow(a,b)</tt>.
- */
- public static final IntIntFunction pow = new IntIntFunction() {
- public final int apply(int a, int b) { return (int) Math.pow(a,b); }
- };
-
- /**
- * Function that returns <tt>a << b</tt>.
- */
- public static final IntIntFunction shiftLeft = new IntIntFunction() {
- public final int apply(int a, int b) { return a << b; }
- };
-
-
- /**
- * Function that returns <tt>a >> b</tt>.
- */
- public static final IntIntFunction shiftRightSigned = new IntIntFunction() {
- public final int apply(int a, int b) { return a >> b; }
- };
-
- /**
- * Function that returns <tt>a >>> b</tt>.
- */
- public static final IntIntFunction shiftRightUnsigned = new IntIntFunction() {
- public final int apply(int a, int b) { return a >>> b; }
- };
-
- /**
- * Function that returns <tt>a ^ b</tt>.
- */
- public static final IntIntFunction xor = new IntIntFunction() {
- public final int apply(int a, int b) { return a ^ b; }
- };
-
+ /*****************************
+ * <H3>Binary functions</H3>
+ *****************************/
+
+ /**
+ * Function that returns <tt>a & b</tt>.
+ */
+ public static final IntIntFunction and = new IntIntFunction() {
+ public final int apply(int a, int b) { return a & b; }
+ };
+
+ /**
+ * Function that returns <tt>a < b ? -1 : a > b ? 1 : 0</tt>.
+ */
+ public static final IntIntFunction compare = new IntIntFunction() {
+ public final int apply(int a, int b) { return a < b ? -1 : a > b ? 1 : 0; }
+ };
+
+ /**
+ * Function that returns <tt>a / b</tt>.
+ */
+ public static final IntIntFunction div = new IntIntFunction() {
+ public final int apply(int a, int b) { return a / b; }
+ };
+
+ /**
+ * Function that returns <tt>a == b ? 1 : 0</tt>.
+ */
+ public static final IntIntFunction equals = new IntIntFunction() {
+ public final int apply(int a, int b) { return a == b ? 1 : 0; }
+ };
+
+ /**
+ * Function that returns <tt>a == b</tt>.
+ */
+ public static final IntIntProcedure isEqual = new IntIntProcedure() {
+ public final boolean apply(int a, int b) { return a == b; }
+ };
+
+ /**
+ * Function that returns <tt>a < b</tt>.
+ */
+ public static final IntIntProcedure isLess = new IntIntProcedure() {
+ public final boolean apply(int a, int b) { return a < b; }
+ };
+
+ /**
+ * Function that returns <tt>a > b</tt>.
+ */
+ public static final IntIntProcedure isGreater = new IntIntProcedure() {
+ public final boolean apply(int a, int b) { return a > b; }
+ };
+
+ /**
+ * Function that returns <tt>Math.max(a,b)</tt>.
+ */
+ public static final IntIntFunction max = new IntIntFunction() {
+ public final int apply(int a, int b) { return (a >= b) ? a : b; }
+ };
+
+ /**
+ * Function that returns <tt>Math.min(a,b)</tt>.
+ */
+ public static final IntIntFunction min = new IntIntFunction() {
+ public final int apply(int a, int b) { return (a <= b) ? a : b; }
+ };
+
+ /**
+ * Function that returns <tt>a - b</tt>.
+ */
+ public static final IntIntFunction minus = new IntIntFunction() {
+ public final int apply(int a, int b) { return a - b; }
+ };
+
+ /**
+ * Function that returns <tt>a % b</tt>.
+ */
+ public static final IntIntFunction mod = new IntIntFunction() {
+ public final int apply(int a, int b) { return a % b; }
+ };
+
+ /**
+ * Function that returns <tt>a * b</tt>.
+ */
+ public static final IntIntFunction mult = new IntIntFunction() {
+ public final int apply(int a, int b) { return a * b; }
+ };
+
+ /**
+ * Function that returns <tt>a | b</tt>.
+ */
+ public static final IntIntFunction or = new IntIntFunction() {
+ public final int apply(int a, int b) { return a | b; }
+ };
+
+ /**
+ * Function that returns <tt>a + b</tt>.
+ */
+ public static final IntIntFunction plus = new IntIntFunction() {
+ public final int apply(int a, int b) { return a + b; }
+ };
+
+ /**
+ * Function that returns <tt>(int) Math.pow(a,b)</tt>.
+ */
+ public static final IntIntFunction pow = new IntIntFunction() {
+ public final int apply(int a, int b) { return (int) Math.pow(a,b); }
+ };
+
+ /**
+ * Function that returns <tt>a << b</tt>.
+ */
+ public static final IntIntFunction shiftLeft = new IntIntFunction() {
+ public final int apply(int a, int b) { return a << b; }
+ };
+
+
+ /**
+ * Function that returns <tt>a >> b</tt>.
+ */
+ public static final IntIntFunction shiftRightSigned = new IntIntFunction() {
+ public final int apply(int a, int b) { return a >> b; }
+ };
+
+ /**
+ * Function that returns <tt>a >>> b</tt>.
+ */
+ public static final IntIntFunction shiftRightUnsigned = new IntIntFunction() {
+ public final int apply(int a, int b) { return a >>> b; }
+ };
+
+ /**
+ * Function that returns <tt>a ^ b</tt>.
+ */
+ public static final IntIntFunction xor = new IntIntFunction() {
+ public final int apply(int a, int b) { return a ^ b; }
+ };
+
/**
* Makes this class non instantiable, but still let's others inherit from it.
*/
@@ -259,18 +259,18 @@
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction and(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return a & b; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return a & b; }
+ };
}
/**
* Constructs a function that returns <tt>(from<=a && a<=to) ? 1 : 0</tt>.
* <tt>a</tt> is a variable, <tt>from</tt> and <tt>to</tt> are fixed.
*/
public static IntFunction between(final int from, final int to) {
- return new IntFunction() {
- public final int apply(int a) { return (from<=a && a<=to) ? 1 : 0; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return (from<=a && a<=to) ? 1 : 0; }
+ };
}
/**
* Constructs a unary function from a binary function with the first operand (argument) fixed to the given constant <tt>c</tt>.
@@ -280,9 +280,9 @@
* @return the unary function <tt>function(c,var)</tt>.
*/
public static IntFunction bindArg1(final IntIntFunction function, final int c) {
- return new IntFunction() {
- public final int apply(int var) { return function.apply(c,var); }
- };
+ return new IntFunction() {
+ public final int apply(int var) { return function.apply(c,var); }
+ };
}
/**
* Constructs a unary function from a binary function with the second operand (argument) fixed to the given constant <tt>c</tt>.
@@ -292,9 +292,9 @@
* @return the unary function <tt>function(var,c)</tt>.
*/
public static IntFunction bindArg2(final IntIntFunction function, final int c) {
- return new IntFunction() {
- public final int apply(int var) { return function.apply(var,c); }
- };
+ return new IntFunction() {
+ public final int apply(int var) { return function.apply(var,c); }
+ };
}
/**
* Constructs the function <tt>g( h(a) )</tt>.
@@ -304,9 +304,9 @@
* @return the unary function <tt>g( h(a) )</tt>.
*/
public static IntFunction chain(final IntFunction g, final IntFunction h) {
- return new IntFunction() {
- public final int apply(int a) { return g.apply(h.apply(a)); }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return g.apply(h.apply(a)); }
+ };
}
/**
* Constructs the function <tt>g( h(a,b) )</tt>.
@@ -316,9 +316,9 @@
* @return the unary function <tt>g( h(a,b) )</tt>.
*/
public static IntIntFunction chain(final IntFunction g, final IntIntFunction h) {
- return new IntIntFunction() {
- public final int apply(int a, int b) { return g.apply(h.apply(a,b)); }
- };
+ return new IntIntFunction() {
+ public final int apply(int a, int b) { return g.apply(h.apply(a,b)); }
+ };
}
/**
* Constructs the function <tt>f( g(a), h(b) )</tt>.
@@ -329,152 +329,152 @@
* @return the binary function <tt>f( g(a), h(b) )</tt>.
*/
public static IntIntFunction chain(final IntIntFunction f, final IntFunction g, final IntFunction h) {
- return new IntIntFunction() {
- public final int apply(int a, int b) { return f.apply(g.apply(a), h.apply(b)); }
- };
+ return new IntIntFunction() {
+ public final int apply(int a, int b) { return f.apply(g.apply(a), h.apply(b)); }
+ };
}
/**
* Constructs a function that returns <tt>a < b ? -1 : a > b ? 1 : 0</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction compare(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return a < b ? -1 : a > b ? 1 : 0; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return a < b ? -1 : a > b ? 1 : 0; }
+ };
}
/**
* Constructs a function that returns the constant <tt>c</tt>.
*/
public static IntFunction constant(final int c) {
- return new IntFunction() {
- public final int apply(int a) { return c; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return c; }
+ };
}
/**
* Constructs a function that returns <tt>a / b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction div(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return a / b; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return a / b; }
+ };
}
/**
* Constructs a function that returns <tt>a == b ? 1 : 0</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction equals(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return a == b ? 1 : 0; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return a == b ? 1 : 0; }
+ };
}
/**
* Constructs a function that returns <tt>from<=a && a<=to</tt>.
* <tt>a</tt> is a variable, <tt>from</tt> and <tt>to</tt> are fixed.
*/
public static IntProcedure isBetween(final int from, final int to) {
- return new IntProcedure() {
- public final boolean apply(int a) { return from<=a && a<=to; }
- };
+ return new IntProcedure() {
+ public final boolean apply(int a) { return from<=a && a<=to; }
+ };
}
/**
* Constructs a function that returns <tt>a == b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntProcedure isEqual(final int b) {
- return new IntProcedure() {
- public final boolean apply(int a) { return a==b; }
- };
+ return new IntProcedure() {
+ public final boolean apply(int a) { return a==b; }
+ };
}
/**
* Constructs a function that returns <tt>a > b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntProcedure isGreater(final int b) {
- return new IntProcedure() {
- public final boolean apply(int a) { return a > b; }
- };
+ return new IntProcedure() {
+ public final boolean apply(int a) { return a > b; }
+ };
}
/**
* Constructs a function that returns <tt>a < b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntProcedure isLess(final int b) {
- return new IntProcedure() {
- public final boolean apply(int a) { return a < b; }
- };
+ return new IntProcedure() {
+ public final boolean apply(int a) { return a < b; }
+ };
}
/**
* Constructs a function that returns <tt>Math.max(a,b)</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction max(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return (a >= b) ? a : b; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return (a >= b) ? a : b; }
+ };
}
/**
* Constructs a function that returns <tt>Math.min(a,b)</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction min(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return (a <= b) ? a : b; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return (a <= b) ? a : b; }
+ };
}
/**
* Constructs a function that returns <tt>a - b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction minus(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return a - b; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return a - b; }
+ };
}
/**
* Constructs a function that returns <tt>a % b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction mod(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return a % b; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return a % b; }
+ };
}
/**
* Constructs a function that returns <tt>a * b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction mult(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return a * b; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return a * b; }
+ };
}
/**
* Constructs a function that returns <tt>a | b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction or(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return a | b; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return a | b; }
+ };
}
/**
* Constructs a function that returns <tt>a + b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction plus(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return a + b; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return a + b; }
+ };
}
/**
* Constructs a function that returns <tt>(int) Math.pow(a,b)</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction pow(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return (int) Math.pow(a,b); }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return (int) Math.pow(a,b); }
+ };
}
/**
* Constructs a function that returns a 32 bit uniformly distributed random number in the closed interval <tt>[Integer.MIN_VALUE,Integer.MAX_VALUE]</tt> (including <tt>Integer.MIN_VALUE</tt> and <tt>Integer.MAX_VALUE</tt>).
@@ -485,34 +485,34 @@
* Thus, if you are not happy with the default, just pass your favourite random generator to function evaluating methods.
*/
public static IntFunction random() {
- return new org.apache.mahout.jet.random.engine.MersenneTwister(new java.util.Date());
+ return new org.apache.mahout.jet.random.engine.MersenneTwister(new java.util.Date());
}
/**
* Constructs a function that returns <tt>a << b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction shiftLeft(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return a << b; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return a << b; }
+ };
}
/**
* Constructs a function that returns <tt>a >> b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction shiftRightSigned(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return a >> b; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return a >> b; }
+ };
}
/**
* Constructs a function that returns <tt>a >>> b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction shiftRightUnsigned(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return a >>> b; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return a >>> b; }
+ };
}
/**
* Constructs a function that returns <tt>function.apply(b,a)</tt>, i.e. applies the function with the first operand as second operand and the second operand as first operand.
@@ -521,17 +521,17 @@
* @return the binary function <tt>function(b,a)</tt>.
*/
public static IntIntFunction swapArgs(final IntIntFunction function) {
- return new IntIntFunction() {
- public final int apply(int a, int b) { return function.apply(b,a); }
- };
+ return new IntIntFunction() {
+ public final int apply(int a, int b) { return function.apply(b,a); }
+ };
}
/**
* Constructs a function that returns <tt>a | b</tt>.
* <tt>a</tt> is a variable, <tt>b</tt> is fixed.
*/
public static IntFunction xor(final int b) {
- return new IntFunction() {
- public final int apply(int a) { return a ^ b; }
- };
+ return new IntFunction() {
+ public final int apply(int a) { return a ^ b; }
+ };
}
}
Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/Mult.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/Mult.java?rev=883972&r1=883971&r2=883972&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/Mult.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/Mult.java Wed Nov 25 03:31:47 2009
@@ -23,33 +23,33 @@
*/
@Deprecated
public final class Mult implements org.apache.mahout.matrix.function.DoubleFunction {
- /**
- * Public read/write access to avoid frequent object construction.
- */
- public double multiplicator;
+ /**
+ * Public read/write access to avoid frequent object construction.
+ */
+ public double multiplicator;
/**
* Insert the method's description here.
* Creation date: (8/10/99 19:12:09)
*/
protected Mult(final double multiplicator) {
- this.multiplicator = multiplicator;
+ this.multiplicator = multiplicator;
}
/**
* Returns the result of the function evaluation.
*/
public final double apply(double a) {
- return a * multiplicator;
+ return a * multiplicator;
}
/**
* <tt>a / constant</tt>.
*/
public static Mult div(final double constant) {
- return mult(1/constant);
+ return mult(1/constant);
}
/**
* <tt>a * constant</tt>.
*/
public static Mult mult(final double constant) {
- return new Mult(constant);
+ return new Mult(constant);
}
}
Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/PlusMult.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/PlusMult.java?rev=883972&r1=883971&r2=883972&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/PlusMult.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/PlusMult.java Wed Nov 25 03:31:47 2009
@@ -25,45 +25,45 @@
*/
@Deprecated
public final class PlusMult implements org.apache.mahout.matrix.function.DoubleDoubleFunction {
- /**
- * Public read/write access to avoid frequent object construction.
- */
- public double multiplicator;
+ /**
+ * Public read/write access to avoid frequent object construction.
+ */
+ public double multiplicator;
/**
* Insert the method's description here.
* Creation date: (8/10/99 19:12:09)
*/
protected PlusMult(final double multiplicator) {
- this.multiplicator = multiplicator;
+ this.multiplicator = multiplicator;
}
/**
* Returns the result of the function evaluation.
*/
public final double apply(double a, double b) {
- return a + b*multiplicator;
+ return a + b*multiplicator;
}
/**
* <tt>a - b/constant</tt>.
*/
public static PlusMult minusDiv(final double constant) {
- return new PlusMult(-1/constant);
+ return new PlusMult(-1/constant);
}
/**
* <tt>a - b*constant</tt>.
*/
public static PlusMult minusMult(final double constant) {
- return new PlusMult(-constant);
+ return new PlusMult(-constant);
}
/**
* <tt>a + b/constant</tt>.
*/
public static PlusMult plusDiv(final double constant) {
- return new PlusMult(1/constant);
+ return new PlusMult(1/constant);
}
/**
* <tt>a + b*constant</tt>.
*/
public static PlusMult plusMult(final double constant) {
- return new PlusMult(constant);
+ return new PlusMult(constant);
}
}
Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/Polynomial.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/Polynomial.java?rev=883972&r1=883971&r2=883972&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/Polynomial.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/math/Polynomial.java Wed Nov 25 03:31:47 2009
@@ -45,13 +45,13 @@
* @param N the degree of the polynomial.
*/
public static double p1evl( double x, double coef[], int N ) throws ArithmeticException {
- double ans;
+ double ans;
- ans = x + coef[0];
+ ans = x + coef[0];
- for(int i=1; i<N; i++) { ans = ans*x+coef[i]; }
+ for(int i=1; i<N; i++) { ans = ans*x+coef[i]; }
- return ans;
+ return ans;
}
/**
* Evaluates the given polynomial of degree <tt>N</tt> at <tt>x</tt>.
@@ -72,11 +72,11 @@
* @param N the degree of the polynomial.
*/
public static double polevl( double x, double coef[], int N ) throws ArithmeticException {
- double ans;
- ans = coef[0];
+ double ans;
+ ans = coef[0];
- for(int i=1; i<=N; i++) ans = ans*x+coef[i];
+ for(int i=1; i<=N; i++) ans = ans*x+coef[i];
- return ans;
+ return ans;
}
}
Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/random/AbstractContinousDistribution.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/random/AbstractContinousDistribution.java?rev=883972&r1=883971&r2=883972&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/random/AbstractContinousDistribution.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/random/AbstractContinousDistribution.java Wed Nov 25 03:31:47 2009
@@ -11,8 +11,6 @@
/**
* Abstract base class for all continous distributions.
*
- * @author wolfgang.hoschek@cern.ch
- * @version 1.0, 09/24/99
*/
/**
* @deprecated until unit tests are in place. Until this time, this class/interface is unsupported.
Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/random/AbstractDiscreteDistribution.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/random/AbstractDiscreteDistribution.java?rev=883972&r1=883971&r2=883972&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/random/AbstractDiscreteDistribution.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/random/AbstractDiscreteDistribution.java Wed Nov 25 03:31:47 2009
@@ -11,8 +11,6 @@
/**
* Abstract base class for all discrete distributions.
*
- * @author wolfgang.hoschek@cern.ch
- * @version 1.0, 09/24/99
*/
/**
* @deprecated until unit tests are in place. Until this time, this class/interface is unsupported.
@@ -27,7 +25,7 @@
* Returns a random number from the distribution; returns <tt>(double) nextInt()</tt>.
*/
public double nextDouble() {
- return (double) nextInt();
+ return (double) nextInt();
}
/**
* Returns a random number from the distribution.
Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/random/AbstractDistribution.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/random/AbstractDistribution.java?rev=883972&r1=883971&r2=883972&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/random/AbstractDistribution.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/jet/random/AbstractDistribution.java Wed Nov 25 03:31:47 2009
@@ -40,15 +40,13 @@
* @see org.apache.mahout.jet.random.engine
* @see org.apache.mahout.jet.random.engine.Benchmark
* @see org.apache.mahout.jet.random.Benchmark
- * @author wolfgang.hoschek@cern.ch
- * @version 1.0, 09/24/99
*/
/**
* @deprecated until unit tests are in place. Until this time, this class/interface is unsupported.
*/
@Deprecated
public abstract class AbstractDistribution extends org.apache.mahout.matrix.PersistentObject implements org.apache.mahout.matrix.function.DoubleFunction, org.apache.mahout.matrix.function.IntFunction {
- protected RandomEngine randomGenerator;
+ protected RandomEngine randomGenerator;
/**
* Makes this class non instantiable, but still let's others inherit from it.
*/
@@ -58,14 +56,14 @@
This has the effect that distributions can now be used as function objects, returning a random number upon function evaluation.
*/
public double apply(double dummy) {
- return nextDouble();
+ return nextDouble();
}
/**
Equivalent to <tt>nextInt()</tt>.
This has the effect that distributions can now be used as function objects, returning a random number upon function evaluation.
*/
public int apply(int dummy) {
- return nextInt();
+ return nextInt();
}
/**
* Returns a deep copy of the receiver; the copy will produce identical sequences.
@@ -74,22 +72,22 @@
* @return a copy of the receiver.
*/
public Object clone() {
- AbstractDistribution copy = (AbstractDistribution) super.clone();
- if (this.randomGenerator != null) copy.randomGenerator = (RandomEngine) this.randomGenerator.clone();
- return copy;
+ AbstractDistribution copy = (AbstractDistribution) super.clone();
+ if (this.randomGenerator != null) copy.randomGenerator = (RandomEngine) this.randomGenerator.clone();
+ return copy;
}
/**
* Returns the used uniform random number generator;
*/
protected RandomEngine getRandomGenerator() {
- return randomGenerator;
+ return randomGenerator;
}
/**
* Constructs and returns a new uniform random number generation engine seeded with the current time.
* Currently this is {@link org.apache.mahout.jet.random.engine.MersenneTwister}.
*/
public static RandomEngine makeDefaultGenerator() {
- return org.apache.mahout.jet.random.engine.RandomEngine.makeDefault();
+ return org.apache.mahout.jet.random.engine.RandomEngine.makeDefault();
}
/**
* Returns a random number from the distribution.
@@ -100,12 +98,12 @@
* Override this method if necessary.
*/
public int nextInt() {
- return (int) Math.round(nextDouble());
+ return (int) Math.round(nextDouble());
}
/**
* Sets the uniform random generator internally used.
*/
protected void setRandomGenerator(RandomEngine randomGenerator) {
- this.randomGenerator = randomGenerator;
+ this.randomGenerator = randomGenerator;
}
}