pub struct ConstraintLoss { /* private fields */ }Expand description
Constraint-aware loss wrapper
Bridges kizzasi-logic constraints with candle tensor operations. Allows combining task loss with constraint violations for constrained optimization.
§Examples
ⓘ
use kizzasi_core::{ConstraintLoss, Loss};
let constraint_loss = ConstraintLoss::new(0.1);
// In training loop:
let task_loss = Loss::mse(&predictions, &targets)?;
let total_loss = constraint_loss.compute(&task_loss, &predictions, |pred| {
// Compute constraint violation from prediction
Ok(0.0)
})?;Implementations§
Source§impl ConstraintLoss
impl ConstraintLoss
Sourcepub fn compute<F>(
&self,
task_loss: &Tensor,
prediction: &Tensor,
constraint_fn: F,
) -> CoreResult<Tensor>
pub fn compute<F>( &self, task_loss: &Tensor, prediction: &Tensor, constraint_fn: F, ) -> CoreResult<Tensor>
Compute combined loss: task_loss + constraint_weight * constraint_penalty
§Arguments
task_loss- Base task loss (MSE, MAE, etc.)prediction- Model prediction tensorconstraint_fn- Function that computes constraint violation from prediction
Auto Trait Implementations§
impl Freeze for ConstraintLoss
impl RefUnwindSafe for ConstraintLoss
impl Send for ConstraintLoss
impl Sync for ConstraintLoss
impl Unpin for ConstraintLoss
impl UnsafeUnpin for ConstraintLoss
impl UnwindSafe for ConstraintLoss
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more