예제 #1
0
 def displacements(self,
                   select='all',
                   deltas=None,
                   srange=None,
                   sample_size=100,
                   corr=None,
                   stats=None):
     I = self.select(select)
     s = Sampler(*srange) if srange else Sampler(self.start, self.stop)
     if deltas is None:
         deltas = get_exponential_deltas(s.start, s.stop)
     if corr is None:
         corr = correlator
     if stats is None:
         stats = mean_var
     data = [[
         stats(data) for data in zip(*[
             iterable(corr(*self.get_rand_pair(s, delta), I))
             for _ in range(sample_size)
         ])
     ] for delta in deltas]
     results = [
         list(zip(*[dat[j] for dat in data])) for j in range(len(data[0]))
     ]
     return deltas, results
예제 #2
0
def chan_stats(x,m,v,s,k):
    xptr = x.ctypes.data_as(ctypes.POINTER(ctypes.c_float))
    stats_out = stats.stats(xptr, len(z), ctypes.byref(m),ctypes.byref(v), ctypes.byref(s), ctypes.byref(k))
    #print 'mean = %f, variance = %f, skew = %f, kurtosis = %f' %(m.value, v.value, s.value, k.value)
    #print 'expected values: %f, %f, %f, %f' %(mu, sig, scipy.stats.skew(x), scipy.stats.kurtosis(x))
    #norm_kurt = scipy.stats.kurtosistest(x)
    #print norm_kurt
    #count, bins, ignored = plt.hist(x, 500, normed=True)
    #plt.plot(bins, 1/(sig * np.sqrt(2 * np.pi)) * np.exp(-(bins-mu)**2 / (2*sig**2)))
    #plt.show()
    return np.array([m.value, v.value, s.value, k.value]) 
예제 #3
0
import numpy as np
import ctypes
import matplotlib.pyplot as plt
import scipy.stats

n = 1000000
mu = 0
sig = np.sqrt(0.1)
x = np.random.normal(mu,sig,n).astype(np.float32)
print x
m = ctypes.c_double()
v = ctypes.c_double()
s = ctypes.c_double()
k = ctypes.c_double()

stats = ctypes.cdll.LoadLibrary("./stats.so")
xptr = x.ctypes.data_as(ctypes.POINTER(ctypes.c_float))

stats.stats(xptr, n, ctypes.byref(m),ctypes.byref(v), ctypes.byref(s), ctypes.byref(k))
print 'mean = %f, variance = %f, skew = %f, kurtosis = %f' %(m.value, v.value, s.value, k.value)
print 'expected values: %f, %f, %f, %f' %(mu, sig, scipy.stats.skew(x), scipy.stats.kurtosis(x))
norm_kurt = scipy.stats.kurtosistest(x)
print norm_kurt
count, bins, ignored = plt.hist(x, 500, normed=True)
plt.plot(bins, 1/(sig * np.sqrt(2 * np.pi)) * np.exp(-(bins-mu)**2 / (2*sig**2)))
plt.show()
예제 #4
0
import ctypes
import matplotlib.pyplot as plt
import scipy.stats

n = 1000000
mu = 0
sig = np.sqrt(0.1)
x = np.random.normal(mu, sig, n).astype(np.float32)
print x
m = ctypes.c_double()
v = ctypes.c_double()
s = ctypes.c_double()
k = ctypes.c_double()

stats = ctypes.cdll.LoadLibrary("./stats.so")
xptr = x.ctypes.data_as(ctypes.POINTER(ctypes.c_float))

stats.stats(xptr, n, ctypes.byref(m), ctypes.byref(v), ctypes.byref(s),
            ctypes.byref(k))
print 'mean = %f, variance = %f, skew = %f, kurtosis = %f' % (m.value, v.value,
                                                              s.value, k.value)
print 'expected values: %f, %f, %f, %f' % (mu, sig, scipy.stats.skew(x),
                                           scipy.stats.kurtosis(x))
norm_kurt = scipy.stats.kurtosistest(x)
print norm_kurt
count, bins, ignored = plt.hist(x, 500, normed=True)
plt.plot(
    bins,
    1 / (sig * np.sqrt(2 * np.pi)) * np.exp(-(bins - mu)**2 / (2 * sig**2)))
plt.show()
예제 #5
0
 def ave_vol(self, srange=None, sample_size=100, stats=None):
     s = Sampler(*srange) if srange else Sampler(self.start, self.stop)
     if stats is None:
         stats = mean_var
     v = stats([self[s.sample()].get_volume() for _ in range(sample_size)])
     return v