Package stallone.api.doubles

Examples of stallone.api.doubles.IDoubleArray


    }

    @Override
    public IDoubleArray propagate(double t)
    {
        IDoubleArray res = null;

        if (reversible)
        {
            IDoubleArray evalPower = Doubles.create.array(evalReal.size());
            for (int i=0; i<evalPower.size(); i++)
                evalPower.set(i, Math.pow(evalReal.get(i),t));

            IDoubleArray D = Doubles.create.diag(evalPower);
            res = Algebra.util.product(R, Algebra.util.product(D, L));
        }
        else
        {
            throw(new IllegalArgumentException("Trying to use a nonreversible rate matrix propagator. This is not implemented yet."));
View Full Code Here


    }

    @Override
    public IDoubleArray estimate(IDataSequence data)
    {
        IDoubleArray par = Doubles.create.array(2);

        // mean
        double mean = 0;
        for (IDoubleArray a : data)
            mean += a.get(0);
        mean /= (double)data.size();

        // var
        double var = 0;
        for (IDoubleArray a : data)
        {
            double d = a.get(0) - mean;
            var += d*d;
        }
        var /= (double)(data.size()-1);

        par.set(0, mean);
        par.set(1, var);

        return par;
    }
View Full Code Here

    }

    @Override
    public IDoubleArray estimate(IDataSequence data, IDoubleArray weights)
    {
        IDoubleArray par = Doubles.create.array(2);
        double W = 0;

        // mean
        double mean = 0;
        for (int i=0; i<data.size(); i++)
        {
            mean += weights.get(i) * data.get(i).get(0);
            W += weights.get(i);
        }
        mean /= W;

        // var
        double var = 0;
        for (int i=0; i<data.size(); i++)
        {
            double d = data.get(i).get(0) - mean;
            var += weights.get(i) * d*d;
        }
        var /= W-1;

        par.set(0, mean);
        par.set(1, var);

        return par;
    }
View Full Code Here

    }

    @Override
    public IDoubleArray propagate(double t)
    {
        IDoubleArray res = null;

        if (reversible)
        {
            IDoubleArray evalPower = Doubles.create.array(evalReal.size());
            for (int i=0; i<evalPower.size(); i++)
                evalPower.set(i, Math.pow(evalReal.get(i),t));

            IDoubleArray D = Doubles.create.diag(evalPower);
            res = Algebra.util.product(R, Algebra.util.product(D, L));
        }
        else
        {
            if (((int)t - t) != 0)
View Full Code Here

        // select Cluster centers from data
        int i = 0;
        for (Iterator<IDoubleArray> it = data.iterator(); it.hasNext();)
        {
            IDoubleArray current = it.next();

            // do we have this index?
            if (Arrays.binarySearch(sortedIndexes, i) >= 0)
            {
                clusterCenters.add(current.copy());
            }


            this.assignments.add(-1);
View Full Code Here

        // make the assignments
        //for (int i = 0; i < n; i++)
        int i = 0;
        for (Iterator<IDoubleArray> it = data.iterator(); it.hasNext();)
        {
            IDoubleArray current = it.next();

            // find the closest center
            int closest = 0;
            double closestDistance = metric.distance(current, clusterCenters.get(0));
View Full Code Here

    private void updateCenters()
    {
        // set all cluster centers to zero
        for (int i = 0; i < numberOfClusters; i++)
        {
            IDoubleArray clusterCenter = clusterCenters.get(i);
            clusterCenter.zero();
        }

        // sum up all data points per cluster they are assigned to
        double[] assignmentWeight = new double[this.numberOfClusters];

        int j = 0;
        for (Iterator<IDoubleArray> it = data.iterator(); it.hasNext();)
        //for (int j = 0; j < data.size(); j++)
        {

            IDoubleArray currentVector = it.next();

            int assignedTo = assignments.get(j);
            assignmentWeight[assignedTo] += 1;

            IDoubleArray clusterCenter = clusterCenters.get(assignedTo);
            Algebra.util.addTo(clusterCenter, currentVector);

            j++;
        }
View Full Code Here

    }

    //@Override
    public IDoubleArray getMembership(int i)
    {
        IDoubleArray membership = Doubles.create.array(numberOfClusters);
        membership.set(i, 1.0d);

        return membership;
    }
View Full Code Here

    {
        // test input!
        //System.out.println("Splitting state "+state+"\t to probability "+p1+"\tk1 "+k1+"\tk2 "+k2);

        // compute correlation matrix
        IDoubleArray pi_old = msm.stationaryDistribution(T_old);
        IDoubleArray Pi_old = doublesNew.diag(pi_old);
        IDoubleArray C_old = alg.product(Pi_old, T_old);
        // useful stuff
        int n = T_old.rows();
        double pi_state_old = pi_old.get(state);

        //System.out.println("C_old = \n"+C_old);
        //System.out.println();
        //System.out.println("pi_old = \n"+pi_old);

        // fill unaffected states
        IDoubleArray C_split = doublesNew.matrix(n+1,n+1);
        IDoubleArray pi_split = doublesNew.array(n+1);
        for (int i=0; i<n; i++)
            for (int j=0; j<n; j++)
                if (i != state && j != state)
                {
                    C_split.set(i,j, C_old.get(i,j));
                    pi_split.set(i, pi_old.get(i));
                }

        // compute stationary probabilities of the new states
        double pi_split_1 = p1 * pi_old.get(state);
        double pi_split_2 = pi_old.get(state) - pi_split_1;
        pi_split.set(state, pi_split_1);
        pi_split.set(n, pi_split_2);

        //System.out.println("pi_split_1 = "+pi_split_1);
        //System.out.println("pi_split_2 = "+pi_split_2);

        // compute diagonal elements
        double d1 = pi_split_1 * Math.exp(-k1);
        double d2 = pi_split_2 * Math.exp(-k2);
        C_split.set(state,state,d1);
        C_split.set(n,n,d2);
        //System.out.println("d1 = "+d1);
        //System.out.println("d2 = "+d2);

        // set transition elements in the splitting block
        double split_block_trans = 0.5 * (C_old.get(state,state) - d1 - d2);
        //System.out.println("initial st: "+split_block_trans);

        if (split_block_trans < 0 || split_block_trans > Math.min(pi_split_1 - d1, pi_split_2 - d2))
        {
            split_block_trans = Math.min(pi_split_1 - d1, pi_split_2 - d2) / (double)(10*n+1);
            //System.out.println("correcting to: "+split_block_trans);
        }
        C_split.set(state, n, split_block_trans);
        C_split.set(n, state, split_block_trans);

        //System.out.println("trans_el = "+split_block_trans);

        // set remaining elements
        double sum_old = pi_state_old - C_old.get(state,state);
        double rest1 = pi_split_1 - d1 - split_block_trans;
        double rest2 = pi_split_2 - d2 - split_block_trans;
        //System.out.println("sum_old = "+sum_old);
        //System.out.println("rest1 = "+rest1);
        //System.out.println("rest2 = "+rest2);
        for (int i=0; i<n; i++)
        {
            if (i != state)
            {
                C_split.set(state, i, rest1 * C_old.get(state,i)/sum_old);
                C_split.set(i, state, C_split.get(state,i));
                C_split.set(n, i, rest2 * C_old.get(state,i)/sum_old);
                C_split.set(i, n, C_split.get(n,i));
            }
        }

        //System.out.println("C_split = \n"+C_split);

        // normalize
        IDoubleArray T_split = C_split.copy();
        alg.normalizeRows(T_split, 1);

        //System.out.println("T_split = \n"+T_split);

        IDoubleArray pi_res = msm.stationaryDistribution(T_split);
        double err = alg.distance(pi_res, pi_split);
        //System.out.println("pi error = "+err);

        double p1_res = pi_res.get(state) / (pi_res.get(state)+pi_res.get(n));
        double k1_res = -Math.log(T_split.get(state,state));
        double k2_res = -Math.log(T_split.get(n,n));
        //System.out.println("Have obtained parameters: p1 "+p1_res+"\tk1 "+k1_res+"\tk2 "+k2_res);
        //System.out.println("Compared to reference:    p1 "+p1+"\tk1 "+k1+"\tk2 "+k2);

View Full Code Here

        return parser;
    }

    private static IDoubleArray cumulate(IDoubleArray data)
    {
        IDoubleArray res = doublesNew.array(data.size()+1);
        res.set(0,0);
        for (int i=1; i<res.size(); i++)
            res.set(i, res.get(i-1)+data.get(i-1));
        return res;
    }
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.