mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-14 14:32:37 +02:00
bug fix: param object randomize
This commit is contained in:
parent
6c043ed829
commit
31f11eda40
2 changed files with 11 additions and 9 deletions
|
|
@ -14,6 +14,7 @@ Observable Pattern for patameterization
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from transformations import Transformation,Logexp, NegativeLogexp, Logistic, __fixed__, FIXED, UNFIXED
|
from transformations import Transformation,Logexp, NegativeLogexp, Logistic, __fixed__, FIXED, UNFIXED
|
||||||
|
from ...util.misc import param_to_array
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
|
|
@ -740,7 +741,6 @@ class OptimizationHandlable(Indexable):
|
||||||
self.param_array.flat[f] = p
|
self.param_array.flat[f] = p
|
||||||
[np.put(self.param_array, ind[f[ind]], c.f(self.param_array.flat[ind[f[ind]]]))
|
[np.put(self.param_array, ind[f[ind]], c.f(self.param_array.flat[ind[f[ind]]]))
|
||||||
for c, ind in self.constraints.iteritems() if c != __fixed__]
|
for c, ind in self.constraints.iteritems() if c != __fixed__]
|
||||||
self._highest_parent_.tie.propagate_val()
|
|
||||||
|
|
||||||
self._optimizer_copy_transformed = False
|
self._optimizer_copy_transformed = False
|
||||||
self._trigger_params_changed()
|
self._trigger_params_changed()
|
||||||
|
|
@ -829,11 +829,11 @@ class OptimizationHandlable(Indexable):
|
||||||
self.update_model(False) # Switch off the updates
|
self.update_model(False) # Switch off the updates
|
||||||
self.optimizer_array = x # makes sure all of the tied parameters get the same init (since there's only one prior object...)
|
self.optimizer_array = x # makes sure all of the tied parameters get the same init (since there's only one prior object...)
|
||||||
# now draw from prior where possible
|
# now draw from prior where possible
|
||||||
x = self.param_array.copy()
|
x = param_to_array(self.param_array).flat.copy()
|
||||||
[np.put(x, ind, p.rvs(ind.size)) for p, ind in self.priors.iteritems() if not p is None]
|
[np.put(x, ind, p.rvs(ind.size)) for p, ind in self.priors.iteritems() if not p is None]
|
||||||
unfixlist = np.ones((self.size,),dtype=np.bool)
|
unfixlist = np.ones((self.size,),dtype=np.bool)
|
||||||
unfixlist[self.constraints[__fixed__]] = False
|
unfixlist[self.constraints[__fixed__]] = False
|
||||||
self.param_array[unfixlist] = x[unfixlist]
|
self.param_array.flat[unfixlist] = x[unfixlist]
|
||||||
self.update_model(True)
|
self.update_model(True)
|
||||||
|
|
||||||
#===========================================================================
|
#===========================================================================
|
||||||
|
|
|
||||||
|
|
@ -143,8 +143,9 @@ class ParameterizedTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_randomize(self):
|
def test_randomize(self):
|
||||||
ps = self.test1.param.view(np.ndarray).copy()
|
ps = self.test1.param.view(np.ndarray).copy()
|
||||||
|
self.test1.param[2:5].fix()
|
||||||
self.test1.param.randomize()
|
self.test1.param.randomize()
|
||||||
self.assertFalse(np.all(ps==self.test1.param))
|
self.assertFalse(np.all(ps==self.test1.param),str(ps)+str(self.test1.param))
|
||||||
|
|
||||||
def test_fixing_randomize_parameter_handling(self):
|
def test_fixing_randomize_parameter_handling(self):
|
||||||
self.rbf.fix(warning=True)
|
self.rbf.fix(warning=True)
|
||||||
|
|
@ -152,11 +153,12 @@ class ParameterizedTest(unittest.TestCase):
|
||||||
self.test1.kern.randomize()
|
self.test1.kern.randomize()
|
||||||
self.assertEqual(val, self.rbf.variance)
|
self.assertEqual(val, self.rbf.variance)
|
||||||
|
|
||||||
def test_updates(self):
|
# def test_updates(self):
|
||||||
self.test1.update_model(False)
|
# # WHAT DO YOU WANT TO TEST HERE?
|
||||||
val = float(self.rbf.variance)
|
# self.test1.update_model(False)
|
||||||
self.test1.kern.randomize()
|
# val = float(self.rbf.variance)
|
||||||
self.assertEqual(val, self.rbf.variance)
|
# self.test1.kern.randomize()
|
||||||
|
# self.assertEqual(val, self.rbf.variance,str(self.test1))
|
||||||
|
|
||||||
def test_fixing_optimize(self):
|
def test_fixing_optimize(self):
|
||||||
self.testmodel.kern.lengthscale.fix()
|
self.testmodel.kern.lengthscale.fix()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue