dnaty 5.2.0__tar.gz

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.
Files changed (44) hide show
  1. dnaty-5.2.0/LICENSE +44 -0
  2. dnaty-5.2.0/PKG-INFO +242 -0
  3. dnaty-5.2.0/README.md +209 -0
  4. dnaty-5.2.0/dnaty/__init__.py +21 -0
  5. dnaty-5.2.0/dnaty/analysis/__init__.py +1 -0
  6. dnaty-5.2.0/dnaty/analysis/cl_metrics.py +40 -0
  7. dnaty-5.2.0/dnaty/compress.py +177 -0
  8. dnaty-5.2.0/dnaty/core/__init__.py +1 -0
  9. dnaty-5.2.0/dnaty/core/arch.py +85 -0
  10. dnaty-5.2.0/dnaty/core/arch_cnn.py +140 -0
  11. dnaty-5.2.0/dnaty/core/individual.py +34 -0
  12. dnaty-5.2.0/dnaty/core/memory.py +88 -0
  13. dnaty-5.2.0/dnaty/evolution/__init__.py +1 -0
  14. dnaty-5.2.0/dnaty/evolution/evolver.py +285 -0
  15. dnaty-5.2.0/dnaty/evolution/selection.py +78 -0
  16. dnaty-5.2.0/dnaty/experiments/__init__.py +1 -0
  17. dnaty-5.2.0/dnaty/experiments/fast_dataset.py +106 -0
  18. dnaty-5.2.0/dnaty/logging_config.py +40 -0
  19. dnaty-5.2.0/dnaty/operators/__init__.py +1 -0
  20. dnaty-5.2.0/dnaty/operators/mutations.py +256 -0
  21. dnaty-5.2.0/dnaty/operators/mutations_cnn.py +259 -0
  22. dnaty-5.2.0/dnaty/tracking.py +113 -0
  23. dnaty-5.2.0/dnaty/training/__init__.py +1 -0
  24. dnaty-5.2.0/dnaty/training/local_train.py +214 -0
  25. dnaty-5.2.0/dnaty.egg-info/PKG-INFO +242 -0
  26. dnaty-5.2.0/dnaty.egg-info/SOURCES.txt +42 -0
  27. dnaty-5.2.0/dnaty.egg-info/dependency_links.txt +1 -0
  28. dnaty-5.2.0/dnaty.egg-info/requires.txt +10 -0
  29. dnaty-5.2.0/dnaty.egg-info/top_level.txt +1 -0
  30. dnaty-5.2.0/pyproject.toml +58 -0
  31. dnaty-5.2.0/setup.cfg +4 -0
  32. dnaty-5.2.0/tests/test_auth_rate_limit.py +316 -0
  33. dnaty-5.2.0/tests/test_compress.py +54 -0
  34. dnaty-5.2.0/tests/test_docker.py +321 -0
  35. dnaty-5.2.0/tests/test_e2e_integration.py +261 -0
  36. dnaty-5.2.0/tests/test_edge_cases.py +278 -0
  37. dnaty-5.2.0/tests/test_exp23.py +79 -0
  38. dnaty-5.2.0/tests/test_load.py +239 -0
  39. dnaty-5.2.0/tests/test_market_real_models.py +318 -0
  40. dnaty-5.2.0/tests/test_market_reality.py +230 -0
  41. dnaty-5.2.0/tests/test_market_validation.py +284 -0
  42. dnaty-5.2.0/tests/test_regression.py +190 -0
  43. dnaty-5.2.0/tests/test_reproducibility.py +230 -0
  44. dnaty-5.2.0/tests/test_sanity.py +95 -0
dnaty-5.2.0/LICENSE ADDED
@@ -0,0 +1,44 @@
1
+ Business Source License 1.1
2
+
3
+ Parameters
4
+
5
+ Licensor: Pedro Vergueiro
6
+ Licensed Work: dNaty — Dynamic Neuro-Adaptive sYstem with evoluTionarY Learning
7
+ Copyright (c) 2026 Pedro Vergueiro
8
+ Additional Use Grant: You may use the Licensed Work for non-commercial research,
9
+ academic, and personal purposes free of charge.
10
+ Commercial use requires a separate commercial license.
11
+ Contact: legal@vergueiro.co for commercial licensing.
12
+ Change Date: 2029-01-01
13
+ Change License: Apache License, Version 2.0
14
+
15
+ ---
16
+
17
+ Terms
18
+
19
+ The Licensor hereby grants you the right to copy, modify, create derivative
20
+ works, redistribute, and make non-production use of the Licensed Work.
21
+
22
+ The Licensor may make an Additional Use Grant, above, permitting limited
23
+ production use.
24
+
25
+ Effective on the Change Date, or the fourth anniversary of the first publicly
26
+ available distribution of a specific version of the Licensed Work under this
27
+ License, whichever comes first, the Licensor hereby grants you rights under
28
+ the terms of the Change License, and the rights granted in the paragraphs
29
+ above terminate.
30
+
31
+ COMMERCIAL USE RESTRICTION:
32
+ Any use of the Licensed Work in a commercial product or service — including
33
+ but not limited to SaaS, APIs, embedded systems, or consulting services —
34
+ requires a separate commercial license from the Licensor.
35
+
36
+ For commercial licensing inquiries, contact: legal@vergueiro.co
37
+
38
+ ---
39
+
40
+ NOTICE: This is NOT an open source license. The source is available for
41
+ inspection and non-commercial use only. Commercial use without a license
42
+ is a violation of this agreement.
43
+
44
+ Full BSL 1.1 text: https://mariadb.com/bsl11/
dnaty-5.2.0/PKG-INFO ADDED
@@ -0,0 +1,242 @@
1
+ Metadata-Version: 2.4
2
+ Name: dnaty
3
+ Version: 5.2.0
4
+ Summary: Evolutionary Neural Architecture Search — compress any PyTorch model with one function call
5
+ Author-email: Pedro Vergueiro <pedrol.vergueiro@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/pedrovergueiroo/dNATY
8
+ Project-URL: Repository, https://github.com/pedrovergueiroo/dNATY
9
+ Project-URL: Bug Tracker, https://github.com/pedrovergueiroo/dNATY/issues
10
+ Keywords: neural architecture search,neuroevolution,model compression,continual learning,pytorch,evolutionary algorithms,nas,edge ml
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Operating System :: OS Independent
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: torch>=2.0.0
24
+ Requires-Dist: torchvision>=0.15.0
25
+ Requires-Dist: numpy>=1.24.0
26
+ Requires-Dist: scipy>=1.10.0
27
+ Requires-Dist: tqdm>=4.65.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
30
+ Requires-Dist: matplotlib>=3.7.0; extra == "dev"
31
+ Requires-Dist: jupyter; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ <div align="center">
35
+
36
+ # dNATY
37
+
38
+ ### Evolutionary AI Model Compression
39
+
40
+ **46.5% fewer FLOPs • 1.6× faster inference • 98.85% accuracy retained**
41
+
42
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-3776ab.svg?logo=python&logoColor=white)](https://www.python.org/)
43
+ [![PyTorch 2.0+](https://img.shields.io/badge/PyTorch-2.0+-ee4c2c.svg?logo=pytorch&logoColor=white)](https://pytorch.org/)
44
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
45
+
46
+ Automated model compression using multi-objective evolutionary search. Zero manual engineering. One function call: `compress(model, dataset)`.
47
+
48
+ ![dNATY Architecture](figure_1.png)
49
+
50
+ </div>
51
+
52
+ ---
53
+
54
+ ## Why dNATY?
55
+
56
+ **Problem:** Most production models are oversized — too slow for real-time inference, too expensive to run.
57
+
58
+ **Existing solutions require:**
59
+ - Manual architecture tuning
60
+ - Days of hyperparameter search
61
+ - Accuracy/speed trade-offs
62
+
63
+ **dNATY solves this** with episodic memory-guided evolutionary search — operators that worked before are tried more often. Finds Pareto-optimal solutions in minutes.
64
+
65
+ ### Proven Results (CIFAR-100)
66
+
67
+ | Model | FLOPs Reduction | Speedup | Accuracy | Time |
68
+ |-------|-----------------|---------|----------|------|
69
+ | ResNet-50 | **-46.5%** | 1.6× | 98.85% | 5min |
70
+ | EfficientNet-B0 | **-40%** | 1.4× | 98.85% | 6min |
71
+ | MobileNetV3-Large | **-98%** | 1.8× | 97.2% | 4min |
72
+
73
+ ---
74
+
75
+ ## Project Structure
76
+
77
+ ```
78
+ dNATY/
79
+ ├── dnaty/ # Core compression framework
80
+ ├── dnaty_saas/ # Production API (FastAPI)
81
+ ├── frontend/ # Web UI (React + TypeScript)
82
+ ├── notebooks/ # Experiments & benchmarks
83
+ ├── scripts/ # Demo & utilities
84
+ ├── tests/ # Unit tests
85
+ └── setup.py # Installation
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Quick Start
91
+
92
+ ```bash
93
+ pip install dnaty
94
+ ```
95
+
96
+ ```python
97
+ from dnaty import compress
98
+ from dnaty.experiments.fast_dataset import FastDataset
99
+
100
+ # Your existing model (any PyTorch model with Linear layers)
101
+ model = your_trained_model
102
+
103
+ # Your data
104
+ ds = FastDataset("MNIST", device="cpu", train_subset=10_000)
105
+
106
+ # Compress
107
+ result = compress(model, ds, target_flops=0.5, n_generations=30)
108
+
109
+ print(result.summary())
110
+ # CompressResult | arch=[128, 64] | FLOPs -46.5% (327680 -> 175104) |
111
+ # params -52.3% (328K -> 156K) | acc=0.9821
112
+ ```
113
+
114
+ ---
115
+
116
+ ## How It Works
117
+
118
+ dNATY runs a population of candidate architectures through an evolution loop:
119
+
120
+ 1. **Mutate** — apply structural operators (add/remove neurons, merge layers, etc.)
121
+ 2. **Train** — locally train each candidate for a few epochs
122
+ 3. **Select** — NSGA-II Pareto selection: maximize accuracy, minimize FLOPs
123
+ 4. **Remember** — episodic memory records which operators helped most; they get picked more often next round
124
+
125
+ The memory mechanism is dNATY's core innovation. Over generations, the search becomes smarter — not random.
126
+
127
+ ---
128
+
129
+ ## API
130
+
131
+ ### `compress(model, train_data, **kwargs) -> CompressResult`
132
+
133
+ | Parameter | Default | Description |
134
+ |---|---|---|
135
+ | `model` | required | Any `nn.Module` with Linear layers |
136
+ | `train_data` | required | `DataLoader` or `FastDataset` |
137
+ | `target_flops` | `0.5` | Target fraction of original FLOPs (0.5 = 50% less) |
138
+ | `n_generations` | `30` | Evolutionary generations |
139
+ | `n_pop` | `15` | Population size |
140
+ | `device` | auto | `'cpu'` or `'cuda'` |
141
+ | `seed` | `None` | Fix for reproducibility |
142
+
143
+ ### `CompressResult`
144
+
145
+ ```python
146
+ result.model # compressed nn.Module, ready to use
147
+ result.accuracy # validation accuracy
148
+ result.flops_reduction # e.g. 0.465 = 46.5% fewer FLOPs
149
+ result.flops_reduction_pct # same as percentage
150
+ result.params_reduction_pct
151
+ result.arch # hidden layer sizes found [128, 64]
152
+ result.summary() # one-line human-readable summary
153
+ ```
154
+
155
+ ---
156
+
157
+ ## SaaS API
158
+
159
+ dNATY ships with a production-ready FastAPI backend.
160
+
161
+ ```bash
162
+ cd dnaty_saas
163
+ cp .env.example .env # fill DATABASE_URL, JWT_SECRET, ANTHROPIC_API_KEY
164
+ uvicorn main:app --reload
165
+ ```
166
+
167
+ ### `POST /api/v1/compress`
168
+
169
+ ```json
170
+ {
171
+ "description": "classifica defeitos em pecas, precisa rodar no Raspberry Pi",
172
+ "dataset": "MNIST",
173
+ "target_flops": 0.5,
174
+ "n_generations": 30
175
+ }
176
+ ```
177
+
178
+ Response `202`:
179
+ ```json
180
+ { "job_id": "a3f2c1b0", "status": "queued", "message": "..." }
181
+ ```
182
+
183
+ ### `GET /api/v1/compress/{job_id}`
184
+
185
+ ```json
186
+ {
187
+ "status": "completed",
188
+ "result": {
189
+ "accuracy": 0.9821,
190
+ "flops_reduction": 0.465,
191
+ "arch": [128, 64],
192
+ "explanation": "...", // Claude-generated explanation
193
+ "deployment_code": "..." // ready-to-use Python code
194
+ }
195
+ }
196
+ ```
197
+
198
+ > Set `ANTHROPIC_API_KEY` in `.env` to enable Claude explanations.
199
+ > Without it, the endpoint still works — returns template text instead.
200
+
201
+ ---
202
+
203
+ ## Getting Started
204
+
205
+ ### Web UI
206
+ ```bash
207
+ cd frontend
208
+ npm install
209
+ npm run dev
210
+ ```
211
+ Open [http://localhost:5173](http://localhost:5173)
212
+
213
+ ### Jupyter Notebooks
214
+ - **CIFAR-100 Baseline** — [notebooks/colab_cifar100_notebook.ipynb](notebooks/colab_cifar100_notebook.ipynb)
215
+ - **ImageNet Benchmark** — [notebooks/colab_imagenet_simple_FIXED.ipynb](notebooks/colab_imagenet_simple_FIXED.ipynb)
216
+ - **CPU Latency** — [notebooks/benchmark_cpu_latency.py](notebooks/benchmark_cpu_latency.py)
217
+
218
+ ### CLI Demo
219
+ ```bash
220
+ python scripts/demo_compress.py # 20 gens, MNIST (~5 min CPU)
221
+ python scripts/demo_compress.py --full # 30 gens, more accurate
222
+ python scripts/demo_compress.py --dataset FashionMNIST
223
+ ```
224
+
225
+ ---
226
+
227
+ ## Benchmarks
228
+
229
+ | Metric | Value |
230
+ |---|---|
231
+ | FLOPs reduction vs. initial arch | -46.5% |
232
+ | FLOPs reduction vs. RandomNAS | better in Pareto front |
233
+ | Speedup to target accuracy | 1.6x fewer generations |
234
+ | CL: BWT vs. EWC | 6.9x less forgetting |
235
+
236
+ All numbers reproducible with `python scripts/prove_it.py`.
237
+
238
+ ---
239
+
240
+ ## License
241
+
242
+ [BSL 1.1](LICENSE) — free for non-commercial use; contact pedrol.vergueiro@gmail.com for commercial licensing.
dnaty-5.2.0/README.md ADDED
@@ -0,0 +1,209 @@
1
+ <div align="center">
2
+
3
+ # dNATY
4
+
5
+ ### Evolutionary AI Model Compression
6
+
7
+ **46.5% fewer FLOPs • 1.6× faster inference • 98.85% accuracy retained**
8
+
9
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-3776ab.svg?logo=python&logoColor=white)](https://www.python.org/)
10
+ [![PyTorch 2.0+](https://img.shields.io/badge/PyTorch-2.0+-ee4c2c.svg?logo=pytorch&logoColor=white)](https://pytorch.org/)
11
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
12
+
13
+ Automated model compression using multi-objective evolutionary search. Zero manual engineering. One function call: `compress(model, dataset)`.
14
+
15
+ ![dNATY Architecture](figure_1.png)
16
+
17
+ </div>
18
+
19
+ ---
20
+
21
+ ## Why dNATY?
22
+
23
+ **Problem:** Most production models are oversized — too slow for real-time inference, too expensive to run.
24
+
25
+ **Existing solutions require:**
26
+ - Manual architecture tuning
27
+ - Days of hyperparameter search
28
+ - Accuracy/speed trade-offs
29
+
30
+ **dNATY solves this** with episodic memory-guided evolutionary search — operators that worked before are tried more often. Finds Pareto-optimal solutions in minutes.
31
+
32
+ ### Proven Results (CIFAR-100)
33
+
34
+ | Model | FLOPs Reduction | Speedup | Accuracy | Time |
35
+ |-------|-----------------|---------|----------|------|
36
+ | ResNet-50 | **-46.5%** | 1.6× | 98.85% | 5min |
37
+ | EfficientNet-B0 | **-40%** | 1.4× | 98.85% | 6min |
38
+ | MobileNetV3-Large | **-98%** | 1.8× | 97.2% | 4min |
39
+
40
+ ---
41
+
42
+ ## Project Structure
43
+
44
+ ```
45
+ dNATY/
46
+ ├── dnaty/ # Core compression framework
47
+ ├── dnaty_saas/ # Production API (FastAPI)
48
+ ├── frontend/ # Web UI (React + TypeScript)
49
+ ├── notebooks/ # Experiments & benchmarks
50
+ ├── scripts/ # Demo & utilities
51
+ ├── tests/ # Unit tests
52
+ └── setup.py # Installation
53
+ ```
54
+
55
+ ---
56
+
57
+ ## Quick Start
58
+
59
+ ```bash
60
+ pip install dnaty
61
+ ```
62
+
63
+ ```python
64
+ from dnaty import compress
65
+ from dnaty.experiments.fast_dataset import FastDataset
66
+
67
+ # Your existing model (any PyTorch model with Linear layers)
68
+ model = your_trained_model
69
+
70
+ # Your data
71
+ ds = FastDataset("MNIST", device="cpu", train_subset=10_000)
72
+
73
+ # Compress
74
+ result = compress(model, ds, target_flops=0.5, n_generations=30)
75
+
76
+ print(result.summary())
77
+ # CompressResult | arch=[128, 64] | FLOPs -46.5% (327680 -> 175104) |
78
+ # params -52.3% (328K -> 156K) | acc=0.9821
79
+ ```
80
+
81
+ ---
82
+
83
+ ## How It Works
84
+
85
+ dNATY runs a population of candidate architectures through an evolution loop:
86
+
87
+ 1. **Mutate** — apply structural operators (add/remove neurons, merge layers, etc.)
88
+ 2. **Train** — locally train each candidate for a few epochs
89
+ 3. **Select** — NSGA-II Pareto selection: maximize accuracy, minimize FLOPs
90
+ 4. **Remember** — episodic memory records which operators helped most; they get picked more often next round
91
+
92
+ The memory mechanism is dNATY's core innovation. Over generations, the search becomes smarter — not random.
93
+
94
+ ---
95
+
96
+ ## API
97
+
98
+ ### `compress(model, train_data, **kwargs) -> CompressResult`
99
+
100
+ | Parameter | Default | Description |
101
+ |---|---|---|
102
+ | `model` | required | Any `nn.Module` with Linear layers |
103
+ | `train_data` | required | `DataLoader` or `FastDataset` |
104
+ | `target_flops` | `0.5` | Target fraction of original FLOPs (0.5 = 50% less) |
105
+ | `n_generations` | `30` | Evolutionary generations |
106
+ | `n_pop` | `15` | Population size |
107
+ | `device` | auto | `'cpu'` or `'cuda'` |
108
+ | `seed` | `None` | Fix for reproducibility |
109
+
110
+ ### `CompressResult`
111
+
112
+ ```python
113
+ result.model # compressed nn.Module, ready to use
114
+ result.accuracy # validation accuracy
115
+ result.flops_reduction # e.g. 0.465 = 46.5% fewer FLOPs
116
+ result.flops_reduction_pct # same as percentage
117
+ result.params_reduction_pct
118
+ result.arch # hidden layer sizes found [128, 64]
119
+ result.summary() # one-line human-readable summary
120
+ ```
121
+
122
+ ---
123
+
124
+ ## SaaS API
125
+
126
+ dNATY ships with a production-ready FastAPI backend.
127
+
128
+ ```bash
129
+ cd dnaty_saas
130
+ cp .env.example .env # fill DATABASE_URL, JWT_SECRET, ANTHROPIC_API_KEY
131
+ uvicorn main:app --reload
132
+ ```
133
+
134
+ ### `POST /api/v1/compress`
135
+
136
+ ```json
137
+ {
138
+ "description": "classifica defeitos em pecas, precisa rodar no Raspberry Pi",
139
+ "dataset": "MNIST",
140
+ "target_flops": 0.5,
141
+ "n_generations": 30
142
+ }
143
+ ```
144
+
145
+ Response `202`:
146
+ ```json
147
+ { "job_id": "a3f2c1b0", "status": "queued", "message": "..." }
148
+ ```
149
+
150
+ ### `GET /api/v1/compress/{job_id}`
151
+
152
+ ```json
153
+ {
154
+ "status": "completed",
155
+ "result": {
156
+ "accuracy": 0.9821,
157
+ "flops_reduction": 0.465,
158
+ "arch": [128, 64],
159
+ "explanation": "...", // Claude-generated explanation
160
+ "deployment_code": "..." // ready-to-use Python code
161
+ }
162
+ }
163
+ ```
164
+
165
+ > Set `ANTHROPIC_API_KEY` in `.env` to enable Claude explanations.
166
+ > Without it, the endpoint still works — returns template text instead.
167
+
168
+ ---
169
+
170
+ ## Getting Started
171
+
172
+ ### Web UI
173
+ ```bash
174
+ cd frontend
175
+ npm install
176
+ npm run dev
177
+ ```
178
+ Open [http://localhost:5173](http://localhost:5173)
179
+
180
+ ### Jupyter Notebooks
181
+ - **CIFAR-100 Baseline** — [notebooks/colab_cifar100_notebook.ipynb](notebooks/colab_cifar100_notebook.ipynb)
182
+ - **ImageNet Benchmark** — [notebooks/colab_imagenet_simple_FIXED.ipynb](notebooks/colab_imagenet_simple_FIXED.ipynb)
183
+ - **CPU Latency** — [notebooks/benchmark_cpu_latency.py](notebooks/benchmark_cpu_latency.py)
184
+
185
+ ### CLI Demo
186
+ ```bash
187
+ python scripts/demo_compress.py # 20 gens, MNIST (~5 min CPU)
188
+ python scripts/demo_compress.py --full # 30 gens, more accurate
189
+ python scripts/demo_compress.py --dataset FashionMNIST
190
+ ```
191
+
192
+ ---
193
+
194
+ ## Benchmarks
195
+
196
+ | Metric | Value |
197
+ |---|---|
198
+ | FLOPs reduction vs. initial arch | -46.5% |
199
+ | FLOPs reduction vs. RandomNAS | better in Pareto front |
200
+ | Speedup to target accuracy | 1.6x fewer generations |
201
+ | CL: BWT vs. EWC | 6.9x less forgetting |
202
+
203
+ All numbers reproducible with `python scripts/prove_it.py`.
204
+
205
+ ---
206
+
207
+ ## License
208
+
209
+ [BSL 1.1](LICENSE) — free for non-commercial use; contact pedrol.vergueiro@gmail.com for commercial licensing.
@@ -0,0 +1,21 @@
1
+ """
2
+ dNATY — Dynamic Neuro-Adaptive sYstem.
3
+
4
+ Evolutionary Neural Architecture Search with episodic memory.
5
+ Finds compact, efficient models via guided evolution — not random search.
6
+
7
+ Quick start:
8
+ from dnaty import compress
9
+ from dnaty.experiments.fast_dataset import FastDataset
10
+
11
+ ds = FastDataset("MNIST", device="cpu", train_subset=10_000)
12
+ result = compress(your_model, ds, target_flops=0.5)
13
+ print(result.summary())
14
+ """
15
+
16
+ __version__ = "5.2.0"
17
+
18
+ from dnaty.compress import compress, CompressResult
19
+ from dnaty.evolution.evolver import DnatyEvolver
20
+
21
+ __all__ = ["compress", "CompressResult", "DnatyEvolver", "__version__"]
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,40 @@
1
+ """
2
+ Métricas de Continual Learning — Lopez-Paz et al. (2017).
3
+ BWT, FWT, FM implementados conforme formalização seção 1.5.
4
+ """
5
+ from __future__ import annotations
6
+ import numpy as np
7
+
8
+
9
+ def compute_cl_metrics(R: np.ndarray, baselines: np.ndarray | None = None) -> dict[str, float]:
10
+ """
11
+ R[i, j] = acurácia na tarefa j após treinar sequencialmente até tarefa i.
12
+ R é indexado de 0 (após tarefa 0) até T-1 (após tarefa T-1).
13
+ baselines[j] = acurácia single-task na tarefa j (para FWT).
14
+ """
15
+ T = R.shape[1]
16
+
17
+ # BWT: Backward Transfer — forgetting
18
+ # BWT = (1/(T-1)) * Σ_{i=1}^{T-1} (R[T-1,i] - R[i,i])
19
+ bwt_terms = [R[T - 1, i] - R[i, i] for i in range(T - 1)]
20
+ BWT = float(np.mean(bwt_terms)) if bwt_terms else 0.0
21
+
22
+ # FWT: Forward Transfer
23
+ if baselines is not None:
24
+ fwt_terms = [R[i - 1, i] - baselines[i] for i in range(1, T)]
25
+ FWT = float(np.mean(fwt_terms)) if fwt_terms else 0.0
26
+ else:
27
+ FWT = 0.0
28
+
29
+ # FM: Forgetting Measure — queda do pico
30
+ fm_terms = []
31
+ for i in range(T - 1):
32
+ peak = max(R[j, i] for j in range(T))
33
+ fm_terms.append(peak - R[T - 1, i])
34
+ FM = float(np.mean(fm_terms)) if fm_terms else 0.0
35
+
36
+ return {
37
+ "BWT": round(BWT, 4),
38
+ "FWT": round(FWT, 4),
39
+ "FM": round(FM, 4),
40
+ }