Package de.jungblut.math.dense

Examples of de.jungblut.math.dense.DenseDoubleVector


    assertEquals(minimizeFunction.get(1), 0, 1E-5);
  }

  @Test
  public void testBoldDriver() {
    DoubleVector start = new DenseDoubleVector(new double[] { 2, -1 });

    CostFunction inlineFunction = getCostFunction();
    GradientDescent gd = GradientDescentBuilder.create(0.8d)
        .breakOnDifference(1e-20).boldDriver().build();
    DoubleVector minimizeFunction = gd.minimize(inlineFunction, start, 1000,
View Full Code Here


        MultilayerPerceptron.SEED, false);

    CostGradientTuple evaluateCost = fnc.evaluateCost(foldMatrices);

    assertEquals(10.62, evaluateCost.getCost(), 1e-2);
    DoubleVector target = new DenseDoubleVector(new double[] { 0.0,
        0.027379415757720366, 0.029102968186221934, -0.38090575317687425,
        -0.27799120250510584, -0.05453365605307239, 0.028442797042677864,
        -0.007547440696105356, -0.020996345540311157, 0.23725599589259425,
        0.16279353745280023, 0.021913996227666748, 0.21119663986488538,
        0.14066157414419367, 0.018971946780403166, 0.027585532151946184,
View Full Code Here

    RBMCostFunction fnc = new RBMCostFunction(test, 0, 1, hiddenUnits,
        new SigmoidActivationFunction(), TrainingType.CPU, 0.1d,
        MultilayerPerceptron.SEED, false);
    CostGradientTuple evaluateCost = fnc.evaluateCost(foldMatrices);
    assertEquals(10.62, evaluateCost.getCost(), 1e-2);
    DoubleVector target = new DenseDoubleVector(new double[] { 0.0,
        0.02692309216175836, 0.028617918716451567, -0.38090575317687425,
        -0.2733580157966874, -0.05362476178552118, 0.028442797042677864,
        -0.0074216500178369334, -0.020646406447972637, 0.23725599589259425,
        0.1600803118285869, 0.021548762957205637, 0.21119663986488538,
        0.13831721457512378, 0.018655747667396447, 0.027585532151946184,
View Full Code Here

  }

  @Test
  public void testMomentumGradientDescent() {

    DoubleVector start = new DenseDoubleVector(new double[] { 2, -1 });

    CostFunction inlineFunction = getCostFunction();
    GradientDescent gd = GradientDescentBuilder.create(0.8d).momentum(0.9d)
        .breakOnDifference(1e-20).build();
    DoubleVector minimizeFunction = gd.minimize(inlineFunction, start, 1000,
View Full Code Here

    CostFunction inlineFunction = new CostFunction() {
      @Override
      public CostGradientTuple evaluateCost(DoubleVector input) {

        double cost = Math.pow(input.get(0), 2) + Math.pow(input.get(1), 2);
        DenseDoubleVector gradient = new DenseDoubleVector(new double[] {
            input.get(0) * 2, input.get(1) * 2 });

        return new CostGradientTuple(cost, gradient);
      }
    };
View Full Code Here

public class ParticleSwarmOptimizationTest {

  @Test
  public void testParticleSwarmOptimization() {

    DoubleVector start = new DenseDoubleVector(new double[] { 22, 15 });

    // our function is f(x,y) = x^2+y^2
    CostFunction inlineFunction = new CostFunction() {
      @Override
      public CostGradientTuple evaluateCost(DoubleVector input) {
View Full Code Here

  }

  @Test
  public void testParticleSwarmOptimizationNonConvex() {

    DoubleVector start = new DenseDoubleVector(new double[] { 100, 30 });

    CostFunction inlineFunction = new CostFunction() {
      @Override
      public CostGradientTuple evaluateCost(DoubleVector input) {
        double x = input.get(0);
View Full Code Here

    List<DoubleVector> outcome = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
      features.add(new SingleEntryDoubleVector(i));
      double[] arr = new double[5];
      arr[i % 5] = 1d;
      outcome.add(new DenseDoubleVector(arr));
    }
    knn.train(features, outcome);

    DoubleVector prediction = knn.predict(new SingleEntryDoubleVector(5));
    assertArrayEquals(new double[] { 1d, 0, 0, 0, 1d }, prediction.toArray());
View Full Code Here

  @Test
  public void testSimpleParable() {
    int startPoint = -5;
    // start at x=-5
    DoubleVector start = new DenseDoubleVector(new double[] { startPoint });

    // our function is f(x) = (4-x)^2+10
    // the derivative is f'(x) = 2x-8
    CostFunction inlineFunction = new CostFunction() {
      @Override
      public CostGradientTuple evaluateCost(DoubleVector input) {

        double cost = Math.pow(4 - input.get(0), 2) + 10;
        DenseDoubleVector gradient = new DenseDoubleVector(
            new double[] { 2 * input.get(0) - 8 });

        return new CostGradientTuple(cost, gradient);
      }
    };
View Full Code Here

  }

  @Test
  public void testNamedSerDe() throws Exception {
    String name = "myName";
    DoubleVector vec = new NamedDoubleVector(name, new DenseDoubleVector(
        new double[] { 1, 2, 3 }));
    DoubleVector check = check(vec);
    assertTrue(check instanceof NamedDoubleVector);
    assertEquals(name, ((NamedDoubleVector) check).getName());
  }
View Full Code Here

TOP

Related Classes of de.jungblut.math.dense.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.