Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MarkovChain

Hierarchy

  • MarkovChain

Index

Constructors

Properties

_engine: Random

Accessors

  • get delimiter(): string
  • get endDelimiter(): string
  • get maxOrder(): number
  • get seed(): number | number[]
  • get sequences(): undefined | string[][]
  • get startDelimiter(): string
  • get uses(): number

Methods

  • addEdge(gram: string | string[], lastId: undefined | string, nextId: undefined | string, order: number): MarkovChain
  • Adds an edge from a gram to the items before and after it in the sequence.

    Parameters

    • gram: string | string[]

      The id of a gram, or the gram sequence.

    • lastId: undefined | string

      The id of the previous gram in the sequence.

    • nextId: undefined | string

      The id of the next gram in the sequence.

    • order: number

      The order of the Gram we're adding.

    Returns MarkovChain

  • Adds or inserts a Sequence into a Markov Chain DTO.

    Parameters

    • sequence: string[]

      The sequence to be added.

    • insert: MCInsertOption = false

      Determines how sequences should be inserted. If false, delimiters will be prepended and appended to the sequences. "start" or setting true will only prepend the start delimiter, while "end" will append the end delimiter. "middle" will not add any delimiters.

    Returns MarkovChain

  • Adds or inserts a list of Sequences into a Markov Chain DTO.

    Parameters

    • sequences: string[][]

      The sequences to be added.

    • insert: MCInsertOption = false

      Determines how sequences should be inserted. If false, delimiters will be prepended and appended to the sequences. "start" or setting true will only prepend the start delimiter, while "end" will append the end delimiter. "middle" will not add any delimiters.

    Returns MarkovChain

  • Analyze's a sequences sources and sinks. Generates a number of samples from a given gram sequence, and gives the resulting distribution of where the generated sequences terminated both backwards (sources) and forwards (sinks).

    Parameters

    Returns MCAnalysis

  • Ceates a clone of the Markov Chain.

    Parameters

    • stripSequences: boolean = false

      If true this will strip out the sequences, removing the chain's source data.

    Returns MarkovChain

  • findGram(gramSequence: string[], order?: number, direction?: string): Gram
  • Finds the valid gram of the highest valid order in a sequence.

    Parameters

    • gramSequence: string[]

      An array containing the Gram sequence.

    • Optional order: number

      The highest order to look for.

    • direction: string = 'next'

      The direction we are looking for sequences in. "next" will look for grams at the end of the sequence. "last" will look for grams at the beginning of the sequence.

    Returns Gram

  • getGram(gramSequence: string[]): Gram
  • Returns the corresponding Gram from a sequence.

    Parameters

    • gramSequence: string[]

      An array containing the Gram sequence.

    Returns Gram

  • getGramId(gramSequence: string[]): string
  • Returns the id of a Gram from its sequence.

    Parameters

    • gramSequence: string[]

      An array containing the Gram sequence.

    Returns string

  • last(gramSequence?: string[], mask?: string[]): undefined | string
  • Picks the last random value from a Markov Chain given a sequence.

    Parameters

    • Optional gramSequence: string[]

      The starting Gram sequence. If this isn't supplied this defaults to the start.

    • Optional mask: string[]

      A mask containing keys in the chain that should be ignored.

    Returns undefined | string

  • next(gramSequence?: string[], mask?: string[]): undefined | string
  • Picks the next random value from a Markov Chain given a sequence.

    Parameters

    • Optional gramSequence: string[]

      The starting Gram sequence. If this isn't supplied this defaults to the start.

    • Optional mask: string[]

      A mask containing keys in the chain that should be ignored.

    Returns undefined | string

  • pick(gramSequence?: string[], next?: boolean, mask?: string[]): undefined | string
  • Picks the next or last random value from a Markov Chain.

    Parameters

    • Optional gramSequence: string[]

      The starting Gram sequence. If this isn't supplied this defaults to the start.

    • next: boolean = true

      If true states that come after the gram will be picked. If false states that came before the gram will be picked.

    • Optional mask: string[]

      A mask containing keys in the chain that should be ignored.

    Returns undefined | string

  • Serializes a Markov Chain instance into a DTO.

    Parameters

    • stripSequences: boolean = false

      If true this will strip out the sequences, removing the chain's source data.

    Returns MarkovChainDTO

  • addEdge(model: MarkovChainDTO, gram: string | string[], lastId: undefined | string, nextId: undefined | string, order: number, weight?: number): MarkovChainDTO
  • Adds an edge from a gram to the items before and after it in the sequence.

    Parameters

    • model: MarkovChainDTO

      A Markov Chain data transfer object.

    • gram: string | string[]

      The id of a gram, or the gram sequence.

    • lastId: undefined | string

      The id of the previous gram in the sequence.

    • nextId: undefined | string

      The id of the next gram in the sequence.

    • order: number

      The order of the Gram we're adding.

    • weight: number = 1

    Returns MarkovChainDTO

  • Adds or inserts a Sequence into a Markov Chain DTO.

    Parameters

    • model: MarkovChainDTO

      A Markov Chain data transfer object.

    • sequence: string[]

      The sequence to be added.

    • insert: MCInsertOption = false

      Determines how sequences should be inserted. If false, delimiters will be prepended and appended to the sequences. "start" or setting true will only prepend the start delimiter, while "end" will append the end delimiter. "middle" will not add any delimiters.

    Returns MarkovChainDTO

  • Adds or inserts a list of Sequences into a Markov Chain DTO.

    Parameters

    • model: MarkovChainDTO

      A Markov Chain data transfer object.

    • sequences: string[][]

      The sequences to be added.

    • insert: MCInsertOption = false

      Determines how sequences should be inserted. If false, delimiters will be prepended and appended to the sequences. "start" or setting true will only prepend the start delimiter, while "end" will append the end delimiter. "middle" will not add any delimiters.

    Returns MarkovChainDTO

  • Analyze's a sequences sources and sinks. Generates a number of samples from a given gram sequence, and gives the resulting distribution of where the generated sequences terminated both backwards (sources) and forwards (sinks).

    Parameters

    Returns MCAnalysis

  • Create a deep copy of a Markov Chain DTO.

    Parameters

    • model: MarkovChainDTO

      Markov DTO to clone.

    • stripSequences: boolean = false

      If true this will strip out the sequences, removing the chain's source data.

    Returns MarkovChainDTO

  • findGram(model: MarkovChainDTO, gramSequence: string[], order?: number, direction?: string): Gram
  • Finds the valid gram of the highest valid order in a sequence.

    Parameters

    • model: MarkovChainDTO

      A Markov Chain data transfer object.

    • gramSequence: string[]

      An array containing the Gram sequence.

    • Optional order: number

      The highest order to look for.

    • direction: string = 'next'

      The direction we are looking for sequences in. "next" will look for grams at the end of the sequence. "last" will look for grams at the beginning of the sequence.

    Returns Gram

  • Returns the corresponding Gram from a sequence.

    Parameters

    • model: MarkovChainDTO

      A Markov Chain data transfer object.

    • gramSequence: string[]

      An array containing the Gram sequence.

    Returns Gram

  • Returns the id of a Gram from its sequence.

    Parameters

    • model: MarkovChainDTO

      A Markov Chain data transfer object.

    • gramSequence: string[]

      An array containing the Gram sequence.

    Returns string

  • getSequence(gramSequence: string[], order: number, next: boolean): string[]
  • Utility function to find a sequence given an order and a direction. This returns an array containing the first or last elements of an array equal to the order.

    Parameters

    • gramSequence: string[]

      An array containing the Gram sequence.

    • order: number

      The length of the array to return.

    • next: boolean

      If true, will find elements at the end. If false will find elements at the beginning.

    Returns string[]

  • last(model: MarkovChainDTO, gramSequence?: string[], mask?: string[], engine?: Random): undefined | string
  • Picks the last random value from a Markov Chain given a sequence.

    Parameters

    • model: MarkovChainDTO

      A Markov Chain data transfer object.

    • Optional gramSequence: string[]

      The starting Gram sequence. If this isn't supplied this defaults to the start.

    • Optional mask: string[]

      A mask containing keys in the chain that should be ignored.

    • Optional engine: Random

      A Random engine.

    Returns undefined | string

  • Creates a new Markov Chain data transfer object.

    Parameters

    • Optional sequences: string[][]

      An optional array of sequences to generate the grams from.

    • maxOrder: number = defaultOptions.maxOrder

      The maximum gram size of the markov chain.

    • insert: MCInsertOption = false

      Determines how sequences should be inserted. If false, delimiters will be prepended and appended to the sequences. "start" or setting true will only prepend the start delimiter, while "end" will append the end delimiter. "middle" will not add any delimiters.

    • stripSequences: boolean = false

      If true this will strip out the sequences, removing the chain's source data.

    Returns MarkovChainDTO

  • next(model: MarkovChainDTO, gramSequence?: string[], mask?: string[], engine?: Random): undefined | string
  • Picks the next random value from a Markov Chain given a sequence.

    Parameters

    • model: MarkovChainDTO

      A Markov Chain data transfer object.

    • Optional gramSequence: string[]

      The starting Gram sequence. If this isn't supplied this defaults to the start.

    • Optional mask: string[]

      A mask containing keys in the chain that should be ignored.

    • Optional engine: Random

      A Random engine.

    Returns undefined | string

  • pick(model: MarkovChainDTO, gramSequence?: string[], next?: boolean, mask?: string[], engine?: Random): undefined | string
  • Picks the next or last random value from a Markov Chain.

    Parameters

    • model: MarkovChainDTO

      A Markov Chain data transfer object.

    • Optional gramSequence: string[]

      The starting Gram sequence. If this isn't supplied this defaults to the start.

    • next: boolean = true

      If true states that come after the gram will be picked. If false states that came before the gram will be picked.

    • Optional mask: string[]

      A mask containing keys in the chain that should be ignored.

    • Optional engine: Random

      A Random engine.

    Returns undefined | string

  • pickGram(gram: Gram, next?: boolean, mask?: string[], engine?: Random): undefined | string
  • Makes a random pick from the next or last state of a given Gram.

    Parameters

    • gram: Gram

      The starting Gram sequence. If this isn't supplied this defaults to the start.

    • next: boolean = true

      If true states that come after the gram will be picked. If false states that came before the gram will be picked.

    • Optional mask: string[]

      A mask containing keys in the chain that should be ignored.

    • Optional engine: Random

      A Random engine.

    Returns undefined | string

Generated using TypeDoc