andrey.TemporalStructure#
- class andrey.TemporalStructure[source]#
A time-series result: one
GraphStructureper lag.varma_lingam,longitudinal_lingam,pcmci,pcmciplus, andlpcmcireturn one asStructureOutput.structure;from_lag_graphsandfrom_time_lag_graphsbuild one from existing graphs. An edgei -> jinlag(k)meansX_i(t-k) -> X_j(t). Lag 0 holds the relations within one time step, and a self-loop at a positive lag is a variable’s effect on its own future.lagslists the lag values,lag_weightsholds the coefficients, andsummary_graph()merges the lags into one graph over the variables.A
longitudinal_lingamresult also has a time axis, one lag stack per occasion:timeslists the occasions,at(time, lag)selects a graph, andtime_weightsholds every occasion’s coefficients. On such a result,lag(k),lag_weights, andsummary_graph()describe the final occasion only.- classmethod from_lag_graphs(graphs, *, lags=None, lag_weights=None, lag_weights_ma=None, labels=None)[source]#
Build a time-series result from one graph per lag.
- Parameters:
graphs (
Sequence[GraphStructure]) – One graph per lag, all over the same nodes. An edgei -> jin the graph for lagkmeansX_i(t-k) -> X_j(t); a variable’s effect on its own future is a self-loop,M[i, i] = 2, built withallow_self_loops=True.lags (
Sequence[int] |None) – The lag value of each graph, without repeats; gaps are allowed, for example,[0, 1, 12].Nonenumbers the graphs0, 1, ..., len(graphs) - 1.lag(k)finds a graph by this value, not by position.lag_weights (
ndarray|None) – Coefficients, one block per graph:lag_weights[k, i, j]is the weight ofi -> jingraphs[k]. Stored as a read-onlyfloat64copy.lag_weights_ma (
ndarray|None) – Moving-average coefficients of a VARMA model:lag_weights_ma[m, i, j]is the weight ofi -> jat moving-average lagm + 1. Stored as a read-onlyfloat64copy.labels (
tuple[str,...] |None) – Node names, one per node, each taken as text,str(label);Nonenumbers the nodes from 0.
- Returns:
The result, without a time axis.
- Return type:
- Raises:
ValueError – If
graphsis empty,lagsdoes not have one value per graph or repeats a value, the graphs differ in node count,labelsdoes not have one entry per node or has two that are equal as text, or a weight array has the wrong shape.
- classmethod from_time_lag_graphs(time_graphs, *, lags=None, times=None, time_weights=None, labels=None)[source]#
Build a panel result: one lag stack per occasion.
lag,n_lags,lag_weights, andsummary_graph()then describe the final occasion;atandtime_weightsreach every occasion.- Parameters:
time_graphs (
Sequence[Sequence[GraphStructure]]) – One row per occasion, each row a graph per lag in the order oflags; every row has the same length. Use an empty graph for a block that cannot be computed.lags (
Sequence[int] |None) – The lag value of each column, without repeats.Nonenumbers the columns0, 1, ..., n_lags - 1.times (
Sequence[int] |None) – The occasion value of each row, strictly increasing; gaps are allowed. For example, a panel whose first occasion has no estimate starts at1.Nonenumbers the rows0, 1, ..., n_times - 1.time_weights (
ndarray|None) – Coefficients:time_weights[t, k, i, j]is the weight ofi -> jintime_graphs[t][k], withNaNfor a block that cannot be computed.lag_weightsis the last row withNaNreplaced by0.labels (
tuple[str,...] |None) – Node names, one per node, each taken as text,str(label);Nonenumbers the nodes from 0.
- Returns:
The result, with a time axis.
- Return type:
- Raises:
ValueError – If the grid is empty or its rows differ in length,
lagsortimesdoes not match the grid,lagsrepeats a value,timesis not strictly increasing, the graphs differ in node count,labelsdoes not have one entry per node or has two that are equal as text, ortime_weightshas the wrong shape.
- property lags: tuple[int, ...]#
The lag value of each graph, in stack order;
lag(k)looks up by this value.
- lag(k)[source]#
Select the graph at lag value
k(not position).For a time-carrying structure this is the final occasion’s lag graph (
at(times[-1], k)); the full grid is reached viaat/times.
- property lag_weights: ndarray | None#
Coefficients
(n_lags, n, n), orNonewhen the result has none.lag_weights[k, i, j]is the weight ofi -> jat laglags[k]. On a panel result it is the final occasion withNaNreplaced by0;time_weightskeeps every occasion.
- property lag_weights_ma: ndarray | None#
Moving-average coefficients
(q, n, n)fromvarma_lingam, orNone.lag_weights_ma[m, i, j]is the weight ofi -> jat moving-average lagm + 1.
- property n_times: int#
Number of absolute occasions in the
(time, lag)axis;0for a lag-only stack.
- property times: tuple[int, ...]#
The explicit occasion index of each
(time, lag)row;()when lag-only.
- at(time, lag)[source]#
Select the graph at occasion value
timeand lag valuelag.A lag-only stack has no time axis, so every
atcall raises there – uselaginstead.- Parameters:
- Returns:
The graph stored at occasion
timeand laglag.- Return type:
- Raises:
KeyError – If either
timeorlagis absent (including anyatcall on a lag-only stack).
- property time_weights: ndarray | None#
Coefficients
(n_times, n_lags, n, n), orNonewithout a time axis or weights.time_weights[t, k, i, j]is the weight ofi -> jinat(times[t], lags[k]);NaNmarks a block that could not be computed.
- summary_graph(*, include_lag0=True)[source]#
Merge the lags into one directed graph over the variables.
i -> jin the summary meansi -> jin at least one lag graph;lags_of(i, j)lists those lags.i -> jat one lag andj -> iat another form a 2-cycle, and a self-loop at a positive lag stays a self-loop. Only directed edges are kept; an undirected edge or one with a circle is left out. On a panel result it merges the final occasion’s lags. Each call builds a new graph.- Parameters:
include_lag0 (
bool) – Include lag 0, the relations within one time step.Falsesummarizes the effects across time steps only.- Returns:
A
kind="digraph"graph;lags_of(i, j)gives the lags of each edge.- Return type: