(
    study: Study,
    param_names: List[str],
    multivariate: bool,
    constant_liar: bool = False,  # TODO(hvy): Remove default value and fix unit tests.
)
return values, scores
Get observation pairs from the study.

    This function collects observation pairs from the complete or pruned trials of the study.
    In addition, if ``constant_liar`` is :obj:`True`, the running trials are considered.
    The values for trials that don't contain the parameter in the ``param_names`` are skipped.

    An observation pair fundamentally consists of a parameter value and an objective value.
    However, due to the pruning mechanism of Optuna, final objective values are not always
    available. Therefore, this function uses intermediate values in addition to the final
    ones, and reports the value with its step count as ``(-step, value)``.
    Consequently, the structure of the observation pair is as follows:
    ``(param_value, (-step, value))``.

    The second element of an observation pair is used to rank observations in
    ``_split_observation_pairs`` method (i.e., observations are sorted lexicographically by
    ``(-step, value)``).
Get observation pairs from the study.
Get observation pairs from the study .
def _get_observation_pairs(
    study: Study,
    param_names: List[str],
    multivariate: bool,
    constant_liar: bool = False,  # TODO(hvy): Remove default value and fix unit tests.
) -> Tuple[Dict[str, List[Optional[float]]], List[Tuple[float, List[float]]]]:
    """Get observation pairs from the study.

    This function collects observation pairs from the complete or pruned trials of the study.
    In addition, if ``constant_liar`` is :obj:`True`, the running trials are considered.
    The values for trials that don't contain the parameter in the ``param_names`` are skipped.

    An observation pair fundamentally consists of a parameter value and an objective value.
    However, due to the pruning mechanism of Optuna, final objective values are not always
    available. Therefore, this function uses intermediate values in addition to the final
    ones, and reports the value with its step count as ``(-step, value)``.
    Consequently, the structure of the observation pair is as follows:
    ``(param_value, (-step, value))``.

    The second element of an observation pair is used to rank observations in
    ``_split_observation_pairs`` method (i.e., observations are sorted lexicographically by
    ``(-step, value)``).
    """

    if len(param_names) > 1:
        assert multivariate

    signs = []
    for d in study.directions:
        if d == StudyDirection.MINIMIZE:
            signs.append(1)
        else:
            signs.append(-1)

    states: Tuple[TrialState, ...]
    if constant_liar:
        states = (TrialState.COMPLETE, TrialState.PRUNED, TrialState.RUNNING)
    else:
        states = (TrialState.COMPLETE, TrialState.PRUNED)

    scores = []
    values: Dict[str, List[Optional[float]]] = {param_name: [] for param_name in param_names}
    for trial in study.get_trials(deepcopy=False, states=states):
        # If ``multivariate`` = True and ``group`` = True, we ignore the trials that are not
        # included in each subspace.
        # If ``multivariate`` = False, we skip the check.
        if multivariate and any([param_name not in trial.params for param_name in param_names]):
            continue

        # We extract score from the trial.
        if trial.state is TrialState.COMPLETE:
            if trial.values is None:
                continue
            score = (-float("inf"), [sign * v for sign, v in zip(signs, trial.values)])
        elif trial.state is TrialState.PRUNED:
            if study._is_multi_objective():
                continue

            if len(trial.intermediate_values) > 0:
                step, intermediate_value = max(trial.intermediate_values.items())
                if math.isnan(intermediate_value):
                    score = (-step, [float("inf")])
                else:
                    score = (-step, [signs[0] * intermediate_value])
            else:
                score = (float("inf"), [0.0])
        elif trial.state is TrialState.RUNNING:
            if study._is_multi_objective():
                continue

            assert constant_liar
            score = (-float("inf"), [signs[0] * float("inf")])
        else:
            assert False
        scores.append(score)

        # We extract param_value from the trial.
        for param_name in param_names:
            raw_param_value = trial.params.get(param_name, None)
            param_value: Optional[float]
            if raw_param_value is not None:
                distribution = trial.distributions[param_name]
                param_value = distribution.to_internal_repr(trial.params[param_name])
            else:
                param_value = None
            values[param_name].append(param_value)

    return values, scores
def _get_observation_pairs ( study : Study , param_names : List [ str ] , multivariate : bool , constant_liar : bool = False , # TODO(hvy): Remove default value and fix unit tests. ) -> Tuple [ Dict [ str , List [ Optional [ float ] ] ] , List [ Tuple [ float , List [ float ] ] ] ] : if len ( param_names ) > 1 : assert multivariate signs = [ ] for d in study . directions : if d == StudyDirection . MINIMIZE : signs . append ( 1 ) else : signs . append ( - 1 ) states : Tuple [ TrialState , ... ] if constant_liar : states = ( TrialState . COMPLETE , TrialState . PRUNED , TrialState . RUNNING ) else : states = ( TrialState . COMPLETE , TrialState . PRUNED ) scores = [ ] values : Dict [ str , List [ Optional [ float ] ] ] = { param_name : [ ] for param_name in param_names } for trial in study . get_trials ( deepcopy = False , states = states ) : # If ``multivariate`` = True and ``group`` = True, we ignore the trials that are not # included in each subspace. # If ``multivariate`` = False, we skip the check. if multivariate and any ( [ param_name not in trial . params for param_name in param_names ] ) : continue # We extract score from the trial. if trial . state is TrialState . COMPLETE : if trial . values is None : continue score = ( - float ( "inf" ) , [ sign * v for sign , v in zip ( signs , trial . values ) ] ) elif trial . state is TrialState . PRUNED : if study . _is_multi_objective ( ) : continue if len ( trial . intermediate_values ) > 0 : step , intermediate_value = max ( trial . intermediate_values . items ( ) ) if math . isnan ( intermediate_value ) : score = ( - step , [ float ( "inf" ) ] ) else : score = ( - step , [ signs [ 0 ] * intermediate_value ] ) else : score = ( float ( "inf" ) , [ 0.0 ] ) elif trial . state is TrialState . RUNNING : if study . _is_multi_objective ( ) : continue assert constant_liar score = ( - float ( "inf" ) , [ signs [ 0 ] * float ( "inf" ) ] ) else : assert False scores . append ( score ) # We extract param_value from the trial. for param_name in param_names : raw_param_value = trial . params . get ( param_name , None ) param_value : Optional [ float ] if raw_param_value is not None : distribution = trial . distributions [ param_name ] param_value = distribution . to_internal_repr ( trial . params [ param_name ] ) else : param_value = None values [ param_name ] . append ( param_value ) return values , scores