本文整理汇总了Java中org.apache.commons.math3.stat.descriptive.SummaryStatistics.getN方法的典型用法代码示例。如果您正苦于以下问题:Java SummaryStatistics.getN方法的具体用法?Java SummaryStatistics.getN怎么用?Java SummaryStatistics.getN使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.stat.descriptive.SummaryStatistics
的用法示例。
在下文中一共展示了SummaryStatistics.getN方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStats
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
private static Stats getStats(FloatColumn values, SummaryStatistics summaryStatistics) {
Stats stats = new Stats("Column: " + values.name());
stats.min = (float) summaryStatistics.getMin();
stats.max = (float) summaryStatistics.getMax();
stats.n = summaryStatistics.getN();
stats.sum = summaryStatistics.getSum();
stats.variance = summaryStatistics.getVariance();
stats.populationVariance = summaryStatistics.getPopulationVariance();
stats.quadraticMean = summaryStatistics.getQuadraticMean();
stats.geometricMean = summaryStatistics.getGeometricMean();
stats.mean = summaryStatistics.getMean();
stats.standardDeviation = summaryStatistics.getStandardDeviation();
stats.sumOfLogs = summaryStatistics.getSumOfLogs();
stats.sumOfSquares = summaryStatistics.getSumsq();
stats.secondMoment = summaryStatistics.getSecondMoment();
return stats;
}
示例2: getSummaryStatisticsForCollection
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
/**
* This function will take an aggregated collection of Summary Statistics
* and will generate a derived {@link SummaryStatistic} based on a flag for the
* desired summation. This is particularly helpful for finding out the
* means of the individual statistics of the collection.
* For example, if you wanted to find out the mean of means of the collection
* you would call this function like <p>
* getSummaryStatisticsForCollection(aggregate,1).getMean(); <p>
* Or if you wanted to determine the max number of annotations per
* individual, you could call: <p>
* getSummaryStatisticsForCollection(aggregate,5).getMax(); <p>
* The stat flag should be set to the particular individual statistic that should
* be summarized over.
*
* @param aggregate The aggregated collection of summary statistics
* @param stat Integer flag for the statistic (1:mean ; 2:sum; 3:min; 4:max; 5:N)
* @return {@link SummaryStatistics} of the selected statistic
*/
public SummaryStatistics getSummaryStatisticsForCollection(Collection<SummaryStatistics> aggregate, Stat stat) {
//LOG.info("Computing stats over collection of "+aggregate.size()+" elements ("+stat+"):");
//TODO: turn stat into enum
int x = 0;
//To save memory, I am using SummaryStatistics, which does not store the values,
//but this could be changed to DescriptiveStatistics to see values
//as well as other statistical functions like distributions
SummaryStatistics stats = new SummaryStatistics();
Double v = 0.0;
ArrayList<String> vals = new ArrayList();
for (SummaryStatistics s : aggregate) {
switch (stat) {
case MEAN : v= s.getMean(); stats.addValue(s.getMean()); break;
case SUM : v=s.getSum(); stats.addValue(s.getSum()); break;
case MIN : v=s.getMin(); stats.addValue(s.getMin()); break;
case MAX : v=s.getMax(); stats.addValue(s.getMax()); break;
case N : v= ((int)s.getN())*1.0; stats.addValue(s.getN()); break;
};
//vals.add(v.toString());
};
//LOG.info("vals: "+vals.toString());
return stats;
}
示例3: printImpostorThresholds
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
private void printImpostorThresholds(Set<float[]> impostorScoresArray) {
// Calculate Distributions - only with raw scores, not imp_prob scores
if (!isImpProb) {
SummaryStatistics muStats = new SummaryStatistics();
SummaryStatistics sigmaStats = new SummaryStatistics();
SummaryStatistics shapeStats = new SummaryStatistics();
for (float[] impostorScores : impostorScoresArray) {
double[] scores = new double[impostorScores.length];
for (int i = 0; i < impostorScores.length; i++) {
scores[i] = impostorScores[i];
}
GaussianParetoDistribution dist = new GaussianParetoDistribution(scores);
shapeStats.addValue(dist.getShape());
muStats.addValue(dist.getMu());
sigmaStats.addValue(dist.getSigma());
}
String type = cmd.get("type");
if (muStats.getN() < 100) {
System.out.printf("Warning: result is statistically weak as not enough data recorded: %d < 100%n", muStats.getN());
}
// System.out.println("mu_stats:"+muStats);
// System.out.println("sigma_stats:"+sigmaStats);
// System.out.println("shape_stats:"+shapeStats);
System.out.printf("calibration.impostor_mu.print_%s=%.3f%n", type, muStats.getMean());
System.out.printf("calibration.impostor_sigma.print_%s=%.3f%n", type, sigmaStats.getMean());
System.out.printf("calibration.impostor_shape.print_%s=%.3f%n", type, shapeStats.getMean());
}
}
示例4: getKernel
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
/**
* The within-bin smoothing kernel. Returns a Gaussian distribution
* parameterized by {@code bStats}, unless the bin contains only one
* observation, in which case a constant distribution is returned.
*
* @param bStats summary statistics for the bin
* @return within-bin kernel parameterized by bStats
*/
protected RealDistribution getKernel(SummaryStatistics bStats) {
if (bStats.getN() == 1 || bStats.getVariance() == 0) {
return new ConstantRealDistribution(bStats.getMean());
} else {
return new NormalDistribution(randomData.getRandomGenerator(),
bStats.getMean(), bStats.getStandardDeviation(),
NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
}
示例5: computeAll
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
public SummaryStatistics[] computeAll() {
SummaryStatistics[] results = new SummaryStatistics[retrievers.length];
for (int i = 0; i < retrievers.length; i++)
results[i] = new SummaryStatistics();
IntSet queries = groundtruth.queriesWithRelevantDocs();
ProgressLogger pl = new ProgressLogger(LOGGER, "query retrievals");
pl.expectedUpdates = queries.size() * retrievers.length;
pl.start("Computing results for each of the " + queries.size() +
" queries and "+retrievers.length+ " retrieving algorithms..." );
for (int query : queries) {
for (int i = 0; i < retrievers.length; i++) {
double value = computeForQuery(query, retrievers[i]);
if (Double.isNaN(value))
continue;
results[i].addValue(value);
pl.update();
}
}
pl.done();
long nItems = results[0].getN();
for (SummaryStatistics s : results)
if (s.getN() != nItems)
throw new IllegalStateException("The measure returned NaN differently for different algorithms.");
print(retrievers, results);
return results;
}
示例6: getKernel
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
/**
* The within-bin smoothing kernel. Returns a Gaussian distribution
* parameterized by {@code bStats}, unless the bin contains only one
* observation, in which case a constant distribution is returned.
*
* @param bStats summary statistics for the bin
* @return within-bin kernel parameterized by bStats
*/
protected RealDistribution getKernel(SummaryStatistics bStats) {
if (bStats.getN() == 1) {
return new ConstantRealDistribution(bStats.getMean());
} else {
return new NormalDistribution(randomData.getRandomGenerator(),
bStats.getMean(), bStats.getStandardDeviation(),
NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
}
示例7: calcMeanCI
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
private static double calcMeanCI(SummaryStatistics stats, double level) {
try {
TDistribution tDist = new TDistribution(stats.getN() - 1);
double critVal = tDist.inverseCumulativeProbability(1.0 - (1 - level) / 2);
return critVal * stats.getStandardDeviation() / Math.sqrt(stats.getN());
} catch (MathIllegalArgumentException e) {
return Double.NaN;
}
}
示例8: computeSystemStats
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
public void computeSystemStats() throws UnknownOWLClassException {
Set<OWLNamedIndividual> insts = this.getAllElements();
LOG.info("Computing system stats for " + insts.size() + " individuals");
LOG.info("Creating singular stat scores for all IDspaces");
Collection<SummaryStatistics> aggregate = new ArrayList<SummaryStatistics>();
this.overallStats = new SummaryStatistics();
int counter = 0;
for (OWLNamedIndividual i : insts) {
counter++;
SummaryStatistics statsPerIndividual = computeIndividualStats(i);
//put this individual into the aggregate
if (statsPerIndividual.getN() == 0) {
LOG.error("No annotations found for Individual "+i.toStringID());
} else {
aggregate.add(statsPerIndividual);
}
//TODO: put this individual into an idSpace aggregate
// String idSpace = i.getIRI().getNamespace();
this.overallStats.addValue(statsPerIndividual.getMean());
if (counter % 1000 == 0) {
LOG.info("Finished "+counter+" individuals");
}
}
// this.aggregateStatsPerIndividual = AggregateSummaryStatistics.aggregate(aggregate);
StatsPerIndividual myStats = new StatsPerIndividual();
myStats.mean = getSummaryStatisticsForCollection(aggregate,Stat.MEAN);
myStats.sum = getSummaryStatisticsForCollection(aggregate,Stat.SUM);
myStats.min = getSummaryStatisticsForCollection(aggregate,Stat.MIN);
myStats.max = getSummaryStatisticsForCollection(aggregate,Stat.MAX);
myStats.n = getSummaryStatisticsForCollection(aggregate,Stat.N);
myStats.aggregate = AggregateSummaryStatistics.aggregate(aggregate);
this.overallSummaryStatsPerIndividual = myStats;
LOG.info("Finished computing overall statsPerIndividual:\n"+this.getSummaryStatistics().toString());
}
示例9: computeSystemStatsForSubgraph
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
public void computeSystemStatsForSubgraph(OWLClass c) throws UnknownOWLClassException {
Set<OWLNamedIndividual> insts = this.getAllElements();
LOG.info("Computing system stats for subgraph rooted at" + c.toString() +" with "+ insts.size() + " individuals");
// LOG.info("Creating singular stat scores for all IDspaces");
Collection<SummaryStatistics> aggregate = new ArrayList<SummaryStatistics>();
SummaryStatistics subgraphStats = new SummaryStatistics();
for (OWLNamedIndividual i : insts) {
SummaryStatistics statsPerIndividual = computeIndividualStatsForSubgraph(i,c);
//put this individual into the aggregate
if (statsPerIndividual.getN() == 0) {
//LOG.info("No annotations found in this subgraph for Individual "+i.toStringID());
} else {
//LOG.info(statsPerIndividual.getN()+" Annotations found in this subgraph for Individual "+i.toStringID());
aggregate.add(statsPerIndividual);
}
//TODO: put this individual into an idSpace aggregate
//String idSpace = i.getIRI().getNamespace();
subgraphStats.addValue(statsPerIndividual.getMean());
}
StatsPerIndividual myStats = new StatsPerIndividual();
myStats.mean = getSummaryStatisticsForCollection(aggregate,Stat.MEAN);
myStats.sum = getSummaryStatisticsForCollection(aggregate,Stat.SUM);
myStats.min = getSummaryStatisticsForCollection(aggregate,Stat.MIN);
myStats.max = getSummaryStatisticsForCollection(aggregate,Stat.MAX);
myStats.n = getSummaryStatisticsForCollection(aggregate,Stat.N);
this.subgraphSummaryStatsPerIndividual.put(c, myStats);
LOG.info("Finished omputing system stats for subgraph rooted at" + c.toString());
}
示例10: calcMeanCI
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
private static double calcMeanCI( SummaryStatistics stats, double level )
{
// Create T Distribution with N-1 degrees of freedom
TDistribution tDist = new TDistribution( stats.getN() - 1 );
// Calculate critical value
double critVal = tDist.inverseCumulativeProbability( 1.0 - ( 1 - level ) / 2 );
// Calculate confidence interval
return critVal * stats.getStandardDeviation() / Math.sqrt( stats.getN() );
}
示例11: add
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
@Override
public void add(String cacheName, TransactionStats txStats)
{
boolean registerCacheStats = false;
WriteLock writeLock = getWriteLock(cacheName);
writeLock.lock();
try
{
// Are we adding new stats for a previously unseen cache?
registerCacheStats = !cacheToStatsMap.containsKey(cacheName);
if (registerCacheStats)
{
// There are no statistics yet for this cache.
cacheToStatsMap.put(cacheName, new HashMap<OpType, OperationStats>());
}
Map<OpType, OperationStats> cacheStats = cacheToStatsMap.get(cacheName);
for (OpType opType : OpType.values())
{
SummaryStatistics txOpSummary = txStats.getTimings(opType);
long count = txOpSummary.getN();
double totalTime = txOpSummary.getSum();
OperationStats oldStats = cacheStats.get(opType);
OperationStats newStats;
if (oldStats == null)
{
newStats = new OperationStats(totalTime, count);
}
else
{
newStats = new OperationStats(oldStats, totalTime, count);
}
cacheStats.put(opType, newStats);
}
}
finally
{
writeLock.unlock();
}
if (registerCacheStats)
{
// We've added stats for a previously unseen cache, raise an event
// so that an MBean for the cache may be registered, for example.
applicationContext.publishEvent(new CacheStatisticsCreated(this, cacheName));
}
}
示例12: getCount
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
public long getCount(OpType op)
{
SummaryStatistics stats = getTimings(op);
return stats.getN();
}
示例13: anovaStats
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
/**
* This method actually does the calculations (except P-value).
*
* @param categoryData <code>Collection</code> of <code>double[]</code>
* arrays each containing data for one category
* @param allowOneElementData if true, allow computation for one catagory
* only or for one data element per category
* @return computed AnovaStats
* @throws NullArgumentException if <code>categoryData</code> is <code>null</code>
* @throws DimensionMismatchException if <code>allowOneElementData</code> is false and the number of
* categories is less than 2 or a contained SummaryStatistics does not contain
* at least two values
*/
private AnovaStats anovaStats(final Collection<SummaryStatistics> categoryData,
final boolean allowOneElementData)
throws NullArgumentException, DimensionMismatchException {
MathUtils.checkNotNull(categoryData);
if (!allowOneElementData) {
// check if we have enough categories
if (categoryData.size() < 2) {
throw new DimensionMismatchException(LocalizedFormats.TWO_OR_MORE_CATEGORIES_REQUIRED,
categoryData.size(), 2);
}
// check if each category has enough data
for (final SummaryStatistics array : categoryData) {
if (array.getN() <= 1) {
throw new DimensionMismatchException(LocalizedFormats.TWO_OR_MORE_VALUES_IN_CATEGORY_REQUIRED,
(int) array.getN(), 2);
}
}
}
int dfwg = 0;
double sswg = 0;
double totsum = 0;
double totsumsq = 0;
int totnum = 0;
for (final SummaryStatistics data : categoryData) {
final double sum = data.getSum();
final double sumsq = data.getSumsq();
final int num = (int) data.getN();
totnum += num;
totsum += sum;
totsumsq += sumsq;
dfwg += num - 1;
final double ss = sumsq - ((sum * sum) / num);
sswg += ss;
}
final double sst = totsumsq - ((totsum * totsum) / totnum);
final double ssbg = sst - sswg;
final int dfbg = categoryData.size() - 1;
final double msbg = ssbg / dfbg;
final double mswg = sswg / dfwg;
final double F = msbg / mswg;
return new AnovaStats(dfbg, dfwg, F);
}
示例14: doBins
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
public static BinnedData doBins(IDocument<?> o)
{
// collate the values into an array
double[] data = new double[o.size()];
// Add the data from the array
Iterator<Double> oIter = o.getIndexIterator();
int ctr = 0;
while(oIter.hasNext())
{
data[ctr++] = oIter.next();
}
// Get a DescriptiveStatistics instance
DescriptiveStatistics stats = new DescriptiveStatistics(data);
// also do some frequency binning
double range = stats.getMax() - stats.getMin();
// aah, double-check we don't have zero range
final int binCount;
final int maxRange = 30;
if (range > maxRange)
{
binCount = maxRange;
}
else
{
binCount = (int) Math.max(2, range);
}
BinnedData res = new BinnedData();
if (range > THRESHOLD_VALUE)
{
long[] histogram = new long[binCount];
EmpiricalDistribution distribution = new EmpiricalDistribution(binCount);
distribution.load(data);
int k = 0;
for (SummaryStatistics sStats : distribution.getBinStats())
{
histogram[k++] = sStats.getN();
}
long rangeSoFar = (long) stats.getMin();
long rangeStep = (long) (range / binCount);
for (int i = 0; i < histogram.length; i++)
{
long l = histogram[i];
res.add(new Bin(rangeSoFar, rangeSoFar + rangeStep, l));
rangeSoFar += rangeStep;
}
}
return res;
}
示例15: binTheseValues
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
public static BinnedData binTheseValues(double[] data)
{
// Get a DescriptiveStatistics instance
DescriptiveStatistics stats = new DescriptiveStatistics(data);
// also do some frequency binning
double range = stats.getMax() - stats.getMin();
// aah, double-check we don't have zero range
final int binCount;
if (range > DEFAULT_NUM_BINS)
{
binCount = DEFAULT_NUM_BINS;
}
else if(range > MIN_NUM_BINS)
{
binCount = (int) range;
}
else
{
binCount = MIN_NUM_BINS;
}
BinnedData res = new BinnedData();
if (range > THRESHOLD_VALUE)
{
long[] histogram = new long[binCount];
EmpiricalDistribution distribution = new EmpiricalDistribution(binCount);
distribution.load(data);
int k = 0;
for (SummaryStatistics sStats : distribution.getBinStats())
{
histogram[k++] = sStats.getN();
}
double rangeSoFar = stats.getMin();
double rangeStep = range / binCount;
for (int i = 0; i < histogram.length; i++)
{
long l = histogram[i];
res.add(new Bin(rangeSoFar, rangeSoFar + rangeStep, l));
rangeSoFar += rangeStep;
}
}
return res;
}