Package stallone.api.algebra

Examples of stallone.api.algebra.IEigenvalueDecomposition


     */
    @Override
    final public void computeTransform()
    {
        IDoubleArray Cov = moments.getCov();
        IEigenvalueDecomposition evd = alg.evd(Cov);
        this.eval = evd.getEvalNorm();
        this.evec = evd.getRightEigenvectorMatrix().viewReal();
    }
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

            IDoubleArray TC = doublesNew.fromFile(cmd.inDir+"/hmm-TC-lag"+tau+".dat");           
            IDoubleArray Pi = doublesNew.diag(msm.stationaryDistribution(TC));
            IDoubleArray Chi = doublesNew.fromFile(cmd.inDir+"/hmm-Chi-lag"+tau+".dat");           

            // diagonalize TC
            IEigenvalueDecomposition evd = alg.evd(TC);
            IDoubleArray R = evd.R().viewReal();
            IDoubleArray L = alg.inverse(R);

            // pi
            IDoubleArray Lbig = alg.product(L, alg.transposeToNew(Chi));
            IDoubleArray pibig = Lbig.viewRow(0);
View Full Code Here

            doubles.writeMatrixSparse(T, System.out);
        }
        if (arg.hasCommand("eigenvalues"))
        {
            IDoubleArray T = doublesNew.fromFile(arg.getArgument("eigenvalues"));
            IEigenvalueDecomposition evd = alg.evd(T);

            if (arg.hasCommand("norm"))
            {
                doubles.print(evd.getEvalNorm(), "\n");
            }
            else if (arg.hasCommand("complex"))
            {
                IComplexArray eval = evd.getEval();
                for (int i=0; i<eval.size(); i++)
                    System.out.println(eval.getRe(i)+" + "+eval.getIm(i)+"i");
            }
            else
            {
                doubles.print(evd.getEvalRe(), "\n");
            }
        }
        if (arg.hasCommand("eigenvectors"))
        {
            IDoubleArray T = doublesNew.fromFile(arg.getArgument("eigenvectors"));
View Full Code Here

    public IDoubleArray timescales(IDoubleArray T, double tau)
    {
        if (!this.isTransitionMatrix(T))
            throw(new IllegalArgumentException("Trying to calculate timescales of a matrix that is not a transition matrix"));

        IEigenvalueDecomposition evd = Algebra.util.evd(T);
        IDoubleArray ev = evd.getEvalNorm();

        IDoubleArray timescales = Doubles.create.array(ev.size()-1);
        for (int i=0; i<timescales.size(); i++)
            timescales.set(i, -tau/Math.log(ev.get(i+1)));
View Full Code Here

        }

        // eigenvalues and timescales
        if (T != null)
        {
            IEigenvalueDecomposition evd = Algebra.util.evd(T);
            IDoubleArray evalT = evd.getEval();
            timescales = Doubles.create.array(evalT.size());
            for (int i=0; i<timescales.size(); i++)
                timescales.set(i, -1/Math.log(Math.abs(evalT.get(i))));

            R = evd.getRightEigenvectorMatrix();
        }
        else
        {
            IEigenvalueDecomposition evd = Algebra.util.evd(K);
            IDoubleArray evalK = evd.getEval();
            timescales = Doubles.create.array(evalK.size());
            for (int i=0; i<timescales.size(); i++)
                timescales.set(i, -1/Math.abs(evalK.get(i)));

            R = evd.getRightEigenvectorMatrix();
        }

        // normalize eigenvectors
        for (int i=0; i<R.columns(); i++)
        {
View Full Code Here

            {0.2, 0.75, 0.05, 0   },
            {, 0.05, 0.75, 0.2},
            {, 0   , 0.2 , 0.8 }});
        IDoubleArray ts1 = msm.timescales(T, 1);

        IEigenvalueDecomposition evd = alg.evd(T);
        IDoubleArray Lambda = evd.getDiagonalMatrix();
        System.out.println("old timescales: "+ts1);
        System.out.println("Lambda = \n"+Lambda+"\n");

        int nhidden = 2;
        PCCA pcca = msmNew.createPCCA(T, nhidden);
        IDoubleArray R = evd.getRightEigenvectorMatrix().viewReal();
        IDoubleArray Rsub = R.viewBlock(0, 0, T.rows(), nhidden);
        pcca.setEigenvectors(Rsub);
        pcca.perform();
        IDoubleArray M = pcca.getFuzzy();
       
        System.out.println("M\n"+M);

        IDoubleArray pi = msm.stationaryDistribution(T);
        IDoubleArray Pi = doublesNew.diag(pi);
        IDoubleArray piC = alg.product(alg.transposeToNew(M),pi);
        IDoubleArray PiC = doublesNew.diag(piC);
       
        System.out.println("Pi = \n"+Pi+"\n");
        System.out.println("PiC = \n"+PiC+"\n");
       
        IDoubleArray Res = alg.transposeToNew(M);
        IDoubleArray Int = alg.product(alg.product(Pi,M),alg.inverse(PiC));

        System.out.println("R = \n"+Res+"\n");
        System.out.println("I = \n"+Int+"\n");
       
        IDoubleArray RItinv = alg.transposeToNew(alg.inverse(alg.product(Res,Int)));
        IDoubleArray IntT = alg.transposeToNew(Int);
        IDoubleArray ResT = alg.transposeToNew(Res);
       
        IDoubleArray TC = alg.product(alg.product(alg.product(RItinv,IntT),T),ResT);
        System.out.println("TC = \n"+TC+"\n");

        IEigenvalueDecomposition evdC = alg.evd(TC);
        IDoubleArray LambdaC = evdC.getDiagonalMatrix();
        System.out.println("LambdaC = \n"+LambdaC+"\n");
       
        System.exit(0);
        /*
        IDoubleArray pi = msm.stationaryDistribution(T);
View Full Code Here

TOP

Related Classes of stallone.api.algebra.IEigenvalueDecomposition

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.