{"record":{"id":"25f10a405a9bf98e","repo":"tracel-ai/burn","slug":"standard-deviation-is-required-to-be-non-negative","errorCode":null,"errorMessage":"Standard deviation is required to be non-negative, but got {}","messagePattern":"Standard deviation is required to be non-negative, but got (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-nn/src/modules/noise.rs","lineNumber":36,"sourceCode":"/// distortion.\n///\n/// Should be created with [GaussianNoiseConfig].\n#[derive(Module, Debug)]\n#[module(custom_display)]\npub struct GaussianNoise {\n    /// Standard deviation of the normal noise distribution.\n    pub std: f64,\n    /// Whether to behave as during training. Cleared by\n    /// [`freeze`](burn::module::Module::freeze) and matching\n    /// [`freeze_group`](burn::module::Module::freeze_group) traversals.\n    pub training: Param<Flag>,\n}\n\nimpl GaussianNoiseConfig {\n    /// Initialize a new [Gaussian noise](GaussianNoise) module.\n    pub fn init(&self) -> GaussianNoise {\n        if self.std.is_sign_negative() {\n            panic!(\n                \"Standard deviation is required to be non-negative, but got {}\",\n                self.std\n            );\n        }\n        GaussianNoise {\n            std: self.std,\n            training: Param::from_bool(true),\n        }\n    }\n}\n\nimpl GaussianNoise {\n    /// Applies the forward pass on the input tensor.\n    ///\n    /// See [GaussianNoise](GaussianNoise) for more information.\n    ///\n    /// # Shapes\n    ///","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-nn/src/modules/noise.rs#L18-L54","documentation":"GaussianNoiseConfig::init in burn-nn panics when the configured standard deviation is negative (std.is_sign_negative() is true, which also catches -0.0). A Gaussian noise layer is parameterized by a standard deviation, which is mathematically undefined for negative values, so the library rejects the config at initialization time rather than producing undefined sampling behavior later.","triggerScenarios":"Calling GaussianNoiseConfig::init() (or building it via GaussianNoiseConfig::new(std)) with a negative std, e.g. GaussianNoiseConfig::new(-0.5). Also triggered by std = -0.0, or a std computed from a formula/sign-flip (e.g. -temperature, 1.0 - x where x > 1) that went negative at runtime.","commonSituations":"Sign errors when wiring hyperparameters (noise = -sigma), loading noise magnitude from a config file with a stray minus sign, computing std as a difference that underflows below zero (e.g. start_noise - end_noise with swapped bounds), or hand-tuned sweeps that iterate sigma over a range including negatives.","solutions":["Pass a non-negative standard deviation to GaussianNoiseConfig::new(...) (strictly positive if you want actual noise; use 0.0 to disable).","Clamp computed values: std = std.max(0.0) before constructing the config.","If std comes from a sweep or external config, validate range (0.0..=upper_bound) before init().","Check for accidental sign flips in the expression that produces std."],"exampleFix":"// before\nlet cfg = GaussianNoiseConfig::new(-0.5);\nlet noise = cfg.init(); // panics\n// after\nlet sigma = 0.5_f64.max(0.0);\nlet cfg = GaussianNoiseConfig::new(sigma);\nlet noise = cfg.init();","handlingStrategy":"validation","validationCode":"// before GaussianNoiseConfig::init()\nassert!(!std_dev.is_sign_negative(), \"std must be non-negative, got {}\", std_dev);","typeGuard":"fn is_valid_std(std: f64) -> bool {\n    std.is_finite() && !std.is_sign_negative()\n}","tryCatchPattern":"let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| config.init()));\nmatch result {\n    Ok(module) => module,\n    Err(_) => GaussianNoiseConfig::new(0.0).init(), // noise disabled fallback\n}","preventionTips":["Clamp any computed sigma with .max(0.0) before constructing the config.","Validate externally-sourced noise magnitudes are in a sane range (0.0..=1.0) at load time.","Watch for -0.0: is_sign_negative() rejects it too, so normalize -0.0 to 0.0."],"tags":["rust","burn-nn","panic","config-validation","gaussian-noise"],"backgroundTag":"negative-standard-deviation","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}