You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hama.apache.org by ed...@apache.org on 2008/08/22 08:02:29 UTC

svn commit: r687955 - in /incubator/hama/trunk/src: java/org/apache/hama/ java/org/apache/hama/io/ java/org/apache/hama/mapred/ java/org/apache/hama/util/ test/org/apache/hama/util/

Author: edwardyoon
Date: Thu Aug 21 23:02:28 2008
New Revision: 687955

URL: http://svn.apache.org/viewvc?rev=687955&view=rev
Log: (empty)

Added:
    incubator/hama/trunk/src/java/org/apache/hama/util/
    incubator/hama/trunk/src/java/org/apache/hama/util/Numeric.java
    incubator/hama/trunk/src/java/org/apache/hama/util/RandomVariable.java
    incubator/hama/trunk/src/java/org/apache/hama/util/package.html
    incubator/hama/trunk/src/test/org/apache/hama/util/
    incubator/hama/trunk/src/test/org/apache/hama/util/TestRandomVariable.java
Modified:
    incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java
    incubator/hama/trunk/src/java/org/apache/hama/Matrix.java
    incubator/hama/trunk/src/java/org/apache/hama/Vector.java
    incubator/hama/trunk/src/java/org/apache/hama/io/VectorWritable.java
    incubator/hama/trunk/src/java/org/apache/hama/mapred/MatrixInputFormatBase.java

Modified: incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java?rev=687955&r1=687954&r2=687955&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java Thu Aug 21 23:02:28 2008
@@ -1,172 +1,173 @@
-/**
- * Copyright 2007 The Apache Software Foundation
- *
- * 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;
-
-import java.io.IOException;
-
-import org.apache.hadoop.hbase.HColumnDescriptor;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.MasterNotRunningException;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.client.HTable;
-import org.apache.hadoop.hbase.io.BatchUpdate;
-import org.apache.hadoop.hbase.io.Cell;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.io.Text;
-import org.apache.log4j.Logger;
-
-/**
- * Methods of the matrix classes
- */
-public abstract class AbstractMatrix extends AbstractBase implements
-    MatrixInterface {
-  static final Logger LOG = Logger.getLogger(AbstractMatrix.class);
-
-  /** Hama Configuration */
-  protected HamaConfiguration config;
-  /** Hbase admin object */
-  protected HBaseAdmin admin;
-  /** The name of Matrix */
-  protected String matrixName;
-  /** Hbase table object */
-  protected HTable table;
-  /** Matrix attribute description */
-  protected HTableDescriptor tableDesc;
-
-  /**
-   * Sets the job configuration
-   * 
-   * @param conf configuration object
-   */
-  public void setConfiguration(HamaConfiguration conf) {
-    config = (HamaConfiguration) conf;
-    try {
-        admin = new HBaseAdmin(config);
-    } catch (MasterNotRunningException e) {
-      LOG.error(e, e);
-    }
-  }
-
-  /**
-   * Create matrix space
-   */
-  protected void create() {
-    try {
-      tableDesc.addFamily(new HColumnDescriptor(Constants.METADATA));
-      LOG.info("Initializing the matrix storage.");
-      admin.createTable(tableDesc);
-    } catch (IOException e) {
-      LOG.error(e, e);
-    }
-  }
-
-  /** {@inheritDoc} */
-  public double get(int i, int j) {
-    String row = String.valueOf(i);
-    String column = Constants.COLUMN + String.valueOf(j);
-    Cell c;
-    double result = -1;
-    try {
-      c = table.get(row, column);
-      if (c != null) {
-        result = bytesToDouble(c.getValue());
-      }
-    } catch (IOException e) {
-      LOG.error(e, e);
-    }
-    return result;
-  }
-
-  /** {@inheritDoc} */
-  public Vector getRow(int row) {
-    try {
-      return new Vector(row, table.getRow(String.valueOf(row)));
-    } catch (IOException e) {
-      LOG.error(e, e);
-    }
-    return null;
-  }
-
-  public Vector getRow(byte[] row) {
-    try {
-      return new Vector(bytesToInt(row), table.getRow(row));
-    } catch (IOException e) {
-      LOG.error(e, e);
-    }
-    return null;
-  }
-
-  /** {@inheritDoc} */
-  public int getRows() {
-    Cell rows = null;
-    try {
-      rows = table.get(Constants.METADATA, Constants.METADATA_ROWS);
-    } catch (IOException e) {
-      LOG.error(e, e);
-    }
-
-    return Bytes.toInt(rows.getValue());
-  }
-
-  /** {@inheritDoc} */
-  public int getColumns() {
-    Cell columns = null;
-    try {
-      columns = table.get(Constants.METADATA, Constants.METADATA_COLUMNS);
-    } catch (IOException e) {
-      LOG.error(e, e);
-    }
-    return Bytes.toInt(columns.getValue());
-  }
-
-  /** {@inheritDoc} */
-  public void set(int i, int j, double value) {
-    BatchUpdate b = new BatchUpdate(new Text(String.valueOf(i)));
-    b.put(new Text(Constants.COLUMN + String.valueOf(j)), doubleToBytes(value));
-    try {
-      table.commit(b);
-    } catch (IOException e) {
-      LOG.error(e, e);
-    }
-  }
-
-  /** {@inheritDoc} */
-  public void add(int i, int j, double value) {
-    // TODO Auto-generated method stub
-  }
-
-  /** {@inheritDoc} */
-  public void setDimension(int rows, int columns) {
-    BatchUpdate b = new BatchUpdate(Constants.METADATA);
-    b.put(Constants.METADATA_ROWS, Bytes.toBytes(rows));
-    b.put(Constants.METADATA_COLUMNS, Bytes.toBytes(columns));
-
-    try {
-      table.commit(b);
-    } catch (IOException e) {
-      LOG.error(e, e);
-    }
-  }
-
-  /** {@inheritDoc} */
-  public String getName() {
-    return (matrixName != null) ? matrixName.toString() : null;
-  }
-}
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.MasterNotRunningException;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.io.BatchUpdate;
+import org.apache.hadoop.hbase.io.Cell;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.io.Text;
+import org.apache.hama.util.Numeric;
+import org.apache.log4j.Logger;
+
+/**
+ * Methods of the matrix classes
+ */
+public abstract class AbstractMatrix implements MatrixInterface {
+  static final Logger LOG = Logger.getLogger(AbstractMatrix.class);
+
+  /** Hama Configuration */
+  protected HamaConfiguration config;
+  /** Hbase admin object */
+  protected HBaseAdmin admin;
+  /** The name of Matrix */
+  protected String matrixName;
+  /** Hbase table object */
+  protected HTable table;
+  /** Matrix attribute description */
+  protected HTableDescriptor tableDesc;
+
+  /**
+   * Sets the job configuration
+   * 
+   * @param conf configuration object
+   */
+  public void setConfiguration(HamaConfiguration conf) {
+    config = (HamaConfiguration) conf;
+    try {
+      admin = new HBaseAdmin(config);
+    } catch (MasterNotRunningException e) {
+      LOG.error(e, e);
+    }
+  }
+
+  /**
+   * Create matrix space
+   */
+  protected void create() {
+    try {
+      tableDesc.addFamily(new HColumnDescriptor(Constants.METADATA));
+      LOG.info("Initializing the matrix storage.");
+      admin.createTable(tableDesc);
+    } catch (IOException e) {
+      LOG.error(e, e);
+    }
+  }
+
+  /** {@inheritDoc} */
+  public double get(int i, int j) {
+    String row = String.valueOf(i);
+    String column = Constants.COLUMN + String.valueOf(j);
+    Cell c;
+    double result = -1;
+    try {
+      c = table.get(row, column);
+      if (c != null) {
+        result = Numeric.bytesToDouble(c.getValue());
+      }
+    } catch (IOException e) {
+      LOG.error(e, e);
+    }
+    return result;
+  }
+
+  /** {@inheritDoc} */
+  public Vector getRow(int row) {
+    try {
+      return new Vector(row, table.getRow(String.valueOf(row)));
+    } catch (IOException e) {
+      LOG.error(e, e);
+    }
+    return null;
+  }
+
+  public Vector getRow(byte[] row) {
+    try {
+      return new Vector(Numeric.bytesToInt(row), table.getRow(row));
+    } catch (IOException e) {
+      LOG.error(e, e);
+    }
+    return null;
+  }
+
+  /** {@inheritDoc} */
+  public int getRows() {
+    Cell rows = null;
+    try {
+      rows = table.get(Constants.METADATA, Constants.METADATA_ROWS);
+    } catch (IOException e) {
+      LOG.error(e, e);
+    }
+
+    return Bytes.toInt(rows.getValue());
+  }
+
+  /** {@inheritDoc} */
+  public int getColumns() {
+    Cell columns = null;
+    try {
+      columns = table.get(Constants.METADATA, Constants.METADATA_COLUMNS);
+    } catch (IOException e) {
+      LOG.error(e, e);
+    }
+    return Bytes.toInt(columns.getValue());
+  }
+
+  /** {@inheritDoc} */
+  public void set(int i, int j, double value) {
+    BatchUpdate b = new BatchUpdate(new Text(String.valueOf(i)));
+    b.put(new Text(Constants.COLUMN + String.valueOf(j)), Numeric
+        .doubleToBytes(value));
+    try {
+      table.commit(b);
+    } catch (IOException e) {
+      LOG.error(e, e);
+    }
+  }
+
+  /** {@inheritDoc} */
+  public void add(int i, int j, double value) {
+    // TODO Auto-generated method stub
+  }
+
+  /** {@inheritDoc} */
+  public void setDimension(int rows, int columns) {
+    BatchUpdate b = new BatchUpdate(Constants.METADATA);
+    b.put(Constants.METADATA_ROWS, Bytes.toBytes(rows));
+    b.put(Constants.METADATA_COLUMNS, Bytes.toBytes(columns));
+
+    try {
+      table.commit(b);
+    } catch (IOException e) {
+      LOG.error(e, e);
+    }
+  }
+
+  /** {@inheritDoc} */
+  public String getName() {
+    return (matrixName != null) ? matrixName.toString() : null;
+  }
+}

Modified: incubator/hama/trunk/src/java/org/apache/hama/Matrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/Matrix.java?rev=687955&r1=687954&r2=687955&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/Matrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/Matrix.java Thu Aug 21 23:02:28 2008
@@ -1,177 +1,178 @@
-/**
- * Copyright 2007 The Apache Software Foundation
- *
- * 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;
-
-import java.io.IOException;
-
-import org.apache.hadoop.hbase.HColumnDescriptor;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.client.HTable;
-import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-import org.apache.hadoop.mapred.JobClient;
-import org.apache.hadoop.mapred.JobConf;
-import org.apache.hama.algebra.AdditionMap;
-import org.apache.hama.algebra.AdditionReduce;
-import org.apache.hama.mapred.MatrixMap;
-import org.apache.hama.mapred.MatrixReduce;
-
-/**
- * A library for mathematical operations on matrices of double.
- */
-public class Matrix extends AbstractMatrix {
-
-  /**
-   * Construct
-   * 
-   * @param conf configuration object
-   */
-  public Matrix(HamaConfiguration conf) {
-    setConfiguration(conf);
-  }
-
-  /**
-   * Construct an matrix
-   * 
-   * @param conf configuration object
-   * @param matrixName the name of the matrix
-   */
-  public Matrix(HamaConfiguration conf, String matrixName) {
-    try {
-      setConfiguration(conf);
-      this.matrixName = matrixName;
-
-      if (!admin.tableExists(matrixName)) {
-        tableDesc = new HTableDescriptor(matrixName.toString());
-        tableDesc.addFamily(new HColumnDescriptor(Constants.COLUMN.toString()));
-        create();
-      }
-
-      table = new HTable(config, matrixName);
-    } catch (Exception e) {
-      e.printStackTrace();
-    }
-  }
-
-  /**
-   * Construct an m-by-n constant matrix.
-   * 
-   * @param conf configuration object
-   * @param m the number of rows.
-   * @param n the number of columns.
-   * @param s fill the matrix with this scalar value.
-   */
-  public Matrix(HamaConfiguration conf, int m, int n, double s) {
-    try {
-      setConfiguration(conf);
-      matrixName = RandomVariable.randMatrixName();
-
-      if (!admin.tableExists(matrixName)) {
-        tableDesc = new HTableDescriptor(matrixName.toString());
-        tableDesc.addFamily(new HColumnDescriptor(Constants.COLUMN.toString()));
-        create();
-      }
-
-      table = new HTable(config, matrixName);
-
-      for (int i = 0; i < m; i++) {
-        for (int j = 0; j < n; j++) {
-          set(i, j, s);
-        }
-      }
-
-      setDimension(m, n);
-    } catch (IOException e) {
-      e.printStackTrace();
-    }
-  }
-
-  /**
-   * Generate matrix with random elements
-   * 
-   * @param conf configuration object
-   * @param m the number of rows.
-   * @param n the number of columns.
-   * @return an m-by-n matrix with uniformly distributed random elements.
-   */
-  public static Matrix random(HamaConfiguration conf, int m, int n) {
-    String name = RandomVariable.randMatrixName();
-    Matrix rand = new Matrix(conf, name);
-    for (int i = 0; i < m; i++) {
-      for (int j = 0; j < n; j++) {
-        rand.set(i, j, RandomVariable.rand());
-      }
-    }
-
-    rand.setDimension(m, n);
-    LOG.info("Create the " + m + " * " + n + " random matrix : " + name);
-    return rand;
-  }
-
-  public Matrix add(Matrix B) {
-    String output = RandomVariable.randMatrixName();
-    Matrix C = new Matrix(config, output);
-
-    JobConf jobConf = new JobConf(config);
-    jobConf.setJobName("addition MR job");
-
-    MatrixMap.initJob(this.getName(), B.getName(), AdditionMap.class,
-        ImmutableBytesWritable.class, Vector.class, jobConf);
-    MatrixReduce.initJob(C.getName(), AdditionReduce.class, jobConf);
-
-    try {
-      JobClient.runJob(jobConf);
-    } catch (IOException e) {
-      // TODO Auto-generated catch block
-      e.printStackTrace();
-    }
-
-    return C;
-  }
-
-  public Matrix add(double alpha, Matrix B) {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-  public Matrix mult(Matrix B) {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-  public Matrix multAdd(double alpha, Matrix B, Matrix C) {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-  public double norm(Norm type) {
-    // TODO Auto-generated method stub
-    return 0;
-  }
-
-  public Matrix set(double alpha, Matrix B) {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-  public Matrix set(Matrix B) {
-    // TODO Auto-generated method stub
-    return null;
-  }
-}
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.mapred.JobClient;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hama.algebra.AdditionMap;
+import org.apache.hama.algebra.AdditionReduce;
+import org.apache.hama.mapred.MatrixMap;
+import org.apache.hama.mapred.MatrixReduce;
+import org.apache.hama.util.RandomVariable;
+
+/**
+ * A library for mathematical operations on matrices of double.
+ */
+public class Matrix extends AbstractMatrix {
+
+  /**
+   * Construct
+   * 
+   * @param conf configuration object
+   */
+  public Matrix(HamaConfiguration conf) {
+    setConfiguration(conf);
+  }
+
+  /**
+   * Construct an matrix
+   * 
+   * @param conf configuration object
+   * @param matrixName the name of the matrix
+   */
+  public Matrix(HamaConfiguration conf, String matrixName) {
+    try {
+      setConfiguration(conf);
+      this.matrixName = matrixName;
+
+      if (!admin.tableExists(matrixName)) {
+        tableDesc = new HTableDescriptor(matrixName.toString());
+        tableDesc.addFamily(new HColumnDescriptor(Constants.COLUMN.toString()));
+        create();
+      }
+
+      table = new HTable(config, matrixName);
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+
+  /**
+   * Construct an m-by-n constant matrix.
+   * 
+   * @param conf configuration object
+   * @param m the number of rows.
+   * @param n the number of columns.
+   * @param s fill the matrix with this scalar value.
+   */
+  public Matrix(HamaConfiguration conf, int m, int n, double s) {
+    try {
+      setConfiguration(conf);
+      matrixName = RandomVariable.randMatrixName();
+
+      if (!admin.tableExists(matrixName)) {
+        tableDesc = new HTableDescriptor(matrixName.toString());
+        tableDesc.addFamily(new HColumnDescriptor(Constants.COLUMN.toString()));
+        create();
+      }
+
+      table = new HTable(config, matrixName);
+
+      for (int i = 0; i < m; i++) {
+        for (int j = 0; j < n; j++) {
+          set(i, j, s);
+        }
+      }
+
+      setDimension(m, n);
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+  }
+
+  /**
+   * Generate matrix with random elements
+   * 
+   * @param conf configuration object
+   * @param m the number of rows.
+   * @param n the number of columns.
+   * @return an m-by-n matrix with uniformly distributed random elements.
+   */
+  public static Matrix random(HamaConfiguration conf, int m, int n) {
+    String name = RandomVariable.randMatrixName();
+    Matrix rand = new Matrix(conf, name);
+    for (int i = 0; i < m; i++) {
+      for (int j = 0; j < n; j++) {
+        rand.set(i, j, RandomVariable.rand());
+      }
+    }
+
+    rand.setDimension(m, n);
+    LOG.info("Create the " + m + " * " + n + " random matrix : " + name);
+    return rand;
+  }
+
+  public Matrix add(Matrix B) {
+    String output = RandomVariable.randMatrixName();
+    Matrix C = new Matrix(config, output);
+
+    JobConf jobConf = new JobConf(config);
+    jobConf.setJobName("addition MR job");
+
+    MatrixMap.initJob(this.getName(), B.getName(), AdditionMap.class,
+        ImmutableBytesWritable.class, Vector.class, jobConf);
+    MatrixReduce.initJob(C.getName(), AdditionReduce.class, jobConf);
+
+    try {
+      JobClient.runJob(jobConf);
+    } catch (IOException e) {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+    }
+
+    return C;
+  }
+
+  public Matrix add(double alpha, Matrix B) {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public Matrix mult(Matrix B) {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public Matrix multAdd(double alpha, Matrix B, Matrix C) {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public double norm(Norm type) {
+    // TODO Auto-generated method stub
+    return 0;
+  }
+
+  public Matrix set(double alpha, Matrix B) {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public Matrix set(Matrix B) {
+    // TODO Auto-generated method stub
+    return null;
+  }
+}

Modified: incubator/hama/trunk/src/java/org/apache/hama/Vector.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/Vector.java?rev=687955&r1=687954&r2=687955&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/Vector.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/Vector.java Thu Aug 21 23:02:28 2008
@@ -28,6 +28,7 @@
 import org.apache.hadoop.hbase.io.RowResult;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hama.io.VectorWritable;
+import org.apache.hama.util.Numeric;
 import org.apache.log4j.Logger;
 
 public class Vector extends VectorWritable implements VectorInterface {
@@ -44,7 +45,7 @@
 
   public Vector(int row, RowResult rowResult) {
     this.cells = new HbaseMapWritable<byte[], Cell>();
-    this.row = intToBytes(row);
+    this.row = Numeric.intToBytes(row);
     for (Map.Entry<byte[], Cell> f : rowResult.entrySet()) {
       this.cells.put(f.getKey(), f.getValue());
     }
@@ -53,14 +54,14 @@
   /**
    * Get the row for this Vector
    */
-  public byte [] getRow() {
+  public byte[] getRow() {
     return row;
   }
-  
+
   public HbaseMapWritable<byte[], Cell> getCells() {
     return cells;
   }
-  
+
   public void add(int index, double value) {
     // TODO Auto-generated method stub
 
@@ -99,7 +100,7 @@
 
     while (it.hasNext()) {
       byte[] key = it.next();
-      double oValue = bytesToDouble(get(key).getValue());
+      double oValue = Numeric.bytesToDouble(get(key).getValue());
       double nValue = oValue * alpha;
       Cell cValue = new Cell(String.valueOf(nValue), System.currentTimeMillis());
       cells.put(key, cValue);
@@ -109,7 +110,8 @@
   }
 
   public double get(int index) {
-    return bytesToDouble(cells.get(getColumnIndex(index)).getValue());
+    return Numeric.bytesToDouble(cells.get(Numeric.getColumnIndex(index))
+        .getValue());
   }
 
   public double norm(Norm type) {
@@ -125,7 +127,7 @@
 
   public void set(int index, double value) {
     Cell cValue = new Cell(String.valueOf(value), System.currentTimeMillis());
-    cells.put(getColumnIndex(index), cValue);
+    cells.put(Numeric.getColumnIndex(index), cValue);
   }
 
   public Vector set(Vector v) {
@@ -139,7 +141,7 @@
     Iterator<byte[]> it = keySet.iterator();
 
     while (it.hasNext()) {
-      sum += bytesToDouble(get(it.next()).getValue());
+      sum += Numeric.bytesToDouble(get(it.next()).getValue());
     }
 
     return sum;
@@ -152,7 +154,7 @@
     Iterator<byte[]> it = keySet.iterator();
 
     while (it.hasNext()) {
-      double value = bytesToDouble(get(it.next()).getValue());
+      double value = Numeric.bytesToDouble(get(it.next()).getValue());
       square_sum += value * value;
     }
 

Modified: incubator/hama/trunk/src/java/org/apache/hama/io/VectorWritable.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/io/VectorWritable.java?rev=687955&r1=687954&r2=687955&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/io/VectorWritable.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/io/VectorWritable.java Thu Aug 21 23:02:28 2008
@@ -35,11 +35,10 @@
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Writables;
 import org.apache.hadoop.io.Writable;
-import org.apache.hama.AbstractBase;
 import org.apache.hama.Vector;
+import org.apache.hama.util.Numeric;
 
-public class VectorWritable extends AbstractBase implements Writable,
-    Map<byte[], Cell> {
+public class VectorWritable implements Writable, Map<byte[], Cell> {
 
   public byte[] row;
   public HbaseMapWritable<byte[], Cell> cells;
@@ -128,7 +127,7 @@
    * Get the double value without timestamp
    */
   public double get(int key) {
-    return bytesToDouble(get(intToBytes(key)).getValue());
+    return Numeric.bytesToDouble(get(Numeric.intToBytes(key)).getValue());
   }
 
   public int size() {

Modified: incubator/hama/trunk/src/java/org/apache/hama/mapred/MatrixInputFormatBase.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/mapred/MatrixInputFormatBase.java?rev=687955&r1=687954&r2=687955&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/mapred/MatrixInputFormatBase.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/mapred/MatrixInputFormatBase.java Thu Aug 21 23:02:28 2008
@@ -22,14 +22,13 @@
 import org.apache.hadoop.mapred.JobConf;
 import org.apache.hadoop.mapred.RecordReader;
 import org.apache.hadoop.mapred.Reporter;
-import org.apache.hama.AbstractBase;
 import org.apache.hama.Vector;
 import org.apache.hama.io.VectorWritable;
 
-public abstract class MatrixInputFormatBase extends AbstractBase
-implements InputFormat<ImmutableBytesWritable, Vector> {
+public abstract class MatrixInputFormatBase implements
+    InputFormat<ImmutableBytesWritable, Vector> {
   private final Log LOG = LogFactory.getLog(MatrixInputFormatBase.class);
-  private byte [][] inputColumns;
+  private byte[][] inputColumns;
   private HTable table;
   private TableRecordReader tableRecordReader;
   private RowFilterInterface rowFilter;
@@ -37,37 +36,36 @@
   /**
    * Iterate over an HBase table data, return (Text, VectorResult) pairs
    */
-  protected class TableRecordReader
-  implements RecordReader<ImmutableBytesWritable, Vector> {
-    private byte [] startRow;
-    private byte [] endRow;
+  protected class TableRecordReader implements
+      RecordReader<ImmutableBytesWritable, Vector> {
+    private byte[] startRow;
+    private byte[] endRow;
     private RowFilterInterface trrRowFilter;
     private Scanner scanner;
     private HTable htable;
-    private byte [][] trrInputColumns;
+    private byte[][] trrInputColumns;
 
     /**
      * Build the scanner. Not done in constructor to allow for extension.
-     *
+     * 
      * @throws IOException
      */
     public void init() throws IOException {
       if ((endRow != null) && (endRow.length > 0)) {
         if (trrRowFilter != null) {
-          final Set<RowFilterInterface> rowFiltersSet =
-            new HashSet<RowFilterInterface>();
+          final Set<RowFilterInterface> rowFiltersSet = new HashSet<RowFilterInterface>();
           rowFiltersSet.add(new StopRowFilter(endRow));
           rowFiltersSet.add(trrRowFilter);
           this.scanner = this.htable.getScanner(trrInputColumns, startRow,
-            new RowFilterSet(RowFilterSet.Operator.MUST_PASS_ALL,
-              rowFiltersSet));
+              new RowFilterSet(RowFilterSet.Operator.MUST_PASS_ALL,
+                  rowFiltersSet));
         } else {
-          this.scanner =
-            this.htable.getScanner(trrInputColumns, startRow, endRow);
+          this.scanner = this.htable.getScanner(trrInputColumns, startRow,
+              endRow);
         }
       } else {
-        this.scanner =
-          this.htable.getScanner(trrInputColumns, startRow, trrRowFilter);
+        this.scanner = this.htable.getScanner(trrInputColumns, startRow,
+            trrRowFilter);
       }
     }
 
@@ -81,22 +79,22 @@
     /**
      * @param inputColumns the columns to be placed in {@link VectorWritable}.
      */
-    public void setInputColumns(final byte [][] inputColumns) {
+    public void setInputColumns(final byte[][] inputColumns) {
       this.trrInputColumns = inputColumns;
     }
 
     /**
      * @param startRow the first row in the split
      */
-    public void setStartRow(final byte [] startRow) {
+    public void setStartRow(final byte[] startRow) {
       this.startRow = startRow;
     }
 
     /**
-     *
+     * 
      * @param endRow the last row in the split
      */
-    public void setEndRow(final byte [] endRow) {
+    public void setEndRow(final byte[] endRow) {
       this.endRow = endRow;
     }
 
@@ -114,7 +112,7 @@
 
     /**
      * @return ImmutableBytesWritable
-     *
+     * 
      * @see org.apache.hadoop.mapred.RecordReader#createKey()
      */
     public ImmutableBytesWritable createKey() {
@@ -123,7 +121,7 @@
 
     /**
      * @return VectorResult
-     *
+     * 
      * @see org.apache.hadoop.mapred.RecordReader#createValue()
      */
     public Vector createValue() {
@@ -146,15 +144,15 @@
     /**
      * @param key HStoreKey as input key.
      * @param value MapWritable as input value
-     *
-     * Converts Scanner.next() to Text, VectorResult
-     *
+     * 
+     *          Converts Scanner.next() to Text, VectorResult
+     * 
      * @return true if there was more data
      * @throws IOException
      */
     @SuppressWarnings("unchecked")
     public boolean next(ImmutableBytesWritable key, Vector value)
-    throws IOException {
+        throws IOException {
       RowResult result = this.scanner.next();
       boolean hasMore = result != null && result.size() > 0;
       if (hasMore) {
@@ -166,17 +164,15 @@
   }
 
   /**
-   * Builds a TableRecordReader. If no TableRecordReader was provided, uses
-   * the default.
-   *
+   * Builds a TableRecordReader. If no TableRecordReader was provided, uses the
+   * default.
+   * 
    * @see org.apache.hadoop.mapred.InputFormat#getRecordReader(InputSplit,
    *      JobConf, Reporter)
    */
-  public RecordReader<ImmutableBytesWritable, Vector> getRecordReader(InputSplit split,
-      @SuppressWarnings("unused")
-      JobConf job, @SuppressWarnings("unused")
-      Reporter reporter)
-  throws IOException {
+  public RecordReader<ImmutableBytesWritable, Vector> getRecordReader(
+      InputSplit split, @SuppressWarnings("unused") JobConf job,
+      @SuppressWarnings("unused") Reporter reporter) throws IOException {
     TableSplit tSplit = (TableSplit) split;
     TableRecordReader trr = this.tableRecordReader;
     // if no table record reader was provided use default
@@ -201,16 +197,17 @@
    * multiple {@link HRegion}s and are grouped the most evenly possible. In the
    * case splits are uneven the bigger splits are placed first in the
    * {@link InputSplit} array.
-   *
+   * 
    * @param job the map task {@link JobConf}
    * @param numSplits a hint to calculate the number of splits
-   *
+   * 
    * @return the input splits
-   *
-   * @see org.apache.hadoop.mapred.InputFormat#getSplits(org.apache.hadoop.mapred.JobConf, int)
+   * 
+   * @see org.apache.hadoop.mapred.InputFormat#getSplits(org.apache.hadoop.mapred.JobConf,
+   *      int)
    */
   public InputSplit[] getSplits(JobConf job, int numSplits) throws IOException {
-    byte [][] startKeys = this.table.getStartKeys();
+    byte[][] startKeys = this.table.getStartKeys();
     if (startKeys == null || startKeys.length == 0) {
       throw new IOException("Expecting at least one region");
     }
@@ -243,13 +240,13 @@
   /**
    * @param inputColumns to be passed in {@link VectorWritable} to the map task.
    */
-  protected void setInputColums(byte [][] inputColumns) {
+  protected void setInputColums(byte[][] inputColumns) {
     this.inputColumns = inputColumns;
   }
 
   /**
    * Allows subclasses to set the {@link HTable}.
-   *
+   * 
    * @param table to get the data from
    */
   protected void setHTable(HTable table) {
@@ -258,9 +255,9 @@
 
   /**
    * Allows subclasses to set the {@link TableRecordReader}.
-   *
-   * @param tableRecordReader
-   *                to provide other {@link TableRecordReader} implementations.
+   * 
+   * @param tableRecordReader to provide other {@link TableRecordReader}
+   *          implementations.
    */
   protected void setTableRecordReader(TableRecordReader tableRecordReader) {
     this.tableRecordReader = tableRecordReader;
@@ -268,10 +265,10 @@
 
   /**
    * Allows subclasses to set the {@link RowFilterInterface} to be used.
-   *
+   * 
    * @param rowFilter
    */
   protected void setRowFilter(RowFilterInterface rowFilter) {
     this.rowFilter = rowFilter;
   }
-}
\ No newline at end of file
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/util/Numeric.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/util/Numeric.java?rev=687955&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/util/Numeric.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/util/Numeric.java Thu Aug 21 23:02:28 2008
@@ -0,0 +1,90 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * 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.util;
+
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hama.Constants;
+
+/**
+ * Provides a number format conversion
+ */
+public class Numeric {
+  /**
+   * Bytes to integer conversion
+   * 
+   * @param bytes
+   * @return the converted value
+   */
+  public static int bytesToInt(byte[] bytes) {
+    return Integer.parseInt(Bytes.toString(bytes));
+  }
+
+  /**
+   * Integer to bytes conversion
+   * 
+   * @param integer
+   * @return the converted value
+   */
+  public static byte[] intToBytes(int integer) {
+    return Bytes.toBytes(String.valueOf(integer));
+  }
+
+  /**
+   * Bytes to double conversion
+   * 
+   * @param bytes
+   * @return the converted value
+   */
+  public static double bytesToDouble(byte[] bytes) {
+    return Double.parseDouble(Bytes.toString(bytes));
+  }
+
+  /**
+   * Double to bytes conversion
+   * 
+   * @param doubleValue
+   * @return the converted value
+   */
+  public static byte[] doubleToBytes(Double doubleValue) {
+    return Bytes.toBytes(doubleValue.toString());
+  }
+
+  /**
+   * Gets the column index
+   * 
+   * @param bytes
+   * @return the converted value
+   */
+  public static int getColumnIndex(byte[] bytes) {
+    String cKey = new String(bytes);
+    return Integer.parseInt(cKey
+        .substring(cKey.indexOf(":") + 1, cKey.length()));
+  }
+
+  /**
+   * Gets the column index
+   * 
+   * @param integer
+   * @return the converted value
+   */
+  public static byte[] getColumnIndex(int integer) {
+    return Bytes.toBytes(Constants.COLUMN + String.valueOf(integer));
+  }
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/util/RandomVariable.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/util/RandomVariable.java?rev=687955&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/util/RandomVariable.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/util/RandomVariable.java Thu Aug 21 23:02:28 2008
@@ -0,0 +1,226 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * 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.util;
+
+import org.apache.hama.Constants;
+
+/**
+ * The RandomVaraibale Class provides static methods for generating random
+ * numbers.
+ */
+public class RandomVariable {
+
+  /**
+   * Generate a random number between 0 and 1.
+   * 
+   * @return a double between 0 and 1.
+   */
+  public static double rand() {
+    double x = Math.random();
+    return x;
+  }
+
+  /**
+   * Generate a random integer.
+   * 
+   * @param i0 min of the random variable.
+   * @param i1 max of the random variable.
+   * @return an int between i0 and i1.
+   */
+  public static int randInt(int i0, int i1) {
+    double x = rand();
+    int i = i0 + (int) Math.floor((i1 - i0 + 1) * x);
+    return i;
+  }
+
+  /**
+   * Generate a random name.
+   * 
+   * @return random name
+   */
+  public static String randMatrixName() {
+    String rName = Constants.RANDOM;
+    for (int i = 1; i <= 5; i++) {
+      char ch = (char) ((Math.random() * 26) + 97);
+      rName += ch;
+    }
+
+    return rName;
+  }
+
+  /**
+   * Generate a random number from a uniform random variable.
+   * 
+   * @param min min of the random variable.
+   * @param max max of the random variable.
+   * @return a double.
+   */
+  public static double uniform(double min, double max) {
+    double x = min + (max - min) * rand();
+    return x;
+  }
+
+  /**
+   * Generate a random number from a discrete random variable.
+   * 
+   * @param values discrete values.
+   * @param prob probability of each value.
+   * @return a double.
+   */
+  public static double dirac(double[] values, double[] prob) {
+    double[] prob_cumul = new double[values.length];
+    prob_cumul[0] = prob[0];
+    for (int i = 1; i < values.length; i++) {
+      prob_cumul[i] = prob_cumul[i - 1] + prob[i];
+    }
+    double y = rand();
+    double x = 0;
+    for (int i = 0; i < values.length - 1; i++) {
+      if ((y > prob_cumul[i]) && (y < prob_cumul[i + 1])) {
+        x = values[i];
+      }
+    }
+    return x;
+  }
+
+  /**
+   * Generate a random number from a Gaussian (Normal) random variable.
+   * 
+   * @param mu mean of the random variable.
+   * @param sigma standard deviation of the random variable.
+   * @return a double.
+   */
+  public static double normal(double mu, double sigma) {
+    double x = mu + sigma * Math.cos(2 * Math.PI * rand())
+        * Math.sqrt(-2 * Math.log(rand()));
+    return x;
+  }
+
+  /**
+   * Generate a random number from a Chi-2 random variable.
+   * 
+   * @param n degrees of freedom of the chi2 random variable.
+   * @return a double.
+   */
+  public static double chi2(int n) {
+    double x = 0;
+    for (int i = 0; i < n; i++) {
+      double norm = normal(0, 1);
+      x += norm * norm;
+    }
+    return x;
+  }
+
+  /**
+   * Generate a random number from a LogNormal random variable.
+   * 
+   * @param mu mean of the Normal random variable.
+   * @param sigma standard deviation of the Normal random variable.
+   * @return a double.
+   */
+  public static double logNormal(double mu, double sigma) {
+    double x = mu + sigma * Math.cos(2 * Math.PI * rand())
+        * Math.sqrt(-2 * Math.log(rand()));
+    return x;
+  }
+
+  /**
+   * Generate a random number from an exponantial random variable (Mean =
+   * 1/lambda, variance = 1/lambda^2).
+   * 
+   * @param lambda parmaeter of the exponential random variable.
+   * @return a double.
+   */
+  public static double exponential(double lambda) {
+    double x = -1 / lambda * Math.log(rand());
+    return x;
+  }
+
+  /**
+   * Generate a random number from a symetric triangular random variable.
+   * 
+   * @param min min of the random variable.
+   * @param max max of the random variable.
+   * @return a double.
+   */
+  public static double triangular(double min, double max) {
+    double x = min / 2 + (max - min) * rand() / 2 + min / 2 + (max - min)
+        * rand() / 2;
+    return x;
+  }
+
+  /**
+   * Generate a random number from a non-symetric triangular random variable.
+   * 
+   * @param min min of the random variable.
+   * @param med value of the random variable with max density.
+   * @param max max of the random variable.
+   * @return a double.
+   */
+  public static double triangular(double min, double med, double max) {
+    double y = rand();
+    double x = (y < ((med - min) / (max - min))) ? (min + Math.sqrt(y
+        * (max - min) * (med - min))) : (max - Math.sqrt((1 - y) * (max - min)
+        * (max - med)));
+    return x;
+  }
+
+  /**
+   * Generate a random number from a beta random variable.
+   * 
+   * @param a first parameter of the Beta random variable.
+   * @param b second parameter of the Beta random variable.
+   * @return a double.
+   */
+  public static double beta(double a, double b) {
+    double try_x;
+    double try_y;
+    do {
+      try_x = Math.pow(rand(), 1 / a);
+      try_y = Math.pow(rand(), 1 / b);
+    } while ((try_x + try_y) > 1);
+    return try_x / (try_x + try_y);
+  }
+
+  /**
+   * Generate a random number from a Cauchy random variable (Mean = Inf, and
+   * Variance = Inf).
+   * 
+   * @param mu median of the Weibull random variable
+   * @param sigma second parameter of the Cauchy random variable.
+   * @return a double.
+   */
+  public static double cauchy(double mu, double sigma) {
+    double x = sigma * Math.tan(Math.PI * (rand() - 0.5)) + mu;
+    return x;
+  }
+
+  /**
+   * Generate a random number from a Weibull random variable.
+   * 
+   * @param lambda first parameter of the Weibull random variable.
+   * @param c second parameter of the Weibull random variable.
+   * @return a double.
+   */
+  public static double weibull(double lambda, double c) {
+    double x = Math.pow(-Math.log(1 - rand()), 1 / c) / lambda;
+    return x;
+  }
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/util/package.html
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/util/package.html?rev=687955&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/util/package.html (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/util/package.html Thu Aug 21 23:02:28 2008
@@ -0,0 +1,23 @@
+<html>
+
+<!--
+   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.
+-->
+
+<body>
+Numerical and variable utilities
+</body>
+</html>

Added: incubator/hama/trunk/src/test/org/apache/hama/util/TestRandomVariable.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/util/TestRandomVariable.java?rev=687955&view=auto
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/util/TestRandomVariable.java (added)
+++ incubator/hama/trunk/src/test/org/apache/hama/util/TestRandomVariable.java Thu Aug 21 23:02:28 2008
@@ -0,0 +1,71 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * 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.util;
+
+import junit.framework.TestCase;
+
+/**
+ * Random variable generation test
+ */
+public class TestRandomVariable extends TestCase {
+  final static int COUNT = 50;
+
+  /**
+   * Random object test
+   * 
+   * @throws Exception
+   */
+  public void testRand() throws Exception {
+    for (int i = 0; i < COUNT; i++) {
+      double result = RandomVariable.rand();
+      assertTrue(result >= 0.0d && result <= 1.0);
+    }
+  }
+
+  /**
+   * Random integer test
+   * 
+   * @throws Exception
+   */
+  public void testRandInt() throws Exception {
+    final int min = 122;
+    final int max = 561;
+
+    for (int i = 0; i < COUNT; i++) {
+      int result = RandomVariable.randInt(min, max);
+      assertTrue(result >= min && result <= max);
+    }
+  }
+
+  /**
+   * Uniform test
+   * 
+   * @throws Exception
+   */
+  public void testUniform() throws Exception {
+    final double min = 1.0d;
+    final double max = 3.0d;
+
+    for (int i = 0; i < COUNT; i++) {
+      double result = RandomVariable.uniform(min, max);
+      assertTrue(result >= min && result <= max);
+    }
+  }
+}