def test_fast_cvm(n_samples=1000): random = RandomState() data1 = random.uniform(size=n_samples) weights1 = random.uniform(size=n_samples) mask = random.uniform(size=n_samples) > 0.5 data2 = data1[mask] weights2 = weights1[mask] a = cvm_2samp(data1, data2, weights1, weights2) prepared_data1, prepared_weights1, F1 = prepare_distibution(data1, weights1) b = _cvm_2samp_fast(prepared_data1, data2, prepared_weights1, weights2, F1=F1) assert numpy.allclose(a, b)
def test_ks2samp_fast(size=1000): y1 = RandomState().uniform(size=size) y2 = y1[RandomState().uniform(size=size) > 0.5] a = ks_2samp(y1, y2)[0] prep_data, prep_weights, prep_F = prepare_distibution(y1, numpy.ones(len(y1))) b = _ks_2samp_fast(prep_data, y2, prep_weights, numpy.ones(len(y2)), F1=prep_F) c = _ks_2samp_fast(prep_data, y2, prep_weights, numpy.ones(len(y2)), F1=prep_F) d = ks_2samp_weighted(y1, y2, numpy.ones(len(y1)) / 3, numpy.ones(len(y2)) / 4) assert numpy.allclose(a, b, rtol=1e-2, atol=1e-3) assert numpy.allclose(b, c) assert numpy.allclose(b, d) print('ks2samp is ok')
def test_fast_cvm(n_samples=1000): random = RandomState() data1 = random.uniform(size=n_samples) weights1 = random.uniform(size=n_samples) mask = random.uniform(size=n_samples) > 0.5 data2 = data1[mask] weights2 = weights1[mask] a = cvm_2samp(data1, data2, weights1, weights2) prepared_data1, prepared_weights1, F1 = prepare_distibution( data1, weights1) b = _cvm_2samp_fast(prepared_data1, data2, prepared_weights1, weights2, F1=F1) assert numpy.allclose(a, b)
def test_ks2samp_fast(size=1000): y1 = RandomState().uniform(size=size) y2 = y1[RandomState().uniform(size=size) > 0.5] a = ks_2samp(y1, y2)[0] prep_data, prep_weights, prep_F = prepare_distibution( y1, numpy.ones(len(y1))) b = _ks_2samp_fast(prep_data, y2, prep_weights, numpy.ones(len(y2)), F1=prep_F) c = _ks_2samp_fast(prep_data, y2, prep_weights, numpy.ones(len(y2)), F1=prep_F) d = ks_2samp_weighted(y1, y2, numpy.ones(len(y1)) / 3, numpy.ones(len(y2)) / 4) assert numpy.allclose(a, b, rtol=1e-2, atol=1e-3) assert numpy.allclose(b, c) assert numpy.allclose(b, d) print('ks2samp is ok')