diff --git a/scikits/learn/bayes/bayes.py b/scikits/learn/bayes/bayes.py index 3e3ffa0769bb563fdd2153017b3bff66be2adbbe..f0aa191689d3f812d630d660003bd47632eb738a 100755 --- a/scikits/learn/bayes/bayes.py +++ b/scikits/learn/bayes/bayes.py @@ -97,11 +97,11 @@ def bayesian_ridge( X , Y, step_th=300,th_w = 1.e-6,ll_bool=True) : ### Compute the log likelihood if ll_bool : + residual_ = (Y - np.dot(X, w))**2 ll = 0.5*X.shape[1]*np.log(alpha) + 0.5*X.shape[0]*np.log(beta) - ll -= 0.5*beta*residual_.sum()+ 0.5*alpha*np.dot(w.T,w) - ll -= fast_logdet(inv_sigma_) + ll -= (0.5*beta*residual_.sum()+ 0.5*alpha*np.dot(w.T,w)) + ll -= fast_logdet(alpha*ones + beta*gram) ll -= X.shape[0]*np.log(2*np.pi) log_likelihood.append(ll) - return w - + return w,log_likelihood[1:] diff --git a/scikits/learn/samples_generator/linear.py b/scikits/learn/samples_generator/linear.py new file mode 100755 index 0000000000000000000000000000000000000000..72fc93c5369c97451965947bd405c4ead6dfc5e6 --- /dev/null +++ b/scikits/learn/samples_generator/linear.py @@ -0,0 +1,28 @@ +import numpy as np + + +def sparse_uncorrelated(nb_samples=100,nb_features=10): + """ + Function creating simulated data with sparse uncorrelated design. + (cf.Celeux et al. 2009, Bayesian regularization in regression) + X = NR.normal(0,1) + Y = NR.normal(2+X[:,2]+2*X[:,3]-2*X[:,6]-1.5*X[:,7]) + The number of features is at least 10. + + Parameters + ---------- + nb_samples : int + number of samples (defaut is 100). + nb_features : int + number of features (defaut is 10). + + Returns + ------- + X : numpy array of shape (nb_samples,nb_features) + simulated samples. + Y : numpy array of shape (nb_samples) + """ + X = nr.normal(loc=0,scale=1,size=(nb_samples,nb_features)) + Y = nr.normal(loc=2+x[:,2]+2*x[:,3]-2*x[:,6]-1.5*x[:,7], + scale=np.ones(nb_samples)) + return X,Y \ No newline at end of file