Examples of MatrixWritable


Examples of de.jungblut.writable.MatrixWritable

   * Deserializes a new MultinomialNaiveBayesClassifier from the given input
   * stream. Note that "in" will not be closed by this method.
   */
  public static MultinomialNaiveBayes deserialize(DataInput in)
      throws IOException {
    MatrixWritable matrixWritable = new MatrixWritable();
    matrixWritable.readFields(in);
    DoubleVector classProbability = VectorWritable.readVector(in);

    return new MultinomialNaiveBayes(matrixWritable.getMatrix(),
        classProbability);
  }
View Full Code Here

Examples of de.jungblut.writable.MatrixWritable

        classProbability);
  }

  public static void serialize(MultinomialNaiveBayes model, DataOutput out)
      throws IOException {
    new MatrixWritable(model.probabilityMatrix).write(out);
    VectorWritable.writeVector(model.classPriorProbability, out);
  }
View Full Code Here

Examples of de.jungblut.writable.MatrixWritable

    for (int layer : model.layerSizes) {
      out.writeInt(layer);
    }

    for (DoubleMatrix mat : model.weights) {
      new MatrixWritable(mat).write(out);
    }

    out.writeUTF(model.activationFunction.getClass().getName());

  }
View Full Code Here

Examples of de.jungblut.writable.MatrixWritable

      sizes[i] = in.readInt();
    }

    DoubleMatrix[] array = new DoubleMatrix[layers];
    for (int i = 0; i < layers; i++) {
      MatrixWritable mv = new MatrixWritable();
      mv.readFields(in);
      array[i] = mv.getMatrix();
    }
    ActivationFunction func = null;
    try {
      func = (ActivationFunction) Class.forName(in.readUTF()).newInstance();
    } catch (InstantiationException | IllegalAccessException
View Full Code Here

Examples of de.jungblut.writable.MatrixWritable

      layers[i] = in.readInt();
    }

    WeightMatrix[] weights = new WeightMatrix[numLayers - 1];
    for (int i = 0; i < weights.length; i++) {
      MatrixWritable wm = new MatrixWritable();
      wm.readFields(in);
      weights[i] = new WeightMatrix(wm.getMatrix());
    }

    ActivationFunction[] funcs = new ActivationFunction[numLayers];
    for (int i = 0; i < numLayers; i++) {
      try {
View Full Code Here

Examples of de.jungblut.writable.MatrixWritable

      out.writeInt(l);
    }
    // write the weight matrices
    for (WeightMatrix mat : model.weights) {
      DoubleMatrix weights = mat.getWeights();
      new MatrixWritable(weights).write(out);
    }
    // then write the activation classes
    for (ActivationFunction func : model.activations) {
      out.writeUTF(func.getClass().getName());
    }
View Full Code Here

Examples of org.apache.hama.commons.io.MatrixWritable

    // write the number of neurons for each layer
    for (int i = 0; i < this.numberOfLayers; ++i) {
      output.writeInt(this.layerSizeArray[i]);
    }
    for (int i = 0; i < numberOfLayers - 1; ++i) {
      MatrixWritable matrixWritable = new MatrixWritable(this.weightMatrice[i]);
      matrixWritable.write(output);
    }

    // serialize the feature transformer
    Class<? extends FeatureTransformer> featureTransformerCls = this.featureTransformer
        .getClass();
View Full Code Here

Examples of org.apache.hama.commons.io.MatrixWritable

      BSPPeer<Text, VectorWritable, Text, VectorWritable, MapWritable> peer,
      DoubleMatrix featureMatrix, IntWritable msgFeatureMatrix, boolean broadcast)
          throws IOException, SyncException, InterruptedException {
    // send to master peer
    MapWritable msg = new MapWritable();
    MatrixWritable mtx = new MatrixWritable(featureMatrix);
    msg.put(msgFeatureMatrix, mtx);
    String master = peer.getPeerName(peer.getNumPeers()/2);
    peer.send(master, msg);
    peer.sync();

    // normalize
    DoubleMatrix res = null;
    if (peer.getPeerName().equals(master)) {
      res = new DenseDoubleMatrix(featureMatrix.getRowCount(),
                                  featureMatrix.getColumnCount(), 0);
      int incomingMsgCount = 0;
      while ( (msg = peer.getCurrentMessage()) != null) {
        MatrixWritable tmp = (MatrixWritable) msg.get(msgFeatureMatrix);
        res.add(tmp.getMatrix());
        incomingMsgCount++;
      }
      res.divide(incomingMsgCount);
    }

    if (broadcast) {
      if (peer.getPeerName().equals(master)) {
        // broadcast to all
        msg = new MapWritable();
        msg.put(msgFeatureMatrix, new MatrixWritable(res));
        // send to all
        for (String peerName : peer.getAllPeerNames()) {
          peer.send(peerName, msg);
        }
      }
View Full Code Here

Examples of org.apache.hama.commons.io.MatrixWritable

    // write the number of neurons for each layer
    for (int i = 0; i < this.numberOfLayers; ++i) {
      output.writeInt(this.layerSizeArray[i]);
    }
    for (int i = 0; i < numberOfLayers - 1; ++i) {
      MatrixWritable matrixWritable = new MatrixWritable(this.weightMatrice[i]);
      matrixWritable.write(output);
    }

    // serialize the feature transformer
    Class<? extends FeatureTransformer> featureTransformerCls = this.featureTransformer
        .getClass();
View Full Code Here

Examples of org.apache.hama.ml.writable.MatrixWritable

    // write the number of neurons for each layer
    for (int i = 0; i < this.numberOfLayers; ++i) {
      output.writeInt(this.layerSizeArray[i]);
    }
    for (int i = 0; i < numberOfLayers - 1; ++i) {
      MatrixWritable matrixWritable = new MatrixWritable(this.weightMatrice[i]);
      matrixWritable.write(output);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.