pylawr.remap.kernel#

pylawr.remap.kernel.base_ops.BaseKernel()

This BaseKernel is a base object for all Kernel classes.

pylawr.remap.kernel.base_ops.KernelNode(...)

A kernel node is a dependent node within a kernel definition.

pylawr.remap.kernel.Parameter(value[, name, ...])

This parameter can be used to introduce variable and constant values into a defined kernel function.

pylawr.remap.kernel.Placeholder(name)

This placeholder can be used to dynamically feed-in data into a defined kernel function.

pylawr.remap.kernel.exp_sin_squared([...])

The exponential sine squared kernel as in scikit-learn.

pylawr.remap.kernel.gaussian_rbf([...])

The gaussian, also called radial basis function, kernel is one of the default kernels for kernel based learning.

pylawr.remap.kernel.rational_quadratic([...])

This rational quadratic kernel is a mixture of gaussian / radial basis function kernels.

pylawr.remap.kernel.WhiteNoise(dependency[, ...])

pylawr.remap.kernel.base_ops.BaseKernel#

class pylawr.remap.kernel.base_ops.BaseKernel[source]#

Bases: NDArrayOperatorsMixin

This BaseKernel is a base object for all Kernel classes. This BaseKernel defines all available mathematical operation for any kernel. Many different numpy ufuncs can be used to manipulate this kernel, resulting in a new kernel.

property T#

Returns a view of this kernel with axes transposed.

Returns

kernel – The transposed kernel.

Return type

pylawr.remap.kernel.base_ops.UnaryKernel

diag(*args, **kwargs)[source]#

The diagonal elements of this kernel.

Parameters
  • args (list of any) – Additional arguments, which are used to estimate the diagonal elements.

  • kwargs (dict(str, any)) – Additional keyword arguments. If no additional argument is given, this dictionary is used to determine the diagonal elements.

Returns

diag_values – The diagonal values of this kernel.

Return type

any

get_named_param(name)[source]#

This method can be used to get a list with found parameters, where the name equals the given name.

Parameters

name (str) – This name is searched in the list of parameter names.

Returns

params – These are the found parameter, where the name matches the given name.

Return type

list

property params#

The parameters of this kernel. Parameters are optimisable during training and are used during inference to obtain optimized values.

Returns

params – This are the tunable parameters of this kernel. Here this is an empty list.

Return type

list

property placeholders#

The placeholders of this kernel. Placeholders can be used to feed-in values into the kernel function.

Returns

placeholders – This are the placeholders of this kernel. Here this is an empty list.

Return type

list

transpose()[source]#

Returns a view of this kernel with axes transposed.

Returns

kernel – The transposed kernel.

Return type

pylawr.remap.kernel.base_ops.UnaryKernel

variogram(distance)[source]#

The corresponding theoretical variogram to this kernel function. For every given distance a variogram value is estimated. The variogram value \(\gamma(d)\) is estimated based on following formula with \(d\) as distance and \(K(d)\) as kernel value for given distance \(d\):

\[\gamma(d) = K(0) - K(d)\]
Parameters

distance (numpy.ndarray) – The variogram is estimated for these distance values.

Returns

variogram – The theoretical variogram values for this kernel based on given distance. This variogram has the same shape as given distance.

Return type

numpy.ndarray

pylawr.remap.kernel.base_ops.KernelNode#

class pylawr.remap.kernel.base_ops.KernelNode(*dependencies)[source]#

Bases: BaseKernel

A kernel node is a dependent node within a kernel definition. This node depends on other kernel nodes, e.g. placeholders or parameters. A numpy ufunc is used to manipulate and combine parent nodes.

Parameters

*dependencies

iterable(child of BaseKernel)

This variable-length argument iterable can be used to define parent nodes of this dependent node.

Warning

self._np_func has to be set before this kernel node can be used.

diag(*args, **kwargs)[source]#

The diagonal elements of this kernel.

Parameters
  • args (list of any) – Additional arguments, which are used to estimate the diagonal elements.

  • kwargs (dict(str, any)) – Additional keyword arguments. If no additional argument is given, this dictionary is used to determine the diagonal elements.

Returns

diag_values – The diagonal values of this kernel.

Return type

any

property np_func#

The set numpy function of this kernel. This numpy func either transforms or combines the parent nodes into this kernel.

Returns

np_func – This numpy function can be used to manipulate gained data from the parent nodes.

Return type

python function

Raises

AttributeError – An AttributeError is raised if not numpy function for this dependent kernel is set.

property params#

A list of trainable parameters. These parameters can be used to train this kernel function onto data. This dependent kernel only forwards parents parameters.

Returns

params – This is the list of parameters for this kernel node. If this list is empty no parameter can be learned.

Return type

list(Parameter)

property placeholders#

The placeholders of this kernel. Placeholders can be used to feed-in data into the kernel function. This dependent kernel only forwards parents placeholders

Returns

  • placeholders

  • list(Placeholder) – This is the list with available placeholders for this kernel. These placeholders are inherited from the dependent kernels. If this list is empty no placeholder can be used to feed-in data and the results of this kernel are static.

pylawr.remap.kernel.Parameter#

class pylawr.remap.kernel.Parameter(value, name=None, constant=False)[source]#

Bases: BaseKernel

This parameter can be used to introduce variable and constant values into a defined kernel function.

Parameters
  • value (any) – The value of this parameter, which is returned by calling this instance.

  • name (str or None, optional) – You can name a parameter. This parameter can be then extracted by using get_named_param(). If the name of the parameter is None (default) it cannot be found.

  • constant (bool, optional) – This indicates if the value is included in the parameters list (False) or not (True). If it is included in the parameters list, it can be changed during training of this kernel. In its default value, this parameter is trainable. Default is False.

property name#
property params#

A list of trainable parameter of this kernel.

Returns

params – This is the list of trainable parameters. If constant is set to False, this is a list with this parameter as item. If constant is True, then this returned parameter list is empty.

Return type

list(Parameter)

pylawr.remap.kernel.Placeholder#

class pylawr.remap.kernel.Placeholder(name)[source]#

Bases: BaseKernel

This placeholder can be used to dynamically feed-in data into a defined kernel function. This placeholder returns one of the arguments if called.

Parameters

name (str) – Name of this placeholder. This name is used to identify this placeholder. If this placeholder is called with additional keyword arguments, then this name is used to get an additional argument.

property placeholders#

The placeholders of this kernel. Placeholders can be used to feed-in values into the kernel function.

Returns

  • placeholders (list()

  • Placeholder) – This are the placeholders of this kernel. This placeholder only includes an instance of this placeholder class.

pylawr.remap.kernel.exp_sin_squared#

pylawr.remap.kernel.exp_sin_squared(placeholder_name='distance', length_scale=1.0, periodicity=1.0)[source]#

The exponential sine squared kernel as in scikit-learn. This kernel can be used to model periodic processes.

Parameters
  • placeholder_name (str, optional) – The placeholder name, which is used to identify the placeholder in this kernel chain. Default name is distance.

  • length_scale (float, optional) – This length scale is used within this kernel to define the decorrelation length of this kernel. Default is 200.

  • periodicity (float, optional) – The periodicity of this kernel. The periodicity defines the period of this kernel. Default is 1.

Returns

kernel – This is the precompiled exponential sine squared kernel, which can be evaluated with given placeholder_name and has given length_scale and periodicity as trainable parameters.

Return type

KernelNode

pylawr.remap.kernel.gaussian_rbf#

pylawr.remap.kernel.gaussian_rbf(placeholder_name='distance', length_scale=200, stddev=1)[source]#

The gaussian, also called radial basis function, kernel is one of the default kernels for kernel based learning. It is universal and is can integrate into almost any function that you want. It has also infinitely many derivatives.

Parameters
  • placeholder_name (str, optional) – The placeholder name, which is used to identify the placeholder in this kernel chain. Default name is distance.

  • length_scale (float, optional) – This length scale is used within the gaussian kernel to define the decorrelation length of this kernel. Default is 200.

  • stddev (float, optional) – The standard deviation of this gaussian kernel. The standard deviation defines the width gaussian distribution. Default is 1.

Returns

kernel – This is the precompiled gaussian kernel function, which can be evaluated with given placeholder_name and has given length_scale and stddev as trainable parameters.

Return type

KernelNode

pylawr.remap.kernel.rational_quadratic#

pylawr.remap.kernel.rational_quadratic(placeholder_name='distance', length_scale=200, stddev=1, scale=1)[source]#

This rational quadratic kernel is a mixture of gaussian / radial basis function kernels. This mixture combines these kernel with different length scales with the scale parameter as relative weighting between large-scale and small-scale variations.

Parameters
  • placeholder_name (str, optional) – The placeholder name, which is used to identify the placeholder in this kernel chain. Default name is distance.

  • length_scale (float, optional) – This length scale is used within the rational kernel to define the decorrelation length of this kernel. Default is 200.

  • stddev (float, optional) – The standard deviation of this rational kernel. The standard deviation defines the width gaussian distribution. Default is 1.

  • scale (float, optional) – This scale parameter is a weighting between large- and small-scale variations. If this factor converges towards zero, only large scale variations are important for the weights of kriging and every distance will be then unity. If this factor converges toward infinity, this kernel is the same as the gaussian rbf kernel. Default is 1.

Returns

kernel – This is the precompiled rational quadratic kernel, which can be evaluated with given placeholder_name and has given length_scale, stddev and scale as trainable parameters.

Return type

KernelNode

pylawr.remap.kernel.WhiteNoise#

class pylawr.remap.kernel.WhiteNoise(dependency, noise_level=1.0, constant=False)[source]#

Bases: BaseKernel

diag(*args, **kwargs)[source]#

The diagonal elements of this kernel.

Parameters
  • args (list of any) – Additional arguments, which are used to estimate the diagonal elements.

  • kwargs (dict(str, any)) – Additional keyword arguments. If no additional argument is given, this dictionary is used to determine the diagonal elements.

Returns

diag_values – The diagonal values of this kernel.

Return type

any

property noise_level#
property params#

The parameters of this kernel. Parameters are optimisable during training and are used during inference to obtain optimized values.

Returns

params – This are the tunable parameters of this kernel. Here this is an empty list.

Return type

list

property placeholders#

The placeholders of this kernel. Placeholders can be used to feed-in values into the kernel function.

Returns

placeholders – This are the placeholders of this kernel. Here this is an empty list.

Return type

list

property value#