lppl  v2.0.0
record.hpp File Reference
#include <cstddef>
#include <forward_list>
#include <functional>
#include <memory>
#include <optional>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <type_traits>
#include <utility>
#include <variant>
#include <domains.hpp>
#include <functional_util.hpp>
#include <distribution_traits.hpp>

Classes

struct  node_t< D >
 A fundamental data structure that includes address, distribution, sampled value type, score, whether the value was observed, and a markov process over interpretations. More...
 
struct  NodeBlock
 
struct  NodeCondition
 
struct  NodeParameter
 
struct  NodePropose
 
struct  NodeReplace
 
struct  NodeReplay
 
struct  NodeStandard
 
struct  Obs
 
struct  ParamConstructor< V, Ts >
 
struct  record_t< DTypes< Ts... > >
 A fundamental data structure that holds a mapping from addresses to nodes, an insertion order, and a record-level interpretation. More...
 
struct  RecordBlock< Obs >
 
struct  RecordBlock< Sample >
 
struct  RecordReplace
 
struct  RecordReplay
 
struct  RecordRewrite
 
struct  RecordStandard
 
struct  Sample
 

Typedefs

template<typename... Ds>
using data_types = unique_variant_t< var_ret_t< Ds... > >
 
template<typename... Ds>
using DTypes = Holder< Ds... >
 
using node_interpretation = std::variant< NodeStandard, NodeReplay, NodeReplace, NodeCondition, NodeBlock, NodePropose, NodeParameter >
 Semantic instructions for actions to perform on the node.
 
template<typename... Ts>
using node_map_t = std::unordered_map< std::string, var_node_t< Ts... > >
 
template<typename... Ds>
using param_store = std::unordered_map< std::string, data_types< Ds... > >
 
template<typename I , typename O , typename... Ts>
using pp_t = std::function< O(record_t< DTypes< Ts... > > &, I)>
 A shorthand for probabilistic program type. Probabilistic programs are callables that take a single input of type I, output a single value of type O, and contain an arbitrary positive number of distributions of type Ts... More...
 
using record_interpretation = std::variant< RecordStandard, RecordReplay, RecordReplace, RecordRewrite, RecordBlock< Obs >, RecordBlock< Sample > >
 Semantic instructions for operations to perform on the record.
 
template<typename... Ts>
using var_node_t = std::variant< node_t< Ts >... >
 
template<typename... Ts>
using var_ret_t = std::variant< DSType< Ts >... >
 

Functions

template<typename D , typename V , typename... Ts>
_block_observe (record_t< DTypes< Ts... >> &r, std::string address, D, V value)
 
template<typename D , typename RNG , typename... Ts>
DSType< D > _block_sample (record_t< DTypes< Ts... >> &r, std::string address, D dist, RNG &rng)
 
template<typename D , typename... Ts>
DSType< D > _condition (record_t< DTypes< Ts... >> &r, std::string address, D dist)
 
template<typename D , typename V , typename... Ts>
_observe (record_t< DTypes< Ts... >> &r, std::string address, D dist, V value)
 
template<typename D , typename V , typename... Ts>
_observe_with_node_interp (record_t< DTypes< Ts... >> &r, std::string address, D dist, V value)
 
template<typename D , typename V , typename... Ts>
_observe_with_record_interp (record_t< DTypes< Ts... >> &r, std::string address, D dist, V value)
 
template<typename D , typename RNG , typename... Ts>
DSType< D > _replace (record_t< DTypes< Ts... >> &r, std::string address, D orig_dist, RNG &rng)
 
template<typename D , typename V , typename... Ts>
_replace_observe (record_t< DTypes< Ts... >> &r, std::string address, D orig_dist, V value)
 
template<typename D , typename RNG , typename... Ts>
DSType< D > _replay (record_t< DTypes< Ts... >> &r, std::string address, D dist, RNG &rng)
 
template<typename D , typename RNG , typename... Ts>
DSType< D > _rewrite (record_t< DTypes< Ts... >> &r, std::string address, D orig_dist, RNG &rng)
 
template<typename D , typename RNG , typename... Ts>
DSType< D > _sample_with_node_interp (record_t< DTypes< Ts... >> &r, std::string address, D dist, RNG &rng)
 
template<typename D , typename RNG , typename... Ts>
DSType< D > _sample_with_record_interp (record_t< DTypes< Ts... >> &r, std::string address, D dist, RNG &rng)
 
template<typename D , typename RNG , typename... Ts>
DSType< D > _standard (record_t< DTypes< Ts... >> &r, std::string address, D dist, RNG &rng)
 
template<typename... Ts>
std::string display (record_t< DTypes< Ts... >> &record)
 Returns a string representation of the record. Does not display node- or record-level interpretations. More...
 
template<template< typename, typename > class Map, typename V >
std::optional< V > get (Map< std::string, V > &map_, std::string &address)
 
template<typename... Ts>
double loglatent (record_t< DTypes< Ts... >> &record)
 Computes the cumulative log-latent of the record, \( \sum_{a\ unobserved} \log p(r(a)) \). More...
 
template<typename... Ts>
double loglikelihood (record_t< DTypes< Ts... >> &record)
 Computes the cumulative log-likelihood of the record, \( \sum_{a\ observed} \log p(r(a)) \). More...
 
template<typename... Ts>
double loglikelihood (record_t< DTypes< Ts... >> &record, std::function< double(double)> &&scale)
 Computes the scaled cumulative log-likelihood of the record, \( \sum_{a\ observed} \beta(\log p(r(a))) \). More...
 
template<typename... Ts>
double loglikelihood (record_t< DTypes< Ts... >> &record, std::function< double(std::string &, double)> &&scale)
 Computes the scaled cumulative log-likelihood of the record on a per-address basis, \( \sum_{a\ observed} \beta(a, \log p(r(a))) \). More...
 
template<typename... Ts>
double logprob (record_t< DTypes< Ts... >> &record)
 Computes the cumulative log probability of the record, \( \log p(x, z) \).
 
template<typename D , typename V >
node_t< D > observe (D dist, V value)
 Creates a node with specified address by scoring passed value from corresponding distribution.
 
template<typename D , typename V , typename... Ts>
observe (record_t< DTypes< Ts... >> &r, std::string address, D dist, V value)
 Scores the passed value against the distribution, storing the result in the record at the specified address. More...
 
template<typename V , typename... Ts>
ParamConstructor< V, Ts... > param (record_t< DTypes< Ts... >> &r, std::string address)
 
template<typename D , typename RNG >
node_t< D > sample (D dist, RNG &rng)
 Creates a node with specified address by sampling value from corresponding distribution, then scoring it.
 
template<typename D , typename RNG , typename... Ts>
DSType< D > sample (record_t< DTypes< Ts... >> &r, std::string address, D dist, RNG &rng)
 Samples a value into a node stored at the address by drawing a value from the specified distribution. Returns the underlying value of the created node. More...
 
template<template< typename, typename > class Map, typename D , typename RNG , typename... Ts>
DSType< D > sample (record_t< DTypes< Ts... >> &r, std::string address, D dist, RNG &rng, Map< std::string, DSType< D >> &map_)
 Either samples a value from the specified distribution or observes a value against it, depending on whether there is data at the corresponding address in the passed Map<std::string, DSType<D>>. More...
 
template<typename D , typename RNG , typename... Ts>
DSType< D > sample (record_t< DTypes< Ts... >> &r, std::string address, D dist, RNG &rng, std::optional< DSType< D >> maybe_value)
 Either samples a value from the specified distribution or observes a value against it, depending on whether data or null is passed as maybe_value. More...
 

Detailed Description

This file is part of fmcs. Copyright David Rushing Dewhurst, 2022 - present. Some rights reserved.