PiecewiseConstant

class safe_learning.PiecewiseConstant(discretization, vertex_values=None)

A piecewise constant function approximator.

Parameters:
discretization : instance of discretization

For example, an instance of GridWorld.

vertex_values: arraylike, optional

A 2D array with the values at the vertices of the grid on each row.

Attributes:
limits

Return the discretization limits.

nindex

Return the number of discretization indices.

output_dim

Return the output dimensions of the function.

parameters

Return the vertex values.

scope_name

Methods

__call__(self, \*args, \*\*kwargs) Evaluate the function using the template to ensure variable sharing.
build_evaluation(self, points) Return the function values.
copy_parameters(self, other_instance) Copy over the parameters of another instance.
gradient(self, points) Return the gradient.
parameter_derivative(self, points) Obtain function values at points from triangulation.
build_evaluation(self, points)

Return the function values.

Parameters:
points : ndarray

The points at which to evaluate the function. One row for each data points.

Returns:
values : ndarray

The function values at the points.

copy_parameters(self, other_instance)

Copy over the parameters of another instance.

gradient(self, points)

Return the gradient.

The gradient is always zero for piecewise constant functions!

Parameters:
points : ndarray

The points at which to evaluate the function. One row for each data points.

Returns:
gradient : ndarray

The function gradient at the points.

limits

Return the discretization limits.

nindex

Return the number of discretization indices.

output_dim

Return the output dimensions of the function.

parameter_derivative(self, points)

Obtain function values at points from triangulation.

This function returns a sparse matrix that, when multiplied with the vector with all the function values on the vertices, returns the function values at points.

Parameters:
points : ndarray

A 2d array where each row represents one point.

Returns:
values

A sparse matrix B so that evaluate(points) = B.dot(parameters).

parameters

Return the vertex values.