Package stallone.api.doubles

Examples of stallone.api.doubles.IDoubleArray


        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


        // check transition matrix structure and determine components
        calculateComponents();

        for (int c=0; c<components.size(); c++)
        {
            IDoubleArray Tsub = T.view(components.get(c).getArray(),components.get(c).getArray()).copy();
            for (int i=0; i<Tsub.rows(); i++)
            {
                IDoubleArray row = Tsub.viewRow(i);
                Algebra.util.scale(1.0/Doubles.util.sum(row), row);
            }

            //System.out.println(c+" "+componentIsClosed(components[c]));

            if (!componentIsClosed(components.get(c)))
                continue; // no probability in this set.

            IDoubleArray pisub = calculateSub(Tsub);

            /*if (c == 0)
            {
            System.out.println("Submatrix: "+Tsub.length);
            for (int j=0; j<Tsub.length; j++)
                System.out.println(j+" "+DoubleArrays.sum(Tsub[j]));

            Graph g = Graph.fromWeightMatrix(Tsub);
            int[][] C = g.strongComponents();
            System.out.println("Number of components: "+C.length);

            System.out.println("PI: ");
            DoubleArrays.print(pisub,"\n");

            System.out.println("T sub:");
            AlgebraPrimitive.writeMatrixSparse(Tsub,System.out);

                System.exit(0);
            }
             *
             */

            this.componentsPi.set(c, pisub);

            for (int i=0; i<pisub.size(); i++)
            {
                int s = components.get(c).get(i);
                pi.set(s, pisub.get(i));
                //this.componentsPi.set(c).set(s, pisub.get(i));
                //this.componentsPi.get(c).set(s, pisub.get(i));
                //System.out.println("trying to get from component "+c+" with size "+components.get(c));
                //System.out.println("trying to get from pi comp with size "+componentsPi.get(c));

View Full Code Here

        {
            throw (new IllegalArgumentException("Number of time points does not match number of data points in correlate."));
        }

        // cumulate data
        IDoubleArray cumdata = cumulate(data);

        Window w1 = new Window(time, data, windowSize);
        w1.init(windowSize/2.0);

        Window w2 = new Window(time, data, windowSize);
        w2.init(windowSize/2.0 + tau);

        // estimate
        double sum = 0;
        double count = 0;

        while(!w2.endOfData())
        {
            /*
                if (tau == 0)
                {
                    System.out.println("t = "+w1.t+"\t times ["+w1.tl+","+w1.tr+"] -> ["+w2.tl+","+w2.tr+"]");
                    System.out.println("  w1=("+w1.l+", "+w1.r+") w2="+w2.l+", "+w2.r);
                }*/

            // update convolution sums
            if ((!w1.isEmpty()) && (!w2.isEmpty()))
            {
                double x1 = (cumdata.get(w1.r) - cumdata.get(w1.l))/((double)(w1.r-w1.l));
                double x2 = (cumdata.get(w2.r) - cumdata.get(w2.l))/((double)(w2.r-w2.l));
                sum += x1*x2;
                count += 1.0;

                /*if (tau == 0)
                {
View Full Code Here

        if (!success)
        {
            return (false);
        }

        IDoubleArray gradient = model.getGradient();

        for (int i = 0; i < x.size(); i++)
        {
            // calculate acceleration from forces
            a.set(i, -gradient.get(i) / masses.get(i));
            // update velocities to full step
            v.set(i, v.get(i) + 0.5 * dt * a.get(i));
        }

        return (true);
View Full Code Here

        return (pi);
    }

    private IDoubleArray calculateSub(IDoubleArray Tsub)
    {
        IDoubleArray pisub = null;
        if (!reversible)
        {
            pisub = calculateSubGeneral(Tsub);
        }
        else
View Full Code Here

     * @param data
     * @return the autocorrelations of the data on the tau grid specified
     */
    public IDoubleArray correlate(IDoubleArray time, IDoubleArray data)
    {
        IDoubleArray res = doublesNew.array(lagtimes.size());

        for (int i = 0; i < res.size(); i++)
        {
            res.set(i, correlate(time, data, lagtimes.get(i), averageWidths.get(i)));
        }

        return res;
    }
View Full Code Here

    private IDoubleArray calculateSubGeneral(IDoubleArray Tsub)
    {
        IEigenvalueDecomposition evd = Algebra.util.evd(Tsub, true, false);
        evd.sortNormDescending();

        IDoubleArray l1 = evd.getLeftEigenvector(0).copy();

        Algebra.util.scale(1.0 / Doubles.util.sum(l1), l1);

        return(l1);
    }
View Full Code Here

        Iterator<IDoubleArray> it = data.iterator();
        if (!it.hasNext())
        {
            throw (new RuntimeException("Trying to cluster an empty data set"));
        }
        IDoubleArray v_0 = it.next().copy();
        clusters.add(v_0);
        assignedClusters.add(0);
        minDistances.add(0);
        //clusterCenterIndexes[0]=0;

        // consider second data point
        /*
         * if (!it.hasNext()) throw(new RuntimeException("Trying to cluster a
         * data set with one data point")); IVector v_i = it.next();
         * assignedClusters.add(0); minDistances.add(distanceMetric.measure(v_i,
         * v_0));
         */

        // first iteration: go over data, calculate distance to first center and assign first center
        System.out.println("KCenter: iteration 1/" + numberOfClusters + ".");
        IDoubleArray v_i = null;
        double maxMinDistance = 0;
        int count = 0;
        while (it.hasNext())
        {
            IDoubleArray p_j = it.next().copy();

            // calculate distance to cluster 0
            double d = distanceMetric.distance(p_j, v_0);
            minDistances.add(d);

            // is this the largest distance so far? Then memorize as next center candidate
            if (d >= maxMinDistance)
            {
                count++;
                maxMinDistance = d;
                v_i = p_j;
            }

            // assign every data point p_j to cluster 0
            assignedClusters.add(0);
        }


        // for all other clusters, add the most distance point as center and the reassign
        // for k clusters do k-2 further passes to the data
        for (int i = 1; i < numberOfClusters; i++)
        {
            System.out.println("KCenter: iteration " + (i + 1) + "/" + numberOfClusters + ".");

            // add most distance point as a new center
            clusters.add(v_i);

            int j = 0;
            maxMinDistance = 0;
            IDoubleArray v_next = null;
            for (it = data.iterator(); it.hasNext(); j++) //for (int j = 0; j < dataPoints.size(); j++)
            {
                IDoubleArray p_j = it.next().copy();

                // get minimal distance of p_j to cluster centers
                double currentDistance = minDistances.get(j);

                // calculate new distance of p_j to the possible new cluster center
View Full Code Here

        return(l1);
    }

    private IDoubleArray calculateSubReversible(IDoubleArray Tsubrev)
    {
        IDoubleArray pisub = Doubles.create.array(Tsubrev.rows());
        pisub.set(0,1);

        boolean[] done = new boolean[Tsubrev.rows()];
        done[0] = true;

        LinkedList<Integer> todo = new LinkedList<Integer>();
View Full Code Here

        double minimalDistance = Double.MAX_VALUE;
        int indexOfNearestCluster = -1;

        for (int i = 0; i < numberOfClusters; i++)
        {
            IDoubleArray v_i = clusters.get(i);

            // calculate distance
            double currentDistance = distanceMetric.distance(p, v_i);

            if (currentDistance < minimalDistance)
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.