From 7c2448f2da5d8c8ab1efb2397107571d871f9a95 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 23 Sep 2025 16:23:16 +0300 Subject: [PATCH 1/4] Initial version of local_maxima --- hands_on/local_maxima_part2/local_maxima.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/hands_on/local_maxima_part2/local_maxima.py b/hands_on/local_maxima_part2/local_maxima.py index db89ba3..723b640 100644 --- a/hands_on/local_maxima_part2/local_maxima.py +++ b/hands_on/local_maxima_part2/local_maxima.py @@ -7,4 +7,14 @@ def find_maxima(x): Output: idx -- list of indices of the local maxima in x """ - return [] + sol = [] + for idx, num in enumerate(x): + if idx == 0 and num > x[idx+1]: + sol.append(idx) + elif idx == len(x)-1 and num > x[idx-1]: + sol.append(idx) + else: + if x[idx-1] < num and num > x[idx+1]: + sol.append(idx) + + return sol -- 2.39.5 From c14f7b84d5c09703b5ea40859e78b2a8fbc370b1 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 23 Sep 2025 16:26:51 +0300 Subject: [PATCH 2/4] Allow equality of neighbors for maxima --- hands_on/local_maxima_part2/local_maxima.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hands_on/local_maxima_part2/local_maxima.py b/hands_on/local_maxima_part2/local_maxima.py index 723b640..1d3d46a 100644 --- a/hands_on/local_maxima_part2/local_maxima.py +++ b/hands_on/local_maxima_part2/local_maxima.py @@ -9,12 +9,12 @@ def find_maxima(x): """ sol = [] for idx, num in enumerate(x): - if idx == 0 and num > x[idx+1]: + if idx == 0 and num => x[idx+1]: sol.append(idx) - elif idx == len(x)-1 and num > x[idx-1]: + elif idx == len(x)-1 and num => x[idx-1]: sol.append(idx) else: - if x[idx-1] < num and num > x[idx+1]: + if x[idx-1] <= num and num => x[idx+1]: sol.append(idx) return sol -- 2.39.5 From 9c3284cb98d5394855943119c78a959cf716dda4 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 23 Sep 2025 16:57:34 +0300 Subject: [PATCH 3/4] test for the logistic function (generic cases) --- testing_project/test_logistic.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/testing_project/test_logistic.py b/testing_project/test_logistic.py index 100d824..750e963 100644 --- a/testing_project/test_logistic.py +++ b/testing_project/test_logistic.py @@ -13,12 +13,15 @@ def test_f_corner_cases(): result = f(x, r) assert_allclose(result, expected) -# Hands on 1 -#Add a new test for these generic cases using the for-loop pattern: -# x=0.1, r=2.2 => f(x, r)=0.198 -# x=0.2, r=3.4 => f(x, r)=0.544 -# x=0.5, r=2 => f(x, r)=0.5 - +def test_f_generic_cases(): + cases = [ + (0.1, 2.2, 0.198), + (0.2, 3.4, 0.544), + (0.5, 2, 0.5) + ] + for x, r, expected in cases: + result = f(x, r) + assert_allclose(result, expected) # Hands on 2: # parametrize the above test using @pytest.mark.parametrize -- 2.39.5 From 8ca3620a0b9f3f6323f6641bf57d09e78115d175 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 23 Sep 2025 16:58:06 +0300 Subject: [PATCH 4/4] code for logistic function --- testing_project/logistic.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testing_project/logistic.py b/testing_project/logistic.py index e49d1c2..1afaa23 100644 --- a/testing_project/logistic.py +++ b/testing_project/logistic.py @@ -1 +1,3 @@ -# Your code goes here + +def f(x, r): + return r * x * (1-x) -- 2.39.5