Package paramz :: Module parameterized :: Class Parameterized
[hide private]
[frames] | no frames]

Class Parameterized

source code


Say m is a handle to a parameterized class.

Printing parameters:

   - print m:           prints a nice summary over all parameters
   - print m.name:      prints details for param with name 'name'
   - print m[regexp]: prints details for all the parameters
                        which match (!) regexp
   - print m['']:       prints details for all parameters

Fields:

   Name:       The name of the param, can be renamed!
   Value:      Shape or value, if one-valued
   Constrain:  constraint of the param, curly "{c}" brackets indicate
               some parameters are constrained by c. See detailed print
               to get exact constraints.
   Tied_to:    which paramter it is tied to.

Getting and setting parameters:

   - Set all values in param to one:      m.name.to.param = 1
   - Set all values in parameterized:     m.name[:] = 1
   - Set values to random values:         m[:] = np.random.norm(m.size)

Handling of constraining, fixing and tieing parameters:

    - You can constrain parameters by calling the constrain on the param itself, e.g:

       - m.name[:,1].constrain_positive()
       - m.name[0].tie_to(m.name[1])

    - Fixing parameters will fix them to the value they are right now. If you change
      the parameters value, the param will be fixed to the new value!

    - If you want to operate on all parameters use m[''] to wildcard select all paramters
      and concatenate them. Printing m[''] will result in printing of all parameters in detail.
Instance Methods [hide private]
 
__init__(self, name=None, parameters=[])
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
link_parameter(self, param, index=None)
:param parameters: the parameters to add :type parameters: list of or one :py:class:`paramz.param.Param` :param [index]: index of where to put parameters
source code
 
link_parameters(self, *parameters)
convenience method for adding several parameters without gradient specification
source code
 
unlink_parameter(self, param)
:param param: param object to remove from being a parameter of this parameterized object.
source code
 
_connect_parameters(self, ignore_added_names=False) source code
 
grep_param_names(self, regexp)
create a list of parameters, matching regular expression regexp
source code
 
__getitem__(self, name, paramlist=None) source code
 
__setitem__(self, name, value, paramlist=None) source code
 
__setattr__(self, name, val)
x.__setattr__('name', value) <==> x.name = value
source code
 
__setstate__(self, state) source code
 
copy(self, memo=None)
Returns a (deep) copy of the current parameter handle.
source code
 
_short(self) source code
 
get_property_string(self, propname) source code
 
_repr_html_(self, header=True)
Representation of the parameters in html for notebook display.
source code
 
_format_spec(self, name, names, desc, iops, VT100=True) source code
 
__str__(self, header=True, VT100=True)
str(x)
source code
 
build_pydot(self, G=None)
Build a pydot representation of this model.
source code

Inherited from core.parameter_core.Parameterizable: disable_caching, enable_caching, initialize_parameter, parameters_changed, save, traverse, traverse_parents

Inherited from core.parameter_core.OptimizationHandlable: parameter_names, parameter_names_flat, randomize

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

Inherited from core.indexable.Indexable: add_index_operation, remove_index_operation

Inherited from core.nameable.Nameable: hierarchy_name

Inherited from core.gradcheckable.Gradcheckable: checkgrad

Inherited from core.gradcheckable.Gradcheckable (private): _checkgrad

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

Inherited from core.parentable.Parentable: has_parent

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

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

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

Class Variables [hide private]

Inherited from core.parentable.Parentable: _parent_, _parent_index_

Properties [hide private]
  flattened_parameters
  _description_str

Inherited from core.parameter_core.Parameterizable: gradient, num_params, param_array, unfixed_param_array

Inherited from core.parameter_core.OptimizationHandlable: gradient_full, optimizer_array

Inherited from core.constrainable.Constrainable: is_fixed

Inherited from core.nameable.Nameable: name

Inherited from core.parentable.Parentable: _highest_parent_

Inherited from object: __class__

Method Details [hide private]

__init__(self, name=None, parameters=[])
(Constructor)

source code 

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

Overrides: object.__init__
(inherited documentation)

link_parameter(self, param, index=None)

source code 

:param parameters: the parameters to add :type parameters: list of or one :py:class:`paramz.param.Param` :param [index]: index of where to put parameters

Add all parameters to this param class, you can insert parameters at any given index using the :func:`list.insert` syntax

_connect_parameters(self, ignore_added_names=False)

source code 
Overrides: core.parameter_core.OptimizationHandlable._connect_parameters

__setattr__(self, name, val)

source code 

x.__setattr__('name', value) <==> x.name = value

Overrides: object.__setattr__
(inherited documentation)

__setstate__(self, state)

source code 
Overrides: core.pickleable.Pickleable.__setstate__

copy(self, memo=None)

source code 

Returns a (deep) copy of the current parameter handle.

All connections to parents of the copy will be cut.

:param dict memo: memo for deepcopy :param Parameterized which: parameterized object which started the copy process [default: self]

Overrides: core.pickleable.Pickleable.copy
(inherited documentation)

__str__(self, header=True, VT100=True)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

build_pydot(self, G=None)

source code 

Build a pydot representation of this model. This needs pydot installed.

Example Usage:

   np.random.seed(1000)
   X = np.random.normal(0,1,(20,2))
   beta = np.random.uniform(0,1,(2,1))
   Y = X.dot(beta)
   m = RidgeRegression(X, Y)
   G = m.build_pydot()
   G.write_png('example_hierarchy_layout.png')

The output looks like:

.. image:: ./example_hierarchy_layout.png

Rectangles are parameterized objects (nodes or leafs of hierarchy).

Trapezoids are param objects, which represent the arrays for parameters.

Black arrows show parameter hierarchical dependence. The arrow points from parents towards children.

Orange arrows show the observer pattern. Self references (here) are the references to the call to parameters changed and references upwards are the references to tell the parents they need to update.


Property Details [hide private]

flattened_parameters

Get Method:
unreachable.flattened_parameters(self)

_description_str

Get Method:
unreachable._description_str(self)