Shrinkage

shrinkage::DisjointGroups

Shrinkage for Rust · rust · 0.3.0

pub struct DisjointGroups

Validated disjoint groups of optimization-scale coefficient indices.

Groups and their members retain the supplied order. Indices address a vector of ncoefficients entries, excluding intercepts. For a flattened coefficient matrix, use crate::CoefficientLayout::index to respect its response-major layout. Each coefficient belongs to at most one group.

Supply one finite, nonnegative weight per group. Weights are multipliers of group penalty values, stored without adjustment for group size or count. A zero weight still counts as coverage and must obey all membership rules. The coverage policy explicitly requires full coverage or leaves uncovered coefficients unpenalized. All definitions are checked at construction and exposed through immutable slices.

use shrinkage::{DisjointGroups, UncoveredPolicy};

let groups = DisjointGroups::new(
    5,
    vec![vec![3, 1], vec![0]],
    vec![0.5, 2.0],
    UncoveredPolicy::Unpenalized,
)?;
assert_eq!(groups.groups(), [vec![3, 1], vec![0]]);
assert_eq!(groups.weights(), [0.5, 2.0]);
assert_eq!(groups.uncovered(), [2, 4]);

Inherent implementation

impl DisjointGroups

groups

pub fn groups(&self) -> &[Vec<usize>]

Disjoint index vectors in their supplied group and member order.

ncoefficients

pub fn ncoefficients(&self) -> usize

Coefficient vector length, excluding intercepts.

new

pub fn new(
    ncoefficients: usize,
    groups: Vec<Vec<usize>>,
    weights: Vec<f64>,
    uncovered_policy: UncoveredPolicy
) -> Result<Self, FitError>

Validate and own weighted groups over a fixed coefficient vector.

Individual groups must be nonempty. An empty collection is valid for zero coefficients under either policy, or for any coefficient count under UncoveredPolicy::Unpenalized.

Errors

Reject a weight count different from the group count, nonfinite or negative weights, empty groups, repeated indices within a group, overlapping groups (including duplicate groups), or indices outside 0..ncoefficients. UncoveredPolicy::Reject also rejects any coefficient omitted from the groups. Errors identify group and coefficient indices using zero-based numbering when applicable.

uncovered

pub fn uncovered(&self) -> &[usize]

Uncovered coefficient indices in increasing order.

Always empty under UncoveredPolicy::Reject. Under UncoveredPolicy::Unpenalized, these coefficients remain unpenalized.

uncovered_policy

pub fn uncovered_policy(&self) -> UncoveredPolicy

Policy governing coefficients outside every group.

weights

pub fn weights(&self) -> &[f64]

One finite, nonnegative weight per group, in group order.

Implementation of Clone

impl Clone for DisjointGroups

clone

fn clone(&self) -> Self

Implementation of Debug

impl Debug for DisjointGroups

fmt

fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result

Implementation of Freeze

impl Freeze for DisjointGroups

Implementation of RefUnwindSafe

impl RefUnwindSafe for DisjointGroups

Implementation of Send

impl Send for DisjointGroups

Implementation of Sync

impl Sync for DisjointGroups

Implementation of Unpin

impl Unpin for DisjointGroups

Implementation of UnsafeUnpin

impl UnsafeUnpin for DisjointGroups

Implementation of UnwindSafe

impl UnwindSafe for DisjointGroups

Implementation of Any

impl<T> Any for T where T: 'static + ?Sized

Implementation of Borrow

impl<T> Borrow<T> for T where T: ?Sized

Implementation of BorrowMut

impl<T> BorrowMut<T> for T where T: ?Sized

Implementation of ByRef

impl<T> ByRef<T> for T

Implementation of CastableFrom

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT where ST: ?Sized, DT: ?Sized

Implementation of CastableFrom

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT where ST: ?Sized, DT: ?Sized

Implementation of CloneToUninit

impl<T> CloneToUninit for T where T: Clone

Implementation of From

impl<T> From<T> for T

Implementation of Imply

impl<T, U> Imply<T> for U where T: ?Sized, U: ?Sized

Implementation of Into

impl<T, U> Into<U> for T where U: From<T>

Implementation of IntoEither

impl<T> IntoEither for T

Implementation of Pointable

impl<T> Pointable for T

Implementation of Read

impl<T> Read<Exclusive, BecauseExclusive> for T where T: ?Sized

Implementation of Same

impl<T> Same for T

Implementation of SupersetOf

impl<SS, SP> SupersetOf<SS> for SP where SS: SubsetOf<SP>

Implementation of ToOwned

impl<T> ToOwned for T where T: Clone

Implementation of TryFrom

impl<T, U> TryFrom<U> for T where U: Into<T>

Implementation of TryInto

impl<T, U> TryInto<U> for T where U: TryFrom<T>