|
FreeTensor
|
#include <rand_ctx.h>


Public Member Functions | |
| RandCtx (RNG &rng) | |
| int | decide (ProgramPosition pos, const std::string &name, const RandCondStack &condStack, const std::vector< double > &priori, const Ref< RandTrace > &trace, const std::string &message="") |
Public Member Functions inherited from freetensor::RandCtxImpl | |
| void | observeTrace (const Ref< RandTrace > &trace, double value, double stddev) |
| void | setLearnFilter (const std::regex &toLearn) |
| void | setLearn () |
| void | setInfer () |
Additional Inherited Members | |
Protected Attributes inherited from freetensor::RandCtxImpl | |
| std::unordered_map< ProgramPosition, std::unordered_map< Ref< RandCondInterface >, Ref< DiscreteRandVar >, PtrInvocable< std::hash< RandCondInterface > >, PtrInvocable< std::equal_to< RandCondInterface > > > > | randVars_ |
| std::unordered_map< ProgramPosition, Ref< std::vector< int > > > | totCnt_ |
| std::multimap< Ref< RandTrace >, std::pair< double, double >, PtrInvocable< std::less< RandTrace > > > | traces_ |
| bool | isInfer_ = true |
| std::regex | toLearn_ {".*"} |
| std::mutex | lock_ |
Context to do random decisions
If setLearned, sample a decision and use the decision traces to learn a Bayesian model. Each trace is labeled with a performance value, and traces are compared pairwisely (lower is better), to learn P(this decision leads to
better performance).
|
inline |
|
inline |
Get decision from a random variable uniquely defined by conditions and the program position
If learning, sample a random variable and record it as a trace. If infering, pick a most likely decision
This function is thread-safe