2
/******************************************************
3
* Presage, an extensible predictive text entry system
4
* ---------------------------------------------------
6
* Copyright (C) 2008 Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License along
19
with this program; if not, write to the Free Software Foundation, Inc.,
20
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25
#ifndef PRESAGE_RECENCYPREDICTOR
26
#define PRESAGE_RECENCYPREDICTOR
28
#include "predictor.h"
29
#include "../core/logger.h"
30
#include "../core/dispatcher.h"
32
/** Recency predictor, a recency promotion statistical predictor.
34
* RecencyPredictor, based on recency promotion principle, generates
35
* predictions by assigning exponentially decaying probability values
36
* to previously encountered tokens. Tokens are assigned a probability
37
* value that decays exponentially with their distance from the
38
* current token, thereby promoting context recency
40
* (from Wikipedia) A quantity is said to be subject to exponential
41
* decay if it decreases at a rate proportional to its
42
* value. Symbolically, this can be expressed as the following
43
* differential equation, where N is the quantity and λ is a positive
44
* number called the decay constant.
46
* frac{dN}{dt} = -lambda N.
48
* The solution to this equation is below:
50
* N(t) = N_0 e^{-lambda t}
52
* Here N(t) is the quantity at time t, and N0 = N(0) is the (initial)
53
* quantity, at time t = 0.
55
* This is the form of the equation that is most commonly used to
56
* describe exponential decay. The constant of integration N0 denotes
57
* the original quantity at t = 0. (The notation λ for the decay
58
* constant is a remnant of the usual notation for an eigenvalue. In
59
* this case, λ is the eigenvalue of the opposite of the
60
* differentiation operator with N(t) as the corresponding
64
class RecencyPredictor : public Predictor, public Observer {
66
RecencyPredictor(Configuration*, ContextTracker*);
69
virtual Prediction predict(const size_t size, const char** filter) const;
71
virtual void learn(const std::vector<std::string>& change);
73
virtual void update (const Observable* variable);
76
void set_lambda (const std::string& value);
77
void set_n_0 (const std::string& value);
78
void set_cutoff_threshold (const std::string& value);
80
static const char* LOGGER;
81
static const char* LAMBDA;
82
static const char* N_0;
83
static const char* CUTOFF_THRESHOLD;
87
size_t cutoff_threshold;
89
Dispatcher<RecencyPredictor> dispatcher;
93
#endif // PRESAGE_RECENCYPREDICTOR