Examples of DenseDoubleVector


Examples of de.jungblut.math.dense.DenseDoubleVector

    LogisticRegressionCostFunction cnf = new LogisticRegressionCostFunction(x,
        y, lambda);

    // random init theta
    theta = new DenseDoubleVector(x.getColumnCount() * y.getRowCount());
    for (int i = 0; i < theta.getDimension(); i++) {
      theta.set(i, (random.nextDouble() * 2) - 1d);
    }
    theta = minimizer.minimize(cnf, theta, numIterations, verbose);
  }
View Full Code Here

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

    regression.setMomemtumWeight(0.1);

    int iterations = 100;
    for (int i = 0; i < iterations; ++i) {
      for (int j = 0; j < instances.length; ++j) {
        regression.trainOnline(new DenseDoubleVector(instances[j]));
      }
    }

    double relativeError = 0;
    for (int i = 0; i < instances.length; ++i) {
      DoubleVector test = new DenseDoubleVector(instances[i]);
      double expected = test.get(test.getDimension() - 1);
      test = test.slice(test.getDimension() - 1);
      double actual = regression.getOutput(test).get(0);
      relativeError += Math.abs((expected - actual) / expected);
    }

    relativeError /= instances.length;
View Full Code Here

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

    regression.setMomemtumWeight(0.1);
    regression.setRegularizationWeight(0.05);
    int iterations = 2000;
    for (int i = 0; i < iterations; ++i) {
      for (double[] trainingInstance : trainingInstances) {
        regression.trainOnline(new DenseDoubleVector(trainingInstance));
      }
    }

    double relativeError = 0.0;
    // calculate the error on test instance
    for (double[] testInstance : testInstances) {
      DoubleVector instance = new DenseDoubleVector(testInstance);
      double expected = instance.get(instance.getDimension() - 1);
      instance = instance.slice(instance.getDimension() - 1);
      double actual = regression.getOutput(instance).get(0);
      if (expected == 0) {
        expected = 0.0000001;
      }
      relativeError += Math.abs((expected - actual) / expected);
View Full Code Here

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

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});
    BigDecimal cost = logisticRegressionModel.calculateCostForItem(x, y, 2, theta);
    assertEquals("wrong cost calculation for logistic regression", 6.170109486162941E-5d, cost.doubleValue(), 0.000001);
  }
View Full Code Here

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

  }

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

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

    double[] theta1 = new double[] { 10.010000000474975, 10.050000002374873, 10.01600000075996,
        10.018000000854954, 10.024000001139939, 10.038000001804903, 10.036000001709908 };
    double[] theta2 = new double[] { 13.000000142492354, 25.00000071246177, 14.800000227987766,
        15.400000256486237, 17.20000034198165, 21.400000541470945, 20.800000512972474 };

    DenseDoubleVector theta1Vector = new DenseDoubleVector(theta1);
    DenseDoubleVector theta2Vector = new DenseDoubleVector(theta2);

    DenseDoubleVector x = new DenseDoubleVector(new double[] { 1, 10, 3, 2, 1, 6, 1 });

    BigDecimal res1 = logisticRegressionModel.applyHypothesis(theta1Vector, x);
    BigDecimal res2 = logisticRegressionModel.applyHypothesis(theta2Vector, x);

    assertFalse(res1 + " shouldn't be the same as " + res2, res1.equals(res2));
View Full Code Here

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

public class LinearRegressionModelTest {

  @Test
  public void testCorrectCostCalculation() throws Exception {
    LinearRegressionModel linearRegressionModel = new LinearRegressionModel();
    DoubleVector x = new DenseDoubleVector(new double[]{2, 3, 4});
    double y = 1;
    DoubleVector theta = new DenseDoubleVector(new double[]{1, 1, 1});
    BigDecimal cost = linearRegressionModel.calculateCostForItem(x, y, 2, theta);
    assertEquals("wrong cost calculation for linear regression", BigDecimal.valueOf(16d), cost);
  }
View Full Code Here

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

  }

  @Test
  public void testCorrectHypothesisCalculation() throws Exception {
    LinearRegressionModel linearRegressionModel = new LinearRegressionModel();
    BigDecimal hypothesisValue = linearRegressionModel.applyHypothesis(new DenseDoubleVector(new double[]{1, 1, 1}),
            new DenseDoubleVector(new double[]{2, 3, 4}));
    assertEquals("wrong hypothesis value for linear regression", BigDecimal.valueOf(9d), hypothesisValue);
  }
View Full Code Here

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

    regression.setMomemtumWeight(0.1);
    regression.setRegularizationWeight(0.1);
    int iterations = 1000;
    for (int i = 0; i < iterations; ++i) {
      for (double[] trainingInstance : trainingInstances) {
        regression.trainOnline(new DenseDoubleVector(trainingInstance));
      }
    }

    double errorRate = 0;
    // calculate the error on test instance
    for (double[] testInstance : testInstances) {
      DoubleVector instance = new DenseDoubleVector(testInstance);
      double expected = instance.get(instance.getDimension() - 1);
      DoubleVector features = instance.slice(instance.getDimension() - 1);
      double actual = regression.getOutput(features).get(0);
      if (actual < 0.5 && expected >= 0.5 || actual >= 0.5 && expected < 0.5) {
        ++errorRate;
      }
View Full Code Here

Examples of org.apache.hama.commons.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
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.