當前位置: 首頁>>代碼示例>>Java>>正文


Java AbstractContinousDistribution類代碼示例

本文整理匯總了Java中org.apache.mahout.math.jet.random.AbstractContinousDistribution的典型用法代碼示例。如果您正苦於以下問題:Java AbstractContinousDistribution類的具體用法?Java AbstractContinousDistribution怎麽用?Java AbstractContinousDistribution使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AbstractContinousDistribution類屬於org.apache.mahout.math.jet.random包,在下文中一共展示了AbstractContinousDistribution類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testNarrowNormal

import org.apache.mahout.math.jet.random.AbstractContinousDistribution; //導入依賴的package包/類
@Test
public void testNarrowNormal() {
    // this mixture of a uniform and normal distribution has a very narrow peak which is centered
    // near the median.  Our system should be scale invariant and work well regardless.
    final Random gen = RandomUtils.getRandom();
    AbstractContinousDistribution mix = new AbstractContinousDistribution() {
        AbstractContinousDistribution normal = new Normal(0, 1e-5, gen);
        AbstractContinousDistribution uniform = new Uniform(-1, 1, gen);

        @Override
        public double nextDouble() {
            double x;
            if (gen.nextDouble() < 0.5) {
                x = uniform.nextDouble();
            } else {
                x = normal.nextDouble();
            }
            return x;
        }
    };

    for (int i = 0; i < repeats(); i++) {
        runTest(mix, 100, new double[]{0.001, 0.01, 0.1, 0.3, 0.5, 0.7, 0.9, 0.99, 0.999}, "mixture", false, gen);
    }
}
 
開發者ID:mayconbordin,項目名稱:streaminer,代碼行數:26,代碼來源:TDigestTest.java

示例2: testSequentialPoints

import org.apache.mahout.math.jet.random.AbstractContinousDistribution; //導入依賴的package包/類
@Test
public void testSequentialPoints() {
    Random gen = RandomUtils.getRandom();
    for (int i = 0; i < repeats(); i++) {
        runTest(new AbstractContinousDistribution() {
            double base = 0;

            @Override
            public double nextDouble() {
                base += Math.PI * 1e-5;
                return base;
            }
        }, 100, new double[]{0.001, 0.01, 0.1, 0.5, 0.9, 0.99, 0.999},
                "sequential", true, gen);
    }
}
 
開發者ID:mayconbordin,項目名稱:streaminer,代碼行數:17,代碼來源:TDigestTest.java

示例3: compare

import org.apache.mahout.math.jet.random.AbstractContinousDistribution; //導入依賴的package包/類
private void compare(AbstractContinousDistribution gen, String tag, long scale, Random rand) {
    for (double compression : new double[]{2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000}) {
        QDigest qd = new QDigest(compression);
        TDigest dist = new TDigest(compression, rand);
        List<Double> data = Lists.newArrayList();
        for (int i = 0; i < 100000; i++) {
            double x = gen.nextDouble();
            dist.add(x);
            qd.offer((long) (x * scale));
            data.add(x);
        }
        dist.compress();
        Collections.sort(data);

        for (double q : new double[]{0.001, 0.01, 0.1, 0.2, 0.3, 0.5, 0.7, 0.8, 0.9, 0.99, 0.999}) {
            double x1 = dist.quantile(q);
            double x2 = (double) qd.getQuantile(q) / scale;
            double e1 = cdf(x1, data) - q;
            System.out.printf("%s\t%.0f\t%.8f\t%.10g\t%.10g\t%d\t%d\n", tag, compression, q, e1, cdf(x2, data) - q, dist.smallByteSize(), QDigest.serialize(qd).length);

        }
    }
}
 
開發者ID:mayconbordin,項目名稱:streaminer,代碼行數:24,代碼來源:TDigestTest.java

示例4: testNarrowNormal

import org.apache.mahout.math.jet.random.AbstractContinousDistribution; //導入依賴的package包/類
@Test
public void testNarrowNormal() {
    // this mixture of a uniform and normal distribution has a very narrow peak which is centered
    // near the median.  Our system should be scale invariant and work well regardless.
    final Random gen = getRandom();
    AbstractContinousDistribution mix = new AbstractContinousDistribution() {
        final AbstractContinousDistribution normal = new Normal(0, 1e-5, gen);
        final AbstractContinousDistribution uniform = new Uniform(-1, 1, gen);

        @Override
        public double nextDouble() {
            double x;
            if (gen.nextDouble() < 0.5) {
                x = uniform.nextDouble();
            } else {
                x = normal.nextDouble();
            }
            return x;
        }
    };

    for (int i = 0; i < repeats(); i++) {
        runTest(factory(), mix, 100, new double[]{0.001, 0.01, 0.1, 0.3, 0.5, 0.7, 0.9, 0.99, 0.999}, "mixture", false);
    }
}
 
開發者ID:tdunning,項目名稱:t-digest,代碼行數:26,代碼來源:TDigestTest.java

示例5: compareQD

import org.apache.mahout.math.jet.random.AbstractContinousDistribution; //導入依賴的package包/類
private void compareQD(PrintWriter out, AbstractContinousDistribution gen, String tag, long scale) {
    for (double compression : new double[]{10, 20, 50, 100, 200, 500, 1000, 2000}) {
        QDigest qd = new QDigest(compression);
        TDigest dist = factory(compression).create();
        List<Double> data = Lists.newArrayList();
        for (int i = 0; i < 100000; i++) {
            double x = gen.nextDouble();
            dist.add(x);
            qd.offer((long) (x * scale));
            data.add(x);
        }
        dist.compress();
        Collections.sort(data);

        for (double q : new double[]{0.001, 0.01, 0.1, 0.2, 0.3, 0.5, 0.7, 0.8, 0.9, 0.99, 0.999}) {
            double x1 = dist.quantile(q);
            double x2 = (double) qd.getQuantile(q) / scale;
            double e1 = cdf(x1, data) - q;
            out.printf("%s\t%.0f\t%.8f\t%.10g\t%.10g\t%d\t%d\n", tag, compression, q, e1, cdf(x2, data) - q, dist.smallByteSize(), QDigest.serialize(qd).length);

        }
    }
}
 
開發者ID:tdunning,項目名稱:t-digest,代碼行數:24,代碼來源:TDigestTest.java

示例6: testAccuracyVersusCompression

import org.apache.mahout.math.jet.random.AbstractContinousDistribution; //導入依賴的package包/類
@Test
public void testAccuracyVersusCompression() throws FileNotFoundException {
    PrintWriter out = new PrintWriter("accuracy.csv");
    PrintWriter sizes = new PrintWriter("accuracy-sizes.csv");
    out.printf("digest, dist, sort, q.digest, q.raw, error, compression, x, k\n");
    sizes.printf("digest, dist, sort, q.0, q.1, dk, mean, compression, count, k\n");
    for (int k = 0; k < 5; k++) {
        for (double compression : new double[]{100, 200, 500}) {
            for (Util.Distribution dist : Util.Distribution.values()) {
                AbstractContinousDistribution dx = dist.create(gen);
                double[] raw = new double[N];
                for (int i = 0; i < N; i++) {
                    raw[i] = dx.nextDouble();
                }
                double[] sorted = Arrays.copyOf(raw, raw.length);
                Arrays.sort(sorted);

                for (Util.Factory factory : Util.Factory.values()) {
                    evaluate(k, out, sizes, dist, "unsorted", factory, raw, compression);
                    evaluate(k, out, sizes, dist, "sorted", factory, sorted, compression);
                }
            }
        }
        System.out.printf("%d\n", k);
    }
    sizes.close();
    out.close();
}
 
開發者ID:tdunning,項目名稱:t-digest,代碼行數:29,代碼來源:AccuracyTest.java

示例7: testSequentialPoints

import org.apache.mahout.math.jet.random.AbstractContinousDistribution; //導入依賴的package包/類
@Test
public void testSequentialPoints() {
    for (int i = 0; i < repeats(); i++) {
        runTest(factory(), new AbstractContinousDistribution() {
                    double base = 0;

                    @Override
                    public double nextDouble() {
                        base += Math.PI * 1e-5;
                        return base;
                    }
                }, 100, new double[]{0.001, 0.01, 0.1, 0.5, 0.9, 0.99, 0.999},
                "sequential", true);
    }
}
 
開發者ID:tdunning,項目名稱:t-digest,代碼行數:16,代碼來源:TDigestTest.java

示例8: compareSQ

import org.apache.mahout.math.jet.random.AbstractContinousDistribution; //導入依賴的package包/類
private void compareSQ(PrintWriter out, AbstractContinousDistribution gen, String tag, long scale) {
    double[] quantiles = {0.001, 0.01, 0.1, 0.2, 0.3, 0.5, 0.7, 0.8, 0.9, 0.99, 0.999};
    for (double compression : new double[]{10, 20, 50, 100, 200, 500, 1000, 2000}) {
        QuantileEstimator sq = new QuantileEstimator(1001);
        TDigest dist = factory(compression).create();
        List<Double> data = Lists.newArrayList();
        for (int i = 0; i < 100000; i++) {
            double x = gen.nextDouble();
            dist.add(x);
            sq.add(x);
            data.add(x);
        }
        dist.compress();
        Collections.sort(data);

        List<Double> qz = sq.getQuantiles();
        for (double q : quantiles) {
            double x1 = dist.quantile(q);
            double x2 = qz.get((int) (q * 1000 + 0.5));
            double e1 = cdf(x1, data) - q;
            double e2 = cdf(x2, data) - q;
            out.printf("%s\t%.0f\t%.8f\t%.10g\t%.10g\t%d\t%d\n",
                    tag, compression, q, e1, e2, dist.smallByteSize(), sq.serializedSize());

        }
    }
}
 
開發者ID:tdunning,項目名稱:t-digest,代碼行數:28,代碼來源:TDigestTest.java

示例9: testRepeatedValues

import org.apache.mahout.math.jet.random.AbstractContinousDistribution; //導入依賴的package包/類
@Test
public void testRepeatedValues() {
    final Random gen = RandomUtils.getRandom();

    // 5% of samples will be 0 or 1.0.  10% for each of the values 0.1 through 0.9
    AbstractContinousDistribution mix = new AbstractContinousDistribution() {
        @Override
        public double nextDouble() {
            return Math.rint(gen.nextDouble() * 10) / 10.0;
        }
    };

    TDigest dist = new TDigest((double) 1000, gen);
    long t0 = System.nanoTime();
    List<Double> data = Lists.newArrayList();
    for (int i1 = 0; i1 < 100000; i1++) {
        double x = mix.nextDouble();
        data.add(x);
        dist.add(x);
    }

    System.out.printf("# %fus per point\n", (System.nanoTime() - t0) * 1e-3 / 100000);
    System.out.printf("# %d centroids\n", dist.centroidCount());

    // I would be happier with 5x compression, but repeated values make things kind of weird
    assertTrue("Summary is too large", dist.centroidCount() < 10 * (double) 1000);

    // all quantiles should round to nearest actual value
    for (int i = 0; i < 10; i++) {
        double z = i / 10.0;
        // we skip over troublesome points that are nearly halfway between
        for (double delta : new double[]{0.01, 0.02, 0.03, 0.07, 0.08, 0.09}) {
            double q = z + delta;
            double cdf = dist.cdf(q);
            // we also relax the tolerances for repeated values
            assertEquals(String.format("z=%.1f, q = %.3f, cdf = %.3f", z, q, cdf), z + 0.05, cdf, 0.005);

            double estimate = dist.quantile(q);
            assertEquals(String.format("z=%.1f, q = %.3f, cdf = %.3f, estimate = %.3f", z, q, cdf, estimate), Math.rint(q * 10) / 10.0, estimate, 0.001);
        }
    }
}
 
開發者ID:mayconbordin,項目名稱:streaminer,代碼行數:43,代碼來源:TDigestTest.java

示例10: create

import org.apache.mahout.math.jet.random.AbstractContinousDistribution; //導入依賴的package包/類
@Override
public AbstractContinousDistribution create(Random gen) {
    return new Uniform(0, 1, gen);
}
 
開發者ID:tdunning,項目名稱:t-digest,代碼行數:5,代碼來源:Util.java


注:本文中的org.apache.mahout.math.jet.random.AbstractContinousDistribution類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。