Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ pub mod bayesian_mcmc;
pub mod beam;
/// Implements genetic algorithm functionalities.
pub mod ga;
/// Implements simulated annealing.
pub mod sa;

use crate::aco::aco as aco_run;
use crate::bayesian_mcmc::mcmc;
use crate::beam::{beam, keep_n_best_model_within_collection};
use crate::experiment::{Experiment, ExperimentMetadata};
use crate::ga::ga;
use crate::sa::sa as sa_run;
use chrono::Local;
use cv::CV;
use data::Data;
Expand Down Expand Up @@ -660,6 +663,11 @@ pub fn run_training(
(collection, meta) = aco_run(data, &mut None, initial_pop, &param, running);
final_population = collection[collection.len() - 1].clone()
}
"sa" => {
cinfo!(param.general.display_colorful, "Training using Simulated Annealing\n-----------------------------------------------------");
(collection, meta) = (sa_run(data, &mut None, initial_pop, &param, running), None);
final_population = collection[collection.len() - 1].clone()
}
_ => {
panic!("Unknown algorithm: {}", param.general.algo);
}
Expand Down
68 changes: 68 additions & 0 deletions src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::error::Error;

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[allow(non_camel_case_types)]

Check warning on line 10 in src/param.rs

View workflow job for this annotation

GitHub Actions / lint

empty line after outer attribute

/// Fit function options for model evaluation
pub enum FitFunction {
Expand Down Expand Up @@ -125,6 +125,10 @@
#[serde(default)]
pub aco: ACO,

/// Simulated Annealing parameters section
#[serde(default)]
pub sa: SA,

/// Voting ensemble parameters section
#[serde(default)]
pub voting: Voting,
Expand Down Expand Up @@ -425,6 +429,35 @@
pub max_age_best_model: usize,
}

/// Simulated Annealing parameters
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[allow(missing_docs)]
pub struct SA {
/// Initial temperature (higher = more exploration)
#[serde(default = "one_f64_default")]
pub initial_temperature: f64,
/// Cooling rate per iteration (T *= cooling_rate)
#[serde(default = "sa_cooling_rate_default")]
pub cooling_rate: f64,
/// Stop when temperature drops below this
#[serde(default = "sa_min_temp_default")]
pub min_temperature: f64,
/// Maximum number of iterations
#[serde(default = "sa_max_iterations_default")]
pub max_iterations: usize,
/// Iterations between snapshots (for generation_tracking)
#[serde(default = "sa_snapshot_interval_default")]
pub snapshot_interval: usize,
/// Minimum number of features per model
#[serde(default = "one_default")]
#[serde(alias = "kmin")]
pub k_min: usize,
/// Maximum number of features per model (0 = no limit)
#[serde(default = "k_max_default")]
#[serde(alias = "kmax")]
pub k_max: usize,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[allow(missing_docs)]
pub struct GPU {
Expand Down Expand Up @@ -511,6 +544,12 @@
}
}

impl Default for SA {
fn default() -> Self {
serde_json::from_value(serde_json::json!({})).unwrap()
}
}

impl Default for Experimental {
fn default() -> Self {
serde_json::from_value(serde_json::json!({})).unwrap()
Expand Down Expand Up @@ -733,6 +772,21 @@
.cloned()
.collect();

let valid_sa_keys: HashSet<&str> = [
"initial_temperature",
"cooling_rate",
"min_temperature",
"max_iterations",
"snapshot_interval",
"k_min",
"kmin",
"k_max",
"kmax",
]
.iter()
.cloned()
.collect();

let valid_gpu_keys: HashSet<&str> = [
"memory_policy",
"max_total_memory_mb",
Expand Down Expand Up @@ -764,6 +818,7 @@
"beam",
"mcmc",
"aco",
"sa",
"gpu",
"importance",
"experimental",
Expand Down Expand Up @@ -794,6 +849,7 @@
"beam" => &valid_beam_keys,
"mcmc" => &valid_mcmc_keys,
"aco" => &valid_aco_keys,
"sa" => &valid_sa_keys,
"gpu" => &valid_gpu_keys,
"importance" => &valid_importance_keys,
"experimental" => &valid_experimental_keys,
Expand Down Expand Up @@ -1019,7 +1075,7 @@
Ok(())
}

/// Default value definitions

Check warning on line 1078 in src/param.rs

View workflow job for this annotation

GitHub Actions / lint

empty line after doc comment

fn seed_default() -> u64 {
4815162342
Expand Down Expand Up @@ -1108,6 +1164,18 @@
fn one_f64_default() -> f64 {
1.0
}
fn sa_cooling_rate_default() -> f64 {
0.995
}
fn sa_min_temp_default() -> f64 {
0.001
}
fn sa_max_iterations_default() -> usize {
10000
}
fn sa_snapshot_interval_default() -> usize {
100
}
fn specialist_threshold_default() -> f64 {
0.7
}
Expand Down
Loading
Loading