Skip to content
Merged
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 .github/workflows/checking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
matrix:
toolchain:
- 1.70.0
- 1.71.1
- stable
- nightly
os:
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/codequality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
matrix:
toolchain:
- 1.70.0
- 1.71.1
- stable

steps:
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
run: echo "::set-output name=version::$(cargo --version | cut -d ' ' -f 2)"
shell: bash

- uses: actions/cache@v2
- uses: actions/cache@v4
id: tarpaulin-cache
with:
path: |
Expand All @@ -61,6 +61,8 @@ jobs:
run: |
cargo tarpaulin --verbose --timeout 120 --out Xml --all --release
- name: Upload to codecov.io
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
matrix:
toolchain:
- 1.70.0
- 1.71.1
- stable
os:
- ubuntu-latest
Expand All @@ -35,7 +35,7 @@ jobs:
fail-fast: false
matrix:
toolchain:
- 1.70.0
- 1.71.1
- stable
os:
- ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions algorithms/linfa-bayes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

`linfa-bayes` currently provides an implementation of the following methods:

- Gaussian Naive Bayes ([`GaussianNb`](crate::GaussianNb))
- Multinomial Naive Nayes ([`MultinomialNb`](crate::MultinomialNb))
- Gaussian Naive Bayes ([`GaussianNb`])
- Multinomial Naive Nayes ([`MultinomialNb`]))

## Examples

Expand Down
3 changes: 2 additions & 1 deletion algorithms/linfa-bayes/src/base_nb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ pub fn filter<F: Float, L: Label + Ord>(
let index = y
.into_iter()
.enumerate()
.filter_map(|(i, y)| (*ycondition == *y).then(|| i))
.filter(|(_, y)| (*ycondition == **y))
.map(|(i, _)| i)
.collect::<Vec<_>>();

// We subset x to only records corresponding to the class represented in `ycondition`
Expand Down
4 changes: 2 additions & 2 deletions algorithms/linfa-bayes/src/gaussian_nb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ where
}
}

impl<'a, F, L> GaussianNbValidParams<F, L>
impl<F, L> GaussianNbValidParams<F, L>
where
F: Float,
{
Expand Down Expand Up @@ -259,7 +259,7 @@ impl<F: Float, L: Label> GaussianNb<F, L> {
}
}

impl<'a, F, L> NaiveBayes<'a, F, L> for GaussianNb<F, L>
impl<F, L> NaiveBayes<'_, F, L> for GaussianNb<F, L>
where
F: Float,
L: Label + Ord,
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-bayes/src/multinomial_nb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl<F: Float, L: Label> MultinomialNb<F, L> {
}
}

impl<'a, F, L> NaiveBayes<'a, F, L> for MultinomialNb<F, L>
impl<F, L> NaiveBayes<'_, F, L> for MultinomialNb<F, L>
where
F: Float,
L: Label + Ord,
Expand Down
1 change: 1 addition & 0 deletions algorithms/linfa-clustering/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ categories = ["algorithms", "mathematics", "science"]

[features]
default = []
blas = []
serde = ["serde_crate", "ndarray/serde", "linfa-nn/serde"]

[dependencies.serde_crate]
Expand Down
6 changes: 2 additions & 4 deletions algorithms/linfa-clustering/src/dbscan/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ use linfa::{traits::Transformer, DatasetBase};
/// The algorithm iterates over each point in the dataset and for every point
/// not yet assigned to a cluster:
/// - Find all points within the neighborhood of size `tolerance`
/// - If the number of points in the neighborhood is below a minimum size label
/// as noise
/// - Otherwise label the point with the cluster ID and repeat with each of the
/// neighbours
/// - If the number of points in the neighborhood is below a minimum size label as noise
/// - Otherwise label the point with the cluster ID and repeat with each of the neighbours
///
/// ## Tutorial
///
Expand Down
7 changes: 3 additions & 4 deletions algorithms/linfa-clustering/src/gaussian_mixture/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ impl<F: Float> GaussianMixtureModel<F> {
self.means()
}

#[allow(clippy::type_complexity)]
fn estimate_gaussian_parameters<D: Data<Elem = F>>(
observations: &ArrayBase<D, Ix2>,
resp: &Array2<F>,
Expand Down Expand Up @@ -505,17 +506,15 @@ mod tests {
}

pub struct MultivariateNormal {
pub mean: Array1<f64>,
pub covariance: Array2<f64>,
/// Lower triangular matrix (Cholesky decomposition of the coviariance matrix)
mean: Array1<f64>,
/// Lower triangular matrix (Cholesky decomposition of the covariance matrix)
lower: Array2<f64>,
}
impl MultivariateNormal {
pub fn new(mean: &ArrayView1<f64>, covariance: &ArrayView2<f64>) -> LAResult<Self> {
let lower = covariance.cholesky()?;
Ok(MultivariateNormal {
mean: mean.to_owned(),
covariance: covariance.to_owned(),
lower,
})
}
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-clustering/src/k_means/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ mod tests {
&mut rng,
);

let expected_memberships = (0..n_centroids).into_iter().collect::<Array1<_>>();
let expected_memberships = (0..n_centroids).collect::<Array1<_>>();
assert_eq!(
calc_memberships!(L2Dist, centroids, centroids),
expected_memberships
Expand Down
3 changes: 2 additions & 1 deletion algorithms/linfa-clustering/src/k_means/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ fn k_means_para<R: Rng, F: Float, D: Distance<F>>(
let next_candidates_idx = sample_subsequent_candidates::<R, _>(
&dists,
F::cast(candidates_per_round),
rng.gen_range(0..std::u64::MAX),
rng.gen_range(0..u64::MAX),
);

// Append the newly generated candidates to the current cadidates, breaking out of the loop
Expand All @@ -191,6 +191,7 @@ fn k_means_para<R: Rng, F: Float, D: Distance<F>>(

/// Generate candidate centroids by sampling each observation in parallel using a seedable RNG in
/// every thread. Average number of generated candidates should equal `multiplier`.
#[allow(clippy::extra_unused_type_parameters)]
fn sample_subsequent_candidates<R: Rng, F: Float>(
dists: &Array1<F>,
multiplier: F,
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-clustering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! * [K-Means](KMeans)
//! * [DBSCAN](Dbscan)
//! * [Approximated DBSCAN](AppxDbscan) (Currently an alias for DBSCAN, due to its superior
//! performance)
//! performance)
//! * [Gaussian-Mixture-Model](GaussianMixtureModel)
//! * [OPTICS](OpticsAnalysis)
//!
Expand Down
1 change: 1 addition & 0 deletions algorithms/linfa-clustering/src/optics/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl<F: Float> PartialEq for Sample<F> {
}
}

#[allow(clippy::non_canonical_partial_ord_impl)]
impl<F: Float> PartialOrd for Sample<F> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.reachability_distance
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-elasticnet/examples/elasticnet_cv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn main() -> Result<()> {
let mut dataset = linfa_datasets::diabetes();

// parameters to compare
let ratios = vec![0.1, 0.2, 0.5, 0.7, 1.0];
let ratios = &[0.1, 0.2, 0.5, 0.7, 1.0];

// create a model for each parameter
let models = ratios
Expand Down
3 changes: 1 addition & 2 deletions algorithms/linfa-elasticnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ pub use hyperparams::{
///
/// See also:
/// * [Talk on Fast Regularization Paths](https://web.stanford.edu/~hastie/TALKS/glmnet.pdf)
/// * [Regularization Paths for Generalized Linear Models via Coordinate
/// Descent](http://www.jstatsoft.org/v33/i01/paper)
/// * [Regularization Paths for Generalized Linear Models via Coordinate Descent](http://www.jstatsoft.org/v33/i01/paper)
#[derive(Debug, Clone)]
pub struct ElasticNet<F> {
hyperplane: Array1<F>,
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-ftrl/examples/winequality_ftrl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rand::{rngs::SmallRng, SeedableRng};
fn main() -> Result<()> {
// Read the data
let (train, valid) = linfa_datasets::winequality()
.map_targets(|v| if *v > 6 { true } else { false })
.map_targets(|v| *v > 6)
.split_with_ratio(0.9);

let params = Ftrl::params()
Expand Down
6 changes: 3 additions & 3 deletions algorithms/linfa-ftrl/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rand::Rng;
/// Simplified `Result` using [`FtrlError`](crate::FtrlError) as error type
pub type Result<T> = std::result::Result<T, FtrlError>;

impl<'a, F, R, D, T> FitWith<'a, ArrayBase<D, Ix2>, T, FtrlError> for FtrlValidParams<F, R>
impl<F, R, D, T> FitWith<'_, ArrayBase<D, Ix2>, T, FtrlError> for FtrlValidParams<F, R>
where
F: Float,
R: Rng + Clone,
Expand Down Expand Up @@ -255,7 +255,7 @@ mod test {
let gradient: f64 = 0.5;
let n: f64 = 0.11;
let alpha = 0.5;
let expected_result = (((0.11 + 0.25) as f64).sqrt() - (0.11 as f64).sqrt()) / 0.5;
let expected_result = ((0.11f64 + 0.25).sqrt() - 0.11f64.sqrt()) / 0.5;
let result = calculate_weight_in_average(n, gradient, alpha);
assert_abs_diff_eq!(result, expected_result)
}
Expand Down Expand Up @@ -302,7 +302,7 @@ mod test {
let sigma = model.calculate_sigma(gradient.view());
model.update_params(gradient.clone(), sigma.clone());
let expected_z = initial_z + &gradient - sigma * weights;
let expected_n = initial_n + &gradient.mapv(|grad| (grad as f64).powf(2.));
let expected_n = initial_n + &gradient.mapv(|grad: f64| grad.powf(2.));
assert_abs_diff_eq!(model.z(), &expected_z, epsilon = 1e-1);
assert_abs_diff_eq!(model.n(), &expected_n, epsilon = 1e-1)
}
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-ftrl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<F: Float> Ftrl<F> {
/// The description can be found [here](https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/41159.pdf)
///
/// It requires data preprocessing done in the separate step.

///
/// Create default hyperparameters. Random number generator will default to rand_xoshiro::Xoshiro256Plus
pub fn params() -> FtrlParams<F, Xoshiro256Plus> {
FtrlParams::default_with_rng(Xoshiro256Plus::seed_from_u64(42))
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-hierarchical/examples/irisflower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.transform(kernel)?;

for (id, target) in kernel.targets().iter().zip(dataset.targets().into_iter()) {
let name = match *target as usize {
let name = match *target {
0 => "setosa",
1 => "versicolor",
2 => "virginica",
Expand Down
6 changes: 3 additions & 3 deletions algorithms/linfa-hierarchical/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ impl<F: Float> ParamGuard for HierarchicalCluster<F> {

fn check_ref(&self) -> std::result::Result<&Self::Checked, Self::Error> {
match self.0.stopping {
Criterion::NumClusters(x) if x == 0 => Err(
HierarchicalError::InvalidStoppingCondition(self.0.stopping.clone()),
),
Criterion::NumClusters(0) => Err(HierarchicalError::InvalidStoppingCondition(
self.0.stopping.clone(),
)),
Criterion::Distance(x) if x.is_negative() || x.is_nan() || x.is_infinite() => Err(
HierarchicalError::InvalidStoppingCondition(self.0.stopping.clone()),
),
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ features = ["std", "derive"]
[dependencies]
ndarray = "0.15"
num-traits = "0.2"
sprs = { version="0.11", default-features = false }
sprs = { version = "=0.11.1", default-features = false }

linfa = { version = "0.7.0", path = "../.." }
linfa-nn = { version = "0.7.0", path = "../linfa-nn" }
2 changes: 1 addition & 1 deletion algorithms/linfa-kernel/src/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<F: Float> Inner for CsMat<F> {
}
}

impl<'a, F: Float> Inner for CsMatView<'a, F> {
impl<F: Float> Inner for CsMatView<'_, F> {
type Elem = F;

fn dot(&self, rhs: &ArrayView2<F>) -> Array2<F> {
Expand Down
Loading
Loading