pub fn compute_loss(logits: ArrayView2<f32>, labels: ArrayView1<Option<NonZeroUsize>>) -> f32 {
	let mut loss = 0.0;
	for (label, logits) in zip!(labels.into_iter(), logits.axis_iter(Axis(0))) {
		let mut probabilities = logits.to_owned();
		softmax(probabilities.as_slice_mut().unwrap());
		for (index, &probability) in probabilities.indexed_iter() {
			let probability = clamp(probability, std::f32::EPSILON, 1.0 - std::f32::EPSILON);
			if index == (label.unwrap().get() - 1) {
				loss += -probability.ln();
			}
		}
	}
	loss / labels.len().to_f32().unwrap()
}
/// This function is used by the common train function to compute the loss after each tree is trained for multiclass classification.
This function is used by the common train function to compute the loss after each tree is trained for multiclass classification.
This function is used by the common train function to compute the loss after each tree is trained for multiclass classification .
pub fn compute_loss(logits: ArrayView2<f32>, labels: ArrayView1<Option<NonZeroUsize>>) -> f32 {
	let mut loss = 0.0;
	for (label, logits) in zip!(labels.into_iter(), logits.axis_iter(Axis(0))) {
		let mut probabilities = logits.to_owned();
		softmax(probabilities.as_slice_mut().unwrap());
		for (index, &probability) in probabilities.indexed_iter() {
			let probability = clamp(probability, std::f32::EPSILON, 1.0 - std::f32::EPSILON);
			if index == (label.unwrap().get() - 1) {
				loss += -probability.ln();
			}
		}
	}
	loss / labels.len().to_f32().unwrap()
}
pub fn compute_loss ( logits : ArrayView2 < f32 > , labels : ArrayView1 < Option < NonZeroUsize > > ) -> f32 { let mut loss = 0.0 ; for ( label , logits ) in zip ! ( labels into_iter ( ) logits axis_iter ( Axis ( 0 ) ) ) { let mut probabilities = logits . to_owned ( ) ; softmax ( probabilities . as_slice_mut ( ) . unwrap ( ) ) ; for ( index , & probability ) in probabilities . indexed_iter ( ) { let probability = clamp ( probability , std :: f32 :: EPSILON , 1.0 - std :: f32 :: EPSILON ) ; if index == ( label . unwrap ( ) . get ( ) - 1 ) { loss += - probability . ln ( ) ; } } } loss / labels . len ( ) . to_f32 ( ) . unwrap ( ) }
This function is used by the common train function to compute the loss after each tree is trained for multiclass classification.
This function is used by the common train function to compute the loss after each tree is trained for multiclass classification .
logits
ArrayView2<f32>
labels
ArrayView1<Option<NonZeroUsize>>