commit in quantile test

This commit is contained in:
tqchen
2014-11-10 16:44:07 -08:00
parent d4c4ee0b01
commit 7b8ba268dc
4 changed files with 305 additions and 225 deletions

View File

@@ -1,5 +1,5 @@
export CC = gcc
export CXX = g++
export CXX = clang++
export MPICXX = mpicxx
export LDFLAGS= -pthread -lm
export CFLAGS = -Wall -O3 -msse2 -Wno-unknown-pragmas -fPIC -I../src

35
test/mkquantest.py Executable file
View File

@@ -0,0 +1,35 @@
#!/usr/bin/python
import math
import sys
import random
import subprocess
funcs = {
'seq': 'lambda n: sorted([(x,1) for x in range(1,n+1)], key = lambda x:random.random())',
'seqlogw': 'lambda n: sorted([(x, math.log(x)) for x in range(1,n+1)], key = lambda x:random.random())'
}
if len(sys.argv) < 3:
print 'Usage: python mkquantest.py <maxn> <eps> [generate-type] [ndata]|./test_quantile'
print 'Possible generate-types:'
for k, v in funcs.items():
print '\t%s: %s' % (k, v)
exit(-1)
random.seed(0)
maxn = int(sys.argv[1])
eps = float(sys.argv[2])
if len(sys.argv) > 3:
method = sys.argv[3]
assert method in funcs, ('cannot find method %s' % method)
else:
method = 'seq'
if len(sys.argv) > 4:
ndata = int(sys.argv[4])
assert ndata <= maxn, 'ndata must be smaller than maxn'
else:
ndata = maxn
fo = sys.stdout
fo.write('%d\t%g\n' % (maxn, eps))
for x, w in eval(funcs[method])(ndata):
fo.write(str(x)+'\t'+str(w)+'\n')

23
test/test_quantile.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include <vector>
#include <utils/quantile.h>
using namespace xgboost;
int main(int argc, char *argv[]) {
utils::WQuantileSketch<float, float> sketch;
size_t n;
double wsum = 0.0;
float eps, x, w;
utils::Check(scanf("%lu%f", &n, &eps) == 2, "needs to start with n eps");
sketch.Init(n, eps);
printf("nlevel = %lu, limit_size=%lu\n", sketch.nlevel, sketch.limit_size);
while (scanf("%f%f", &x, &w) == 2) {
sketch.Push(x, w);
wsum += w;
}
sketch.CheckValid(0.1);
utils::WQuantileSketch<float, float>::SummaryContainer out;
sketch.GetSummary(&out);
printf("MaxError=%f/%f = %g\n", out.MaxError(), wsum, out.MaxError() / wsum);
out.Print();
return 0;
}