bayespecon.graph.flow_design_matrix_asymmetric

bayespecon.graph.flow_design_matrix_asymmetric(Xd, Xo, col_names_d=None, col_names_o=None, dist=None, log_distance=True)[source]

Build a flow design matrix with different numbers of dest/origin variables.

Unlike flow_design_matrix() (which uses a single (n, k) matrix for both destination and origin blocks), this function accepts separate attribute matrices Xd of shape (n, k_d) and Xo of shape (n, k_o) where k_d and k_o may differ.

The design matrix column layout is:

intercept | intra_indicator | X_dest (k_d cols) | X_orig (k_o cols) | X_intra (k_d cols) [| dist]

The intra-zonal block uses k_d columns (destination-side variables), matching the LeSage convention where X_intra = intra_indicator * X_dest.

Parameters:
Xd : np.ndarray, shape (n, k_d)

Destination-side regional attribute matrix (no intercept).

Xo : np.ndarray, shape (n, k_o)

Origin-side regional attribute matrix (no intercept). k_o may differ from k_d.

col_names_d : list[str], optional

Names for the k_d destination columns. Defaults to ["x0", "x1", ...].

col_names_o : list[str], optional

Names for the k_o origin columns. Defaults to ["y0", "y1", ...] when k_o != k_d, or the same names as col_names_d when k_o == k_d.

dist : np.ndarray, shape (n, n), optional

Distance / cost matrix appended as the last predictor.

log_distance : bool, default True

If True and dist is provided, the appended column is log(1 + dist).ravel() and is named "log_distance".

Returns:

Dataclass with k_d and k_o set independently.

Return type:

FlowDesignMatrix

Examples

>>> import numpy as np
>>> n = 3
>>> Xd = np.ones((n, 2))   # 2 destination variables
>>> Xo = 2 * np.ones((n, 1))  # 1 origin variable
>>> dm = flow_design_matrix_asymmetric(Xd, Xo)
>>> dm.combined.shape  # 9 OD pairs, 1+1+2+1+2 = 7 cols
(9, 7)
>>> dm.k_d, dm.k_o
(2, 1)
>>> dm.feature_names
['intercept', 'intra_indicator', 'dest_x0', 'dest_x1', 'orig_y0', 'intra_x0', 'intra_x1']