Skip to content
Snippets Groups Projects
Commit 6b937e9c authored by Vincent Michel's avatar Vincent Michel
Browse files

Add samples_generator folder for simulated data

git-svn-id: https://scikit-learn.svn.sourceforge.net/svnroot/scikit-learn/trunk@440 22fbfee3-77ab-4535-9bad-27d1bd3bc7d8
parent 4c29de14
No related branches found
No related tags found
No related merge requests found
......@@ -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:]
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment