A notebook to test and demonstrate LinearKernelSteinTest
.
In [ ]:
%load_ext autoreload
%autoreload 2
%matplotlib inline
#%config InlineBackend.figure_format = 'svg'
#%config InlineBackend.figure_format = 'pdf'
import kgof
import kgof.data as data
import kgof.density as density
import kgof.goftest as gof
import kgof.kernel as ker
import kgof.util as util
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats
In [ ]:
# font options
font = {
#'family' : 'normal',
#'weight' : 'bold',
'size' : 18
}
plt.rc('font', **font)
plt.rc('lines', linewidth=2)
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
In [ ]:
# true p
seed = 20
d = 1
mean = np.zeros(d)
variance = 1
isonorm = density.IsotropicNormal(mean, variance)
In [ ]:
# sample
n = 1000
# only one dimension of the mean is shifted
#draw_mean = mean + np.hstack((1, np.zeros(d-1)))
draw_mean = mean + 0
draw_variance = variance + 0
X = util.randn(n, d, seed=seed+2)*np.sqrt(draw_variance) + draw_mean
dat = data.Data(X)
In [ ]:
# Test
alpha = 0.01
sig2 = util.meddistance(X, subsample=1000)**2
k = ker.KGauss(sig2)
#k = ker.KGauss(1)
lin_kstein = gof.LinearKernelSteinTest(isonorm, k, alpha=alpha, seed=seed+1)
In [ ]:
lin_kstein_result = lin_kstein.perform_test(dat)
lin_kstein_result
#kstein.compute_stat(dat)
In [ ]:
In [ ]: