Package paramz :: Package core :: Module parameter_core :: Class Parameterizable
[hide private]
[frames] | no frames]

Class Parameterizable

source code


A parameterisable class.

This class provides the parameters list (ArrayList) and standard parameter handling, such as {link|unlink}_parameter(), traverse hierarchy and param_array, gradient_array and the empty parameters_changed().

This class is abstract and should not be instantiated. Use paramz.Parameterized() as node (or leaf) in the parameterized hierarchy. Use paramz.Param() for a leaf in the parameterized hierarchy.

Instance Methods [hide private]
 
__init__(self, *args, **kwargs)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
initialize_parameter(self)
Call this function to initialize the model, if you built it without initialization.
source code
 
traverse(self, visit, *args, **kwargs)
Traverse the hierarchy performing `visit(self, *args, **kwargs)` at every node passed by downwards.
source code
 
_traverse(self, visit, *args, **kwargs) source code
 
traverse_parents(self, visit, *args, **kwargs)
Traverse the hierarchy upwards, visiting all parents and their children except self.
source code
 
enable_caching(self) source code
 
disable_caching(self) source code
 
_add_parameter_name(self, param) source code
 
_remove_parameter_name(self, param=None, pname=None) source code
 
_name_changed(self, param, old_name) source code
 
__setstate__(self, state) source code
 
_parameters_changed_notification(self, me, which=None)
In parameterizable we just need to make sure, that the next call to optimizer_array will update the optimizer_array to the latest parameters
source code
 
_pass_through_notify_observers(self, me, which=None) source code
 
_setup_observers(self)
Setup the default observers
source code
 
_notify_parent_change(self)
Notify all parameters that the parent has changed
source code
 
parameters_changed(self)
This method gets called when parameters have changed.
source code
 
save(self, filename, ftype='HDF5')
Save all the model parameters into a file (HDF5 by default).
source code

Inherited from OptimizationHandlable: parameter_names, parameter_names_flat, randomize

Inherited from constrainable.Constrainable: constrain, constrain_bounded, constrain_fixed, constrain_negative, constrain_positive, fix, unconstrain, unconstrain_bounded, unconstrain_fixed, unconstrain_negative, unconstrain_positive, unfix

Inherited from indexable.Indexable: add_index_operation, remove_index_operation

Inherited from nameable.Nameable: hierarchy_name

Inherited from gradcheckable.Gradcheckable: checkgrad

Inherited from gradcheckable.Gradcheckable (private): _checkgrad

Inherited from pickleable.Pickleable: __deepcopy__, __getstate__, copy, pickle

Inherited from parentable.Parentable: has_parent

Inherited from updateable.Updateable: toggle_update, trigger_update, update_model, update_toggle

Inherited from observable.Observable: add_observer, change_priority, notify_observers, remove_observer, set_updates

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]

Inherited from parentable.Parentable: _parent_, _parent_index_

Properties [hide private]
  param_array
Array representing the parameters of this class.
  unfixed_param_array
Array representing the parameters of this class.
  gradient
  num_params
Return the number of parameters of this parameter_handle.

Inherited from OptimizationHandlable: gradient_full, optimizer_array

Inherited from constrainable.Constrainable: is_fixed

Inherited from nameable.Nameable: name

Inherited from parentable.Parentable: _highest_parent_

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args, **kwargs)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

initialize_parameter(self)

source code 

Call this function to initialize the model, if you built it without initialization.

This HAS to be called manually before optmizing or it will be causing unexpected behaviour, if not errors!

traverse(self, visit, *args, **kwargs)

source code 

Traverse the hierarchy performing `visit(self, *args, **kwargs)` at every node passed by downwards. This function includes self!

See *visitor pattern* in literature. This is implemented in pre-order fashion.

Example:

   #Collect all children:

   children = []
   self.traverse(children.append)
   print children

traverse_parents(self, visit, *args, **kwargs)

source code 

Traverse the hierarchy upwards, visiting all parents and their children except self. See "visitor pattern" in literature. This is implemented in pre-order fashion.

Example:

parents = [] self.traverse_parents(parents.append) print parents

__setstate__(self, state)

source code 
Overrides: pickleable.Pickleable.__setstate__

_setup_observers(self)

source code 

Setup the default observers

1: parameters_changed_notify 2: pass through to parent, if present

_notify_parent_change(self)

source code 

Notify all parameters that the parent has changed

Overrides: parentable.Parentable._notify_parent_change

parameters_changed(self)

source code 

This method gets called when parameters have changed. Another way of listening to param changes is to add self as a listener to the param, such that updates get passed through. See :py:function:``paramz.param.Observable.add_observer``

save(self, filename, ftype='HDF5')

source code 

Save all the model parameters into a file (HDF5 by default).

This is not supported yet. We are working on having a consistent, human readable way of saving and loading GPy models. This only saves the parameter array to a hdf5 file. In order to load the model again, use the same script for building the model you used to build this model. Then load the param array from this hdf5 file and set the parameters of the created model:

>>> m[:] = h5_file['param_array']

This is less then optimal, we are working on a better solution to that.


Property Details [hide private]

param_array

Array representing the parameters of this class. There is only one copy of all parameters in memory, two during optimization.

!WARNING!: setting the parameter array MUST always be done in memory: m.param_array[:] = m_copy.param_array

Get Method:
unreachable.param_array(self) - Array representing the parameters of this class.

unfixed_param_array

Array representing the parameters of this class. There is only one copy of all parameters in memory, two during optimization.

!WARNING!: setting the parameter array MUST always be done in memory: m.param_array[:] = m_copy.param_array

Get Method:
unreachable.unfixed_param_array(self) - Array representing the parameters of this class.

gradient

Get Method:
unreachable.gradient(self)
Set Method:
unreachable.gradient(self, val)

num_params

Return the number of parameters of this parameter_handle. Param objects will always return 0.

Get Method:
unreachable.num_params(self)