hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From millec...@apache.org
Subject svn commit: r1537427 [2/3] - in /hama/trunk: ./ commons/ commons/src/ commons/src/main/ commons/src/main/java/ commons/src/main/java/org/ commons/src/main/java/org/apache/ commons/src/main/java/org/apache/hama/ commons/src/main/java/org/apache/hama/com...
Date Thu, 31 Oct 2013 10:32:41 GMT
Added: hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleMatrix.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleMatrix.java?rev=1537427&view=auto
==============================================================================
--- hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleMatrix.java (added)
+++ hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleMatrix.java Thu Oct 31 10:32:38 2013
@@ -0,0 +1,273 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.commons.math;
+
+/**
+ * Standard matrix interface for double elements. Every implementation should
+ * return a fresh new Matrix when operating with other elements.
+ */
+public interface DoubleMatrix {
+
+  /**
+   * Not flagged value for sparse matrices, it is default to 0.0d.
+   */
+  public static final double NOT_FLAGGED = 0.0d;
+
+  /**
+   * Get a specific value of the matrix.
+   * 
+   * @return Returns the integer value at in the column at the row.
+   */
+  public double get(int row, int col);
+
+  /**
+   * Returns the number of columns in the matrix. Always a constant time
+   * operation.
+   */
+  public int getColumnCount();
+
+  /**
+   * Get a whole column of the matrix as vector.
+   */
+  public DoubleVector getColumnVector(int col);
+
+  /**
+   * Returns the number of rows in this matrix. Always a constant time
+   * operation.
+   */
+  public int getRowCount();
+
+  /**
+   * Get a single row of the matrix as a vector.
+   */
+  public DoubleVector getRowVector(int row);
+
+  /**
+   * Sets the value at the given row and column index.
+   */
+  public void set(int row, int col, double value);
+
+  /**
+   * Sets a whole column at index col with the given vector.
+   */
+  public void setColumnVector(int col, DoubleVector column);
+
+  /**
+   * Sets the whole row at index rowIndex with the given vector.
+   */
+  public void setRowVector(int rowIndex, DoubleVector row);
+
+  /**
+   * Multiplies this matrix (each element) with the given scalar and returns a
+   * new matrix.
+   */
+  public DoubleMatrix multiply(double scalar);
+
+  /**
+   * Multiplies this matrix with the given other matrix.
+   * 
+   * @param other the other matrix.
+   * @return
+   */
+  public DoubleMatrix multiplyUnsafe(DoubleMatrix other);
+
+  /**
+   * Validates the input and multiplies this matrix with the given other matrix.
+   * 
+   * @param other the other matrix.
+   * @return
+   */
+  public DoubleMatrix multiply(DoubleMatrix other);
+
+  /**
+   * Multiplies this matrix per element with a given matrix.
+   */
+  public DoubleMatrix multiplyElementWiseUnsafe(DoubleMatrix other);
+
+  /**
+   * Validates the input and multiplies this matrix per element with a given
+   * matrix.
+   * 
+   * @param other the other matrix
+   * @return
+   */
+  public DoubleMatrix multiplyElementWise(DoubleMatrix other);
+
+  /**
+   * Multiplies this matrix with a given vector v. The returning vector contains
+   * the sum of the rows.
+   */
+  public DoubleVector multiplyVectorUnsafe(DoubleVector v);
+
+  /**
+   * Multiplies this matrix with a given vector v. The returning vector contains
+   * the sum of the rows.
+   * 
+   * @param v the vector
+   * @return
+   */
+  public DoubleVector multiplyVector(DoubleVector v);
+
+  /**
+   * Transposes this matrix.
+   */
+  public DoubleMatrix transpose();
+
+  /**
+   * Substracts the given amount by each element in this matrix. <br/>
+   * = (amount - matrix value)
+   */
+  public DoubleMatrix subtractBy(double amount);
+
+  /**
+   * Subtracts each element in this matrix by the given amount.<br/>
+   * = (matrix value - amount)
+   */
+  public DoubleMatrix subtract(double amount);
+
+  /**
+   * Subtracts this matrix by the given other matrix.
+   */
+  public DoubleMatrix subtractUnsafe(DoubleMatrix other);
+
+  /**
+   * Validates the input and subtracts this matrix by the given other matrix.
+   * 
+   * @param other
+   * @return
+   */
+  public DoubleMatrix subtract(DoubleMatrix other);
+
+  /**
+   * Subtracts each element in a column by the related element in the given
+   * vector.
+   */
+  public DoubleMatrix subtractUnsafe(DoubleVector vec);
+
+  /**
+   * Validates and subtracts each element in a column by the related element in
+   * the given vector.
+   * 
+   * @param vec
+   * @return
+   */
+  public DoubleMatrix subtract(DoubleVector vec);
+
+  /**
+   * Divides each element in a column by the related element in the given
+   * vector.
+   */
+  public DoubleMatrix divideUnsafe(DoubleVector vec);
+
+  /**
+   * Validates and divides each element in a column by the related element in
+   * the given vector.
+   * 
+   * @param vec
+   * @return
+   */
+  public DoubleMatrix divide(DoubleVector vec);
+
+  /**
+   * Divides this matrix by the given other matrix. (Per element division).
+   */
+  public DoubleMatrix divideUnsafe(DoubleMatrix other);
+
+  /**
+   * Validates and divides this matrix by the given other matrix. (Per element
+   * division).
+   * 
+   * @param other
+   * @return
+   */
+  public DoubleMatrix divide(DoubleMatrix other);
+
+  /**
+   * Divides each element in this matrix by the given scalar.
+   */
+  public DoubleMatrix divide(double scalar);
+
+  /**
+   * Adds the elements in the given matrix to the elements in this matrix.
+   */
+  public DoubleMatrix add(DoubleMatrix other);
+
+  /**
+   * Pows each element by the given argument. <br/>
+   * = (matrix element^x)
+   */
+  public DoubleMatrix pow(int x);
+
+  /**
+   * Returns the maximum value of the given column.
+   */
+  public double max(int column);
+
+  /**
+   * Returns the minimum value of the given column.
+   */
+  public double min(int column);
+
+  /**
+   * Sums all elements.
+   */
+  public double sum();
+
+  /**
+   * Returns an array of column indices existing in this matrix.
+   */
+  public int[] columnIndices();
+
+  /**
+   * Returns true if the underlying implementation is sparse.
+   */
+  public boolean isSparse();
+
+  /**
+   * Slices the given matrix from 0-rows and from 0-columns.
+   */
+  public DoubleMatrix slice(int rows, int cols);
+
+  /**
+   * Slices the given matrix from rowOffset-rowMax and from colOffset-colMax.
+   */
+  public DoubleMatrix slice(int rowOffset, int rowMax, int colOffset, int colMax);
+
+  /**
+   * Apply a double function f(x) onto each element of the matrix. After
+   * applying, each element of the current matrix will be changed from x to
+   * f(x).
+   * 
+   * @param fun The function.
+   * @return The matrix itself, supply for chain operation.
+   */
+  public DoubleMatrix applyToElements(DoubleFunction fun);
+
+  /**
+   * Apply a double double function f(x, y) onto each pair of the current matrix
+   * elements and given matrix. After applying, each element of the current
+   * matrix will be changed from x to f(x, y).
+   * 
+   * @param other The matrix contributing the second argument of the function.
+   * @param fun The function that takes two arguments.
+   * @return The matrix itself, supply for chain operation.
+   */
+  public DoubleMatrix applyToElements(DoubleMatrix other,
+      DoubleDoubleFunction fun);
+
+}

Added: hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleVector.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleVector.java?rev=1537427&view=auto
==============================================================================
--- hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleVector.java (added)
+++ hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleVector.java Thu Oct 31 10:32:38 2013
@@ -0,0 +1,388 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.commons.math;
+
+import java.util.Iterator;
+
+/**
+ * Vector with doubles. Some of the operations are mutable, unlike the apply and
+ * math functions, they return a fresh instance every time.
+ * 
+ */
+public interface DoubleVector {
+
+  /**
+   * Retrieves the value at given index.
+   * 
+   * @param index the index.
+   * @return a double value at the index.
+   */
+  public double get(int index);
+
+  /**
+   * Get the length of a vector, for sparse instance it is the actual length.
+   * (not the dimension!) Always a constant time operation.
+   * 
+   * @return the length of the vector.
+   */
+  public int getLength();
+
+  /**
+   * Get the dimension of a vector, for dense instance it is the same like the
+   * length, for sparse instances it is usually not the same. Always a constant
+   * time operation.
+   * 
+   * @return the dimension of the vector.
+   */
+  public int getDimension();
+
+  /**
+   * Set a value at the given index.
+   * 
+   * @param index the index of the vector to set.
+   * @param value the value at the index of the vector to set.
+   */
+  public void set(int index, double value);
+
+  /**
+   * Apply a given {@link DoubleVectorFunction} to this vector and return a new
+   * one.
+   * 
+   * @param func the function to apply.
+   * @return a new vector with the applied function.
+   */
+  @Deprecated
+  public DoubleVector apply(DoubleVectorFunction func);
+
+  /**
+   * Apply a given {@link DoubleDoubleVectorFunction} to this vector and the
+   * other given vector.
+   * 
+   * @param other the other vector.
+   * @param func the function to apply on this and the other vector.
+   * @return a new vector with the result of the function of the two vectors.
+   */
+  @Deprecated
+  public DoubleVector apply(DoubleVector other, DoubleDoubleVectorFunction func);
+
+  /**
+   * Apply a given {@link DoubleVectorFunction} to this vector and return a new
+   * one.
+   * 
+   * @param func the function to apply.
+   * @return a new vector with the applied function.
+   */
+  public DoubleVector applyToElements(DoubleFunction func);
+
+  /**
+   * Apply a given {@link DoubleDoubleVectorFunction} to this vector and the
+   * other given vector.
+   * 
+   * @param other the other vector.
+   * @param func the function to apply on this and the other vector.
+   * @return a new vector with the result of the function of the two vectors.
+   */
+  public DoubleVector applyToElements(DoubleVector other,
+      DoubleDoubleFunction func);
+
+  /**
+   * Adds the given {@link DoubleVector} to this vector.
+   * 
+   * @param vector the other vector.
+   * @return a new vector with the sum of both vectors at each element index.
+   */
+  public DoubleVector addUnsafe(DoubleVector vector);
+
+  /**
+   * Validates the input and adds the given {@link DoubleVector} to this vector.
+   * 
+   * @param vector the other vector.
+   * @return a new vector with the sum of both vectors at each element index.
+   */
+  public DoubleVector add(DoubleVector vector);
+
+  /**
+   * Adds the given scalar to this vector.
+   * 
+   * @param scalar the scalar.
+   * @return a new vector with the result at each element index.
+   */
+  public DoubleVector add(double scalar);
+
+  /**
+   * Subtracts this vector by the given {@link DoubleVector}.
+   * 
+   * @param vector the other vector.
+   * @return a new vector with the difference of both vectors.
+   */
+  public DoubleVector subtractUnsafe(DoubleVector vector);
+
+  /**
+   * Validates the input and subtracts this vector by the given
+   * {@link DoubleVector}.
+   * 
+   * @param vector the other vector.
+   * @return a new vector with the difference of both vectors.
+   */
+  public DoubleVector subtract(DoubleVector vector);
+
+  /**
+   * Subtracts the given scalar to this vector. (vector - scalar).
+   * 
+   * @param scalar the scalar.
+   * @return a new vector with the result at each element index.
+   */
+  public DoubleVector subtract(double scalar);
+
+  /**
+   * Subtracts the given scalar from this vector. (scalar - vector).
+   * 
+   * @param scalar the scalar.
+   * @return a new vector with the result at each element index.
+   */
+  public DoubleVector subtractFrom(double scalar);
+
+  /**
+   * Multiplies the given scalar to this vector.
+   * 
+   * @param scalar the scalar.
+   * @return a new vector with the result of the operation.
+   */
+  public DoubleVector multiply(double scalar);
+
+  /**
+   * Multiplies the given {@link DoubleVector} with this vector.
+   * 
+   * @param vector the other vector.
+   * @return a new vector with the result of the operation.
+   */
+  public DoubleVector multiplyUnsafe(DoubleVector vector);
+
+  /**
+   * Validates the input and multiplies the given {@link DoubleVector} with this
+   * vector.
+   * 
+   * @param vector the other vector.
+   * @return a new vector with the result of the operation.
+   */
+  public DoubleVector multiply(DoubleVector vector);
+
+  /**
+   * Validates the input and multiplies the given {@link DoubleMatrix} with this
+   * vector.
+   * 
+   * @param matrix
+   * @return
+   */
+  public DoubleVector multiply(DoubleMatrix matrix);
+
+  /**
+   * Multiplies the given {@link DoubleMatrix} with this vector.
+   * 
+   * @param matrix
+   * @return
+   */
+  public DoubleVector multiplyUnsafe(DoubleMatrix matrix);
+
+  /**
+   * Divides this vector by the given scalar. (= vector/scalar).
+   * 
+   * @param scalar the given scalar.
+   * @return a new vector with the result of the operation.
+   */
+  public DoubleVector divide(double scalar);
+
+  /**
+   * Divides the given scalar by this vector. (= scalar/vector).
+   * 
+   * @param scalar the given scalar.
+   * @return a new vector with the result of the operation.
+   */
+  public DoubleVector divideFrom(double scalar);
+
+  /**
+   * Powers this vector by the given amount. (=vector^x).
+   * 
+   * @param x the given exponent.
+   * @return a new vector with the result of the operation.
+   */
+  public DoubleVector pow(int x);
+
+  /**
+   * Absolutes the vector at each element.
+   * 
+   * @return a new vector that does not contain negative values anymore.
+   */
+  public DoubleVector abs();
+
+  /**
+   * Square-roots each element.
+   * 
+   * @return a new vector.
+   */
+  public DoubleVector sqrt();
+
+  /**
+   * @return the sum of all elements in this vector.
+   */
+  public double sum();
+
+  /**
+   * Calculates the dot product between this vector and the given vector.
+   * 
+   * @param vector the given vector.
+   * @return the dot product as a double.
+   */
+  public double dotUnsafe(DoubleVector vector);
+
+  /**
+   * Validates the input and calculates the dot product between this vector and
+   * the given vector.
+   * 
+   * @param vector the given vector.
+   * @return the dot product as a double.
+   */
+  public double dot(DoubleVector vector);
+
+  /**
+   * Validates the input and slices this vector from index 0 to the given
+   * length.
+   * 
+   * @param length must be > 0 and smaller than the dimension of the vector.
+   * @return a new vector that is only length long.
+   */
+  public DoubleVector slice(int length);
+
+  /**
+   * Slices this vector from index 0 to the given length.
+   * 
+   * @param length must be > 0 and smaller than the dimension of the vector.
+   * @return a new vector that is only length long.
+   */
+  public DoubleVector sliceUnsafe(int length);
+
+  /**
+   * Validates the input and then slices this vector from start to end, both are
+   * INCLUSIVE. For example vec = [0, 1, 2, 3, 4, 5], vec.slice(2, 5) = [2, 3,
+   * 4, 5].
+   * 
+   * @param offset must be > 0 and smaller than the dimension of the vector
+   * @param length must be > 0 and smaller than the dimension of the vector.
+   *          This must be greater than the offset.
+   * @return a new vector that is only (length) long.
+   */
+  public DoubleVector slice(int start, int end);
+
+  /**
+   * Slices this vector from start to end, both are INCLUSIVE. For example vec =
+   * [0, 1, 2, 3, 4, 5], vec.slice(2, 5) = [2, 3, 4, 5].
+   * 
+   * @param offset must be > 0 and smaller than the dimension of the vector
+   * @param length must be > 0 and smaller than the dimension of the vector.
+   *          This must be greater than the offset.
+   * @return a new vector that is only (length) long.
+   */
+  public DoubleVector sliceUnsafe(int start, int end);
+
+  /**
+   * @return the maximum element value in this vector.
+   */
+  public double max();
+
+  /**
+   * @return the minimum element value in this vector.
+   */
+  public double min();
+
+  /**
+   * @return an array representation of this vector.
+   */
+  public double[] toArray();
+
+  /**
+   * @return a fresh new copy of this vector, copies all elements to a new
+   *         vector. (Does not reuse references or stuff).
+   */
+  public DoubleVector deepCopy();
+
+  /**
+   * @return an iterator that only iterates over non zero elements.
+   */
+  public Iterator<DoubleVectorElement> iterateNonZero();
+
+  /**
+   * @return an iterator that iterates over all elements.
+   */
+  public Iterator<DoubleVectorElement> iterate();
+
+  /**
+   * @return true if this instance is a sparse vector. Smarter and faster than
+   *         instanceof.
+   */
+  public boolean isSparse();
+
+  /**
+   * @return true if this instance is a named vector.Smarter and faster than
+   *         instanceof.
+   */
+  public boolean isNamed();
+
+  /**
+   * @return If this vector is a named instance, this will return its name. Or
+   *         null if this is not a named instance.
+   * 
+   */
+  public String getName();
+
+  /**
+   * Class for iteration of elements, consists of an index and a value at this
+   * index. Can be reused for performance purposes.
+   */
+  public static final class DoubleVectorElement {
+
+    private int index;
+    private double value;
+
+    public DoubleVectorElement() {
+      super();
+    }
+
+    public DoubleVectorElement(int index, double value) {
+      super();
+      this.index = index;
+      this.value = value;
+    }
+
+    public final int getIndex() {
+      return index;
+    }
+
+    public final double getValue() {
+      return value;
+    }
+
+    public final void setIndex(int in) {
+      this.index = in;
+    }
+
+    public final void setValue(double in) {
+      this.value = in;
+    }
+  }
+
+}

Added: hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleVectorFunction.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleVectorFunction.java?rev=1537427&view=auto
==============================================================================
--- hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleVectorFunction.java (added)
+++ hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleVectorFunction.java Thu Oct 31 10:32:38 2013
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.commons.math;
+
+/**
+ * A function that can be applied to a double vector via {@link DoubleVector}
+ * #apply({@link DoubleVectorFunction} f);
+ * 
+ * This class will be replaced by {@link DoubleFunction}
+ */
+@Deprecated
+public interface DoubleVectorFunction {
+
+  /**
+   * Calculates the result with a given index and value of a vector.
+   */
+  public double calculate(int index, double value);
+
+}

Added: hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Function.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Function.java?rev=1537427&view=auto
==============================================================================
--- hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Function.java (added)
+++ hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Function.java Thu Oct 31 10:32:38 2013
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.commons.math;
+
+/**
+ * A generic function.
+ * 
+ */
+public abstract class Function {
+  /**
+   * Get the name of the function.
+   * 
+   * @return The name of the function.
+   */
+  final public String getFunctionName() {
+    return this.getClass().getSimpleName();
+  }
+}

Added: hama/trunk/commons/src/main/java/org/apache/hama/commons/math/FunctionFactory.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/main/java/org/apache/hama/commons/math/FunctionFactory.java?rev=1537427&view=auto
==============================================================================
--- hama/trunk/commons/src/main/java/org/apache/hama/commons/math/FunctionFactory.java (added)
+++ hama/trunk/commons/src/main/java/org/apache/hama/commons/math/FunctionFactory.java Thu Oct 31 10:32:38 2013
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.commons.math;
+
+/**
+ * Factory to create the functions.
+ * 
+ */
+public class FunctionFactory {
+
+  /**
+   * Create a double function with specified name.
+   * 
+   * @param functionName
+   * @return
+   */
+  public static DoubleFunction createDoubleFunction(String functionName) {
+    if (functionName.equalsIgnoreCase(Sigmoid.class.getSimpleName())) {
+      return new Sigmoid();
+    } else if (functionName.equalsIgnoreCase(Tanh.class.getSimpleName())) {
+      return new Tanh();
+    } else if (functionName.equalsIgnoreCase(IdentityFunction.class
+        .getSimpleName())) {
+      return new IdentityFunction();
+    }
+
+    throw new IllegalArgumentException(String.format(
+        "No double function with name '%s' exists.", functionName));
+  }
+
+  /**
+   * Create a double double function with specified name.
+   * 
+   * @param functionName
+   * @return
+   */
+  public static DoubleDoubleFunction createDoubleDoubleFunction(
+      String functionName) {
+    if (functionName.equalsIgnoreCase(SquaredError.class.getSimpleName())) {
+      return new SquaredError();
+    } else if (functionName
+        .equalsIgnoreCase(CrossEntropy.class.getSimpleName())) {
+      return new CrossEntropy();
+    }
+
+    throw new IllegalArgumentException(String.format(
+        "No double double function with name '%s' exists.", functionName));
+  }
+
+}

Added: hama/trunk/commons/src/main/java/org/apache/hama/commons/math/IdentityFunction.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/main/java/org/apache/hama/commons/math/IdentityFunction.java?rev=1537427&view=auto
==============================================================================
--- hama/trunk/commons/src/main/java/org/apache/hama/commons/math/IdentityFunction.java (added)
+++ hama/trunk/commons/src/main/java/org/apache/hama/commons/math/IdentityFunction.java Thu Oct 31 10:32:38 2013
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.commons.math;
+
+/**
+ * The identity function f(x) = x.
+ * 
+ */
+public class IdentityFunction extends DoubleFunction {
+
+  @Override
+  public double apply(double value) {
+    return value;
+  }
+
+  @Override
+  public double applyDerivative(double value) {
+    return 1;
+  }
+
+}

Added: hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Sigmoid.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Sigmoid.java?rev=1537427&view=auto
==============================================================================
--- hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Sigmoid.java (added)
+++ hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Sigmoid.java Thu Oct 31 10:32:38 2013
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.commons.math;
+
+/**
+ * The Sigmoid function
+ * 
+ * <pre>
+ * f(x) = 1 / (1 + e^{-x})
+ * </pre>
+ */
+public class Sigmoid extends DoubleFunction {
+
+  @Override
+  public double apply(double value) {
+    return 1.0 / (1 + Math.exp(-value));
+  }
+
+  @Override
+  public double applyDerivative(double value) {
+    return value * (1 - value);
+  }
+
+}

Added: hama/trunk/commons/src/main/java/org/apache/hama/commons/math/SquaredError.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/main/java/org/apache/hama/commons/math/SquaredError.java?rev=1537427&view=auto
==============================================================================
--- hama/trunk/commons/src/main/java/org/apache/hama/commons/math/SquaredError.java (added)
+++ hama/trunk/commons/src/main/java/org/apache/hama/commons/math/SquaredError.java Thu Oct 31 10:32:38 2013
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.commons.math;
+
+/**
+ * Square error cost function.
+ * 
+ * <pre>
+ * cost(t, y) = 0.5 * (t - y) &circ; 2
+ * </pre>
+ */
+public class SquaredError extends DoubleDoubleFunction {
+
+  @Override
+  /**
+   * {@inheritDoc}
+   */
+  public double apply(double target, double actual) {
+    double diff = target - actual;
+    return 0.5 * diff * diff;
+  }
+
+  @Override
+  /**
+   * {@inheritDoc}
+   */
+  public double applyDerivative(double target, double actual) {
+    return actual - target;
+  }
+
+}

Added: hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Tanh.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Tanh.java?rev=1537427&view=auto
==============================================================================
--- hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Tanh.java (added)
+++ hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Tanh.java Thu Oct 31 10:32:38 2013
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.commons.math;
+
+/**
+ * Tanh function.
+ * 
+ */
+public class Tanh extends DoubleFunction {
+
+  @Override
+  public double apply(double value) {
+    return Math.tanh(value);
+  }
+
+  @Override
+  public double applyDerivative(double value) {
+    return 1 - value * value;
+  }
+  
+}

Added: hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Tuple.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Tuple.java?rev=1537427&view=auto
==============================================================================
--- hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Tuple.java (added)
+++ hama/trunk/commons/src/main/java/org/apache/hama/commons/math/Tuple.java Thu Oct 31 10:32:38 2013
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.commons.math;
+
+/**
+ * Tuple class to hold two generic attributes. This class implements hashcode,
+ * equals and comparable via the first element.
+ */
+public final class Tuple<FIRST, SECOND> implements
+    Comparable<Tuple<FIRST, SECOND>> {
+
+  private final FIRST first;
+  private final SECOND second;
+
+  public Tuple(FIRST first, SECOND second) {
+    super();
+    this.first = first;
+    this.second = second;
+  }
+
+  public final FIRST getFirst() {
+    return first;
+  }
+
+  public final SECOND getSecond() {
+    return second;
+  }
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((first == null) ? 0 : first.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    @SuppressWarnings("rawtypes")
+    Tuple other = (Tuple) obj;
+    if (first == null) {
+      if (other.first != null)
+        return false;
+    } else if (!first.equals(other.first))
+      return false;
+    return true;
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public int compareTo(Tuple<FIRST, SECOND> o) {
+    if (o.getFirst() instanceof Comparable && getFirst() instanceof Comparable) {
+      return ((Comparable<FIRST>) getFirst()).compareTo(o.getFirst());
+    } else {
+      return 0;
+    }
+  }
+
+  @Override
+  public String toString() {
+    return "Tuple [first=" + first + ", second=" + second + "]";
+  }
+
+}

Added: hama/trunk/commons/src/main/java/org/apache/hama/commons/util/KeyValuePair.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/main/java/org/apache/hama/commons/util/KeyValuePair.java?rev=1537427&view=auto
==============================================================================
--- hama/trunk/commons/src/main/java/org/apache/hama/commons/util/KeyValuePair.java (added)
+++ hama/trunk/commons/src/main/java/org/apache/hama/commons/util/KeyValuePair.java Thu Oct 31 10:32:38 2013
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.commons.util;
+
+/**
+ * Mutable class for key values.
+ */
+public class KeyValuePair<K, V> {
+
+  private K key;
+  private V value;
+
+  public KeyValuePair() {
+
+  }
+
+  public KeyValuePair(K key, V value) {
+    super();
+    this.key = key;
+    this.value = value;
+  }
+
+  public K getKey() {
+    return key;
+  }
+
+  public V getValue() {
+    return value;
+  }
+
+  public void setKey(K key) {
+    this.key = key;
+  }
+
+  public void setValue(V value) {
+    this.value = value;
+  }
+
+  public void clear() {
+    this.key = null;
+    this.value = null;
+  }
+
+}

Added: hama/trunk/commons/src/main/java/org/apache/hama/commons/util/TextPair.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/main/java/org/apache/hama/commons/util/TextPair.java?rev=1537427&view=auto
==============================================================================
--- hama/trunk/commons/src/main/java/org/apache/hama/commons/util/TextPair.java (added)
+++ hama/trunk/commons/src/main/java/org/apache/hama/commons/util/TextPair.java Thu Oct 31 10:32:38 2013
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.commons.util;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.io.Writable;
+
+/**
+ * TextPair class for use in BipartiteMatching algorithm.
+ * 
+ */
+public final class TextPair implements Writable {
+
+  Text first;
+  Text second;
+
+  public TextPair() {
+    first = new Text();
+    second = new Text();
+  }
+
+  public TextPair(Text first, Text second) {
+    this.first = first;
+    this.second = second;
+  }
+
+  public Text getFirst() {
+    return first;
+  }
+
+  public void setFirst(Text first) {
+    this.first = first;
+  }
+
+  public Text getSecond() {
+    return second;
+  }
+
+  public void setSecond(Text second) {
+    this.second = second;
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    first.write(out);
+    second.write(out);
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+
+    first.readFields(in);
+    second.readFields(in);
+  }
+
+  @Override
+  public String toString() {
+    return first + " " + second;
+  }
+
+}

Added: hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestDenseDoubleMatrix.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestDenseDoubleMatrix.java?rev=1537427&view=auto
==============================================================================
--- hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestDenseDoubleMatrix.java (added)
+++ hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestDenseDoubleMatrix.java Thu Oct 31 10:32:38 2013
@@ -0,0 +1,237 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.commons.math;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+
+/**
+ * Test case for {@link DenseDoubleMatrix}
+ * 
+ */
+public class TestDenseDoubleMatrix {
+
+  @Test
+  public void testDoubleFunction() {
+    double[][] values = new double[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
+
+    double[][] result = new double[][] { { 2, 3, 4 }, { 5, 6, 7 }, { 8, 9, 10 } };
+
+    DenseDoubleMatrix mat = new DenseDoubleMatrix(values);
+    mat.applyToElements(new DoubleFunction() {
+
+      @Override
+      public double apply(double value) {
+        return value + 1;
+      }
+
+      @Override
+      public double applyDerivative(double value) {
+        throw new UnsupportedOperationException();
+      }
+
+    });
+
+    double[][] actual = mat.getValues();
+    for (int i = 0; i < actual.length; ++i) {
+      assertArrayEquals(result[i], actual[i], 0.0001);
+    }
+  }
+
+  @Test
+  public void testDoubleDoubleFunction() {
+    double[][] values1 = new double[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
+    double[][] values2 = new double[][] { { 2, 3, 4 }, { 5, 6, 7 },
+        { 8, 9, 10 } };
+    double[][] result = new double[][] { { 3, 5, 7 }, { 9, 11, 13 },
+        { 15, 17, 19 } };
+
+    DenseDoubleMatrix mat1 = new DenseDoubleMatrix(values1);
+    DenseDoubleMatrix mat2 = new DenseDoubleMatrix(values2);
+
+    mat1.applyToElements(mat2, new DoubleDoubleFunction() {
+
+      @Override
+      public double apply(double x1, double x2) {
+        return x1 + x2;
+      }
+
+      @Override
+      public double applyDerivative(double x1, double x2) {
+        throw new UnsupportedOperationException();
+      }
+
+    });
+
+    double[][] actual = mat1.getValues();
+    for (int i = 0; i < actual.length; ++i) {
+      assertArrayEquals(result[i], actual[i], 0.0001);
+    }
+  }
+
+  @Test
+  public void testMultiplyNormal() {
+    double[][] mat1 = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } };
+    double[][] mat2 = new double[][] { { 6, 5 }, { 4, 3 }, { 2, 1 } };
+    double[][] expMat = new double[][] { { 20, 14 }, { 56, 41 } };
+    DoubleMatrix matrix1 = new DenseDoubleMatrix(mat1);
+    DoubleMatrix matrix2 = new DenseDoubleMatrix(mat2);
+    DoubleMatrix actMatrix = matrix1.multiply(matrix2);
+    for (int r = 0; r < actMatrix.getRowCount(); ++r) {
+      assertArrayEquals(expMat[r], actMatrix.getRowVector(r).toArray(),
+          0.000001);
+    }
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testMultiplyAbnormal() {
+    double[][] mat1 = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } };
+    double[][] mat2 = new double[][] { { 6, 5 }, { 4, 3 } };
+    DoubleMatrix matrix1 = new DenseDoubleMatrix(mat1);
+    DoubleMatrix matrix2 = new DenseDoubleMatrix(mat2);
+    matrix1.multiply(matrix2);
+  }
+
+  @Test
+  public void testMultiplyElementWiseNormal() {
+    double[][] mat1 = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } };
+    double[][] mat2 = new double[][] { { 6, 5, 4 }, { 3, 2, 1 } };
+    double[][] expMat = new double[][] { { 6, 10, 12 }, { 12, 10, 6 } };
+    DoubleMatrix matrix1 = new DenseDoubleMatrix(mat1);
+    DoubleMatrix matrix2 = new DenseDoubleMatrix(mat2);
+    DoubleMatrix actMatrix = matrix1.multiplyElementWise(matrix2);
+    for (int r = 0; r < actMatrix.getRowCount(); ++r) {
+      assertArrayEquals(expMat[r], actMatrix.getRowVector(r).toArray(),
+          0.000001);
+    }
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testMultiplyElementWiseAbnormal() {
+    double[][] mat1 = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } };
+    double[][] mat2 = new double[][] { { 6, 5 }, { 4, 3 } };
+    DoubleMatrix matrix1 = new DenseDoubleMatrix(mat1);
+    DoubleMatrix matrix2 = new DenseDoubleMatrix(mat2);
+    matrix1.multiplyElementWise(matrix2);
+  }
+
+  @Test
+  public void testMultiplyVectorNormal() {
+    double[][] mat1 = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } };
+    double[] mat2 = new double[] { 6, 5, 4 };
+    double[] expVec = new double[] { 28, 73 };
+    DoubleMatrix matrix1 = new DenseDoubleMatrix(mat1);
+    DoubleVector vector2 = new DenseDoubleVector(mat2);
+    DoubleVector actVec = matrix1.multiplyVector(vector2);
+    assertArrayEquals(expVec, actVec.toArray(), 0.000001);
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testMultiplyVectorAbnormal() {
+    double[][] mat1 = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } };
+    double[] vec2 = new double[] { 6, 5 };
+    DoubleMatrix matrix1 = new DenseDoubleMatrix(mat1);
+    DoubleVector vector2 = new DenseDoubleVector(vec2);
+    matrix1.multiplyVector(vector2);
+  }
+
+  @Test
+  public void testSubtractNormal() {
+    double[][] mat1 = new double[][] {
+        {1, 2, 3},
+        {4, 5, 6}
+    };
+    double[][] mat2 = new double[][] {
+        {6, 5, 4},
+        {3, 2, 1}
+    };
+    double[][] expMat = new double[][] {
+        {-5, -3, -1},
+        {1, 3, 5}
+    };
+    DoubleMatrix matrix1 = new DenseDoubleMatrix(mat1);
+    DoubleMatrix matrix2 = new DenseDoubleMatrix(mat2);
+    DoubleMatrix actMatrix = matrix1.subtract(matrix2);
+    for (int r = 0; r < actMatrix.getRowCount(); ++r) {
+      assertArrayEquals(expMat[r], actMatrix.getRowVector(r).toArray(), 0.000001);
+    }
+  }
+  
+  @Test(expected = IllegalArgumentException.class)
+  public void testSubtractAbnormal() {
+    double[][] mat1 = new double[][] {
+        {1, 2, 3},
+        {4, 5, 6}
+    };
+    double[][] mat2 = new double[][] {
+        {6, 5},
+        {4, 3}
+    };
+    DoubleMatrix matrix1 = new DenseDoubleMatrix(mat1);
+    DoubleMatrix matrix2 = new DenseDoubleMatrix(mat2);
+    matrix1.subtract(matrix2);
+  }
+  
+  @Test
+  public void testDivideVectorNormal() {
+    double[][] mat1 = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } };
+    double[] mat2 = new double[] { 6, 5, 4 };
+    double[][] expVec = new double[][] { {1.0 / 6, 2.0 / 5, 3.0 / 4}, {4.0 / 6, 5.0 / 5, 6.0 / 4} };
+    DoubleMatrix matrix1 = new DenseDoubleMatrix(mat1);
+    DoubleVector vector2 = new DenseDoubleVector(mat2);
+    DoubleMatrix expMat = new DenseDoubleMatrix(expVec);
+    DoubleMatrix actMat = matrix1.divide(vector2);
+    for (int r = 0; r < actMat.getRowCount(); ++r) {
+      assertArrayEquals(expMat.getRowVector(r).toArray(), actMat.getRowVector(r).toArray(), 0.000001);
+    }
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testDivideVectorAbnormal() {
+    double[][] mat1 = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } };
+    double[] vec2 = new double[] { 6, 5 };
+    DoubleMatrix matrix1 = new DenseDoubleMatrix(mat1);
+    DoubleVector vector2 = new DenseDoubleVector(vec2);
+    matrix1.divide(vector2);
+  }
+  
+  @Test
+  public void testDivideNormal() {
+    double[][] mat1 = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } };
+    double[][] mat2 = new double[][] { { 6, 5, 4 }, { 3, 2, 1 } };
+    double[][] expMat = new double[][] { { 1.0 / 6, 2.0 / 5, 3.0 / 4 }, { 4.0 / 3, 5.0 / 2, 6.0 / 1 } };
+    DoubleMatrix matrix1 = new DenseDoubleMatrix(mat1);
+    DoubleMatrix matrix2 = new DenseDoubleMatrix(mat2);
+    DoubleMatrix actMatrix = matrix1.divide(matrix2);
+    for (int r = 0; r < actMatrix.getRowCount(); ++r) {
+      assertArrayEquals(expMat[r], actMatrix.getRowVector(r).toArray(),
+          0.000001);
+    }
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testDivideAbnormal() {
+    double[][] mat1 = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } };
+    double[][] mat2 = new double[][] { { 6, 5 }, { 4, 3 } };
+    DoubleMatrix matrix1 = new DenseDoubleMatrix(mat1);
+    DoubleMatrix matrix2 = new DenseDoubleMatrix(mat2);
+    matrix1.divide(matrix2);
+  }
+  
+}

Added: hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestDenseDoubleVector.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestDenseDoubleVector.java?rev=1537427&view=auto
==============================================================================
--- hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestDenseDoubleVector.java (added)
+++ hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestDenseDoubleVector.java Thu Oct 31 10:32:38 2013
@@ -0,0 +1,208 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.commons.math;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Testcase for {@link DenseDoubleVector}
+ *
+ */
+public class TestDenseDoubleVector {
+
+  @Test
+  public void testApplyDoubleFunction() {
+    double[] values = new double[] {1, 2, 3, 4, 5};
+    double[] result = new double[] {2, 3, 4, 5, 6};
+    
+    DoubleVector vec1 = new DenseDoubleVector(values);
+    
+    vec1.applyToElements(new DoubleFunction() {
+
+      @Override
+      public double apply(double value) {
+        return value + 1;
+      }
+
+      @Override
+      public double applyDerivative(double value) {
+        throw new UnsupportedOperationException("Not supported.");
+      }
+      
+    });
+    
+    assertArrayEquals(result, vec1.toArray(), 0.0001);
+  }
+  
+  @Test
+  public void testApplyDoubleDoubleFunction() {
+    double[] values1 = new double[] {1, 2, 3, 4, 5, 6};
+    double[] values2 = new double[] {7, 8, 9, 10, 11, 12};
+    double[] result = new double[] {8, 10, 12, 14, 16, 18};
+    
+    DoubleVector vec1 = new DenseDoubleVector(values1);
+    DoubleVector vec2 = new DenseDoubleVector(values2);
+    
+    vec1.applyToElements(vec2, new DoubleDoubleFunction() {
+
+      @Override
+      public double apply(double x1, double x2) {
+        return x1 + x2;
+      }
+
+      @Override
+      public double applyDerivative(double x1, double x2) {
+        throw new UnsupportedOperationException("Not supported");
+      }
+      
+    });
+    
+    assertArrayEquals(result, vec1.toArray(), 0.0001);
+    
+  }
+  
+  @Test
+  public void testAddNormal() {
+    double[] arr1 = new double[] {1, 2, 3};
+    double[] arr2 = new double[] {4, 5, 6};
+    DoubleVector vec1 = new DenseDoubleVector(arr1);
+    DoubleVector vec2 = new DenseDoubleVector(arr2);
+    double[] arrExp = new double[] {5, 7, 9};
+    assertArrayEquals(arrExp, vec1.add(vec2).toArray(), 0.000001);
+  }
+  
+  @Test(expected = IllegalArgumentException.class)
+  public void testAddAbnormal() {
+    double[] arr1 = new double[] {1, 2, 3};
+    double[] arr2 = new double[] {4, 5};
+    DoubleVector vec1 = new DenseDoubleVector(arr1);
+    DoubleVector vec2 = new DenseDoubleVector(arr2);
+    vec1.add(vec2);
+  }
+  
+  @Test
+  public void testSubtractNormal() {
+    double[] arr1 = new double[] {1, 2, 3};
+    double[] arr2 = new double[] {4, 5, 6};
+    DoubleVector vec1 = new DenseDoubleVector(arr1);
+    DoubleVector vec2 = new DenseDoubleVector(arr2);
+    double[] arrExp = new double[] {-3, -3, -3};
+    assertArrayEquals(arrExp, vec1.subtract(vec2).toArray(), 0.000001);
+  }
+  
+  @Test(expected = IllegalArgumentException.class)
+  public void testSubtractAbnormal() {
+    double[] arr1 = new double[] {1, 2, 3};
+    double[] arr2 = new double[] {4, 5};
+    DoubleVector vec1 = new DenseDoubleVector(arr1);
+    DoubleVector vec2 = new DenseDoubleVector(arr2);
+    vec1.subtract(vec2);
+  }
+  
+  @Test
+  public void testMultiplyNormal() {
+    double[] arr1 = new double[] {1, 2, 3};
+    double[] arr2 = new double[] {4, 5, 6};
+    DoubleVector vec1 = new DenseDoubleVector(arr1);
+    DoubleVector vec2 = new DenseDoubleVector(arr2);
+    double[] arrExp = new double[] {4, 10, 18};
+    assertArrayEquals(arrExp, vec1.multiply(vec2).toArray(), 0.000001);
+  }
+  
+  @Test(expected = IllegalArgumentException.class)
+  public void testMultiplyAbnormal() {
+    double[] arr1 = new double[] {1, 2, 3};
+    double[] arr2 = new double[] {4, 5};
+    DoubleVector vec1 = new DenseDoubleVector(arr1);
+    DoubleVector vec2 = new DenseDoubleVector(arr2);
+    vec1.multiply(vec2);
+  }
+  
+  @Test
+  public void testDotNormal() {
+    double[] arr1 = new double[] {1, 2, 3};
+    double[] arr2 = new double[] {4, 5, 6};
+    DoubleVector vec1 = new DenseDoubleVector(arr1);
+    DoubleVector vec2 = new DenseDoubleVector(arr2);
+    assertEquals(32.0, vec1.dot(vec2), 0.000001);
+  }
+  
+  @Test(expected = IllegalArgumentException.class)
+  public void testDotAbnormal() {
+    double[] arr1 = new double[] {1, 2, 3};
+    double[] arr2 = new double[] {4, 5};
+    DoubleVector vec1 = new DenseDoubleVector(arr1);
+    DoubleVector vec2 = new DenseDoubleVector(arr2);
+    vec1.add(vec2);
+  }
+  
+  @Test
+  public void testSliceNormal() {
+    double[] arr1 = new double[] {2, 3, 4, 5, 6};
+    double[] arr2 = new double[] {4, 5, 6};
+    double[] arr3 = new double[] {2, 3, 4};
+    DoubleVector vec1 = new DenseDoubleVector(arr1);
+    assertArrayEquals(arr2, vec1.slice(2, 4).toArray(), 0.000001);
+    DoubleVector vec2 = new DenseDoubleVector(arr1);
+    assertArrayEquals(arr3, vec2.slice(3).toArray(), 0.000001);
+  }
+  
+  @Test(expected = IllegalArgumentException.class)
+  public void testSliceAbnormal() {
+    double[] arr1 = new double[] {2, 3, 4, 5, 6};
+    DoubleVector vec = new DenseDoubleVector(arr1);
+    vec.slice(2, 5);
+  }
+  
+  @Test(expected = IllegalArgumentException.class)
+  public void testSliceAbnormalEndTooLarge() {
+    double[] arr1 = new double[] {2, 3, 4, 5, 6};
+    DoubleVector vec = new DenseDoubleVector(arr1);
+    vec.slice(2, 5);
+  }
+  
+  @Test(expected = IllegalArgumentException.class)
+  public void testSliceAbnormalStartLargerThanEnd() {
+    double[] arr1 = new double[] {2, 3, 4, 5, 6};
+    DoubleVector vec = new DenseDoubleVector(arr1);
+    vec.slice(4, 3);
+  }
+  
+  @Test
+  public void testVectorMultiplyMatrix() {
+    DoubleVector vec = new DenseDoubleVector(new double[]{1, 2, 3});
+    DoubleMatrix mat = new DenseDoubleMatrix(new double[][] {
+        {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}
+    });
+    double[] expectedRes = new double[] {38, 44, 50, 56};
+    
+    assertArrayEquals(expectedRes, vec.multiply(mat).toArray(), 0.000001);
+  }
+  
+  @Test(expected = IllegalArgumentException.class)
+  public void testVectorMultiplyMatrixAbnormal() {
+    DoubleVector vec = new DenseDoubleVector(new double[]{1, 2, 3});
+    DoubleMatrix mat = new DenseDoubleMatrix(new double[][] {
+        {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}
+    });
+    vec.multiply(mat);
+  }
+}

Added: hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestFunctionFactory.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestFunctionFactory.java?rev=1537427&view=auto
==============================================================================
--- hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestFunctionFactory.java (added)
+++ hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestFunctionFactory.java Thu Oct 31 10:32:38 2013
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.commons.math;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Random;
+
+import org.junit.Test;
+
+/**
+ * Test case for {@link FunctionFactory}
+ * 
+ */
+public class TestFunctionFactory {
+
+  @Test
+  public void testCreateDoubleFunction() {
+    double input = 0.8;
+    
+    String sigmoidName = "Sigmoid";
+    DoubleFunction sigmoidFunction = FunctionFactory
+        .createDoubleFunction(sigmoidName);
+    assertEquals(sigmoidName, sigmoidFunction.getFunctionName());
+    
+    double sigmoidExcepted = 0.68997448;
+    assertEquals(sigmoidExcepted, sigmoidFunction.apply(input), 0.000001);
+    
+    
+    String tanhName = "Tanh";
+    DoubleFunction tanhFunction = FunctionFactory.createDoubleFunction(tanhName);
+    assertEquals(tanhName, tanhFunction.getFunctionName());
+    
+    double tanhExpected = 0.66403677;
+    assertEquals(tanhExpected, tanhFunction.apply(input), 0.00001);
+    
+    
+    String identityFunctionName = "IdentityFunction";
+    DoubleFunction identityFunction = FunctionFactory.createDoubleFunction(identityFunctionName);
+    
+    Random rnd = new Random();
+    double identityExpected = rnd.nextDouble();
+    assertEquals(identityExpected, identityFunction.apply(identityExpected), 0.000001);
+  }
+  
+  @Test
+  public void testCreateDoubleDoubleFunction() {
+    double target = 0.5;
+    double output = 0.8;
+    
+    String squaredErrorName = "SquaredError";
+    DoubleDoubleFunction squaredErrorFunction = FunctionFactory.createDoubleDoubleFunction(squaredErrorName);
+    assertEquals(squaredErrorName, squaredErrorFunction.getFunctionName());
+    
+    double squaredErrorExpected = 0.045;
+    
+    assertEquals(squaredErrorExpected, squaredErrorFunction.apply(target, output), 0.000001);
+    
+    String crossEntropyName = "CrossEntropy";
+    DoubleDoubleFunction crossEntropyFunction = FunctionFactory.createDoubleDoubleFunction(crossEntropyName);
+    assertEquals(crossEntropyName, crossEntropyFunction.getFunctionName());
+    
+    double crossEntropyExpected = 0.91629;
+    assertEquals(crossEntropyExpected, crossEntropyFunction.apply(target, output), 0.000001);
+  }
+
+}

Modified: hama/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/hama/trunk/core/pom.xml?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/core/pom.xml (original)
+++ hama/trunk/core/pom.xml Thu Oct 31 10:32:38 2013
@@ -32,6 +32,11 @@
 
   <dependencies>
     <dependency>
+      <groupId>org.apache.hama</groupId>
+      <artifactId>hama-commons</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
       <groupId>org.xerial.snappy</groupId>
       <artifactId>snappy-java</artifactId>
       <version>1.0.5</version>

Modified: hama/trunk/core/src/main/java/org/apache/hama/bsp/BSPPeer.java
URL: http://svn.apache.org/viewvc/hama/trunk/core/src/main/java/org/apache/hama/bsp/BSPPeer.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/core/src/main/java/org/apache/hama/bsp/BSPPeer.java (original)
+++ hama/trunk/core/src/main/java/org/apache/hama/bsp/BSPPeer.java Thu Oct 31 10:32:38 2013
@@ -24,7 +24,7 @@ import org.apache.hadoop.io.Writable;
 import org.apache.hama.Constants;
 import org.apache.hama.bsp.Counters.Counter;
 import org.apache.hama.bsp.sync.SyncException;
-import org.apache.hama.util.KeyValuePair;
+import org.apache.hama.commons.util.KeyValuePair;
 
 /**
  * BSP communication interface. Reads key-value inputs, with K1 typed keys and

Modified: hama/trunk/core/src/main/java/org/apache/hama/bsp/BSPPeerImpl.java
URL: http://svn.apache.org/viewvc/hama/trunk/core/src/main/java/org/apache/hama/bsp/BSPPeerImpl.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/core/src/main/java/org/apache/hama/bsp/BSPPeerImpl.java (original)
+++ hama/trunk/core/src/main/java/org/apache/hama/bsp/BSPPeerImpl.java Thu Oct 31 10:32:38 2013
@@ -46,10 +46,10 @@ import org.apache.hama.bsp.message.queue
 import org.apache.hama.bsp.sync.PeerSyncClient;
 import org.apache.hama.bsp.sync.SyncException;
 import org.apache.hama.bsp.sync.SyncServiceFactory;
+import org.apache.hama.commons.util.KeyValuePair;
 import org.apache.hama.ipc.BSPPeerProtocol;
 import org.apache.hama.pipes.util.DistributedCacheUtil;
 import org.apache.hama.util.DistCacheUtils;
-import org.apache.hama.util.KeyValuePair;
 
 /**
  * This class represents a BSP peer.

Modified: hama/trunk/core/src/main/java/org/apache/hama/bsp/PartitioningRunner.java
URL: http://svn.apache.org/viewvc/hama/trunk/core/src/main/java/org/apache/hama/bsp/PartitioningRunner.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/core/src/main/java/org/apache/hama/bsp/PartitioningRunner.java (original)
+++ hama/trunk/core/src/main/java/org/apache/hama/bsp/PartitioningRunner.java Thu Oct 31 10:32:38 2013
@@ -36,7 +36,7 @@ import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.util.ReflectionUtils;
 import org.apache.hama.Constants;
 import org.apache.hama.bsp.sync.SyncException;
-import org.apache.hama.util.KeyValuePair;
+import org.apache.hama.commons.util.KeyValuePair;
 
 public class PartitioningRunner extends
     BSP<Writable, Writable, Writable, Writable, NullWritable> {

Modified: hama/trunk/core/src/main/java/org/apache/hama/pipes/protocol/StreamingProtocol.java
URL: http://svn.apache.org/viewvc/hama/trunk/core/src/main/java/org/apache/hama/pipes/protocol/StreamingProtocol.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/core/src/main/java/org/apache/hama/pipes/protocol/StreamingProtocol.java (original)
+++ hama/trunk/core/src/main/java/org/apache/hama/pipes/protocol/StreamingProtocol.java Thu Oct 31 10:32:38 2013
@@ -35,7 +35,7 @@ import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.Writable;
 import org.apache.hama.bsp.BSPPeer;
 import org.apache.hama.bsp.sync.SyncException;
-import org.apache.hama.util.KeyValuePair;
+import org.apache.hama.commons.util.KeyValuePair;
 
 /**
  * Streaming protocol that inherits from the binary protocol. Basically it

Modified: hama/trunk/core/src/main/java/org/apache/hama/pipes/protocol/UplinkReader.java
URL: http://svn.apache.org/viewvc/hama/trunk/core/src/main/java/org/apache/hama/pipes/protocol/UplinkReader.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/core/src/main/java/org/apache/hama/pipes/protocol/UplinkReader.java (original)
+++ hama/trunk/core/src/main/java/org/apache/hama/pipes/protocol/UplinkReader.java Thu Oct 31 10:32:38 2013
@@ -44,7 +44,7 @@ import org.apache.hadoop.util.StringUtil
 import org.apache.hama.Constants;
 import org.apache.hama.bsp.BSPPeer;
 import org.apache.hama.bsp.sync.SyncException;
-import org.apache.hama.util.KeyValuePair;
+import org.apache.hama.commons.util.KeyValuePair;
 
 public class UplinkReader<K1 extends Writable, V1 extends Writable, K2 extends Writable, V2 extends Writable>
     extends Thread {

Modified: hama/trunk/core/src/test/java/org/apache/hama/bsp/TestCheckpoint.java
URL: http://svn.apache.org/viewvc/hama/trunk/core/src/test/java/org/apache/hama/bsp/TestCheckpoint.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/core/src/test/java/org/apache/hama/bsp/TestCheckpoint.java (original)
+++ hama/trunk/core/src/test/java/org/apache/hama/bsp/TestCheckpoint.java Thu Oct 31 10:32:38 2013
@@ -58,8 +58,8 @@ import org.apache.hama.bsp.sync.SyncEven
 import org.apache.hama.bsp.sync.SyncEventListener;
 import org.apache.hama.bsp.sync.SyncException;
 import org.apache.hama.bsp.sync.SyncServiceFactory;
+import org.apache.hama.commons.util.KeyValuePair;
 import org.apache.hama.util.BSPNetUtils;
-import org.apache.hama.util.KeyValuePair;
 
 public class TestCheckpoint extends TestCase {
 

Modified: hama/trunk/core/src/test/java/org/apache/hama/bsp/TestKeyValueTextInputFormat.java
URL: http://svn.apache.org/viewvc/hama/trunk/core/src/test/java/org/apache/hama/bsp/TestKeyValueTextInputFormat.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/core/src/test/java/org/apache/hama/bsp/TestKeyValueTextInputFormat.java (original)
+++ hama/trunk/core/src/test/java/org/apache/hama/bsp/TestKeyValueTextInputFormat.java Thu Oct 31 10:32:38 2013
@@ -22,6 +22,8 @@ import java.net.URI;
 import java.util.HashMap;
 import java.util.Map;
 
+import junit.framework.TestCase;
+
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FSDataOutputStream;
 import org.apache.hadoop.fs.FileSystem;
@@ -33,11 +35,9 @@ import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.Writable;
 import org.apache.hama.HamaConfiguration;
 import org.apache.hama.bsp.sync.SyncException;
-import org.apache.hama.util.KeyValuePair;
+import org.apache.hama.commons.util.KeyValuePair;
 import org.junit.Test;
 
-import junit.framework.TestCase;
-
 public class TestKeyValueTextInputFormat extends TestCase {
 
   public static class KeyValueHashPartitionedBSP 

Modified: hama/trunk/core/src/test/java/org/apache/hama/bsp/TestPartitioning.java
URL: http://svn.apache.org/viewvc/hama/trunk/core/src/test/java/org/apache/hama/bsp/TestPartitioning.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/core/src/test/java/org/apache/hama/bsp/TestPartitioning.java (original)
+++ hama/trunk/core/src/test/java/org/apache/hama/bsp/TestPartitioning.java Thu Oct 31 10:32:38 2013
@@ -32,7 +32,7 @@ import org.apache.hama.HamaCluster;
 import org.apache.hama.HamaConfiguration;
 import org.apache.hama.bsp.message.queue.DiskQueue;
 import org.apache.hama.bsp.sync.SyncException;
-import org.apache.hama.util.KeyValuePair;
+import org.apache.hama.commons.util.KeyValuePair;
 
 public class TestPartitioning extends HamaCluster {
 

Modified: hama/trunk/examples/pom.xml
URL: http://svn.apache.org/viewvc/hama/trunk/examples/pom.xml?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/examples/pom.xml (original)
+++ hama/trunk/examples/pom.xml Thu Oct 31 10:32:38 2013
@@ -33,6 +33,11 @@
   <dependencies>
     <dependency>
       <groupId>org.apache.hama</groupId>
+      <artifactId>hama-commons</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hama</groupId>
       <artifactId>hama-core</artifactId>
       <version>${project.version}</version>
     </dependency>

Modified: hama/trunk/examples/src/main/java/org/apache/hama/examples/BipartiteMatching.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/main/java/org/apache/hama/examples/BipartiteMatching.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/examples/src/main/java/org/apache/hama/examples/BipartiteMatching.java (original)
+++ hama/trunk/examples/src/main/java/org/apache/hama/examples/BipartiteMatching.java Thu Oct 31 10:32:38 2013
@@ -33,7 +33,7 @@ import org.apache.hama.HamaConfiguration
 import org.apache.hama.bsp.HashPartitioner;
 import org.apache.hama.bsp.TextInputFormat;
 import org.apache.hama.bsp.TextOutputFormat;
-import org.apache.hama.examples.util.TextPair;
+import org.apache.hama.commons.util.TextPair;
 import org.apache.hama.graph.Edge;
 import org.apache.hama.graph.GraphJob;
 import org.apache.hama.graph.Vertex;

Modified: hama/trunk/examples/src/main/java/org/apache/hama/examples/GradientDescentExample.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/main/java/org/apache/hama/examples/GradientDescentExample.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/examples/src/main/java/org/apache/hama/examples/GradientDescentExample.java (original)
+++ hama/trunk/examples/src/main/java/org/apache/hama/examples/GradientDescentExample.java Thu Oct 31 10:32:38 2013
@@ -29,11 +29,11 @@ import org.apache.hama.HamaConfiguration
 import org.apache.hama.bsp.BSPJob;
 import org.apache.hama.bsp.FileOutputFormat;
 import org.apache.hama.bsp.TextOutputFormat;
+import org.apache.hama.commons.io.VectorWritable;
 import org.apache.hama.ml.regression.GradientDescentBSP;
 import org.apache.hama.ml.regression.LogisticRegressionModel;
 import org.apache.hama.ml.regression.RegressionModel;
 import org.apache.hama.ml.regression.VectorDoubleFileInputFormat;
-import org.apache.hama.ml.writable.VectorWritable;
 
 /**
  * A {@link GradientDescentBSP} job example

Modified: hama/trunk/examples/src/main/java/org/apache/hama/examples/InlinkCount.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/main/java/org/apache/hama/examples/InlinkCount.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/examples/src/main/java/org/apache/hama/examples/InlinkCount.java (original)
+++ hama/trunk/examples/src/main/java/org/apache/hama/examples/InlinkCount.java Thu Oct 31 10:32:38 2013
@@ -26,8 +26,8 @@ import org.apache.hadoop.io.Text;
 import org.apache.hama.HamaConfiguration;
 import org.apache.hama.bsp.HashPartitioner;
 import org.apache.hama.bsp.SequenceFileOutputFormat;
-import org.apache.hama.bsp.TextArrayWritable;
 import org.apache.hama.bsp.TextInputFormat;
+import org.apache.hama.commons.io.TextArrayWritable;
 import org.apache.hama.graph.GraphJob;
 import org.apache.hama.graph.Vertex;
 

Modified: hama/trunk/examples/src/main/java/org/apache/hama/examples/Kmeans.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/main/java/org/apache/hama/examples/Kmeans.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/examples/src/main/java/org/apache/hama/examples/Kmeans.java (original)
+++ hama/trunk/examples/src/main/java/org/apache/hama/examples/Kmeans.java Thu Oct 31 10:32:38 2013
@@ -22,8 +22,8 @@ import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.NullWritable;
 import org.apache.hama.bsp.BSPJob;
+import org.apache.hama.commons.io.VectorWritable;
 import org.apache.hama.ml.kmeans.KMeansBSP;
-import org.apache.hama.ml.writable.VectorWritable;
 
 /**
  * Uses the {@link KMeansBSP} class to run a Kmeans Clustering with BSP. You can

Modified: hama/trunk/examples/src/main/java/org/apache/hama/examples/NeuralNetwork.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/main/java/org/apache/hama/examples/NeuralNetwork.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/examples/src/main/java/org/apache/hama/examples/NeuralNetwork.java (original)
+++ hama/trunk/examples/src/main/java/org/apache/hama/examples/NeuralNetwork.java Thu Oct 31 10:32:38 2013
@@ -28,10 +28,10 @@ import java.util.Map;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
+import org.apache.hama.commons.math.DenseDoubleVector;
+import org.apache.hama.commons.math.DoubleVector;
+import org.apache.hama.commons.math.FunctionFactory;
 import org.apache.hama.ml.ann.SmallLayeredNeuralNetwork;
-import org.apache.hama.ml.math.DenseDoubleVector;
-import org.apache.hama.ml.math.DoubleVector;
-import org.apache.hama.ml.math.FunctionFactory;
 
 /**
  * The example of using {@link SmallLayeredNeuralNetwork}, including the

Modified: hama/trunk/examples/src/main/java/org/apache/hama/examples/PageRank.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/main/java/org/apache/hama/examples/PageRank.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/examples/src/main/java/org/apache/hama/examples/PageRank.java (original)
+++ hama/trunk/examples/src/main/java/org/apache/hama/examples/PageRank.java Thu Oct 31 10:32:38 2013
@@ -28,8 +28,8 @@ import org.apache.hadoop.io.Writable;
 import org.apache.hama.HamaConfiguration;
 import org.apache.hama.bsp.HashPartitioner;
 import org.apache.hama.bsp.SequenceFileInputFormat;
-import org.apache.hama.bsp.TextArrayWritable;
 import org.apache.hama.bsp.TextOutputFormat;
+import org.apache.hama.commons.io.TextArrayWritable;
 import org.apache.hama.graph.AverageAggregator;
 import org.apache.hama.graph.Edge;
 import org.apache.hama.graph.GraphJob;

Modified: hama/trunk/examples/src/main/java/org/apache/hama/examples/SpMV.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/main/java/org/apache/hama/examples/SpMV.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/examples/src/main/java/org/apache/hama/examples/SpMV.java (original)
+++ hama/trunk/examples/src/main/java/org/apache/hama/examples/SpMV.java Thu Oct 31 10:32:38 2013
@@ -42,9 +42,9 @@ import org.apache.hama.bsp.FileOutputFor
 import org.apache.hama.bsp.SequenceFileInputFormat;
 import org.apache.hama.bsp.SequenceFileOutputFormat;
 import org.apache.hama.bsp.sync.SyncException;
-import org.apache.hama.examples.util.DenseVectorWritable;
-import org.apache.hama.examples.util.SparseVectorWritable;
-import org.apache.hama.util.KeyValuePair;
+import org.apache.hama.commons.io.DenseVectorWritable;
+import org.apache.hama.commons.io.SparseVectorWritable;
+import org.apache.hama.commons.util.KeyValuePair;
 
 /**
  * Sparse matrix vector multiplication. Currently it uses row-wise access.

Modified: hama/trunk/examples/src/main/java/org/apache/hama/examples/util/FastGraphGen.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/main/java/org/apache/hama/examples/util/FastGraphGen.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/examples/src/main/java/org/apache/hama/examples/util/FastGraphGen.java (original)
+++ hama/trunk/examples/src/main/java/org/apache/hama/examples/util/FastGraphGen.java Thu Oct 31 10:32:38 2013
@@ -34,8 +34,8 @@ import org.apache.hama.bsp.BSPPeer;
 import org.apache.hama.bsp.FileOutputFormat;
 import org.apache.hama.bsp.NullInputFormat;
 import org.apache.hama.bsp.SequenceFileOutputFormat;
-import org.apache.hama.bsp.TextArrayWritable;
 import org.apache.hama.bsp.sync.SyncException;
+import org.apache.hama.commons.io.TextArrayWritable;
 
 import com.google.common.collect.Sets;
 

Modified: hama/trunk/examples/src/main/java/org/apache/hama/examples/util/SymmetricMatrixGen.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/main/java/org/apache/hama/examples/util/SymmetricMatrixGen.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/examples/src/main/java/org/apache/hama/examples/util/SymmetricMatrixGen.java (original)
+++ hama/trunk/examples/src/main/java/org/apache/hama/examples/util/SymmetricMatrixGen.java Thu Oct 31 10:32:38 2013
@@ -37,8 +37,8 @@ import org.apache.hama.bsp.BSPPeer;
 import org.apache.hama.bsp.FileOutputFormat;
 import org.apache.hama.bsp.NullInputFormat;
 import org.apache.hama.bsp.SequenceFileOutputFormat;
-import org.apache.hama.bsp.TextArrayWritable;
 import org.apache.hama.bsp.sync.SyncException;
+import org.apache.hama.commons.io.TextArrayWritable;
 import org.apache.hama.examples.CombineExample;
 
 public class SymmetricMatrixGen {

Modified: hama/trunk/examples/src/test/java/org/apache/hama/examples/BipartiteMatchingTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/test/java/org/apache/hama/examples/BipartiteMatchingTest.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/examples/src/test/java/org/apache/hama/examples/BipartiteMatchingTest.java (original)
+++ hama/trunk/examples/src/test/java/org/apache/hama/examples/BipartiteMatchingTest.java Thu Oct 31 10:32:38 2013
@@ -36,7 +36,7 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.Text;
 import org.apache.hama.HamaConfiguration;
 import org.apache.hama.bsp.Partitioner;
-import org.apache.hama.examples.util.TextPair;
+import org.apache.hama.commons.util.TextPair;
 import org.apache.hama.graph.GraphJob;
 import org.junit.Test;
 

Modified: hama/trunk/examples/src/test/java/org/apache/hama/examples/FastGraphGenTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/test/java/org/apache/hama/examples/FastGraphGenTest.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/examples/src/test/java/org/apache/hama/examples/FastGraphGenTest.java (original)
+++ hama/trunk/examples/src/test/java/org/apache/hama/examples/FastGraphGenTest.java Thu Oct 31 10:32:38 2013
@@ -28,7 +28,7 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.SequenceFile;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.Writable;
-import org.apache.hama.bsp.TextArrayWritable;
+import org.apache.hama.commons.io.TextArrayWritable;
 import org.apache.hama.examples.util.FastGraphGen;
 import org.junit.Test;
 

Modified: hama/trunk/examples/src/test/java/org/apache/hama/examples/NeuralNetworkTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/test/java/org/apache/hama/examples/NeuralNetworkTest.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/examples/src/test/java/org/apache/hama/examples/NeuralNetworkTest.java (original)
+++ hama/trunk/examples/src/test/java/org/apache/hama/examples/NeuralNetworkTest.java Thu Oct 31 10:32:38 2013
@@ -31,8 +31,8 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.SequenceFile;
 import org.apache.hama.HamaConfiguration;
-import org.apache.hama.ml.math.DenseDoubleVector;
-import org.apache.hama.ml.writable.VectorWritable;
+import org.apache.hama.commons.io.VectorWritable;
+import org.apache.hama.commons.math.DenseDoubleVector;
 
 /**
  * Test the functionality of NeuralNetwork Example.

Modified: hama/trunk/examples/src/test/java/org/apache/hama/examples/SpMVTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/test/java/org/apache/hama/examples/SpMVTest.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/examples/src/test/java/org/apache/hama/examples/SpMVTest.java (original)
+++ hama/trunk/examples/src/test/java/org/apache/hama/examples/SpMVTest.java Thu Oct 31 10:32:38 2013
@@ -32,8 +32,8 @@ import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.SequenceFile;
 import org.apache.hadoop.io.Writable;
 import org.apache.hama.HamaConfiguration;
-import org.apache.hama.examples.util.DenseVectorWritable;
-import org.apache.hama.examples.util.SparseVectorWritable;
+import org.apache.hama.commons.io.DenseVectorWritable;
+import org.apache.hama.commons.io.SparseVectorWritable;
 import org.junit.Before;
 import org.junit.Test;
 

Modified: hama/trunk/examples/src/test/java/org/apache/hama/examples/SymmetricMatrixGenTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/test/java/org/apache/hama/examples/SymmetricMatrixGenTest.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/examples/src/test/java/org/apache/hama/examples/SymmetricMatrixGenTest.java (original)
+++ hama/trunk/examples/src/test/java/org/apache/hama/examples/SymmetricMatrixGenTest.java Thu Oct 31 10:32:38 2013
@@ -26,7 +26,7 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.SequenceFile;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.Writable;
-import org.apache.hama.bsp.TextArrayWritable;
+import org.apache.hama.commons.io.TextArrayWritable;
 import org.apache.hama.examples.util.SymmetricMatrixGen;
 import org.junit.Test;
 

Modified: hama/trunk/graph/pom.xml
URL: http://svn.apache.org/viewvc/hama/trunk/graph/pom.xml?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/graph/pom.xml (original)
+++ hama/trunk/graph/pom.xml Thu Oct 31 10:32:38 2013
@@ -33,6 +33,11 @@
   <dependencies>
     <dependency>
       <groupId>org.apache.hama</groupId>
+      <artifactId>hama-commons</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hama</groupId>
       <artifactId>hama-core</artifactId>
       <version>${project.version}</version>
     </dependency>

Modified: hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java
URL: http://svn.apache.org/viewvc/hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java (original)
+++ hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java Thu Oct 31 10:32:38 2013
@@ -39,8 +39,8 @@ import org.apache.hama.bsp.Partitioner;
 import org.apache.hama.bsp.PartitioningRunner.DefaultRecordConverter;
 import org.apache.hama.bsp.PartitioningRunner.RecordConverter;
 import org.apache.hama.bsp.sync.SyncException;
+import org.apache.hama.commons.util.KeyValuePair;
 import org.apache.hama.graph.IDSkippingIterator.Strategy;
-import org.apache.hama.util.KeyValuePair;
 import org.apache.hama.util.ReflectionUtils;
 
 /**

Modified: hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexInputReader.java
URL: http://svn.apache.org/viewvc/hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexInputReader.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexInputReader.java (original)
+++ hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexInputReader.java Thu Oct 31 10:32:38 2013
@@ -31,7 +31,7 @@ import org.apache.hadoop.io.WritableComp
 import org.apache.hama.bsp.BSPPeer;
 import org.apache.hama.bsp.Partitioner;
 import org.apache.hama.bsp.PartitioningRunner.RecordConverter;
-import org.apache.hama.util.KeyValuePair;
+import org.apache.hama.commons.util.KeyValuePair;
 
 /**
  * A reader to read Hama's input files and parses a vertex out of it.

Modified: hama/trunk/graph/src/test/java/org/apache/hama/graph/TestSubmitGraphJob.java
URL: http://svn.apache.org/viewvc/hama/trunk/graph/src/test/java/org/apache/hama/graph/TestSubmitGraphJob.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/graph/src/test/java/org/apache/hama/graph/TestSubmitGraphJob.java (original)
+++ hama/trunk/graph/src/test/java/org/apache/hama/graph/TestSubmitGraphJob.java Thu Oct 31 10:32:38 2013
@@ -36,7 +36,7 @@ import org.apache.hama.bsp.HashPartition
 import org.apache.hama.bsp.SequenceFileInputFormat;
 import org.apache.hama.bsp.SequenceFileOutputFormat;
 import org.apache.hama.bsp.TestBSPMasterGroomServer;
-import org.apache.hama.bsp.TextArrayWritable;
+import org.apache.hama.commons.io.TextArrayWritable;
 import org.apache.hama.graph.example.PageRank;
 import org.apache.hama.graph.example.PageRank.PagerankSeqReader;
 import org.junit.Before;

Modified: hama/trunk/graph/src/test/java/org/apache/hama/graph/example/PageRank.java
URL: http://svn.apache.org/viewvc/hama/trunk/graph/src/test/java/org/apache/hama/graph/example/PageRank.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/graph/src/test/java/org/apache/hama/graph/example/PageRank.java (original)
+++ hama/trunk/graph/src/test/java/org/apache/hama/graph/example/PageRank.java Thu Oct 31 10:32:38 2013
@@ -28,8 +28,8 @@ import org.apache.hadoop.io.Writable;
 import org.apache.hama.HamaConfiguration;
 import org.apache.hama.bsp.HashPartitioner;
 import org.apache.hama.bsp.SequenceFileInputFormat;
-import org.apache.hama.bsp.TextArrayWritable;
 import org.apache.hama.bsp.TextOutputFormat;
+import org.apache.hama.commons.io.TextArrayWritable;
 import org.apache.hama.graph.AverageAggregator;
 import org.apache.hama.graph.Edge;
 import org.apache.hama.graph.GraphJob;

Modified: hama/trunk/ml/pom.xml
URL: http://svn.apache.org/viewvc/hama/trunk/ml/pom.xml?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/ml/pom.xml (original)
+++ hama/trunk/ml/pom.xml Thu Oct 31 10:32:38 2013
@@ -33,6 +33,11 @@
   <dependencies>
     <dependency>
       <groupId>org.apache.hama</groupId>
+      <artifactId>hama-commons</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hama</groupId>
       <artifactId>hama-core</artifactId>
       <version>${project.version}</version>
     </dependency>

Modified: hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/AbstractLayeredNeuralNetwork.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/AbstractLayeredNeuralNetwork.java?rev=1537427&r1=1537426&r2=1537427&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/AbstractLayeredNeuralNetwork.java (original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/AbstractLayeredNeuralNetwork.java Thu Oct 31 10:32:38 2013
@@ -24,11 +24,11 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.hadoop.io.WritableUtils;
-import org.apache.hama.ml.math.DoubleDoubleFunction;
-import org.apache.hama.ml.math.DoubleFunction;
-import org.apache.hama.ml.math.DoubleMatrix;
-import org.apache.hama.ml.math.DoubleVector;
-import org.apache.hama.ml.math.FunctionFactory;
+import org.apache.hama.commons.math.DoubleDoubleFunction;
+import org.apache.hama.commons.math.DoubleFunction;
+import org.apache.hama.commons.math.DoubleMatrix;
+import org.apache.hama.commons.math.DoubleVector;
+import org.apache.hama.commons.math.FunctionFactory;
 
 import com.google.common.base.Preconditions;
 



Mime
View raw message