Metadata-Version: 2.4
Name: mumo-engine
Version: 1.1.0a1
Summary: Boundary-based statistics and risk-corridor calculations
Author: Mumo Framework Authors
License-Expression: MIT
Keywords: statistics,risk,boundaries,mumo
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Mumo Framework Engine

**mumo-engine 1.1.0-alpha.1** is a Python library for parametric data
boundaries, consensus metrics, and risk-corridor calculations.

The active API centers on the parametric formulas and their generalized
counterparts. The original foundational formulas are retained below as
historical background only; they are not implemented or called by the package.

## Historical foundational tier

The first Mumo formulation described three unweighted formulas for a sorted
dataset `x_1 <= ... <= x_n`:

* **MPU (Mumo Potential Upside):**
  `(x_n + mean(x_1, ..., x_(n-1))) / 2`
* **MPD (Mumo Potential Downside):**
  `(x_1 + mean(x_2, ..., x_n)) / 2`
* **MA (Mumo Average):** `(MPU + MPD) / 2`

These formulas are documented as historical context, not part of the active
execution tier or public Python API. The current parametric baselines replace
the single-edge weighting with configurable boundary slices.

## Active formulas

For `n` observations, `k` boundary observations, and `alpha` in `[0, 1]`:

* **P-MPU:** `alpha * mean(top k) + (1 - alpha) * mean(all except top k)`
* **P-MPD:** `alpha * mean(bottom k) + (1 - alpha) * mean(all except bottom k)`
* **P-GMA:** `beta * P-MPU + (1 - beta) * P-MPD`
* **GMA-k:** the mean of the unweighted upper and lower generalized
  boundaries, each of which blends its `k`-slice mean with its remaining-data
  mean.
* **MBV:** `P-MPU - P-MPD`, the signed width of the parametric corridor.
* **P-GMCSI:** weighted mean of the centered contiguous `k`-value core and all
  values outside that core.
* **MAEI:** `gamma * P-GMA + (1 - gamma) * P-GMCSI`.
* **MBTS / P-MBTS:** unweighted / alpha-weighted tension values using the edge
  range and, for P-MBTS, the mean remaining after removing both boundary
  slices. P-MBTS requires `2 * k < n`.
* **MCHI:** `gamma * P-MBTS + (1 - gamma) * P-GMCSI`.

The parametric boundary functions accept an explicit `k` and `alpha`. For
sized inputs up to 2,048 values they use sorted boundary slices; larger inputs
and unsized iterables use bounded heaps for the primary parametric boundary
means. The heap-based `calculate_p_mpu`, `calculate_p_mpd`,
`calculate_p_gma`, and `calculate_mbv` functions consume an iterable once.
The full `analyze_dataset` result also includes formulas that require the full
dataset, such as core slicing.

## Self-calibration

`autotune_parameters(data, fraction=...)` returns `k`, `alpha`, `beta`, and
`gamma` in a `MumoParameters` value. The default fraction is 5%; `k` is
bounded so that both the slice and its remainder are nonempty. Alpha and beta
are derived from the observed range, mean, and optional MBV baseline, then
clamped to `[0, 1]`. When the returned `k` is used with P-MBTS, MAEI, or MCHI,
it must satisfy `2 * k < n`.

`analyze_dataset` uses those calibrated values when parameters are omitted.
Any explicit `k`, `alpha`, `beta`, or `gamma` takes precedence over
autotuning.

## Standard comparison and Blind-Spot Alerts

Set `compare_standard=True` in `analyze_dataset` to return the arithmetic
mean, median, and population standard deviation alongside the Mumo formulas.
The standard mean is compared with P-MPU, P-MPD, and **Core Truth**
(P-GMCSI). A Blind-Spot Alert is emitted for each difference exceeding
`alert_tolerance * (max(data) - min(data))`; the default tolerance is 10% of
the observed range.

```python
from mumo_framework import analyze_dataset

data = [12.0, 15.2, 11.8, 45.0, 14.1, 13.9, 10.5]
analysis = analyze_dataset(
    data,
    k=2,                 # explicit overrides are preserved
    alpha=0.7,
    compare_standard=True,
)

print(analysis.metrics["P-MPU"])
print(analysis.standard_metrics)
for alert in analysis.blind_spot_alerts:
    print(alert)
```

`MumoAnalysis` contains `metrics`, optional `standard_metrics`,
`blind_spot_alerts`, the chosen parameters, and the primary boundary routing
(`"sorted"` or `"heap"`).

## Advanced calculus and matrix extensions

* `risk_velocity(mbv_values, times=None)` calculates first differences per
  time interval.
* `risk_acceleration(mbv_values, times=None)` calculates differences between
  adjacent velocity intervals.
* `cumulative_exposure(floor_values, observations, times=None)` integrates
  `floor - observation` using the trapezoidal rule.
* `boundary_matrix(data, k, alpha=...)` calculates P-MPU, P-MPD, and MBV for
  each row.
* `matrix_multiply(omega, data)` calculates `omega * data` for compatible
  rectangular matrices.

## Installation and use

```shell
python -m pip install mumo-engine
```

Or install the checkout in editable mode:

```shell
python -m pip install -e .
```

```python
from mumo_framework import MumoEngine

data = [12.0, 15.2, 11.8, 45.0, 14.1, 13.9, 10.5]
p_mpu = MumoEngine.calculate_p_mpu(data, k=2, alpha=0.7)
p_mpd = MumoEngine.calculate_p_mpd(data, k=2, alpha=0.7)
mbv = MumoEngine.calculate_mbv(data, k=2, alpha=0.7)
print(p_mpu, p_mpd, mbv)
```

For an unsized stream, pass a known `k` to a primary boundary function:

```python
p_mpu = MumoEngine.calculate_p_mpu((read_value() for _ in range(100_000)), k=500)
```

Run the interactive calculator with `python -m mumo_framework`; it accepts
comma- or whitespace-separated values and can optionally compare standard
metrics. Run the desktop interface with `mumo-framework-gui` or
`python -m mumo_gui`.

## License

MIT. See [LICENSE](./LICENSE).
