(cov: &DMatrix<f64>, bounds: &[(f64, f64)])
| 280 | } |
| 281 | |
| 282 | fn inverse_variance(cov: &DMatrix<f64>, bounds: &[(f64, f64)]) -> Result<Vec<f64>, AllocError> { |
| 283 | check_bounds_feasible(bounds)?; |
| 284 | let diag = cov.diagonal(); |
| 285 | if diag.iter().any(|v| *v == 0.0) { |
| 286 | return Err(AllocError::OptimizationFailed("covariance contained zero on diagonal")); |
| 287 | } |
| 288 | let mut ivp: Vec<f64> = diag.iter().map(|v| 1.0 / v).collect(); |
| 289 | let sum: f64 = ivp.iter().sum(); |
| 290 | if sum == 0.0 { |
| 291 | return Err(AllocError::OptimizationFailed("zero inverse variance sum")); |
| 292 | } |
| 293 | for v in ivp.iter_mut() { |
| 294 | *v /= sum; |
| 295 | } |
| 296 | project_to_bounds(&mut ivp, bounds)?; |
| 297 | Ok(ivp) |
| 298 | } |
| 299 | |
| 300 | fn solve_min_vol(cov: &DMatrix<f64>, bounds: &[(f64, f64)]) -> Result<Vec<f64>, AllocError> { |
| 301 | check_bounds_feasible(bounds)?; |
no test coverage detected