5#ifndef LINE_SOLVERS_CTMC_SOLVER_CTMC_SAMPLE_H
6#define LINE_SOLVERS_CTMC_SOLVER_CTMC_SAMPLE_H
68 std::size_t nevents,
unsigned long seed = 23000) {
70 "solver_ctmc_sample_sys draws exponential holding times as -mean*log(u), which "
71 "is transcendental; use --arith double or real");
75 opt.keep_filtration =
true;
78 const std::size_t n = out.
chain.chain.space.size();
79 const std::size_t A = out.
chain.chain.filt.size();
85 std::size_t cur = analyzer_detail::init_state_index(
sn, out.
chain.chain.space);
86 if (cur ==
static_cast<std::size_t
>(-1))
88 "solver_ctmc_sample_sys: the initial state is not contained in the state space, so "
89 "there is no state to start the trace from");
93 for (std::size_t step = 0; step < nevents; ++step) {
95 out.
state.push_back(cur);
103 out.
event.push_back(
static_cast<std::size_t
>(-1));
114 std::size_t pick_a =
static_cast<std::size_t
>(-1), pick_s = cur;
115 for (std::size_t a = 0; a < A && pick_a == static_cast<std::size_t>(-1); ++a)
116 for (std::size_t j = 0; j < n; ++j) {
117 if (j == cur)
continue;
119 if (w <= 0)
continue;
129 if (pick_a ==
static_cast<std::size_t
>(-1))
130 for (std::size_t a = 0; a < A; ++a)
131 for (std::size_t j = 0; j < n; ++j)
136 out.
event.push_back(pick_a);
154 for (std::size_t i = 0; i < path.
state.size(); ++i)
155 for (std::size_t c = 0; c < A.
cols(); ++c) out(i, c) = A(path.
state[i], c);
171 const std::size_t isf =
sn.stateful_index(ind);
172 if (isf == 0)
throw InputError(
"solver_ctmc_sample: node " + std::to_string(ind) +
173 " is not stateful, so it has no state to sample");
174 const std::size_t w = path.
chain.chain.space[0].local[isf - 1].size();
176 for (std::size_t i = 0; i < path.
state.size(); ++i)
177 for (std::size_t c = 0; c < w; ++c)
178 out(i, c) = path.
chain.chain.space[path.
state[i]].local[isf - 1][c];
186 const std::size_t isf =
sn.stateful_index(ind);
187 if (isf == 0)
throw InputError(
"solver_ctmc_sample_aggr: node " + std::to_string(ind) +
188 " is not stateful, so it has no state to sample");
189 const std::size_t K =
sn.nclasses;
191 for (std::size_t i = 0; i < path.
state.size(); ++i) {
192 const std::vector<T> m = prob_detail::marginal_of(
193 sn, ind, path.
chain.chain.space[path.
state[i]].local[isf - 1]);
194 for (std::size_t k = 0; k < K && k < m.size(); ++k) out(i, k) = m[k];
A network plus its refreshed NetworkStruct.
The exception types the port throws.
Dense matrix and non-owning view.
void assert_phase_type_states(const NetworkStruct< T > &sn, const std::string &what)
Port of @@SolverCTMC/assertPhaseTypeStates: refuse a query whose answer would be a per-state probabil...
Matrix< T > solver_ctmc_sample(const NetworkStruct< T > &sn, const CtmcSamplePath< T > &path, std::size_t ind)
Port of @@SolverCTMC/sample: the walk restricted to ONE stateful node's local block.
Matrix< T > solver_ctmc_sample_aggr(const NetworkStruct< T > &sn, const CtmcSamplePath< T > &path, std::size_t ind)
Port of @@SolverCTMC/sampleAggr: one node's per-class counts over time.
CtmcSamplePath< T > solver_ctmc_sample_sys(const NetworkStruct< T > &sn, const CtmcOptions &opt_in, std::size_t nevents, unsigned long seed=23000)
Port of @@SolverCTMC/sampleSys: a marked walk on the whole network state.
CtmcSolution< T > solver_ctmc_analyzer(const NetworkStruct< T > &sn_in, const CtmcOptions &opt)
Port of solver_ctmc_analyzer.m plus the fork-join wrapper of @@SolverCTMC/runAnalyzer....
Matrix< T > ctmc_state_space_aggr(const NetworkStruct< T > &sn, const std::vector< NetState< T > > &space)
Port of StateSpaceAggr: the per-(station, class) job counts of every state, as an (nstates x nstation...
Matrix< T > solver_ctmc_sample_sys_aggr(const NetworkStruct< T > &sn, const CtmcSamplePath< T > &path)
Port of @@SolverCTMC/sampleSysAggr: the same walk, reported as per-(station, class) job counts rather...
std::mt19937_64 McRng
The generator type every Monte Carlo entry point in this tree accepts.
T mc_uniform(McRng &g)
The same deviate materialized in the working arithmetic.
A queueing network and its refreshed NetworkStruct.
Randomness scaffolding shared by the Monte Carlo normalizing-constant estimators (pfqn_mci,...
Port of solver_ctmc_analyzer.m and the parts of @@SolverCTMC/runAnalyzer.m that surround one solve: t...
The SolverCTMC probability family: solver_ctmc_joint, _jointaggr, _marg, _margaggr,...
The SolverCTMC knobs this port honours.
One sampled trajectory of the chain.
std::vector< std::size_t > event
synchronization that fired to LEAVE it
std::vector< std::size_t > state
0-based index into chain.space
std::vector< T > t
time at which each state was ENTERED
Everything one CTMC solve produces.