tbp.monty.frameworks.models.evidence_matching.feature_evidence#

tbp.monty.frameworks.models.evidence_matching.feature_evidence.calculator#

class DefaultFeatureEvidenceCalculator[source]#

Bases: object

static calculate(channel_feature_array: np.ndarray, channel_feature_order: list[str], channel_feature_weights: dict, channel_query_features: dict, channel_tolerances: dict, input_channel: str) np.ndarray[source]#

Calculate the feature evidence for all nodes stored in a graph.

Evidence for each feature depends on the difference between observed and stored features, feature weights, and distance weights.

Evidence is a float between 0 and 1. An evidence of 1 is a perfect match, the larger the difference between observed and sensed features, the close to 0 goes the evidence. Evidence is 0 if the difference is >= the tolerance for this feature.

If a node does not store a given feature, evidence will be nan.

input_channel indicates where the sensed features are coming from and thereby tells this function to which features in the graph they need to be compared.

Returns:

The feature evidence for all nodes.

class FeatureEvidenceCalculator(*args, **kwargs)[source]#

Bases: Protocol

static calculate(channel_feature_array: np.ndarray, channel_feature_order: list[str], channel_feature_weights: dict, channel_query_features: dict, channel_tolerances: dict, input_channel: str) np.ndarray[source]#

tbp.monty.frameworks.models.evidence_matching.feature_evidence.sdr_calculator#

class SDRFeatureEvidenceCalculator[source]#

Bases: object

static calculate(channel_feature_array: np.ndarray, channel_feature_order: list[str], channel_feature_weights: dict, channel_query_features: dict, channel_tolerances: dict, input_channel: str) np.ndarray[source]#

Calculates feature evidence for all nodes stored in a graph.

This calculation tests if the input_channel is a learning_module. If so, a different function is used for feature comparison.

Note: This assumes that learning modules always outputs 1 feature, object_id. If the learning modules output more than object_id features, we need to compare these according to their weights.

Returns:

The feature evidence for all nodes.

static calculate_feature_evidence_sdr_for_all_nodes(channel_feature_array: numpy.ndarray, channel_feature_weights: dict, channel_query_features: dict, channel_tolerances: dict) numpy.ndarray[source]#

Calculate overlap between stored and query SDR features.

Calculates the overlap between the SDR features stored at every location in the graph and the query SDR feature. This overlap is then compared to the tolerance value and the result is used for adjusting the evidence score.

We use the tolerance (in overlap bits) for generalization. If two objects are close enough, their overlap in bits should be higher that the set tolerance value.

The tolerance sets the lowest overlap for adding evidence, the range [tolerance, sdr_on_bits] is mapped to [0,1] evidence points. Any overlap less then tolerance will not add any evidence. These evidence scores are then multiplied by the feature weight of object_ids which scales all of the evidence points to the range [0, channel_feature_weights[“object_id”]].

The below variables have the following shapes:
  • channel_feature_array: (n, sdr_length)

  • channel_query_features[“object_id”]: (sdr_length)

  • query_feat: (sdr_length, 1)

  • np.matmul(channel_feature_array, query_feat): (n, 1)

  • overlaps: (n)

Returns:

The normalized overlaps.