ENCODERS & DECODERS

binning

image

Decoder plugin, clustering similar Sparse Distributed Representations (SDRs).

See also: https://creatingintelligence.org/#sparse-distributed-representations

Details

  • Decoder plugin for the output component.
  • Clusters similar SDRs into a variable number of bins.
  • Uses the auto-associative pattern matching threshold to determine similarity.
  • Assigns and returns bin numbers 1,2,…
  • Maintains a globally shared mapping for each hyperparameter combination [N, P].

Clustering SDRs

The following circuit classifies SDRs, returning bin numbers 1,2,…

{ "hyperparameters": {"default": [1000, 10]},
  "dataflow": [
    {"component": "input", "send": [1]},
    {"component": "output", "plugin": "binning", "receive": [1]}
  ]}

image

Source code

def binning(config):
    hyperparameters = config.get("hyperparameters", [0, 0])
    n, p = hyperparameters[0], hyperparameters[1]
    lex_key = (n, p)

    if lex_key not in circuit_binning_lexicon:
        circuit_binning_lexicon[lex_key] = {None: []}

    lex = circuit_binning_lexicon[lex_key]
    T = matching_threshold((n, p), (n, p))

    if config.get("component") == "input":
        raise ValueError("binning cannot be used as an encoder.")

    def f(expr):
        if not expr:
            return 0

        overlaps = {k: len(set(v).intersection(expr))
                    for k, v in lex.items() if k is not None}

        bins = [k for k, overlap in overlaps.items() if overlap >= T]

        if len(bins) == 0:
            new_bin = len(lex)
            lex[new_bin] = expr
            return new_bin
        elif len(bins) == 1:
            return bins[0]
        else:
            return sorted(bins)

    def clear():
        lex.clear()
        lex[None] = []

    return {
        "label": "BIN",
        "function": f,
        "clear": clear
    }