{
  "format": 1,
  "method": "permutation-invariant-macrodynamics",
  "version": "0.2.0",
  "interface": "Double precision, row-major matrices, absolute tolerances. encode(groups,point_weights,point_bias,set_weights,set_bias) separately maps each nonempty group through phi(x)=tanh(point_weights*x+point_bias), taking tanh elementwise, averages within that group, then applies rho(v)=set_weights*v+set_bias. Share parameters across groups and concatenate in input group order. target_logpdf(points,query,epsilon) returns log[(1/n) sum of normalized d-dimensional Gaussians with means at the points and covariance epsilon^2 I]. Use stable log-sum-exp. reconstruction_gradient(points,queries,epsilon,weights) is the mean of log q_X(y)-log p(y|h) over the given one-dimensional queries. For weights [a,b,s], use h=a*mean(points), p=N(h+b,exp(2*s)). Return [loss,[d_loss/d_a,d_loss/d_b,d_loss/d_s]] with points and queries fixed. transition_nll(start,end,lag,drift,lower) returns [full normalized Gaussian endpoint NLL, gradient with respect to drift]. Mean start+lag*drift, covariance lag*lower*lower^T. The lower triangular factor is the noise amplitude per square root of time. mmd_squared(predicted,observed,sigmas) is the mean across sigmas of XX+YY-2*XY, where each term is the mean RBF kernel over all pairs between the indicated ensembles, including self terms within an ensemble. Kernel exp(-||x-y||^2/(2*sigma^2)). Return squared MMD with no square root. deterministic_endpoint_loss(start,end,lag,drift) returns [error, gradient with respect to drift], where error is the sum of squared components of start + lag*drift - end for one pair. mean_relative_error(predicted,observed) takes arrays in trajectory, forecast time, observable coordinate order, with the initial frame omitted. For each trajectory divide the sum of squared errors by the sum of squared observed values, then average the ratios. The denominators are nonzero. normalized_interaction_energy(points) averages log(cosh(4*(1-r)))/4 + 0.1*(1-r) over pairs i<j, where r is Euclidean separation. Use at least two particles. Export all eight functions from port_adapter.py.",
  "cases": [
    {
      "name": "separate mean pools with unequal species counts",
      "operation": "encode",
      "tol": 1e-12,
      "inputs": {
        "groups": [
          [
            [
              0.2,
              0.7
            ],
            [
              -0.6,
              0.1
            ],
            [
              0.9,
              -0.3
            ]
          ],
          [
            [
              0.1,
              -0.4
            ],
            [
              -0.8,
              0.5
            ]
          ]
        ],
        "point_weights": [
          [
            0.2,
            0.7
          ],
          [
            -0.4,
            0.6
          ]
        ],
        "point_bias": [
          0.1,
          -0.3
        ],
        "set_weights": [
          [
            1.2,
            -0.6
          ],
          [
            0.3,
            0.4
          ]
        ],
        "set_bias": [
          -0.15,
          0.2
        ]
      },
      "expected": [
        0.2503246687171595,
        0.18167893049433587,
        -0.011960662434764208,
        0.17589124456118382
      ]
    },
    {
      "name": "normalized two-dimensional smoothed empirical density",
      "operation": "target_logpdf",
      "tol": 1e-12,
      "inputs": {
        "points": [
          [
            0.1,
            0.3
          ],
          [
            -0.6,
            0.2
          ],
          [
            0.3,
            -0.7
          ]
        ],
        "query": [
          0.48,
          -0.32
        ],
        "epsilon": 0.22
      },
      "expected": -1.7086711527782041
    },
    {
      "name": "finite density score in the far tail",
      "operation": "target_logpdf",
      "tol": 1e-09,
      "inputs": {
        "points": [
          [
            0.1
          ],
          [
            -0.2
          ]
        ],
        "query": [
          18.0
        ],
        "epsilon": 0.1
      },
      "expected": -16019.809500620766
    },
    {
      "name": "fixed KL reconstruction and encoder decoder derivatives",
      "operation": "reconstruction_gradient",
      "tol": 1e-11,
      "inputs": {
        "points": [
          [
            -0.7
          ],
          [
            1.1
          ],
          [
            1.55
          ]
        ],
        "queries": [
          [
            -0.63
          ],
          [
            -0.11
          ],
          [
            0.8
          ],
          [
            1.9
          ]
        ],
        "epsilon": 0.35,
        "weights": [
          0.8,
          -0.15,
          -0.25
        ]
      },
      "expected": [
        -0.03657696258781873,
        [
          -0.12860025911460998,
          -0.19784655248401534,
          -0.5482317092509552
        ]
      ]
    },
    {
      "name": "correlated endpoint likelihood and drift derivatives",
      "operation": "transition_nll",
      "tol": 1e-12,
      "inputs": {
        "start": [
          0.3,
          -0.7
        ],
        "end": [
          0.47,
          -0.61
        ],
        "lag": 0.17,
        "drift": [
          -0.21,
          0.4
        ],
        "lower": [
          [
            0.29,
            0.0
          ],
          [
            0.11,
            0.43
          ]
        ]
      },
      "expected": [
        -0.4862291760323678,
        [
          -2.5608276222195503,
          0.30299696014621164
        ]
      ]
    },
    {
      "name": "biased multiscale MMD with unequal ensemble sizes",
      "operation": "mmd_squared",
      "tol": 1e-12,
      "inputs": {
        "predicted": [
          [
            0.1,
            0.5
          ],
          [
            0.4,
            -0.06
          ]
        ],
        "observed": [
          [
            0.24,
            0.31
          ],
          [
            0.07,
            -0.42
          ],
          [
            0.37,
            0.02
          ]
        ],
        "sigmas": [
          0.01,
          0.05,
          0.25,
          1.25
        ]
      },
      "expected": 0.47585607617186776
    },
    {
      "name": "deterministic squared endpoint error and drift derivatives",
      "operation": "deterministic_endpoint_loss",
      "tol": 1e-12,
      "inputs": {
        "start": [
          0.6,
          -0.5
        ],
        "end": [
          0.55,
          -0.3
        ],
        "lag": 0.23,
        "drift": [
          0.12,
          0.35
        ]
      },
      "expected": [
        0.02030200999999998,
        [
          0.03569599999999995,
          -0.05497
        ]
      ]
    },
    {
      "name": "mean of per-trajectory squared relative errors",
      "operation": "mean_relative_error",
      "tol": 1e-12,
      "inputs": {
        "predicted": [
          [
            [
              1.2
            ],
            [
              0.7
            ]
          ],
          [
            [
              3.6
            ],
            [
              5.2
            ]
          ]
        ],
        "observed": [
          [
            [
              1.0
            ],
            [
              0.5
            ]
          ],
          [
            [
              4.0
            ],
            [
              5.0
            ]
          ]
        ]
      },
      "expected": 0.03443902439024389
    },
    {
      "name": "normalized interaction energy of a four-particle frame",
      "operation": "normalized_interaction_energy",
      "tol": 1e-12,
      "inputs": {
        "points": [
          [
            0.0,
            0.0
          ],
          [
            0.6,
            0.0
          ],
          [
            0.0,
            0.8
          ],
          [
            0.6,
            1.6
          ]
        ]
      },
      "expected": 0.2006076940032588
    }
  ]
}
