From 75af498b92966d221d4a08a2c2c7de46de08aae9 Mon Sep 17 00:00:00 2001 From: sayanchakraborty Date: Wed, 31 Jan 2024 00:14:25 -0800 Subject: [PATCH] fixed MR comments --- .../optimization/hyperparameter_optimization.py | 4 ++-- luminaire/utils/__init__.py | 2 +- .../{validation.py => random_state_validation.py} | 15 ++++++++------- 3 files changed, 11 insertions(+), 10 deletions(-) rename luminaire/utils/{validation.py => random_state_validation.py} (53%) diff --git a/luminaire/optimization/hyperparameter_optimization.py b/luminaire/optimization/hyperparameter_optimization.py index fbb565e..55c3f34 100644 --- a/luminaire/optimization/hyperparameter_optimization.py +++ b/luminaire/optimization/hyperparameter_optimization.py @@ -1,11 +1,10 @@ from hyperopt import fmin, tpe, hp, STATUS_OK from luminaire.model import LADStructuralModel, LADStructuralHyperParams, LADFilteringModel, LADFilteringHyperParams from luminaire.exploration.data_exploration import DataExploration +from luminaire.utils.random_state_validation import check_random_state import warnings warnings.filterwarnings('ignore') -from ..utils import check_random_state - class HyperparameterOptimization(object): """ Hyperparameter optimization for LAD outlier detection configuration for batch data. @@ -21,6 +20,7 @@ class HyperparameterOptimization(object): :param int min_ts_length: The minimum required length of the time series for training. The input time series will be truncated if the length is greater than this value. :param int scoring_length: Number of innovations to be scored after training window with respect to the frequency. + :param int random_state: Turn seed into a np.random.RandomState instance .. _Pandas offset: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#dateoffset-objects """ diff --git a/luminaire/utils/__init__.py b/luminaire/utils/__init__.py index 5f4bc10..9f27902 100644 --- a/luminaire/utils/__init__.py +++ b/luminaire/utils/__init__.py @@ -1 +1 @@ -from .validation import check_random_state \ No newline at end of file +from .random_state_validation import check_random_state \ No newline at end of file diff --git a/luminaire/utils/validation.py b/luminaire/utils/random_state_validation.py similarity index 53% rename from luminaire/utils/validation.py rename to luminaire/utils/random_state_validation.py index e3610ee..928c9dd 100644 --- a/luminaire/utils/validation.py +++ b/luminaire/utils/random_state_validation.py @@ -3,13 +3,14 @@ def check_random_state(seed): """Turn seed into a np.random.RandomState instance - Parameters - ---------- - seed : None, int or instance of RandomState - If seed is None, return the RandomState singleton used by np.random. - If seed is an int, return a new RandomState instance seeded with seed. - If seed is already a RandomState instance, return it. - Otherwise raise ValueError. + + :param int seed: seed for the random state + :return: None, int or instance of RandomState + If seed is None, return the RandomState singleton used by np.random. + If seed is an int, return a new RandomState instance seeded with seed. + If seed is already a RandomState instance, return it. + Otherwise raise ValueError. + :rtype: np.random.RandomState or None """ if seed is None or seed is np.random: return np.random.mtrand._rand