pysiglib.idx_to_tree#
- idx_to_tree(idx, dimension, degree, *, tree_order='canonical', planar=False, scalar_term=False)[source]#
Inverse of
tree_to_idx(). Given a flat index in the branched-signature coefficient vector, returns the corresponding decorated rooted tree.With
scalar_term=True, index 0 maps to the empty tree (None). Withscalar_term=False(default), all indices shift down by 1 (index 0 maps to the first non-empty tree) and the empty tree is unreachable.- Parameters:
idx (int) – Flat index in the branched signature vector.
dimension (int) – Path dimension (alphabet size).
degree (int) – Maximum number of nodes (same as
degreeinbranched_sig()).tree_order (str) – Tree ordering convention.
"canonical"(default) matchesbranched_sig(..., tree_order="canonical")."recursive"matchesbranched_sig(..., tree_order="recursive")(the default).planar (bool) – If True, interpret
idxin the planar (ordered) enumeration matchingbranched_sig(..., planar=True).scalar_term (bool) – Whether the source branched signature includes the leading scalar 1 at index 0. Must match the format of the bsig the index was taken from. Default
False.
- Returns:
Decorated rooted tree (None for empty tree when
scalar_term=True, tuple otherwise).- Return type:
tuple or None
Example:#
import pysiglib tree = pysiglib.idx_to_tree(3, dimension=2, degree=3) print(tree)
Citation#
If you found this library useful in your research, please consider citing the paper:
@article{shmelev2025pysiglib,
title={pySigLib-Fast Signature-Based Computations on CPU and GPU},
author={Shmelev, Daniil and Salvi, Cristopher},
journal={arXiv preprint arXiv:2509.10613},
year={2025}
}