Package stallone.api.doubles

Examples of stallone.api.doubles.IDoubleArray


     *
     * @return  R
     */
    @Override
    public IDoubleArray getR() {
        final IDoubleArray X = Doubles.create.array(n, n);

        for (int i = 0; i < n; i++) {

            for (int j = 0; j < n; j++) {

                if (i < j) {
                    X.set(i, j, qrMatrix.get(i, j));
                } else if (i == j) {
                    X.set(i, j, Rdiag[i]);
                } else {
                    X.set(i, j, 0.0d);
                }
            }
        }

        return X;
View Full Code Here


     *
     * @return  Q
     */
    @Override
    public IDoubleArray getQ() {
        final IDoubleArray X = Doubles.create.array(m, n);

        for (int k = n - 1; k >= 0; k--) {

            for (int i = 0; i < m; i++) {
                X.set(i, k, 0.0d);
            }

            X.set(k, k, 1.0d);

            for (int j = k; j < n; j++) {

                if (qrMatrix.get(k, k) != 0.0d) {
                    double s = 0.0;

                    for (int i = k; i < m; i++) {
                        s += qrMatrix.get(i, k) * X.get(i, j);
                    }

                    s = -s / qrMatrix.get(k, k);

                    for (int i = k; i < m; i++) {
                        final double a = s * qrMatrix.get(i, k);
                        X.set(i, j, X.get(i, j) + a);
                    }
                }
            }
        } // end for

View Full Code Here

    {
        if (data.dimension() == count.length)
        {
            for (int i=0; i<data.size(); i++)
            {
                IDoubleArray arr = data.get(i);
                double w = weights.get(i);
                for (int j=0; j<count.length; j++)
                {
                    count[j] += w*arr.get(j);
                }
            }
        }
        else
        {
            if (data.dimension() == 1)
            {
                for (int i=0; i<data.size(); i++)
                {
                    IDoubleArray arr = data.get(i);
                    count[(int)arr.get(0)] += weights.get(i);
                }
            }
            else
                throw new IllegalArgumentException("incompatible dimension of observation");
        }
View Full Code Here

        {
            throw new RuntimeException("No first element .... aborting.");
        }


        IDoubleArray current;

        while(it.hasNext())
        {
            current = it.next();
View Full Code Here

        if (!this.isFullRank()) {
            throw new RuntimeException("Matrix is rank deficient.");
        }

        // Copy right hand side
        final IDoubleArray X = B.copy();

        // Compute Y = transpose(Q)*B
        for (int k = 0; k < n; k++) {

            for (int j = 0; j < b_cols; j++) {
                double s = 0.0;

                for (int i = k; i < m; i++) {
                    s += qrMatrix.get(i, k) * X.get(i, j);
                }

                s = -s / qrMatrix.get(k, k);

                for (int i = k; i < m; i++) {
                    final double a = s * qrMatrix.get(i, k);
                    X.set(i, j, X.get(i, j) + a);
                }
            }
        }

        // Solve R*X = Y;
        for (int k = n - 1; k >= 0; k--) {

            for (int j = 0; j < b_cols; j++) {
                X.set(k, j, X.get(k, j) / Rdiag[k]);
            }

            for (int i = 0; i < k; i++) {

                for (int j = 0; j < b_cols; j++) {
                    final double a = X.get(k, j) * qrMatrix.get(i, k);
                    X.set(i, j, X.get(i, j) - a);
                }
            }
        }

        return X.viewBlock(0, 0, n, b_cols);
    }
View Full Code Here

     */
    @Override
    final public void computeTransform()
    {
        // PCA
        IDoubleArray Cov = moments.getCov();
        IEigenvalueDecomposition evd = alg.evd(Cov);
        IDoubleArray evalPCA = evd.getEvalNorm();
        IDoubleArray evecPCA = evd.getRightEigenvectorMatrix().viewReal();
       
        // normalize principal components
        IDoubleArray S = doublesNew.array(evalPCA.size());
        for (int i=0; i<S.size(); i++)
            S.set(i, 1.0*Math.sqrt(evalPCA.get(i)));
        // normalize weights by dividing by the standard deviation of the pcs
        IDoubleArray evecPCAscaled = alg.product(evecPCA, doublesNew.diag(S));

        // time-lagged covariance matrix
        this.CovTauSym = moments.getCovLagged();
        // symmetrize
        CovTauSym = alg.addWeightedToNew(0.5, CovTauSym, 0.5, alg.transposeToNew(CovTauSym)); // symmetrize

        // TICA weights
        IDoubleArray pcCovTau = alg.product(alg.product(alg.transposeToNew(evecPCAscaled), CovTauSym), evecPCAscaled);

        IEigenvalueDecomposition evd2 = alg.evd(pcCovTau);
        this.evalTICA = evd2.getEvalNorm();
        this.evecTICA = alg.product(evecPCAscaled, evd2.getRightEigenvectorMatrix().viewReal());       
    }
View Full Code Here

     * @param x
     */
    @Override
    public IDoubleArray transform(IDoubleArray x)
    {
        IDoubleArray out = doublesNew.array(dimOut);
        transform(x, out);
        return out;
    }   
View Full Code Here

        {
            in = doublesNew.array(in.getArray());
        }

        // subtract mean
        IDoubleArray x = alg.subtract(in, moments.getMean());
       
        // make a row
        if (x.rows() > 1)
            x = alg.transposeToNew(x);
       
        IDoubleArray y = alg.product(x, evecTICA);
        int d = Math.min(in.size(),out.size());
        for (int i=0; i<d; i++)
            out.set(i, y.get(i));
    }
View Full Code Here

    }

    @Override
    public IDoubleArray assignFuzzy(IDoubleArray p)
    {
        IDoubleArray res = Doubles.create.array(centers.size());
        int s = assign(p);
        if (s != -1)
            res.set(s, 1);
        return(res);
    }
View Full Code Here

        // Using the function: 1/4 x^4 - 1/2 x^2 + 1/2 y^2
        IEnergyModel pot = potNew.multivariateFromExpression(new String[]{"x","y"},
                "1/4 x^4 - 1/2 x^2 + 1/2 y^2", // function expression
                "x^3-x", "y"); // derivatives
        // integrator
        IDoubleArray masses = doublesNew.arrayFrom(1.0, 1.0);
        double dt = 0.1, gamma = 1, kT = 0.2;
        IIntegratorThermostatted langevin = dynNew.langevinLeapFrog(pot, masses, 0.1, gamma, kT);
        // run
        IDoubleArray x0 = doublesNew.arrayFrom(0,0);
        int nsteps = 100000, nsave = 10;
        IDataSequence seq = dyn.run(x0, langevin, nsteps, nsave);
       
        // TICA
        int lag = 1;
        TICA tica = new TICA(lag);
        tica.addData(seq);
        tica.computeTransform();
       
        System.out.println("mean: \t"+doubles.toString(tica.getMeanVector(), "\t"));
        System.out.println("cov: \t"+doubles.toString(tica.getCovarianceMatrix(), "\t", "\n"));
        System.out.println("covTau: \t"+doubles.toString(tica.getCovarianceMatrixLagged(), "\t", "\n"));
        System.out.println();
        System.out.println("eval: \t"+doubles.toString(tica.getEigenvalues(), "\t"));
        System.out.println("evec1: \t"+doubles.toString(tica.getEigenvector(0), "\t"));
        System.out.println("evec2: \t"+doubles.toString(tica.getEigenvector(1), "\t"));
       
        tica.setDimension(1);
        IDoubleArray y1 = tica.transform(doublesNew.arrayFrom(2,2));
        System.out.println("y1 = \t"+doubles.toString(y1, "\t"));

        IDoubleArray y2 = tica.transform(doublesNew.arrayFrom(4,4));
        System.out.println("y2 = \t"+doubles.toString(y2, "\t"));
    }
View Full Code Here

TOP

Related Classes of stallone.api.doubles.IDoubleArray

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.