mixle.experimental.tensor_network module

P4 (experimental) – tensor-network (matrix-product-state) leaves with exact conditioning.

A matrix-product state (MPS / tensor-train) is a density model over discrete sequences with a built-in complexity dial – the bond dimension – and two properties classical mixtures lack: its marginals and conditionals are exact by contraction (no sampling), and its entanglement entropy at any cut is a direct, measured receipt of how much long-range correlation the model carries (bounded by log(bond dimension)).

This module implements a Born-machine MPS over length-L sequences of a d-symbol alphabet: p(x) proportional to |psi(x)|^2 where psi(x) is the contraction of one matrix per site. It provides exact normalization / marginals / conditionals by transfer-operator contraction (verified against brute-force enumeration), the entanglement entropy from the Schmidt spectrum, and bond-dimension truncation whose error is exactly the discarded Schmidt weight – the receipt the card asks for (“truncation error tracks the entanglement receipt”).

Scope: this is the exact-conditioning + entanglement-receipt core (the two verification points the card lists first). DMRG fitting and the matched-parameter HMM comparison are follow-ups.

Exploratory mixle.experimental code (P4 card).

class MPS(tensors)[source]

Bases: object

A Born-machine matrix-product state: one (D_left, d, D_right) tensor per site.

Parameters:

tensors (list[ndarray])

probability(x)[source]

Probability of one complete length-L event.

Use marginal() for an explicitly partial event; prefixes and extra symbols are rejected.

Parameters:

x (Any)

Return type:

float

marginal(evidence)[source]

p(X_evidence = values) – exact, by contraction over the free sites.

Parameters:

evidence (dict[int, int])

Return type:

float

conditional(query, evidence)[source]

Exact p(X_query = . | evidence) as a length-d vector.

Parameters:
Return type:

ndarray

all_probabilities()[source]

Brute-force p(x) over all d**L sequences (for verification / entanglement).

Return type:

ndarray

random_mps(length, bond, *, d=2, seed=0)[source]

A random Born-machine MPS with open boundaries and interior bond dimension bond.

Parameters:
Return type:

MPS

product_mps(site_amplitudes)[source]

A bond-1 product state from per-site amplitude vectors (zero entanglement).

Parameters:

site_amplitudes (list[ndarray])

Return type:

MPS

schmidt_values(mps, cut)[source]

Normalized Schmidt coefficients of the wavefunction at the bond after site cut-1.

Parameters:
  • mps (MPS)

  • cut (int)

Return type:

ndarray

entanglement_entropy(mps, cut)[source]

Von Neumann entanglement entropy (nats) across the cut – the long-range-structure receipt.

Parameters:
  • mps (MPS)

  • cut (int)

Return type:

float

truncate_error(mps, cut, chi)[source]

Truncate the wavefunction to bond chi at cut; return (discarded_weight, tv_distance).

discarded_weight is the Schmidt weight thrown away (Eckart-Young); tv_distance is the total-variation distance between the full and truncated probability distributions. As chi shrinks the discarded weight grows and the distribution error grows with it.

Parameters:
  • mps (MPS)

  • cut (int)

  • chi (int)

Return type:

tuple[float, float]