fugue_evo/interactive/mod.rs
1//! Interactive Genetic Algorithm (IGA) module
2//!
3//! This module provides support for human-in-the-loop evolutionary optimization,
4//! where fitness is derived from user preferences rather than an automated function.
5//!
6//! # Overview
7//!
8//! Interactive GAs are useful when:
9//! - The fitness function cannot be easily formalized
10//! - Human aesthetic judgment is needed (art, design, music generation)
11//! - User preferences are subjective and vary per individual
12//!
13//! # Evaluation Modes
14//!
15//! The module supports three interaction paradigms:
16//!
17//! - **Rating**: Users assign numeric scores to individual candidates
18//! - **Pairwise Comparison**: Users pick the better of two candidates
19//! - **Batch Selection**: Users select their favorites from a presented batch
20//!
21//! # Example
22//!
23//! ```rust,no_run
24//! use fugue_evo::interactive::prelude::*;
25//! use fugue_evo::prelude::*;
26//! # use rand::SeedableRng;
27//! # fn present_to_user(_request: &EvaluationRequest<RealVector>) -> EvaluationResponse {
28//! # unimplemented!("show the candidates to a person and collect their choice")
29//! # }
30//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
31//! # let mut rng = rand::rngs::StdRng::seed_from_u64(0);
32//! # let bounds = MultiBounds::symmetric(1.0, 4);
33//!
34//! let mut iga = InteractiveGABuilder::<RealVector, (), (), ()>::new()
35//! .population_size(12)
36//! .evaluation_mode(EvaluationMode::BatchSelection)
37//! .batch_size(6)
38//! .bounds(bounds)
39//! .selection(TournamentSelection::new(2))
40//! .crossover(SbxCrossover::new(15.0))
41//! .mutation(PolynomialMutation::new(20.0))
42//! .build()?;
43//!
44//! loop {
45//! match iga.step(&mut rng) {
46//! StepResult::NeedsEvaluation(request) => {
47//! let response = present_to_user(&request);
48//! iga.provide_response(response);
49//! }
50//! StepResult::GenerationComplete { generation, .. } => {
51//! println!("Generation {} complete", generation);
52//! }
53//! StepResult::Complete(result) => {
54//! println!("Done: {}", result.termination_reason);
55//! break;
56//! }
57//! }
58//! }
59//! # Ok(())
60//! # }
61//! ```
62
63pub mod aggregation;
64pub mod algorithm;
65pub mod bradley_terry;
66pub mod evaluator;
67pub mod selection_strategy;
68pub mod session;
69pub mod traits;
70pub mod uncertainty;
71
72/// Prelude for convenient imports
73pub mod prelude {
74 pub use super::aggregation::{AggregationModel, CandidateStats, FitnessAggregator};
75 pub use super::algorithm::{
76 InteractiveGA, InteractiveGABuilder, InteractiveGAConfig, InteractiveResult, StepResult,
77 };
78 pub use super::bradley_terry::{BradleyTerryModel, BradleyTerryOptimizer, BradleyTerryResult};
79 pub use super::evaluator::{
80 Candidate, CandidateId, EvaluationRequest, EvaluationResponse, RatingScale,
81 };
82 pub use super::selection_strategy::SelectionStrategy;
83 pub use super::session::{CoverageStats, InteractiveSession};
84 pub use super::traits::{EvaluationMode, InteractiveFitness};
85 pub use super::uncertainty::FitnessEstimate;
86}