14 extern volatile sig_atomic_t
CTRL_C;
35 template<
typename HYP>
41 static constexpr
size_t N = 1000000;
46 static typename HYP::data_t*
data;
51 BeamSearch(HYP& h0,
typename HYP::data_t* d,
double temp) : Q(N) {
59 for(
size_t i=0;i<1000 and !
CTRL_C;i++) {
73 assert(not Q.
empty() &&
"*** You should have pushed a non -inf value into Q above -- are you sure its possible?");
77 void add(HYP&& h) { Q.
add(std::move(h)); }
92 #ifdef DEBUG_BEAMSEARCH 93 CERR std::this_thread::get_id()
TAB "BeamSearch popped " << t.posterior
TAB t.string()
ENDL;
96 size_t neigh = t.neighbors();
97 assert(neigh>0 &&
"*** Your starting state has zero neighbors -- did you remember to give it a LOTHypothesis with an empty value?");
98 for(
size_t k=0;k<neigh and ctl.
running();k++) {
99 auto v = t.make_neighbor(k);
103 if(v.is_evaluable()) {
105 v.compute_posterior(*data);
116 for(
size_t i=0;i<N_REPS and not
CTRL_C;i++) {
117 auto g = v; g.complete();
118 g.compute_posterior(*data);
123 if(not std::isnan(g.likelihood)) {
124 likelihood = std::max(likelihood, g.likelihood / temperature);
130 v.likelihood = likelihood;
131 v.posterior = v.compute_prior() + v.likelihood;
150 template<
typename HYP>
153 template<
typename HYP>
volatile sig_atomic_t CTRL_C
const T & best() const
Definition: TopN.h:219
#define TAB
Definition: IO.h:19
Definition: BeamSearch.h:36
void add(HYP &&h)
Definition: BeamSearch.h:77
TopN compute_posterior(data_t &data)
Definition: TopN.h:293
static constexpr size_t N_REPS
Definition: BeamSearch.h:43
void pop()
Pops off the top – you usually won't want to do this and it's not efficient.
Definition: TopN.h:214
void start()
Definition: Control.h:54
This manages multiple threads for running inference. This requires a subclass to define run_thread...
generator< HYP & > run_thread(Control &ctl) override
Definition: BeamSearch.h:79
static constexpr size_t N
Definition: BeamSearch.h:41
constexpr double infinity
Definition: Numerics.h:20
Definition: generator.hpp:21
static double temperature
Definition: BeamSearch.h:45
static HYP::data_t * data
Definition: BeamSearch.h:46
#define CERR
Definition: IO.h:23
std::atomic< uintmax_t > beam_steps(0)
#define ENDL
Definition: IO.h:21
void add(HYP &h)
Definition: BeamSearch.h:76
BeamSearch(HYP &h0, typename HYP::data_t *d, double temp)
Definition: BeamSearch.h:51
TopN< HYP > Q
Definition: BeamSearch.h:49
Definition: ThreadedInferenceInterface.h:22
bool add(const T &x)
Adds x to the TopN. This will return true if we added (false otherwise)
Definition: TopN.h:137
bool running()
Definition: Control.h:63
bool empty() const
Definition: TopN.h:103
static constexpr double PARENT_PENALTY
Definition: BeamSearch.h:44
This class has all the information for running MCMC or MCTS in a little package. It defaultly constru...