smx.graph.builder#
PredicateGraphBuilder: construct a directed predicate graph.
Edges are added between consecutive predicates ordered by a ranking metric inside each bag, and weights are accumulated across bags. Bidirectional edges are resolved by keeping only the higher-weight direction.
Classes#
Build a directed predicate graph from bags and metric rankings. |
Module Contents#
- class smx.graph.builder.PredicateGraphBuilder(random_state: int = 42, show_details: bool = True, var_exp: bool = False, pca_info_dict: Dict | None = None)[source]#
Build a directed predicate graph from bags and metric rankings.
Edge weights derive from the ranking metric of the source predicate in each bag. When the same directed edge appears in multiple bags, the weights are accumulated (summed). Bidirectional edges (A→B and B→A) are resolved by:
keeping the edge with the higher accumulated weight;
breaking ties randomly.
Parameters#
- random_stateint, default 42
Seed for random tie-breaking of bidirectional edges.
- show_detailsbool, default True
Print details about identified and removed bidirectional edges.
- var_expbool, default False
When
True, multiply edge weights by the PC1 explained variance of the source predicate’s spectral zone. Requires pca_info_dict.- pca_info_dictdict, optional
{zone_name: {'variance_explained': float, ...}}as returned bysmx.zones.aggregation.ZoneAggregator(pca_info_attribute). Required whenvar_exp=True.
- random_state = 42#
- show_details = True#
- var_exp = False#
- pca_info_dict = None#
- build(bags_result: Dict[str, Dict[str, pandas.DataFrame]], predicate_ranking_dict: Dict[str, pandas.DataFrame], metric_column: str = 'Covariance') networkx.DiGraph[source]#
Build and return the directed predicate graph.
Parameters#
- bags_resultdict
Bags as returned by
smx.predicates.bagging.PredicateBagger.- predicate_ranking_dictdict
{bag_name: DataFrame(['Predicate', metric_column])}as returned by asmx.predicates.metrics.BasePredicateMetricsubclass.- metric_columnstr, default
'Covariance' Name of the metric column in predicate_ranking_dict.
Returns#
- nx.DiGraph
Directed graph with
'weight'edge attributes.