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));
}
}
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);
}
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;
}
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);
}
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));
}
Aggregations