Fleet  0.0.9
Inference in the LOT
DeterministicLOTHypothesis.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "LOTHypothesis.h"
4 
5 template<typename this_t,
6  typename _input_t,
7  typename _output_t,
8  typename _Grammar_t,
9  _Grammar_t* grammar,
10  typename _datum_t=defaultdatum_t<_input_t, _output_t>,
11  typename _data_t=std::vector<_datum_t>,
12  typename _VirtualMachineState_t=typename _Grammar_t::VirtualMachineState_t
13  >
14 class DeterministicLOTHypothesis : public LOTHypothesis<this_t, _input_t, _output_t, _Grammar_t, grammar, _datum_t, _data_t, _VirtualMachineState_t> {
15 public:
16 
18  using Super::Super;
19 
24 
32  virtual output_t call(const input_t x, const output_t& err=output_t{}) {
33  if constexpr (std::is_same<typename VirtualMachineState_t::input_t, input_t>::value and
34  std::is_same<typename VirtualMachineState_t::output_t, output_t>::value) {
35 
36  assert(not this->program.empty());
37 
38  // we can use this if we are guaranteed that we don't have a stochastic Hypothesis
39  // the savings is that we don't have to create a VirtualMachinePool
40  VirtualMachineState_t vms(x, err, nullptr);
41 
42  vms.program = this->program; // write my program into vms (program->loader is used for everything else)
43 
44  // see below in call()
45  this->was_called = true;
46 
47  const auto out = vms.run();
48  this->total_instruction_count_last_call = vms.runtime_counter.total;
49  this->total_vms_steps = 1;
50 
51  return out;
52 
53  } else {
54  print(typeid(input_t).name(), typeid(output_t).name(), typeid(typename VirtualMachineState_t::input_t).name(), typeid(typename VirtualMachineState_t::output_t).name());
55  UNUSED(x); UNUSED(err);
56  assert(false && "*** Cannot use call when VirtualMachineState_t has different input_t or output_t.");
57  }
58  }
59 
60 };
MyGrammar grammar
void UNUSED(const T &x)
Definition: Miscellaneous.h:38
_input_t input_t
Definition: LOTHypothesis.h:50
_VirtualMachineState_t VirtualMachineState_t
Definition: LOTHypothesis.h:52
Program< VirtualMachineState_t > program
Definition: LOTHypothesis.h:68
virtual output_t call(const input_t x, const output_t &err=output_t{})
A variant of call that assumes no stochasticity and therefore outputs only a single value...
Definition: DeterministicLOTHypothesis.h:32
void print(FIRST f, ARGS... args)
Lock output_lock and print to std:cout.
Definition: IO.h:53
Definition: Datum.h:15
unsigned long total_vms_steps
Definition: LOTHypothesis.h:65
Definition: DeterministicLOTHypothesis.h:14
_output_t output_t
Definition: LOTHypothesis.h:51
Super::VirtualMachineState_t VirtualMachineState_t
Definition: DeterministicLOTHypothesis.h:23
Definition: LOTHypothesis.h:40
A LOTHypothesis is the basic unit for doing LOT models. It store a Node as its value, and handles all of the proposing and computing priors, likelihoods, etc. It compiles this Node into a "program" which is used to make function calls, which means that the value should only be changed via LOTHypothesis::set_value.
unsigned long total_instruction_count_last_call
Definition: LOTHypothesis.h:64
bool was_called
Definition: Program.h:23