Dear Wiki user, You have subscribed to a wiki page or wiki category on "Hama Wiki" for change notification.
The following page has been changed by udanax: http://wiki.apache.org/hama/InterfaceConsiderations ------------------------------------------------------------------------------ - Let's make Hama interfaces with BDD(Behavior Driven Development) style. + {{{ + /** + * Basic vector interface. + */ + public interface VectorInterface { + + /** + * @return size of the vector + */ + public int size(); - == Input/Output Formatters == + /** + * @param index + * @return v(index) + */ + public double get(int index); + + /** + * v(index) = value + * + * @param index + * @param value + */ + public void set(int index, double value); + + /** + * @param v + * @return x = v + */ + public Vector set(Vector v); - {{{ - public void map(ImmutableBytesWritable key, VectorWritable value, - OutputCollector<ImmutableBytesWritable, VectorWritable> output, - Reporter reporter) throws IOException { + /** + * v(index) += value + * + * @param index + * @param value + */ + public void add(int index, double value); + + /** + * @param alpha + * @param v + * @return x = alpha*v + x + */ + public boolean add(double alpha, Vector v); - value.scale(0.5); - output.collect(key, value); + /** + * @param v + * @return x = v + x + */ + public Vector add(Vector v); - } + + /** + * @param v + * @return x dot v + */ + public double dot(Vector v); - public void reduce(ImmutableBytesWritable key, Iterator<VectorWritable> values, - OutputCollector<ImmutableBytesWritable, BatchUpdate> output, - Reporter reporter) throws IOException { + /** + * Computes the given norm of the vector + * + * @param type + * @return norm of the vector + */ + public double norm(Vector.Norm type); + + @Deprecated + public VectorDatum addition(byte[] bs, Vector v2); + + @Deprecated + public double getL1Norm(); + + @Deprecated + public double getL2Norm(); + + @Deprecated + public double getValueAt(int index); + + @Deprecated + public int getDimAt(int index); + + } - BatchUpdate batchObj = new BatchUpdate(key.get()); - VectorDatum vector = values.next(); - for (Map.Entry<byte[], Cell> f : vector.entrySet()) { - batchObj.put(f.getKey(), f.getValue().getValue()); - } - - output.collect(key, batchObj); - } }}} - === Flat file to Matrix Conversion === - - We also need Input/Output Formatters which convert Text File/Sequence File to Matrix. - - For example, - - {{{ - public void map(LongWritable key, Text value, - OutputCollector<ImmutableBytesWritable, VectorWritable> output, Reporter reporter) - throws IOException { - - String line = value.toString(); - - /* Do something */ - - output.collect(rowKey, vector); - } - }}} -
