{
  "format": 1,
  "method": "stochastic-onsagernet",
  "version": "0.1.0",
  "interface": "Double precision. drift(grad_v,lower,skew,alpha=0) uses M=L L^T+alpha I, W=skew and returns -(M+W) grad_v. transition(start,end,dt,velocity,sigma) returns [full normalized Gaussian negative log density, derivative w.r.t. velocity]; conditional covariance is dt*sigma*sigma^T. coordinates(x,observed,projection,residual) concatenates observed and projection*x+residual for training-centered x. rec_loss(x,decoded,pca_decoded,penalty,floor=1e-15) is squared reconstruction error plus penalty*max(0,log(max(error,floor))-log(max(PCA_error,floor))). whitening(samples,count) returns [P,P_pinv] from already-centered samples. Divide the second moments by the number of samples. Order the retained eigenvectors by decreasing eigenvalue. Orient each unit eigenvector so its largest-magnitude component is positive (first index breaks ties). P has rows equal to unit eigenvectors divided by sqrt(eigenvalue), and P_pinv has columns equal to unit eigenvectors multiplied by sqrt(eigenvalue). closure_loss_gradient(pairs,weights,weight,penalty) uses weights [a,k,s]. Encode x as [x[0],a*x[1]], decode the hidden coordinate h as [0,h], and use [0,x[1]] as the PCA reconstruction. Use drift [-z[0],-k*z[1]] and noise factor diag(1,s). For each pair [x,y,lag] add the normalized transition loss to weight*rec_loss at x, then average. Return [loss,[d/da,d/dk,d/ds]], differentiating both encoded endpoints and the reconstruction. Vectors are columns, matrices row-major. Absolute tolerances. Export all six functions from port_adapter.py.",
  "cases": [
    {
      "name": "correlated increments at a short lag",
      "operation": "transition",
      "tol": 1e-11,
      "inputs": {
        "start": [
          0.2,
          -0.5
        ],
        "end": [
          0.1,
          -0.25
        ],
        "dt": 0.08,
        "velocity": [
          -0.7,
          0.4
        ],
        "sigma": [
          [
            0.55,
            0.2
          ],
          [
            -0.15,
            0.4
          ]
        ]
      },
      "expected": [
        -0.4159129390188008,
        [
          0.11976000000000007,
          -1.19288
        ]
      ]
    },
    {
      "name": "normalized scalar density",
      "operation": "transition",
      "tol": 1e-12,
      "inputs": {
        "start": [
          0.0
        ],
        "end": [
          0.25
        ],
        "dt": 0.25,
        "velocity": [
          1.0
        ],
        "sigma": [
          [
            2.0
          ]
        ]
      },
      "expected": [
        0.9189385332046727,
        [
          -0.0
        ]
      ]
    },
    {
      "name": "dissipation independent of diffusion",
      "operation": "drift",
      "tol": 1e-12,
      "inputs": {
        "grad_v": [
          0.5,
          -0.75
        ],
        "lower": [
          [
            1.0,
            0.0
          ],
          [
            0.4,
            0.8
          ]
        ],
        "skew": [
          [
            0.0,
            -0.3
          ],
          [
            0.3,
            0.0
          ]
        ],
        "alpha": 0.02
      },
      "expected": [
        -0.43499999999999994,
        0.2650000000000001
      ]
    },
    {
      "name": "observable before whitened closure",
      "operation": "coordinates",
      "tol": 1e-12,
      "inputs": {
        "x": [
          -0.4,
          0.7,
          1.2
        ],
        "observed": [
          2.1
        ],
        "projection": [
          [
            0.5,
            -0.3,
            0.7
          ]
        ],
        "residual": [
          0.2
        ]
      },
      "expected": [
        2.1,
        0.6299999999999999
      ]
    },
    {
      "name": "penalty above PCA reconstruction error",
      "operation": "rec_loss",
      "tol": 1e-12,
      "inputs": {
        "x": [
          0.0,
          1.0
        ],
        "decoded": [
          2.0,
          2.0
        ],
        "pca_decoded": [
          0.0,
          2.0
        ],
        "penalty": 0.25
      },
      "expected": 5.402359478108525
    },
    {
      "name": "zero penalty when decoder beats PCA",
      "operation": "rec_loss",
      "tol": 1e-12,
      "inputs": {
        "x": [
          0.0,
          1.0
        ],
        "decoded": [
          0.25,
          1.0
        ],
        "pca_decoded": [
          0.0,
          2.0
        ],
        "penalty": 0.4
      },
      "expected": 0.0625
    },
    {
      "name": "whitening and inverse of a correlated covariance",
      "operation": "whitening",
      "tol": 1e-11,
      "inputs": {
        "samples": [
          [
            3.0,
            4.0
          ],
          [
            -3.0,
            -4.0
          ],
          [
            -0.8,
            0.6
          ],
          [
            0.8,
            -0.6
          ]
        ],
        "count": 2
      },
      "expected": [
        [
          [
            0.1697056274847714,
            0.2262741699796952
          ],
          [
            1.1313708498984747,
            -0.8485281374238559
          ]
        ],
        [
          [
            2.1213203435596424,
            0.5656854249492388
          ],
          [
            2.8284271247461903,
            -0.42426406871192907
          ]
        ]
      ]
    },
    {
      "name": "joint closure loss and three weight derivatives",
      "operation": "closure_loss_gradient",
      "tol": 1e-10,
      "inputs": {
        "pairs": [
          [
            [
              0.3,
              -0.7
            ],
            [
              0.26,
              -0.55
            ],
            0.08
          ],
          [
            [
              -0.4,
              0.9
            ],
            [
              -0.27,
              0.62
            ],
            0.19
          ]
        ],
        "weights": [
          0.82,
          1.4,
          0.65
        ],
        "weight": 0.3,
        "penalty": 0.2
      },
      "expected": [
        -0.5993026054893698,
        [
          -0.09654865179062211,
          -0.06895879763313607,
          1.449390630706945
        ]
      ]
    }
  ]
}
