No Format |
---|
/**
* Basic vector interface.
*/
public interface VectorInterface {
/** |
Let's make Hama interfaces with BDD(Behavior Driven Development) style.
Input/Output Formatters
No Format |
---|
public void map(ImmutableBytesWritable key, VectorWritable value, * @return size OutputCollector<ImmutableBytesWritable,of VectorWritable>the output,vector */ public Reporterint reportersize() throws IOException { value.scale(0.5); output.collect(key, value); } public void reduce(ImmutableBytesWritable key, Iterator<VectorWritable> values, OutputCollector<ImmutableBytesWritable, BatchUpdate> output, Reporter reporter) throws IOException { 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,
No Format |
---|
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); }; /** * @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); /** * 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); /** * @param v * @return x = v + x */ public Vector add(Vector v); /** * @param v * @return x dot v */ public double dot(Vector v); /** * 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); } |