zeroth-learn 0.2.0__tar.gz → 0.2.1__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.
- {zeroth_learn-0.2.0/zeroth_learn.egg-info → zeroth_learn-0.2.1}/PKG-INFO +1 -1
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/pyproject.toml +1 -1
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/abstract/__init__.py +1 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/abstract/activation.py +2 -2
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/abstract/blackbox.py +3 -3
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/abstract/data_creator.py +1 -1
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/abstract/loss.py +6 -6
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/abstract/metric.py +1 -1
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/abstract/model.py +6 -4
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/abstract/neural_network.py +3 -2
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/abstract/optimizer.py +1 -1
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/abstract/perturbation_matrix.py +1 -1
- zeroth_learn-0.2.1/zeroth/abstract/summary.py +13 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/data.py +3 -4
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/experiment.py +6 -6
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/first_order/optimizers.py +4 -5
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/utils/dataclasses_utils.py +0 -11
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/zeroth_order/gradient_estimators.py +3 -3
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/zeroth_order/optimizers.py +6 -7
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/zeroth_order/zeroth_order_blackbox.py +2 -2
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1/zeroth_learn.egg-info}/PKG-INFO +1 -1
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth_learn.egg-info/SOURCES.txt +1 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/MANIFEST.in +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/README.md +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/setup.cfg +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/__init__.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/first_order/__init__.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/first_order/layer.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/first_order/model.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/first_order/neural_network.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/losses/__init__.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/losses/cross_entropy.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/losses/mse.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/paths.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/plot_losses.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/types.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/utils/__init__.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/utils/activation_functions.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/utils/metrics.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/utils/perturbation_matrices.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/zeroth_order/__init__.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/zeroth_order/model.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/zeroth_order/neural_network/__init__.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/zeroth_order/neural_network/neural_network.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/zeroth_order/neural_network/parameter_manager.py +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth_learn.egg-info/dependency_links.txt +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth_learn.egg-info/requires.txt +0 -0
- {zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth_learn.egg-info/top_level.txt +0 -0
|
@@ -12,9 +12,9 @@ class Activation(ABC):
|
|
|
12
12
|
@abstractmethod
|
|
13
13
|
def __call__(self, x: float | Array) -> float | Array:
|
|
14
14
|
"""Applique la fonction d'activation (forward)."""
|
|
15
|
-
|
|
15
|
+
...
|
|
16
16
|
|
|
17
17
|
@abstractmethod
|
|
18
18
|
def derivative(self, x: float | Array) -> float | Array:
|
|
19
19
|
"""Calcule la dérivée de la fonction d'activation."""
|
|
20
|
-
|
|
20
|
+
...
|
|
@@ -21,7 +21,7 @@ class BlackBox(ABC):
|
|
|
21
21
|
Returns:
|
|
22
22
|
Array: Network predictions. Shape: (output_dim, batch_size).
|
|
23
23
|
"""
|
|
24
|
-
|
|
24
|
+
...
|
|
25
25
|
|
|
26
26
|
@abstractmethod
|
|
27
27
|
def init_params(self, params: dict) -> None:
|
|
@@ -30,7 +30,7 @@ class BlackBox(ABC):
|
|
|
30
30
|
Args:
|
|
31
31
|
params (tuple): Tuple containing the parameters (eg: weights and biases).
|
|
32
32
|
"""
|
|
33
|
-
|
|
33
|
+
...
|
|
34
34
|
|
|
35
35
|
@abstractmethod
|
|
36
36
|
def get_params(self) -> dict:
|
|
@@ -39,4 +39,4 @@ class BlackBox(ABC):
|
|
|
39
39
|
Returns:
|
|
40
40
|
dict: (eg: List of Weight matrices, List of Bias vectors).
|
|
41
41
|
"""
|
|
42
|
-
|
|
42
|
+
...
|
|
@@ -15,7 +15,7 @@ class Loss(ABC):
|
|
|
15
15
|
:param Y_true: shape (batch, out)
|
|
16
16
|
:return: avg loss shape: float
|
|
17
17
|
"""
|
|
18
|
-
|
|
18
|
+
...
|
|
19
19
|
|
|
20
20
|
@staticmethod
|
|
21
21
|
@abstractmethod
|
|
@@ -25,7 +25,7 @@ class Loss(ABC):
|
|
|
25
25
|
:param Y_true: shape (batch, out)
|
|
26
26
|
:return: batch loss shape (batch, )
|
|
27
27
|
"""
|
|
28
|
-
|
|
28
|
+
...
|
|
29
29
|
|
|
30
30
|
@staticmethod
|
|
31
31
|
@abstractmethod
|
|
@@ -35,7 +35,7 @@ class Loss(ABC):
|
|
|
35
35
|
:param Y_true: (batch, out)
|
|
36
36
|
:return: perturbed loss (T, nb_params)
|
|
37
37
|
"""
|
|
38
|
-
|
|
38
|
+
...
|
|
39
39
|
|
|
40
40
|
@staticmethod
|
|
41
41
|
@abstractmethod
|
|
@@ -46,13 +46,13 @@ class Loss(ABC):
|
|
|
46
46
|
:param Y_true: shape (batch, out)
|
|
47
47
|
:return: batch loss shape (batch, )
|
|
48
48
|
"""
|
|
49
|
-
|
|
49
|
+
...
|
|
50
50
|
|
|
51
51
|
@abstractmethod
|
|
52
52
|
def compute_losses_for_zeroth_order(self, pY_pred: Array, Y_true: Array) -> tuple[float, Array]:
|
|
53
|
-
|
|
53
|
+
...
|
|
54
54
|
|
|
55
55
|
@abstractmethod
|
|
56
56
|
def compute_losses_for_first_order(self, last_layer, Y_pred: Array, Y_true: Array) -> tuple[
|
|
57
57
|
float, Array]:
|
|
58
|
-
|
|
58
|
+
...
|
|
@@ -13,10 +13,11 @@ import pandas as pd
|
|
|
13
13
|
from .blackbox import BlackBox
|
|
14
14
|
from .loss import Loss
|
|
15
15
|
from .optimizer import Optimizer
|
|
16
|
+
from .summary import Summary
|
|
16
17
|
from ..data import Data
|
|
17
18
|
from ..plot_losses import plot_losses
|
|
18
19
|
from ..types import Array
|
|
19
|
-
from ..utils.dataclasses_utils import config_serializer
|
|
20
|
+
from ..utils.dataclasses_utils import config_serializer
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
@dataclass(frozen=True, kw_only=True)
|
|
@@ -38,10 +39,10 @@ class ModelConfig(ABC, Summary):
|
|
|
38
39
|
|
|
39
40
|
@abstractmethod
|
|
40
41
|
def instantiate(self) -> Model:
|
|
41
|
-
|
|
42
|
+
...
|
|
42
43
|
|
|
43
44
|
|
|
44
|
-
class Model(ABC
|
|
45
|
+
class Model(ABC):
|
|
45
46
|
"""
|
|
46
47
|
Base class orchestrating the training and testing loop.
|
|
47
48
|
|
|
@@ -79,7 +80,8 @@ class Model(ABC, Summary):
|
|
|
79
80
|
print(f" Training {self.id} Model")
|
|
80
81
|
|
|
81
82
|
data.batch_size = self.batch_size
|
|
82
|
-
nb_batches = data
|
|
83
|
+
nb_batches = len(data)
|
|
84
|
+
|
|
83
85
|
self.training_loss = np.zeros(self.nb_epochs * nb_batches, dtype=np.float64)
|
|
84
86
|
print_indexes = np.linspace(0, nb_batches - 1, nb_print).astype(int)
|
|
85
87
|
|
|
@@ -2,17 +2,18 @@ from abc import ABC
|
|
|
2
2
|
from dataclasses import dataclass
|
|
3
3
|
|
|
4
4
|
from .activation import Activation
|
|
5
|
+
from .summary import Summary
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
@dataclass(frozen=True)
|
|
8
|
-
class LayerConfig:
|
|
9
|
+
class LayerConfig(Summary):
|
|
9
10
|
input_dim: int
|
|
10
11
|
output_dim: int
|
|
11
12
|
activation: Activation
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
@dataclass(frozen=True)
|
|
15
|
-
class NeuralNetworkConfig:
|
|
16
|
+
class NeuralNetworkConfig(Summary):
|
|
16
17
|
name: str
|
|
17
18
|
layers_config: list[LayerConfig]
|
|
18
19
|
|
|
@@ -17,14 +17,13 @@ class Data:
|
|
|
17
17
|
|
|
18
18
|
self.indices: np.ndarray = np.arange(self.nb_data)
|
|
19
19
|
|
|
20
|
+
def __len__(self) -> int:
|
|
21
|
+
return self.nb_data // self.batch_size
|
|
22
|
+
|
|
20
23
|
def __iter__(self) -> Iterator[tuple[Array, Array]]:
|
|
21
24
|
for i in range(0, self.nb_data - self.batch_size + 1, self.batch_size):
|
|
22
25
|
batch_idx = self.indices[i:i + self.batch_size]
|
|
23
26
|
yield self.raw_X_train[batch_idx], self.raw_Y_train[batch_idx]
|
|
24
27
|
|
|
25
|
-
@property
|
|
26
|
-
def nb_batches(self) -> int:
|
|
27
|
-
return self.nb_data // self.batch_size
|
|
28
|
-
|
|
29
28
|
def permutation(self) -> None:
|
|
30
29
|
self.indices = np.random.permutation(self.nb_data)
|
|
@@ -3,14 +3,14 @@ from __future__ import annotations
|
|
|
3
3
|
import itertools
|
|
4
4
|
import os
|
|
5
5
|
from dataclasses import dataclass, replace
|
|
6
|
-
from typing import
|
|
6
|
+
from typing import Union
|
|
7
7
|
|
|
8
8
|
import pandas as pd
|
|
9
9
|
|
|
10
|
-
from .abstract import Model, ModelConfig
|
|
10
|
+
from .abstract import Model, ModelConfig, DataCreator, Summary
|
|
11
11
|
from .data import Data
|
|
12
12
|
from .plot_losses import plot_losses
|
|
13
|
-
from .utils.dataclasses_utils import get_name, set_value_by_path
|
|
13
|
+
from .utils.dataclasses_utils import get_name, set_value_by_path
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
@dataclass(frozen=True)
|
|
@@ -26,7 +26,7 @@ class ExperimentConfig(Summary):
|
|
|
26
26
|
title: str
|
|
27
27
|
base_model: ModelConfig
|
|
28
28
|
variations: list[VariationConfig]
|
|
29
|
-
|
|
29
|
+
data_creator: DataCreator
|
|
30
30
|
plot_dimension: int
|
|
31
31
|
smooth_fraction: float
|
|
32
32
|
|
|
@@ -34,7 +34,7 @@ class ExperimentConfig(Summary):
|
|
|
34
34
|
return Experiment(self)
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
class Experiment
|
|
37
|
+
class Experiment:
|
|
38
38
|
"""Manages the full lifecycle of a deep learning experiment.
|
|
39
39
|
|
|
40
40
|
It handles data loading, model instantiation, training loops, and results visualization.
|
|
@@ -52,7 +52,7 @@ class Experiment(Summary):
|
|
|
52
52
|
self.title: str = config.title
|
|
53
53
|
self.base_model_config: ModelConfig = config.base_model
|
|
54
54
|
self.models: list[Model] = generate_models(config.base_model, config.variations)
|
|
55
|
-
self.data: Data = config.
|
|
55
|
+
self.data: Data = config.data_creator()
|
|
56
56
|
self.plot_dimension: int = config.plot_dimension
|
|
57
57
|
self.smooth_fraction: float = config.smooth_fraction
|
|
58
58
|
|
|
@@ -8,16 +8,15 @@ import numpy as np
|
|
|
8
8
|
|
|
9
9
|
from .layer import Layer
|
|
10
10
|
from .neural_network import FirstOrderNeuralNetwork
|
|
11
|
-
from ..abstract
|
|
12
|
-
from ..abstract.optimizer import Optimizer
|
|
11
|
+
from ..abstract import Loss, Optimizer, Summary
|
|
13
12
|
from ..types import Array
|
|
14
13
|
|
|
15
14
|
|
|
16
15
|
@dataclass(frozen=True)
|
|
17
|
-
class FirstOrderOptimizerConfig(ABC):
|
|
16
|
+
class FirstOrderOptimizerConfig(Summary, ABC):
|
|
18
17
|
@abstractmethod
|
|
19
18
|
def instantiate(self) -> FirstOrderOptimizer:
|
|
20
|
-
|
|
19
|
+
...
|
|
21
20
|
|
|
22
21
|
|
|
23
22
|
@dataclass(frozen=True)
|
|
@@ -42,7 +41,7 @@ class FirstOrderAdamConfig(FirstOrderSGDConfig):
|
|
|
42
41
|
class FirstOrderOptimizer(Optimizer):
|
|
43
42
|
@abstractmethod
|
|
44
43
|
def do_descent(self, neural_network, loss, X: Array, Y_true: Array) -> float:
|
|
45
|
-
|
|
44
|
+
...
|
|
46
45
|
|
|
47
46
|
|
|
48
47
|
class FirstOrderSGD(FirstOrderOptimizer):
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import json
|
|
2
1
|
from dataclasses import is_dataclass, asdict, replace
|
|
3
2
|
from typing import Any
|
|
4
3
|
|
|
@@ -34,13 +33,3 @@ def config_serializer(obj: Any):
|
|
|
34
33
|
return getattr(obj, "__name__", str(obj))
|
|
35
34
|
|
|
36
35
|
return str(obj)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
class Summary:
|
|
40
|
-
def summary(self) -> None:
|
|
41
|
-
summary = json.dumps(
|
|
42
|
-
self,
|
|
43
|
-
default=config_serializer,
|
|
44
|
-
indent=4
|
|
45
|
-
)
|
|
46
|
-
print(summary)
|
|
@@ -5,15 +5,15 @@ from dataclasses import dataclass
|
|
|
5
5
|
|
|
6
6
|
import numpy as np
|
|
7
7
|
|
|
8
|
-
from ..abstract
|
|
8
|
+
from ..abstract import PerturbationMatrix, Summary
|
|
9
9
|
from ..types import Array
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
@dataclass(frozen=True)
|
|
13
|
-
class GradientEstimatorConfig(ABC):
|
|
13
|
+
class GradientEstimatorConfig(Summary, ABC):
|
|
14
14
|
@abstractmethod
|
|
15
15
|
def instantiate(self, nb_params: int) -> GradientEstimator:
|
|
16
|
-
|
|
16
|
+
...
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
@dataclass(frozen=True)
|
|
@@ -7,16 +7,15 @@ import numpy as np
|
|
|
7
7
|
|
|
8
8
|
from .gradient_estimators import GradientEstimator
|
|
9
9
|
from .zeroth_order_blackbox import ZerothOrderBlackBox
|
|
10
|
-
from ..abstract
|
|
11
|
-
from ..abstract.optimizer import Optimizer
|
|
10
|
+
from ..abstract import Loss, Optimizer, Summary
|
|
12
11
|
from ..types import Array
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
@dataclass(frozen=True)
|
|
16
|
-
class ZerothOrderOptimizerConfig(ABC):
|
|
15
|
+
class ZerothOrderOptimizerConfig(Summary, ABC):
|
|
17
16
|
@abstractmethod
|
|
18
17
|
def instantiate(self, gradient_estimator: GradientEstimator) -> ZerothOrderOptimizer:
|
|
19
|
-
|
|
18
|
+
...
|
|
20
19
|
|
|
21
20
|
|
|
22
21
|
@dataclass(frozen=True)
|
|
@@ -42,16 +41,16 @@ class ZerothOrderAdamConfig(ZerothOrderSGDConfig):
|
|
|
42
41
|
class ZerothOrderOptimizer(Optimizer):
|
|
43
42
|
@abstractmethod
|
|
44
43
|
def do_descent(self, blackbox: ZerothOrderBlackBox, loss: Loss, X: Array, Y_true: Array) -> float:
|
|
45
|
-
|
|
44
|
+
...
|
|
46
45
|
|
|
47
46
|
@abstractmethod
|
|
48
47
|
def compute_gradient(self, blackbox: ZerothOrderBlackBox, loss: Loss, X: Array, Y_true: Array) -> tuple[
|
|
49
48
|
float, Array]:
|
|
50
|
-
|
|
49
|
+
...
|
|
51
50
|
|
|
52
51
|
@abstractmethod
|
|
53
52
|
def update_params(self, blackbox: ZerothOrderBlackBox, gradient: Array) -> None:
|
|
54
|
-
|
|
53
|
+
...
|
|
55
54
|
|
|
56
55
|
|
|
57
56
|
class ZerothOrderSGD(ZerothOrderOptimizer):
|
|
@@ -9,8 +9,8 @@ class ZerothOrderBlackBox(BlackBox):
|
|
|
9
9
|
|
|
10
10
|
@abstractmethod
|
|
11
11
|
def forward_perturbed(self, X: Array, gradient_estimator: GradientEstimator) -> Array:
|
|
12
|
-
|
|
12
|
+
...
|
|
13
13
|
|
|
14
14
|
@abstractmethod
|
|
15
15
|
def update_params(self, grad: Array, learning_rate: float) -> None:
|
|
16
|
-
|
|
16
|
+
...
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/zeroth_order/neural_network/neural_network.py
RENAMED
|
File without changes
|
{zeroth_learn-0.2.0 → zeroth_learn-0.2.1}/zeroth/zeroth_order/neural_network/parameter_manager.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|