Skip to content

Commit 770d4f0

Browse files
committed
Fix some more numpy tests
1 parent d3ee053 commit 770d4f0

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

Diff for: fractals/julia_sets.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def eval_exponential(c_parameter: complex, z_values: np.ndarray) -> np.ndarray:
4242
Evaluate $e^z + c$.
4343
>>> float(eval_exponential(0, 0))
4444
1.0
45-
>>> abs(eval_exponential(1, np.pi*1.j)) < 1e-15
45+
>>> bool(abs(eval_exponential(1, np.pi*1.j)) < 1e-15)
4646
True
47-
>>> abs(eval_exponential(1.j, 0)-1-1.j) < 1e-15
47+
>>> bool(abs(eval_exponential(1.j, 0)-1-1.j) < 1e-15)
4848
True
4949
"""
5050
return np.exp(z_values) + c_parameter

Diff for: machine_learning/loss_functions.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def binary_focal_cross_entropy(
6868
6969
>>> true_labels = np.array([0, 1, 1, 0, 1])
7070
>>> predicted_probs = np.array([0.2, 0.7, 0.9, 0.3, 0.8])
71-
>>> binary_focal_cross_entropy(true_labels, predicted_probs)
71+
>>> float(binary_focal_cross_entropy(true_labels, predicted_probs))
7272
0.008257977659239775
7373
>>> true_labels = np.array([0, 1, 1, 0, 1])
7474
>>> predicted_probs = np.array([0.3, 0.8, 0.9, 0.2])
@@ -108,7 +108,7 @@ def categorical_cross_entropy(
108108
109109
>>> true_labels = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
110110
>>> pred_probs = np.array([[0.9, 0.1, 0.0], [0.2, 0.7, 0.1], [0.0, 0.1, 0.9]])
111-
>>> categorical_cross_entropy(true_labels, pred_probs)
111+
>>> float(categorical_cross_entropy(true_labels, pred_probs))
112112
0.567395975254385
113113
>>> true_labels = np.array([[1, 0], [0, 1]])
114114
>>> pred_probs = np.array([[0.9, 0.1, 0.0], [0.2, 0.7, 0.1]])
@@ -179,13 +179,13 @@ def categorical_focal_cross_entropy(
179179
>>> true_labels = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
180180
>>> pred_probs = np.array([[0.9, 0.1, 0.0], [0.2, 0.7, 0.1], [0.0, 0.1, 0.9]])
181181
>>> alpha = np.array([0.6, 0.2, 0.7])
182-
>>> categorical_focal_cross_entropy(true_labels, pred_probs, alpha)
182+
>>> float(categorical_focal_cross_entropy(true_labels, pred_probs, alpha))
183183
0.0025966118981496423
184184
185185
>>> true_labels = np.array([[0, 1, 0], [0, 0, 1]])
186186
>>> pred_probs = np.array([[0.05, 0.95, 0], [0.1, 0.8, 0.1]])
187187
>>> alpha = np.array([0.25, 0.25, 0.25])
188-
>>> categorical_focal_cross_entropy(true_labels, pred_probs, alpha)
188+
>>> float(categorical_focal_cross_entropy(true_labels, pred_probs, alpha))
189189
0.23315276982014324
190190
191191
>>> true_labels = np.array([[1, 0], [0, 1]])
@@ -265,7 +265,7 @@ def hinge_loss(y_true: np.ndarray, y_pred: np.ndarray) -> float:
265265
266266
>>> true_labels = np.array([-1, 1, 1, -1, 1])
267267
>>> pred = np.array([-4, -0.3, 0.7, 5, 10])
268-
>>> hinge_loss(true_labels, pred)
268+
>>> float(hinge_loss(true_labels, pred))
269269
1.52
270270
>>> true_labels = np.array([-1, 1, 1, -1, 1, 1])
271271
>>> pred = np.array([-4, -0.3, 0.7, 5, 10])
@@ -309,11 +309,11 @@ def huber_loss(y_true: np.ndarray, y_pred: np.ndarray, delta: float) -> float:
309309
310310
>>> true_values = np.array([0.9, 10.0, 2.0, 1.0, 5.2])
311311
>>> predicted_values = np.array([0.8, 2.1, 2.9, 4.2, 5.2])
312-
>>> np.isclose(huber_loss(true_values, predicted_values, 1.0), 2.102)
312+
>>> bool(np.isclose(huber_loss(true_values, predicted_values, 1.0), 2.102))
313313
True
314314
>>> true_labels = np.array([11.0, 21.0, 3.32, 4.0, 5.0])
315315
>>> predicted_probs = np.array([8.3, 20.8, 2.9, 11.2, 5.0])
316-
>>> np.isclose(huber_loss(true_labels, predicted_probs, 1.0), 1.80164)
316+
>>> bool(np.isclose(huber_loss(true_labels, predicted_probs, 1.0), 1.80164))
317317
True
318318
>>> true_labels = np.array([11.0, 21.0, 3.32, 4.0])
319319
>>> predicted_probs = np.array([8.3, 20.8, 2.9, 11.2, 5.0])
@@ -347,7 +347,7 @@ def mean_squared_error(y_true: np.ndarray, y_pred: np.ndarray) -> float:
347347
348348
>>> true_values = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
349349
>>> predicted_values = np.array([0.8, 2.1, 2.9, 4.2, 5.2])
350-
>>> np.isclose(mean_squared_error(true_values, predicted_values), 0.028)
350+
>>> bool(np.isclose(mean_squared_error(true_values, predicted_values), 0.028))
351351
True
352352
>>> true_labels = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
353353
>>> predicted_probs = np.array([0.3, 0.8, 0.9, 0.2])
@@ -381,11 +381,11 @@ def mean_absolute_error(y_true: np.ndarray, y_pred: np.ndarray) -> float:
381381
382382
>>> true_values = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
383383
>>> predicted_values = np.array([0.8, 2.1, 2.9, 4.2, 5.2])
384-
>>> np.isclose(mean_absolute_error(true_values, predicted_values), 0.16)
384+
>>> bool(np.isclose(mean_absolute_error(true_values, predicted_values), 0.16))
385385
True
386386
>>> true_values = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
387387
>>> predicted_values = np.array([0.8, 2.1, 2.9, 4.2, 5.2])
388-
>>> np.isclose(mean_absolute_error(true_values, predicted_values), 2.16)
388+
>>> bool(np.isclose(mean_absolute_error(true_values, predicted_values), 2.16))
389389
False
390390
>>> true_labels = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
391391
>>> predicted_probs = np.array([0.3, 0.8, 0.9, 5.2])
@@ -600,17 +600,17 @@ def smooth_l1_loss(y_true: np.ndarray, y_pred: np.ndarray, beta: float = 1.0) ->
600600
601601
>>> y_true = np.array([3, 5, 2, 7])
602602
>>> y_pred = np.array([2.9, 4.8, 2.1, 7.2])
603-
>>> smooth_l1_loss(y_true, y_pred, 1.0)
603+
>>> float(smooth_l1_loss(y_true, y_pred, 1.0))
604604
0.012500000000000022
605605
606606
>>> y_true = np.array([2, 4, 6])
607607
>>> y_pred = np.array([1, 5, 7])
608-
>>> smooth_l1_loss(y_true, y_pred, 1.0)
608+
>>> float(smooth_l1_loss(y_true, y_pred, 1.0))
609609
0.5
610610
611611
>>> y_true = np.array([1, 3, 5, 7])
612612
>>> y_pred = np.array([1, 3, 5, 7])
613-
>>> smooth_l1_loss(y_true, y_pred, 1.0)
613+
>>> float(smooth_l1_loss(y_true, y_pred, 1.0))
614614
0.0
615615
616616
>>> y_true = np.array([1, 3, 5])
@@ -647,7 +647,7 @@ def kullback_leibler_divergence(y_true: np.ndarray, y_pred: np.ndarray) -> float
647647
648648
>>> true_labels = np.array([0.2, 0.3, 0.5])
649649
>>> predicted_probs = np.array([0.3, 0.3, 0.4])
650-
>>> kullback_leibler_divergence(true_labels, predicted_probs)
650+
>>> float(kullback_leibler_divergence(true_labels, predicted_probs))
651651
0.030478754035472025
652652
>>> true_labels = np.array([0.2, 0.3, 0.5])
653653
>>> predicted_probs = np.array([0.3, 0.3, 0.4, 0.5])

0 commit comments

Comments
 (0)