Package org.jquantlib.math.functions

Examples of org.jquantlib.math.functions.Square


    }

    private void testSeveral(final Integrator I) {
        testSingle(I, "f(x) = 1",      new Constant(1.0),               0.0, 1.0, 1.0);
        testSingle(I, "f(x) = x",      new Identity(),                  0.0, 1.0, 0.5);
        testSingle(I, "f(x) = x^2",    new Square(),                    0.0, 1.0, 1.0/3.0);
        testSingle(I, "f(x) = sin(x)", new Sin(),                       0.0, Constants.M_PI, 2.0);
        testSingle(I, "f(x) = cos(x)", new Cos(),                       0.0, Constants.M_PI, 0.0);
        testSingle(I, "f(x) = Gaussian(x)", new NormalDistribution(), -10.0, 10.0, 1.0);

//TODO: http://bugs.jquantlib.org/view.php?id=452
View Full Code Here


    public double variance() {
        final int n = getSampleSize();
        QL.require(n >= 1 , unsufficient_sample_size);

        final List<Ops.DoubleOp> functions = new ArrayList<Ops.DoubleOp>();
        functions.add(new Square());
        functions.add(new Bind2nd(new Minus(), mean()));
        final Expression comp = new Expression(functions);

        // Evaluate the composed function in the specified range (ie. everyWhere).
        final double s2 = expectationValue(comp, new TruePredicate()).getFirst();
View Full Code Here

     */
    public double regret(final double target){
        // average over the range below the target

        final List<Ops.DoubleOp> functions = new ArrayList<Ops.DoubleOp>();
        functions.add(new Square());
        functions.add(new Bind2nd(new Minus(), target));
        final Expression comp = new Expression(functions);
        final Ops.DoublePredicate less = new Bind2ndPredicate(new LessThanPredicate(), target);

        final Pair<Double, Integer> result = statistics.expectationValue(comp, less);
View Full Code Here

        QL.require(N > 1, "sample number <=1, unsufficient");
        // Subtract the mean and square. Repeat on the whole range.
        // Hopefully, the whole thing will be inlined in a single loop.
        /*@Real*/ final double s2 = expectationValue(
            new ComposedFunction(
                new Square(), new Bind2nd(
                    new Minus(), mean())),
                                   new Everywhere()).first();
        return s2*N/(N-1.0);
    }
View Full Code Here

   */
  public /*@Real*/ double regret(final /*@Real*/ double target) /*@ReadOnly*/ {
    // average over the range below the target

    final List<Ops.DoubleOp> functions = new ArrayList<Ops.DoubleOp>();
    functions.add(new Square());
    functions.add(new Bind2nd(new Minus(), target));
    final Expression comp = new Expression(functions);
    final Ops.DoublePredicate less = new Bind2ndPredicate(new LessThanPredicate(), target);

    final Pair<Double, Integer> result = expectationValue(comp, less);
View Full Code Here

    }

    private void testSeveral(final Integrator I) {
        testSingle(I, "f(x) = 1",      new Constant(1.0),               0.0, 1.0, 1.0);
        testSingle(I, "f(x) = x",      new Identity(),                  0.0, 1.0, 0.5);
        testSingle(I, "f(x) = x^2",    new Square(),                    0.0, 1.0, 1.0/3.0);
        testSingle(I, "f(x) = sin(x)", new Sin(),                       0.0, Constants.M_PI, 2.0);
        testSingle(I, "f(x) = cos(x)", new Cos(),                       0.0, Constants.M_PI, 0.0);
        testSingle(I, "f(x) = Gaussian(x)", new NormalDistribution(), -10.0, 10.0, 1.0);

//TODO: http://bugs.jquantlib.org/view.php?id=452
View Full Code Here

  @Test
  public void testPolynomials() {
    checkSingleTabulated(new Constant(1.0), "f(x)=1", 2.0, 1.0e-13);
    checkSingleTabulated(new Identity(), "f(x)=x", 0.0, 1.0e-13);
    checkSingleTabulated(new Square(), "f(x)=x^2", 2.0/3.0, 1.0e-13);
    checkSingleTabulated(new Cube(), "f(x)=x^3", 0.0, 1.0e-13);
    checkSingleTabulated(new Fourth(), "f(x)=x^4", 2.0/5.0, 1.0e-13);
  }
View Full Code Here

  @Test
  public void testPolynomials() {
    checkSingleTabulated(new Constant(1.0), "f(x)=1",   2.0,     1.0e-13);
    checkSingleTabulated(new Identity(),    "f(x)=x",   0.0,     1.0e-13);
    checkSingleTabulated(new Square(),         "f(x)=x^2", 2.0/3.0, 1.0e-13);
    checkSingleTabulated(new Cube(),        "f(x)=x^3", 0.0,     1.0e-13);
    checkSingleTabulated(new Fourth(),      "f(x)=x^4", 2.0/5.0, 1.0e-13);
  }
View Full Code Here

        transform(range(augmented(range(augmented(aA)))), range(augmented(range(augmented(aB)))));
    }

    private void transform(final Array aA, final Array aB) {
        final Array tmp1 = aA.clone();
        Array result = tmp1.transform(new Square());
        if (result != tmp1) {
            fail("'transform' must return this");
        }
        if (!equals(result, aB)) {
            fail("'transform' failed");
        }

        final Array aC = new Array(new double[] { 5.0, 4.0, 9.04.0 });

        final Array tmp2 = aA.clone();
        final int offset = aA.begin();
        result = tmp2.transform(1+offset, 3+offset, new Square());
        if (result != tmp2) {
            fail("'transform' must return this");
        }
        if (!equals(result, aC)) {
            fail("'transform' failed");
View Full Code Here

TOP

Related Classes of org.jquantlib.math.functions.Square

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.