o
�J�h�. � @ s� d dl mZ d dlZd dlmZ d dlZd dlmZ d dlm Z d dlm
Z
d dlmZ G dd � d �Zddd�Z
ddd�Zddd�ZdS ) � )�annotationsN)�Any)�BaseDistribution)�CategoricalDistribution)�FloatDistribution)�IntDistributionc @ s` e Zd ZdZ dddd
�Zed dd��Zed!dd��Zed dd��Zd"dd�Z d#dd�Z
dS )$�_SearchSpaceTransformai Transform a search space and parameter configurations to continuous space.
The search space bounds and parameter configurations are represented as ``numpy.ndarray``s and
transformed into continuous space. Bounds and parameters associated with categorical
distributions are one-hot encoded. Parameter configurations in this space can additionally be
untransformed, or mapped back to the original space. This type of
transformation/untransformation is useful for e.g. implementing samplers without having to
condition on distribution types before sampling parameter values.
Args:
search_space:
The search space. If any transformations are to be applied, parameter configurations
are assumed to hold parameter values for all of the distributions defined in this
search space. Otherwise, assertion failures will be raised.
transform_log:
If :obj:`True`, apply log/exp operations to the bounds and parameters with
corresponding distributions in log space during transformation/untransformation.
Should always be :obj:`True` if any parameters are going to be sampled from the
transformed space.
transform_step:
If :obj:`True`, offset the lower and higher bounds by a half step each, increasing the
space by one step. This allows fair sampling for values close to the bounds.
Should always be :obj:`True` if any parameters are going to be sampled from the
transformed space.
transform_0_1:
If :obj:`True`, apply a linear transformation to the bounds and parameters so that
they are in the unit cube.
Attributes:
bounds:
Constructed bounds from the given search space.
column_to_encoded_columns:
Constructed mapping from original parameter column index to encoded column indices.
encoded_column_to_column:
Constructed mapping from encoded column index to original parameter column index.
Note:
Parameter values are not scaled to the unit cube.
Note:
``transform_log`` and ``transform_step`` are useful for constructing bounds and parameters
without any actual transformations by setting those arguments to :obj:`False`. This is
needed for e.g. the hyperparameter importance assessments.
TF�search_space�dict[str, BaseDistribution]�
transform_log�bool�transform_step�
transform_0_1�return�Nonec C s: t |||�\}}}|| _|| _|| _|| _|| _|| _d S �N)�_transform_search_space�_raw_bounds�_column_to_encoded_columns�_encoded_column_to_column�
_search_space�_transform_log�_transform_0_1)�selfr r r
r �bounds�column_to_encoded_columns�encoded_column_to_column� r �OC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\optuna\_transform.py�__init__= s
�
z_SearchSpaceTransform.__init__�
np.ndarrayc C s( | j rt�ddgg| jjd �S | jS )N� g �?r )r �np�arrayr �shape�r r r r r N s z_SearchSpaceTransform.bounds�list[np.ndarray]c C � | j S r )r r% r r r r U � z/_SearchSpaceTransform.column_to_encoded_columnsc C r'