Skip to main content

MultiTargetSGBT

Struct MultiTargetSGBT 

Source
pub struct MultiTargetSGBT<L: Loss = SquaredLoss> { /* private fields */ }
Available on crate feature alloc only.
Expand description

Multi-target regression SGBT.

Wraps T independent SGBT<L> models, one per target dimension. Each model is trained and predicts independently, sharing the same configuration and loss function.

§Examples

use irithyll::ensemble::multi_target::MultiTargetSGBT;
use irithyll::SGBTConfig;

let config = SGBTConfig::builder()
    .n_steps(10)
    .learning_rate(0.1)
    .grace_period(10)
    .build()
    .unwrap();

let mut model = MultiTargetSGBT::new(config, 3).unwrap();
model.train_one(&[1.0, 2.0], &[0.5, 1.0, 1.5]);
let preds = model.predict(&[1.0, 2.0]);
assert_eq!(preds.len(), 3);

Implementations§

Source§

impl MultiTargetSGBT<SquaredLoss>

Source

pub fn new(config: SGBTConfig, n_targets: usize) -> Result<Self>

Create a new multi-target SGBT with squared loss (default).

§Errors

Returns IrithyllError::InvalidConfig if n_targets < 1.

Source§

impl<L: Loss + Clone> MultiTargetSGBT<L>

Source

pub fn with_loss(config: SGBTConfig, loss: L, n_targets: usize) -> Result<Self>

Create a new multi-target SGBT with a custom loss function.

The loss is cloned for each target model.

§Errors

Returns IrithyllError::InvalidConfig if n_targets < 1.

Source

pub fn train_one(&mut self, features: &[f64], targets: &[f64])

Train on a single sample with multiple target values.

§Panics

Panics if targets.len() != n_targets.

Source

pub fn train_batch( &mut self, feature_matrix: &[Vec<f64>], target_matrix: &[Vec<f64>], )

Train on a batch of multi-target samples.

Source

pub fn predict(&self, features: &[f64]) -> Vec<f64>

Predict all target values for a feature vector.

Source

pub fn n_targets(&self) -> usize

Number of target dimensions.

Source

pub fn n_samples_seen(&self) -> u64

Total samples trained.

Source

pub fn model(&self, idx: usize) -> &SGBT<L>

Access the model for a specific target dimension.

§Panics

Panics if idx >= n_targets.

Source

pub fn models(&self) -> &[SGBT<L>]

Access all target models.

Source

pub fn reset(&mut self)

Reset all target models.

Trait Implementations§

Source§

impl<L: Loss + Clone> Clone for MultiTargetSGBT<L>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<L: Debug + Loss> Debug for MultiTargetSGBT<L>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.