本文整理汇总了Java中org.apache.commons.math3.stat.Frequency.getCount方法的典型用法代码示例。如果您正苦于以下问题:Java Frequency.getCount方法的具体用法?Java Frequency.getCount怎么用?Java Frequency.getCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.stat.Frequency
的用法示例。
在下文中一共展示了Frequency.getCount方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例6: 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));
}
示例7: checkNextUniformUniform
import org.apache.commons.math3.stat.Frequency; //导入方法依赖的package包/类
private void checkNextUniformUniform(double min, double max) {
// Set up bin bounds - min, binBound[0], ..., binBound[binCount-2], max
final int binCount = 5;
final double binSize = max / binCount - min/binCount; // Prevent overflow in extreme value case
final double[] binBounds = new double[binCount - 1];
binBounds[0] = min + binSize;
for (int i = 1; i < binCount - 1; i++) {
binBounds[i] = binBounds[i - 1] + binSize; // + instead of * to avoid overflow in extreme case
}
final Frequency freq = new Frequency();
for (int i = 0; i < smallSampleSize; i++) {
final double value = randomData.nextUniform(min, max);
Assert.assertTrue("nextUniform range", (value > min) && (value < max));
// Find bin
int j = 0;
while (j < binCount - 1 && value > binBounds[j]) {
j++;
}
freq.addValue(j);
}
final long[] observed = new long[binCount];
for (int i = 0; i < binCount; i++) {
observed[i] = freq.getCount(i);
}
final double[] expected = new double[binCount];
for (int i = 0; i < binCount; i++) {
expected[i] = 1d / binCount;
}
TestUtils.assertChiSquareAccept(expected, observed, 0.01);
}
示例8: testNextLongDirect
import org.apache.commons.math3.stat.Frequency; //导入方法依赖的package包/类
@Test
public void testNextLongDirect() {
long q1 = Long.MAX_VALUE/4;
long q2 = 2 * q1;
long q3 = 3 * q1;
Frequency freq = new Frequency();
long val = 0;
int value = 0;
for (int i=0; i<smallSampleSize; i++) {
val = generator.nextLong();
val = val < 0 ? -val : val;
if (val < q1) {
value = 0;
} else if (val < q2) {
value = 1;
} else if (val < q3) {
value = 2;
} else {
value = 3;
}
freq.addValue(value);
}
long[] observed = new long[4];
for (int i=0; i<4; i++) {
observed[i] = freq.getCount(i);
}
/* Use ChiSquare dist with df = 4-1 = 3, alpha = .001
* Change to 11.34 for alpha = .01
*/
Assert.assertTrue("chi-square test -- will fail about 1 in 1000 times",
testStatistic.chiSquare(expected,observed) < 16.27);
}
示例9: testNextFloatDirect
import org.apache.commons.math3.stat.Frequency; //导入方法依赖的package包/类
@Test
public void testNextFloatDirect() {
Frequency freq = new Frequency();
float val = 0;
int value = 0;
for (int i=0; i<smallSampleSize; i++) {
val = generator.nextFloat();
if (val < 0.25) {
value = 0;
} else if (val < 0.5) {
value = 1;
} else if (val < 0.75) {
value = 2;
} else {
value = 3;
}
freq.addValue(value);
}
long[] observed = new long[4];
for (int i=0; i<4; i++) {
observed[i] = freq.getCount(i);
}
/* Use ChiSquare dist with df = 4-1 = 3, alpha = .001
* Change to 11.34 for alpha = .01
*/
Assert.assertTrue("chi-square test -- will fail about 1 in 1000 times",
testStatistic.chiSquare(expected,observed) < 16.27);
}
示例10: publishTable
import org.apache.commons.math3.stat.Frequency; //导入方法依赖的package包/类
public void publishTable(VariableAttributes v){
TextTableColumnFormat[] cformats = new TextTableColumnFormat[6];
cformats[0] = new TextTableColumnFormat();
cformats[0].setStringFormat(11, TextTableColumnFormat.OutputAlignment.LEFT);
cformats[1] = new TextTableColumnFormat();
cformats[1].setIntFormat(10, TextTableColumnFormat.OutputAlignment.RIGHT);
cformats[2] = new TextTableColumnFormat();
cformats[2].setDoubleFormat(10, 4, TextTableColumnFormat.OutputAlignment.RIGHT);
cformats[3] = new TextTableColumnFormat();
cformats[3].setDoubleFormat(10, 4, TextTableColumnFormat.OutputAlignment.RIGHT);
cformats[4] = new TextTableColumnFormat();
cformats[4].setIntFormat(10, TextTableColumnFormat.OutputAlignment.RIGHT);
cformats[5] = new TextTableColumnFormat();
cformats[5].setDoubleFormat(10, 4, TextTableColumnFormat.OutputAlignment.RIGHT);
Frequency temp = frequencyTables.get(v);
TextTable table = new TextTable();
table.addAllColumnFormats(cformats, 4);
table.getRowAt(0).addHeader(0, 6, v.getName().toString(), TextTablePosition.CENTER);
table.getRowAt(1).addHorizontalRule(0, 6, "=");
table.getRowAt(2).addHeader(0, 1, "Value", TextTablePosition.CENTER);
table.getRowAt(2).addHeader(1, 1, "Frequency", TextTablePosition.CENTER);
table.getRowAt(2).addHeader(2, 1, "Percent", TextTablePosition.CENTER);
table.getRowAt(2).addHeader(3, 1, "Valid Pct.", TextTablePosition.CENTER);
table.getRowAt(2).addHeader(4, 1, "Cum. Freq.", TextTablePosition.CENTER);
table.getRowAt(2).addHeader(5, 1, "Cum. Pct.", TextTablePosition.CENTER);
table.getRowAt(3).addHorizontalRule(0, 6, "-");
Iterator<Comparable<?>> iter = temp.valuesIterator();
int index=4;
double pctSum = 0.0;
long validSum = temp.getSumFreq();
long miss = (long)(maxProgress - validSum);
while(iter.hasNext()){
table.addRow(new TextTableRow(cformats.length), cformats);
Comparable<?> value = iter.next();
table.addStringAt(index, 0, value.toString());
table.addLongAt(index, 1, temp.getCount(value));
table.addDoubleAt(index, 2, ((double)temp.getCount(value)/ maxProgress)*100);
table.addDoubleAt(index, 3, temp.getPct(value)*100);
table.addLongAt(index, 4, temp.getCumFreq(value));
table.addDoubleAt(index, 5, temp.getCumPct(value)*100);
index++;
pctSum += (double)temp.getCount(value)/(double) maxProgress;
}
table.addRow(new TextTableRow(cformats.length), cformats);
table.addStringAt(index, 0, "Valid Total");
table.addLongAt(index, 1, validSum);
table.addDoubleAt(index, 2, pctSum*100);
table.addDoubleAt(index, 3, (double)validSum/(double)(maxProgress -miss)*100);
index++;
table.addRow(new TextTableRow(cformats.length), cformats);
table.addStringAt(index, 0, "Missing");
table.addLongAt(index, 1, miss);
table.addDoubleAt(index, 2, ((double)miss/ maxProgress)*100);
index++;
table.addRow(new TextTableRow(cformats.length), cformats);
table.addStringAt(index, 0, "Grand Total");
table.addLongAt(index, 1, (long) maxProgress);
table.addDoubleAt(index, 2, ((double)(miss+temp.getSumFreq())/ maxProgress)*100);
index++;
table.addRow(new TextTableRow(cformats.length), cformats);
table.getRowAt(index).addHorizontalRule(0, 6, "=");
publish(table.toString() + "\n");
}