mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-11 15:15:15 +02:00
Merge branch 'devel' of github.com:SheffieldML/GPy into devel
This commit is contained in:
commit
2ad798f61d
6 changed files with 67 additions and 9 deletions
|
|
@ -66,7 +66,7 @@ class model(parameterised):
|
|||
|
||||
|
||||
# check constraints are okay
|
||||
if isinstance(what, (priors.gamma, priors.log_Gaussian)):
|
||||
if isinstance(what, (priors.gamma, priors.inverse_gamma, priors.log_Gaussian)):
|
||||
constrained_positive_indices = [i for i, t in zip(self.constrained_indices, self.constraints) if t.domain == 'positive']
|
||||
if len(constrained_positive_indices):
|
||||
constrained_positive_indices = np.hstack(constrained_positive_indices)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ class Gaussian(prior):
|
|||
:param mu: mean
|
||||
:param sigma: standard deviation
|
||||
|
||||
|
||||
.. Note:: Bishop 2006 notation is used throughout the code
|
||||
|
||||
"""
|
||||
|
|
@ -144,7 +143,6 @@ def gamma_from_EV(E,V):
|
|||
b = E/V
|
||||
return gamma(a,b)
|
||||
|
||||
|
||||
class gamma(prior):
|
||||
"""
|
||||
Implementation of the Gamma probability function, coupled with random variables.
|
||||
|
|
@ -155,7 +153,6 @@ class gamma(prior):
|
|||
.. Note:: Bishop 2006 notation is used throughout the code
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,a,b):
|
||||
self.a = float(a)
|
||||
self.b = float(b)
|
||||
|
|
@ -183,3 +180,30 @@ class gamma(prior):
|
|||
|
||||
def rvs(self,n):
|
||||
return np.random.gamma(scale=1./self.b,shape=self.a,size=n)
|
||||
|
||||
class inverse_gamma(prior):
|
||||
"""
|
||||
Implementation of the inverse-Gamma probability function, coupled with random variables.
|
||||
|
||||
:param a: shape parameter
|
||||
:param b: rate parameter (warning: it's the *inverse* of the scale)
|
||||
|
||||
.. Note:: Bishop 2006 notation is used throughout the code
|
||||
|
||||
"""
|
||||
def __init__(self,a,b):
|
||||
self.a = float(a)
|
||||
self.b = float(b)
|
||||
self.constant = -gammaln(self.a) + a*np.log(b)
|
||||
|
||||
def __str__(self):
|
||||
return "iGa("+str(np.round(self.a))+', '+str(np.round(self.b))+')'
|
||||
|
||||
def lnpdf(self,x):
|
||||
return self.constant - (self.a+1)*np.log(x) - self.b/x
|
||||
|
||||
def lnpdf_grad(self,x):
|
||||
return -(self.a+1.)/x + self.b/x**2
|
||||
|
||||
def rvs(self,n):
|
||||
return 1./np.random.gamma(scale=1./self.b,shape=self.a,size=n)
|
||||
|
|
|
|||
|
|
@ -313,9 +313,7 @@ def brendan_faces():
|
|||
m = GPy.models.GPLVM(Yn, Q)#, M=Y.shape[0]/4)
|
||||
|
||||
# optimize
|
||||
# m.constrain_fixed('white', 1e-2)
|
||||
# m.constrain_bounded('noise', 1e-6, 10)
|
||||
m.constrain('rbf', GPy.core.transformations.logexp_clipped())
|
||||
m.constrain('rbf|noise|white', GPy.core.transformations.logexp_clipped())
|
||||
|
||||
m.ensure_default_constraints()
|
||||
m.optimize('scg', messages=1, max_f_eval=10000)
|
||||
|
|
|
|||
|
|
@ -39,8 +39,10 @@ def SCG(f, gradf, x, optargs=(), maxiters=500, max_f_eval=500, display=True, xto
|
|||
function_eval number of fn evaluations
|
||||
status: string describing convergence status
|
||||
"""
|
||||
print " SCG"
|
||||
print ' {0:{mi}s} {1:11s} {2:11s} {3:11s}'.format("I", "F", "Scale", "|g|", mi=len(str(maxiters)))
|
||||
|
||||
if display:
|
||||
print " SCG"
|
||||
print ' {0:{mi}s} {1:11s} {2:11s} {3:11s}'.format("I", "F", "Scale", "|g|", mi=len(str(maxiters)))
|
||||
|
||||
if xtol is None:
|
||||
xtol = 1e-6
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import GPy
|
|||
import scipy.sparse
|
||||
import scipy.io
|
||||
import cPickle as pickle
|
||||
import urllib2 as url
|
||||
|
||||
data_path = os.path.join(os.path.dirname(__file__), 'datasets')
|
||||
default_seed = 10000
|
||||
|
||||
|
|
@ -15,6 +17,25 @@ def sample_class(f):
|
|||
c = np.where(c, 1, -1)
|
||||
return c
|
||||
|
||||
def fetch_dataset(resource, save_name = None, save_file = True, messages = True):
|
||||
if messages:
|
||||
print "Downloading resource: " , resource, " ... "
|
||||
response = url.urlopen(resource)
|
||||
# TODO: Some error checking...
|
||||
# ...
|
||||
html = response.read()
|
||||
response.close()
|
||||
if save_file:
|
||||
# TODO: Check if already exists...
|
||||
# ...
|
||||
with open(save_name, "w") as text_file:
|
||||
text_file.write("%s"%html)
|
||||
if messages:
|
||||
print "Done!"
|
||||
return html
|
||||
|
||||
|
||||
|
||||
def della_gatta_TRP63_gene_expression(gene_number=None):
|
||||
mat_data = scipy.io.loadmat(os.path.join(data_path, 'DellaGattadata.mat'))
|
||||
X = np.double(mat_data['timepoints'])
|
||||
|
|
|
|||
13
GPy/util/mocap_fetch.py
Normal file
13
GPy/util/mocap_fetch.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import GPy
|
||||
import urllib2
|
||||
|
||||
# TODO...
|
||||
class mocap_fetch(base_url = 'http://mocap.cs.cmu.edu:8080/subjects/', skel_store_dir = './', motion_store_dir = './'):
|
||||
def __init__(self):
|
||||
self.base_url = base_url
|
||||
self.store_dir = store_dir
|
||||
self.motion_dict = []
|
||||
|
||||
def fetch_motions(self, motion_dict = None):
|
||||
response = urllib2.urlopen(...)
|
||||
html = response.read()
|
||||
Loading…
Add table
Add a link
Reference in a new issue