-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsoft_thresholding.py
More file actions
35 lines (27 loc) · 1.11 KB
/
Copy pathsoft_thresholding.py
File metadata and controls
35 lines (27 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import numpy as np
import numpy.random as npr
# The maximum number of candidates to select
max_candidates = 3
# The sorted list
sorted_list = sorted(npr.random_integers(1, 100, size=25))
print("Sorted list of candidates:", sorted_list)
while len(sorted_list) > 1:
# Output remaining candidates
print("Remaining candidates:", len(sorted_list))
# Calculate the mean, median and standard deviation of the list
mean = np.mean(sorted_list)
median = np.median(sorted_list)
std = np.std(sorted_list)
# If the standard deviation is zero the list values are identical
if std == 0:
sorted_list = sorted_list[:max_candidates]
break
# Stop iterating if the exit conditions for the distribution are met
if (abs(mean - median) < 0.1 * max(mean, median)) & (std < 0.5 * mean):
if len(sorted_list) <= max_candidates:
break
# Remove any values less or equal to the minimum of the mean and median
sorted_list = [_ for _ in sorted_list if _ <= min(mean, median)]
# Results after soft threshold iterations
print("=" * 24)
print("Selected candidates:", sorted_list)