mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-09 12:02:38 +02:00
started copy implementation, have to get rid of _getstate_ and _setstate_
This commit is contained in:
parent
a126f288d2
commit
9cf37ff104
4 changed files with 20 additions and 28 deletions
|
|
@ -216,15 +216,16 @@ class GP(Model):
|
|||
|
||||
"""
|
||||
|
||||
return Model._getstate(self) + [self.X,
|
||||
self.num_data,
|
||||
self.input_dim,
|
||||
self.kern,
|
||||
self.likelihood,
|
||||
self.output_dim,
|
||||
]
|
||||
return []#Model._getstate(self) + [self.X,
|
||||
# self.num_data,
|
||||
# self.input_dim,
|
||||
# self.kern,
|
||||
# self.likelihood,
|
||||
# self.output_dim,
|
||||
# ]
|
||||
|
||||
def _setstate(self, state):
|
||||
return
|
||||
self.output_dim = state.pop()
|
||||
self.likelihood = state.pop()
|
||||
self.kern = state.pop()
|
||||
|
|
|
|||
|
|
@ -902,15 +902,19 @@ class Parameterizable(OptimizationHandlable):
|
|||
#===========================================================================
|
||||
def copy(self):
|
||||
"""Returns a (deep) copy of the current model"""
|
||||
raise NotImplementedError, "Copy is not yet implemented, TODO: Observable hierarchy"
|
||||
#raise NotImplementedError, "Copy is not yet implemented, TODO: Observable hierarchy"
|
||||
import copy
|
||||
from .index_operations import ParameterIndexOperations, ParameterIndexOperationsView
|
||||
from .lists_and_dicts import ArrayList
|
||||
|
||||
param_mapping = [[] for _ in range(self.num_params)]
|
||||
|
||||
dc = dict()
|
||||
for k, v in self.__dict__.iteritems():
|
||||
if k not in ['_parent_', '_parameters_', '_parent_index_', '_observer_callables_'] + self.parameter_names(recursive=False):
|
||||
if isinstance(v, (Constrainable, ParameterIndexOperations, ParameterIndexOperationsView)):
|
||||
if v in self._parameters_:
|
||||
param_mapping[self._parameters_.index(v)] += [k]
|
||||
elif isinstance(v, (Constrainable, ParameterIndexOperations, ParameterIndexOperationsView)):
|
||||
dc[k] = v.copy()
|
||||
else:
|
||||
dc[k] = copy.deepcopy(v)
|
||||
|
|
@ -928,9 +932,10 @@ class Parameterizable(OptimizationHandlable):
|
|||
s = self.__new__(self.__class__)
|
||||
s.__dict__ = dc
|
||||
|
||||
for p in params:
|
||||
for p, mlist in zip(params, param_mapping):
|
||||
s.add_parameter(p, _ignore_added_names=True)
|
||||
|
||||
for m in mlist:
|
||||
setattr(s, m, p)
|
||||
return s
|
||||
|
||||
#===========================================================================
|
||||
|
|
|
|||
|
|
@ -110,29 +110,15 @@ class Parameterized(Parameterizable, Pickleable):
|
|||
Allways append the state of the inherited object
|
||||
and call down to the inherited object in _setstate!!
|
||||
"""
|
||||
return [
|
||||
self._fixes_,
|
||||
self.priors,
|
||||
self.constraints,
|
||||
self._parameters_,
|
||||
self._name,
|
||||
self._added_names_,
|
||||
]
|
||||
return []
|
||||
|
||||
def _setstate(self, state):
|
||||
self._added_names_ = state.pop()
|
||||
self._name = state.pop()
|
||||
self._parameters_ = state.pop()
|
||||
self.constraints = state.pop()
|
||||
self.priors = state.pop()
|
||||
self._fixes_ = state.pop()
|
||||
self._connect_parameters()
|
||||
self.parameters_changed()
|
||||
#===========================================================================
|
||||
# Override copy to handle programmatically added observers
|
||||
#===========================================================================
|
||||
def copy(self):
|
||||
c = super(Pickleable, self).copy()
|
||||
c = super(Parameterized, self).copy()
|
||||
c.add_observer(c, c._parameters_changed_notification, -100)
|
||||
return c
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class Cacher(object):
|
|||
if k in kw and kw[k] is not None:
|
||||
return self.operation(*args, **kw)
|
||||
# TODO: WARNING !!! Cache OFFSWITCH !!! WARNING
|
||||
#return self.operation(*args)
|
||||
# return self.operation(*args, **kw)
|
||||
|
||||
#if the result is cached, return the cached computation
|
||||
state = [all(a is b for a, b in itertools.izip_longest(args, cached_i)) for cached_i in self.cached_inputs]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue