andrey.BootstrapOutput#
- class andrey.BootstrapOutput[source]#
The edge frequencies over bootstrap refits of one method, and the averaged graph.
bootstrapreturns one (multi_group_direct_lingamreturns one per group), andBootstrapOutput.from_fitsbuilds one from fits made elsewhere.structureis the averaged graph.frequencyreads the share of fits in which a pair has a given edge,tablelists every edge that appeared, andaveragetakes the averaged graph at another threshold without refitting.print(out)shows the averaged graph and its most frequent edges. The result is read-only.An edge is read as the pair
(i, j)carries it:->is a tail atiand an arrowhead atj,<-the reverse,--two tails,<->two arrowheads, andoa circle. A fit adds its edge to a pair’s count once. A time-series result has its own frequencies for each lag. A lag graph that is adigraph(every lag above 0) counts each directed edgei -> jon its own, so a 2-cycle adds to both->and<-, and it holds no other edge.- classmethod from_fits(fits, *, threshold=0.5, strict=False, keep_fits=False, metadata=None)[source]#
Count the edges of fits and build the averaged graph.
Use it to summarize fits made elsewhere, such as resamples drawn another way. Every fit must be over the same nodes and, for a time-series result, the same lags.
- Parameters:
fits (
Sequence[StructureOutput]) – The results to count, at least one.threshold (
float) – A pair of the averaged graph must be adjacent in more than this share of the fits, or in all of them, in[0.5, 1].strict (
bool) – Raise when the vote of the fits has no valid graph of their kind, instead of returning the valid fit nearest the others with a warning.keep_fits (
bool) – Keepfitsin thefitsproperty.metadata (
Mapping[str,str|bool|int|float|None|list|dict] |None) – Run values by name, with the typesStructureOutputaccepts.
- Returns:
The counts and the averaged graph. The vote gives a pair its most frequent edge when more fits have that edge than have no edge and the pair is adjacent in more than
thresholdof the fits, or in all of them; otherwise the pair has no edge. When two edges tie for most frequent, the pair takes the least committal one:--, oro-ofor apag. Adigraphlag graph takes each directed edge that more thanthresholdof the fits have, or all of them. The vote is then made a valid graph of the fits’ kind, the widest among them (dag,cpdag,pag, with amagread as apag), asbootstrap’s Notes describe.metadata["averaged_graph"]is"vote", or"nearest_resample"when the vote has no valid graph of that kind and the averaged graph is the fit nearest the others among the fits that are valid graphs of that kind, or"nearest_resample_invalid"when no fit is, so the averaged graph is the fit nearest the others and not a valid graph of that kind. Acpdagfit is valid when it has a consistent DAG extension, and apagormagfit when it passes the steps that make a vote a PAG.from_fitshas no data to rank the nodes by, so adagvote with a tie edge becomes acpdagthat leaves the tie edge undirected;bootstrappoints it by the ranks of its data.- Return type:
- Raises:
TypeError – If a fit is not a
StructureOutput.ValueError – If
fitsis empty,thresholdis not in[0.5, 1], the fits differ in graph type, node count, labels, or lags, a graph is adigraphorundirectedin some fits and another kind in others, a fit has latent nodes, orstrictisTrueand the vote has no valid graph of the fits’ kind.
- Warns:
AndreyWarning – When
strictisFalseand the vote has no valid graph of the fits’ kind.
- property structure: Structure#
a
GraphStructure, or aTemporalStructure.A time-series result has one graph per lag and no time axis or weights.
- Type:
The averaged graph at
threshold
- property threshold: float#
more, or all.
- Type:
The share of fits in which a pair of
structuremust be adjacent
- property strict: bool#
Whether a vote with no valid graph of the fits’ kind raises, rather than warns.
- property fits: tuple[StructureOutput, ...] | None#
The fits, in resample order, or
Noneunlesskeep_fits=True.
- property metadata: Mapping[str, str | bool | int | float | None | list | dict]#
Run values such as
method,seed, andblock_length, as a read-only mapping.
- average(threshold=0.5)[source]#
Return the averaged graph at
threshold, without refitting.- Parameters:
threshold (
float) – A pair must be adjacent in more than this share of the fits, or in all of them, in[0.5, 1].- Returns:
The graph
from_fitsdescribes, at this threshold, with thestrictthis result was built with. When the vote has no valid graph of the fits’ kind, it is the fit nearest the others, asstructurewould be: the valid one when some fit is.- Return type:
- Raises:
ValueError – If
thresholdis not in[0.5, 1], or the result was built withstrict=Trueand the vote atthresholdhas no valid graph of the fits’ kind.- Warns:
AndreyWarning – When the result was built with
strict=Falseand the vote atthresholdhas no valid graph of the fits’ kind.
- frequency(edge, *, lag=None)[source]#
Return the share of fits in which each pair has
edge, as an(n, n)array.- Parameters:
edge (
str) – One of"->","<-","--","<->","o->","<-o","o-o","-o","o-", or"absent". Cell[i, j]is the share of fits in which nodesiandjreadi edge j, so the array for"<-"is the transpose of the one for"->"."absent"is the share with no edge betweeniandj(for a lag above 0, with no edgei -> j).lag (
int|None) – The lag of a time-series result;Nonefor any other result.
- Returns:
The shares, from 0 to 1. A lag above 0 holds only
->,<-, andabsent; any other edge there is 0, and so is an edge that no fit has.- Return type:
- Raises:
ValueError – If
edgeis not one of the names above,lagis missing for a time-series result, orlagis not one of its lags or is given for another result.
- table(*, min_frequency=0.0, index=False)[source]#
List every edge that appeared in a fit, most frequent first.
- Parameters:
- Returns:
One row per edge, most frequent first, then by lag and node index. A row has
source,target,type(one oforiented_edgestypes: a directed edge runs from its tail to its arrowhead, and the symmetric types list the lower node index first),count, andfrequency; a time-series result addslagfirst. A pair can have several rows, one per edge it had in some fit.- Return type: