# shrinkage::RuntimeProblem

Shrinkage for Rust · 0.3.0

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/problem/runtime.rs>)

```rust
pub type RuntimeProblem<'a> = shrinkage::Problem<Box<dyn RuntimeDesign + 'a>, Box<dyn SmoothDatafit + 'a>, Box<dyn ProximalPenalty + 'a>>;
```

A problem whose design, smooth datafit, and complete proximal term are selected independently before fitting. 

The shared iteration calls object-safe oracles for complete products, loss and gradient evaluations, and proximal operations. It does not erase an already composed typed problem. Use [`MatrixDesign`](<d52234a7db90a8cebd6a9c7a010ac7241fd7bed88c81ce410a9ad36a79d5fe4f>) to adapt each concrete backend once, independently of the chosen datafit and penalty. 

[`ProximalGradient<Vec<f64>>`](<dbf207e0ed64fdc5c0f5cc6c364e567527bca92737c69f45f608ed62e8d669d5>) fits this problem, while adapters retain each backend's native vector type. Normalization and supplied vectors use the same builders and semantics as the typed [`Problem`](<4fd51b866367bd6673d82fc698be06078f421c181aef012c7bc5b92a97232647>). Selecting [`CoordinateDescent`](<a483abd31a32ac227c08ded97cd2308397e21a231635317d7b09559f288d410d>) returns [`FitError::UnsupportedCombination`](<1b3b3442a395454abc564cf4b94d07f97e67975dd92cef1ff14dba46f928b87f#variant-UnsupportedCombination>) before preparing the design: these oracles do not expose its Gaussian/L1 coordinate updates and dual certificate. Use proximal gradient here, or a typed Gaussian/L1 problem with coordinate descent. A value-only datafit or penalty cannot be boxed into the required capability traits. 

```rust
use shrinkage::{FitError, Penalty, ProximalPenalty};
fn select_penalty<P: Penalty<Error = FitError> + 'static>(penalty: P)
    -> Box<dyn ProximalPenalty>
{
    Box::new(penalty)
}
```

```rust
use shrinkage::{Datafit, FitError, SmoothDatafit};
fn select_datafit<D: Datafit<Error = FitError> + 'static>(datafit: D)
    -> Box<dyn SmoothDatafit>
{
    Box::new(datafit)
}
```

```rust
use faer::{Col, Mat};
use shrinkage::{Gaussian, MatrixDesign, ProximalGradient, Ridge, RuntimeProblem};
let x = Mat::from_fn(3, 1, |i, _| i as f64);
let y = [1.0, 3.0, 5.0];
let problem = RuntimeProblem::new(
    Box::new(MatrixDesign::<_, Col<f64>>::new(&x)),
    Box::new(Gaussian::new(&y)),
    Box::new(Ridge::new(0.1)),
);
let fit = problem.fit_with(&ProximalGradient::new())?;
let predictions = fit.predict(&x)?;
```
