MCPcopy
hub / github.com/optuna/optuna / optimize

Method optimize

optuna/study/study.py:414–526  ·  view source on GitHub ↗

Optimize an objective function. Optimization is done by choosing a suitable set of hyperparameter values from a given range. Uses a sampler which implements the task of value suggestion based on a specified distribution. The sampler is specified in :func:`~optuna.study.creat

(
        self,
        func: ObjectiveFuncType,
        n_trials: int | None = None,
        timeout: float | None = None,
        n_jobs: int = 1,
        catch: Iterable[type[Exception]] | type[Exception] = (),
        callbacks: Iterable[Callable[[Study, FrozenTrial], None]] | None = None,
        gc_after_trial: bool = False,
        show_progress_bar: bool = False,
    )

Source from the content-addressed store, hash-verified

412 return self._storage.get_study_system_attrs(self._study_id).get(_SYSTEM_ATTR_METRIC_NAMES)
413
414 def optimize(
415 self,
416 func: ObjectiveFuncType,
417 n_trials: int | None = None,
418 timeout: float | None = None,
419 n_jobs: int = 1,
420 catch: Iterable[type[Exception]] | type[Exception] = (),
421 callbacks: Iterable[Callable[[Study, FrozenTrial], None]] | None = None,
422 gc_after_trial: bool = False,
423 show_progress_bar: bool = False,
424 ) -> None:
425 """Optimize an objective function.
426
427 Optimization is done by choosing a suitable set of hyperparameter values from a given
428 range. Uses a sampler which implements the task of value suggestion based on a specified
429 distribution. The sampler is specified in :func:`~optuna.study.create_study` and the
430 default choice for the sampler is TPE.
431 See also :class:`~optuna.samplers.TPESampler` for more details on 'TPE'.
432
433 Optimization will be stopped when receiving a termination signal such as SIGINT and
434 SIGTERM. Unlike other signals, a trial is automatically and cleanly failed when receiving
435 SIGINT (Ctrl+C). If ``n_jobs`` is greater than one or if another signal than SIGINT
436 is used, the interrupted trial state won't be properly updated.
437
438 Example:
439
440 .. testcode::
441
442 import optuna
443
444
445 def objective(trial):
446 x = trial.suggest_float("x", -1, 1)
447 return x**2
448
449
450 study = optuna.create_study()
451 study.optimize(objective, n_trials=3)
452
453 Args:
454 func:
455 A callable that implements objective function.
456 n_trials:
457 The number of trials for each process. :obj:`None` represents no limit in terms of
458 the number of trials. The study continues to create trials until the number of
459 trials reaches ``n_trials``, ``timeout`` period elapses,
460 :func:`~optuna.study.Study.stop` is called, or a termination signal such as
461 SIGTERM or Ctrl+C is received.
462
463 .. seealso::
464 :class:`optuna.study.MaxTrialsCallback` can ensure how many times trials
465 will be performed across all processes.
466 timeout:
467 Stop study after the given number of second(s). :obj:`None` represents no limit in
468 terms of elapsed time. The study continues to create trials until the number of
469 trials reaches ``n_trials``, ``timeout`` period elapses,
470 :func:`~optuna.study.Study.stop` is called or, a termination signal such as
471 SIGTERM or Ctrl+C is received.

Calls 1

_optimizeFunction · 0.90