| freqai.feature_parameters.label_knn_p_order | `None` | float | p-order for KNN Minkowski metric distance. (optional) |
| freqai.feature_parameters.label_knn_n_neighbors | 5 | int >= 1 | Number of neighbors for KNN. |
| _Predictions extrema_ | | | |
-| freqai.predictions_extrema.selection_method | `rank` | enum {`values`,`rank`,`partition`} | Extrema selection method. `values` uses reversal values, `rank` uses ranked extrema values, `partition` uses sign-based partitioning. |
-| freqai.predictions_extrema.thresholds_smoothing | `mean` | enum {`mean`,`median`,`isodata`,`li`,`minimum`,`otsu`,`triangle`,`yen`,`soft_extremum`} | Thresholding method for prediction thresholds smoothing. |
+| freqai.predictions_extrema.selection_method | `rank` | enum {`rank`,`values`,`partition`} | Extrema selection method. `values` uses reversal values, `rank` uses ranked extrema values, `partition` uses sign-based partitioning. |
+| freqai.predictions_extrema.thresholds_smoothing | `mean` | enum {`mean`,`isodata`,`li`,`minimum`,`otsu`,`triangle`,`yen`,`median`,`soft_extremum`} | Thresholding method for prediction thresholds smoothing. |
| freqai.predictions_extrema.thresholds_alpha | 12.0 | float > 0 | Alpha for `soft_extremum`. |
| freqai.predictions_extrema.threshold_outlier | 0.999 | float (0,1) | Quantile threshold for predictions outlier filtering. |
| _Optuna / HPO_ | | | |
]
TransformFunction = Literal["tanh", "softsign", "arctan", "sigmoid", "asinh", "clip"]
ExitAttenuationMode = Literal["legacy", "sqrt", "linear", "power", "half_life"]
-ActivationFunction = Literal["tanh", "relu", "elu", "leaky_relu"]
+ActivationFunction = Literal["relu", "tanh", "elu", "leaky_relu"]
OptimizerClassOptuna = Literal["adamw", "rmsprop"]
OptimizerClass = Union[OptimizerClassOptuna, Literal["adam"]]
NetArchSize = Literal["small", "medium", "large", "extra_large"]
"half_life",
)
_ACTIVATION_FUNCTIONS: Final[tuple[ActivationFunction, ...]] = (
- "tanh",
"relu",
+ "tanh",
"elu",
"leaky_relu",
)
model_params["policy_kwargs"]["activation_fn"] = get_activation_fn(
model_params.get("policy_kwargs", {}).get(
- "activation_fn", ReforceXY._ACTIVATION_FUNCTIONS[1]
+ "activation_fn", ReforceXY._ACTIVATION_FUNCTIONS[0]
) # "relu"
)
model_params["policy_kwargs"]["optimizer_class"] = get_optimizer_class(
Get activation function
"""
return {
- ReforceXY._ACTIVATION_FUNCTIONS[0]: th.nn.Tanh, # "tanh"
- ReforceXY._ACTIVATION_FUNCTIONS[1]: th.nn.ReLU, # "relu"
+ ReforceXY._ACTIVATION_FUNCTIONS[0]: th.nn.ReLU, # "relu"
+ ReforceXY._ACTIVATION_FUNCTIONS[1]: th.nn.Tanh, # "tanh"
ReforceXY._ACTIVATION_FUNCTIONS[2]: th.nn.ELU, # "elu"
ReforceXY._ACTIVATION_FUNCTIONS[3]: th.nn.LeakyReLU, # "leaky_relu"
}.get(activation_fn_name, th.nn.ReLU)
zigzag,
)
-ExtremaSelectionMethod = Literal["values", "rank", "partition"]
+ExtremaSelectionMethod = Literal["rank", "values", "partition"]
OptunaNamespace = Literal["hp", "train", "label"]
CustomThresholdMethod = Literal["median", "soft_extremum"]
SkimageThresholdMethod = Literal[
- "isodata", "li", "mean", "minimum", "otsu", "triangle", "yen"
+ "mean", "isodata", "li", "minimum", "otsu", "triangle", "yen"
]
-ThresholdMethod = Union[CustomThresholdMethod, SkimageThresholdMethod]
+ThresholdMethod = Union[SkimageThresholdMethod, CustomThresholdMethod]
debug = False
_SQRT_2: Final[float] = np.sqrt(2.0)
_EXTREMA_SELECTION_METHODS: Final[tuple[ExtremaSelectionMethod, ...]] = (
- "values",
"rank",
+ "values",
"partition",
)
_CUSTOM_THRESHOLD_METHODS: Final[tuple[CustomThresholdMethod, ...]] = (
"soft_extremum",
)
_SKIMAGE_THRESHOLD_METHODS: Final[tuple[SkimageThresholdMethod, ...]] = (
+ "mean",
"isodata",
"li",
- "mean",
"minimum",
"otsu",
"triangle",
"yen",
)
_THRESHOLD_METHODS: Final[tuple[ThresholdMethod, ...]] = (
- *_CUSTOM_THRESHOLD_METHODS,
*_SKIMAGE_THRESHOLD_METHODS,
+ *_CUSTOM_THRESHOLD_METHODS,
)
- _OPTUNA_STORAGE_BACKENDS: Final[tuple[str, ...]] = ("sqlite", "file")
+ _OPTUNA_STORAGE_BACKENDS: Final[tuple[str, ...]] = ("file", "sqlite")
_OPTUNA_SAMPLERS: Final[tuple[str, ...]] = ("tpe", "auto")
_OPTUNA_NAMESPACES: Final[tuple[OptunaNamespace, ...]] = ("hp", "train", "label")
max(int(self.max_system_threads / 4), 1),
),
"sampler": QuickAdapterRegressorV3._OPTUNA_SAMPLERS[0], # "tpe"
- "storage": QuickAdapterRegressorV3._OPTUNA_STORAGE_BACKENDS[1], # "file"
+ "storage": QuickAdapterRegressorV3._OPTUNA_STORAGE_BACKENDS[0], # "file"
"continuous": True,
"warm_start": True,
"n_startup_trials": 15,
extrema_selection = str(
predictions_extrema.get(
"selection_method",
- QuickAdapterRegressorV3._EXTREMA_SELECTION_METHODS[1],
+ QuickAdapterRegressorV3._EXTREMA_SELECTION_METHODS[0], # "rank"
)
)
if (
thresholds_smoothing = str(
predictions_extrema.get(
"thresholds_smoothing",
- QuickAdapterRegressorV3._SKIMAGE_THRESHOLD_METHODS[2],
+ QuickAdapterRegressorV3._THRESHOLD_METHODS[0], # "mean"
)
)
if thresholds_smoothing not in QuickAdapterRegressorV3._threshold_methods_set():
f"Supported methods are {', '.join(QuickAdapterRegressorV3._THRESHOLD_METHODS)}"
)
if (
- thresholds_smoothing == QuickAdapterRegressorV3._CUSTOM_THRESHOLD_METHODS[0]
+ thresholds_smoothing == QuickAdapterRegressorV3._THRESHOLD_METHODS[7]
): # "median"
return QuickAdapterRegressorV3.median_min_max(
pred_extrema, extrema_selection
)
elif (
- thresholds_smoothing == QuickAdapterRegressorV3._CUSTOM_THRESHOLD_METHODS[1]
+ thresholds_smoothing == QuickAdapterRegressorV3._THRESHOLD_METHODS[8]
): # "soft_extremum"
thresholds_alpha = float(predictions_extrema.get("thresholds_alpha", 12.0))
return QuickAdapterRegressorV3.soft_extremum_min_max(
pred_extrema, thresholds_alpha, extrema_selection
)
- else:
+ elif (
+ thresholds_smoothing
+ in QuickAdapterRegressorV3.skimage_threshold_methods_set()
+ ):
return QuickAdapterRegressorV3.skimage_min_max(
pred_extrema, thresholds_smoothing, extrema_selection
)
if (
extrema_selection == QuickAdapterRegressorV3._EXTREMA_SELECTION_METHODS[0]
- ): # "values"
- minima_indices = sp.signal.find_peaks(-pred_extrema)[0]
- maxima_indices = sp.signal.find_peaks(pred_extrema)[0]
-
- pred_minima = (
- pred_extrema.iloc[minima_indices]
- if minima_indices.size > 0
- else pd.Series(dtype=float)
- )
- pred_maxima = (
- pred_extrema.iloc[maxima_indices]
- if maxima_indices.size > 0
- else pd.Series(dtype=float)
- )
- elif (
- extrema_selection == QuickAdapterRegressorV3._EXTREMA_SELECTION_METHODS[1]
): # "rank"
minima_indices = sp.signal.find_peaks(-pred_extrema)[0]
maxima_indices = sp.signal.find_peaks(pred_extrema)[0]
pred_maxima = pred_extrema.nlargest(n_maxima)
else:
pred_maxima = pd.Series(dtype=float)
+ elif (
+ extrema_selection == QuickAdapterRegressorV3._EXTREMA_SELECTION_METHODS[1]
+ ): # "values"
+ minima_indices = sp.signal.find_peaks(-pred_extrema)[0]
+ maxima_indices = sp.signal.find_peaks(pred_extrema)[0]
+
+ pred_minima = (
+ pred_extrema.iloc[minima_indices]
+ if minima_indices.size > 0
+ else pd.Series(dtype=float)
+ )
+ pred_maxima = (
+ pred_extrema.iloc[maxima_indices]
+ if maxima_indices.size > 0
+ else pd.Series(dtype=float)
+ )
+
elif (
extrema_selection == QuickAdapterRegressorV3._EXTREMA_SELECTION_METHODS[2]
): # "partition"
storage_backend = self._optuna_config.get("storage")
if (
storage_backend == QuickAdapterRegressorV3._OPTUNA_STORAGE_BACKENDS[0]
+ ): # "file"
+ storage = optuna.storages.JournalStorage(
+ optuna.storages.journal.JournalFileBackend(
+ f"{storage_dir}/{storage_filename}.log"
+ )
+ )
+ elif (
+ storage_backend == QuickAdapterRegressorV3._OPTUNA_STORAGE_BACKENDS[1]
): # "sqlite"
storage = optuna.storages.RDBStorage(
url=f"sqlite:///{storage_dir}/{storage_filename}.sqlite",
max_retry=3
),
)
- elif (
- storage_backend == QuickAdapterRegressorV3._OPTUNA_STORAGE_BACKENDS[1]
- ): # "file"
- storage = optuna.storages.JournalStorage(
- optuna.storages.journal.JournalFileBackend(
- f"{storage_dir}/{storage_filename}.log"
- )
- )
else:
raise ValueError(
f"Unsupported optuna storage backend: {storage_backend}. "