Skip to content

joint_program

from tensorsig.offset_coded_signatures.rolling_logsignature import joint_program

Compile a FIFO polynomial from a bound RollingLogSignature context.

The callable takes state, outgoing and incoming quotient vectors. With a grade, it returns that grade's forcing using only lower-grade state inputs. Compiled programs preserve their owned first- and second-derivative kernels.

Source code in src/tensorsig/offset_coded_signatures/rolling_logsignature/_joint.py
def joint_program(owner, grade=None, compiled=False):
    """Compile a FIFO polynomial from a bound ``RollingLogSignature`` context.

    The callable takes state, outgoing and incoming quotient vectors. With a
    grade, it returns that grade's forcing using only lower-grade state inputs.
    Compiled programs preserve their owned first- and second-derivative kernels.
    """
    plan = owner.plan
    degrees = plan.basis_depths.cpu().tolist()
    state = [i for i, d in enumerate(degrees) if grade is None or d < grade]
    endpoints = [
        torch.where(e.any(dim=0))[0].cpu().tolist()
        for e in (owner.embeddings[0], owner.embeddings[-1])
    ]
    program = PolynomialProgram(plan, [state, *endpoints])
    negative = program.add([(0, Fraction(-1))])
    removed = program.add([(program.bch(negative, 1, grade), Fraction(-1))])
    shifted = program.transport(removed, owner.transport_rows)
    result = program.bch(shifted, 2, grade)
    outputs = [i for i, d in enumerate(degrees) if grade is None or d == grade]
    program.finish(result, outputs)
    return program.compile() if compiled else program