Esempio n. 1
0
    def _sample_qmc(self, study: Study,
                    search_space: Dict[str, BaseDistribution]) -> np.ndarray:

        # Lazy import because the `scipy.stats.qmc` is slow to import.
        qmc_module = _LazyImport("scipy.stats.qmc")

        sample_id = self._find_sample_id(study, search_space)
        d = len(search_space)

        if self._qmc_type == "halton":
            qmc_engine = qmc_module.Halton(d,
                                           seed=self._seed,
                                           scramble=self._scramble)
        elif self._qmc_type == "sobol":
            qmc_engine = qmc_module.Sobol(d,
                                          seed=self._seed,
                                          scramble=self._scramble)
        else:
            raise ValueError("Invalid `qmc_type`")

        forward_size = sample_id  # `sample_id` starts from 0.
        qmc_engine.fast_forward(forward_size)
        sample = qmc_engine.random(1)

        return sample
Esempio n. 2
0
File: cli.py Progetto: not522/optuna
from typing import Union
import warnings

from cliff.app import App
from cliff.command import Command
from cliff.commandmanager import CommandManager
import yaml

import optuna
from optuna._imports import _LazyImport
from optuna.exceptions import CLIUsageError
from optuna.exceptions import ExperimentalWarning
from optuna.storages import RDBStorage
from optuna.trial import TrialState

_dataframe = _LazyImport("optuna.study._dataframe")

_DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"


def _check_storage_url(storage_url: Optional[str]) -> str:

    if storage_url is None:
        raise CLIUsageError("Storage URL is not specified.")
    return storage_url


def _format_value(value: Any) -> Any:
    #  Format value that can be serialized to JSON or YAML.
    if value is None or isinstance(value, (int, float)):
        return value
Esempio n. 3
0
__all__ = [
    "Study",
    "TYPE_CHECKING",
    "Trial",
    "TrialPruned",
    "__version__",
    "copy_study",
    "create_study",
    "create_trial",
    "delete_study",
    "distributions",
    "exceptions",
    "get_all_study_summaries",
    "importance",
    "integration",
    "load_study",
    "logging",
    "multi_objective",
    "pruners",
    "samplers",
    "storages",
    "study",
    "trial",
    "version",
    "visualization",
]

importance = _LazyImport("optuna.importance")
visualization = _LazyImport("optuna.visualization")
Esempio n. 4
0
from optuna._imports import _LazyImport
from optuna.multi_objective import samplers  # NOQA
from optuna.multi_objective import study  # NOQA
from optuna.multi_objective import trial  # NOQA
from optuna.multi_objective.study import create_study  # NOQA
from optuna.multi_objective.study import load_study  # NOQA


visualization = _LazyImport("optuna.multi_objective.visualization")
Esempio n. 5
0
from typing import NamedTuple
from typing import Optional
from typing import Tuple
from typing import TYPE_CHECKING

import numpy as np

from optuna import distributions
from optuna._imports import _LazyImport
from optuna.distributions import BaseDistribution

if TYPE_CHECKING:
    import scipy.special as special
    import scipy.stats as stats
else:
    special = _LazyImport("scipy.special")
    stats = _LazyImport("scipy.stats")

EPS = 1e-12
SIGMA0_MAGNITUDE = 0.2

_DISTRIBUTION_CLASSES = (
    distributions.CategoricalDistribution,
    distributions.FloatDistribution,
    distributions.IntDistribution,
)


class _ParzenEstimatorParameters(
        NamedTuple(
            "_ParzenEstimatorParameters",
Esempio n. 6
0
__all__ = [
    "Study",
    "TYPE_CHECKING",
    "Trial",
    "TrialPruned",
    "__version__",
    "copy_study",
    "create_study",
    "create_trial",
    "delete_study",
    "distributions",
    "exceptions",
    "get_all_study_summaries",
    "importance",
    "integration",
    "load_study",
    "logging",
    "multi_objective",
    "pruners",
    "samplers",
    "storages",
    "study",
    "trial",
    "version",
    "visualization",
]

importance = _LazyImport("optuna.importance")
type_checking = _LazyImport("optuna.type_checking")
visualization = _LazyImport("optuna.visualization")