Search in sources :

Example 6 with DoubleFactory2D

use of cern.colt.matrix.DoubleFactory2D in project tdq-studio-se by Talend.

the class BenchmarkMatrix method getFactory.

/**
 * Not yet documented.
 */
protected static DoubleFactory2D getFactory(String type) {
    DoubleFactory2D factory;
    if (type.equals("dense"))
        return DoubleFactory2D.dense;
    if (type.equals("sparse"))
        return DoubleFactory2D.sparse;
    if (type.equals("rowCompressed"))
        return DoubleFactory2D.rowCompressed;
    String s = "type=" + type + " is unknown. Use one of {dense,sparse,rowCompressed}";
    throw new IllegalArgumentException(s);
}
Also used : DoubleFactory2D(cern.colt.matrix.DoubleFactory2D)

Example 7 with DoubleFactory2D

use of cern.colt.matrix.DoubleFactory2D in project tdq-studio-se by Talend.

the class Statistic method demo2.

/**
 * Demonstrates usage of this class.
 */
public static void demo2(int rows, int columns, boolean print) {
    System.out.println("\n\ninitializing...");
    DoubleFactory2D factory = DoubleFactory2D.dense;
    DoubleMatrix2D A = factory.ascending(rows, columns);
    // double value = 1;
    // DoubleMatrix2D A = factory.make(rows,columns);
    // A.assign(value);
    System.out.println("benchmarking correlation...");
    cern.colt.Timer timer = new cern.colt.Timer().start();
    DoubleMatrix2D corr = correlation(covariance(A));
    timer.stop().display();
    if (print) {
        System.out.println("printing result...");
        System.out.println(corr);
    }
    System.out.println("done.");
}
Also used : DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DoubleFactory2D(cern.colt.matrix.DoubleFactory2D)

Example 8 with DoubleFactory2D

use of cern.colt.matrix.DoubleFactory2D in project tdq-studio-se by Talend.

the class Statistic method demo1.

/**
 * Demonstrates usage of this class.
 */
public static void demo1() {
    double[][] values = { { 1, 2, 3 }, { 2, 4, 6 }, { 3, 6, 9 }, { 4, -8, -10 } };
    DoubleFactory2D factory = DoubleFactory2D.dense;
    DoubleMatrix2D A = factory.make(values);
    System.out.println("\n\nmatrix=" + A);
    System.out.println("\ncovar1=" + covariance(A));
// System.out.println(correlation(covariance(A)));
// System.out.println(distance(A,EUCLID));
// System.out.println(cern.colt.matrixpattern.Converting.toHTML(A.toString()));
// System.out.println(cern.colt.matrixpattern.Converting.toHTML(covariance(A).toString()));
// System.out.println(cern.colt.matrixpattern.Converting.toHTML(correlation(covariance(A)).toString()));
// System.out.println(cern.colt.matrixpattern.Converting.toHTML(distance(A,EUCLID).toString()));
}
Also used : DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DoubleFactory2D(cern.colt.matrix.DoubleFactory2D)

Example 9 with DoubleFactory2D

use of cern.colt.matrix.DoubleFactory2D in project tdq-studio-se by Talend.

the class BenchmarkMatrix method run.

/**
 * Executes procedure repeatadly until more than minSeconds have elapsed.
 */
protected static void run(double minSeconds, String title, Double2DProcedure function, String[] types, int[] sizes, double[] densities) {
    // int[] sizes = {33,500,1000};
    // double[] densities = {0.001,0.01,0.99};
    // int[] sizes = {3,5,7,9,30,45,60,61,100,200,300,500,800,1000};
    // double[] densities = {0.001,0.01,0.1,0.999};
    // int[] sizes = {3};
    // double[] densities = {0.1};
    DoubleMatrix3D timings = DoubleFactory3D.dense.make(types.length, sizes.length, densities.length);
    cern.colt.Timer runTime = new cern.colt.Timer().start();
    for (int k = 0; k < types.length; k++) {
        // DoubleFactory2D factory = (k==0 ? DoubleFactory2D.dense : k==1 ? DoubleFactory2D.sparse : DoubleFactory2D.rowCompressed);
        // DoubleFactory2D factory = (k==0 ? DoubleFactory2D.dense : k==1 ? DoubleFactory2D.sparse : k==2 ? DoubleFactory2D.rowCompressed : DoubleFactory2D.rowCompressedModified);
        DoubleFactory2D factory = getFactory(types[k]);
        System.out.print("\n@");
        for (int i = 0; i < sizes.length; i++) {
            int size = sizes[i];
            System.out.print("x");
            for (int j = 0; j < densities.length; j++) {
                final double density = densities[j];
                System.out.print(".");
                // System.out.println("   doing density="+density+"...");
                float opsPerSec;
                // if (!((k==1 && density >= 0.1 && size >=100) || (size>5000 && (k==0 || density>1.0E-4) ))) {
                if (!((k > 0 && density >= 0.1 && size >= 500))) {
                    double val = 0.5;
                    // --> help gc before allocating new mem
                    function.A = null;
                    // --> help gc before allocating new mem
                    function.B = null;
                    // --> help gc before allocating new mem
                    function.C = null;
                    // --> help gc before allocating new mem
                    function.D = null;
                    DoubleMatrix2D A = factory.sample(size, size, val, density);
                    DoubleMatrix2D B = factory.sample(size, size, val, density);
                    function.setParameters(A, B);
                    // help gc
                    A = null;
                    // help gc
                    B = null;
                    double ops = function.operations();
                    double secs = BenchmarkKernel.run(minSeconds, function);
                    opsPerSec = (float) (ops / secs);
                } else {
                    // skip this parameter combination (not used in practice & would take a lot of memory and time)
                    opsPerSec = Float.NaN;
                }
                timings.set(k, i, j, opsPerSec);
            // System.out.println(secs);
            // System.out.println(opsPerSec+" Mops/sec\n");
            }
        }
    }
    runTime.stop();
    String sliceAxisName = "type";
    String rowAxisName = "size";
    // "density";
    String colAxisName = "d";
    // String[] sliceNames = {"dense", "sparse"};
    // String[] sliceNames = {"dense", "sparse", "rowCompressed"};
    String[] sliceNames = types;
    hep.aida.bin.BinFunctions1D F = hep.aida.bin.BinFunctions1D.functions;
    // {F.mean, F.median, F.sum};
    hep.aida.bin.BinFunction1D[] aggr = null;
    String[] rowNames = new String[sizes.length];
    String[] colNames = new String[densities.length];
    for (int i = sizes.length; --i >= 0; ) rowNames[i] = Integer.toString(sizes[i]);
    for (int j = densities.length; --j >= 0; ) colNames[j] = Double.toString(densities[j]);
    System.out.println("*");
    // show transposed
    String tmp = rowAxisName;
    rowAxisName = colAxisName;
    colAxisName = tmp;
    String[] tmp2 = rowNames;
    rowNames = colNames;
    colNames = tmp2;
    timings = timings.viewDice(0, 2, 1);
    System.out.println(new cern.colt.matrix.doublealgo.Formatter("%1.3G").toTitleString(timings, sliceNames, rowNames, colNames, sliceAxisName, rowAxisName, colAxisName, "Performance of " + title, aggr));
    /*
	title = "Speedup of dense over sparse";
	DoubleMatrix2D speedup = cern.colt.matrix.doublealgo.Transform.div(timings.viewSlice(0).copy(),timings.viewSlice(1));
	System.out.println("\n"+new cern.colt.matrix.doublealgo.Formatter("%1.3G").toTitleString(speedup,rowNames,colNames,rowAxisName,colAxisName,title,aggr));
	*/
    System.out.println("Run took a total of " + runTime + ". End of run.");
}
Also used : DoubleFactory2D(cern.colt.matrix.DoubleFactory2D) DoubleMatrix3D(cern.colt.matrix.DoubleMatrix3D) DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D)

Example 10 with DoubleFactory2D

use of cern.colt.matrix.DoubleFactory2D in project tdq-studio-se by Talend.

the class BenchmarkMatrix method runSpecial.

/**
 * Executes procedure repeatadly until more than minSeconds have elapsed.
 */
protected static void runSpecial(double minSeconds, String title, Double2DProcedure function) {
    int[] sizes = { 10000 };
    double[] densities = { 0.00001 };
    boolean[] sparses = { true };
    DoubleMatrix2D timings = DoubleFactory2D.dense.make(sizes.length, 4);
    cern.colt.Timer runTime = new cern.colt.Timer().start();
    for (int i = 0; i < sizes.length; i++) {
        int size = sizes[i];
        double density = densities[i];
        boolean sparse = sparses[i];
        final DoubleFactory2D factory = (sparse ? DoubleFactory2D.sparse : DoubleFactory2D.dense);
        System.out.print("\n@");
        System.out.print("x");
        double val = 0.5;
        // --> help gc before allocating new mem
        function.A = null;
        // --> help gc before allocating new mem
        function.B = null;
        // --> help gc before allocating new mem
        function.C = null;
        // --> help gc before allocating new mem
        function.D = null;
        DoubleMatrix2D A = factory.sample(size, size, val, density);
        DoubleMatrix2D B = factory.sample(size, size, val, density);
        function.setParameters(A, B);
        // help gc
        A = null;
        // help gc
        B = null;
        float secs = BenchmarkKernel.run(minSeconds, function);
        double ops = function.operations();
        float opsPerSec = (float) (ops / secs);
        timings.viewRow(i).set(0, sparse ? 0 : 1);
        timings.viewRow(i).set(1, size);
        timings.viewRow(i).set(2, density);
        timings.viewRow(i).set(3, opsPerSec);
    // System.out.println(secs);
    // System.out.println(opsPerSec+" Mops/sec\n");
    }
    runTime.stop();
    hep.aida.bin.BinFunctions1D F = hep.aida.bin.BinFunctions1D.functions;
    // {F.mean, F.median, F.sum};
    hep.aida.bin.BinFunction1D[] aggr = null;
    String[] rowNames = null;
    String[] colNames = { "dense (y=1,n=0)", "size", "density", "flops/sec" };
    String rowAxisName = null;
    String colAxisName = null;
    System.out.println("*");
    System.out.println(new cern.colt.matrix.doublealgo.Formatter("%1.3G").toTitleString(timings, rowNames, colNames, rowAxisName, colAxisName, title, aggr));
    System.out.println("Run took a total of " + runTime + ". End of run.");
}
Also used : DoubleFactory2D(cern.colt.matrix.DoubleFactory2D) DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D)

Aggregations

DoubleFactory2D (cern.colt.matrix.DoubleFactory2D)14 DoubleMatrix2D (cern.colt.matrix.DoubleMatrix2D)13 Algebra (cern.colt.matrix.linalg.Algebra)4 DoubleMatrix1D (cern.colt.matrix.DoubleMatrix1D)3 DenseDoubleMatrix2D (cern.colt.matrix.impl.DenseDoubleMatrix2D)3 Endpoint (edu.cmu.tetrad.graph.Endpoint)3 Node (edu.cmu.tetrad.graph.Node)3 DenseDoubleMatrix1D (cern.colt.matrix.impl.DenseDoubleMatrix1D)2 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)2 Graph (edu.cmu.tetrad.graph.Graph)2 SemGraph (edu.cmu.tetrad.graph.SemGraph)2 DoubleMatrix3D (cern.colt.matrix.DoubleMatrix3D)1 DoubleMatrix2DComparator (cern.colt.matrix.doublealgo.DoubleMatrix2DComparator)1