Commit 6c98a7ea authored by Sebastian Heimann's avatar Sebastian Heimann
Browse files

changed to bayesian bootstrap

parent 0f9e71fc
...@@ -216,21 +216,31 @@ class Problem(Object): ...@@ -216,21 +216,31 @@ class Problem(Object):
def combined(self): def combined(self):
return self.parameters + self.dependants return self.parameters + self.dependants
def make_bootstrap_weights(self, nbootstrap): def make_bootstrap_weights(self, nbootstrap, type='classic'):
ntargets = self.ntargets ntargets = self.ntargets
ws = num.zeros((nbootstrap, ntargets)) ws = num.zeros((nbootstrap, ntargets))
rstate = num.random.RandomState(23) rstate = num.random.RandomState(23)
for ibootstrap in xrange(nbootstrap): for ibootstrap in xrange(nbootstrap):
ii = rstate.randint(0, ntargets, size=self.ntargets) if type == 'classic':
ws[ibootstrap, :] = num.histogram( ii = rstate.randint(0, ntargets, size=self.ntargets)
ii, ntargets, (-0.5, ntargets - 0.5))[0] ws[ibootstrap, :] = num.histogram(
ii, ntargets, (-0.5, ntargets - 0.5))[0]
elif type == 'bayesian':
f = rstate.uniform(0., 1., size=self.ntargets+1)
f[0] = 0.
f[-1] = 1.
f = num.sort(f)
g = f[1:] - f[:-1]
ws[ibootstrap, :] = g * ntargets
else:
assert False
return ws return ws
def get_bootstrap_weights(self, ibootstrap=None): def get_bootstrap_weights(self, ibootstrap=None):
if self._bootstrap_weights is None: if self._bootstrap_weights is None:
self._bootstrap_weights = self.make_bootstrap_weights( self._bootstrap_weights = self.make_bootstrap_weights(
self.nbootstrap) self.nbootstrap, type='bayesian')
if ibootstrap is None: if ibootstrap is None:
return self._bootstrap_weights return self._bootstrap_weights
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment