本文整理汇总了Java中java.util.DoubleSummaryStatistics类的典型用法代码示例。如果您正苦于以下问题:Java DoubleSummaryStatistics类的具体用法?Java DoubleSummaryStatistics怎么用?Java DoubleSummaryStatistics使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DoubleSummaryStatistics类属于java.util包,在下文中一共展示了DoubleSummaryStatistics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEquivalentStreams
import java.util.DoubleSummaryStatistics; //导入依赖的package包/类
public void testEquivalentStreams() {
// For datasets of many double values created from an array, we test many combinations of finite
// and non-finite values:
for (ManyValues values : ALL_MANY_VALUES) {
double[] array = values.asArray();
Stats stats = Stats.of(array);
// instance methods on Stats vs on instance methods on DoubleStream
assertThat(stats.count()).isEqualTo(stream(array).count());
assertEquivalent(stats.mean(), stream(array).average().getAsDouble());
assertEquivalent(stats.sum(), stream(array).sum());
assertEquivalent(stats.max(), stream(array).max().getAsDouble());
assertEquivalent(stats.min(), stream(array).min().getAsDouble());
// static method on Stats vs on instance method on DoubleStream
assertEquivalent(Stats.meanOf(array), stream(array).average().getAsDouble());
// instance methods on Stats vs instance methods on DoubleSummaryStatistics
DoubleSummaryStatistics streamStats = stream(array).summaryStatistics();
assertThat(stats.count()).isEqualTo(streamStats.getCount());
assertEquivalent(stats.mean(), streamStats.getAverage());
assertEquivalent(stats.sum(), streamStats.getSum());
assertEquivalent(stats.max(), streamStats.getMax());
assertEquivalent(stats.min(), streamStats.getMin());
}
}
示例2: getMinOfMdBottom
import java.util.DoubleSummaryStatistics; //导入依赖的package包/类
private double getMinOfMdBottom(ObjMudLog mudLog) {
List<CsGeologyInterval> geologyIntervals = mudLog.getGeologyInterval();
DoubleSummaryStatistics summaryStat = geologyIntervals.stream()
.map(CsGeologyInterval::getMdBottom)
.mapToDouble(MeasuredDepthCoord::getValue)
.summaryStatistics();
double mdMax = -1;
for (CsGeologyInterval geologyInterval : geologyIntervals) {
if (geologyInterval.getMdBottom() != null) {
double value = geologyInterval.getMdBottom().getValue();
if (mdMax < value) {
mdMax = value;
}
}
}
return mdMax;
}
示例3: testDoubleStatistics
import java.util.DoubleSummaryStatistics; //导入依赖的package包/类
public void testDoubleStatistics() {
List<DoubleSummaryStatistics> instances = new ArrayList<>();
instances.add(countTo(1000).stream().collect(Collectors.summarizingDouble(i -> i)));
instances.add(countTo(1000).stream().mapToDouble(i -> i).summaryStatistics());
instances.add(countTo(1000).stream().mapToDouble(i -> i).collect(DoubleSummaryStatistics::new,
DoubleSummaryStatistics::accept,
DoubleSummaryStatistics::combine));
instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingDouble(i -> i)));
instances.add(countTo(1000).parallelStream().mapToDouble(i -> i).summaryStatistics());
instances.add(countTo(1000).parallelStream().mapToDouble(i -> i).collect(DoubleSummaryStatistics::new,
DoubleSummaryStatistics::accept,
DoubleSummaryStatistics::combine));
for (DoubleSummaryStatistics stats : instances) {
assertEquals(stats.getCount(), 1000);
assertEquals(stats.getSum(), (double) countTo(1000).stream().mapToInt(i -> i).sum());
assertEquals(stats.getAverage(), stats.getSum() / stats.getCount());
assertEquals(stats.getMax(), 1000.0);
assertEquals(stats.getMin(), 1.0);
}
}
示例4: selectSolutions
import java.util.DoubleSummaryStatistics; //导入依赖的package包/类
@Override
public <S> void selectSolutions(Generation<S> generation, GenerationSelectorConfiguration configuration) {
int selectionSize = (int) Math.round(generation.getSolutions().size() * configuration.getSelectionRatio());
DoubleSummaryStatistics statistics = calculateFitnessStatistics(generation);
Random random = new Random(configuration.getRandomSeed());
while (!isSelectionSizeReached(selectionSize, generation)) {
for (S solution : generation.getSolutions()) {
if (selectSolution(solution, generation, random, statistics)) {
generation.selectSolution(solution);
if (isSelectionSizeReached(selectionSize, generation)) {
break;
}
}
}
}
}
示例5: updateFitnesses
import java.util.DoubleSummaryStatistics; //导入依赖的package包/类
private void updateFitnesses(FishState simState) {
ObservableList<Fisher> fishers = simState.getFishers();
DoubleSummaryStatistics statistics[] =
new DoubleSummaryStatistics[lastObservedFitnesses.length];
Arrays.setAll(statistics, value -> new DoubleSummaryStatistics());
//get each fishers' utility
for(Fisher fisher : fishers)
{
int index = ((ReplicatorDrivenDestinationStrategy) fisher.getDestinationStrategy()).getStrategyIndex();
statistics[index].accept(objectiveFunction.computeCurrentFitness(fisher, fisher));
}
for(int i=0; i<options.size(); i++)
{
lastObservedFitnesses[i] = statistics[i].getAverage();
}
}
示例6: addDataGatherers
import java.util.DoubleSummaryStatistics; //导入依赖的package包/类
private void addDataGatherers(FishState state) {
//first add data gatherers
state.getYearlyDataSet().registerGatherer("Average Prediction Error",
model -> {
double size =model.getFishers().size();
if(size == 0)
return Double.NaN;
else
{
double total = 0;
for(Fisher fisher1 : state.getFishers()) {
DoubleSummaryStatistics errors = new DoubleSummaryStatistics();
for(Double error : ((HeatmapDestinationStrategy) fisher1.getDestinationStrategy()).getErrors())
errors.accept(error);
total += errors.getAverage();
}
return total/size;
}
}, Double.NaN);
}
示例7: addDataGatherers
import java.util.DoubleSummaryStatistics; //导入依赖的package包/类
private void addDataGatherers(FishState state) {
//first add data gatherers
state.getYearlyDataSet().registerGatherer("Average Prediction Error",
model -> {
double size =model.getFishers().size();
if(size == 0)
return Double.NaN;
else
{
double total = 0;
for(Fisher fisher1 : state.getFishers()) {
DoubleSummaryStatistics errors = new DoubleSummaryStatistics();
for(Double error : ((HeatmapDestinationStrategy) fisher1.getDestinationStrategy()).getErrors())
errors.accept(error);
total += errors.getAverage();
}
return total/size;
}
}, Double.NaN);
}
示例8: MetaScores
import java.util.DoubleSummaryStatistics; //导入依赖的package包/类
public MetaScores(List<Double> scores) {
// A meta alert could be entirely alerts with no values.
DoubleSummaryStatistics stats = scores
.stream()
.mapToDouble(a -> a)
.summaryStatistics();
metaScores.put("max", stats.getMax());
metaScores.put("min", stats.getMin());
metaScores.put("average", stats.getAverage());
metaScores.put("count", stats.getCount());
metaScores.put("sum", stats.getSum());
// median isn't in the stats summary
double[] arr = scores
.stream()
.mapToDouble(d -> d)
.toArray();
metaScores.put("median", new Median().evaluate(arr));
}
示例9: gauges
import java.util.DoubleSummaryStatistics; //导入依赖的package包/类
@Test
public void gauges() {
Registry r = newRegistry(true, 10000);
r.gauge(r.createId("foo", "a", "1")).set(1.0);
r.gauge(r.createId("foo", "a", "2")).set(2.0);
r.gauge(r.createId("bar")).set(7.0);
Assert.assertEquals(3, r.gauges().count());
final DoubleSummaryStatistics valueSummary = r.gauges()
.filter(Functions.nameEquals("foo"))
.collect(Collectors.summarizingDouble(Gauge::value));
Assert.assertEquals(2, valueSummary.getCount());
Assert.assertEquals(3.0, valueSummary.getSum(), 1e-12);
Assert.assertEquals(1.5, valueSummary.getAverage(), 1e-12);
}
示例10: double_summary_stats_with_stream
import java.util.DoubleSummaryStatistics; //导入依赖的package包/类
@Test
public void double_summary_stats_with_stream() {
DoubleSummaryStatistics stats = companies.stream()
.mapToDouble((x) -> x.getRevenue()).summaryStatistics();
// average
assertEquals(109.9425, stats.getAverage(), 0);
// count
assertEquals(4, stats.getCount(), 0);
// max
assertEquals(184.9, stats.getMax(), 0);
// min
assertEquals(12.1, stats.getMin(), 0);
// sum
assertEquals(439.77, stats.getSum(), 0);
}
示例11: double_summary_stats_stream_reduction_target
import java.util.DoubleSummaryStatistics; //导入依赖的package包/类
@Test
public void double_summary_stats_stream_reduction_target() {
DoubleSummaryStatistics stats = companies.stream().collect(
Collectors.summarizingDouble(Company::getRevenue));
// average
assertEquals(109.9425, stats.getAverage(), 0);
// count
assertEquals(4, stats.getCount(), 0);
// max
assertEquals(184.9, stats.getMax(), 0);
// min
assertEquals(12.1, stats.getMin(), 0);
// sum
assertEquals(439.77, stats.getSum(), 0);
}
示例12: main
import java.util.DoubleSummaryStatistics; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
Path salesDataPath = Paths
.get("src/main/resources/com/levelup/java/exercises/beginner/SalesData.txt")
.toAbsolutePath();
//read all lines into a list of strings
List<String> fileByLines = java.nio.file.Files
.readAllLines(salesDataPath);
//convert each string into a DoubleSummaryStatistics object
List<DoubleSummaryStatistics> weeksSummary = new ArrayList<>();
for (String row : fileByLines) {
// split on comma, map to double
weeksSummary.add(Arrays.stream(row.split(","))
.mapToDouble(Double::valueOf).summaryStatistics());
}
displayWeeklyStats(weeksSummary);
displaySummaryResults(weeksSummary);
}
示例13: displaySummaryResults
import java.util.DoubleSummaryStatistics; //导入依赖的package包/类
public static void displaySummaryResults(
List<DoubleSummaryStatistics> weeksSummary) {
System.out.println("Total sales for all weeks: $"
+ weeksSummary.stream().mapToDouble(p -> p.getSum()).sum());
System.out.println("Average weekly sales: $"
+ weeksSummary.stream().mapToDouble(p -> p.getSum()).average()
.getAsDouble());
System.out.println("The highest sales was $"
+ weeksSummary.stream().mapToDouble(p -> p.getSum()).max()
.getAsDouble());
System.out.println("The lowest sales were made during "
+ weeksSummary.stream().mapToDouble(p -> p.getSum()).min()
.getAsDouble());
}
示例14: main
import java.util.DoubleSummaryStatistics; //导入依赖的package包/类
public static void main(String[] args) {
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Get a string of digits.
System.out.print("Enter a string of digits: ");
String input = keyboard.nextLine();
// close keyboard
keyboard.close();
DoubleSummaryStatistics summaryStats = Stream.of(input.split(""))
.mapToDouble(Double::valueOf).summaryStatistics();
System.out.println("The sum of numbers " + summaryStats.getSum());
System.out.println("The highest digit is " + summaryStats.getMax());
System.out.println("The lowest digit is " + summaryStats.getMin());
}
示例15: combinedStatisticsJDK_parallel
import java.util.DoubleSummaryStatistics; //导入依赖的package包/类
@Benchmark
public Object[] combinedStatisticsJDK_parallel()
{
DoubleSummaryStatistics stats1 =
Person.getJDKPeople().parallelStream().mapToDouble(Person::getHeightInInches).summaryStatistics();
DoubleSummaryStatistics stats2 =
Person.getJDKPeople().parallelStream().mapToDouble(Person::getWeightInPounds).summaryStatistics();
IntSummaryStatistics stats3 =
Person.getJDKPeople().parallelStream().mapToInt(Person::getAge).summaryStatistics();
return new Object[]{stats1, stats2, stats3};
}