FreeTensor
Loading...
Searching...
No Matches
Public Member Functions | List of all members
freetensor::RandCtx< RNG > Class Template Reference

#include <rand_ctx.h>

Inheritance diagram for freetensor::RandCtx< RNG >:
Inheritance graph
[legend]
Collaboration diagram for freetensor::RandCtx< RNG >:
Collaboration graph
[legend]

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_
 

Detailed Description

template<std::uniform_random_bit_generator RNG>
class freetensor::RandCtx< RNG >

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).

Constructor & Destructor Documentation

◆ RandCtx()

template<std::uniform_random_bit_generator RNG>
freetensor::RandCtx< RNG >::RandCtx ( RNG &  rng)
inline

Member Function Documentation

◆ decide()

template<std::uniform_random_bit_generator RNG>
int freetensor::RandCtx< RNG >::decide ( ProgramPosition  pos,
const std::string &  name,
const RandCondStack condStack,
const std::vector< double > &  priori,
const Ref< RandTrace > &  trace,
const std::string &  message = "" 
)
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


The documentation for this class was generated from the following file: