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.
Files changed (50) hide show
  1. {zeroth_learn-0.2.4/zeroth_learn.egg-info → zeroth_learn-0.2.5}/PKG-INFO +1 -1
  2. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/pyproject.toml +1 -1
  3. zeroth_learn-0.2.5/zeroth/losses/binary_cross_entropy.py +38 -0
  4. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/utils/activation_functions.py +2 -3
  5. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/utils/metrics.py +1 -1
  6. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5/zeroth_learn.egg-info}/PKG-INFO +1 -1
  7. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth_learn.egg-info/SOURCES.txt +1 -0
  8. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/MANIFEST.in +0 -0
  9. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/README.md +0 -0
  10. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/setup.cfg +0 -0
  11. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/__init__.py +0 -0
  12. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/__init__.py +0 -0
  13. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/activation.py +0 -0
  14. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/blackbox.py +0 -0
  15. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/data_creator.py +0 -0
  16. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/loss.py +0 -0
  17. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/metric.py +0 -0
  18. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/model.py +0 -0
  19. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/neural_network.py +0 -0
  20. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/optimizer.py +0 -0
  21. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/perturbation_matrix.py +0 -0
  22. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/abstract/summary.py +0 -0
  23. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/all.py +0 -0
  24. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/data.py +0 -0
  25. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/experiment.py +0 -0
  26. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/first_order/__init__.py +0 -0
  27. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/first_order/layer.py +0 -0
  28. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/first_order/model.py +0 -0
  29. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/first_order/neural_network.py +0 -0
  30. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/first_order/optimizers.py +0 -0
  31. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/losses/__init__.py +0 -0
  32. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/losses/cross_entropy.py +0 -0
  33. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/losses/mse.py +0 -0
  34. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/paths.py +0 -0
  35. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/plot_losses.py +0 -0
  36. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/types.py +0 -0
  37. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/utils/__init__.py +0 -0
  38. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/utils/dataclasses_utils.py +0 -0
  39. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/utils/perturbation_matrices.py +0 -0
  40. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/__init__.py +0 -0
  41. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/gradient_estimators.py +0 -0
  42. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/model.py +0 -0
  43. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/neural_network/__init__.py +0 -0
  44. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/neural_network/neural_network.py +0 -0
  45. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/neural_network/parameter_manager.py +0 -0
  46. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/optimizers.py +0 -0
  47. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth/zeroth_order/zeroth_order_blackbox.py +0 -0
  48. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth_learn.egg-info/dependency_links.txt +0 -0
  49. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth_learn.egg-info/requires.txt +0 -0
  50. {zeroth_learn-0.2.4 → zeroth_learn-0.2.5}/zeroth_learn.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zeroth-learn
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Requires-Dist: numpy
5
5
  Requires-Dist: pandas
6
6
  Requires-Dist: matplotlib
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "zeroth-learn"
7
- version = "0.2.4"
7
+ version = "0.2.5"
8
8
  dependencies = [
9
9
  "numpy",
10
10
  "pandas",
@@ -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) # On réutilise le __call__ pour optimiser
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
- # Comme indiqué dans votre code original, pas besoin de dérivée si géré par CrossEntropy
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.sum(np.argmax(Y_pred, axis=1) == Y_true[:, 0]).item() / Y_true.shape[0]
11
+ return float(np.mean(np.argmax(Y_pred, axis=1) == Y_true[:, 0]))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zeroth-learn
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Requires-Dist: numpy
5
5
  Requires-Dist: pandas
6
6
  Requires-Dist: matplotlib
@@ -25,6 +25,7 @@ zeroth/first_order/model.py
25
25
  zeroth/first_order/neural_network.py
26
26
  zeroth/first_order/optimizers.py
27
27
  zeroth/losses/__init__.py
28
+ zeroth/losses/binary_cross_entropy.py
28
29
  zeroth/losses/cross_entropy.py
29
30
  zeroth/losses/mse.py
30
31
  zeroth/utils/__init__.py
File without changes
File without changes
File without changes
File without changes