{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.calculatorx.com/schemas/engineering.tolerance.monte_carlo.agent.input.json",
  "title": "1-D Tolerance Analysis Workspace — agent input",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "tolerances": {
      "type": "array",
      "minItems": 1,
      "description": "Canonical stack components. y = Σ c·(nominal + ε).",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [],
        "properties": {
          "name": {
            "type": "string"
          },
          "nominal": {
            "type": "number",
            "description": "Nominal dimension (default 0 = error-only stack)."
          },
          "tol_plus": {
            "type": "number",
            "minimum": 0,
            "description": "Upper half-tolerance (+). With tol_minus for asymmetric (both required in agent schema)."
          },
          "tol_minus": {
            "type": "number",
            "minimum": 0,
            "description": "Lower half-tolerance (−). With tol_plus for asymmetric (both required in agent schema)."
          },
          "half_tolerance": {
            "type": "number",
            "description": "Symmetric ± half-tolerance. Prefer this OR both tol_plus and tol_minus — not a mix."
          },
          "coefficient": {
            "type": "number",
            "description": "Stack sense / sensitivity (default +1). Use -1 to subtract."
          },
          "distribution": {
            "type": "string",
            "enum": [
              "normal",
              "uniform",
              "triangular"
            ],
            "description": "Error distribution (default normal). k_sigma applies to normal only."
          },
          "mean_shift": {
            "type": "number",
            "description": "Process mean shift from nominal (default 0)."
          }
        },
        "oneOf": [
          {
            "required": [
              "half_tolerance"
            ]
          },
          {
            "required": [
              "tol_plus",
              "tol_minus"
            ]
          }
        ]
      }
    },
    "N": {
      "type": "integer",
      "minimum": 100,
      "maximum": 100000,
      "description": "Monte Carlo iterations (default 5000)."
    },
    "seed": {
      "type": "integer",
      "minimum": 0,
      "description": "PRNG seed (mulberry32)."
    },
    "k_sigma": {
      "type": "number",
      "exclusiveMinimum": 0,
      "description": "For normal: half_tolerance = k_sigma · σ (default 3)."
    },
    "LSL": {
      "type": "number",
      "description": "Lower specification limit (optional)."
    },
    "USL": {
      "type": "number",
      "description": "Upper specification limit (optional)."
    },
    "unit": {
      "type": "string",
      "description": "Optional display unit (mm, in, …)."
    },
    "correlations": {
      "type": "array",
      "description": "Optional pairwise correlations by dimension name: [{a,b,rho}]. ρ is Pearson (all-normal) or latent normal (NORTA).",
      "items": {
        "type": "object",
        "properties": {
          "a": {
            "type": "string",
            "description": "First dimension name"
          },
          "b": {
            "type": "string",
            "description": "Second dimension name"
          },
          "rho": {
            "type": "number",
            "minimum": -1,
            "maximum": 1
          }
        },
        "oneOf": [
          {
            "required": [
              "a",
              "b",
              "rho"
            ]
          }
        ],
        "additionalProperties": false
      }
    },
    "sensitivity_method": {
      "type": "string",
      "enum": [
        "spearman",
        "pearson",
        "sobol",
        "shapley"
      ],
      "description": "Sensitivity method (default spearman). sobol = exact first-order for independent linear stacks; shapley = variance attribution (supports correlation)."
    },
    "sobol_N": {
      "type": "integer",
      "minimum": 128,
      "maximum": 4096,
      "description": "Optional Saltelli MC cross-check size when sensitivity_method=sobol."
    },
    "shapley_N": {
      "type": "integer",
      "minimum": 200,
      "maximum": 20000,
      "description": "Optional permutation count when sensitivity_method=shapley and d>12 (exact for d≤12)."
    }
  },
  "anyOf": [
    {
      "required": [
        "tolerances"
      ]
    }
  ],
  "description": "1-D Tolerance Analysis Workspace — dimensional Monte Carlo with asymmetric ±tol, correlations (normal or NORTA), Spearman/Pearson/Sobol/Shapley sensitivity, σ convergence, LSL/USL yield, simulated capability, fingerprint, and snapshots. (calculation_version 1.12.0) Canonical agent fields only (no legacy aliases)."
}
