nexml 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of nexml might be problematic. Click here for more details.
- nexml/__init__.py +27 -0
- nexml/__main__.py +31 -0
- nexml/core/__init__.py +4 -0
- nexml/core/auto_tuner.py +121 -0
- nexml/core/configuration.py +40 -0
- nexml/core/engine.py +491 -0
- nexml/core/progress.py +127 -0
- nexml/detection/__init__.py +12 -0
- nexml/detection/concept_drift.py +92 -0
- nexml/detection/data_drift.py +84 -0
- nexml/detection/data_quality.py +43 -0
- nexml/detection/spectral_drift.py +52 -0
- nexml/diagnosis/__init__.py +15 -0
- nexml/diagnosis/bayesian_diagnosis.py +43 -0
- nexml/diagnosis/feature_analysis.py +27 -0
- nexml/diagnosis/graph_root_cause.py +44 -0
- nexml/diagnosis/information_ranking.py +72 -0
- nexml/diagnosis/root_cause.py +29 -0
- nexml/diagnosis/segment_analysis.py +50 -0
- nexml/label_quality/__init__.py +5 -0
- nexml/label_quality/consistency.py +31 -0
- nexml/label_quality/label_error_report.py +41 -0
- nexml/label_quality/noise_detector.py +95 -0
- nexml/math/__init__.py +19 -0
- nexml/math/calculus.py +54 -0
- nexml/math/linear_algebra.py +88 -0
- nexml/math/optimization.py +67 -0
- nexml/recovery/__init__.py +4 -0
- nexml/recovery/intervention.py +180 -0
- nexml/recovery/recommendations.py +27 -0
- nexml/reporting/__init__.py +5 -0
- nexml/reporting/expert_diagnostics.py +147 -0
- nexml/reporting/plain_english.py +106 -0
- nexml/reporting/reports.py +134 -0
- nexml/validation/__init__.py +15 -0
- nexml/validation/comparison.py +55 -0
- nexml/validation/conformal.py +86 -0
- nexml/validation/performance.py +74 -0
- nexml/validation/stability.py +49 -0
- nexml-1.0.0.dist-info/METADATA +92 -0
- nexml-1.0.0.dist-info/RECORD +45 -0
- nexml-1.0.0.dist-info/WHEEL +5 -0
- nexml-1.0.0.dist-info/entry_points.txt +2 -0
- nexml-1.0.0.dist-info/licenses/LICENSE +21 -0
- nexml-1.0.0.dist-info/top_level.txt +1 -0
nexml/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""NEXML — Nonlinear Evolutionary eXtensible Mathematical Learning.
|
|
2
|
+
|
|
3
|
+
NEXML v1.0.0 "Aegis"
|
|
4
|
+
Model-agnostic ML failure diagnosis, label quality analysis,
|
|
5
|
+
and validated recovery. Works for classification and regression.
|
|
6
|
+
|
|
7
|
+
Quickstart:
|
|
8
|
+
>>> from nexml import NEXML
|
|
9
|
+
>>> engine = NEXML(model=trained_model, task="classification")
|
|
10
|
+
>>> engine.fit(reference_data=X_train, reference_target=y_train)
|
|
11
|
+
>>> report = engine.analyze(
|
|
12
|
+
... new_data=X_new, new_target=y_new,
|
|
13
|
+
... recent_labeled_data=X_recent, recent_labeled_target=y_recent,
|
|
14
|
+
... validation_data=X_val, validation_target=y_val,
|
|
15
|
+
... )
|
|
16
|
+
>>> print(report.plain_english)
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from nexml.core.engine import NEXML
|
|
20
|
+
from nexml.core.configuration import NEXMLConfig
|
|
21
|
+
|
|
22
|
+
__version__ = "1.0.0"
|
|
23
|
+
__codename__ = "Aegis"
|
|
24
|
+
__author__ = "NEXML Research"
|
|
25
|
+
__license__ = "MIT"
|
|
26
|
+
|
|
27
|
+
__all__ = ["NEXML", "NEXMLConfig", "__version__", "__codename__"]
|
nexml/__main__.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""NEXML CLI: `nexml` or `python -m nexml` prints the release banner."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
import nexml
|
|
6
|
+
|
|
7
|
+
BANNER = r"""
|
|
8
|
+
███╗ ██╗███████╗██╗ ██╗███╗ ███╗██╗
|
|
9
|
+
████╗ ██║██╔════╝╚██╗██╔╝████╗ ████║██║
|
|
10
|
+
██╔██╗ ██║█████╗ ╚███╔╝ ██╔████╔██║██║
|
|
11
|
+
██║╚██╗██║██╔══╝ ██╔██╗ ██║╚██╔╝██║██║
|
|
12
|
+
██║ ╚████║███████╗██╔╝ ██╗██║ ╚═╝ ██║███████╗
|
|
13
|
+
╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def main() -> None:
|
|
18
|
+
"""Entry point for the `nexml` CLI command."""
|
|
19
|
+
print(BANNER)
|
|
20
|
+
print(f" NEXML v{nexml.__version__} — \"{nexml.__codename__}\"")
|
|
21
|
+
print(" Nonlinear Evolutionary eXtensible Mathematical Learning")
|
|
22
|
+
print(" Model-agnostic ML failure diagnosis, label quality analysis,")
|
|
23
|
+
print(" and validated recovery — for classification and regression.")
|
|
24
|
+
print()
|
|
25
|
+
print(f" Python {sys.version.split()[0]}")
|
|
26
|
+
print(" MIT License · https://github.com/sam-x-specx/nexml-aegisv1.0.0")
|
|
27
|
+
print()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if __name__ == "__main__":
|
|
31
|
+
main()
|
nexml/core/__init__.py
ADDED
nexml/core/auto_tuner.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""Bayesian optimization of NEXML configuration parameters.
|
|
2
|
+
|
|
3
|
+
v1.0.8: More descriptive lambda_source when tuning fails to improve objective.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
import optuna
|
|
12
|
+
_HAS_OPTUNA = True
|
|
13
|
+
except ImportError: # pragma: no cover
|
|
14
|
+
_HAS_OPTUNA = False
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
_DEFAULT_LAMBDA_COST = 0.05
|
|
18
|
+
_DEFAULT_LAMBDA_RISK = 0.5
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def tune_lambdas(
|
|
22
|
+
validation_results: list[dict],
|
|
23
|
+
higher_is_better: bool = True,
|
|
24
|
+
n_trials: int = 30,
|
|
25
|
+
seed: int = 42,
|
|
26
|
+
gain_scale: float = 1.0,
|
|
27
|
+
) -> dict:
|
|
28
|
+
"""Tune λ₁ (cost), λ₂ (risk) to produce EXACTLY ONE clear winner.
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
{"lambda_cost": float, "lambda_risk": float, "lambda_source": str}
|
|
32
|
+
where lambda_source is "tuned" or a descriptive "default (...)".
|
|
33
|
+
"""
|
|
34
|
+
if not validation_results:
|
|
35
|
+
return _defaults("default (empty validation)")
|
|
36
|
+
|
|
37
|
+
if higher_is_better:
|
|
38
|
+
gains = np.array(
|
|
39
|
+
[r["metric"] - r["baseline_metric"] for r in validation_results], dtype=float
|
|
40
|
+
)
|
|
41
|
+
else:
|
|
42
|
+
gains = np.array(
|
|
43
|
+
[r["baseline_metric"] - r["metric"] for r in validation_results], dtype=float
|
|
44
|
+
)
|
|
45
|
+
costs = np.array(
|
|
46
|
+
[min(r["cost_seconds"] / 60.0, 1.0) for r in validation_results], dtype=float
|
|
47
|
+
)
|
|
48
|
+
risks = np.array([r["risk"] for r in validation_results], dtype=float)
|
|
49
|
+
|
|
50
|
+
# No action has positive gain → tuning cannot help; return defaults.
|
|
51
|
+
gains = gains / gain_scale
|
|
52
|
+
if not np.any(gains > 0):
|
|
53
|
+
return _defaults("default (no action beat baseline)")
|
|
54
|
+
|
|
55
|
+
# Lexicographic objective:
|
|
56
|
+
# 1) Prefer accepted_count == 1 (highest priority)
|
|
57
|
+
# 2) Among configurations with accepted_count == 1, maximize gain
|
|
58
|
+
# 3) If accepted_count != 1, score = -|accepted_count - 1| * penalty
|
|
59
|
+
def objective(lam1: float, lam2: float) -> float:
|
|
60
|
+
J = gains - lam1 * costs - lam2 * risks
|
|
61
|
+
accepted = int((J > 0).sum())
|
|
62
|
+
if accepted == 1:
|
|
63
|
+
# Excellent: one clear winner. Score = its gain.
|
|
64
|
+
return float(gains[J > 0][0])
|
|
65
|
+
if accepted == 0:
|
|
66
|
+
# Bad: nothing works. Score strictly below any 1-accepted solution.
|
|
67
|
+
return -100.0
|
|
68
|
+
# 2+ accepted: heavily penalize, so tuning pushes toward exactly 1.
|
|
69
|
+
accepted_gains = np.sort(gains[J > 0])[::-1]
|
|
70
|
+
best = float(accepted_gains[0])
|
|
71
|
+
return best - 0.1 * (accepted - 1)
|
|
72
|
+
|
|
73
|
+
# Baseline: λ = 0 (unpenalized). If tuning can't beat this, stay at 0.
|
|
74
|
+
zero_score = objective(0.0, 0.0)
|
|
75
|
+
|
|
76
|
+
if not _HAS_OPTUNA:
|
|
77
|
+
best = {"lambda_cost": 0.0, "lambda_risk": 0.0}
|
|
78
|
+
best_score = zero_score
|
|
79
|
+
for lam1 in np.linspace(0.0, 0.5, 11):
|
|
80
|
+
for lam2 in np.linspace(0.0, 2.0, 11):
|
|
81
|
+
score = objective(float(lam1), float(lam2))
|
|
82
|
+
if score > best_score + 1e-9:
|
|
83
|
+
best_score = score
|
|
84
|
+
best = {"lambda_cost": float(lam1), "lambda_risk": float(lam2)}
|
|
85
|
+
if best["lambda_cost"] == 0.0 and best["lambda_risk"] == 0.0:
|
|
86
|
+
return _defaults("default (tuning did not improve objective)")
|
|
87
|
+
return {
|
|
88
|
+
"lambda_cost": best["lambda_cost"],
|
|
89
|
+
"lambda_risk": best["lambda_risk"],
|
|
90
|
+
"lambda_source": "tuned",
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
optuna.logging.set_verbosity(optuna.logging.WARNING)
|
|
94
|
+
|
|
95
|
+
def optuna_obj(trial):
|
|
96
|
+
lam1 = trial.suggest_float("lambda_cost", 0.0, 0.5)
|
|
97
|
+
lam2 = trial.suggest_float("lambda_risk", 0.0, 2.0)
|
|
98
|
+
return objective(lam1, lam2)
|
|
99
|
+
|
|
100
|
+
study = optuna.create_study(
|
|
101
|
+
direction="maximize", sampler=optuna.samplers.TPESampler(seed=seed)
|
|
102
|
+
)
|
|
103
|
+
study.optimize(optuna_obj, n_trials=n_trials, show_progress_bar=False)
|
|
104
|
+
|
|
105
|
+
best_lam1 = float(study.best_params["lambda_cost"])
|
|
106
|
+
best_lam2 = float(study.best_params["lambda_risk"])
|
|
107
|
+
best_score = float(study.best_value)
|
|
108
|
+
|
|
109
|
+
# If tuning didn't beat λ = 0, return defaults to avoid false "tuned" label.
|
|
110
|
+
if best_score <= zero_score + 1e-9:
|
|
111
|
+
return _defaults("default (tuning did not improve objective)")
|
|
112
|
+
|
|
113
|
+
return {"lambda_cost": best_lam1, "lambda_risk": best_lam2, "lambda_source": "tuned"}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _defaults(source: str) -> dict:
|
|
117
|
+
return {
|
|
118
|
+
"lambda_cost": _DEFAULT_LAMBDA_COST,
|
|
119
|
+
"lambda_risk": _DEFAULT_LAMBDA_RISK,
|
|
120
|
+
"lambda_source": source,
|
|
121
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""NEXML configuration."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Literal
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class NEXMLConfig:
|
|
9
|
+
task: Literal["classification", "regression"] = "classification"
|
|
10
|
+
drift_alpha: float = 0.05
|
|
11
|
+
effect_size_threshold: float = 0.10
|
|
12
|
+
importance_weight: float = 0.4
|
|
13
|
+
drift_weight: float = 0.4
|
|
14
|
+
error_weight: float = 0.2
|
|
15
|
+
cost_lambda: float = 0.05
|
|
16
|
+
risk_lambda: float = 0.5
|
|
17
|
+
validation_chunks: int = 5
|
|
18
|
+
min_performance_gain: float = 0.005
|
|
19
|
+
metric: str = ""
|
|
20
|
+
|
|
21
|
+
auto_tune: bool = True
|
|
22
|
+
# FFT drift only means something when rows are an ordered time series.
|
|
23
|
+
# Off by default; enable it for time-ordered data.
|
|
24
|
+
spectral_drift: bool = False
|
|
25
|
+
bayesian_diagnosis: bool = True
|
|
26
|
+
information_ranking: bool = True
|
|
27
|
+
graph_root_cause: bool = True
|
|
28
|
+
conformal_bounds: bool = True
|
|
29
|
+
label_quality: bool = True
|
|
30
|
+
|
|
31
|
+
def resolved_metric(self) -> str:
|
|
32
|
+
if self.metric:
|
|
33
|
+
return self.metric
|
|
34
|
+
return "f1" if self.task == "classification" else "mae"
|
|
35
|
+
|
|
36
|
+
def higher_is_better(self) -> bool:
|
|
37
|
+
"""F1 is higher-better; MAE/RMSE are lower-better; R² is higher-better."""
|
|
38
|
+
if self.task == "classification":
|
|
39
|
+
return True
|
|
40
|
+
return self.resolved_metric() in ("r2",)
|