forked from hxim/paq8px
-
Notifications
You must be signed in to change notification settings - Fork 0
/
APM1.hpp
37 lines (34 loc) · 1.06 KB
/
APM1.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once
#include <cstdint>
#include <cassert>
#include "Shared.hpp"
/**
* APM1 maps a probability and a context into a new probability that bit y will next be 1.
* After each guess it updates its state to improve future guesses.
* Probabilities are scaled 12 bits (0-4095).
*/
class APM1 : IPredictor {
private:
const Shared * const shared;
int index; /**< last p, context */
const int n; /**< number of contexts */
Array<uint16_t> t; /**< [n][33]: p, context -> p */
const int rate;
public:
/**
* Creates an instance with @ref n contexts and learning rate @ref r.
* @ref r determines the learning rate. Smaller = faster, must be in the range (0, 32).
* Uses 66*n bytes memory.
* @param n the number of contexts
* @param r the learning rate
*/
APM1(const Shared* const sh, int n, int r);
/**
* Returns adjusted probability in context @ref cx (0 to n-1).
* @param pr initial (pre-adjusted) probability
* @param cxt the context
* @return adjusted probability
*/
int p(int pr, int cxt);
void update() override;
};