|
| CCDResult | ccd_window (const std::vector< arma::mat > &conversations, int max_window=20, int min_overlap=10) |
| | Estimate the ENA moving-window size via cross-covariance decay.
|
| |
|
| arma::mat | between_group_scatter (const arma::mat &V, const arma::uvec &labels, arma::uword n_groups) |
| | Compute the between-group scatter matrix S_B.
|
| |
|
| arma::vec | gmr_direction (const arma::mat &Vx, const arma::vec &target, bool categorical, arma::uword n_groups=0) |
| | Compute the unit rotation direction from a covariate-adjusted contribution matrix.
|
| |
|
| GMRStepResult | gmr_step (const arma::mat &V, const arma::mat &X_model, const arma::vec &target, const arma::uvec &x1_cols, bool categorical, arma::uword n_groups, const arma::uvec &subset, int n_lambda=50, int k_folds=5, double lasso_eps=0.01) |
| | Compute the rotation direction for one axis of the Generalized Means Rotation.
|
| |
|
| RotationResult | generalized_means_rotation (const arma::mat &V, const GeneralizedRotationParams ¶ms) |
| | Full Generalized Means Rotation (GMR) producing a complete q×q rotation matrix.
|
| |
|
| arma::mat | ena_correlation (arma::mat points, arma::mat centroids, double conf_level=0.95) |
| | Pearson correlation with Fisher-z confidence interval between ENA unit points and their centroids.
|
| |
|
| NodePositions | node_positions (arma::mat adj_mats, arma::mat t, int num_dims) |
| | Multiobjective least-squares node positions for undirected ENA.
|
| |
| NodePositions | directed_node_positions (arma::mat line_weights, arma::mat points, int num_dims, bool combine_pairs=false, double self_weight=DIRECTED_SELF_WEIGHT) |
| | Least-squares node positions for directed (ordered) ENA.
|
| |
| NodePositions | node_positions_by_key (const arma::mat &line_weights, const arma::mat &points, int num_dims, const ConnectionKey &key, int n_codes, double self_weight=DIRECTED_SELF_WEIGHT) |
| | Layout-agnostic least-squares node positions: the solve of node_positions / directed_node_positions with node_weights_by_key.
|
| |
|
| RotationResult | ena_svd (const arma::mat &points) |
| | Compute a full SVD rotation of a (pre-centered) points matrix.
|
| |
|
| arma::mat | deflate (const arma::mat &data, const arma::vec &axis) |
| | Project a data matrix onto the hyperplane orthogonal to a given axis.
|
| |
|
| RotationResult | orthogonal_svd (const arma::mat &data, const arma::mat &weights, const std::vector< std::string > &named_labels) |
| | Orthonormalize named axes via QR, then complete the rotation with an SVD of the data projected onto the orthogonal complement.
|
| |
|
| RotationResult | complete_rotation (const arma::mat &data, const arma::mat &named_axes, const std::vector< std::string > &named_labels) |
| | Keep named axes verbatim and fill remaining axes from an SVD of the data after parallel deflation by all named axes.
|
| |
|
| RotationResult | means_rotation (const arma::mat &points, const std::vector< GroupPair > &pairs) |
| | Compute a means rotation from one or more group pairs.
|
| |
|
| enum class | UnitCircleMode { Equal
, Radial
} |
| | How unit_circle_nodes places the nodes on the circle. More...
|
| |
| UnitCircleMode | unit_circle_mode (const std::string &name) |
| | Parse a mode name for the bindings: "equal" or "radial".
|
| |
| arma::mat | unit_circle_nodes (const arma::mat &nodes, arma::uword dim_x, arma::uword dim_y, UnitCircleMode mode=UnitCircleMode::Equal) |
| | Move nodes onto a circle in the plane of two dimensions.
|
| |
| arma::mat | node_centroids (const arma::mat &line_weights, const arma::mat &nodes, bool directed=false, double self_weight=DIRECTED_SELF_WEIGHT) |
| | Unit centroids for a set of node positions.
|
| |
| MovedNodes | move_nodes_to_unit_circle (const arma::mat &line_weights, const arma::mat &nodes, arma::uword dim_x, arma::uword dim_y, UnitCircleMode mode=UnitCircleMode::Equal, bool directed=false, double self_weight=DIRECTED_SELF_WEIGHT) |
| | The post-fit unit-circle move of a model: moved nodes and their centroids.
|
| |
| arma::mat | node_centroids_by_key (const arma::mat &line_weights, const arma::mat &nodes, const ConnectionKey &key, double self_weight=DIRECTED_SELF_WEIGHT) |
| | Layout-agnostic unit centroids: node_weights_by_key times nodes (as node_centroids).
|
| |
| MovedNodes | move_nodes_to_unit_circle_by_key (const arma::mat &line_weights, const arma::mat &nodes, arma::uword dim_x, arma::uword dim_y, UnitCircleMode mode, const ConnectionKey &key, double self_weight=DIRECTED_SELF_WEIGHT) |
| | Layout-agnostic post-fit unit-circle move (as move_nodes_to_unit_circle), centroids from node_centroids_by_key.
|
| |
|
| constexpr double | DIRECTED_SELF_WEIGHT = 2.0 |
| |
| arma::mat | node_weights (const arma::mat &line_weights) |
| | Per-unit node weights for undirected ENA.
|
| |
| arma::mat | directed_node_weights (const arma::mat &line_weights, double self_weight=DIRECTED_SELF_WEIGHT) |
| | Per-unit node weights for directed (ordered) ENA.
|
| |
| ConnectionKey | undirected_connection_key (int n_codes, bool diagonal=false) |
| | Key of the undirected layout: the column-major upper triangle (libqe connection_indices), with the diagonal (A & A, A & B, B & B, ...) when diagonal.
|
| |
| ConnectionKey | directed_connection_key (int n_codes) |
| | Key of the ordered (directed) layout: column j*n+i is ground i -> response j, so from = i and to = j.
|
| |
| arma::mat | node_weights_by_key (const arma::mat &line_weights, const ConnectionKey &key, int n_codes, double self_weight=DIRECTED_SELF_WEIGHT) |
| | Layout-agnostic node weights: every column counts toward each code it connects; a self-connection (from == to) toward its code self_weight times. Each row is then L1-normalised (as node_weights).
|
| |
| RotationResult qe::complete_rotation |
( |
const arma::mat & |
data, |
|
|
const arma::mat & |
named_axes, |
|
|
const std::vector< std::string > & |
named_labels |
|
) |
| |
|
inline |
Keep named axes verbatim and fill remaining axes from an SVD of the data after parallel deflation by all named axes.
Unlike orthogonal_svd(), this routine preserves the caller-supplied named_axes exactly (no QR re-orthonormalization). The complementary axes are obtained by deflating data simultaneously by all named axes and then running ena_svd() on the result.
The deflation is parallel: every projection is subtracted from the original data, not from a progressively deflated copy:
defA = data - data * (named_axes * named_axes^T)
This matches defA <- A - A %*% v1 %*% t(v1) - A %*% v2 %*% t(v2) in rENA line-for-line. For mutually orthogonal axes the result is identical to sequential deflation; for non-orthogonal axes it differs.
- Parameters
-
| data | n x p data matrix. |
| named_axes | p x k matrix of named rotation axes. Each column must be unit-norm; orthonormality between columns is NOT required. |
| named_labels | Length-k vector of labels for the first k axes. Trailing axes receive labels "SVD{k+1}" .. "SVDp". Conventional labels for generalized rotation are "GMR1", "GMR2", then "SVD{k+1}" onward, but labels are entirely caller-supplied. |
- Returns
- A RotationResult where columns 0..k-1 of
rotation equal named_axes verbatim and columns k..p-1 come from the SVD of the deflated data. Columns from the deflated data's null space (rank-deficient data) are orthogonalised against the named axes and each other, so the result is orthonormal whenever the named axes are.
- Note
- Equivalent to the tail of
ena.rotate.by.generalized in rENA (canonical version: commit 2c079126 on rENA origin/main).
- Exceptions
-
| std::runtime_error | if data.n_cols != named_axes.n_rows or named_labels.size() != named_axes.n_cols. |
| NodePositions qe::directed_node_positions |
( |
arma::mat |
line_weights, |
|
|
arma::mat |
points, |
|
|
int |
num_dims, |
|
|
bool |
combine_pairs = false, |
|
|
double |
self_weight = DIRECTED_SELF_WEIGHT |
|
) |
| |
|
inline |
Least-squares node positions for directed (ordered) ENA.
Each row of line_weights is an n_nodes × n_nodes directed weight matrix stored in row-major order. The per-unit node weight for node x accumulates the full row weight plus all column weights directed at x from other nodes. Each row is L1-normalised before solving (directed_node_weights).
When combine_pairs is false (the standard directed case) the system:
is solved directly with W = normalised weight matrix and P = points.
When combine_pairs is true, adjacent row pairs (ground row k and response row k+1) are summed before solving:
W_combined[k/2] = W[k] + W[k+1]
P_combined[k/2] = P[k] + P[k+1]
The system is then solved on the combined matrices, but centroids are projected back using the original (un-combined) weight matrix so that every unit retains its own centroid.
- Parameters
-
| [in] | line_weights | Directed adjacency vectors, n_units × (n_nodes²). |
| [in] | points | Rotated unit points, n_units × n_dims. |
| [in] | num_dims | Number of dimensions to solve for. |
| [in] | combine_pairs | If true, sum adjacent row pairs before solving (ground + response model). Default false. |
| [in] | self_weight | Self-connection multiplier (see directed_node_weights). Default 2. |
- Returns
- A NodePositions struct containing
nodes, centroids, weights, and points.
- Note
- Equivalent to
directed_node_positions() in rENA/ena.cpp when combine_pairs is false.
-
Equivalent to
directed_node_positions_with_ground_response_added() in rENA/ena.cpp when combine_pairs is true.
- Warning
- When
combine_pairs is true, line_weights must have an even number of rows (row_count must be even); odd row counts result in an out-of-bounds access when forming the combined matrices.
| arma::mat qe::directed_node_weights |
( |
const arma::mat & |
line_weights, |
|
|
double |
self_weight = DIRECTED_SELF_WEIGHT |
|
) |
| |
|
inline |
Per-unit node weights for directed (ordered) ENA.
A node's weight is the sum of its column plus the sum of its row of the unit's adjacency matrix: every directed connection's weight goes in full to both of its codes, and a self-connection (the diagonal, ground i × response i) goes to its code self_weight times – twice by default, as it is in both the node's row and its column. Each row is then L1-normalised as in node_weights. This is the weighting directed_node_positions solves with, and the weighting its centroids use.
- Parameters
-
| [in] | line_weights | Directed adjacency vectors, n_units × (n_codes²). |
| [in] | self_weight | Multiplier for a self-connection's contribution to its code: 2 (default, row + column sum) or e.g. 1 (counted once). Must be finite and >= 0. |
- Returns
- n_units × n_codes weights.
| arma::vec qe::gmr_direction |
( |
const arma::mat & |
Vx, |
|
|
const arma::vec & |
target, |
|
|
bool |
categorical, |
|
|
arma::uword |
n_groups = 0 |
|
) |
| |
|
inline |
Compute the unit rotation direction from a covariate-adjusted contribution matrix.
Numeric target: Centres the target, then computes β = (t_c' t_c)^{-1} t_c' Vx (OLS slope from lm(Vx ~ target)). Mirrors R: model = lm(Vx ~ target); beta = coefficients[2,].
Categorical target: Computes the between-group scatter matrix S_B and returns its leading eigenvector (the direction of maximum between-group variance). Mirrors R: sb = compute_SB(Vx, target); r = svd(sb)$v[,1].
- Note
- Mirrors rENA's
gmr() direction computation (commit 46776a1981a90b3a3b2861ed1010e9dbb7acf901).
- Parameters
-
| [in] | Vx | n×q covariate-adjusted contribution matrix. |
| [in] | target | n×1 target variable (numeric float, or 0-based integer codes). |
| [in] | categorical | true if the target is categorical (uses between-group scatter); false for a numeric target (uses OLS slope). |
| [in] | n_groups | Number of distinct groups; only used when categorical is true. |
- Returns
- Unit vector (p×1) representing the rotation direction.
- Exceptions
-
| std::runtime_error | If categorical is true and n_groups < 2. |
| std::runtime_error | If the numeric target has zero variance after centering. |
- Warning
- Throws
std::runtime_error if the resulting direction has zero norm, which can occur when the Lasso-adjusted contribution collapses to zero.
| GMRStepResult qe::gmr_step |
( |
const arma::mat & |
V, |
|
|
const arma::mat & |
X_model, |
|
|
const arma::vec & |
target, |
|
|
const arma::uvec & |
x1_cols, |
|
|
bool |
categorical, |
|
|
arma::uword |
n_groups, |
|
|
const arma::uvec & |
subset, |
|
|
int |
n_lambda = 50, |
|
|
int |
k_folds = 5, |
|
|
double |
lasso_eps = 0.01 |
|
) |
| |
|
inline |
Compute the rotation direction for one axis of the Generalized Means Rotation.
Applies optional row subsetting, performs Lasso-based covariate adjustment (or a simple OLS projection when all columns are target columns), then delegates to gmr_direction() to produce a unit direction vector.
When x1_cols.n_elem >= p (all columns are target columns and there are no penalized covariates), the function falls back to a simple OLS projection: Vx = fitted values from lm(V ~ t).
- Note
- Mirrors rENA's
gmr() step logic (commit 46776a1981a90b3a3b2861ed1010e9dbb7acf901).
- Parameters
-
| [in] | V | n×q matrix of ENA points (full data; subset applied internally). |
| [in] | X_model | n×p model matrix (caller-built; target cols + covariate cols). |
| [in] | target | n×1 target variable (raw float or 0-based integer codes). |
| [in] | x1_cols | 0-based indices of target columns in X_model (unpenalized in Lasso). |
| [in] | categorical | true if the target is categorical. |
| [in] | n_groups | Number of distinct groups (only used when categorical is true). |
| [in] | subset | Optional 0-based row indices to use; empty means use all rows. |
| [in] | n_lambda | Length of the Lasso lambda path (forwarded to lasso_x1_contribution). |
| [in] | k_folds | Number of cross-validation folds (forwarded to lasso_x1_contribution). |
| [in] | lasso_eps | lambda_min = lasso_eps * lambda_max (forwarded to lasso_x1_contribution). |
- Returns
GMRStepResult containing the unit direction vector.
- Exceptions
-
| std::runtime_error | Propagated from gmr_direction() if the direction is degenerate or the target has zero variance. |
Compute a means rotation from one or more group pairs.
For each GroupPair, computes the normalized mean-difference vector on the progressively deflated data and stacks the resulting unit-norm axes into a weights matrix. The final rotation is completed by orthogonal_svd(). The input points is mean-centered before any axes are computed, matching rENA's scale(data, scale=FALSE, center=TRUE).
- Parameters
-
| points | n x p matrix of network positions (raw, not pre-centered). |
| pairs | Ordered list of GroupPair objects. Each pair contributes one "MR" axis in sequence. Must be non-empty. |
- Returns
- A RotationResult with
column_names = {"MR1", ..., "MRm", "SVD{m+1}", ..., "SVDp"} where m = pairs.size().
- Note
- Equivalent to
ena.rotate.by.mean() in rENA/R/ena.rotate.by.mean.R. The progressive deflation (each axis is computed on the data after removing all previous axes) is the key numerical step.
- Warning
- There is NO guard against a zero-norm mean-difference vector. If the two group means are identical on the current deflated data, the axis will contain NaN values (division by zero). This mirrors a latent bug in rENA and is preserved verbatim for numerical fidelity; a safe opt-in guard will be added in a future release.
- Exceptions
-
| std::runtime_error | if pairs is empty. |
| arma::mat qe::node_centroids |
( |
const arma::mat & |
line_weights, |
|
|
const arma::mat & |
nodes, |
|
|
bool |
directed = false, |
|
|
double |
self_weight = DIRECTED_SELF_WEIGHT |
|
) |
| |
|
inline |
Unit centroids for a set of node positions.
The model's node weights (node_weights, or directed_node_weights when directed) times nodes: the centroids node_positions and directed_node_positions return, for any nodes. Given a fit's own nodes it reproduces the fit's centroids; given moved nodes, it gives the centroids that match them.
Line weights rather than raw connection counts: the two give the same weights for the default (binary) weight model, since each unit's line weights are its counts scaled, and the line weights are what the fit used for any weight model.
- Parameters
-
| [in] | line_weights | The model's line weights, n_units × choose(n_codes, 2), or n_units × n_codes² when directed. |
| [in] | nodes | Node positions, n_codes × n_dims. |
| [in] | directed | Ordered (directed) networks. Default false. |
| [in] | self_weight | Directed self-connection multiplier (see directed_node_weights); use the fit's. Default 2. |
- Returns
- n_units × n_dims centroids.
- Exceptions
-
| std::invalid_argument | if the line weights' column count does not match the number of nodes, or either input contains NaN or Inf. |