def rapid(self): a, b = 5, 100 x_sim = np.linspace(wald.ppf(0.01), wald.ppf(0.99), self.n_intervals) y = np.exp(wald.pdf(x_sim) / 2) y[2:] = y[:-2] y[:2] = 1 return y
def rapid(self): a, b = 5, 100 y = np.linspace(wald.ppf(0.01), wald.ppf(0.99), self.n_effective_intervals) y = np.exp(wald.pdf(y) / 1.6) y[2:] = y[:-2] y[:2] = 1 effect = np.ones(self.n_intervals) effect[0:self.n_effective_intervals] = y return effect
'/home/fearofchou/data/KKBOX/libfm/tr_te_data_BS/split_by_month/short_term_playcount/ID_02*' ) with open( '/home/fearofchou/data/KKBOX/libfm/tr_te_data_BS/split_by_month/short_term_playcount/rel_target_02.test' ) as f: true = np.array(f.readlines()).astype('int') with open( '/home/fearofchou/data/KKBOX/fearure_extraction/song_age/rel_songage_201212201301' ) as f: sa = np.array(f.readlines()).astype('int') f_sa = sa for idx, val in enumerate(sa): if val > 12: f_sa[idx] = 12 if val < 0: f_sa[idx] = 0 pred = {} for fn in fl: with open(fn) as f: pred[fn.split('/')[-1]] = np.array(f.readlines()).astype('float') x = pl.frange(0, 1.3, 0.1) wald_dis = wald.pdf(x, 0, 0.5) f_sa = f_sa + 1 for fn in pred.keys(): wald_pred = (wald_dis[f_sa] * pred[fn] + pred[fn]) / 2 print fn print np.sqrt(((true - wald_pred)**2).mean())
def density(self, x, _mu=None, _sigma=None): return wald.pdf(x, loc=_mu, scale=_sigma)
def z(a): return wald.pdf(1-a)
from scipy.stats import wald import matplotlib.pyplot as plt fig, ax = plt.subplots(1, 1) # Calculate a few first moments: mean, var, skew, kurt = wald.stats(moments='mvsk') # Display the probability density function (``pdf``): x = np.linspace(wald.ppf(0.01), wald.ppf(0.99), 100) ax.plot(x, wald.pdf(x), 'r-', lw=5, alpha=0.6, label='wald pdf') # Alternatively, the distribution object can be called (as a function) # to fix the shape, location and scale parameters. This returns a "frozen" # RV object holding the given parameters fixed. # Freeze the distribution and display the frozen ``pdf``: rv = wald() ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf') # Check accuracy of ``cdf`` and ``ppf``: vals = wald.ppf([0.001, 0.5, 0.999]) np.allclose([0.001, 0.5, 0.999], wald.cdf(vals)) # True # Generate random numbers: r = wald.rvs(size=1000)
''' import glob fl = glob.glob('/home/fearofchou/data/KKBOX/libfm/tr_te_data_BS/split_by_month/short_term_playcount/ID_02*') with open('/home/fearofchou/data/KKBOX/libfm/tr_te_data_BS/split_by_month/short_term_playcount/rel_target_02.test') as f: true = np.array(f.readlines()).astype('int') with open('/home/fearofchou/data/KKBOX/fearure_extraction/song_age/rel_songage_201212201301') as f: sa = np.array(f.readlines()).astype('int') f_sa = sa for idx,val in enumerate(sa): if val>12: f_sa[idx]=12 if val<0: f_sa[idx]=0 pred = {} for fn in fl: with open(fn) as f: pred[fn.split('/')[-1]] = np.array(f.readlines()).astype('float') x = pl.frange(0,1.3,0.1) wald_dis = wald.pdf(x,0,0.5) f_sa =f_sa+1 for fn in pred.keys(): wald_pred=(wald_dis[f_sa]*pred[fn] + pred[fn])/2 print fn print np.sqrt( ((true-wald_pred)**2).mean() )
def data_prob(pm, y): return wald.pdf(y, pm['mu'], pm['lambda'])
from scipy.stats import wald import matplotlib.pyplot as plt fig, ax = plt.subplots(1, 1) # Calculate a few first moments: mean, var, skew, kurt = wald.stats(moments='mvsk') # Display the probability density function (``pdf``): x = np.linspace(wald.ppf(0.01), wald.ppf(0.99), 100) ax.plot(x, wald.pdf(x), 'r-', lw=5, alpha=0.6, label='wald pdf') # Alternatively, the distribution object can be called (as a function) # to fix the shape, location and scale parameters. This returns a "frozen" # RV object holding the given parameters fixed. # Freeze the distribution and display the frozen ``pdf``: rv = wald() ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf') # Check accuracy of ``cdf`` and ``ppf``: vals = wald.ppf([0.001, 0.5, 0.999]) np.allclose([0.001, 0.5, 0.999], wald.cdf(vals)) # True # Generate random numbers: