Index: src/examples/org/apache/hama/examples/ExampleDriver.java =================================================================== --- src/examples/org/apache/hama/examples/ExampleDriver.java (리비전 950897) +++ src/examples/org/apache/hama/examples/ExampleDriver.java (작업 사본) @@ -27,7 +27,6 @@ ProgramDriver pgd = new ProgramDriver(); try { pgd.addClass("rand", RandomMatrix.class, "Generate matrix with random elements."); - pgd.addClass("add", MatrixAddition.class, "Mat-Mat Addition."); pgd.addClass("mult", MatrixMultiplication.class, "Mat-Mat Multiplication."); pgd.addClass("similarity", CosineSimilarityMatrix.class, "Cosine Similarity Matrix."); pgd.addClass("norms", MatrixNorm.class, "Matrix Norms."); Index: src/examples/org/apache/hama/examples/MatrixAddition.java =================================================================== --- src/examples/org/apache/hama/examples/MatrixAddition.java (리비전 950897) +++ src/examples/org/apache/hama/examples/MatrixAddition.java (작업 사본) @@ -1,63 +0,0 @@ -/** - * 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.examples; - -import java.io.IOException; - -import org.apache.hama.HamaAdmin; -import org.apache.hama.HamaAdminImpl; -import org.apache.hama.matrix.Matrix; - -public class MatrixAddition extends AbstractExample { - public static void main(String[] args) throws IOException { - if (args.length < 2) { - System.out - .println("add [-m maps] [-r reduces] [alpha]"); - System.exit(-1); - } else { - parseArgs(args); - } - - String matrixA = ARGS.get(0); - String matrixB = ARGS.get(1); - - HamaAdmin admin = new HamaAdminImpl(conf); - Matrix a = admin.getMatrix(matrixA); - Matrix b = admin.getMatrix(matrixB); - - Matrix c; - if (a.getType().equals("SparseMatrix")) { - System.out - .println("The addition of sparse matrices is not implemented yet."); - } else { - if (ARGS.size() > 2) { - System.out.println("C = " + Double.parseDouble(ARGS.get(2)) - + " * B + A"); - c = a.add(Double.parseDouble(ARGS.get(2)), b); - } else { - System.out.println("C = A + B"); - c = a.add(b); - } - - c.close(); - } - - } -} Index: src/examples/org/apache/hama/examples/MatrixMultiplication.java =================================================================== --- src/examples/org/apache/hama/examples/MatrixMultiplication.java (리비전 950897) +++ src/examples/org/apache/hama/examples/MatrixMultiplication.java (작업 사본) @@ -37,11 +37,14 @@ import org.apache.hama.Constants; import org.apache.hama.HamaAdmin; import org.apache.hama.HamaAdminImpl; -import org.apache.hama.examples.mapreduce.*; +import org.apache.hama.examples.mapreduce.BlockMultMap; +import org.apache.hama.examples.mapreduce.BlockMultReduce; +import org.apache.hama.examples.mapreduce.CollectBlocksMapper; +import org.apache.hama.examples.mapreduce.DenseMatrixVectorMultMap; +import org.apache.hama.examples.mapreduce.DenseMatrixVectorMultReduce; import org.apache.hama.io.BlockID; import org.apache.hama.matrix.DenseMatrix; import org.apache.hama.matrix.Matrix; -import org.apache.hama.matrix.SparseMatrix; import org.apache.hama.util.RandomVariable; public class MatrixMultiplication extends AbstractExample { @@ -66,13 +69,11 @@ System.exit(-1); } - Matrix c; + Matrix c = null; if (a.getType().equals("SparseMatrix")) { - if (ARGS.size() > 2) { System.out - .println("NOTE: You can't use the block algorithm for sparse matrix multiplication."); - } - c = ((SparseMatrix) a).mult(b); + .println("NOTE: Not implemented M/R based sparse matrix multiplication."); + System.exit(-1); } else { if (ARGS.size() > 2) { c = mult(a, b, Integer.parseInt(ARGS.get(2))); Index: src/java/org/apache/hama/matrix/AbstractMatrix.java =================================================================== --- src/java/org/apache/hama/matrix/AbstractMatrix.java (리비전 950897) +++ src/java/org/apache/hama/matrix/AbstractMatrix.java (작업 사본) @@ -40,15 +40,11 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.mapreduce.TableMapper; import org.apache.hadoop.hbase.util.Bytes; -import org.apache.hadoop.io.IntWritable; -import org.apache.hadoop.io.MapWritable; import org.apache.hadoop.mapreduce.Job; import org.apache.hama.Constants; import org.apache.hama.HamaAdmin; import org.apache.hama.HamaAdminImpl; import org.apache.hama.HamaConfiguration; -import org.apache.hama.matrix.algebra.TransposeMap; -import org.apache.hama.matrix.algebra.TransposeReduce; import org.apache.hama.util.BytesUtil; import org.apache.hama.util.RandomVariable; import org.apache.log4j.Logger; @@ -424,34 +420,6 @@ closed = true; } - public Matrix transpose() throws IOException { - Matrix result; - if (this.getType().equals("SparseMatrix")) { - result = new SparseMatrix(config, this.getRows(), this.getColumns()); - } else { - result = new DenseMatrix(config, this.getRows(), this.getColumns()); - } - - Job job = new Job(config, "set MR job : " + this.getPath()); - - Scan scan = new Scan(); - scan.addFamily(Constants.COLUMNFAMILY); - org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil.initTableMapperJob( - this.getPath(), scan, TransposeMap.class, IntWritable.class, - MapWritable.class, job); - org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil.initTableReducerJob( - result.getPath(), TransposeReduce.class, job); - try { - job.waitForCompletion(true); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - - return result; - } - public boolean checkAllJobs(List jobId) throws IOException { Iterator it = jobId.iterator(); boolean allTrue = true; Index: src/java/org/apache/hama/matrix/DenseMatrix.java =================================================================== --- src/java/org/apache/hama/matrix/DenseMatrix.java (리비전 950897) +++ src/java/org/apache/hama/matrix/DenseMatrix.java (작업 사본) @@ -29,17 +29,13 @@ import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; -import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.io.DoubleWritable; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.MapWritable; import org.apache.hadoop.io.Writable; -import org.apache.hadoop.mapreduce.Job; import org.apache.hama.Constants; import org.apache.hama.HamaConfiguration; -import org.apache.hama.matrix.algebra.MatrixAdditionMap; -import org.apache.hama.matrix.algebra.MatrixAdditionReduce; import org.apache.hama.util.BytesUtil; import org.apache.hama.util.RandomVariable; @@ -333,104 +329,6 @@ } /** - * C = alpha*B + A - * - * @param alpha - * @param B - * @return C - * @throws IOException - */ - public DenseMatrix add(double alpha, Matrix B) throws IOException { - ensureForAddition(B); - - DenseMatrix result = new DenseMatrix(config, this.getRows(), this - .getColumns()); - Job job = new Job(config, "addition MR job" + result.getPath()); - - Scan scan = new Scan(); - scan.addFamily(Constants.COLUMNFAMILY); - job.getConfiguration().set(MatrixAdditionMap.MATRIX_SUMMANDS, B.getPath()); - job.getConfiguration().set(MatrixAdditionMap.MATRIX_ALPHAS, - Double.toString(alpha)); - - TableMapReduceUtil.initTableMapperJob(this.getPath(), scan, - MatrixAdditionMap.class, IntWritable.class, MapWritable.class, job); - TableMapReduceUtil.initTableReducerJob(result.getPath(), - MatrixAdditionReduce.class, job); - try { - job.waitForCompletion(true); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - - return result; - } - - /** - * C = B + A - * - * @param B - * @return C - * @throws IOException - */ - public DenseMatrix add(Matrix B) throws IOException { - return add(1.0, B); - } - - public DenseMatrix add(Matrix... matrices) throws IOException { - // ensure all the matrices are suitable for addition. - for (Matrix m : matrices) { - ensureForAddition(m); - } - - DenseMatrix result = new DenseMatrix(config, this.getRows(), this - .getColumns()); - - StringBuilder summandList = new StringBuilder(); - StringBuilder alphaList = new StringBuilder(); - for (Matrix m : matrices) { - summandList.append(m.getPath()); - summandList.append(","); - alphaList.append("1"); - alphaList.append(","); - } - summandList.deleteCharAt(summandList.length() - 1); - alphaList.deleteCharAt(alphaList.length() - 1); - - Job job = new Job(config, "addition MR job" + result.getPath()); - - Scan scan = new Scan(); - scan.addFamily(Constants.COLUMNFAMILY); - job.getConfiguration().set(MatrixAdditionMap.MATRIX_SUMMANDS, - summandList.toString()); - job.getConfiguration().set(MatrixAdditionMap.MATRIX_ALPHAS, - alphaList.toString()); - - TableMapReduceUtil.initTableMapperJob(this.getPath(), scan, - MatrixAdditionMap.class, IntWritable.class, MapWritable.class, job); - TableMapReduceUtil.initTableReducerJob(result.getPath(), - MatrixAdditionReduce.class, job); - try { - job.waitForCompletion(true); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - - return result; - } - - private void ensureForAddition(Matrix m) throws IOException { - if (getRows() != m.getRows() || getColumns() != m.getColumns()) { - throw new IOException( - "Matrices' rows and columns should be same while A+B."); - } - } - - /** * C = alpha*A*B + C * * @param alpha Index: src/java/org/apache/hama/matrix/Matrix.java =================================================================== --- src/java/org/apache/hama/matrix/Matrix.java (리비전 950897) +++ src/java/org/apache/hama/matrix/Matrix.java (작업 사본) @@ -177,25 +177,6 @@ public void add(int i, int j, double value) throws IOException; /** - * A = B + A - * - * @param B - * @return A - * @throws IOException - */ - public Matrix add(Matrix B) throws IOException; - - /** - * A = alpha*B + A - * - * @param alpha - * @param B - * @return A - * @throws IOException - */ - public Matrix add(double alpha, Matrix B) throws IOException; - - /** * C = alpha*A*B + C * * @param alpha @@ -222,14 +203,6 @@ /** Largest entry in absolute value. */ Maxvalue } - - /** - * Transposes the matrix. In most cases, the matrix must be square - * for this to work. - * - * @return the transposed matrix - */ - public Matrix transpose() throws IOException; /** * Save to a table or file Index: src/java/org/apache/hama/matrix/SparseMatrix.java =================================================================== --- src/java/org/apache/hama/matrix/SparseMatrix.java (리비전 950897) +++ src/java/org/apache/hama/matrix/SparseMatrix.java (작업 사본) @@ -34,13 +34,9 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.io.DoubleWritable; import org.apache.hadoop.io.IntWritable; -import org.apache.hadoop.io.MapWritable; import org.apache.hadoop.io.Writable; -import org.apache.hadoop.mapreduce.Job; import org.apache.hama.Constants; import org.apache.hama.HamaConfiguration; -import org.apache.hama.matrix.algebra.SparseMatrixVectorMultMap; -import org.apache.hama.matrix.algebra.SparseMatrixVectorMultReduce; import org.apache.hama.util.BytesUtil; import org.apache.hama.util.RandomVariable; @@ -107,18 +103,6 @@ } @Override - public Matrix add(Matrix B) throws IOException { - // TODO Auto-generated method stub - return null; - } - - @Override - public Matrix add(double alpha, Matrix B) throws IOException { - // TODO Auto-generated method stub - return null; - } - - @Override public double get(int i, int j) throws IOException { if (this.getRows() < i || this.getColumns() < j) throw new ArrayIndexOutOfBoundsException(i + ", " + j); @@ -168,56 +152,6 @@ return this.getClass().getSimpleName(); } - /** - * C = A*B using iterative method - * - * @param B - * @return C - * @throws IOException - */ - public SparseMatrix mult(Matrix B) throws IOException { - SparseMatrix result = new SparseMatrix(config, this.getRows(), this - .getColumns()); - - List jobId = new ArrayList(); - - for (int i = 0; i < this.getRows(); i++) { - Job job = new Job(config, "multiplication MR job : " + result.getPath() - + " " + i); - - Scan scan = new Scan(); - scan.addFamily(Constants.COLUMNFAMILY); - job.getConfiguration().set(SparseMatrixVectorMultMap.MATRIX_A, - this.getPath()); - job.getConfiguration().setInt(SparseMatrixVectorMultMap.ITH_ROW, i); - - TableMapReduceUtil.initTableMapperJob(B.getPath(), scan, - SparseMatrixVectorMultMap.class, IntWritable.class, - MapWritable.class, job); - TableMapReduceUtil.initTableReducerJob(result.getPath(), - SparseMatrixVectorMultReduce.class, job); - try { - job.waitForCompletion(false); - jobId.add(job); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - } - - while (checkAllJobs(jobId) == false) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - return result; - } - @Override public Matrix multAdd(double alpha, Matrix B, Matrix C) throws IOException { // TODO Auto-generated method stub Index: src/java/org/apache/hama/matrix/algebra/MatrixAdditionMap.java =================================================================== --- src/java/org/apache/hama/matrix/algebra/MatrixAdditionMap.java (리비전 950897) +++ src/java/org/apache/hama/matrix/algebra/MatrixAdditionMap.java (작업 사본) @@ -1,65 +0,0 @@ -package org.apache.hama.matrix.algebra; - -import java.io.IOException; - -import org.apache.hadoop.conf.Configurable; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.client.Result; -import org.apache.hadoop.hbase.io.ImmutableBytesWritable; -import org.apache.hadoop.hbase.mapreduce.TableMapper; -import org.apache.hadoop.io.IntWritable; -import org.apache.hadoop.io.MapWritable; -import org.apache.hama.HamaConfiguration; -import org.apache.hama.matrix.DenseMatrix; -import org.apache.hama.matrix.DenseVector; -import org.apache.hama.util.BytesUtil; -import org.apache.log4j.Logger; - -public class MatrixAdditionMap extends TableMapper - implements Configurable { - static final Logger LOG = Logger.getLogger(MatrixAdditionMap.class); - private Configuration conf = null; - protected DenseMatrix[] matrix_summands; - protected double[] matrix_alphas; - public static final String MATRIX_SUMMANDS = "hama.addition.summands"; - public static final String MATRIX_ALPHAS = "hama.addition.alphas"; - - public void map(ImmutableBytesWritable key, Result value, Context context) - throws IOException, InterruptedException { - IntWritable nKey = new IntWritable(BytesUtil.getRowIndex(key.get())); - - DenseVector result = new DenseVector(value); - DenseVector summand; - for (int i = 0; i < matrix_summands.length; i++) { - summand = matrix_summands[i].getRow(nKey.get()); - result = result.add(matrix_alphas[i], summand); - } - context.write(nKey, result.getEntries()); - } - - @Override - public Configuration getConf() { - return conf; - } - - @Override - public void setConf(Configuration conf) { - this.conf = conf; - try { - String[] matrix_names = conf.get(MATRIX_SUMMANDS, "").split(","); - String[] matrix_alpha_strs = conf.get(MATRIX_ALPHAS, "").split(","); - assert (matrix_names.length == matrix_alpha_strs.length && matrix_names.length >= 1); - - matrix_summands = new DenseMatrix[matrix_names.length]; - matrix_alphas = new double[matrix_names.length]; - for (int i = 0; i < matrix_names.length; i++) { - matrix_summands[i] = new DenseMatrix(new HamaConfiguration(conf), - matrix_names[i]); - matrix_alphas[i] = Double.valueOf(matrix_alpha_strs[i]); - } - } catch (IOException e) { - LOG.warn("Load matrix_b failed : " + e.getMessage()); - } - } - -} Index: src/java/org/apache/hama/matrix/algebra/MatrixAdditionReduce.java =================================================================== --- src/java/org/apache/hama/matrix/algebra/MatrixAdditionReduce.java (리비전 950897) +++ src/java/org/apache/hama/matrix/algebra/MatrixAdditionReduce.java (작업 사본) @@ -1,37 +0,0 @@ -package org.apache.hama.matrix.algebra; - -import java.io.IOException; -import java.util.Map; - -import org.apache.hadoop.hbase.client.Put; -import org.apache.hadoop.hbase.io.ImmutableBytesWritable; -import org.apache.hadoop.hbase.mapreduce.TableReducer; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.hadoop.io.DoubleWritable; -import org.apache.hadoop.io.IntWritable; -import org.apache.hadoop.io.MapWritable; -import org.apache.hadoop.io.Writable; -import org.apache.hama.Constants; -import org.apache.hama.util.BytesUtil; - -public class MatrixAdditionReduce extends - TableReducer { - - @Override - public void reduce(IntWritable key, Iterable values, - Context context) throws IOException, InterruptedException { - - Put put = new Put(BytesUtil.getRowIndex(key.get())); - for (MapWritable value : values) { - for (Map.Entry e : value.entrySet()) { - - put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String - .valueOf(((IntWritable) e.getKey()).get())), Bytes - .toBytes(((DoubleWritable) e.getValue()).get())); - } - } - - context.write(new ImmutableBytesWritable(BytesUtil.getRowIndex(key.get())), - put); - } -} Index: src/java/org/apache/hama/matrix/algebra/SparseMatrixVectorMultMap.java =================================================================== --- src/java/org/apache/hama/matrix/algebra/SparseMatrixVectorMultMap.java (리비전 950897) +++ src/java/org/apache/hama/matrix/algebra/SparseMatrixVectorMultMap.java (작업 사본) @@ -1,73 +0,0 @@ -/** - * 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.matrix.algebra; - -import java.io.IOException; - -import org.apache.hadoop.conf.Configurable; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.client.Result; -import org.apache.hadoop.hbase.io.ImmutableBytesWritable; -import org.apache.hadoop.hbase.mapreduce.TableMapper; -import org.apache.hadoop.io.IntWritable; -import org.apache.hadoop.io.MapWritable; -import org.apache.hama.HamaConfiguration; -import org.apache.hama.matrix.SparseMatrix; -import org.apache.hama.matrix.SparseVector; -import org.apache.hama.util.BytesUtil; - -public class SparseMatrixVectorMultMap extends - TableMapper implements Configurable { - private Configuration conf = null; - protected SparseVector currVector; - public static final String ITH_ROW = "ith.row"; - public static final String MATRIX_A = "hama.multiplication.matrix.a"; - private IntWritable nKey = new IntWritable(); - - public void map(ImmutableBytesWritable key, Result value, Context context) - throws IOException, InterruptedException { - double ithjth = currVector.get(BytesUtil.getRowIndex(key.get())); - if (ithjth != 0) { - SparseVector scaled = new SparseVector(value).scale(ithjth); - context.write(nKey, scaled.getEntries()); - } - } - - @Override - public Configuration getConf() { - return conf; - } - - @Override - public void setConf(Configuration conf) { - this.conf = conf; - SparseMatrix matrix_a; - try { - matrix_a = new SparseMatrix(new HamaConfiguration(conf), conf.get(MATRIX_A, - "")); - int ithRow = conf.getInt(ITH_ROW, 0); - nKey.set(ithRow); - currVector = matrix_a.getRow(ithRow); - } catch (IOException e) { - e.printStackTrace(); - } - } - -} Index: src/java/org/apache/hama/matrix/algebra/SparseMatrixVectorMultReduce.java =================================================================== --- src/java/org/apache/hama/matrix/algebra/SparseMatrixVectorMultReduce.java (리비전 950897) +++ src/java/org/apache/hama/matrix/algebra/SparseMatrixVectorMultReduce.java (작업 사본) @@ -1,59 +0,0 @@ -/** - * 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.matrix.algebra; - -import java.io.IOException; -import java.util.Map; - -import org.apache.hadoop.hbase.client.Put; -import org.apache.hadoop.hbase.io.ImmutableBytesWritable; -import org.apache.hadoop.hbase.mapreduce.TableReducer; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.hadoop.io.DoubleWritable; -import org.apache.hadoop.io.IntWritable; -import org.apache.hadoop.io.MapWritable; -import org.apache.hadoop.io.Writable; -import org.apache.hama.Constants; -import org.apache.hama.matrix.SparseVector; -import org.apache.hama.util.BytesUtil; - -public class SparseMatrixVectorMultReduce extends - TableReducer { - - @Override - public void reduce(IntWritable key, Iterable values, - Context context) throws IOException, InterruptedException { - SparseVector sum = new SparseVector(); - - for (MapWritable value : values) { - sum.add(new SparseVector(value)); - } - - Put put = new Put(BytesUtil.getRowIndex(key.get())); - for (Map.Entry e : sum.getEntries().entrySet()) { - put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String - .valueOf(((IntWritable) e.getKey()).get())), Bytes - .toBytes(((DoubleWritable) e.getValue()).get())); - } - - context.write(new ImmutableBytesWritable(BytesUtil.getRowIndex(key.get())), - put); - } -} Index: src/java/org/apache/hama/matrix/algebra/TransposeMap.java =================================================================== --- src/java/org/apache/hama/matrix/algebra/TransposeMap.java (리비전 950897) +++ src/java/org/apache/hama/matrix/algebra/TransposeMap.java (작업 사본) @@ -1,50 +0,0 @@ -/** - * 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.matrix.algebra; - -import java.io.IOException; -import java.util.Map; - -import org.apache.hadoop.hbase.client.Result; -import org.apache.hadoop.hbase.io.ImmutableBytesWritable; -import org.apache.hadoop.hbase.mapreduce.TableMapper; -import org.apache.hadoop.io.IntWritable; -import org.apache.hadoop.io.MapWritable; -import org.apache.hadoop.io.Writable; -import org.apache.hama.matrix.DenseVector; -import org.apache.hama.util.BytesUtil; - -public class TransposeMap extends TableMapper { - private IntWritable nKey = new IntWritable(); - - public void map(ImmutableBytesWritable key, Result value, Context context) - throws IOException, InterruptedException { - IntWritable k = new IntWritable(BytesUtil.getRowIndex(key.get())); - - for(Map.Entry e : new DenseVector(value).getEntries().entrySet()) { - MapWritable val = new MapWritable(); - nKey.set(((IntWritable) e.getKey()).get()); - val.put(k, e.getValue()); - context.write(nKey, val); - val.clear(); - } - - } -} Index: src/java/org/apache/hama/matrix/algebra/TransposeReduce.java =================================================================== --- src/java/org/apache/hama/matrix/algebra/TransposeReduce.java (리비전 950897) +++ src/java/org/apache/hama/matrix/algebra/TransposeReduce.java (작업 사본) @@ -1,61 +0,0 @@ -/** - * 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.matrix.algebra; - -import java.io.IOException; -import java.util.Map; - -import org.apache.hadoop.hbase.client.Put; -import org.apache.hadoop.hbase.io.ImmutableBytesWritable; -import org.apache.hadoop.hbase.mapreduce.TableReducer; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.hadoop.io.DoubleWritable; -import org.apache.hadoop.io.IntWritable; -import org.apache.hadoop.io.MapWritable; -import org.apache.hadoop.io.Writable; -import org.apache.hama.Constants; -import org.apache.hama.util.BytesUtil; - -public class TransposeReduce extends - TableReducer { - - @Override - public void reduce(IntWritable key, Iterable values, - Context context) throws IOException, InterruptedException { - - MapWritable sum = new MapWritable(); - for (MapWritable value : values) { - for (Map.Entry e : value.entrySet()) { - sum.put(e.getKey(), e.getValue()); - } - } - - Put put = new Put(BytesUtil.getRowIndex(key.get())); - for (Map.Entry e : sum.entrySet()) { - put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String - .valueOf(((IntWritable) e.getKey()).get())), Bytes - .toBytes(((DoubleWritable) e.getValue()).get())); - } - - context.write(new ImmutableBytesWritable(BytesUtil.getRowIndex(key.get())), - put); - } - -} Index: src/java/org/apache/hama/matrix/algebra/package.html =================================================================== --- src/java/org/apache/hama/matrix/algebra/package.html (리비전 950897) +++ src/java/org/apache/hama/matrix/algebra/package.html (작업 사본) @@ -1,23 +0,0 @@ - - - - - -Algebraic operations on map/reduce - - Index: src/test/org/apache/hama/matrix/TestAbstractMatrix.java =================================================================== --- src/test/org/apache/hama/matrix/TestAbstractMatrix.java (리비전 950897) +++ src/test/org/apache/hama/matrix/TestAbstractMatrix.java (작업 사본) @@ -33,20 +33,9 @@ } public void testTransposeAndNorm() throws IOException { - testTrans(m1); - testTrans(m2); normTest(m1); normTest(m2); } - - public void testTrans(Matrix matrix) throws IOException { - Matrix trans1 = matrix.transpose(); - for (int i = 0; i < trans1.getRows(); i++) { - for (int j = 0; j < trans1.getColumns(); j++) { - assertEquals(trans1.get(i, j), matrix.get(j, i)); - } - } - } public void normTest(Matrix matrix) throws IOException { double norm1 = MatrixNorm.norm(matrix, Norm.One); Index: src/test/org/apache/hama/matrix/TestDenseMatrix.java =================================================================== --- src/test/org/apache/hama/matrix/TestDenseMatrix.java (리비전 950897) +++ src/test/org/apache/hama/matrix/TestDenseMatrix.java (작업 사본) @@ -37,7 +37,6 @@ static final Logger LOG = Logger.getLogger(TestDenseMatrix.class); private int SIZE = 10; private Matrix m1; - private Matrix m2; private HamaConfiguration conf; /** @@ -53,28 +52,13 @@ conf = getConf(); m1 = DenseMatrix.random(conf, SIZE, SIZE); - m2 = DenseMatrix.random(conf, SIZE, SIZE); } public void testAddMult() throws IOException { - - Matrix m3 = DenseMatrix.random(conf, SIZE, SIZE); - Matrix m4 = DenseMatrix.random(conf, SIZE - 2, SIZE - 2); - try { - m1.add(m4); - fail("Matrix-Addition should be failed while rows and columns aren't same."); - } catch (IOException e) { - LOG.info(e.toString()); - } - double origin = m1.get(1, 1); m1.add(1, 1, 0.5); assertEquals(m1.get(1, 1), origin + 0.5); - matrixAdd(m1, m2); - multMatrixAdd(m1, m2, m3); - addAlphaMatrix(m1, m2); - getRowColumnVector(); setRowColumnVector(); @@ -82,53 +66,6 @@ setAlphaMatrix(m1); } - /** - * Test matrices addition - * - * @throws IOException - */ - public void matrixAdd(Matrix m1, Matrix m2) throws IOException { - Matrix result = m1.add(m2); - - assertEquals(result.getRows(), SIZE); - assertEquals(result.getColumns(), SIZE); - - for (int i = 0; i < SIZE; i++) { - for (int j = 0; j < SIZE; j++) { - assertEquals(result.get(i, j), m1.get(i, j) + m2.get(i, j)); - } - } - - Matrix subtract = result.add(-1.0, m2); - - for (int i = 0; i < SIZE; i++) { - for (int j = 0; j < SIZE; j++) { - double gap = (subtract.get(i, j) - m1.get(i, j)); - assertTrue(-0.00001 < gap && gap < 0.00001); - } - } - } - - public void multMatrixAdd(Matrix m1, Matrix m2, Matrix m3) throws IOException { - Matrix result = ((DenseMatrix) m1).add(m2, m3); - - assertEquals(result.getRows(), SIZE); - assertEquals(result.getColumns(), SIZE); - - for (int i = 0; i < SIZE; i++) { - for (int j = 0; j < SIZE; j++) { - assertEquals(result.get(i, j), m1.get(i, j) + m2.get(i, j) - + m3.get(i, j)); - } - } - } - - public void addAlphaMatrix(Matrix m1, Matrix m2) throws IOException { - double value = m1.get(0, 0) + (m2.get(0, 0) * 0.1); - Matrix result = m1.add(0.1, m2); - assertEquals(value, result.get(0, 0)); - } - public void setMatrix(Matrix m1) throws IOException { Matrix a = new DenseMatrix(conf, m1.getRows(), m1.getColumns()); a.set(m1); Index: src/test/org/apache/hama/matrix/TestSparseMatrix.java =================================================================== --- src/test/org/apache/hama/matrix/TestSparseMatrix.java (리비전 950897) +++ src/test/org/apache/hama/matrix/TestSparseMatrix.java (작업 사본) @@ -29,7 +29,6 @@ static final Logger LOG = Logger.getLogger(TestSparseMatrix.class); private int SIZE = 10; private SparseMatrix m1; - private SparseMatrix m2; /** * @throws UnsupportedEncodingException @@ -41,7 +40,6 @@ public void setUp() throws Exception { super.setUp(); m1 = SparseMatrix.random(getConf(), SIZE, SIZE); - m2 = SparseMatrix.random(getConf(), SIZE, SIZE); } public void testMult() throws IOException { @@ -50,9 +48,6 @@ m1.set(0, 0, -8); assertEquals(m1.get(0, 0), -8.0); - SparseMatrix result = m1.mult(m2); - verifyMultResult(m1, m2, result); - SparseVector vector = new SparseVector(); vector.set(0, 3); vector.set(1, -8); @@ -75,32 +70,4 @@ assertTrue(appeared); } - - /** - * Verifying multiplication result - * - * @param m1 - * @param m2 - * @param result - * @throws IOException - */ - private void verifyMultResult(SparseMatrix m1, SparseMatrix m2, - SparseMatrix result) throws IOException { - double[][] c = new double[SIZE][SIZE]; - - for (int i = 0; i < SIZE; i++) { - for (int j = 0; j < SIZE; j++) { - for (int k = 0; k < SIZE; k++) { - c[i][k] += m1.get(i, j) * m2.get(j, k); - } - } - } - - for (int i = 0; i < SIZE; i++) { - for (int j = 0; j < SIZE; j++) { - double gap = (c[i][j] - result.get(i, j)); - assertTrue(gap < 0.000001 && gap > -0.000001); - } - } - } }