Package stallone.api.doubles

Examples of stallone.api.doubles.IDoubleArray


            if (arg.hasCommand("lag"))
            {
                lag = arg.getIntArgument("lag");
            }
           
            IDoubleArray C = null;
            if (arg.hasCommand("sampleLag"))
            {
                C = msm.estimateCstepping(dtrajs, lag);
            }
            else
            {
                C = msm.estimateC(dtrajs, lag);
            }
           
            if (arg.hasCommand("countrev"))
            {
                C = alg.addWeightedToNew(0.5, C, 0.5, alg.transposeToNew(C));
            }

            if (arg.hasCommand("subset"))
            {
                IIntArray S = intseq.loadIntSequence(arg.getArgument("subset"));
                C = C.view(S.getArray(), S.getArray());
            }

            doubles.writeMatrixSparse(C, System.out);
        }
        if (arg.hasCommand("submatrix"))
        {
            IDoubleArray C = doublesNew.fromFile(arg.getArgument("submatrix", 0));
            IIntArray S = intseq.loadIntSequence(arg.getArgument("submatrix", 1));
            C = C.view(S.getArray(), S.getArray());
            doubles.writeMatrixSparse(C, System.out);
        }
        if (arg.hasCommand("populousSet"))
        {
            IDoubleArray C = doublesNew.fromFile(arg.getArgument("populousSet", 0));
            int n = C.rows();
            double minCount = arg.getIntArgument("populousSet",1);
            double minIn = arg.getIntArgument("populousSet",2);
            double minOut = arg.getIntArgument("populousSet",3);

            IDoubleArray counts = alg.rowSums(C);
            IDoubleArray ins = alg.columnSums(C);
            IDoubleArray outs = alg.rowSums(C);
            for (int i=0; i<n; i++)
            {
                ins.set(i,i, ins.get(i,i)-C.get(i,i));
                outs.set(i,i, outs.get(i,i)-C.get(i,i));
            }

            IIntArray iC = doubles.largeValueIndexes(counts, minCount);
            IIntArray iI = doubles.largeValueIndexes(ins, minIn);
            IIntArray iO = doubles.largeValueIndexes(outs, minOut);
View Full Code Here


        if (cmd.singlePointEstimate)
        {
            IHMM pmm = hmm.pmm(cmd.discreteTrajectories, cmd.nhidden, cmd.tau, cmd.timeshift, cmd.hmmNIter, cmd.hmmDecTol, null, null);
           
            IDoubleArray hmmTC = pmm.getTransitionMatrix();
            io.writeString(cmd.outdir+"/hmmTc.dat", doubles.toString(hmmTC,"\t","\n"));
            IDoubleArray hmmChi = pmm.getOutputParameters();
            io.writeString(cmd.outdir+"/hmmChi.dat", doubles.toString(hmmChi,"\t","\n"));
        }
        else if (cmd.hmmTimescalesEstimate)
        {
            IIntList lagtimes = intsNew.list(0);
            lagtimes.append(cmd.taumin);
            for (double tau = cmd.taumin; tau <= cmd.taumax; tau *= cmd.taumult)
            {
                int lag = (int)tau;
                if (lag != lagtimes.get(lagtimes.size()-1))
                    lagtimes.append(lag);
            }

            PrintStream itsout = new PrintStream(cmd.outdir+"/hmm-its.dat");
           
            IDoubleArray lastTC = cmd.init_T;
            IDoubleArray lastChi = cmd.init_Chi;
           
            for (int i=0; i<lagtimes.size(); i++)
            {
                //set lag and timeshift
                int lag = lagtimes.get(i);
                System.out.println("\ntau = "+lag+"\n");

                // in direct mode, erase the results from last lag. Otherwise use as initialization.
                if (cmd.direct)
                {
                    lastTC = null;
                    lastChi = null;
                }

                System.out.println("Hidden state: "+cmd.nhidden);
                IHMM pmm = hmm.pmm(cmd.discreteTrajectories, cmd.nhidden, lag, cmd.timeshift, cmd.hmmNIter, cmd.hmmDecTol, lastTC, lastChi);
               
                // remember estimation results and use them as a next initializer.
                lastTC = pmm.getTransitionMatrix();
                lastChi = pmm.getOutputParameters();
                //double[] logL = cmd.ninja.getHMMLikelihoodHistory();
                double lastLogL = pmm.getLogLikelihood();

                // output timescales
                IDoubleArray hmmTimescales = msm.timescales(lastTC, lag);
                itsout.println(lag+"\t"+lastLogL+"\t"+doubles.toString(hmmTimescales,""," "));
               
                // output hidden matrix
                PrintStream TCout = new PrintStream(cmd.outdir+"/hmm-TC-lag"+lag+".dat");
                TCout.print(doubles.toString(lastTC,"\t","\n"));
View Full Code Here

        }
        Arguments arg = new Arguments(args);

        if (arg.hasCommand("cg"))
        {
            IDoubleArray f = doublesNew.fromFile(arg.getArgument("i", 0));
            int[][] I = io.readIntMatrix(arg.getArgument("i", 1));
            IDoubleArray F = doublesNew.matrix(I.length, I.length);

            // sum up fluxes
            for (int I1 = 0; I1 < I.length; I1++)
            {
                for (int I2 = 0; I2 < I.length; I2++)
                {
                    for (int i = 0; i < I[I1].length; i++)
                    {
                        for (int j = 0; j < I[I2].length; j++)
                        {
                            F.set(I1, I2, F.get(I1, I2) + f.get(I[I1][i], I[I2][j]));
                        }
                    }
                }
            }

            // net flux
            IDoubleArray Fnet = doublesNew.matrix(I.length, I.length);
            for (int i = 0; i < Fnet.rows(); i++)
            {
                Fnet.set(i, i, 0);
                for (int j = i + 1; j < Fnet.columns(); j++)
                {
                    if (F.get(i, j) > F.get(j, i))
                    {
                        Fnet.set(i, j, F.get(i, j) - F.get(j, i));
                    }
                    else
                    {
                        Fnet.set(j, i, F.get(j, i) - F.get(i, j));
                    }
                }
            }

            if (arg.hasCommand("oflux"))
            {
                doubles.writeMatrixSparse(F, new PrintStream(arg.getArgument("oflux")));
            }
            if (arg.hasCommand("onetflux"))
            {
                doubles.writeMatrixSparse(Fnet, new PrintStream(arg.getArgument("onetflux")));
            }
        }
        if (arg.hasCommand("pathways"))
        {
            IDoubleArray F = doublesNew.fromFile(arg.getArgument("pathways", 0));
            double[] Q = io.readDoubleColumn(arg.getArgument("pathways", 1), 0);
            int[] A = str.toIntArray(arg.getArgument("pathways", 2));
            int[] B = str.toIntArray(arg.getArgument("pathways", 3));

            PathwayDecomposition decomp = new PathwayDecomposition(F, Q, A, B);
View Full Code Here

                {
                    continue;
                }

                // get actual distance
                IDoubleArray c1 = coordinates.viewRow(i);
                IDoubleArray c2 = coordinates.viewRow(j);
                double d = metric.distance(c1, c2);

                // energy
                double e = charges.get(i) * charges.get(j) / (4*Math.PI*epsilon0*epsilonr*d);
                this.energy += e;
//System.out.println(" c ["+i+","+j+"]\t"+e);

                // gradient
                double fm = -charges.get(i) * charges.get(j) / (4*Math.PI*epsilon0*epsilonr*d*d);

                IDoubleArray mg1 = metric.gradientX(c1, c2);
                for (int dim = 0; dim < 3; dim++)
                {
                    this.gradient.set(i, dim, this.gradient.get(i, dim) + fm * mg1.get(dim));
                }

                IDoubleArray mg2 = metric.gradientY(c1, c2);
                for (int dim = 0; dim < 3; dim++)
                {
                    this.gradient.set(j, dim, this.gradient.get(j, dim) + fm * mg2.get(dim));
                }
            }
        }

        return (true);
View Full Code Here

        {
            boolean success = models.get(i).calculate();
            if (!success)
                return(false);
            this.energy += models.get(i).getEnergy();
            IDoubleArray gradother = models.get(i).getGradient();
            for (int j=0; j<grad.size(); j++)
            {
                this.grad.set(j, this.grad.get(j) + gradother.get(j));
            }
        }

        return(true);
    }
View Full Code Here

                {
                    continue;
                }

                // get actual distance
                IDoubleArray c1 = coordinates.viewRow(i);
                IDoubleArray c2 = coordinates.viewRow(j);
                double d = metric.distance(c1, c2);

                // effective epsilon
                double eps2 = 2 * eps.get(i) * eps.get(j) / (eps.get(i) + eps.get(j));

                // effective distance
                double r2 = 2*Math.sqrt(r.get(i) * r.get(j));

                // energy
                double r2d = r2 / d;
                double e = 4 * eps2 * (Math.pow(r2d, 12) - Math.pow(r2d, 6));
                this.energy += e;
System.out.println(" vdw ["+i+","+j+"]\t"+e+"\t at d = "+d+" \t with eps = "+eps2+"\t r = "+r2);

                // gradient
                double fm = 4 * eps2 * (6 * Math.pow(r2d, 6) / d - 12 * Math.pow(r2d, 12) / d);

                IDoubleArray mg1 = metric.gradientX(c1, c2);
                for (int dim = 0; dim < 3; dim++)
                {
                    this.gradient.set(i, dim, this.gradient.get(i, dim) + fm * mg1.get(dim));
                }

                IDoubleArray mg2 = metric.gradientY(c1, c2);
                for (int dim = 0; dim < 3; dim++)
                {
                    this.gradient.set(j, dim, this.gradient.get(j, dim) + fm * mg2.get(dim));
                }
            }
        }

        return (true);
View Full Code Here

        // go through all bonds
        for (int i = 0; i < bonds.size(); i++)
        {
            // get actual distance
            int[] b = bonds.get(i);
            IDoubleArray c1 = coordinates.viewRow(b[0]);
            IDoubleArray c2 = coordinates.viewRow(b[1]);
            double d = metric.distance(c1, c2);

            // energy
            double e = 0.5 * k.get(i) * (d - d0.get(i)) * (d - d0.get(i));
            this.energy += e;
System.out.println(" b ["+b[0]+","+b[1]+"]\t"+e);

            // gradient
            double fm = k.get(i) * (d - d0.get(i));

            IDoubleArray mg1 = metric.gradientX(c1, c2);
            for (int dim = 0; dim < 3; dim++)
            {
                this.gradient.set(b[0], dim, this.gradient.get(b[0], dim) + fm * mg1.get(dim));
            }

            IDoubleArray mg2 = metric.gradientY(c1, c2);
            for (int dim = 0; dim < 3; dim++)
            {
                this.gradient.set(b[1], dim, this.gradient.get(b[1], dim) + fm * mg2.get(dim));
            }
        }

        return(true);
    }
View Full Code Here

    }

    @Override
    public IDoubleArray copy()
    {
        IDoubleArray res = doublesNew.matrix(rows,cols);
        res.copyFrom(this);
        return(res);
    }
View Full Code Here

    }

    @Override
    public IDoubleArray copy()
    {
        IDoubleArray res = doublesNew.array(size);
        res.copyFrom(this);
        return res;
    }
View Full Code Here

        da.set(0,1,0.1);
        da.set(1,0,0.1);
        da.set(1,1,0.9);
   
       
        IDoubleArray da2 = alg.product(da, da);
        System.out.println(da2);
    }
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.