Class: Sooth::Predictor
- Inherits:
-
Object
- Object
- Sooth::Predictor
- Defined in:
- ext/sooth_native/native.c,
ext/sooth_native/native.c
Overview
A minimal stochastic predictive model, implemented in C for efficiency. No assumptions about PRNG or real-world significance of context/event.
Instance Method Summary collapse
-
#clear ⇒ Object
Clear the predictor to a blank slate.
-
#count(context) ⇒ Fixnum
Return the number of times the context has been observed.
-
#distribution(context) ⇒ Array
Return an Enumerator that yields each observed event within the context together with its probability.
-
#frequency(context, event) ⇒ Float
Return a number indicating the frequency that the event has been observed within the given context.
-
#initialize(error_event) ⇒ Object
constructor
Returns a new Sooth::Predictor instance.
-
#load(filename) ⇒ Object
Load the predictor from the specified filename.
-
#observe(context, event) ⇒ Fixnum
Register an observation of the given event within the given context.
-
#save(filename) ⇒ Object
Save the predictor to a file that can be loaded later.
-
#select(context, limit) ⇒ Fixnum
Return an event that may occur in the given context, based on the limit, which should be between 1 and #count.
-
#size(context) ⇒ Fixnum
Return the number of different events that have been observed within the given context.
-
#surprise(context, event) ⇒ Float
Return a number indicating the surprise received by the predictor when it observed the given event within the given context.
-
#uncertainty(context) ⇒ Float
Return a number indicating how uncertain the predictor is about which event is likely to be observed after the given context.
Constructor Details
#initialize(error_event) ⇒ Object
Returns a new Sooth::Predictor instance.
60 |
# File 'ext/sooth_native/native.c', line 60
VALUE method_sooth_native_initialize(VALUE self, VALUE error_event);
|
Instance Method Details
#clear ⇒ Object
Clear the predictor to a blank slate.
65 66 |
# File 'ext/sooth_native/native.c', line 65 def clear end |
#count(context) ⇒ Fixnum
Return the number of times the context has been observed.
16 17 18 |
# File 'ext/sooth_native/native.c', line 16 def count(context) # (native code) end |
#distribution(context) ⇒ Array
Return an Enumerator that yields each observed event within the context together with its probability.
25 26 27 |
# File 'ext/sooth_native/native.c', line 25 def distribution(context) # (native code) end |
#frequency(context, event) ⇒ Float
Return a number indicating the frequency that the event has been observed within the given context.
34 35 36 |
# File 'ext/sooth_native/native.c', line 34 def frequency(context, event) # (native code) end |
#load(filename) ⇒ Object
Load the predictor from the specified filename. The predictor will be cleared before the file is loaded.
73 74 |
# File 'ext/sooth_native/native.c', line 73 def load(filename) end |
#observe(context, event) ⇒ Fixnum
Register an observation of the given event within the given context.
19 20 21 |
# File 'ext/sooth_native/native.c', line 19 def observe(context, event) # (native code) end |
#save(filename) ⇒ Object
Save the predictor to a file that can be loaded later.
80 81 |
# File 'ext/sooth_native/native.c', line 80 def save(filename) end |
#select(context, limit) ⇒ Fixnum
Return an event that may occur in the given context, based on the limit, which should be between 1 and #count. The event is selected by iterating through all observed events for the context, subtracting the observation count of each event from the limit until it is zero or less.
22 23 24 |
# File 'ext/sooth_native/native.c', line 22 def select(context, limit) # (native code) end |
#size(context) ⇒ Fixnum
Return the number of different events that have been observed within the given context.
92 93 94 |
# File 'ext/sooth_native/native.c', line 92 def size(context) # (native code) end |
#surprise(context, event) ⇒ Float
Return a number indicating the surprise received by the predictor when it observed the given event within the given context. Note that nil will be returned if the event has never been observed within the context.
31 32 33 |
# File 'ext/sooth_native/native.c', line 31 def surprise(context, event) # (native code) end |
#uncertainty(context) ⇒ Float
Return a number indicating how uncertain the predictor is about which event is likely to be observed after the given context. Note that nil will be returned if the context has never been observed.
28 29 30 |
# File 'ext/sooth_native/native.c', line 28 def uncertainty(context) # (native code) end |