Package org.jquantlib.math.matrixutilities

Examples of org.jquantlib.math.matrixutilities.Matrix


        // because it is too slow and too inefficient.
        // This method is useful for testing and R&D.
        // Please overload the method within derived classes.
        QL.require(!x.empty() , "can not handle given x here"); // QA:[RG]::verified // TODO: message

        final Matrix tmp = new Matrix(size_, size_);
        for (int i = 0; i < size_; ++i) {
            for (int j = 0; j <= i; ++j) {
                final Var_Helper helper = new Var_Helper(this, i, j);
                final GaussKronrodAdaptive integrator = new GaussKronrodAdaptive(1e-10, 10000);
                for(int k = 0; k<64; ++k) {
                    tmp.set(i, j, tmp.get(i, j)+integrator.op(helper, k*t/64.0,(k+1)*t/64.0));
                }
                tmp.set(j,i, tmp.get(i, j));
            }
        }

        return tmp;
    }
View Full Code Here


            this.j_ = j;
            this.param_ = param;
        }

        public double op(final double t) {
            final Matrix m = param_.diffusion(t);
            return m.constRangeRow(i_).innerProduct(m.constRangeRow(j_));
        }
View Full Code Here

        return sqrtCorrelation_;
    }

    @Override
    public Matrix covariance(final /*@Time*/ double t0, final Array x0, final /*@Time*/ double dt)  {
        final Matrix tmp = stdDeviation(t0, x0, dt);
        return tmp.mul(tmp.transpose());
    }
View Full Code Here

        }
        return results_;
    }

    public Matrix correlation() {
        final Matrix correlation = covariance();
        final Array variances = correlation.diagonal();
        for (int i = 0; i < dimension_; i++) {
            for (int j = 0; j < dimension_; j++)
                if (i == j) {
                    if (variances.get(i) == 0.0) {
                        correlation.set(i, j, 1.0);
                    } else {
                        correlation.set(i, j, correlation.get(i, j) * 1.0 / Math.sqrt(variances.get(i) * variances.get(j)));
                    }
                } else if (variances.get(i) == 0.0 && variances.get(j) == 0) {
                    correlation.set(i, j, 1.0);
                } else if (variances.get(i) == 0.0 || variances.get(j) == 0.0) {
                    correlation.set(i, j, 1.0);
                } else {
                    correlation.set(i, j, correlation.get(i, j) * 1.0 / Math.sqrt(variances.get(i) * variances.get(j)));
                }
        }

        return correlation;
    }
View Full Code Here

        } else {
            dimension_ = dimension;
            stats_ = new Statistics[dimension];
            results_ = new double[dimension];
        }
        quadraticSum_ = new Matrix(dimension_, dimension_);
    }
View Full Code Here

  public TreeLattice2D(final T tree1, final T tree2, final double correlation) {

    super(tree1.timeGrid(), T.branches.getValue() * T.branches.getValue());
    this.tree1 = tree1;
    this.tree2 = tree2;
    this.m = new Matrix(T.branches.getValue(), T.branches.getValue());
    rho = Math.abs(correlation);
    // what happens here?
    if (correlation < 0.0 && T.branches.getValue() == 3) {
      m.set(0, 0, -1.0);
      m.set(0, 1, -4.0);
View Full Code Here

    public void gradient(final Array grad_f, final Array x) {
        // size of target and function to fit vectors
        final Array target = new Array(lsp_.size());
        final Array fct2fit = new Array(lsp_.size());
        // size of gradient matrix
        final Matrix grad_fct2fit  = new Matrix(lsp_.size(), x.size());
        // compute its values
        lsp_.targetValueAndGradient(x, grad_fct2fit, target, fct2fit);
        // do the difference
        final Array diff = target.sub(fct2fit);
        // compute derivative
View Full Code Here

    public double valueAndGradient(final Array grad_f, final Array x) {
        // size of target and function to fit vectors
        final Array target = new Array(lsp_.size());
        final Array fct2fit = new Array(lsp_.size());
        // size of gradient matrix
        final Matrix grad_fct2fit  = new Matrix(lsp_.size (), x.size());
        // compute its values
        lsp_.targetValueAndGradient(x, grad_fct2fit, target, fct2fit);
        // do the difference
        final Array diff = target.sub(fct2fit);
        // compute derivative
View Full Code Here

    public BilinearInterpolationTest() {
        QL.info("::::: " + this.getClass().getSimpleName() + " :::::");
        QL.info("::::: Testing use of interpolations as functors... :::::");

        // fill zz using f(x,y) = x + y;
        zz = new Matrix(x.size(), y.size());
        for (int i = 0; i < x.size(); i++)
            for (int ii = 0; ii < y.size(); ii++) {
                final double value = x.get(i) + y.get(ii);
                zz.set(i, ii, value);
            }
View Full Code Here

            }
        }

        // array multiplied by Matrix

        final Matrix mB = new Matrix(new double[][] {
                { 1.02.00.0 },
                { 2.01.00.0 },
                { 2.01.01.0 },
                { 1.02.00.0 }
        });
        final Array aB2 = new Array(new double[] { 1400.01750.0,   250.0 });

        final Array a2 = clone.mul(mB);

        if (a2 == clone) {
            fail("'mul' must return a new instance");
        }
        if (a2.size() != mB.cols()) {
            fail("'mul' failed");
        }

        for (int i=a2.begin(); i<a2.end(); i++) {
            final double elem = aB2.get(i);
View Full Code Here

TOP

Related Classes of org.jquantlib.math.matrixutilities.Matrix

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.