Skip to content

Add analyze_weights API for per-layer weight-entry distribution fitting#357

Open
charlesmartin14 wants to merge 2 commits intomasterfrom
codex/task-title
Open

Add analyze_weights API for per-layer weight-entry distribution fitting#357
charlesmartin14 wants to merge 2 commits intomasterfrom
codex/task-title

Conversation

@charlesmartin14
Copy link
Copy Markdown
Member

Motivation

  • Provide a dedicated, testable routine to analyze the distribution of raw weight entries per layer and compare left/right tails to multiple candidate families (power law, exponential, log-normal, Laplace).
  • Keep the new analysis isolated from the main analyze() workflow by placing it in a separate module so it can be unit tested in isolation.
  • Support practical requirements like fast subsampling and optional plotting for interactive inspection of fits.

Description

  • Added a new module weightwatcher/analyze_weights.py that implements _ks_metrics, _fit_side_models, _plot_side_distribution, and analyze_weights to fit left/right sides of the flattened weight entries to power_law, exponential, lognormal, and laplace using scipy.stats.
  • Fit scoring combines the Kolmogorov–Smirnov statistic and log-likelihood, and the code marks a single best fit per side with is_best_fit and best_fit_for_side fields; results are returned as a pandas.DataFrame and stored in watcher.details.
  • Added a wrapper method WeightWatcher.analyze_weights(...) in weightwatcher/weightwatcher.py that follows the analyze()-style signature and delegates to the new module so callers can invoke the new analysis via the WeightWatcher object.
  • Added unit tests tests/test_analyze_weights.py which generate synthetic samples for each target family (power-law, exponential, log-normal, Laplace) and assert that _fit_side_models selects the expected best distribution.

Testing

  • Ran the unit tests for the new analyzer with pytest -q tests/test_analyze_weights.py.
  • Result: 4 passed (all synthetic-distribution tests succeeded).

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant