LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
infer_lqn_getobs.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2012-2026, QORE Lab, Imperial College London
3
* All rights reserved.
4
*/
5
#ifndef LINE_API_INFER_INFER_LQN_GETOBS_H
6
#define LINE_API_INFER_INFER_LQN_GETOBS_H
7
8
/**
9
* @file
10
* @ingroup api_infer
11
* Observation vector of a solved LQN, z = h(a).
12
*
13
* Templated port of matlab/src/api/infer/infer_lqn_getobs.m. The JAR carries
14
* the same selection inline inside jline/api/infer/InferLqn.java.
15
*
16
* This is the measurement half of the LQN parameter identification method of
17
* Zheng, Yang, Woodside, Litoiu, Iszlai, "Tracking Time-Varying Parameters in
18
* Software Systems with Extended Kalman Filters", CASCON 2005: given the
19
* per-element metric vectors of a solved model, it selects the entries the
20
* filter observes, in the order the specification lists them. It is the map
21
* whose sensitivity infer_lqn_jacobian differentiates and whose residual
22
* infer_lqn_ekf corrects on.
23
*
24
* The metric name is an enum here rather than MATLAB's case-insensitive
25
* string, so an unknown metric is a compile error instead of a runtime one;
26
* the only runtime rejection left is the one MATLAB also makes, an element
27
* name absent from the LQN. That rejection is an InputError and NOT a
28
* not-a-number or a zero: an observation silently read off the wrong element
29
* would be indistinguishable from a badly fitting model.
30
*
31
* ARITHMETIC: selection and copying only, no operation on the values at all,
32
* so the port is exact in every instantiation.
33
*/
34
35
#include <cstddef>
36
#include <string>
37
#include <vector>
38
39
#include "
line/api/infer/infer_lqn_findbyname.h
"
40
#include "
line/num/number.h
"
41
#include "
line/util/error.h
"
42
43
namespace
line
{
44
namespace
infer
{
45
46
/** The four per-element metrics of a solved LQN, as in getEnsembleAvg. */
47
enum class
LqnMetric
{
QLen
,
Util
,
RespT
,
Tput
};
48
49
/**
50
* Per-element metric vectors, each aligned with the element name list.
51
* Mirrors the struct MATLAB passes as METRICS.
52
*/
53
template
<
class
T>
54
struct
LqnMetrics
{
55
std::vector<T>
QLen
;
56
std::vector<T>
Util
;
57
std::vector<T>
RespT
;
58
std::vector<T>
Tput
;
59
};
60
61
/** One row of MATLAB's OBSSPEC struct array. */
62
struct
LqnObsSpec
{
63
LqnMetric
metric
;
64
std::string
name
;
65
};
66
67
/**
68
* @brief Observation vector of a solved LQN, z = h(a).
69
*
70
* @param names element names, as in LayeredNetworkStruct.names
71
* @param metrics per-element metric vectors, indexed like names
72
* @param spec observations to extract, in order
73
* @return (numel(spec)) observation vector
74
*/
75
template
<
class
T>
76
std::vector<T>
infer_lqn_getobs
(
const
std::vector<std::string>& names,
77
const
LqnMetrics<T>
& metrics,
78
const
std::vector<LqnObsSpec>& spec) {
79
std::vector<T> z;
80
z.reserve(spec.size());
81
for
(std::size_t i = 0; i < spec.size(); ++i) {
82
const
std::size_t idx =
infer_lqn_findbyname
(names, spec[i].name);
83
if
(idx ==
INFER_LQN_NOT_FOUND
)
84
throw
InputError
(
"infer_lqn_getobs: element '"
+ spec[i].name +
85
"' not found in the LQN"
);
86
const
std::vector<T>* v =
nullptr
;
87
switch
(spec[i].metric) {
88
case
LqnMetric::QLen
:
89
v = &metrics.
QLen
;
90
break
;
91
case
LqnMetric::Util
:
92
v = &metrics.
Util
;
93
break
;
94
case
LqnMetric::RespT
:
95
v = &metrics.
RespT
;
96
break
;
97
case
LqnMetric::Tput
:
98
v = &metrics.
Tput
;
99
break
;
100
}
101
if
(idx >= v->size())
102
throw
InputError
(
"infer_lqn_getobs: metric vector shorter than the element list"
);
103
z.push_back((*v)[idx]);
104
}
105
return
z;
106
}
107
108
}
// namespace infer
109
}
// namespace line
110
111
#endif
// LINE_API_INFER_INFER_LQN_GETOBS_H
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
error.h
The exception types the port throws.
infer_lqn_findbyname.h
First element of a named LQN container matching a name.
line::infer
Definition
infer_compute_ql_at_arrival.h:39
line::infer::INFER_LQN_NOT_FOUND
static const std::size_t INFER_LQN_NOT_FOUND
Returned when no element carries the requested name, MATLAB's [].
Definition
infer_lqn_findbyname.h:40
line::infer::infer_lqn_findbyname
std::size_t infer_lqn_findbyname(const std::vector< std::string > &names, const std::string &name)
First element of a named LQN container matching a name.
Definition
infer_lqn_findbyname.h:49
line::infer::LqnMetric
LqnMetric
The four per-element metrics of a solved LQN, as in getEnsembleAvg.
Definition
infer_lqn_getobs.h:47
line::infer::LqnMetric::Util
@ Util
Definition
infer_lqn_getobs.h:47
line::infer::LqnMetric::Tput
@ Tput
Definition
infer_lqn_getobs.h:47
line::infer::LqnMetric::RespT
@ RespT
Definition
infer_lqn_getobs.h:47
line::infer::LqnMetric::QLen
@ QLen
Definition
infer_lqn_getobs.h:47
line::infer::infer_lqn_getobs
std::vector< T > infer_lqn_getobs(const std::vector< std::string > &names, const LqnMetrics< T > &metrics, const std::vector< LqnObsSpec > &spec)
Observation vector of a solved LQN, z = h(a).
Definition
infer_lqn_getobs.h:76
line
Definition
aoi_dist2ph.h:52
number.h
Number-type abstraction for the templated API port.
line::infer::LqnMetrics
Per-element metric vectors, each aligned with the element name list.
Definition
infer_lqn_getobs.h:54
line::infer::LqnMetrics::Tput
std::vector< T > Tput
Definition
infer_lqn_getobs.h:58
line::infer::LqnMetrics::Util
std::vector< T > Util
Definition
infer_lqn_getobs.h:56
line::infer::LqnMetrics::RespT
std::vector< T > RespT
Definition
infer_lqn_getobs.h:57
line::infer::LqnMetrics::QLen
std::vector< T > QLen
Definition
infer_lqn_getobs.h:55
line::infer::LqnObsSpec
One row of MATLAB's OBSSPEC struct array.
Definition
infer_lqn_getobs.h:62
line::infer::LqnObsSpec::name
std::string name
Definition
infer_lqn_getobs.h:64
line::infer::LqnObsSpec::metric
LqnMetric metric
Definition
infer_lqn_getobs.h:63
include
line
api
infer
infer_lqn_getobs.h
Generated by
1.18.0