Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/adam w #237

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion delta/src/classical_ml/losses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ where
.zip(actuals.iter())
.map(|(p, y)| {
let p_clamped = p.max(epsilon).min(T::one() - epsilon);
-(y.clone() * p_clamped.ln() + (T::one() - y.clone()) * (T::one() - p_clamped).ln())
-(*y * p_clamped.ln() + (T::one() - *y) * (T::one() - p_clamped).ln())
})
.sum::<T>()
/ m
Expand Down
2 changes: 1 addition & 1 deletion delta/src/deep_learning/dataset/vision/cifar10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Cifar10Dataset {
let path = entry.path().unwrap().into_owned();
let file_name = path.file_name().unwrap().to_string_lossy().to_string();

if path.is_dir() || !path.extension().map_or(false, |ext| ext == "bin") {
if path.is_dir() || path.extension().is_none_or(|ext| ext != "bin") {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion delta/src/deep_learning/dataset/vision/cifar100.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Cifar100Dataset {
let path = entry.path().unwrap().into_owned();
let file_name = path.file_name().unwrap().to_string_lossy().to_string();

if path.is_dir() || !path.extension().map_or(false, |ext| ext == "bin") {
if path.is_dir() || path.extension().is_none_or(|ext| ext != "bin") {
continue;
}

Expand Down
15 changes: 15 additions & 0 deletions delta/src/deep_learning/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ pub enum OptimizerError {
IncompatibleGradientWeightShape(Vec<usize>, Vec<usize>),
/// Error when epsilon is not set or is invalid.
InvalidEpsilon(String),
/// Error when beta parameter is invalid.
InvalidBeta(String),
/// Error when weight decay parameter is invalid.
InvalidWeightDecay(String),
/// Error when gradient contains invalid values (NaN or Inf).
InvalidGradient(String),
/// Error when weight contains invalid values (NaN or Inf).
InvalidWeight(String),
/// Error when shapes don't match
ShapeMismatch(String),
}

/// An enumeration of possible errors that can occur in a model.
Expand Down Expand Up @@ -105,6 +115,11 @@ impl fmt::Display for OptimizerError {
write!(f, "Gradient shape {:?} is incompatible with weight shape {:?}", g, w)
}
OptimizerError::InvalidEpsilon(s) => write!(f, "{}", s),
OptimizerError::InvalidBeta(s) => write!(f, "{}", s),
OptimizerError::InvalidWeightDecay(s) => write!(f, "{}", s),
OptimizerError::InvalidGradient(s) => write!(f, "{}", s),
OptimizerError::InvalidWeight(s) => write!(f, "{}", s),
OptimizerError::ShapeMismatch(s) => write!(f, "Shape mismatch: {}", s),
}
}
}
Expand Down
Loading
Loading