List of usage examples for org.apache.mahout.math VectorWritable readVector
public static Vector readVector(DataInput in) throws IOException
From source file:Vectors.java
License:Apache License
public static Vector read(Path path, Configuration conf) throws IOException { FileSystem fs = FileSystem.get(path.toUri(), conf); FSDataInputStream in = fs.open(path); try {// www. jav a 2 s. c o m return VectorWritable.readVector(in); } finally { Closeables.closeQuietly(in); } }
From source file:at.illecker.hama.rootbeer.examples.matrixmultiplication.compositeinput.util.MatrixRowMessage.java
License:Apache License
@Override public void readFields(DataInput in) throws IOException { rowIndex = in.readInt();// ww w .ja va 2s . c o m rowValues = new VectorWritable(VectorWritable.readVector(in)); }
From source file:com.cloudera.knittingboar.sgd.ParallelOnlineLogisticRegression.java
License:Apache License
@Override public void readFields(DataInput in) throws IOException { int version = in.readInt(); if (version == WRITABLE_VERSION) { learningRate = in.readDouble();/*w ww. ja v a2 s.c o m*/ decayFactor = in.readDouble(); stepOffset = in.readInt(); step = in.readInt(); forgettingExponent = in.readDouble(); perTermAnnealingOffset = in.readInt(); numCategories = in.readInt(); beta = MatrixWritable.readMatrix(in); prior = PolymorphicWritable.read(in, PriorFunction.class); updateCounts = VectorWritable.readVector(in); updateSteps = VectorWritable.readVector(in); } else { throw new IOException("Incorrect object version, wanted " + WRITABLE_VERSION + " got " + version); } }
From source file:com.netease.news.classifier.naivebayes.NaiveBayesModel.java
License:Apache License
public static NaiveBayesModel materialize(Path output, Configuration conf) throws IOException { FileSystem fs = output.getFileSystem(conf); Vector weightsPerLabel = null; Vector perLabelThetaNormalizer = null; Vector weightsPerFeature = null; Matrix weightsPerLabelAndFeature;// w w w. ja va 2 s. c o m float alphaI; FSDataInputStream in = fs.open(new Path(output, "naiveBayesModel.bin")); try { alphaI = in.readFloat(); weightsPerFeature = VectorWritable.readVector(in); weightsPerLabel = new DenseVector(VectorWritable.readVector(in)); perLabelThetaNormalizer = new DenseVector(VectorWritable.readVector(in)); weightsPerLabelAndFeature = new SparseRowMatrix(weightsPerLabel.size(), weightsPerFeature.size()); for (int label = 0; label < weightsPerLabelAndFeature.numRows(); label++) { weightsPerLabelAndFeature.assignRow(label, VectorWritable.readVector(in)); } } finally { Closeables.close(in, true); } NaiveBayesModel model = new NaiveBayesModel(weightsPerLabelAndFeature, weightsPerFeature, weightsPerLabel, perLabelThetaNormalizer, alphaI); model.validate(); return model; }
From source file:com.netease.news.classifier.naivebayes.NaiveBayesModel.java
License:Apache License
public static NaiveBayesModel materializeLocal(String modelfile) throws IOException { Vector weightsPerLabel = null; Vector perLabelThetaNormalizer = null; Vector weightsPerFeature = null; Matrix weightsPerLabelAndFeature;/*ww w. j a va 2s. c o m*/ float alphaI; System.out.println(modelfile); ClassLoader loader = NaiveBayesModel.class.getClassLoader(); InputStream sin = loader.getResourceAsStream(modelfile); DataInputStream in = new DataInputStream(sin); try { alphaI = in.readFloat(); weightsPerFeature = VectorWritable.readVector(in); weightsPerLabel = new DenseVector(VectorWritable.readVector(in)); perLabelThetaNormalizer = new DenseVector(VectorWritable.readVector(in)); weightsPerLabelAndFeature = new SparseRowMatrix(weightsPerLabel.size(), weightsPerFeature.size()); for (int label = 0; label < weightsPerLabelAndFeature.numRows(); label++) { weightsPerLabelAndFeature.assignRow(label, VectorWritable.readVector(in)); } } finally { in.close(); } NaiveBayesModel model = new NaiveBayesModel(weightsPerLabelAndFeature, weightsPerFeature, weightsPerLabel, perLabelThetaNormalizer, alphaI); model.validate(); return model; }