dragon-ml-toolbox 10.14.0__tar.gz → 10.15.0__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.
Potentially problematic release.
This version of dragon-ml-toolbox might be problematic. Click here for more details.
- {dragon_ml_toolbox-10.14.0/dragon_ml_toolbox.egg-info → dragon_ml_toolbox-10.15.0}/PKG-INFO +1 -1
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0/dragon_ml_toolbox.egg-info}/PKG-INFO +1 -1
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/ML_optimization.py +103 -3
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/pyproject.toml +1 -1
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/LICENSE +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/LICENSE-THIRD-PARTY.md +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/README.md +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/dragon_ml_toolbox.egg-info/SOURCES.txt +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/dragon_ml_toolbox.egg-info/dependency_links.txt +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/dragon_ml_toolbox.egg-info/requires.txt +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/dragon_ml_toolbox.egg-info/top_level.txt +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/ETL_cleaning.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/ETL_engineering.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/GUI_tools.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/MICE_imputation.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/ML_callbacks.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/ML_datasetmaster.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/ML_evaluation.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/ML_evaluation_multi.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/ML_inference.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/ML_models.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/ML_scaler.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/ML_trainer.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/PSO_optimization.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/RNN_forecast.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/SQL.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/VIF_factor.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/__init__.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/_logger.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/_script_info.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/custom_logger.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/data_exploration.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/ensemble_evaluation.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/ensemble_inference.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/ensemble_learning.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/handle_excel.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/keys.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/optimization_tools.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/path_manager.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/ml_tools/utilities.py +0 -0
- {dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/setup.cfg +0 -0
|
@@ -20,12 +20,112 @@ from .SQL import DatabaseManager
|
|
|
20
20
|
from .optimization_tools import _save_result
|
|
21
21
|
from .utilities import threshold_binary_values, save_dataframe
|
|
22
22
|
|
|
23
|
+
|
|
23
24
|
__all__ = [
|
|
25
|
+
"MLOptimizer",
|
|
24
26
|
"create_pytorch_problem",
|
|
25
27
|
"run_optimization"
|
|
26
28
|
]
|
|
27
29
|
|
|
28
30
|
|
|
31
|
+
class MLOptimizer:
|
|
32
|
+
"""
|
|
33
|
+
A wrapper class for setting up and running EvoTorch optimization tasks.
|
|
34
|
+
|
|
35
|
+
This class combines the functionality of `create_pytorch_problem` and
|
|
36
|
+
`run_optimization` functions into a single, streamlined workflow.
|
|
37
|
+
|
|
38
|
+
SNES and CEM algorithms do not accept bounds, the given bounds will be used as an initial starting point.
|
|
39
|
+
|
|
40
|
+
Example:
|
|
41
|
+
>>> # 1. Initialize the optimizer with model and search parameters
|
|
42
|
+
>>> optimizer = MLOptimizer(
|
|
43
|
+
... inference_handler=my_handler,
|
|
44
|
+
... bounds=(lower_bounds, upper_bounds),
|
|
45
|
+
... number_binary_features=2,
|
|
46
|
+
... task="max",
|
|
47
|
+
... algorithm="Genetic"
|
|
48
|
+
... )
|
|
49
|
+
>>> # 2. Run the optimization and save the results
|
|
50
|
+
>>> best_result = optimizer.run(
|
|
51
|
+
... num_generations=100,
|
|
52
|
+
... target_name="my_target",
|
|
53
|
+
... feature_names=my_feature_names,
|
|
54
|
+
... save_dir="/path/to/results",
|
|
55
|
+
... save_format="csv"
|
|
56
|
+
... )
|
|
57
|
+
"""
|
|
58
|
+
def __init__(self,
|
|
59
|
+
inference_handler: PyTorchInferenceHandler,
|
|
60
|
+
bounds: Tuple[List[float], List[float]],
|
|
61
|
+
number_binary_features: int,
|
|
62
|
+
task: Literal["min", "max"],
|
|
63
|
+
algorithm: Literal["SNES", "CEM", "Genetic"] = "Genetic",
|
|
64
|
+
population_size: int = 200,
|
|
65
|
+
**searcher_kwargs):
|
|
66
|
+
"""
|
|
67
|
+
Initializes the optimizer by creating the EvoTorch problem and searcher.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
inference_handler (PyTorchInferenceHandler): An initialized inference handler containing the model and weights.
|
|
71
|
+
bounds (tuple[list[float], list[float]]): A tuple containing the lower and upper bounds for the solution features.
|
|
72
|
+
number_binary_features (int): Number of binary features located at the END of the feature vector.
|
|
73
|
+
task (str): The optimization goal, either "min" or "max".
|
|
74
|
+
algorithm (str): The search algorithm to use ("SNES", "CEM", "Genetic").
|
|
75
|
+
population_size (int): Population size for CEM and GeneticAlgorithm.
|
|
76
|
+
**searcher_kwargs: Additional keyword arguments for the selected search algorithm's constructor.
|
|
77
|
+
"""
|
|
78
|
+
# Call the existing factory function to get the problem and searcher factory
|
|
79
|
+
self.problem, self.searcher_factory = create_pytorch_problem(
|
|
80
|
+
inference_handler=inference_handler,
|
|
81
|
+
bounds=bounds,
|
|
82
|
+
binary_features=number_binary_features,
|
|
83
|
+
task=task,
|
|
84
|
+
algorithm=algorithm,
|
|
85
|
+
population_size=population_size,
|
|
86
|
+
**searcher_kwargs
|
|
87
|
+
)
|
|
88
|
+
# Store binary_features count to pass it to the run function later
|
|
89
|
+
self._binary_features = number_binary_features
|
|
90
|
+
|
|
91
|
+
def run(self,
|
|
92
|
+
num_generations: int,
|
|
93
|
+
target_name: str,
|
|
94
|
+
save_dir: Union[str, Path],
|
|
95
|
+
feature_names: Optional[List[str]],
|
|
96
|
+
save_format: Literal['csv', 'sqlite', 'both'],
|
|
97
|
+
repetitions: int = 1,
|
|
98
|
+
verbose: bool = True) -> Optional[dict]:
|
|
99
|
+
"""
|
|
100
|
+
Runs the evolutionary optimization process using the pre-configured settings.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
num_generations (int): The total number of generations for each repetition.
|
|
104
|
+
target_name (str): Target name used for the CSV filename and/or SQL table.
|
|
105
|
+
save_dir (str | Path): The directory where result files will be saved.
|
|
106
|
+
feature_names (List[str] | None): Names of the solution features for labeling output. If None, generic names like 'feature_0', 'feature_1', ... , will be created.
|
|
107
|
+
save_format (Literal['csv', 'sqlite', 'both']): The format for saving results.
|
|
108
|
+
repetitions (int): The number of independent times to run the optimization.
|
|
109
|
+
verbose (bool): If True, enables detailed logging.
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
Optional[dict]: A dictionary with the best result if repetitions is 1, otherwise None.
|
|
113
|
+
"""
|
|
114
|
+
# Call the existing run function with the stored problem, searcher, and binary feature count
|
|
115
|
+
return run_optimization(
|
|
116
|
+
problem=self.problem,
|
|
117
|
+
searcher_factory=self.searcher_factory,
|
|
118
|
+
num_generations=num_generations,
|
|
119
|
+
target_name=target_name,
|
|
120
|
+
binary_features=self._binary_features,
|
|
121
|
+
save_dir=save_dir,
|
|
122
|
+
save_format=save_format,
|
|
123
|
+
feature_names=feature_names,
|
|
124
|
+
repetitions=repetitions,
|
|
125
|
+
verbose=verbose
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
|
|
29
129
|
def create_pytorch_problem(
|
|
30
130
|
inference_handler: PyTorchInferenceHandler,
|
|
31
131
|
bounds: Tuple[List[float], List[float]],
|
|
@@ -38,7 +138,7 @@ def create_pytorch_problem(
|
|
|
38
138
|
"""
|
|
39
139
|
Creates and configures an EvoTorch Problem and a Searcher factory class for a PyTorch model.
|
|
40
140
|
|
|
41
|
-
SNES and CEM do not accept bounds, the given bounds will be used as initial
|
|
141
|
+
SNES and CEM do not accept bounds, the given bounds will be used as an initial starting point.
|
|
42
142
|
|
|
43
143
|
The Genetic Algorithm works directly with the bounds, and operators such as SimulatedBinaryCrossOver and GaussianMutation.
|
|
44
144
|
|
|
@@ -62,8 +162,8 @@ def create_pytorch_problem(
|
|
|
62
162
|
|
|
63
163
|
# add binary bounds
|
|
64
164
|
if binary_features > 0:
|
|
65
|
-
lower_bounds.extend([0.
|
|
66
|
-
upper_bounds.extend([0.
|
|
165
|
+
lower_bounds.extend([0.48] * binary_features)
|
|
166
|
+
upper_bounds.extend([0.52] * binary_features)
|
|
67
167
|
|
|
68
168
|
solution_length = len(lower_bounds)
|
|
69
169
|
device = inference_handler.device
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/dragon_ml_toolbox.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/dragon_ml_toolbox.egg-info/requires.txt
RENAMED
|
File without changes
|
{dragon_ml_toolbox-10.14.0 → dragon_ml_toolbox-10.15.0}/dragon_ml_toolbox.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|