LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
mtrace_moment.h File Reference

Empirical class-dependent moments of a marked trace. More...

#include <cstddef>
#include <vector>
#include "line/api/trace/trace_types.h"
#include "line/num/number.h"
#include "line/util/error.h"
#include "line/util/matrix.h"
Include dependency graph for mtrace_moment.h:

Go to the source code of this file.

Namespaces

namespace  line
namespace  line::trace

Functions

template<class T>
Matrix< T > line::trace::mtrace_moment (const std::vector< T > &Tv, const std::vector< int > &A, const std::vector< unsigned > &orders, bool after=false, bool norm=false)
 Empirical class-dependent moments of a marked trace.

Detailed Description

Empirical class-dependent moments of a marked trace.

Templated port of matlab/lib/m3a/m3a/mtrace/mtrace_moment.m, cross-checked against jar/src/main/java/jline/api/trace/Mtrace_moment.java.

after = false (Horvath variables): M(c,j) = (1/N) sum_{i: A_i=c} T_i^k after = true (Buchholz variables): M(c,j) = (1/(N-1)) sum_{i<N: A_i=c} T_{i+1}^k

and with norm = true each entry is multiplied by N/count_c, which turns the contribution into the class-conditional moment normalized so that M_k = sum_c M(c,k) * p_c with p_c = count_c/N the class probabilities of mtrace_pc.

REFERENCE DEFECT (JAR): Mtrace_moment.java divides the class sum by count_c ALREADY in the unnormalized branch, so its norm = 0 output is MATLAB's norm = 1 output, and its norm = 1 output is that value multiplied by N/count_c a SECOND time – a quantity that is neither of the two documented normalizations and that diverges as the class becomes rare. Consequently sum_c M_java(c,k) is not the class-independent moment for either flag value. MATLAB is the reference and is implemented here. Measured on T = 1,2,3,4,5 with A = 1,2,1,2,1 and order 1: MATLAB returns (9/5, 6/5) unnormalized and (3, 3) normalized, the JAR returns (3, 3) and (5, 15/2). Only the MATLAB pair sums to the trace mean 3.

A second, smaller divergence: for after = true the JAR normalizes by (N-1)/count_c whereas MATLAB uses N/count_c (its length(T-1) is the length of the elementwise T-1, i.e. N). MATLAB's factor is the one consistent with p_c = count_c/N, so it is kept.

ARITHMETIC: sums of integer powers and a division, exact in Rational.

Definition in file mtrace_moment.h.