本文整理汇总了Java中org.apache.commons.math3.stat.Frequency类的典型用法代码示例。如果您正苦于以下问题:Java Frequency类的具体用法?Java Frequency怎么用?Java Frequency使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Frequency类属于org.apache.commons.math3.stat包,在下文中一共展示了Frequency类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkNextIntUniform
import org.apache.commons.math3.stat.Frequency; //导入依赖的package包/类
private void checkNextIntUniform(int min, int max) {
final Frequency freq = new Frequency();
for (int i = 0; i < smallSampleSize; i++) {
final int value = randomData.nextInt(min, max);
Assert.assertTrue("nextInt range", (value >= min) && (value <= max));
freq.addValue(value);
}
final int len = max - min + 1;
final long[] observed = new long[len];
for (int i = 0; i < len; i++) {
observed[i] = freq.getCount(min + i);
}
final double[] expected = new double[len];
for (int i = 0; i < len; i++) {
expected[i] = 1d / len;
}
TestUtils.assertChiSquareAccept(expected, observed, 0.001);
}
示例2: checkNextLongUniform
import org.apache.commons.math3.stat.Frequency; //导入依赖的package包/类
private void checkNextLongUniform(long min, long max) {
final Frequency freq = new Frequency();
for (int i = 0; i < smallSampleSize; i++) {
final long value = randomData.nextLong(min, max);
Assert.assertTrue("nextLong range: " + value + " " + min + " " + max,
(value >= min) && (value <= max));
freq.addValue(value);
}
final int len = ((int) (max - min)) + 1;
final long[] observed = new long[len];
for (int i = 0; i < len; i++) {
observed[i] = freq.getCount(min + i);
}
final double[] expected = new double[len];
for (int i = 0; i < len; i++) {
expected[i] = 1d / len;
}
TestUtils.assertChiSquareAccept(expected, observed, 0.01);
}
示例3: checkNextSecureLongUniform
import org.apache.commons.math3.stat.Frequency; //导入依赖的package包/类
private void checkNextSecureLongUniform(int min, int max) {
final Frequency freq = new Frequency();
for (int i = 0; i < smallSampleSize; i++) {
final long value = randomData.nextSecureLong(min, max);
Assert.assertTrue("nextLong range", (value >= min) && (value <= max));
freq.addValue(value);
}
final int len = max - min + 1;
final long[] observed = new long[len];
for (int i = 0; i < len; i++) {
observed[i] = freq.getCount(min + i);
}
final double[] expected = new double[len];
for (int i = 0; i < len; i++) {
expected[i] = 1d / len;
}
TestUtils.assertChiSquareAccept(expected, observed, 0.0001);
}
示例4: checkNextSecureIntUniform
import org.apache.commons.math3.stat.Frequency; //导入依赖的package包/类
private void checkNextSecureIntUniform(int min, int max) {
final Frequency freq = new Frequency();
for (int i = 0; i < smallSampleSize; i++) {
final int value = randomData.nextSecureInt(min, max);
Assert.assertTrue("nextInt range", (value >= min) && (value <= max));
freq.addValue(value);
}
final int len = max - min + 1;
final long[] observed = new long[len];
for (int i = 0; i < len; i++) {
observed[i] = freq.getCount(min + i);
}
final double[] expected = new double[len];
for (int i = 0; i < len; i++) {
expected[i] = 1d / len;
}
TestUtils.assertChiSquareAccept(expected, observed, 0.0001);
}
示例5: doBins
import org.apache.commons.math3.stat.Frequency; //导入依赖的package包/类
public static BinnedData doBins(IDocument<?> collection)
{
// build up the histogram
Frequency freq = new Frequency();
Iterator<?> iter2 = collection.getIterator();
while (iter2.hasNext())
{
Object object = (Object) iter2.next();
freq.addValue(object.toString());
}
BinnedData res = new BinnedData();
Iterator<Comparable<?>> vIter = freq.valuesIterator();
while (vIter.hasNext())
{
Comparable<?> value = vIter.next();
res.add(new Bin(value, freq.getCount(value)));
}
return res;
}
示例6: checkNextLongUniform
import org.apache.commons.math3.stat.Frequency; //导入依赖的package包/类
private void checkNextLongUniform(int min, int max) {
final Frequency freq = new Frequency();
for (int i = 0; i < smallSampleSize; i++) {
final long value = randomData.nextLong(min, max);
Assert.assertTrue("nextLong range", (value >= min) && (value <= max));
freq.addValue(value);
}
final int len = max - min + 1;
final long[] observed = new long[len];
for (int i = 0; i < len; i++) {
observed[i] = freq.getCount(min + i);
}
final double[] expected = new double[len];
for (int i = 0; i < len; i++) {
expected[i] = 1d / len;
}
TestUtils.assertChiSquareAccept(expected, observed, 0.01);
}
示例7: getCDF
import org.apache.commons.math3.stat.Frequency; //导入依赖的package包/类
public static void getCDF(int rangeI, int rangeF, int increment) {
long startTime = -1;
valuesFreq = new Frequency();
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
if (scanner.hasNextLong()) {
long opStartTime = scanner.nextLong();
long opTime = scanner.nextLong();
if (startTime == -1) {
startTime = opStartTime;
}
if (opStartTime - startTime > WARMUP_TIME)
valuesFreq.addValue(opTime);
} else
scanner.nextLine();
}
scanner.close();
System.out.printf("LAT\tCUM_FREQ\n");
for (int i = rangeI; i <= rangeF; i += increment) {
System.out.printf("%d\t%f\n", i, valuesFreq.getCumPct(i));
}
}
示例8: getFreqStats
import org.apache.commons.math3.stat.Frequency; //导入依赖的package包/类
public void getFreqStats(double[] values){
Frequency freq = new Frequency();
for( int i = 0; i < values.length; i++) {
freq.addValue(values[i]);
}
for( int i = 0; i < values.length; i++) {
System.out.println(freq.getCount(values[i]));
}
}
示例9: getFreqStats
import org.apache.commons.math3.stat.Frequency; //导入依赖的package包/类
public void getFreqStats(String[] words){
Frequency freq = new Frequency();
for( int i = 0; i < words.length; i++) {
freq.addValue(words[i].trim());
}
for( int i = 0; i < words.length; i++) {
System.out.println(words[i] + "=" + freq.getCount(words[i]));
}
}
示例10: formatFrequency
import org.apache.commons.math3.stat.Frequency; //导入依赖的package包/类
public static String formatFrequency(Frequency frequency, int maxCount) {
List<Map.Entry<Comparable<?>, Long>> list = sortByFrequency(frequency);
String result = "";
for (int i = 0; i < maxCount && i < list.size(); i++) {
String percent = String.format(Locale.US, "%.0f",
frequency.getPct(list.get(i).getKey()) * 100) + "%";
result += list.get(i).getKey() + ","
+ list.get(i).getValue() + ","
+ percent + "\n";
}
return result;
}
示例11: sortByFrequency
import org.apache.commons.math3.stat.Frequency; //导入依赖的package包/类
public static List<Map.Entry<Comparable<?>, Long>> sortByFrequency(Frequency frequency) {
Iterator<Map.Entry<Comparable<?>, Long>> iterator = frequency.entrySetIterator();
List<Map.Entry<Comparable<?>, Long>> list = new ArrayList<Map.Entry<Comparable<?>, Long>>();
while (iterator.hasNext()) {
Map.Entry<Comparable<?>, Long> entry = iterator.next();
list.add(entry);
}
Comparator<Map.Entry<Comparable<?>, Long>> comparator =
new Comparator<Map.Entry<Comparable<?>, Long>>() {
@Override
public int compare(Map.Entry<Comparable<?>, Long> arg0,
Map.Entry<Comparable<?>, Long> arg1) {
if (arg0 == null || arg1 == null) {
throw new NullPointerException();
}
return -Long.compare(arg0.getValue(), arg1.getValue());
}
};
Collections.sort(list, comparator);
return list;
}
示例12: formatTopItems
import org.apache.commons.math3.stat.Frequency; //导入依赖的package包/类
public String formatTopItems(Frequency frequency, int maxCount) {
itemStore.flushItems();
List<Map.Entry<Comparable<?>, Long>> list = FrequencyUtils.sortByFrequency(frequency);
String result = "";
for (int i = 0; i < maxCount && i < list.size(); i++) {
// String percent = String.format(Locale.US, "%.0f", frequency.getPct(list.get(i).getKey()) * 100) + "%";
int itemId = (int) (long) ((Long) list.get(i).getKey());
int count = (int) (long) ((Long) list.get(i).getValue());
String label = null;
Integer instanceOfId = null;
String instanceOfLabel = null;
DbItem item = itemStore.getItem(itemId);
if (item != null) {
label = item.getLabel();
instanceOfId = item.getInstanceOfId();
if (instanceOfId != null) {
DbItem instanceOfItem = itemStore.getItem(instanceOfId);
if (instanceOfItem != null) {
instanceOfLabel = instanceOfItem.getLabel();
}
}
}
result += itemId + "," + count + "," + label + "," + instanceOfId + "," + instanceOfLabel + "\n";
}
return result;
}
示例13: frequency
import org.apache.commons.math3.stat.Frequency; //导入依赖的package包/类
public ReflexValue frequency(List<ReflexValue> params) {
if (params.size() != 1) {
throw new ReflexException(-1, "frequency needs one list parameter");
}
if (!params.get(0).isList()) {
throw new ReflexException(-1, "frequency needs one list parameter");
}
Frequency f = new Frequency();
List<ReflexValue> values = params.get(0).asList();
for (ReflexValue v : values) {
f.addValue(v.asDouble());
}
return new ReflexValue(f);
}
示例14: frequency_count
import org.apache.commons.math3.stat.Frequency; //导入依赖的package包/类
public ReflexValue frequency_count(List<ReflexValue> params) {
if (params.size() != 2) {
throw new ReflexException(-1, "frequency_count needs one frequency parameter and one value parameter");
}
Frequency f = params.get(0).asObjectOfType(Frequency.class);
double value = params.get(1).asDouble();
return new ReflexValue(f.getCount(value));
}
示例15: frequency_cum_pct
import org.apache.commons.math3.stat.Frequency; //导入依赖的package包/类
public ReflexValue frequency_cum_pct(List<ReflexValue> params) {
if (params.size() != 2) {
throw new ReflexException(-1, "frequency_count needs one frequency parameter and one value parameter");
}
Frequency f = params.get(0).asObjectOfType(Frequency.class);
double value = params.get(1).asDouble();
return new ReflexValue(f.getCumPct(value));
}