Package org.apache.hama.ml.math

Examples of org.apache.hama.ml.math.DenseDoubleVector


    VectorWritable key = recordReader.createKey();
    assertNotNull(key);
    DoubleWritable value = recordReader.createValue();
    assertNotNull(value);
    assertTrue(recordReader.next(key, value));
    assertEquals(new DenseDoubleVector(new double[]{2d, 3d, 4d}), key.getVector());
    assertEquals(new DoubleWritable(1d), value);
  }
View Full Code Here


  }

  public static DoubleVector readVector(DataInput in) throws IOException {
    int length = in.readInt();
    DoubleVector vector;
    vector = new DenseDoubleVector(length);
    for (int i = 0; i < length; i++) {
      vector.set(i, in.readDouble());
    }
    return vector;
  }
View Full Code Here

public class LogisticRegressionModelTest {

  @Test
  public void testCorrectCostCalculation() throws Exception {
    LogisticRegressionModel logisticRegressionModel = new LogisticRegressionModel();
    DoubleVector x = new DenseDoubleVector(new double[]{2, 3, 4});
    double y = 1;
    DoubleVector theta = new DenseDoubleVector(new double[]{1, 1, 1});
    Double cost = logisticRegressionModel.calculateCostForItem(x, y, 2, theta);
    assertEquals("wrong cost calculation for logistic regression", Double.valueOf(6.170109486162941E-5), cost);
  }
View Full Code Here

  }

  @Test
  public void testCorrectHypothesisCalculation() throws Exception {
    LogisticRegressionModel logisticRegressionModel = new LogisticRegressionModel();
    Double hypothesisValue = logisticRegressionModel.applyHypothesis(new DenseDoubleVector(new double[]{1, 1, 1}),
            new DenseDoubleVector(new double[]{2, 3, 4}));
    assertEquals("wrong hypothesis value for logistic regression", Double.valueOf(0.9998766054240138), hypothesisValue);
  }
View Full Code Here

  private void updateTheta(double[] thetaDiff) {
    double[] newTheta = new double[theta.getLength()];
    for (int j = 0; j < theta.getLength(); j++) {
      newTheta[j] = theta.get(j) - thetaDiff[j] * alpha;
    }
    theta = new DenseDoubleVector(newTheta);
  }
View Full Code Here

  private void broadcastVector(
      BSPPeer<VectorWritable, DoubleWritable, VectorWritable, DoubleWritable, VectorWritable> peer,
      double[] vector) throws IOException {
    for (String peerName : peer.getAllPeerNames()) {
      if (!peerName.equals(peer.getPeerName())) { // avoid sending to oneself
        peer.send(peerName, new VectorWritable(new DenseDoubleVector(vector)));
      }
    }
  }
View Full Code Here

      BSPPeer<VectorWritable, DoubleWritable, VectorWritable, DoubleWritable, VectorWritable> peer)
      throws IOException, SyncException, InterruptedException {
    if (theta == null) {
      if (master) {
        int size = getXSize(peer);
        theta = new DenseDoubleVector(size, peer.getConfiguration().getInt(
            INITIAL_THETA_VALUES, 1));
        broadcastVector(peer, theta.toArray());
        if (log.isDebugEnabled()) {
          log.debug(new StringBuilder(peer.getPeerName()).append(
              ": sending theta").toString());
View Full Code Here

      String[] split = s.split(" ");
      double[] dar = new double[split.length];
      for (int i = 0; i < split.length; i++) {
        dar[i] = Double.valueOf(split[i]);
      }
      return new DenseDoubleVector(dar);
    }
View Full Code Here

    BufferedReader br = new BufferedReader(
        new InputStreamReader(fs.open(txtIn)));
    String line;
    while ((line = br.readLine()) != null) {
      String[] split = line.split("\t");
      DenseDoubleVector vec = new DenseDoubleVector(split.length);
      for (int j = 0; j < split.length; j++) {
        vec.set(j, Double.parseDouble(split[j]));
      }
      VectorWritable vector = new VectorWritable(vec);
      dataWriter.append(vector, value);
      if (k > i) {
          assert centerWriter != null;
View Full Code Here

      double[] arr = new double[dimension];
      for (int d = 0; d < dimension; d++) {
        arr[d] = r.nextInt(count);
      }
      VectorWritable vector = new VectorWritable(new DenseDoubleVector(arr));
      dataWriter.append(vector, value);
      if (k > i) {
        centerWriter.append(vector, value);
      } else if (k == i) {
        centerWriter.close();
View Full Code Here

TOP

Related Classes of org.apache.hama.ml.math.DenseDoubleVector

Copyright © 2018 www.massapicom. 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.