FiniteStateAutomata

class torchhd.structures.FiniteStateAutomata(dimensions, vsa: Literal['BSC', 'MAP', 'HRR', 'FHRR', 'BSBC', 'VTB', 'MCR', 'CGR'] = 'MAP', device=None, dtype=None)[source]

Hypervector-based finite state automata data structure.

Creates an empty finite state automata.

Parameters:
  • dimensions (int) – dimensions of the automata.

  • vsa – (VSAOptions, optional): specifies the hypervector type and operations used (Default: "MAP").

  • dtype (torch.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see torch.set_default_tensor_type()).

  • device (torch.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

Examples:

>>> FSA = structures.FiniteStateAutomata(10000)
add_transition(token: VSATensor, initial_state: VSATensor, final_state: VSATensor) None[source]

Adds a transition to the automata.

Parameters:
  • token (VSATensor) – token used for changing state.

  • initial_state (VSATensor) – initial state of the transition.

  • final_state (VSATensor) – final state of the transition.

Examples:

>>> letters = list(string.ascii_lowercase)
>>> letters_hv = torchhd.random(len(letters), 10000)
>>> T.add_transition(letters_hv[0], letters_hv[1], letters_hv[2])
clear() None[source]

Empties the tree.

Examples:

>>> FSA.clear()
transition(state: VSATensor, action: VSATensor) VSATensor[source]

Returns the next state off the automata plus some noise.

Parameters:
  • state (VSATensor) – initial state of the transition.

  • action (VSATensor) – token used for changing state.

Examples:

>>> FSA.transition(letters_hv[1], letters_hv[0])
tensor([ 1.,  1., -1.,  ..., -1., -1.,  1.])