Skip to content

Commit

Permalink
Merge pull request #70 from Polochon-street/add-mahalanobis-distance
Browse files Browse the repository at this point in the history
Add custom Mahalanobis distance
  • Loading branch information
Polochon-street authored Sep 16, 2024
2 parents e3dc9a7 + 4168c12 commit b033794
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## blissify 0.5.1
* Add support for Mahalanobis distance.

## blissify 0.5.0
Note: to take advantage of the fix below, a rescan is needed if you
have an existing database.
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "blissify"
version = "0.5.0"
version = "0.5.1"
authors = ["Polochon-street <[email protected]>"]
edition = "2021"
license = "GPL-3.0-only"
Expand All @@ -17,7 +17,7 @@ default = ["bliss-audio/library"]
rpi = ["bliss-audio/rpi"]

[dependencies]
bliss-audio = "0.9.0"
bliss-audio = "0.9.1"
mpd = "0.1.0"
dirs = "3.0.1"
tempdir = "0.3.7"
Expand Down
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ ask questions if you want to tackle an item.

## Actual TODO

- Add a feature to focus on a specific feature ("I want tempo being prioritized, or timbre, or tonal features")
=> take advantage of the Mahalanobis distance and make it easy-ish to use
- Erroneous report with CUE files (see https://github.com/Polochon-street/blissify-rs/issues/48)
- Try to trim out the crates (it's too big rn)
- grep TODO and see what can be fixed
Expand Down
16 changes: 9 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
use anyhow::{bail, Context, Result};
use bliss_audio::library::{AppConfigTrait, BaseConfig, Library, LibrarySong};
use bliss_audio::playlist::{
closest_to_songs, cosine_distance, euclidean_distance, song_to_song, DistanceMetricBuilder,
closest_to_songs, cosine_distance, euclidean_distance, mahalanobis_distance_builder,
song_to_song, DistanceMetricBuilder,
};
use bliss_audio::{BlissError, BlissResult};
use clap::{App, Arg, ArgMatches, SubCommand};
Expand Down Expand Up @@ -361,13 +362,11 @@ impl MPDLibrary {
.iter()
.take_while(|s| {
for (tagname, value) in s.tags.iter() {
if tagname.to_ascii_lowercase() == String::from("album")
&& *value == current_album
{
if tagname.to_ascii_lowercase() == *"album" && *value == current_album {
return true;
}
}
return false;
false
})
.count();
let index = playlist
Expand Down Expand Up @@ -888,7 +887,7 @@ Useful to avoid a too heavy load on a machine.")
.long("distance")
.value_name("distance metric")
.help(
"Choose the distance metric used to make the playlist. Default is 'euclidean' for playlists from a single song, and 'extended_isolation_forest' for playlists from multiple songs. Other options are 'cosine', and 'extended_isolation_forest'. The extended_isolation_forest works better for playlists from multiple songs."
"Choose the distance metric used to make the playlist. Default is 'euclidean' for playlists from a single song, and 'extended_isolation_forest' for playlists from multiple songs. Other options are 'cosine', 'mahalanobis', and 'extended_isolation_forest'. By default, the mahalanobis distance is the same as the euclidean distance. You can tailor this distance to your tastes by running metric learning e.g. using https://github.com/Polochon-street/bliss-metric-learning. The extended_isolation_forest works better for playlists from multiple songs."
)
.default_value("euclidean")
)
Expand Down Expand Up @@ -1049,8 +1048,11 @@ Defaults to 3, cannot be more than 9."
match m {
"euclidean" => &euclidean_distance,
"cosine" => &cosine_distance,
"mahalanobis" => {
&mahalanobis_distance_builder(library.library.config.base_config.m.to_owned())
}
"extended_isolation_forest" => forest_distance,
_ => bail!("Please choose a distance name, between 'euclidean', 'cosine' and 'extended_isolation_forest'."),
_ => bail!("Please choose a distance name, between 'euclidean', 'cosine', 'mahalanobis' and 'extended_isolation_forest'."),
}
} else {
&euclidean_distance
Expand Down

0 comments on commit b033794

Please sign in to comment.