concepts.language.neural_ccg.ckyee.CKYEEExpectationFunction#

class CKYEEExpectationFunction[source]#

Bases: object

A collection of functions to perform expected execution. This class maintains a set of functions of the following form:

def expectation_<typename>(self, values: List[Value], weights: List[torch.Tensor]) -> Tuple[Optional[Value], Optional[Tuple[torch.Tensor, float]]]:
    ...

where typename is the name of a type, and values is a list of values of the type, and weights is a list of corresponding weights. The function should return a tuple of (expectation, (sum_weight, max_weight)), where expectation is the expectation of the values, as a Value instance, and sum_weight is the sum of the weights (as a PyTorch tensor), and max_weight is the maximum of the weights (as a float).

Methods

expectation(values, weights)

Compute the expectation of a list of values.

get_function(typename)

Get the registered function for a type.

register_function(typename, function)

Register a function to compute the expectation of a list of values.

__init__(domain)[source]#

Initialize the expectation function.

Parameters:

domain (FunctionDomain) – the function domain.

__new__(**kwargs)#
expectation(values, weights)[source]#

Compute the expectation of a list of values.

Parameters:
  • values (List[Value]) – a list of values.

  • weights (List[Tensor]) – a list of corresponding weights.

Returns:

A tuple of (expectation, (sum_weight, max_weight)). The expectation is the expectation of the values, as a Value instance. The second element is a tuple of (sum_weight, max_weight), where sum_weight is the sum of the weights (as a PyTorch tensor), and max_weight is the maximum of the weights (as a float).

Return type:

Tuple[Value | None, Tuple[Tensor, float] | None]

get_function(typename)[source]#

Get the registered function for a type.

Parameters:

typename (str) – the name of the type.

Returns:

The registered function.

Return type:

Callable[[List[Value], List[Tensor]], Tuple[Tensor, Tuple[Tensor, float]]] | None

register_function(typename, function)[source]#

Register a function to compute the expectation of a list of values.

Parameters: