refactor: rename library from optimize to optimizer

This commit is contained in:
Manuel Raimann
2026-01-30 18:08:13 +01:00
parent 12d572025f
commit 530faba61c
12 changed files with 76 additions and 76 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
[package]
name = "optimize"
name = "optimizer"
version = "0.1.0"
edition = "2024"
rust-version = "1.88"
license = "MIT"
authors = ["Manuel Raimann <raimannma@outlook.de"]
description = "A Rust library for optimization algorithms."
repository = "https://github.com/raimannma/rust-optimize"
repository = "https://github.com/raimannma/rust-optimizer"
[dependencies]
+7 -7
View File
@@ -1,10 +1,10 @@
# optimize
# optimizer
A Rust library for black-box optimization using Tree-Parzen Estimator (TPE).
[![Docs](https://docs.rs/optimize/badge.svg)](https://docs.rs/optimize)
[![Crates.io](https://img.shields.io/crates/v/optimize.svg)](https://crates.io/crates/optimize)
[![codecov](https://codecov.io/gh/raimannma/rust-optimize/graph/badge.svg?token=WOE77XJ4M6)](https://codecov.io/gh/raimannma/rust-optimize)
[![Docs](https://docs.rs/optimizer/badge.svg)](https://docs.rs/optimizer)
[![Crates.io](https://img.shields.io/crates/v/optimizer.svg)](https://crates.io/crates/optimizer)
[![codecov](https://codecov.io/gh/raimannma/rust-optimizer/graph/badge.svg?token=WOE77XJ4M6)](https://codecov.io/gh/raimannma/rust-optimizer)
## Features
@@ -17,7 +17,7 @@ A Rust library for black-box optimization using Tree-Parzen Estimator (TPE).
## Quick Start
```rust
use optimize::{Direction, Study, TpeSampler};
use optimizer::{Direction, Study, TpeSampler};
let sampler = TpeSampler::builder().seed(42).build();
let study: Study<f64> = Study::with_sampler(Direction::Minimize, sampler);
@@ -25,7 +25,7 @@ let study: Study<f64> = Study::with_sampler(Direction::Minimize, sampler);
study
.optimize_with_sampler(20, |trial| {
let x = trial.suggest_float("x", -10.0, 10.0)?;
Ok::<_, optimize::TpeError>(x * x)
Ok::<_, optimizer::TpeError>(x * x)
})
.unwrap();
@@ -40,7 +40,7 @@ println!("Best value: {} at x={:?}", best.value, best.params);
## Documentation
Full API documentation is available at [docs.rs/optimize](https://docs.rs/optimize).
Full API documentation is available at [docs.rs/optimizer](https://docs.rs/optimizer).
## License
+1 -1
View File
@@ -1,4 +1,4 @@
//! Error types for the optimize library.
//! Error types for the optimizer library.
use thiserror::Error;
+8 -8
View File
@@ -12,7 +12,7 @@
//! # Quick Start
//!
//! ```
//! use optimize::{Direction, Study, TpeSampler};
//! use optimizer::{Direction, Study, TpeSampler};
//!
//! // Create a study with TPE sampler
//! let sampler = TpeSampler::builder().seed(42).build();
@@ -22,7 +22,7 @@
//! study
//! .optimize_with_sampler(20, |trial| {
//! let x = trial.suggest_float("x", -10.0, 10.0)?;
//! Ok::<_, optimize::TpeError>(x * x)
//! Ok::<_, optimizer::TpeError>(x * x)
//! })
//! .unwrap();
//!
@@ -36,7 +36,7 @@
//! A [`Study`] manages optimization trials. Create one with an optimization direction:
//!
//! ```
//! use optimize::{Direction, RandomSampler, Study, TpeSampler};
//! use optimizer::{Direction, RandomSampler, Study, TpeSampler};
//!
//! // Minimize with default random sampler
//! let study: Study<f64> = Study::new(Direction::Minimize);
@@ -53,7 +53,7 @@
//! Within the objective function, use [`Trial`] to suggest parameter values:
//!
//! ```
//! use optimize::{Direction, Study};
//! use optimizer::{Direction, Study};
//!
//! let study: Study<f64> = Study::new(Direction::Minimize);
//!
@@ -73,7 +73,7 @@
//! let optimizer = trial.suggest_categorical("optimizer", &["sgd", "adam", "rmsprop"])?;
//!
//! // Return objective value
//! Ok::<_, optimize::TpeError>(x * n as f64)
//! Ok::<_, optimizer::TpeError>(x * n as f64)
//! })
//! .unwrap();
//! ```
@@ -83,7 +83,7 @@
//! The [`TpeSampler`] can be configured using the builder pattern:
//!
//! ```
//! use optimize::TpeSampler;
//! use optimizer::TpeSampler;
//!
//! let sampler = TpeSampler::builder()
//! .gamma(0.15) // Quantile for good/bad split
@@ -98,7 +98,7 @@
//! With the `async` feature enabled, you can run trials asynchronously:
//!
//! ```ignore
//! use optimize::{Study, Direction};
//! use optimizer::{Study, Direction};
//!
//! // Sequential async
//! study.optimize_async(10, |mut trial| async move {
@@ -118,7 +118,7 @@
//! With the `serde` feature enabled, studies can be serialized:
//!
//! ```ignore
//! use optimize::{Study, Direction, TpeSampler};
//! use optimizer::{Study, Direction, TpeSampler};
//!
//! // Save study state
//! let study: Study<f64> = Study::new(Direction::Minimize);
+1 -1
View File
@@ -59,7 +59,7 @@ impl<V> CompletedTrial<V> {
/// Implementing a custom sampler:
///
/// ```ignore
/// use optimize::{Sampler, ParamValue, Distribution, CompletedTrial};
/// use optimizer::{Sampler, ParamValue, Distribution, CompletedTrial};
///
/// struct MySampler;
///
+1 -1
View File
@@ -17,7 +17,7 @@ use crate::sampler::{CompletedTrial, Sampler};
/// # Examples
///
/// ```
/// use optimize::RandomSampler;
/// use optimizer::RandomSampler;
///
/// // Create with default RNG
/// let sampler = RandomSampler::new();
+9 -9
View File
@@ -27,7 +27,7 @@ use crate::sampler::{CompletedTrial, Sampler};
/// # Examples
///
/// ```
/// use optimize::TpeSampler;
/// use optimizer::TpeSampler;
///
/// // Create with default settings
/// let sampler = TpeSampler::new();
@@ -76,7 +76,7 @@ impl TpeSampler {
/// # Examples
///
/// ```
/// use optimize::TpeSampler;
/// use optimizer::TpeSampler;
///
/// let sampler = TpeSampler::builder()
/// .gamma(0.15)
@@ -395,7 +395,7 @@ impl Default for TpeSampler {
/// # Examples
///
/// ```
/// use optimize::TpeSamplerBuilder;
/// use optimizer::TpeSamplerBuilder;
///
/// let sampler = TpeSamplerBuilder::new()
/// .gamma(0.15)
@@ -448,7 +448,7 @@ impl TpeSamplerBuilder {
/// # Examples
///
/// ```
/// use optimize::TpeSamplerBuilder;
/// use optimizer::TpeSamplerBuilder;
///
/// let sampler = TpeSamplerBuilder::new()
/// .gamma(0.10) // Use top 10% as "good" trials
@@ -476,7 +476,7 @@ impl TpeSamplerBuilder {
/// # Examples
///
/// ```
/// use optimize::TpeSamplerBuilder;
/// use optimizer::TpeSamplerBuilder;
///
/// let sampler = TpeSamplerBuilder::new()
/// .n_startup_trials(20) // Random sample first 20 trials
@@ -500,7 +500,7 @@ impl TpeSamplerBuilder {
/// # Examples
///
/// ```
/// use optimize::TpeSamplerBuilder;
/// use optimizer::TpeSamplerBuilder;
///
/// let sampler = TpeSamplerBuilder::new()
/// .n_ei_candidates(48) // Evaluate more candidates
@@ -530,7 +530,7 @@ impl TpeSamplerBuilder {
/// # Examples
///
/// ```
/// use optimize::TpeSamplerBuilder;
/// use optimizer::TpeSamplerBuilder;
///
/// let sampler = TpeSamplerBuilder::new()
/// .kde_bandwidth(0.5) // Fixed bandwidth of 0.5
@@ -554,7 +554,7 @@ impl TpeSamplerBuilder {
/// # Examples
///
/// ```
/// use optimize::TpeSamplerBuilder;
/// use optimizer::TpeSamplerBuilder;
///
/// let sampler = TpeSamplerBuilder::new()
/// .seed(42) // Reproducible results
@@ -570,7 +570,7 @@ impl TpeSamplerBuilder {
/// # Examples
///
/// ```
/// use optimize::TpeSamplerBuilder;
/// use optimizer::TpeSamplerBuilder;
///
/// let sampler = TpeSamplerBuilder::new()
/// .gamma(0.15)
+32 -32
View File
@@ -39,7 +39,7 @@ fn default_sampler() -> Arc<dyn Sampler> {
/// # Examples
///
/// ```
/// use optimize::{Direction, Study};
/// use optimizer::{Direction, Study};
///
/// // Create a study to minimize an objective function
/// let study: Study<f64> = Study::new(Direction::Minimize);
@@ -74,7 +74,7 @@ where
/// # Examples
///
/// ```
/// use optimize::{Direction, Study};
/// use optimizer::{Direction, Study};
///
/// let study: Study<f64> = Study::new(Direction::Minimize);
/// assert_eq!(study.direction(), Direction::Minimize);
@@ -93,7 +93,7 @@ where
/// # Examples
///
/// ```
/// use optimize::{Direction, RandomSampler, Study};
/// use optimizer::{Direction, RandomSampler, Study};
///
/// let sampler = RandomSampler::with_seed(42);
/// let study: Study<f64> = Study::with_sampler(Direction::Maximize, sampler);
@@ -125,7 +125,7 @@ where
/// # Examples
///
/// ```
/// use optimize::{Direction, Study, TpeSampler};
/// use optimizer::{Direction, Study, TpeSampler};
///
/// // After deserializing a study, restore the TPE sampler
/// let mut study: Study<f64> = Study::new(Direction::Minimize);
@@ -153,7 +153,7 @@ where
/// # Examples
///
/// ```
/// use optimize::{Direction, Study};
/// use optimizer::{Direction, Study};
///
/// let study: Study<f64> = Study::new(Direction::Minimize);
/// let trial = study.create_trial();
@@ -181,7 +181,7 @@ where
/// # Examples
///
/// ```
/// use optimize::{Direction, Study};
/// use optimizer::{Direction, Study};
///
/// let study: Study<f64> = Study::new(Direction::Minimize);
/// let mut trial = study.create_trial();
@@ -217,7 +217,7 @@ where
/// # Examples
///
/// ```
/// use optimize::{Direction, Study};
/// use optimizer::{Direction, Study};
///
/// let study: Study<f64> = Study::new(Direction::Minimize);
/// let trial = study.create_trial();
@@ -243,7 +243,7 @@ where
/// # Examples
///
/// ```
/// use optimize::{Direction, Study};
/// use optimizer::{Direction, Study};
///
/// let study: Study<f64> = Study::new(Direction::Minimize);
/// let mut trial = study.create_trial();
@@ -268,7 +268,7 @@ where
/// # Examples
///
/// ```
/// use optimize::{Direction, Study};
/// use optimizer::{Direction, Study};
///
/// let study: Study<f64> = Study::new(Direction::Minimize);
/// assert_eq!(study.n_trials(), 0);
@@ -295,7 +295,7 @@ where
/// # Examples
///
/// ```
/// use optimize::{Direction, Study};
/// use optimizer::{Direction, Study};
///
/// let study: Study<f64> = Study::new(Direction::Minimize);
///
@@ -360,7 +360,7 @@ where
/// # Examples
///
/// ```
/// use optimize::{Direction, Study};
/// use optimizer::{Direction, Study};
///
/// let study: Study<f64> = Study::new(Direction::Maximize);
///
@@ -409,7 +409,7 @@ where
/// # Examples
///
/// ```
/// use optimize::{Direction, RandomSampler, Study};
/// use optimizer::{Direction, RandomSampler, Study};
///
/// // Minimize x^2
/// let sampler = RandomSampler::with_seed(42);
@@ -418,7 +418,7 @@ where
/// study
/// .optimize(10, |trial| {
/// let x = trial.suggest_float("x", -10.0, 10.0)?;
/// Ok::<_, optimize::TpeError>(x * x)
/// Ok::<_, optimizer::TpeError>(x * x)
/// })
/// .unwrap();
///
@@ -476,10 +476,10 @@ where
/// # Examples
///
/// ```
/// use optimize::{Direction, RandomSampler, Study};
/// use optimizer::{Direction, RandomSampler, Study};
///
/// # #[cfg(feature = "async")]
/// # async fn example() -> optimize::Result<()> {
/// # async fn example() -> optimizer::Result<()> {
/// // Minimize x^2 with async objective
/// let sampler = RandomSampler::with_seed(42);
/// let study: Study<f64> = Study::with_sampler(Direction::Minimize, sampler);
@@ -489,7 +489,7 @@ where
/// let x = trial.suggest_float("x", -10.0, 10.0)?;
/// // Simulate async work (e.g., network request)
/// let value = x * x;
/// Ok::<_, optimize::TpeError>((trial, value))
/// Ok::<_, optimizer::TpeError>((trial, value))
/// })
/// .await?;
///
@@ -556,10 +556,10 @@ where
/// # Examples
///
/// ```
/// use optimize::{Direction, RandomSampler, Study};
/// use optimizer::{Direction, RandomSampler, Study};
///
/// # #[cfg(feature = "async")]
/// # async fn example() -> optimize::Result<()> {
/// # async fn example() -> optimizer::Result<()> {
/// // Minimize x^2 with parallel async evaluation
/// let sampler = RandomSampler::with_seed(42);
/// let study: Study<f64> = Study::with_sampler(Direction::Minimize, sampler);
@@ -569,7 +569,7 @@ where
/// let x = trial.suggest_float("x", -10.0, 10.0)?;
/// // Async objective function (e.g., network request)
/// let value = x * x;
/// Ok::<_, optimize::TpeError>((trial, value))
/// Ok::<_, optimizer::TpeError>((trial, value))
/// })
/// .await?;
///
@@ -657,7 +657,7 @@ where
/// ```
/// use std::ops::ControlFlow;
///
/// use optimize::{Direction, RandomSampler, Study};
/// use optimizer::{Direction, RandomSampler, Study};
///
/// // Stop early when we find a good enough value
/// let sampler = RandomSampler::with_seed(42);
@@ -668,7 +668,7 @@ where
/// 100,
/// |trial| {
/// let x = trial.suggest_float("x", -10.0, 10.0)?;
/// Ok::<_, optimize::TpeError>(x * x)
/// Ok::<_, optimizer::TpeError>(x * x)
/// },
/// |_study, completed_trial| {
/// // Stop early if we find a value less than 1.0
@@ -746,7 +746,7 @@ impl Study<f64> {
/// # Examples
///
/// ```
/// use optimize::{Direction, RandomSampler, Study};
/// use optimizer::{Direction, RandomSampler, Study};
///
/// // With a seeded sampler for reproducibility
/// let sampler = RandomSampler::with_seed(42);
@@ -767,7 +767,7 @@ impl Study<f64> {
/// Runs optimization with full sampler integration.
///
/// This method is similar to the generic `optimize` method but creates trials
/// This method is similar to the generic `optimizer` method but creates trials
/// using `create_trial_with_sampler()`, giving the sampler access to the history
/// of completed trials for informed parameter suggestions.
///
@@ -787,7 +787,7 @@ impl Study<f64> {
/// # Examples
///
/// ```
/// use optimize::{Direction, RandomSampler, Study};
/// use optimizer::{Direction, RandomSampler, Study};
///
/// // Minimize x^2 with sampler integration
/// let sampler = RandomSampler::with_seed(42);
@@ -796,7 +796,7 @@ impl Study<f64> {
/// study
/// .optimize_with_sampler(10, |trial| {
/// let x = trial.suggest_float("x", -10.0, 10.0)?;
/// Ok::<_, optimize::TpeError>(x * x)
/// Ok::<_, optimizer::TpeError>(x * x)
/// })
/// .unwrap();
///
@@ -856,7 +856,7 @@ impl Study<f64> {
/// ```
/// use std::ops::ControlFlow;
///
/// use optimize::{Direction, RandomSampler, Study};
/// use optimizer::{Direction, RandomSampler, Study};
///
/// // Optimize with sampler integration and early stopping
/// let sampler = RandomSampler::with_seed(42);
@@ -867,7 +867,7 @@ impl Study<f64> {
/// 100,
/// |trial| {
/// let x = trial.suggest_float("x", -10.0, 10.0)?;
/// Ok::<_, optimize::TpeError>(x * x)
/// Ok::<_, optimizer::TpeError>(x * x)
/// },
/// |study, _completed_trial| {
/// // Stop after finding 5 good trials
@@ -950,10 +950,10 @@ impl Study<f64> {
/// # Examples
///
/// ```
/// use optimize::{Direction, RandomSampler, Study};
/// use optimizer::{Direction, RandomSampler, Study};
///
/// # #[cfg(feature = "async")]
/// # async fn example() -> optimize::Result<()> {
/// # async fn example() -> optimizer::Result<()> {
/// // Minimize x^2 with async objective and sampler integration
/// let sampler = RandomSampler::with_seed(42);
/// let study: Study<f64> = Study::with_sampler(Direction::Minimize, sampler);
@@ -963,7 +963,7 @@ impl Study<f64> {
/// let x = trial.suggest_float("x", -10.0, 10.0)?;
/// // Simulate async work (e.g., network request)
/// let value = x * x;
/// Ok::<_, optimize::TpeError>((trial, value))
/// Ok::<_, optimizer::TpeError>((trial, value))
/// })
/// .await?;
///
@@ -1030,10 +1030,10 @@ impl Study<f64> {
/// # Examples
///
/// ```
/// use optimize::{Direction, RandomSampler, Study};
/// use optimizer::{Direction, RandomSampler, Study};
///
/// # #[cfg(feature = "async")]
/// # async fn example() -> optimize::Result<()> {
/// # async fn example() -> optimizer::Result<()> {
/// // Minimize x^2 with parallel async evaluation and sampler integration
/// let sampler = RandomSampler::with_seed(42);
/// let study: Study<f64> = Study::with_sampler(Direction::Minimize, sampler);
+8 -8
View File
@@ -71,7 +71,7 @@ impl Trial {
/// # Examples
///
/// ```
/// use optimize::Trial;
/// use optimizer::Trial;
///
/// let trial = Trial::new(0);
/// assert_eq!(trial.id(), 0);
@@ -178,7 +178,7 @@ impl Trial {
/// # Examples
///
/// ```
/// use optimize::Trial;
/// use optimizer::Trial;
///
/// let mut trial = Trial::new(0);
/// let x = trial.suggest_float("x", 0.0, 1.0).unwrap();
@@ -261,7 +261,7 @@ impl Trial {
/// # Examples
///
/// ```
/// use optimize::Trial;
/// use optimizer::Trial;
///
/// let mut trial = Trial::new(0);
/// let lr = trial
@@ -358,7 +358,7 @@ impl Trial {
/// # Examples
///
/// ```
/// use optimize::Trial;
/// use optimizer::Trial;
///
/// let mut trial = Trial::new(0);
/// let x = trial.suggest_float_step("x", 0.0, 1.0, 0.25).unwrap();
@@ -450,7 +450,7 @@ impl Trial {
/// # Examples
///
/// ```
/// use optimize::Trial;
/// use optimizer::Trial;
///
/// let mut trial = Trial::new(0);
/// let n = trial.suggest_int("n_layers", 1, 10).unwrap();
@@ -536,7 +536,7 @@ impl Trial {
/// # Examples
///
/// ```
/// use optimize::Trial;
/// use optimizer::Trial;
///
/// let mut trial = Trial::new(0);
/// let batch_size = trial.suggest_int_log("batch_size", 1, 1024).unwrap();
@@ -627,7 +627,7 @@ impl Trial {
/// # Examples
///
/// ```
/// use optimize::Trial;
/// use optimizer::Trial;
///
/// let mut trial = Trial::new(0);
/// let n = trial
@@ -731,7 +731,7 @@ impl Trial {
/// # Examples
///
/// ```
/// use optimize::Trial;
/// use optimizer::Trial;
///
/// let mut trial = Trial::new(0);
/// let optimizer = trial
+1 -1
View File
@@ -1,4 +1,4 @@
//! Core types for the optimize library.
//! Core types for the optimizer library.
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
+2 -2
View File
@@ -1,10 +1,10 @@
//! Async integration tests for the optimize library.
//! Async integration tests for the optimizer library.
//!
//! These tests are only compiled when the `async` feature is enabled.
#![cfg(feature = "async")]
use optimize::{Direction, RandomSampler, Study, TpeError, TpeSampler};
use optimizer::{Direction, RandomSampler, Study, TpeError, TpeSampler};
#[tokio::test]
async fn test_optimize_async_basic() {
+4 -4
View File
@@ -1,6 +1,6 @@
//! Integration tests for the optimize library.
//! Integration tests for the optimizer library.
use optimize::{Direction, RandomSampler, Study, TpeError, TpeSampler, Trial};
use optimizer::{Direction, RandomSampler, Study, TpeError, TpeSampler, Trial};
// =============================================================================
// Test: optimize simple quadratic function with TPE, finds near-optimal
@@ -671,7 +671,7 @@ fn test_study_direction() {
#[test]
fn test_trial_state() {
use optimize::TrialState;
use optimizer::TrialState;
let trial = Trial::new(0);
assert_eq!(trial.state(), TrialState::Running);
@@ -863,7 +863,7 @@ fn test_trial_debug_format() {
#[test]
fn test_tpe_sampler_builder_default_trait() {
use optimize::TpeSamplerBuilder;
use optimizer::TpeSamplerBuilder;
let builder = TpeSamplerBuilder::default();
let sampler = builder.build();