You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sr...@apache.org on 2009/07/10 11:35:28 UTC
svn commit: r792856 [10/13] - in /lucene/mahout/trunk/core/src:
main/java/org/apache/mahout/cf/taste/common/
main/java/org/apache/mahout/cf/taste/eval/
main/java/org/apache/mahout/cf/taste/hadoop/
main/java/org/apache/mahout/cf/taste/impl/common/ main/...
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/Matrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/Matrix.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/Matrix.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/Matrix.java Fri Jul 10 09:35:19 2009
@@ -17,22 +17,19 @@
package org.apache.mahout.matrix;
-import java.util.Map;
-
import org.apache.hadoop.io.Writable;
-/**
- * The basic interface including numerous convenience functions
- */
+import java.util.Map;
+
+/** The basic interface including numerous convenience functions */
public interface Matrix extends Cloneable, Writable {
- /**
- * @return a formatted String suitable for output
- */
+ /** @return a formatted String suitable for output */
String asFormatString();
+
/**
* Assign the value to all elements of the receiver
- *
+ *
* @param value a double value
* @return the modified receiver
*/
@@ -40,7 +37,7 @@
/**
* Assign the values to the receiver
- *
+ *
* @param values a double[] of values
* @return the modified receiver
* @throws CardinalityException if the cardinalities differ
@@ -49,7 +46,7 @@
/**
* Assign the other vector values to the receiver
- *
+ *
* @param other a Matrix
* @return the modified receiver
* @throws CardinalityException if the cardinalities differ
@@ -58,17 +55,16 @@
/**
* Apply the function to each element of the receiver
- *
+ *
* @param function a UnaryFunction to apply
* @return the modified receiver
*/
Matrix assign(UnaryFunction function);
/**
- * Apply the function to each element of the receiver and the corresponding
- * element of the other argument
- *
- * @param other a Matrix containing the second arguments to the function
+ * Apply the function to each element of the receiver and the corresponding element of the other argument
+ *
+ * @param other a Matrix containing the second arguments to the function
* @param function a BinaryFunction to apply
* @return the modified receiver
* @throws CardinalityException if the cardinalities differ
@@ -77,10 +73,9 @@
/**
* Assign the other vector values to the column of the receiver
- *
+ *
* @param column the int row to assign
- * @param other a Vector
- *
+ * @param other a Vector
* @return the modified receiver
* @throws CardinalityException if the cardinalities differ
*/
@@ -88,10 +83,9 @@
/**
* Assign the other vector values to the row of the receiver
- *
- * @param row the int row to assign
+ *
+ * @param row the int row to assign
* @param other a Vector
- *
* @return the modified receiver
* @throws CardinalityException if the cardinalities differ
*/
@@ -99,29 +93,28 @@
/**
* Return the cardinality of the recipient (the maximum number of values)
- *
+ *
* @return an int[2]
*/
int[] size();
/**
* Return a copy of the recipient
- *
+ *
* @return a new Matrix
*/
Matrix clone();
- /**
- * Returns matrix determinator using Laplace theorem
- *
- * @return a matrix determinator
- */
+ /**
+ * Returns matrix determinator using Laplace theorem
+ *
+ * @return a matrix determinator
+ */
double determinant();
/**
- * Return a new matrix containing the values of the recipient divided by the
- * argument
- *
+ * Return a new matrix containing the values of the recipient divided by the argument
+ *
* @param x a double value
* @return a new Matrix
*/
@@ -129,8 +122,8 @@
/**
* Return the value at the given indexes
- *
- * @param row an int row index
+ *
+ * @param row an int row index
* @param column an int column index
* @return the double at the index
* @throws IndexException if the index is out of bounds
@@ -139,7 +132,7 @@
/**
* Return the column at the given index
- *
+ *
* @param column an int column index
* @return a Vector at the index
* @throws IndexException if the index is out of bounds
@@ -148,7 +141,7 @@
/**
* Return the row at the given index
- *
+ *
* @param row an int row index
* @return a Vector at the index
* @throws IndexException if the index is out of bounds
@@ -157,8 +150,8 @@
/**
* Return the value at the given indexes, without checking bounds
- *
- * @param row an int row index
+ *
+ * @param row an int row index
* @param column an int column index
* @return the double at the index
*/
@@ -166,7 +159,7 @@
/**
* Return if the other matrix and the receiver share any underlying data cells
- *
+ *
* @param other a Matrix
* @return true if the other matrix has common data cells
*/
@@ -174,24 +167,22 @@
/**
* Return an empty matrix of the same underlying class as the receiver
- *
+ *
* @return a Matrix
*/
Matrix like();
/**
- * Return an empty matrix of the same underlying class as the receiver and of
- * the given cardinality
- *
- * @param rows the int number of rows
+ * Return an empty matrix of the same underlying class as the receiver and of the given cardinality
+ *
+ * @param rows the int number of rows
* @param columns the int number of columns
*/
Matrix like(int rows, int columns);
/**
- * Return a new matrix containing the element by element difference of the
- * recipient and the argument
- *
+ * Return a new matrix containing the element by element difference of the recipient and the argument
+ *
* @param x a Matrix
* @return a new Matrix
* @throws CardinalityException if the cardinalities differ
@@ -199,18 +190,16 @@
Matrix minus(Matrix x);
/**
- * Return a new matrix containing the sum of each value of the recipient and
- * the argument
- *
+ * Return a new matrix containing the sum of each value of the recipient and the argument
+ *
* @param x a double
* @return a new Matrix
*/
Matrix plus(double x);
/**
- * Return a new matrix containing the element by element sum of the recipient
- * and the argument
- *
+ * Return a new matrix containing the element by element sum of the recipient and the argument
+ *
* @param x a Matrix
* @return a new Matrix
* @throws CardinalityException if the cardinalities differ
@@ -219,10 +208,10 @@
/**
* Set the value at the given index
- *
- * @param row an int row index into the receiver
+ *
+ * @param row an int row index into the receiver
* @param column an int column index into the receiver
- * @param value a double value to set
+ * @param value a double value to set
* @throws IndexException if the index is out of bounds
*/
void set(int row, int column, double value);
@@ -231,33 +220,31 @@
/**
* Set the value at the given index, without checking bounds
- *
- * @param row an int row index into the receiver
+ *
+ * @param row an int row index into the receiver
* @param column an int column index into the receiver
- * @param value a double value to set
+ * @param value a double value to set
*/
void setQuick(int row, int column, double value);
/**
* Return the number of values in the recipient
- *
+ *
* @return an int[2] containing [row, column] count
*/
int[] getNumNondefaultElements();
/**
- * Return a new matrix containing the product of each value of the recipient
- * and the argument
- *
+ * Return a new matrix containing the product of each value of the recipient and the argument
+ *
* @param x a double argument
* @return a new Matrix
*/
Matrix times(double x);
/**
- * Return a new matrix containing the product of the recipient and the
- * argument
- *
+ * Return a new matrix containing the product of the recipient and the argument
+ *
* @param x a Matrix argument
* @return a new Matrix
* @throws CardinalityException if the cardinalities are incompatible
@@ -266,109 +253,105 @@
/**
* Return a new matrix that is the transpose of the receiver
- *
+ *
* @return the transpose
*/
Matrix transpose();
/**
* Return a new matrix containing the subset of the recipient
- *
+ *
* @param offset an int[2] offset into the receiver
- * @param size the int[2] size of the desired result
+ * @param size the int[2] size of the desired result
* @return a new Matrix
- * @throws CardinalityException if the length is greater than the cardinality
- * of the receiver
- * @throws IndexException if the offset is negative or the offset+length is
- * outside of the receiver
+ * @throws CardinalityException if the length is greater than the cardinality of the receiver
+ * @throws IndexException if the offset is negative or the offset+length is outside of the receiver
*/
Matrix viewPart(int[] offset, int[] size);
/**
* Return the sum of all the elements of the receiver
- *
+ *
* @return a double
*/
double zSum();
/**
* Return a map of the current column label bindings of the receiver
- *
+ *
* @return a Map<String, Integer>
*/
Map<String, Integer> getColumnLabelBindings();
/**
* Return a map of the current row label bindings of the receiver
- *
+ *
* @return a Map<String, Integer>
*/
Map<String, Integer> getRowLabelBindings();
/**
* Sets a map of column label bindings in the receiver
- *
+ *
* @param bindings a Map<String, Integer> of label bindings
*/
void setColumnLabelBindings(Map<String, Integer> bindings);
/**
* Sets a map of row label bindings in the receiver
- *
+ *
* @param bindings a Map<String, Integer> of label bindings
*/
void setRowLabelBindings(Map<String, Integer> bindings);
/**
* Return the value at the given labels
- *
- * @param rowLabel a String row label
+ *
+ * @param rowLabel a String row label
* @param columnLabel a String column label
* @return the double at the index
* @throws IndexException if the index is out of bounds
*/
double get(String rowLabel, String columnLabel) throws IndexException,
- UnboundLabelException;
+ UnboundLabelException;
/**
* Set the value at the given index
- *
- * @param rowLabel a String row label
+ *
+ * @param rowLabel a String row label
* @param columnLabel a String column label
- * @param value a double value to set
+ * @param value a double value to set
* @throws IndexException if the index is out of bounds
*/
void set(String rowLabel, String columnLabel, double value) throws IndexException,
- UnboundLabelException;
+ UnboundLabelException;
/**
* Set the value at the given index, updating the row and column label bindings
- *
- * @param rowLabel a String row label
+ *
+ * @param rowLabel a String row label
* @param columnLabel a String column label
- * @param row an int row index
- * @param column an int column index
- * @param value a double value
- * @throws IndexException
- * @throws UnboundLabelException
+ * @param row an int row index
+ * @param column an int column index
+ * @param value a double value
*/
void set(String rowLabel, String columnLabel, int row, int column, double value) throws IndexException,
- UnboundLabelException;
+ UnboundLabelException;
/**
* Sets the row values at the given row label
- *
+ *
* @param rowLabel a String row label
- * @param rowData a double[] array of row data
+ * @param rowData a double[] array of row data
*/
void set(String rowLabel, double[] rowData);
/**
* Sets the row values at the given row index and updates the row labels
- *
+ *
* @param rowLabel the String row label
- * @param row an int the row index
- * @param rowData a double[] array of row data
+ * @param row an int the row index
+ * @param rowData a double[] array of row data
*/
void set(String rowLabel, int row, double[] rowData);
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/MatrixView.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/MatrixView.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/MatrixView.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/MatrixView.java Fri Jul 10 09:35:19 2009
@@ -21,9 +21,7 @@
import java.io.DataOutput;
import java.io.IOException;
-/**
- * Implements subset view of a Matrix
- */
+/** Implements subset view of a Matrix */
public class MatrixView extends AbstractMatrix {
private Matrix matrix;
@@ -40,9 +38,9 @@
/**
* Construct a view of the matrix with given offset and cardinality
- *
- * @param matrix an underlying Matrix
- * @param offset the int[2] offset into the underlying matrix
+ *
+ * @param matrix an underlying Matrix
+ * @param offset the int[2] offset into the underlying matrix
* @param cardinality the int[2] cardinality of the view
*/
public MatrixView(Matrix matrix, int[] offset, int[] cardinality) {
@@ -93,11 +91,13 @@
@Override
public Matrix viewPart(int[] offset, int[] size) {
- if (size[ROW] > cardinality[ROW] || size[COL] > cardinality[COL])
+ if (size[ROW] > cardinality[ROW] || size[COL] > cardinality[COL]) {
throw new CardinalityException();
+ }
if ((offset[ROW] < ROW || offset[ROW] + size[ROW] > cardinality[ROW])
- || (offset[COL] < ROW || offset[COL] + size[COL] > cardinality[COL]))
+ || (offset[COL] < ROW || offset[COL] + size[COL] > cardinality[COL])) {
throw new IndexException();
+ }
int[] origin = offset.clone();
origin[ROW] += offset[ROW];
origin[COL] += offset[COL];
@@ -106,44 +106,51 @@
@Override
public boolean haveSharedCells(Matrix other) {
- if (other instanceof MatrixView)
+ if (other instanceof MatrixView) {
return other == this || matrix.haveSharedCells(other);
- else
+ } else {
return other.haveSharedCells(matrix);
+ }
}
@Override
public Matrix assignColumn(int column, Vector other) {
- if (cardinality[ROW] != other.size())
+ if (cardinality[ROW] != other.size()) {
throw new CardinalityException();
- for (int row = 0; row < cardinality[ROW]; row++)
+ }
+ for (int row = 0; row < cardinality[ROW]; row++) {
matrix.setQuick(row + offset[ROW], column + offset[COL], other
.getQuick(row));
+ }
return this;
}
@Override
public Matrix assignRow(int row, Vector other) {
- if (cardinality[COL] != other.size())
+ if (cardinality[COL] != other.size()) {
throw new CardinalityException();
- for (int col = 0; col < cardinality[COL]; col++)
+ }
+ for (int col = 0; col < cardinality[COL]; col++) {
matrix
.setQuick(row + offset[ROW], col + offset[COL], other.getQuick(col));
+ }
return this;
}
@Override
public Vector getColumn(int column) {
- if (column < 0 || column >= cardinality[COL])
+ if (column < 0 || column >= cardinality[COL]) {
throw new IndexException();
+ }
return new VectorView(matrix.getColumn(column + offset[COL]), offset[ROW],
cardinality[ROW]);
}
@Override
public Vector getRow(int row) {
- if (row < 0 || row >= cardinality[ROW])
+ if (row < 0 || row >= cardinality[ROW]) {
throw new IndexException();
+ }
return new VectorView(matrix.getRow(row + offset[ROW]), offset[COL],
cardinality[COL]);
}
@@ -151,9 +158,9 @@
@Override
public void readFields(DataInput in) throws IOException {
super.readFields(in);
- int[] o = { in.readInt(), in.readInt() };
+ int[] o = {in.readInt(), in.readInt()};
this.offset = o;
- int[] c = { in.readInt(), in.readInt() };
+ int[] c = {in.readInt(), in.readInt()};
this.cardinality = c;
this.matrix = readMatrix(in);
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/OrderedIntDoubleMapping.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/OrderedIntDoubleMapping.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/OrderedIntDoubleMapping.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/OrderedIntDoubleMapping.java Fri Jul 10 09:35:19 2009
@@ -142,7 +142,7 @@
@Override
public String toString() {
- StringBuilder result = new StringBuilder(10* numMappings);
+ StringBuilder result = new StringBuilder(10 * numMappings);
for (int i = 0; i < numMappings; i++) {
result.append('(');
result.append(indices[i]);
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseColumnMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseColumnMatrix.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseColumnMatrix.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseColumnMatrix.java Fri Jul 10 09:35:19 2009
@@ -22,8 +22,8 @@
import java.io.IOException;
/**
- * sparse matrix with general element values whose columns are accessible
- * quickly. Implemented as a column array of SparseVectors.
+ * sparse matrix with general element values whose columns are accessible quickly. Implemented as a column array of
+ * SparseVectors.
*/
public class SparseColumnMatrix extends AbstractMatrix {
@@ -37,27 +37,29 @@
/**
* Construct a matrix of the given cardinality with the given data columns
- *
+ *
* @param cardinality the int[2] cardinality
- * @param columns a SparseVector[] array of columns
+ * @param columns a SparseVector[] array of columns
*/
public SparseColumnMatrix(int[] cardinality, SparseVector[] columns) {
this.cardinality = cardinality.clone();
this.columns = columns.clone();
- for (int col = 0; col < cardinality[COL]; col++)
+ for (int col = 0; col < cardinality[COL]; col++) {
this.columns[col] = columns[col].clone();
+ }
}
/**
* Construct a matrix of the given cardinality
- *
+ *
* @param cardinality the int[2] cardinality
*/
public SparseColumnMatrix(int[] cardinality) {
this.cardinality = cardinality.clone();
this.columns = new SparseVector[cardinality[COL]];
- for (int col = 0; col < cardinality[COL]; col++)
+ for (int col = 0; col < cardinality[COL]; col++) {
this.columns[col] = new SparseVector(cardinality[ROW]);
+ }
}
@Override
@@ -78,16 +80,18 @@
@Override
public double getQuick(int row, int column) {
- if (columns[column] == null)
+ if (columns[column] == null) {
return 0.0;
- else
+ } else {
return columns[column].getQuick(row);
+ }
}
@Override
public boolean haveSharedCells(Matrix other) {
- if (other instanceof SparseColumnMatrix)
+ if (other instanceof SparseColumnMatrix) {
return other == this;
+ }
return other.haveSharedCells(this);
}
@@ -106,8 +110,9 @@
@Override
public void setQuick(int row, int column, double value) {
- if (columns[column] == null)
+ if (columns[column] == null) {
columns[column] = new SparseVector(cardinality[ROW]);
+ }
columns[column].setQuick(row, value);
}
@@ -115,60 +120,69 @@
public int[] getNumNondefaultElements() {
int[] result = new int[2];
result[COL] = columns.length;
- for (int col = 0; col < cardinality[COL]; col++)
+ for (int col = 0; col < cardinality[COL]; col++) {
result[ROW] = Math.max(result[ROW], columns[col]
.getNumNondefaultElements());
+ }
return result;
}
@Override
public Matrix viewPart(int[] offset, int[] size) {
- if (size[COL] > columns.length || size[ROW] > columns[COL].size())
+ if (size[COL] > columns.length || size[ROW] > columns[COL].size()) {
throw new CardinalityException();
+ }
if (offset[COL] < 0 || offset[COL] + size[COL] > columns.length
- || offset[ROW] < 0 || offset[ROW] + size[ROW] > columns[COL].size())
+ || offset[ROW] < 0 || offset[ROW] + size[ROW] > columns[COL].size()) {
throw new IndexException();
+ }
return new MatrixView(this, offset, size);
}
@Override
public Matrix assignColumn(int column, Vector other) {
- if (other.size() != cardinality[ROW] || column >= cardinality[COL])
+ if (other.size() != cardinality[ROW] || column >= cardinality[COL]) {
throw new CardinalityException();
+ }
columns[column].assign(other);
return this;
}
@Override
public Matrix assignRow(int row, Vector other) {
- if (row >= cardinality[ROW] || other.size() != cardinality[COL])
+ if (row >= cardinality[ROW] || other.size() != cardinality[COL]) {
throw new CardinalityException();
- for (int col = 0; col < cardinality[COL]; col++)
+ }
+ for (int col = 0; col < cardinality[COL]; col++) {
columns[col].setQuick(row, other.getQuick(col));
+ }
return this;
}
@Override
public Vector getColumn(int column) {
- if (column < 0 || column >= cardinality[COL])
+ if (column < 0 || column >= cardinality[COL]) {
throw new IndexException();
+ }
return columns[column];
}
@Override
public Vector getRow(int row) {
- if (row < 0 || row >= cardinality[ROW])
+ if (row < 0 || row >= cardinality[ROW]) {
throw new IndexException();
+ }
double[] d = new double[cardinality[COL]];
- for (int col = 0; col < cardinality[COL]; col++)
+ for (int col = 0; col < cardinality[COL]; col++) {
d[col] = getQuick(row, col);
+ }
return new DenseVector(d);
}
@Override
public void readFields(DataInput in) throws IOException {
super.readFields(in);
- int[] card = { in.readInt(), in.readInt() };
+ int[] card = {in.readInt(), in.readInt()};
this.cardinality = card;
int colSize = in.readInt();
this.columns = new Vector[colSize];
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java Fri Jul 10 09:35:19 2009
@@ -23,9 +23,7 @@
import java.util.HashMap;
import java.util.Map;
-/**
- * Doubly sparse matrix. Implemented as a Map of SparseVector rows
- */
+/** Doubly sparse matrix. Implemented as a Map of SparseVector rows */
public class SparseMatrix extends AbstractMatrix {
private int[] cardinality;
@@ -38,20 +36,21 @@
/**
* Construct a matrix of the given cardinality with the given row map
- *
+ *
* @param cardinality the int[2] cardinality desired
- * @param rows a Map<Integer, SparseVector> of rows
+ * @param rows a Map<Integer, SparseVector> of rows
*/
public SparseMatrix(int[] cardinality, Map<Integer, SparseVector> rows) {
this.cardinality = cardinality.clone();
this.rows = new HashMap<Integer, Vector>();
- for (Map.Entry<Integer, SparseVector> entry : rows.entrySet())
+ for (Map.Entry<Integer, SparseVector> entry : rows.entrySet()) {
this.rows.put(entry.getKey(), entry.getValue().clone());
+ }
}
/**
* Construct a matrix of the given cardinality
- *
+ *
* @param cardinality the int[2] cardinality desired
*/
public SparseMatrix(int[] cardinality) {
@@ -68,25 +67,27 @@
public Matrix clone() {
SparseMatrix clone = (SparseMatrix) super.clone();
clone.cardinality = cardinality.clone();
- clone.rows = (Map<Integer,Vector>) ((HashMap<Integer,Vector>) rows).clone();
+ clone.rows = (Map<Integer, Vector>) ((HashMap<Integer, Vector>) rows).clone();
return clone;
}
@Override
public double getQuick(int row, int column) {
Vector r = rows.get(row);
- if (r == null)
+ if (r == null) {
return 0.0;
- else
+ } else {
return r.getQuick(column);
+ }
}
@Override
public boolean haveSharedCells(Matrix other) {
- if (other instanceof SparseMatrix)
+ if (other instanceof SparseMatrix) {
return other == this;
- else
+ } else {
return other.haveSharedCells(this);
+ }
}
@Override
@@ -96,7 +97,7 @@
@Override
public Matrix like(int rows, int columns) {
- return new SparseMatrix(new int[] { rows, columns });
+ return new SparseMatrix(new int[]{rows, columns});
}
@Override
@@ -114,26 +115,30 @@
public int[] getNumNondefaultElements() {
int[] result = new int[2];
result[ROW] = rows.size();
- for (Map.Entry<Integer, Vector> integerVectorEntry : rows.entrySet())
+ for (Map.Entry<Integer, Vector> integerVectorEntry : rows.entrySet()) {
result[COL] = Math.max(result[COL], integerVectorEntry.getValue()
.getNumNondefaultElements());
+ }
return result;
}
@Override
public Matrix viewPart(int[] offset, int[] size) {
- if (size[ROW] > cardinality[ROW] || size[COL] > cardinality[COL])
+ if (size[ROW] > cardinality[ROW] || size[COL] > cardinality[COL]) {
throw new CardinalityException();
+ }
if (offset[ROW] < 0 || offset[ROW] + size[ROW] > cardinality[ROW]
- || offset[COL] < 0 || offset[COL] + size[COL] > cardinality[COL])
+ || offset[COL] < 0 || offset[COL] + size[COL] > cardinality[COL]) {
throw new IndexException();
+ }
return new MatrixView(this, offset, size);
}
@Override
public Matrix assignColumn(int column, Vector other) {
- if (other.size() != cardinality[ROW] || column >= cardinality[COL])
+ if (other.size() != cardinality[ROW] || column >= cardinality[COL]) {
throw new CardinalityException();
+ }
for (int row = 0; row < cardinality[ROW]; row++) {
double val = other.getQuick(row);
if (val != 0.0) {
@@ -151,36 +156,41 @@
@Override
public Matrix assignRow(int row, Vector other) {
- if (row >= cardinality[ROW] || other.size() != cardinality[COL])
+ if (row >= cardinality[ROW] || other.size() != cardinality[COL]) {
throw new CardinalityException();
+ }
rows.put(row, other);
return this;
}
@Override
public Vector getColumn(int column) {
- if (column < 0 || column >= cardinality[COL])
+ if (column < 0 || column >= cardinality[COL]) {
throw new IndexException();
+ }
double[] d = new double[cardinality[ROW]];
- for (int row = 0; row < cardinality[ROW]; row++)
+ for (int row = 0; row < cardinality[ROW]; row++) {
d[row] = getQuick(row, column);
+ }
return new DenseVector(d);
}
@Override
public Vector getRow(int row) {
- if (row < 0 || row >= cardinality[ROW])
+ if (row < 0 || row >= cardinality[ROW]) {
throw new IndexException();
+ }
Vector res = rows.get(row);
- if (res == null)
+ if (res == null) {
res = new SparseVector(cardinality[ROW]);
+ }
return res;
}
@Override
public void readFields(DataInput in) throws IOException {
super.readFields(in);
- int[] card = { in.readInt(), in.readInt() };
+ int[] card = {in.readInt(), in.readInt()};
this.cardinality = card;
int rowsize = in.readInt();
this.rows = new HashMap<Integer, Vector>();
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseRowMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseRowMatrix.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseRowMatrix.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseRowMatrix.java Fri Jul 10 09:35:19 2009
@@ -22,8 +22,8 @@
import java.io.IOException;
/**
- * sparse matrix with general element values whose rows are accessible quickly.
- * Implemented as a row array of SparseVectors.
+ * sparse matrix with general element values whose rows are accessible quickly. Implemented as a row array of
+ * SparseVectors.
*/
public class SparseRowMatrix extends AbstractMatrix {
@@ -37,27 +37,29 @@
/**
* Construct a matrix of the given cardinality with the given rows
- *
+ *
* @param cardinality the int[2] cardinality desired
- * @param rows a SparseVector[] array of rows
+ * @param rows a SparseVector[] array of rows
*/
public SparseRowMatrix(int[] cardinality, SparseVector[] rows) {
this.cardinality = cardinality.clone();
this.rows = rows.clone();
- for (int row = 0; row < cardinality[ROW]; row++)
+ for (int row = 0; row < cardinality[ROW]; row++) {
this.rows[row] = rows[row].clone();
+ }
}
/**
* Construct a matrix of the given cardinality
- *
+ *
* @param cardinality the int[2] cardinality desired
*/
public SparseRowMatrix(int[] cardinality) {
this.cardinality = cardinality.clone();
this.rows = new SparseVector[cardinality[ROW]];
- for (int row = 0; row < cardinality[ROW]; row++)
+ for (int row = 0; row < cardinality[ROW]; row++) {
this.rows[row] = new SparseVector(cardinality[COL]);
+ }
}
@Override
@@ -78,16 +80,18 @@
@Override
public double getQuick(int row, int column) {
- if (rows[row] == null)
+ if (rows[row] == null) {
return 0.0;
- else
+ } else {
return rows[row].getQuick(column);
+ }
}
@Override
public boolean haveSharedCells(Matrix other) {
- if (other instanceof SparseRowMatrix)
+ if (other instanceof SparseRowMatrix) {
return other == this;
+ }
return other.haveSharedCells(this);
}
@@ -113,59 +117,68 @@
public int[] getNumNondefaultElements() {
int[] result = new int[2];
result[ROW] = rows.length;
- for (int row = 0; row < cardinality[ROW]; row++)
+ for (int row = 0; row < cardinality[ROW]; row++) {
result[COL] = Math.max(result[COL], rows[row].getNumNondefaultElements());
+ }
return result;
}
@Override
public Matrix viewPart(int[] offset, int[] size) {
- if (size[ROW] > rows.length || size[COL] > rows[ROW].size())
+ if (size[ROW] > rows.length || size[COL] > rows[ROW].size()) {
throw new CardinalityException();
+ }
if (offset[ROW] < 0 || offset[ROW] + size[ROW] > rows.length
- || offset[COL] < 0 || offset[COL] + size[COL] > rows[ROW].size())
+ || offset[COL] < 0 || offset[COL] + size[COL] > rows[ROW].size()) {
throw new IndexException();
+ }
return new MatrixView(this, offset, size);
}
@Override
public Matrix assignColumn(int column, Vector other) {
- if (other.size() != cardinality[ROW] || column >= cardinality[COL])
+ if (other.size() != cardinality[ROW] || column >= cardinality[COL]) {
throw new CardinalityException();
- for (int row = 0; row < cardinality[ROW]; row++)
+ }
+ for (int row = 0; row < cardinality[ROW]; row++) {
rows[row].setQuick(column, other.getQuick(row));
+ }
return this;
}
@Override
public Matrix assignRow(int row, Vector other) {
- if (row >= cardinality[ROW] || other.size() != cardinality[COL])
+ if (row >= cardinality[ROW] || other.size() != cardinality[COL]) {
throw new CardinalityException();
+ }
rows[row].assign(other);
return this;
}
@Override
public Vector getColumn(int column) {
- if (column < 0 || column >= cardinality[COL])
+ if (column < 0 || column >= cardinality[COL]) {
throw new IndexException();
+ }
double[] d = new double[cardinality[ROW]];
- for (int row = 0; row < cardinality[ROW]; row++)
+ for (int row = 0; row < cardinality[ROW]; row++) {
d[row] = getQuick(row, column);
+ }
return new DenseVector(d);
}
@Override
public Vector getRow(int row) {
- if (row < 0 || row >= cardinality[ROW])
+ if (row < 0 || row >= cardinality[ROW]) {
throw new IndexException();
+ }
return rows[row];
}
@Override
public void readFields(DataInput in) throws IOException {
super.readFields(in);
- int[] card = { in.readInt(), in.readInt() };
+ int[] card = {in.readInt(), in.readInt()};
this.cardinality = card;
int rowsize = in.readInt();
this.rows = new Vector[rowsize];
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java Fri Jul 10 09:35:19 2009
@@ -23,18 +23,14 @@
import java.util.Iterator;
import java.util.NoSuchElementException;
-/**
- * Implements vector that only stores non-zero doubles
- */
+/** Implements vector that only stores non-zero doubles */
public class SparseVector extends AbstractVector {
private OrderedIntDoubleMapping values;
private int cardinality;
- /**
- * For serialization purposes only.
- */
+ /** For serialization purposes only. */
public SparseVector() {
}
@@ -93,19 +89,22 @@
@Override
public Vector viewPart(int offset, int length) {
- if (length > cardinality)
+ if (length > cardinality) {
throw new CardinalityException();
- if (offset < 0 || offset + length > cardinality)
+ }
+ if (offset < 0 || offset + length > cardinality) {
throw new IndexException();
+ }
return new VectorView(this, offset, length);
}
@Override
public boolean haveSharedCells(Vector other) {
- if (other instanceof SparseVector)
+ if (other instanceof SparseVector) {
return other == this;
- else
+ } else {
return other.haveSharedCells(this);
+ }
}
@Override
@@ -127,8 +126,8 @@
}
/**
- * NOTE: this implementation reuses the Vector.Element instance for each call of next(). If you
- * need to preserve the instance, you need to make a copy of it
+ * NOTE: this implementation reuses the Vector.Element instance for each call of next(). If you need to preserve the
+ * instance, you need to make a copy of it
*
* @return an {@link org.apache.mahout.matrix.SparseVector.NonZeroIterator} over the Elements.
* @see #getElement(int)
@@ -144,31 +143,31 @@
}
/**
- * Indicate whether the two objects are the same or not. Two
- * {@link org.apache.mahout.matrix.Vector}s can be equal even if the
- * underlying implementation is not equal.
+ * Indicate whether the two objects are the same or not. Two {@link org.apache.mahout.matrix.Vector}s can be equal
+ * even if the underlying implementation is not equal.
*
* @param o The object to compare
- * @return true if the objects have the same cell values and same name, false
- * otherwise.
- * <p/>
- * * @see AbstractVector#strictEquivalence(Vector, Vector)
+ * @return true if the objects have the same cell values and same name, false otherwise. <p/> * @see
+ * AbstractVector#strictEquivalence(Vector, Vector)
* @see AbstractVector#equivalent(Vector, Vector)
*/
@Override
public boolean equals(Object o) {
- if (this == o)
+ if (this == o) {
return true;
- if (!(o instanceof Vector))
+ }
+ if (!(o instanceof Vector)) {
return false;
+ }
Vector that = (Vector) o;
- if (this.size() != that.size())
+ if (this.size() != that.size()) {
return false;
+ }
if (that instanceof SparseVector) {
return (values == null ? ((SparseVector) that).values == null : values
- .equals(((SparseVector) that).values));
+ .equals(((SparseVector) that).values));
} else {
return equivalent(this, that);
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/UnaryFunction.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/UnaryFunction.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/UnaryFunction.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/UnaryFunction.java Fri Jul 10 09:35:19 2009
@@ -18,15 +18,14 @@
package org.apache.mahout.matrix;
/**
- * This interface allows the formulation of unary functions to be applied to
- * matrices inside the inner loops of their implementations.
- *
+ * This interface allows the formulation of unary functions to be applied to matrices inside the inner loops of their
+ * implementations.
*/
public interface UnaryFunction {
/**
* Apply the function to the argument and return the result
- *
+ *
* @param arg1 double for the argument
* @return the result of applying the function
*/
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/UnboundLabelException.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/UnboundLabelException.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/UnboundLabelException.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/UnboundLabelException.java Fri Jul 10 09:35:19 2009
@@ -17,9 +17,7 @@
package org.apache.mahout.matrix;
-/**
- * Exception thrown when there is a cardinality mismatch in matrix operations
- */
+/** Exception thrown when there is a cardinality mismatch in matrix operations */
public class UnboundLabelException extends RuntimeException {
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/Vector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/Vector.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/Vector.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/Vector.java Fri Jul 10 09:35:19 2009
@@ -17,42 +17,39 @@
package org.apache.mahout.matrix;
-import java.util.Map;
-import java.util.Iterator;
-
import org.apache.hadoop.io.Writable;
+import java.util.Iterator;
+import java.util.Map;
+
/**
- * The basic interface including numerous convenience functions
- * <p/>
- * NOTE: All implementing classes must have a constructor that takes an int for cardinality
- * and a no-arg constructor that can be used for marshalling the Writable instance
- * <p/>
- * NOTE: Implementations may choose to reuse the Vector.Element in the Iterable methods
+ * The basic interface including numerous convenience functions <p/> NOTE: All implementing classes must have a
+ * constructor that takes an int for cardinality and a no-arg constructor that can be used for marshalling the Writable
+ * instance <p/> NOTE: Implementations may choose to reuse the Vector.Element in the Iterable methods
*/
public interface Vector extends Cloneable, Writable {
/**
* Vectors may have a name associated with them, which makes them easy to identify
+ *
* @return The name, or null if one has not been set
*/
String getName();
/**
- * Set a name for this vector. Need not be unique in a set of Vectors, but probably is more useful if it is.
- * In other words, Mahout does not check for uniqueness.
+ * Set a name for this vector. Need not be unique in a set of Vectors, but probably is more useful if it is. In other
+ * words, Mahout does not check for uniqueness.
+ *
* @param name The name
*/
void setName(String name);
- /**
- * @return a formatted String suitable for output
- */
+ /** @return a formatted String suitable for output */
String asFormatString();
/**
* Assign the value to all elements of the receiver
- *
+ *
* @param value a double value
* @return the modified receiver
*/
@@ -60,7 +57,7 @@
/**
* Assign the values to the receiver
- *
+ *
* @param values a double[] of values
* @return the modified receiver
* @throws CardinalityException if the cardinalities differ
@@ -69,7 +66,7 @@
/**
* Assign the other matrix values to the receiver
- *
+ *
* @param other a Vector
* @return the modified receiver
* @throws CardinalityException if the cardinalities differ
@@ -78,17 +75,16 @@
/**
* Apply the function to each element of the receiver
- *
+ *
* @param function a DoubleFunction to apply
* @return the modified receiver
*/
Vector assign(UnaryFunction function);
/**
- * Apply the function to each element of the receiver and the corresponding
- * element of the other argument
- *
- * @param other a Vector containing the second arguments to the function
+ * Apply the function to each element of the receiver and the corresponding element of the other argument
+ *
+ * @param other a Vector containing the second arguments to the function
* @param function a DoubleDoubleFunction to apply
* @return the modified receiver
* @throws CardinalityException if the cardinalities differ
@@ -96,9 +92,8 @@
Vector assign(Vector other, BinaryFunction function);
/**
- * Apply the function to each element of the receiver, using the y value as
- * the second argument of the BinaryFunction
- *
+ * Apply the function to each element of the receiver, using the y value as the second argument of the BinaryFunction
+ *
* @param f a BinaryFunction to be applied
* @param y a double value to be argument to the function
* @return the modified receiver
@@ -107,90 +102,78 @@
/**
* Return the cardinality of the recipient (the maximum number of values)
- *
+ *
* @return an int
*/
int size();
/**
* Return a copy of the recipient
- *
+ *
* @return a new Vector
*/
Vector clone();
/**
- * Iterates over all elements
- *<p/>
- * * NOTE: Implementations may choose to reuse the Element returned for performance reasons,
- * so if you need a copy of it, you should call {@link #getElement} for the given index
+ * Iterates over all elements <p/> * NOTE: Implementations may choose to reuse the Element returned for performance
+ * reasons, so if you need a copy of it, you should call {@link #getElement} for the given index
*
* @return An {@link java.util.Iterator} over all elements
*/
Iterator<Element> iterateAll();
/**
- * Iterates over all non-zero elements.
- *<p/>
- * NOTE: Implementations may choose to reuse the Element returned for performance reasons,
- * so if you need a copy of it, you should call {@link #getElement} for the given index
+ * Iterates over all non-zero elements. <p/> NOTE: Implementations may choose to reuse the Element returned for
+ * performance reasons, so if you need a copy of it, you should call {@link #getElement} for the given index
+ *
* @return An {@link java.util.Iterator} over all non-zero elements
*/
Iterator<Element> iterateNonZero();
/**
* Return the value at the index defined by the label
- *
+ *
* @param label a String label that maps to an index
* @return the double at the index
- * @throws IndexException if the index is out of bounds
+ * @throws IndexException if the index is out of bounds
* @throws UnboundLabelException if the label is unbound
*/
double get(String label) throws IndexException, UnboundLabelException;
/**
* Return a map of the current label bindings of the receiver
- *
+ *
* @return a Map<String, Integer>
*/
Map<String, Integer> getLabelBindings();
/**
- * Return an object of Vector.Element representing an element of this Vector.
- * Useful when designing new iterator types.
- *
+ * Return an object of Vector.Element representing an element of this Vector. Useful when designing new iterator
+ * types.
+ *
* @param index Index of the Vector.Element required
* @return The Vector.Element Object
*/
Element getElement(int index);
/**
- * A holder for information about a specific item in the Vector.
- * <p/>
- * When using with an Iterator, the implementation may choose to reuse this element, so you may need to make a copy if
- * you want to keep it
+ * A holder for information about a specific item in the Vector. <p/> When using with an Iterator, the implementation
+ * may choose to reuse this element, so you may need to make a copy if you want to keep it
*/
interface Element {
- /**
- * @return the value of this vector element.
- */
+ /** @return the value of this vector element. */
double get();
- /**
- * @return the index of this vector element.
- */
+ /** @return the index of this vector element. */
int index();
- /**
- * @param value Set the current element to value.
- */
+ /** @param value Set the current element to value. */
void set(double value);
}
/**
- * Return a new matrix containing the values of the recipient divided by the
- * argument
- *
+ * Return a new matrix containing the values of the recipient divided by the argument
+ *
* @param x a double value
* @return a new Vector
*/
@@ -198,7 +181,7 @@
/**
* Return the dot product of the recipient and the argument
- *
+ *
* @param x a Vector
* @return a new Vector
* @throws CardinalityException if the cardinalities differ
@@ -207,7 +190,7 @@
/**
* Return the value at the given index
- *
+ *
* @param index an int index
* @return the double at the index
* @throws IndexException if the index is out of bounds
@@ -216,7 +199,7 @@
/**
* Return the value at the given index, without checking bounds
- *
+ *
* @param index an int index
* @return the double at the index
*/
@@ -224,7 +207,7 @@
/**
* Return if the other matrix and the receiver share any underlying data cells
- *
+ *
* @param other a Vector
* @return true if the other matrix has common data cells
*/
@@ -232,24 +215,22 @@
/**
* Return an empty matrix of the same underlying class as the receiver
- *
+ *
* @return a Vector
*/
Vector like();
/**
- * Return an empty matrix of the same underlying class as the receiver and of
- * the given cardinality
- *
+ * Return an empty matrix of the same underlying class as the receiver and of the given cardinality
+ *
* @param cardinality an int specifying the desired cardinality
* @return a Vector
*/
Vector like(int cardinality);
/**
- * Return a new matrix containing the element by element difference of the
- * recipient and the argument
- *
+ * Return a new matrix containing the element by element difference of the recipient and the argument
+ *
* @param x a Vector
* @return a new Vector
* @throws CardinalityException if the cardinalities differ
@@ -257,59 +238,41 @@
Vector minus(Vector x);
/**
- * Return a new matrix containing the normalized (L_2 norm) values of the
- * recipient
- *
+ * Return a new matrix containing the normalized (L_2 norm) values of the recipient
+ *
* @return a new Vector
*/
Vector normalize();
/**
- * Return a new Vector containing the normalized (L_power norm) values of the
- * recipient.
- * <p/>
- * See http://en.wikipedia.org/wiki/Lp_space
- * <p/>
- * Technically, when 0 < power < 1, we don't have a norm, just a metric, but
- * we'll overload this here.
- * <p/>
- * Also supports power == 0 (number of non-zero elements) and power =
- * {@link Double#POSITIVE_INFINITY} (max element). Again, see the Wikipedia
- * page for more info
- *
- *
- * @param power The power to use. Must be >= 0. May also be
- * {@link Double#POSITIVE_INFINITY}. See the Wikipedia link for more on
- * this.
+ * Return a new Vector containing the normalized (L_power norm) values of the recipient. <p/> See
+ * http://en.wikipedia.org/wiki/Lp_space <p/> Technically, when 0 < power < 1, we don't have a norm, just a metric,
+ * but we'll overload this here. <p/> Also supports power == 0 (number of non-zero elements) and power = {@link
+ * Double#POSITIVE_INFINITY} (max element). Again, see the Wikipedia page for more info
+ *
+ * @param power The power to use. Must be >= 0. May also be {@link Double#POSITIVE_INFINITY}. See the Wikipedia link
+ * for more on this.
* @return a new Vector
*/
Vector normalize(double power);
- /**
- *
- * @return The maximum value in the Vector
- */
+ /** @return The maximum value in the Vector */
double maxValue();
- /**
- *
- * @return The index of the maximum value
- */
+ /** @return The index of the maximum value */
int maxValueIndex();
/**
- * Return a new matrix containing the sum of each value of the recipient and
- * the argument
- *
+ * Return a new matrix containing the sum of each value of the recipient and the argument
+ *
* @param x a double
* @return a new Vector
*/
Vector plus(double x);
/**
- * Return a new matrix containing the element by element sum of the recipient
- * and the argument
- *
+ * Return a new matrix containing the element by element sum of the recipient and the argument
+ *
* @param x a Vector
* @return a new Vector
* @throws CardinalityException if the cardinalities differ
@@ -318,35 +281,32 @@
/**
* Set the value at the index that is mapped to the label
- *
+ *
* @param label a String label that maps to an index
* @param value the double value at the index
- * @throws IndexException
- * @throws UnboundLabelException
*/
void set(String label, double value) throws IndexException,
UnboundLabelException;
-
+
/**
* Set the value at the index and add the label to the bindings
- *
+ *
* @param label a String label that maps to an index
* @param index an int index
* @param value a double value
- * @throws IndexException
*/
void set(String label, int index, double value) throws IndexException;
/**
* Sets a map of label bindings in the receiver
- *
+ *
* @param bindings a {@link Map<String, Integer>} of label bindings
*/
void setLabelBindings(Map<String, Integer> bindings);
/**
* Set the value at the given index
- *
+ *
* @param index an int index into the receiver
* @param value a double value to set
* @throws IndexException if the index is out of bounds
@@ -355,7 +315,7 @@
/**
* Set the value at the given index, without checking bounds
- *
+ *
* @param index an int index into the receiver
* @param value a double value to set
*/
@@ -363,24 +323,22 @@
/**
* Return the number of values in the recipient
- *
+ *
* @return an int
*/
int getNumNondefaultElements();
/**
- * Return a new matrix containing the product of each value of the recipient
- * and the argument
- *
+ * Return a new matrix containing the product of each value of the recipient and the argument
+ *
* @param x a double argument
* @return a new Vector
*/
Vector times(double x);
/**
- * Return a new matrix containing the element-wise product of the recipient
- * and the argument
- *
+ * Return a new matrix containing the element-wise product of the recipient and the argument
+ *
* @param x a Vector argument
* @return a new Vector
* @throws CardinalityException if the cardinalities differ
@@ -389,27 +347,25 @@
/**
* Return a new matrix containing the subset of the recipient
- *
+ *
* @param offset an int offset into the receiver
* @param length the cardinality of the desired result
* @return a new Vector
- * @throws CardinalityException if the length is greater than the cardinality
- * of the receiver
- * @throws IndexException if the offset is negative or the offset+length is
- * outside of the receiver
+ * @throws CardinalityException if the length is greater than the cardinality of the receiver
+ * @throws IndexException if the offset is negative or the offset+length is outside of the receiver
*/
Vector viewPart(int offset, int length);
/**
* Return the sum of all the elements of the receiver
- *
+ *
* @return a double
*/
double zSum();
/**
* Return the cross product of the receiver and the other vector
- *
+ *
* @param other another Vector
* @return a Matrix
*/
@@ -425,23 +381,15 @@
// DoubleDoubleFunction map);
// NewVector assign(Vector y, DoubleDoubleFunction function, IntArrayList
// nonZeroIndexes);
-
- /**
- * Return the sum of squares of all elements in the vector. Square root of this value is the length of the vector.
- */
+
+ /** Return the sum of squares of all elements in the vector. Square root of this value is the length of the vector. */
double getLengthSquared();
-
- /**
- * Get the square of the distance between this vector and the other vector.
- * @param v
- * @return
- */
+
+ /** Get the square of the distance between this vector and the other vector. */
double getDistanceSquared(Vector v);
-
- /**
- * Add the elements to the other vector and results are stored in that vector.
- */
+
+ /** Add the elements to the other vector and results are stored in that vector. */
void addTo(Vector v);
-
+
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/VectorView.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/VectorView.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/VectorView.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/VectorView.java Fri Jul 10 09:35:19 2009
@@ -20,12 +20,10 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
-import java.util.NoSuchElementException;
import java.util.Iterator;
+import java.util.NoSuchElementException;
-/**
- * Implements subset view of a Vector
- */
+/** Implements subset view of a Vector */
public class VectorView extends AbstractVector {
private Vector vector;
@@ -90,24 +88,33 @@
@Override
public Vector viewPart(int offset, int length) {
- if (length > cardinality)
- throw new CardinalityException();
- if (offset < 0 || offset + length > cardinality)
- throw new IndexException();
+ if (length > cardinality) {
+ {
+ throw new CardinalityException();
+ }
+ }
+ if (offset < 0 || offset + length > cardinality) {
+ {
+ throw new IndexException();
+ }
+ }
return new VectorView(vector, offset + this.offset, length);
}
@Override
public boolean haveSharedCells(Vector other) {
- if (other instanceof VectorView)
- return other == this || vector.haveSharedCells(other);
- else
- return other.haveSharedCells(vector);
+ if (other instanceof VectorView) {
+ {
+ return other == this || vector.haveSharedCells(other);
+ }
+ } else {
+ {
+ return other.haveSharedCells(vector);
+ }
+ }
}
- /**
- * @return true if index is a valid index in the underlying Vector
- */
+ /** @return true if index is a valid index in the underlying Vector */
private boolean isInView(int index) {
return index >= offset && index < offset + cardinality;
}
@@ -174,10 +181,7 @@
return el != null;
}
- /**
- * @throws UnsupportedOperationException all the time. method not
- * implemented.
- */
+ /** @throws UnsupportedOperationException all the time. method not implemented. */
@Override
public void remove() {
throw new UnsupportedOperationException();
@@ -236,10 +240,7 @@
return el != null;
}
- /**
- * @throws UnsupportedOperationException all the time. method not
- * implemented.
- */
+ /** @throws UnsupportedOperationException all the time. method not implemented. */
@Override
public void remove() {
throw new UnsupportedOperationException();
@@ -249,11 +250,17 @@
@Override
public double dot(Vector x) {
- if (size() != x.size())
- throw new CardinalityException();
+ if (size() != x.size()) {
+ {
+ throw new CardinalityException();
+ }
+ }
double result = 0;
- for (int i = 0; i < size(); i++)
- result += getQuick(i) * x.getQuick(i);
+ for (int i = 0; i < size(); i++) {
+ {
+ result += getQuick(i) * x.getQuick(i);
+ }
+ }
return result;
}
@@ -317,22 +324,22 @@
@Override
public double getLengthSquared() {
- double result = 0.0;
- for (int i = 0; i < cardinality; i++) {
- double value = getQuick(i);
- result += value * value;
- }
- return result;
+ double result = 0.0;
+ for (int i = 0; i < cardinality; i++) {
+ double value = getQuick(i);
+ result += value * value;
+ }
+ return result;
}
@Override
- public double getDistanceSquared(Vector v) {
- double result = 0.0;
- for (int i = 0; i < cardinality; i++) {
- double delta = getQuick(i) - v.getQuick(i);
- result += delta * delta;
- }
- return result;
+ public double getDistanceSquared(Vector v) {
+ double result = 0.0;
+ for (int i = 0; i < cardinality; i++) {
+ double delta = getQuick(i) - v.getQuick(i);
+ result += delta * delta;
+ }
+ return result;
}
@Override
@@ -340,7 +347,7 @@
Iterator<Vector.Element> iter = iterateNonZero();
while (iter.hasNext()) {
Vector.Element elt = iter.next();
- v.set(elt.index(), elt.get() + v.get(elt.index()));
+ v.set(elt.index(), elt.get() + v.get(elt.index()));
}
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/CosineDistanceMeasure.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/CosineDistanceMeasure.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/CosineDistanceMeasure.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/CosineDistanceMeasure.java Fri Jul 10 09:35:19 2009
@@ -27,8 +27,8 @@
import java.util.Iterator;
/**
- * This class implements a cosine distance metric by dividing the dot product
- * of two vectors by the product of their lengths
+ * This class implements a cosine distance metric by dividing the dot product of two vectors by the product of their
+ * lengths
*/
public class CosineDistanceMeasure implements DistanceMeasure {
@@ -59,16 +59,18 @@
double denominator = Math.sqrt(lengthSquaredp1) * Math.sqrt(lengthSquaredp2);
// correct for floating-point rounding errors
- if (denominator < dotProduct)
+ if (denominator < dotProduct) {
denominator = dotProduct;
+ }
return 1.0 - (dotProduct / denominator);
}
@Override
public double distance(Vector v1, Vector v2) {
- if (v1.size() != v2.size())
+ if (v1.size() != v2.size()) {
throw new CardinalityException();
+ }
double lengthSquaredv1 = 0.0;
Iterator<Vector.Element> iter = v1.iterateNonZero();
while (iter.hasNext()) {
@@ -86,15 +88,16 @@
double denominator = Math.sqrt(lengthSquaredv1) * Math.sqrt(lengthSquaredv2);
// correct for floating-point rounding errors
- if (denominator < dotProduct)
+ if (denominator < dotProduct) {
denominator = dotProduct;
+ }
return 1.0 - (dotProduct / denominator);
}
@Override
- public double distance(double centroidLengthSquare, Vector centroid, Vector v) {
- return distance(centroid, v); // TODO
- }
+ public double distance(double centroidLengthSquare, Vector centroid, Vector v) {
+ return distance(centroid, v); // TODO
+ }
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/DistanceMeasure.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/DistanceMeasure.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/DistanceMeasure.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/DistanceMeasure.java Fri Jul 10 09:35:19 2009
@@ -17,34 +17,27 @@
package org.apache.mahout.utils;
-import org.apache.mahout.matrix.CardinalityException;
import org.apache.mahout.matrix.Vector;
import org.apache.mahout.utils.parameters.Parametered;
-/**
- * This interface is used for objects which can determine a distance metric
- * between two points
- */
+/** This interface is used for objects which can determine a distance metric between two points */
public interface DistanceMeasure extends Parametered {
/**
* Returns the distance metric applied to the arguments
- *
+ *
* @param v1 a Vector defining a multidimensional point in some feature space
* @param v2 a Vector defining a multidimensional point in some feature space
* @return a scalar doubles of the distance
- * @throws CardinalityException
*/
double distance(Vector v1, Vector v2);
-
+
/**
- * Optimized version of distance metric for sparse vectors. This distance computation requires
- * operations proportional to the number of non-zero elements in the vector instead of the cardinality
- * of the vector.
+ * Optimized version of distance metric for sparse vectors. This distance computation requires operations proportional
+ * to the number of non-zero elements in the vector instead of the cardinality of the vector.
+ *
* @param centroidLengthSquare Square of the length of centroid
- * @param centroid Centroid vector
- * @param v
- * @return
+ * @param centroid Centroid vector
*/
double distance(double centroidLengthSquare, Vector centroid, Vector v);
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/EuclideanDistanceMeasure.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/EuclideanDistanceMeasure.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/EuclideanDistanceMeasure.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/EuclideanDistanceMeasure.java Fri Jul 10 09:35:19 2009
@@ -20,12 +20,10 @@
import org.apache.mahout.matrix.Vector;
/**
- * This class implements a Euclidian distance metric by summing the square root
- * of the squared differences between each coordinate.
- * <p/>
- * If you don't care about the true distance and only need the values for comparison, then
- * the base class, {@link SquaredEuclideanDistanceMeasure}, will be faster since it doesn't do
- * the actual square root of the squared differences.
+ * This class implements a Euclidian distance metric by summing the square root of the squared differences between each
+ * coordinate. <p/> If you don't care about the true distance and only need the values for comparison, then the base
+ * class, {@link SquaredEuclideanDistanceMeasure}, will be faster since it doesn't do the actual square root of the
+ * squared differences.
*/
public class EuclideanDistanceMeasure extends SquaredEuclideanDistanceMeasure {
@Override
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/ManhattanDistanceMeasure.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/ManhattanDistanceMeasure.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/ManhattanDistanceMeasure.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/ManhattanDistanceMeasure.java Fri Jul 10 09:35:19 2009
@@ -27,15 +27,16 @@
import java.util.Iterator;
/**
- * This class implements a "manhattan distance" metric by summing the absolute
- * values of the difference between each coordinate
+ * This class implements a "manhattan distance" metric by summing the absolute values of the difference between each
+ * coordinate
*/
public class ManhattanDistanceMeasure implements DistanceMeasure {
public static double distance(double[] p1, double[] p2) {
double result = 0.0;
- for (int i = 0; i < p1.length; i++)
+ for (int i = 0; i < p1.length; i++) {
result += Math.abs(p2[i] - p1[i]);
+ }
return result;
}
@@ -54,23 +55,24 @@
// nothing to do
}
- @Override
- public double distance(Vector v1, Vector v2) {
- if (v1.size() != v2.size())
+ @Override
+ public double distance(Vector v1, Vector v2) {
+ if (v1.size() != v2.size()) {
throw new CardinalityException();
+ }
double result = 0;
- Vector vector = v1.plus(v2);
- Iterator<Vector.Element> iter = vector.iterateNonZero();//this contains all non zero elements between the two
- while (iter.hasNext()){
+ Vector vector = v1.plus(v2);
+ Iterator<Vector.Element> iter = vector.iterateNonZero();//this contains all non zero elements between the two
+ while (iter.hasNext()) {
Vector.Element e = iter.next();
result += Math.abs(v2.getQuick(e.index()) - v1.getQuick(e.index()));
}
return result;
}
- @Override
- public double distance(double centroidLengthSquare, Vector centroid, Vector v) {
- return distance(centroid, v); // TODO
- }
-
+ @Override
+ public double distance(double centroidLengthSquare, Vector centroid, Vector v) {
+ return distance(centroid, v); // TODO
+ }
+
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/SquaredEuclideanDistanceMeasure.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/SquaredEuclideanDistanceMeasure.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/SquaredEuclideanDistanceMeasure.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/SquaredEuclideanDistanceMeasure.java Fri Jul 10 09:35:19 2009
@@ -17,9 +17,9 @@
*/
import org.apache.hadoop.mapred.JobConf;
-import org.apache.mahout.utils.parameters.Parameter;
-import org.apache.mahout.matrix.Vector;
import org.apache.mahout.matrix.CardinalityException;
+import org.apache.mahout.matrix.Vector;
+import org.apache.mahout.utils.parameters.Parameter;
import java.util.Collection;
import java.util.Collections;
@@ -27,12 +27,10 @@
/**
- * Like {@link org.apache.mahout.utils.EuclideanDistanceMeasure} but it does not take the square root.
- * <p/>
- * Thus, it is not actually the Euclidean Distance, but it is saves on computation when you only need the distance for
- * comparison and don't care about the actual value as a distance.
- *
- **/
+ * Like {@link org.apache.mahout.utils.EuclideanDistanceMeasure} but it does not take the square root. <p/> Thus, it is
+ * not actually the Euclidean Distance, but it is saves on computation when you only need the distance for comparison
+ * and don't care about the actual value as a distance.
+ */
public class SquaredEuclideanDistanceMeasure implements DistanceMeasure {
@Override
@@ -62,8 +60,9 @@
@Override
public double distance(Vector v1, Vector v2) {
- if (v1.size() != v2.size())
+ if (v1.size() != v2.size()) {
throw new CardinalityException();
+ }
double result = 0;
Vector vector = v1.plus(v2);
Iterator<Vector.Element> iter = vector.iterateNonZero();//this contains all non zero elements between the two
@@ -78,11 +77,12 @@
@Override
public double distance(double centroidLengthSquare, Vector centroid, Vector v) {
- if (centroid.size() != centroid.size())
- throw new CardinalityException();
+ if (centroid.size() != centroid.size()) {
+ throw new CardinalityException();
+ }
- double result = centroidLengthSquare;
- result += v.getDistanceSquared(centroid);
- return result;
+ double result = centroidLengthSquare;
+ result += v.getDistanceSquared(centroid);
+ return result;
}
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/StringUtils.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/StringUtils.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/StringUtils.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/StringUtils.java Fri Jul 10 09:35:19 2009
@@ -20,9 +20,8 @@
import com.thoughtworks.xstream.XStream;
/**
- * Offers two methods to convert an object to a string representation and
- * restore the object given its string representation. Should use Hadoop
- * Stringifier whenever available.
+ * Offers two methods to convert an object to a string representation and restore the object given its string
+ * representation. Should use Hadoop Stringifier whenever available.
*/
public final class StringUtils {
@@ -31,10 +30,10 @@
private StringUtils() {
// do nothing
}
-
+
/**
* Converts the object to a one-line string representation
- *
+ *
* @param obj the object to convert
* @return the string representation of the object
*/
@@ -44,7 +43,7 @@
/**
* Restores the object from its string representation.
- *
+ *
* @param str the string representation of the object
* @return restored object
*/
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/TanimotoDistanceMeasure.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/TanimotoDistanceMeasure.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/TanimotoDistanceMeasure.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/TanimotoDistanceMeasure.java Fri Jul 10 09:35:19 2009
@@ -20,8 +20,8 @@
import org.apache.mahout.matrix.Vector;
import java.util.HashSet;
-import java.util.Set;
import java.util.Iterator;
+import java.util.Set;
/**
@@ -37,8 +37,6 @@
*
* ((a^2 + b^2 - ab) / ab) - 1;
*
- * @param vector0
- * @param vector1
* @return 0 for perfect match, > 0 for greater distance
*/
@Override
@@ -46,8 +44,8 @@
// this whole distance measurent thing
// should be evaluated using an intermediate vector and BinaryFunction or something?
-
- Set<Integer> featuresSeen = new HashSet<Integer>((int)((vector0.getNumNondefaultElements() + vector1.getNumNondefaultElements()) * 0.75));
+
+ Set<Integer> featuresSeen = new HashSet<Integer>((int) ((vector0.getNumNondefaultElements() + vector1.getNumNondefaultElements()) * 0.75));
double ab = 0.0;
double a2 = 0.0;
@@ -94,8 +92,8 @@
}
@Override
- public double distance(double centroidLengthSquare, Vector centroid, Vector v) {
- return distance(centroid, v); // TODO
+ public double distance(double centroidLengthSquare, Vector centroid, Vector v) {
+ return distance(centroid, v); // TODO
}
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/WeightedDistanceMeasure.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/WeightedDistanceMeasure.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/WeightedDistanceMeasure.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/WeightedDistanceMeasure.java Fri Jul 10 09:35:19 2009
@@ -33,9 +33,7 @@
import java.util.Collection;
import java.util.List;
-/**
- * Abstract implementation of DistanceMeasure with support for weights.
- */
+/** Abstract implementation of DistanceMeasure with support for weights. */
public abstract class WeightedDistanceMeasure implements DistanceMeasure {
private List<Parameter<?>> parameters;
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/WeightedEuclideanDistanceMeasure.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/WeightedEuclideanDistanceMeasure.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/WeightedEuclideanDistanceMeasure.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/WeightedEuclideanDistanceMeasure.java Fri Jul 10 09:35:19 2009
@@ -22,8 +22,8 @@
import java.util.Iterator;
/**
- * This class implements a Euclidian distance metric by summing the square root
- * of the squared differences between each coordinate, optionally adding weights.
+ * This class implements a Euclidian distance metric by summing the square root of the squared differences between each
+ * coordinate, optionally adding weights.
*/
public class WeightedEuclideanDistanceMeasure extends WeightedDistanceMeasure {
@@ -48,8 +48,8 @@
}
@Override
- public double distance(double centroidLengthSquare, Vector centroid, Vector v) {
- return distance(centroid, v); // TODO
+ public double distance(double centroidLengthSquare, Vector centroid, Vector v) {
+ return distance(centroid, v); // TODO
}
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/WeightedManhattanDistanceMeasure.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/WeightedManhattanDistanceMeasure.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/WeightedManhattanDistanceMeasure.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/WeightedManhattanDistanceMeasure.java Fri Jul 10 09:35:19 2009
@@ -22,8 +22,8 @@
import java.util.Iterator;
/**
- * This class implements a "manhattan distance" metric by summing the absolute
- * values of the difference between each coordinate, optionally with weights.
+ * This class implements a "manhattan distance" metric by summing the absolute values of the difference between each
+ * coordinate, optionally with weights.
*/
public class WeightedManhattanDistanceMeasure extends WeightedDistanceMeasure {
@@ -39,8 +39,7 @@
result += Math.abs(elt.get());
}
- }
- else {
+ } else {
Iterator<Vector.Element> iter = res.iterateNonZero();
while (iter.hasNext()) {
Vector.Element elt = iter.next();
@@ -52,8 +51,8 @@
}
@Override
- public double distance(double centroidLengthSquare, Vector centroid, Vector v) {
- return distance(centroid, v); // TODO
+ public double distance(double centroidLengthSquare, Vector centroid, Vector v) {
+ return distance(centroid, v); // TODO
}
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/CompositeParameter.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/CompositeParameter.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/CompositeParameter.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/CompositeParameter.java Fri Jul 10 09:35:19 2009
@@ -21,9 +21,7 @@
import java.util.Collection;
-/**
- * A placeholder for some sort of class with more parameters.
- */
+/** A placeholder for some sort of class with more parameters. */
public class CompositeParameter<T extends Parametered> extends AbstractParameter<T> {
public CompositeParameter(Class<T> type, String prefix, String name, JobConf jobConf, T defaultValue, String description) {
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/FileParameter.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/FileParameter.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/FileParameter.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/FileParameter.java Fri Jul 10 09:35:19 2009
@@ -21,7 +21,7 @@
import java.io.File;
-public class FileParameter extends AbstractParameter<File>{
+public class FileParameter extends AbstractParameter<File> {
public FileParameter(String prefix, String name, JobConf jobConf, File defaultValue, String description) {
super(File.class, prefix, name, jobConf, defaultValue, description);
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/Parameter.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/Parameter.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/Parameter.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/Parameter.java Fri Jul 10 09:35:19 2009
@@ -20,28 +20,35 @@
/**
* An accessor to a parameters in the job.
*
- * This is a composite entity that can it self contain more parameters.
- * Say the parameters describes what DistanceMeasure class to use,
- * once set this parameters would also produce the parameters available
- * in that DistanceMeasure implementation.
+ * This is a composite entity that can it self contain more parameters. Say the parameters describes what
+ * DistanceMeasure class to use, once set this parameters would also produce the parameters available in that
+ * DistanceMeasure implementation.
*/
public interface Parameter<T> extends Parametered {
/** @return job configuration setting key prefix, e.g. 'org.apache.mahout.util.WeightedDistanceMeasure.' */
String prefix();
+
/** @return configuration parameters name, e.g. 'weightsFile' */
String name();
+
/** @return human readable description of parameters */
String description();
+
/** @return value class type */
Class<T> type();
+
/** @param stringValue value string representation */
void setStringValue(String stringValue);
+
/** @return value string reprentation of current value */
String getStringValue();
+
/** @param value new parameters value */
void set(T value);
+
/** @return current parameters value */
T get();
+
/** @return value used if not set by consumer */
String defaultValue();
}
\ No newline at end of file
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/Parametered.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/Parametered.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/Parametered.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/parameters/Parametered.java Fri Jul 10 09:35:19 2009
@@ -24,9 +24,7 @@
import java.util.Collection;
-/**
- * Meta information and accessors for configuring a job.
- */
+/** Meta information and accessors for configuring a job. */
public interface Parametered extends JobConfigurable {
Logger log = LoggerFactory.getLogger(Parametered.class);
@@ -34,31 +32,31 @@
Collection<Parameter<?>> getParameters();
/**
- * EXPERT: consumers should never have to call this method. It would be friendly visible to
- * {@link ParameteredGeneralizations} if java supported it.
- * Calling this method should create a new list of parameters and is called
- * @see ParameteredGeneralizations#configureParameters(String,Parametered,org.apache.hadoop.mapred.JobConf) invoking method
- * @see ParameteredGeneralizations#configureParametersRecusivly(Parametered,String,org.apache.hadoop.mapred.JobConf) invoking method
- * @param prefix ends with a dot if not empty.
+ * EXPERT: consumers should never have to call this method. It would be friendly visible to {@link
+ * ParameteredGeneralizations} if java supported it. Calling this method should create a new list of parameters and is
+ * called
+ *
+ * @param prefix ends with a dot if not empty.
* @param jobConf configuration used for retreiving values
+ * @see ParameteredGeneralizations#configureParameters(String,Parametered,org.apache.hadoop.mapred.JobConf) invoking
+ * method
+ * @see ParameteredGeneralizations#configureParametersRecusivly(Parametered,String,org.apache.hadoop.mapred.JobConf)
+ * invoking method
*/
void createParameters(String prefix, JobConf jobConf);
- /**
- * "multiple inheritance"
- */
+ /** "multiple inheritance" */
class ParameteredGeneralizations {
private ParameteredGeneralizations() {
}
/**
- * @see #configureParameters(Parametered,org.apache.hadoop.mapred.JobConf)
- * Uses parametered simple class name as prefix.
- *
* @param parametered instance to be configured
- * @param jobConf configuration used for retreiving values
+ * @param jobConf configuration used for retreiving values
+ * @see #configureParameters(Parametered,org.apache.hadoop.mapred.JobConf) Uses parametered simple class name as
+ * prefix.
*/
public static void configureParameters(Parametered parametered, JobConf jobConf) {
configureParameters(parametered.getClass().getSimpleName() + '.', parametered, jobConf);
@@ -67,15 +65,14 @@
/**
* Calls {@link org.apache.mahout.utils.parameters.Parametered#createParameters(String,org.apache.hadoop.mapred.JobConf)}
- * on parameter parmetered,
- * and then recurse down its composite tree
- * to invoke {@link org.apache.mahout.utils.parameters.Parametered#createParameters(String,org.apache.hadoop.mapred.JobConf)}
- * and {@link org.apache.hadoop.mapred.JobConfigurable#configure(org.apache.hadoop.mapred.JobConf)}
- * on each composite part.
+ * on parameter parmetered, and then recurse down its composite tree to invoke {@link
+ * org.apache.mahout.utils.parameters.Parametered#createParameters(String,org.apache.hadoop.mapred.JobConf)} and
+ * {@link org.apache.hadoop.mapred.JobConfigurable#configure(org.apache.hadoop.mapred.JobConf)} on each composite
+ * part.
*
- * @param prefix ends with a dot if not empty.
+ * @param prefix ends with a dot if not empty.
* @param parametered instance to be configured
- * @param jobConf configuration used for retreiving values
+ * @param jobConf configuration used for retreiving values
*/
public static void configureParameters(String prefix, Parametered parametered, JobConf jobConf) {
parametered.createParameters(prefix, jobConf);
Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/common/CommonTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/common/CommonTest.java?rev=792856&r1=792855&r2=792856&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/common/CommonTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/common/CommonTest.java Fri Jul 10 09:35:19 2009
@@ -24,9 +24,7 @@
import java.io.PrintStream;
import java.io.PrintWriter;
-/**
- * <p>Tests common classes.</p>
- */
+/** <p>Tests common classes.</p> */
public final class CommonTest extends TasteTestCase {
public void testException() {