zeroth-learn 0.2.4__tar.gz → 0.2.5__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.4/zeroth_learn.egg-info → zeroth_learn-0.2.5}/PKG-INFO +1 -1
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/pyproject.toml +1 -1
- zeroth_learn-0.2.5/zeroth/losses/binary_cross_entropy.py +38 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/utils/activation_functions.py +2 -3
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/utils/metrics.py +1 -1
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5/zeroth_learn.egg-info}/PKG-INFO +1 -1
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth_learn.egg-info/SOURCES.txt +1 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/MANIFEST.in +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/README.md +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/setup.cfg +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/__init__.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/__init__.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/activation.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/blackbox.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/data_creator.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/loss.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/metric.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/model.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/neural_network.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/optimizer.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/perturbation_matrix.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/summary.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/all.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/data.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/experiment.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/first_order/__init__.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/first_order/layer.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/first_order/model.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/first_order/neural_network.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/first_order/optimizers.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/losses/__init__.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/losses/cross_entropy.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/losses/mse.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/paths.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/plot_losses.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/types.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/utils/__init__.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/utils/dataclasses_utils.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/utils/perturbation_matrices.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/__init__.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/gradient_estimators.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/model.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/neural_network/__init__.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/neural_network/neural_network.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/neural_network/parameter_manager.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/optimizers.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/zeroth_order_blackbox.py +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth_learn.egg-info/dependency_links.txt +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth_learn.egg-info/requires.txt +0 -0
- {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth_learn.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
from ..abstract.loss import Loss
|
|
4
|
+
from ..first_order.layer import Layer
|
|
5
|
+
from ..types import Array
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BinaryCrossEntropy(Loss):
|
|
9
|
+
@staticmethod
|
|
10
|
+
def compute_loss(Y_pred: Array, Y_true: Array) -> float:
|
|
11
|
+
Y_true = Y_true.reshape(Y_pred.shape)
|
|
12
|
+
loss = - (Y_true * np.log(Y_pred + 1e-15) + (1 - Y_true) * np.log(1 - Y_pred + 1e-15))
|
|
13
|
+
return float(np.mean(loss))
|
|
14
|
+
|
|
15
|
+
@staticmethod
|
|
16
|
+
def compute_batch_losses(Y_pred: Array, Y_true: Array) -> Array:
|
|
17
|
+
Y_true = Y_true.reshape(Y_pred.shape)
|
|
18
|
+
loss = -(Y_true * np.log(Y_pred + 1e-15) + (1 - Y_true) * np.log(1 - Y_pred + 1e-15))
|
|
19
|
+
return np.mean(loss, axis=1)
|
|
20
|
+
|
|
21
|
+
@staticmethod
|
|
22
|
+
def compute_perturbed_losses(pY_pred: Array, Y_true: Array) -> Array:
|
|
23
|
+
Y_true = Y_true.reshape(1, pY_pred.shape[1], -1)
|
|
24
|
+
loss = -(Y_true * np.log(pY_pred + 1e-15) + (1 - Y_true) * np.log(1 - pY_pred + 1e-15))
|
|
25
|
+
return np.mean(loss, axis=2)
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def compute_gradient_wrt_preactivation(last_layer: Layer, Y_pred: Array, Y_true: Array) -> Array:
|
|
29
|
+
Y_true = Y_true.reshape(Y_pred.shape)
|
|
30
|
+
return Y_pred - Y_true
|
|
31
|
+
|
|
32
|
+
def compute_losses_for_zeroth_order(self, pY_pred: Array, Y_true: Array) -> tuple[float, Array]:
|
|
33
|
+
avg_loss = self.compute_loss(pY_pred[0], Y_true)
|
|
34
|
+
p_loss = self.compute_perturbed_losses(pY_pred, Y_true)
|
|
35
|
+
return avg_loss, p_loss
|
|
36
|
+
|
|
37
|
+
def compute_losses_for_first_order(self, last_layer: Layer, Y_pred: Array, Y_true: Array) -> tuple[float, Array]:
|
|
38
|
+
return self.compute_loss(Y_pred, Y_true), self.compute_gradient_wrt_preactivation(last_layer, Y_pred, Y_true)
|
|
@@ -17,7 +17,7 @@ class Sigmoid(Activation):
|
|
|
17
17
|
return 1 / (1 + np.exp(-x))
|
|
18
18
|
|
|
19
19
|
def derivative(self, x: float | Array) -> float | Array:
|
|
20
|
-
s = self.__call__(x)
|
|
20
|
+
s = self.__call__(x)
|
|
21
21
|
return s * (1 - s)
|
|
22
22
|
|
|
23
23
|
|
|
@@ -42,5 +42,4 @@ class Softmax(Activation):
|
|
|
42
42
|
return e / np.sum(e, axis=-1, keepdims=True)
|
|
43
43
|
|
|
44
44
|
def derivative(self, x: float | Array) -> float | Array:
|
|
45
|
-
|
|
46
|
-
raise NotImplementedError("La dérivée de Softmax est généralement combinée avec CrossEntropy.")
|
|
45
|
+
raise NotImplementedError("no need for derivative when using CrossEntropy loss")
|
|
@@ -8,4 +8,4 @@ from ..types import Array
|
|
|
8
8
|
|
|
9
9
|
class Accuracy(Metric):
|
|
10
10
|
def __call__(self: Self, Y_pred: Array, Y_true: Array) -> float:
|
|
11
|
-
return np.
|
|
11
|
+
return float(np.mean(np.argmax(Y_pred, axis=1) == Y_true[:, 0]))
|
|
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
|
|
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.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/neural_network/neural_network.py
RENAMED
|
File without changes
|
{zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/neural_network/parameter_manager.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|