mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-11 21:12:38 +02:00
[stochastics] holds stochastic updates and rules
This commit is contained in:
parent
26396939e5
commit
3d45870846
1 changed files with 48 additions and 0 deletions
48
GPy/inference/optimization/stochastics.py
Normal file
48
GPy/inference/optimization/stochastics.py
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
'''
|
||||||
|
Created on 9 Oct 2014
|
||||||
|
|
||||||
|
@author: maxz
|
||||||
|
'''
|
||||||
|
|
||||||
|
class StochasticStorage(object):
|
||||||
|
'''
|
||||||
|
This is a container for holding the stochastic parameters,
|
||||||
|
such as subset indices or step length and so on.
|
||||||
|
'''
|
||||||
|
def __init__(self, model):
|
||||||
|
"""
|
||||||
|
Initialize this stochastic container using the given model
|
||||||
|
"""
|
||||||
|
|
||||||
|
def do_stochastics(self):
|
||||||
|
"""
|
||||||
|
Update the internal state to the next batch of the stochastic
|
||||||
|
descent algorithm.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
class SparseGPMissing(StochasticStorage):
|
||||||
|
def __init__(self, model, batchsize=1):
|
||||||
|
self.d = xrange(model.Y_normalized.shape[1])
|
||||||
|
|
||||||
|
class SparseGPStochastics(StochasticStorage):
|
||||||
|
"""
|
||||||
|
For the sparse gp we need to store the dimension we are in,
|
||||||
|
and the indices corresponding to those
|
||||||
|
"""
|
||||||
|
def __init__(self, model, batchsize=1):
|
||||||
|
import itertools
|
||||||
|
self.batchsize = batchsize
|
||||||
|
if self.batchsize == 1:
|
||||||
|
self.dimensions = itertools.cycle(range(model.Y_normalized.shape[1]))
|
||||||
|
else:
|
||||||
|
import numpy as np
|
||||||
|
self.dimensions = lambda: np.random.choice(model.Y_normalized.shape[1], size=batchsize, replace=False)
|
||||||
|
self.d = None
|
||||||
|
self.do_stochastics()
|
||||||
|
|
||||||
|
def do_stochastics(self):
|
||||||
|
if self.batchsize == 1:
|
||||||
|
self.d = [self.dimensions.next()]
|
||||||
|
else:
|
||||||
|
self.d = self.dimensions()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue