Tests referenced old DQNParams fields (learning_rate, batch_size, ensemble_size, etc.) that were absorbed into family intensity scalars. Rewrote all affected tests to validate the 14D search space layout, intensity bounds [0.0, 2.0], and round-trip serialization. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
153 lines
5.3 KiB
Rust
153 lines
5.3 KiB
Rust
#![allow(
|
|
clippy::assertions_on_constants,
|
|
clippy::assertions_on_result_states,
|
|
clippy::clone_on_copy,
|
|
clippy::decimal_literal_representation,
|
|
clippy::doc_markdown,
|
|
clippy::empty_line_after_doc_comments,
|
|
clippy::field_reassign_with_default,
|
|
clippy::get_unwrap,
|
|
clippy::identity_op,
|
|
clippy::inconsistent_digit_grouping,
|
|
clippy::indexing_slicing,
|
|
clippy::integer_division,
|
|
clippy::len_zero,
|
|
clippy::let_underscore_must_use,
|
|
clippy::manual_div_ceil,
|
|
clippy::manual_let_else,
|
|
clippy::manual_range_contains,
|
|
clippy::modulo_arithmetic,
|
|
clippy::needless_range_loop,
|
|
clippy::non_ascii_literal,
|
|
clippy::redundant_clone,
|
|
clippy::shadow_reuse,
|
|
clippy::shadow_same,
|
|
clippy::shadow_unrelated,
|
|
clippy::single_match_else,
|
|
clippy::str_to_string,
|
|
clippy::string_slice,
|
|
clippy::tests_outside_test_module,
|
|
clippy::too_many_lines,
|
|
clippy::unnecessary_wraps,
|
|
clippy::unseparated_literal_suffix,
|
|
clippy::use_debug,
|
|
clippy::useless_vec,
|
|
clippy::wildcard_enum_match_arm,
|
|
clippy::else_if_without_else,
|
|
clippy::expect_used,
|
|
clippy::missing_const_for_fn,
|
|
clippy::similar_names,
|
|
clippy::type_complexity,
|
|
clippy::collapsible_else_if,
|
|
clippy::doc_lazy_continuation,
|
|
clippy::items_after_test_module,
|
|
clippy::map_clone,
|
|
clippy::multiple_unsafe_ops_per_block,
|
|
clippy::unwrap_or_default,
|
|
clippy::assign_op_pattern,
|
|
clippy::needless_borrow,
|
|
clippy::println_empty_string,
|
|
clippy::unnecessary_cast,
|
|
clippy::used_underscore_binding,
|
|
clippy::create_dir,
|
|
clippy::implicit_saturating_sub,
|
|
clippy::exit,
|
|
clippy::expect_fun_call,
|
|
clippy::too_many_arguments,
|
|
clippy::unnecessary_map_or,
|
|
clippy::unwrap_used,
|
|
dead_code,
|
|
unused_imports,
|
|
unused_variables,
|
|
clippy::cloned_ref_to_slice_refs,
|
|
clippy::neg_multiply,
|
|
clippy::while_let_loop,
|
|
clippy::bool_assert_comparison,
|
|
clippy::excessive_precision,
|
|
clippy::trivially_copy_pass_by_ref,
|
|
clippy::op_ref,
|
|
clippy::redundant_closure,
|
|
clippy::unnecessary_lazy_evaluations,
|
|
clippy::if_then_some_else_none,
|
|
clippy::unnecessary_to_owned,
|
|
clippy::single_component_path_imports,
|
|
)]
|
|
//! Hyperopt search space dimension tests (updated for 14D family-intensity structure).
|
|
//!
|
|
//! Kelly params (kelly_fractional, kelly_max_fraction, etc.) are now fixed at TOML
|
|
//! defaults and absorbed into the risk_intensity family. The search space is 14D.
|
|
|
|
#[cfg(test)]
|
|
mod hyperopt_kelly_params_tests {
|
|
use ml::hyperopt::adapters::dqn::DQNParams;
|
|
use ml::hyperopt::traits::ParameterSpace;
|
|
|
|
#[test]
|
|
fn test_search_space_has_14_dimensions() {
|
|
let bounds = DQNParams::continuous_bounds();
|
|
assert_eq!(bounds.len(), 14, "Search space should be 14D (3 breakouts + 5 core + 6 gen families)");
|
|
}
|
|
|
|
#[test]
|
|
fn test_risk_intensity_bounds() {
|
|
let bounds = DQNParams::continuous_bounds();
|
|
let names = DQNParams::param_names();
|
|
let risk_idx = names.iter().position(|&n| n == "risk_intensity")
|
|
.expect("risk_intensity should be in param_names");
|
|
let (min, max) = bounds[risk_idx];
|
|
assert_eq!(min, 0.0, "risk_intensity min should be 0.0");
|
|
assert_eq!(max, 2.0, "risk_intensity max should be 2.0");
|
|
}
|
|
|
|
#[test]
|
|
fn test_from_continuous_accepts_14d() {
|
|
let bounds = DQNParams::continuous_bounds();
|
|
let x: Vec<f64> = bounds.iter().map(|(lo, hi)| (lo + hi) / 2.0).collect();
|
|
assert_eq!(x.len(), 14);
|
|
|
|
let result = DQNParams::from_continuous(&x);
|
|
assert!(result.is_ok(), "Should accept 14D parameter vector");
|
|
|
|
let params = result.unwrap();
|
|
assert!((params.gamma - 0.9745).abs() < 0.001, "gamma should be midpoint of [0.95, 0.999]");
|
|
assert!((params.risk_intensity - 1.0).abs() < 1e-6, "risk_intensity should be 1.0 at midpoint");
|
|
}
|
|
|
|
#[test]
|
|
fn test_from_continuous_rejects_wrong_dimensions() {
|
|
// Too few dimensions
|
|
let x_short = vec![0.97; 13];
|
|
let result_short = DQNParams::from_continuous(&x_short);
|
|
assert!(result_short.is_err(), "Should reject 13D parameter vector");
|
|
|
|
// Too many dimensions
|
|
let x_long = vec![0.97; 15];
|
|
let result_long = DQNParams::from_continuous(&x_long);
|
|
assert!(result_long.is_err(), "Should reject 15D parameter vector");
|
|
}
|
|
|
|
#[test]
|
|
fn test_all_intensity_bounds_are_0_to_2() {
|
|
let bounds = DQNParams::continuous_bounds();
|
|
let names = DQNParams::param_names();
|
|
for (i, name) in names.iter().enumerate() {
|
|
if name.ends_with("_intensity") {
|
|
let (lo, hi) = bounds[i];
|
|
assert_eq!(lo, 0.0, "{name} lower bound should be 0.0");
|
|
assert_eq!(hi, 2.0, "{name} upper bound should be 2.0");
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_breakout_params_have_specific_bounds() {
|
|
let bounds = DQNParams::continuous_bounds();
|
|
// gamma at index 0
|
|
assert_eq!(bounds[0], (0.95, 0.999), "gamma bounds should be (0.95, 0.999)");
|
|
// iqn_lambda at index 1
|
|
assert_eq!(bounds[1], (0.0, 1.0), "iqn_lambda bounds should be (0.0, 1.0)");
|
|
// c51_warmup_epochs at index 2
|
|
assert_eq!(bounds[2], (3.0, 15.0), "c51_warmup_epochs bounds should be (3.0, 15.0)");
|
|
}
|
|
}
|