// Encodes a value onto the end of a symbol list using "bits" symbols public void encode(symbol_list_t symlist, int value, int bits) { for (int i = 0; i < bits; i++, value /= 2) { bool sym = ((value & 1) != 0); symlist.push_back(sym); } }
// generate a specified number of random symbols distributed according to // the context tree statistics and update the context tree with the newly // generated bits public void genRandomSymbolsAndUpdate(Random rng, symbol_list_t symbols, UInt64 bits) { // TODONE: implement symbols.clear(); //Random rng = new Random(); for (UInt64 i = 0; i < bits; i++) { // flip a biased coin for each bit double prediction = predict(false); bool rand_sym = rng.NextDouble() < prediction ? false : true; symbols.push_back(rand_sym); update(rand_sym); // TODO: optimise this loop } }
void getContext(symbol_list_t context) { // if (!m_context_functor.empty()) // { // m_context_functor(context); // return; // } context.clear(); // history_t::const_reverse_iterator ri = m_history.rbegin(); int ri = m_history.mem.Count - 1; for (UInt64 c = 0; ri >= 0 && c < m_depth; --ri, c++) { context.push_back((bool)m_history.mem[(int)ri]); } }