Search in sources :

Example 91 with DescriptiveStatistics

use of org.apache.commons.math3.stat.descriptive.DescriptiveStatistics in project hive by apache.

the class HMSBenchmarks method benchmarkDropPartition.

static DescriptiveStatistics benchmarkDropPartition(@NotNull MicroBenchmark bench, @NotNull BenchData data) {
    final HMSClient client = data.getClient();
    String dbName = data.dbName;
    String tableName = data.tableName;
    BenchmarkUtils.createPartitionedTable(client, dbName, tableName);
    final List<String> values = Collections.singletonList("d1");
    try {
        Table t = client.getTable(dbName, tableName);
        Partition partition = new Util.PartitionBuilder(t).withValues(values).build();
        return bench.measure(() -> throwingSupplierWrapper(() -> client.addPartition(partition)), () -> throwingSupplierWrapper(() -> client.dropPartition(dbName, tableName, values)), null);
    } catch (TException e) {
        e.printStackTrace();
        return new DescriptiveStatistics();
    } finally {
        throwingSupplierWrapper(() -> client.dropTable(dbName, tableName));
    }
}
Also used : TException(org.apache.thrift.TException) Partition(org.apache.hadoop.hive.metastore.api.Partition) DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) Table(org.apache.hadoop.hive.metastore.api.Table)

Example 92 with DescriptiveStatistics

use of org.apache.commons.math3.stat.descriptive.DescriptiveStatistics in project nabl by metaborg.

the class StatixGenerate method run.

public void run(String file) throws MetaborgException, InterruptedException {
    final FileObject resource = STX.S.resolve(file);
    TermFormatter tf = ITerm::toString;
    try {
        final ILanguageImpl lang = STX.cli.loadLanguage(STX.project.location());
        final IContext context = STX.S.contextService.get(resource, STX.project, lang);
        tf = StatixGenerator.pretty(STX.S, context, "pp-generated");
    } catch (MetaborgException e) {
    // ignore
    }
    final TermFormatter _tf = tf;
    final Function1<SearchState, String> pretty = (s) -> _tf.format(project(VAR, s));
    final DescriptiveStatistics hitStats = new DescriptiveStatistics();
    final DescriptiveStatistics missStats = new DescriptiveStatistics();
    final StreamProgressPrinter progress = new StreamProgressPrinter(System.err, 80, out -> {
        long hits = hitStats.getN();
        long all = hits + missStats.getN();
        out.println(" " + hits + "/" + all + " " + summary(hitStats));
    });
    final SearchLogger<SearchState, SearchState> searchLog = new SearchLogger<SearchState, SearchState>() {

        @Override
        public void init(long seed, SearchStrategy<SearchState, SearchState> strategy, Iterable<IConstraint> constraints) {
            log.info("seed {}", seed);
            log.info("strategy {}", strategy);
            log.info("constraints {}", constraints);
        }

        @Override
        public void success(SearchNode<SearchState> n) {
            progress.step('+');
            addSize(n.output(), hitStats);
            logSuccess(log, Level.Debug, n, pretty);
        }

        @Override
        public void failure(SearchNodes<?> nodes) {
            progress.step('.');
            SearchNode<?> parentNode = nodes.parent();
            if (parentNode != null && parentNode.output() instanceof SearchState) {
                addSize((SearchState) parentNode.output(), missStats);
            }
            logFailure(log, Level.Debug, nodes, pretty);
        }

        private void addSize(SearchState s, DescriptiveStatistics stats) {
            s.state().unifier().size(project(VAR, s)).ifFinite(size -> {
                stats.addValue(size.doubleValue());
            });
        }
    };
    final StatixGenerator statixGen = new StatixGenerator(STX.S, STX.context, resource);
    // Paret.addFragments(statixGen.spec());
    final Spec spec = statixGen.spec();
    final RandomTermGenerator rtg = new RandomTermGenerator(spec, statixGen.constraint(), new Paret(spec).search(), searchLog);
    final Stream<SearchState> resultStream = rtg.apply().nodes().map(sn -> {
        searchLog.success(sn);
        return sn.output();
    });
    log.info("Generating random terms.");
    final List<SearchState> results = Lists.newArrayList(resultStream.limit(COUNT).iterator());
    progress.done();
    results.forEach(s -> {
        System.out.println(pretty.apply(s));
    });
    log.info("Generated {} random terms.", results.size());
    logStatsInfo("hits", hitStats);
    logStatsInfo("misses", missStats);
}
Also used : Spec(mb.statix.spec.Spec) Function1(org.metaborg.util.functions.Function1) ITerm(mb.nabl2.terms.ITerm) RandomTermGenerator(mb.statix.generator.RandomTermGenerator) SearchStrategy(mb.statix.generator.SearchStrategy) MetaborgException(org.metaborg.core.MetaborgException) Lists(com.google.common.collect.Lists) SearchLogger(mb.statix.generator.SearchLogger) ITermVar(mb.nabl2.terms.ITermVar) ILogger(org.metaborg.util.log.ILogger) B(mb.nabl2.terms.build.TermBuild.B) Level(org.metaborg.util.log.Level) SearchNode(mb.statix.generator.nodes.SearchNode) TermFormatter(mb.nabl2.util.TermFormatter) SearchNodes(mb.statix.generator.nodes.SearchNodes) FileObject(org.apache.commons.vfs2.FileObject) SearchElement(mb.statix.generator.nodes.SearchElement) List(java.util.List) Stream(java.util.stream.Stream) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) IConstraint(mb.statix.solver.IConstraint) DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) IContext(org.metaborg.core.context.IContext) SearchState(mb.statix.generator.SearchState) LoggerUtils(org.metaborg.util.log.LoggerUtils) StatixGenerator(org.metaborg.spoofax.core.shell.StatixGenerator) StreamProgressPrinter(mb.statix.generator.util.StreamProgressPrinter) DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) SearchLogger(mb.statix.generator.SearchLogger) TermFormatter(mb.nabl2.util.TermFormatter) IContext(org.metaborg.core.context.IContext) SearchStrategy(mb.statix.generator.SearchStrategy) RandomTermGenerator(mb.statix.generator.RandomTermGenerator) MetaborgException(org.metaborg.core.MetaborgException) SearchNodes(mb.statix.generator.nodes.SearchNodes) FileObject(org.apache.commons.vfs2.FileObject) SearchNode(mb.statix.generator.nodes.SearchNode) StreamProgressPrinter(mb.statix.generator.util.StreamProgressPrinter) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) SearchState(mb.statix.generator.SearchState) Spec(mb.statix.spec.Spec) StatixGenerator(org.metaborg.spoofax.core.shell.StatixGenerator)

Example 93 with DescriptiveStatistics

use of org.apache.commons.math3.stat.descriptive.DescriptiveStatistics in project MPW by shineangelic.

the class BlocksActivity method doApacheMath.

private SummaryStatistics doApacheMath(List<Matured> maturi) {
    ArrayList<Matured> revElements = new ArrayList<>(maturi);
    Collections.reverse(revElements);
    long[] intervals = new long[maturi.size()];
    Date prevDate = revElements.get(0).getTimestamp();
    int i = 0;
    // parto da 1 a calcolare il 1o intervallo
    for (int t = 1; t < revElements.size(); t++) {
        Date curDate = revElements.get(t).getTimestamp();
        intervals[i++] = curDate.getTime() - prevDate.getTime();
        prevDate = curDate;
    }
    // a oggi, calcolo ultimo intervallo aperto
    intervals[maturi.size() - 1] = (new Date().getTime() - revElements.get(maturi.size() - 1).getTimestamp().getTime());
    // Get a DescriptiveStatistics instance
    SummaryStatistics stats = new SummaryStatistics();
    // Add the data from the array
    for (long interval : intervals) {
        stats.addValue(interval);
    }
    return stats;
}
Also used : Matured(it.angelic.mpw.model.jsonpojos.blocks.Matured) ArrayList(java.util.ArrayList) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) Date(java.util.Date)

Example 94 with DescriptiveStatistics

use of org.apache.commons.math3.stat.descriptive.DescriptiveStatistics in project metron by apache.

the class OnlineStatisticsProviderTest method validateEquality.

private void validateEquality(Iterable<Double> values) {
    DescriptiveStatistics stats = new DescriptiveStatistics();
    SummaryStatistics summaryStats = new SummaryStatistics();
    OnlineStatisticsProvider statsProvider = new OnlineStatisticsProvider();
    // Test that the aggregated provider gives the same results as the provider that is shown all the data.
    List<OnlineStatisticsProvider> providers = new ArrayList<>();
    for (int i = 0; i < 10; ++i) {
        providers.add(new OnlineStatisticsProvider());
    }
    int i = 0;
    for (double d : values) {
        i++;
        stats.addValue(d);
        summaryStats.addValue(d);
        providers.get(i % providers.size()).addValue(d);
        statsProvider.addValue(d);
    }
    StatisticsProvider aggregatedProvider = providers.get(0);
    for (int j = 1; j < providers.size(); ++j) {
        aggregatedProvider = aggregatedProvider.merge(providers.get(j));
    }
    validateStatisticsProvider(statsProvider, summaryStats, stats);
    validateStatisticsProvider(aggregatedProvider, summaryStats, stats);
}
Also used : DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) ArrayList(java.util.ArrayList) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics)

Example 95 with DescriptiveStatistics

use of org.apache.commons.math3.stat.descriptive.DescriptiveStatistics in project metron by apache.

the class StellarStatisticsFunctionsTest method setup.

@BeforeEach
public void setup() {
    variables = new HashMap<>();
    // test input data
    values = Arrays.asList(10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0);
    // the DescriptiveStatistics is used for validation
    stats = new DescriptiveStatistics(1000);
    values.stream().forEach(val -> stats.addValue(val));
    // the StatisticalSummary is used for validation
    summaryStats = new SummaryStatistics();
    values.stream().forEach(val -> summaryStats.addValue(val));
}
Also used : DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

DescriptiveStatistics (org.apache.commons.math3.stat.descriptive.DescriptiveStatistics)183 ArrayList (java.util.ArrayList)22 List (java.util.List)17 Test (org.testng.annotations.Test)15 Test (org.junit.Test)13 Test (org.junit.jupiter.api.Test)12 File (java.io.File)11 Plot (ij.gui.Plot)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 Rectangle (java.awt.Rectangle)8 HashMap (java.util.HashMap)7 TException (org.apache.thrift.TException)7 Result (de.dagere.kopeme.generated.Result)6 LinkedList (java.util.LinkedList)6 AbstractMagmaTest (org.obiba.magma.test.AbstractMagmaTest)6 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)6 PrecisionResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.PrecisionResultProcedure)6 ImagePlus (ij.ImagePlus)5 PlotWindow (ij.gui.PlotWindow)5 ImageProcessor (ij.process.ImageProcessor)5