Class: Sooth::Predictor

Inherits:
Object
  • Object
show all
Defined in:
ext/sooth_native/native.c,
ext/sooth_native/native.c

Overview

A very simple stochastic predictor. Implemented in C for efficiency. The idea here is to build up more complicated learning algorithms using a trivial Markovian predictor.

Instance Method Summary collapse

Constructor Details

#initialize(error_symbol) ⇒ Object

Returns a new Sooth::Predictor instance.

Parameters:

  • The symbol to be returned by #select when no prediction can be made.



40
# File 'ext/sooth_native/native.c', line 40

VALUE method_sooth_native_initialize(VALUE self, VALUE error_symbol);

Instance Method Details

#count(bigram) ⇒ Fixnum

Return a count of the number of times the bigram has been observed.

Parameters:

  • A pair of symbols.

Returns:

  • A count of the number of times the bigram has been observed. This is guaranteed to be equal to the sum of the counts of observations of all symbols in the context of the bigram.



11
12
13
# File 'ext/sooth_native/native.c', line 11

def count(bigram)
  # (native code)
end

#observe(bigram, symbol) ⇒ Fixnum

Add an observation of the given symbol in the context of the bigram.

Parameters:

  • A pair of symbols that provide context, allowing the predictor to maintain observation statistics for different contexts.

  • The symbol that has been observed.

Returns:

  • A count of the number of times the symbol has been observed in the context of the bigram.



52
53
54
# File 'ext/sooth_native/native.c', line 52

def observe(bigram, symbol)
  # (native code)
end

#select(bigram, limit) ⇒ Fixnum

Return a symbol that may occur in the context of the bigram. The limit is used to select a symbol. This is done by iterating through all of the symbols that have been observed in the context of the bigram, subtracting the observation count of each symbol from the supplied limit. For this reason, limit should be between 1 and the observation count of the bigram itself, as returned by #count.

Parameters:

  • A pair of symbols.

  • The total numbe of symbol observations to be analysed before returning a symbol.

Returns:

  • A symbol that has been observed previously in the context of the bigram, or the error_symbol if no such symbol exists, or if the supplied limit was too large.



14
15
16
# File 'ext/sooth_native/native.c', line 14

def select(bigram, limit)
  # (native code)
end