Package paramz :: Module param :: Class Param
[hide private]
[frames] | no frames]

Class Param

source code


Parameter object for GPy models.

:param str name: name of the parameter to be printed :param input_array: array which this parameter handles :type input_array: np.ndarray :param default_constraint: The default constraint for this parameter :type default_constraint:

You can add/remove constraints by calling constrain on the parameter itself, e.g:

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

Important Notes:

The array given into this, will be used as the Param object. That is, the memory of the numpy array given will be the memory of this object. If you want to make a new Param object you need to copy the input array!

Multilevel indexing (e.g. self[:2][1:]) is not supported and might lead to unexpected behaviour. Try to index in one go, using boolean indexing or the numpy builtin np.index function.

See :py:class:`GPy.core.parameterized.Parameterized` for more details on constraining etc.

Instance Methods [hide private]
 
__init__(self, name, input_array, default_constraint=None, *a, **kw)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
__array_finalize__(self, obj)
None.
source code
 
__getitem__(self, s, *args, **kwargs)
x[y]
source code
 
_raveled_index(self, slice_index=None)
Flattened array of ints, specifying the index of this object.
source code
 
_raveled_index_for(self, obj)
get the raveled index for a param that is an int array, containing the indexes for the flattened param inside this parameterized logic.
source code
 
_ensure_fixes(self) source code
 
_get_original(self, param) source code
 
copy(self)
Make a copy.
source code
Deep copy of array
__deepcopy__(self, memo)
Used if copy.deepcopy is called on an array.
source code
 
_setup_observers(self)
Setup the default observers
source code
 
parameter_names(self, add_self=False, adjust_for_printing=False, recursive=True, **kw)
Get the names of all parameters of this model or parameter.
source code
 
get_property_string(self, propname) source code
 
__repr__(self, *args, **kwargs)
repr(x)
source code
 
_indices(self, slice_index=None) source code
 
_max_len_names(self, gen, header) source code
 
_max_len_values(self) source code
 
_max_len_index(self, ind) source code
 
_repr_html_(self, indices=None, iops=None, lx=None, li=None, lls=None)
Representation of the parameter in html for notebook display.
source code
 
_format_spec(self, indices, iops, lx=None, li=None, lls=None, VT100=True) source code
 
__str__(self, indices=None, iops=None, lx=None, li=None, lls=None, only_name=False, VT100=True)
str(x)
source code
 
build_pydot(self, G)
Build a pydot representation of this model.
source code

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

Inherited from core.parameter_core.OptimizationHandlable: 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.observable_array.ObsAr: __array_wrap__, __getslice__, __iadd__, __iand__, __idiv__, __ifloordiv__, __ilshift__, __imod__, __imul__, __ior__, __ipow__, __irshift__, __isub__, __itruediv__, __ixor__, __reduce__, __setitem__, __setslice__

Inherited from numpy.ndarray: __abs__, __add__, __and__, __array__, __array_prepare__, __complex__, __contains__, __copy__, __delitem__, __delslice__, __div__, __divmod__, __eq__, __float__, __floordiv__, __ge__, __gt__, __hex__, __index__, __int__, __invert__, __iter__, __le__, __len__, __long__, __lshift__, __lt__, __mod__, __mul__, __ne__, __neg__, __nonzero__, __oct__, __or__, __pos__, __pow__, __radd__, __rand__, __rdiv__, __rdivmod__, __rfloordiv__, __rlshift__, __rmod__, __rmul__, __ror__, __rpow__, __rrshift__, __rshift__, __rsub__, __rtruediv__, __rxor__, __sizeof__, __sub__, __truediv__, __xor__, all, any, argmax, argmin, argpartition, argsort, astype, byteswap, choose, clip, compress, conj, conjugate, cumprod, cumsum, diagonal, dot, dump, dumps, fill, flatten, getfield, item, itemset, max, mean, min, newbyteorder, nonzero, partition, prod, ptp, put, ravel, repeat, reshape, resize, round, searchsorted, setfield, setflags, sort, squeeze, std, sum, swapaxes, take, tobytes, tofile, tolist, tostring, trace, transpose, var, view

Inherited from core.pickleable.Pickleable: __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__, __reduce_ex__, __setattr__, __subclasshook__

Static Methods [hide private]
a new object with type S, a subtype of T
__new__(cls, name, input_array, default_constraint=None) source code
Class Variables [hide private]
  __array_priority__ = -1
Array priority.
  _fixes_ = None
hash(x)
  parameters = []

Inherited from numpy.ndarray: __hash__

Inherited from core.parentable.Parentable: _parent_, _parent_index_

Properties [hide private]
  param_array
As we are a leaf, this just returns self
  values
Return self as numpy array view
  gradient
Return a view on the gradient, which is in the same shape as this parameter is.
  is_fixed
  _description_str
  flattened_parameters
  num_params
Return the number of parameters of this parameter_handle.

Inherited from core.parameter_core.Parameterizable: unfixed_param_array

Inherited from core.parameter_core.OptimizationHandlable: gradient_full, optimizer_array

Inherited from core.nameable.Nameable: name

Inherited from numpy.ndarray: T, __array_interface__, __array_struct__, base, ctypes, data, dtype, flags, flat, imag, itemsize, nbytes, ndim, real, shape, size, strides

Inherited from core.parentable.Parentable: _highest_parent_

Inherited from object: __class__

Method Details [hide private]

__new__(cls, name, input_array, default_constraint=None)
Static Method

source code 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__
(inherited documentation)

__init__(self, name, input_array, default_constraint=None, *a, **kw)
(Constructor)

source code 

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

Overrides: object.__init__
(inherited documentation)

__array_finalize__(self, obj)

source code 

None.

Overrides: __array_finalize__
(inherited documentation)

__getitem__(self, s, *args, **kwargs)
(Indexing operator)

source code 

x[y]

Overrides: numpy.ndarray.__getitem__
(inherited documentation)

_raveled_index(self, slice_index=None)

source code 

Flattened array of ints, specifying the index of this object. This has to account for shaped parameters!

Overrides: core.indexable.Indexable._raveled_index
(inherited documentation)

_raveled_index_for(self, obj)

source code 

get the raveled index for a param that is an int array, containing the indexes for the flattened param inside this parameterized logic.

!Warning! be sure to call this method on the highest parent of a hierarchy, as it uses the fixes to do its work

Overrides: core.indexable.Indexable._raveled_index_for
(inherited documentation)

_ensure_fixes(self)

source code 
Overrides: core.constrainable.Constrainable._ensure_fixes

_get_original(self, param)

source code 
Overrides: core.constrainable.Constrainable._get_original

copy(self)

source code 

Make a copy. This means, we delete all observers and return a copy of this array. It will still be an ObsAr!

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

__deepcopy__(self, memo)

source code 

Used if copy.deepcopy is called on an array.

Returns: Deep copy of array
Overrides: core.pickleable.Pickleable.__deepcopy__

_setup_observers(self)

source code 

Setup the default observers

1: pass through to parent, if present

Overrides: core.observable_array.ObsAr._setup_observers

parameter_names(self, add_self=False, adjust_for_printing=False, recursive=True, **kw)

source code 

Get the names of all parameters of this model or parameter. It starts
from the parameterized object you are calling this method on.

Note: This does not unravel multidimensional parameters,
      use parameter_names_flat to unravel parameters!

:param bool add_self: whether to add the own name in front of names
:param bool adjust_for_printing: whether to call `adjust_name_for_printing` on names
:param bool recursive: whether to traverse through hierarchy and append leaf node names
:param bool intermediate: whether to add intermediate names, that is parameterized objects

Overrides: core.parameter_core.OptimizationHandlable.parameter_names
(inherited documentation)

__repr__(self, *args, **kwargs)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

__str__(self, indices=None, iops=None, lx=None, li=None, lls=None, only_name=False, VT100=True)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

build_pydot(self, G)

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]

param_array

As we are a leaf, this just returns self

Get Method:
unreachable.param_array(self) - As we are a leaf, this just returns self

values

Return self as numpy array view

Get Method:
unreachable.values(self) - Return self as numpy array view

gradient

Return a view on the gradient, which is in the same shape as this parameter is. Note: this is not the real gradient array, it is just a view on it.

To work on the real gradient array use: self.full_gradient

Get Method:
unreachable.gradient(self) - Return a view on the gradient, which is in the same shape as this parameter is.
Set Method:
unreachable.gradient(self, val)

is_fixed

Get Method:
unreachable.is_fixed(self)

_description_str

Get Method:
unreachable._description_str(self)

flattened_parameters

Get Method:
unreachable.flattened_parameters(self)

num_params

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

Get Method:
unreachable.num_params(self)