Skip to content

Commit 7f5a17e

Browse files
committed
some more cleaning
1 parent 3db87e5 commit 7f5a17e

35 files changed

Lines changed: 155 additions & 92 deletions

mlscorecheck/aggregated/_check_aggregated_scores.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323

2424

2525
def check_aggregated_scores(
26-
*,
2726
experiment: dict,
2827
scores: dict,
29-
eps,
28+
eps: float | dict,
29+
*,
3030
solver_name: str | None = None,
3131
timeout: int | None = None,
3232
verbosity: int = 1,

mlscorecheck/aggregated/_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(
5656
else:
5757
self.identifier = identifier
5858

59-
def resolve_pn(self):
59+
def resolve_pn(self) -> None:
6060
"""
6161
Resolves the ``p`` and ``n`` values from the name of the dataset
6262
"""

mlscorecheck/aggregated/_evaluation.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ def to_dict(self) -> dict:
7070
"aggregation": self.aggregation,
7171
}
7272

73-
def sample_figures(self, random_state=None, score_subset: list | None = None):
73+
def sample_figures(
74+
self,
75+
random_state=None,
76+
score_subset: list | None = None
77+
) -> "Evaluation":
7478
"""
7579
Samples the figures in the evaluation
7680
@@ -156,7 +160,7 @@ def init_lp(self, lp_problem: pl.LpProblem, scores: dict | None = None) -> pl.Lp
156160

157161
return lp_problem
158162

159-
def populate(self, lp_problem: pl.LpProblem):
163+
def populate(self, lp_problem: pl.LpProblem) -> "Evaluation":
160164
"""
161165
Populates the evaluation with the figures in the solved linear programming problem
162166

mlscorecheck/aggregated/_experiment.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ def to_dict(self) -> dict:
6161
"aggregation": self.aggregation,
6262
}
6363

64-
def sample_figures(self, random_state=None, score_subset: list | None = None):
64+
def sample_figures(
65+
self,
66+
random_state=None,
67+
score_subset: list | None = None
68+
) -> "Experiment":
6569
"""
6670
Samples the ``tp`` and ``tn`` figures
6771
@@ -162,7 +166,7 @@ def init_lp(self, lp_problem: pl.LpProblem, scores: dict | None = None) -> pl.Lp
162166

163167
return lp_problem
164168

165-
def populate(self, lp_problem):
169+
def populate(self, lp_problem) -> "Experiment":
166170
"""
167171
Populates the evaluation with the figures in the solved linear programming problem
168172

mlscorecheck/aggregated/_fold.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def to_dict(self) -> dict:
5454
"""
5555
return {"p": self.p, "n": self.n, "identifier": self.identifier}
5656

57-
def sample_figures(self, random_state=None):
57+
def sample_figures(self, random_state=None) -> "Fold":
5858
"""
5959
Samples the ``tp`` and ``tn`` figures
6060
@@ -119,7 +119,7 @@ def set_initial_values(self, scores):
119119
self.tp.setInitialValue(int(tp_init))
120120
self.tn.setInitialValue(int(tn_init))
121121

122-
def init_lp(self, scores: dict | None = None):
122+
def init_lp(self, scores: dict | None = None) -> pl.LpProblem:
123123
"""
124124
Initialize a linear programming problem by creating the variables for the fold
125125

mlscorecheck/aggregated/_fold_enumeration.py

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import copy
66
import itertools
7+
from typing import Generator
78

89
import numpy as np
910

@@ -26,7 +27,7 @@
2627
]
2728

2829

29-
def integer_partitioning_generator(n: int, m: int): # pylint: disable=invalid-name
30+
def integer_partitioning_generator(n: int, m: int) -> Generator[list, None, None]: # pylint: disable=invalid-name
3031
"""
3132
Integer partitioning generator
3233
@@ -75,7 +76,7 @@ def integer_partitioning_generator(n: int, m: int): # pylint: disable=invalid-n
7576
x[m] = n - s[m - 1]
7677

7778

78-
def all_integer_partitioning_generator(n, k, non_zero, max_count): # pylint: disable=invalid-name
79+
def all_integer_partitioning_generator(n: int, k: int, non_zero: bool, max_count: int) -> Generator[list, None, None]: # pylint: disable=invalid-name
7980
"""
8081
Generate all integer partitioning of n to k parts (including 0 parts)
8182
@@ -99,7 +100,7 @@ def all_integer_partitioning_generator(n, k, non_zero, max_count): # pylint: di
99100
yield [0] * (k - m) + positives
100101

101102

102-
def not_enough_diverse_folds(p_values, n_values):
103+
def not_enough_diverse_folds(p_values: list, n_values: list) -> bool:
103104
"""
104105
Checks if there are enough folds with positive and negative samples
105106
@@ -117,8 +118,15 @@ def not_enough_diverse_folds(p_values, n_values):
117118

118119

119120
def determine_min_max_p(
120-
*, p, n, k_a, k_b, c_a, p_non_zero, n_non_zero
121-
): # pylint: disable=too-many-locals
121+
*,
122+
p: int,
123+
n: int,
124+
k_a: int,
125+
k_b: int,
126+
c_a: int,
127+
p_non_zero: int,
128+
n_non_zero: int
129+
) -> tuple[int, int]:
122130
"""
123131
Determines the minimum and maximum number of positives that can appear in folds
124132
of type A
@@ -146,8 +154,14 @@ def determine_min_max_p(
146154

147155

148156
def fold_partitioning_generator(
149-
*, p, n, k, p_non_zero=True, n_non_zero=True, p_min=-1
150-
): # pylint: disable=invalid-name,too-many-locals
157+
*,
158+
p: int,
159+
n: int,
160+
k: int,
161+
p_non_zero: bool = True,
162+
n_non_zero: bool = True,
163+
p_min: int = -1
164+
) -> Generator[tuple[list, list], None, None]:
151165
"""
152166
Generates the fold partitioning
153167
@@ -240,7 +254,11 @@ def _check_specification_and_determine_p_n(dataset: dict, folding: dict) -> tupl
240254
return p, n
241255

242256

243-
def kfolds_generator(evaluation: dict, available_scores: list, repeat_idx=0):
257+
def kfolds_generator(
258+
evaluation: dict,
259+
available_scores: list,
260+
repeat_idx: int = 0
261+
) -> Generator[list[dict], None, None]:
244262
"""
245263
Generates the fold configurations
246264
@@ -299,7 +317,10 @@ def kfolds_generator(evaluation: dict, available_scores: list, repeat_idx=0):
299317
]
300318

301319

302-
def repeated_kfolds_generator(evaluation: dict, available_scores: list):
320+
def repeated_kfolds_generator(
321+
evaluation: dict,
322+
available_scores: list
323+
) -> Generator[dict, None, None]:
303324
"""
304325
Generates the evaluation variations
305326
@@ -334,7 +355,10 @@ def repeated_kfolds_generator(evaluation: dict, available_scores: list):
334355
}
335356

336357

337-
def experiment_kfolds_generator(experiment: dict, available_scores: list):
358+
def experiment_kfolds_generator(
359+
experiment: dict,
360+
available_scores: list
361+
) -> Generator[dict, None, None]:
338362
"""
339363
Generates the experiment variations
340364
@@ -360,7 +384,11 @@ def experiment_kfolds_generator(experiment: dict, available_scores: list):
360384
}
361385

362386

363-
def multiclass_fold_partitioning_generator_22(n0: int, n1: int, c0: int):
387+
def multiclass_fold_partitioning_generator_22(
388+
n0: int,
389+
n1: int,
390+
c0: int
391+
) -> Generator[dict, None, None]:
364392
"""
365393
Generates the configurations for two folds of cardinalities n0 and n1 and two
366394
classes of cardinalities c0 and n0 + n1 - c0

mlscorecheck/aggregated/_generate_problems.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828

2929

3030
def generate_dataset(
31-
max_p: int = 500, max_n: int = 500, random_state=None, no_name: bool = False
31+
max_p: int = 100,
32+
max_n: int = 100,
33+
*,
34+
random_state=None,
3235
) -> dict:
3336
"""
3437
Generate a random dataset specification

mlscorecheck/aggregated/_linear_programming.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Some general purpose linear programming functionalities
33
"""
44

5+
from typing import Any
56
import numpy as np
67
import pulp as pl
78

@@ -54,7 +55,7 @@ def add_bounds(lp_problem: pl.LpProblem, variables: dict, bounds: dict, label: s
5455
return lp_problem
5556

5657

57-
def create_lp_target(obj, scores: dict, eps, lp_problem: pl.LpProblem) -> pl.LpProblem:
58+
def create_lp_target(obj: Any, scores: dict, eps: float | dict, lp_problem: pl.LpProblem) -> pl.LpProblem:
5859
"""
5960
Add the target and the score conditions to the linear programming problem
6061
@@ -78,7 +79,7 @@ def create_lp_target(obj, scores: dict, eps, lp_problem: pl.LpProblem) -> pl.LpP
7879
return lp_problem
7980

8081

81-
def solve(obj, scores: dict, eps, solver=None) -> pl.LpProblem:
82+
def solve(obj: Any, scores: dict, eps: float | dict, solver: Any = None) -> pl.LpProblem:
8283
"""
8384
Solving a problem.
8485

mlscorecheck/aggregated/_utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
aggregated_scores = ["acc", "sens", "spec", "bacc"]
1313

1414

15-
def random_identifier(length: int):
15+
def random_identifier(length: int) -> str:
1616
"""
1717
Generating a random identifier
1818
@@ -55,8 +55,12 @@ def check_bounds(scores: dict, bounds: dict | None = None, tolerance: float = 1e
5555

5656

5757
def compare_scores(
58-
scores0: dict, scores1: dict, eps, subset: list | None = None, tolerance: float = 1e-5
59-
):
58+
scores0: dict,
59+
scores1: dict,
60+
eps: float | dict,
61+
subset: list | None = None,
62+
tolerance: float = 1e-5
63+
) -> bool:
6064
"""
6165
Compares two sets of scores
6266

mlscorecheck/check/binary/_check_1_dataset_kfold_som.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
"""
2-
This module implements the top level check function for
2+
This modudef check_1_dataset_kfold_som(
3+
dataset: dict,
4+
folding: dict,
5+
scores: dict,
6+
eps: float,
7+
*,
8+
numerical_tolerance: float = NUMERICAL_TOLERANCE,
9+
prefilter_by_pairs: bool = True,
10+
) -> dict:ents the top level check function for
311
scores calculated by the score-of-means aggregation
412
in a kfold scenario on one single dataset.
513
"""

0 commit comments

Comments
 (0)