paradance.optimization.BaseObjective

class paradance.optimization.BaseObjective(calculator: Calculator | LogarithmPCACalculator, direction: str | None = None, formula: str | None = None, warmup_formula: str | None = None, warmup_trials: int = 200, first_order: bool | None = False, power: bool | None = True, dirichlet: bool | None = False, weights_num: int | None = None, study_name: str | None = None, study_path: str | None = None, save_study: bool | None = True, checkpoint_path: str | None = None, config: Dict | None = None)[source]

BaseObjective serves as an abstract base class for objective optimization. It provides core functionalities for setting up and optimizing objectives using the optuna library.

calculator

An instance of Calculator for various evaluations.

Type:

Calculator

direction

Direction for optimization (e.g., “minimize” or “maximize”).

Type:

Optional[str]

formula

Mathematical formula representing the objective.

Type:

Optional[str]

first_order

Whether to use first order optimization or not. Default is False.

Type:

bool

power

If True, includes power in the optimization. Default is True.

Type:

bool

dirichlet

If True, uses Dirichlet distribution for optimization. Default is False.

Type:

bool

weights_num

Number of weights for optimization.

Type:

Optional[int]

study_name

Name of the study.

Type:

Optional[str]

study_path

Path to the study directory.

Type:

Optional[str]

full_path

Full path combining study_path and study_name.

Type:

str

study

Optuna study object for optimization.

Type:

Study

logger

Logger object for logging optimization progress.

Type:

logging.Logger

build_logger(process_id) None[source]

Constructs a logger for the optimization process.

objective(trial) float[source]

Abstract method for objective function to be overridden in derived classes.

optimize(n_trials) None[source]

Optimize the objective for a specified number of trials.

__init__(calculator: Calculator | LogarithmPCACalculator, direction: str | None = None, formula: str | None = None, warmup_formula: str | None = None, warmup_trials: int = 200, first_order: bool | None = False, power: bool | None = True, dirichlet: bool | None = False, weights_num: int | None = None, study_name: str | None = None, study_path: str | None = None, save_study: bool | None = True, checkpoint_path: str | None = None, config: Dict | None = None) None[source]

Initializes the BaseObjective class with necessary parameters.

Parameters:
  • calculator (Calculator) – Calculator for evaluations.

  • direction (str) – Direction of optimization.

  • weights_num (int) – Number of weights.

  • formula (str) – Formula for objective.

  • first_order (bool, optional) – Use first order optimization or not. Defaults to False.

  • power (bool, optional) – Include power in optimization. Defaults to True.

  • dirichlet (bool, optional) – Use Dirichlet distribution. Defaults to False.

  • study_name (Optional[str], optional) – Name of the study. Defaults to None.

  • study_path (Optional[str], optional) – Path to the study directory. Defaults to None.

Methods

__init__(calculator[, direction, formula, ...])

Initializes the BaseObjective class with necessary parameters.

build_logger([process_id])

Constructs a logger for the optimization process.

evaluate_custom_weights(weights)

Evaluates the custom weights for the given list of weights.

get_weights_num()

Returns the number of weights.

objective(trial)

Abstract method for the objective function.

optimize(n_trials)

Optimizes the objective for a set number of trials.

build_logger(process_id: int | None = None) None[source]

Constructs a logger for the optimization process.

Parameters:

process_id (Optional[int], optional) – ID of the process, used for creating unique log filenames. Defaults to None.

abstract evaluate_custom_weights(weights: List[float]) List[float][source]

Evaluates the custom weights for the given list of weights.

Parameters:

weights (List[float]) – List of weights to evaluate.

Returns:

Evaluation score for the given weights.

Return type:

float

abstract objective(trial: Trial) float[source]

Abstract method for the objective function. Must be overridden in derived classes.

Parameters:

trial (Trial) – Optuna trial instance.

Returns:

Objective value for the given trial.

Return type:

float

get_weights_num() int[source]

Returns the number of weights.

Returns:

Number of weights.

Return type:

int

optimize(n_trials: int) None[source]

Optimizes the objective for a set number of trials.

Parameters:

n_trials (int) – Number of trials for optimization.