Skip to content
Submodule
causalis.scenarios.synthetic_control._utils

_utils

Submodule causalis.scenarios.synthetic_control._utils with no child pages and 7 documented members.

Functions

Jump directly into the documented functions for this page.

7 items
function
causalis.scenarios.synthetic_control._utils.rmse

rmse

Compute root mean squared error.

Parameters

valuesnumpy.ndarray

Input array-like values. The input is flattened before computation.

Returns

float

Root mean squared error. Returns 0.0 for empty input.

Canonical target

causalis.scenarios.synthetic_control._utils.rmse

Sections

ParametersReturns
Link to this symbol
function
causalis.scenarios.synthetic_control._utils.project_to_simplex

project_to_simplex

Project a vector onto the probability simplex.

The simplex is defined as non-negative vectors whose entries sum to one.

Parameters

valuesnumpy.ndarray

One-dimensional coefficient vector.

Returns

numpy.ndarray

Projected vector with non-negative entries summing to one.

Raises

ValueError

If the input is empty or contains non-finite values.

Canonical target

causalis.scenarios.synthetic_control._utils.project_to_simplex

Sections

ParametersReturnsRaises
Link to this symbol
function
causalis.scenarios.synthetic_control._utils.solve_linear_system

solve_linear_system

Solve a linear system with least-squares fallback.

Parameters

anumpy.ndarray

Coefficient matrix.

bnumpy.ndarray

Right-hand side vector or matrix.

Returns

numpy.ndarray

Exact solution when a is non-singular, otherwise least-squares solution.

Canonical target

causalis.scenarios.synthetic_control._utils.solve_linear_system

Sections

ParametersReturns
Link to this symbol
function
causalis.scenarios.synthetic_control._utils.circular_shift_indices

circular_shift_indices

Generate circular-shift index permutations.

Parameters

n_totalint

Sequence length.

Returns

list[numpy.ndarray]

All n_total circular shifts of arange(n_total).

Canonical target

causalis.scenarios.synthetic_control._utils.circular_shift_indices

Sections

ParametersReturns
Link to this symbol
function
causalis.scenarios.synthetic_control._utils.cwz_stat_from_residuals

cwz_stat_from_residuals

Compute CWZ post-window residual aggregation statistic.

Parameters

residualsnumpy.ndarray

Residual vector containing pre-period entries first, then post-period entries.

n_preint

Number of pre-period residuals.

Returns

float

|sum(post_residuals)| / sqrt(n_post).

Raises

ValueError

If n_pre does not satisfy 1 <= n_pre < len(residuals).

Canonical target

causalis.scenarios.synthetic_control._utils.cwz_stat_from_residuals

Sections

ParametersReturnsRaises
Link to this symbol
function
causalis.scenarios.synthetic_control._utils.accepted_segments

accepted_segments

Convert a boolean acceptance mask into contiguous grid segments.

Parameters

gridnumpy.ndarray

One-dimensional, ordered grid of candidate parameter values.

accepted_masknumpy.ndarray

Boolean mask with the same length as grid.

Returns

list[tuple[float, float]]

Closed intervals corresponding to contiguous accepted regions.

Raises

ValueError

If grid and accepted_mask are not one-dimensional arrays of the same length.

Canonical target

causalis.scenarios.synthetic_control._utils.accepted_segments

Sections

ParametersReturnsRaises
Link to this symbol
function
causalis.scenarios.synthetic_control._utils.build_average_att_blocks

build_average_att_blocks

Build consecutive pre-period holdout blocks for average ATT inference.

Parameters

n_preint

Number of pre-treatment periods T0.

n_postint

Number of post-treatment periods T1.

n_foldsint

Requested number of folds K.

Returns

tuple[list[numpy.ndarray], int, int]

(blocks, k_used, block_length) where blocks are consecutive holdout indices over the pre-period.

Notes

If n_pre is not divisible by k_used, the rule r = min(floor(T0 / K), T1) is applied on the first K * r periods. Remaining pre-periods are included in every fold’s training subset.

Raises

ValueError

If the configuration cannot produce at least two folds and a positive holdout block length.

Canonical target

causalis.scenarios.synthetic_control._utils.build_average_att_blocks

Sections

ParametersReturnsNotesRaises
Link to this symbol