similarity-trait
Similarity trait Rust crate: compare input values, such as two or more items, then return an output value, such as a mesure of similarity, or correlation, or overlap.
Science Score: 54.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
✓Academic publication links
Links to: ncbi.nlm.nih.gov -
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (7.9%) to scientific vocabulary
Repository
Similarity trait Rust crate: compare input values, such as two or more items, then return an output value, such as a mesure of similarity, or correlation, or overlap.
Basic Info
- Host: GitHub
- Owner: SixArm
- License: other
- Language: Rust
- Default Branch: main
- Size: 86.9 KB
Statistics
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 1
- Releases: 0
Metadata Files
README.md
Similarity trait Rust crate
documentation • source • llms.txt • crate • email
The Similarity trait defines one function with one input and one output, so you can compare any kinds of input values and return any kind of output value.
rust
pub trait Similarity<InputType, OutputType> {
fn similarity(input: InputType) -> OutputType;
}
This trait is purposefully very generic so you can use it as you wish.
We use this trait in our programs to create multiple kinds of similarity functionality, such as for trying various similarity algorithms that we want to use with the same input type and same output type.
For examples, please see the directory [examples].
Similarity of a pair
One way to use this trait is to calculate the similarity of a pair of values, such as two numbers, or two strings, or two images.
This is sometimes known as pairwise similarity or pair matching.
Example: given two numbers, then return the percent change.
```rust use similarity_trait::Similarity; struct MyStruct;
impl Similarity<(i32, i32), f64> for MyStruct { /// Similarity of numbers via percent change. fn similarity(input: (i32, i32)) -> f64 { (100.0 * (input.1 - input.0) as f64) / i32::abs(input.0) as f64 } }
let percentchange = MyStruct::similarity((100, 120)); asserteq!(percent_change, 20.0); ```
Similarity of a collection
One way to use this trait is to calculate the similarity of a collection of values, such as an array of numbers, or vector of strings, or set of images.
This is sometimes called intra-group similarity or statistical correlation.
Example: given numbers, then return the population standard deviation.
```rust use similarity_trait::Similarity; struct MyStruct;
impl Similarity<&Vec
let numbers = vec![2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0]; let populationstandarddeviation = MyStruct::similarity(&numbers).expect("similarity"); assert!(populationstandarddeviation > 1.999 && populationstandarddeviation < 2.001); ```
For examples, please see the directory [examples].
Similarity of a pair or a collection
You may want to choose whether you prefer to calculate the similarity of a pair (such as two strings) or a collection (such as a vector of strings).
Example: given a pair of strings, then return the Hamming distance.
```rust use similarity_trait::Similarity; struct MyStruct;
impl Similarity<(&str, &str), usize> for MyStruct { /// Similarity of a pair of strings via Hamming distance. fn similarity(pair: (&str, &str)) -> usize { pair.0.chars().zip(pair.1.chars()).filter(|(c1, c2)| c1 != c2).count() } }
let pair = ("information", "informatics"); let hammingdistance = MyStruct::similarity(pair); asserteq!(hamming_distance, 2); ```
Example: given a collection of strings, then return the maximum Hamming distance.
```rust use similarity_trait::Similarity; struct MyStruct;
impl Similarity
let collection = vec!["information", "informatics", "affirmation"]; let maximumhammingdistance = MyStruct::similarity(collection); asserteq!(maximumhamming_distance, 5); ```
How to learn more
Wikipedia links:
Pearson correlation coefficient also known as product-moment correlation coefficient.
Jaccard index also known as coefficient of community, intersection over union, ratio of verification, critical success index, Tanimoto index.
Similarity research papers about patient matching:
Owner
- Name: SixArm
- Login: SixArm
- Kind: organization
- Email: sixarm@sixarm.com
- Location: San Francisco
- Website: http://sixarm.com
- Twitter: sixarm
- Repositories: 580
- Profile: https://github.com/SixArm
SixArm Software
Citation (CITATION.cff)
cff-version: 1.2.0
title: Assertables: Rust crate of assert macros for testing
message: >-
If you use this work and you want to cite it,
then you can use the metadata from this file.
type: software
authors:
- given-names: Joel Parker
family-names: Henderson
email: joel@joelparkerhenderson.com
affiliation: joelparkerhenderson.com
orcid: 'https://orcid.org/0009-0000-4681-282X'
identifiers:
- type: url
value: 'https://github.com/SixArm/assertables-rust-crate/'
description: Assertables: Rust crate of assert macros for testing
repository-code: 'https://github.com/SixArm/assertables-rust-crate/'
abstract: >-
Assertables: Rust crate of assert macros for testing
license: See license file
GitHub Events
Total
- Issues event: 1
- Watch event: 1
- Push event: 2
- Create event: 2
Last Year
- Issues event: 1
- Watch event: 1
- Push event: 2
- Create event: 2
Issues and Pull Requests
Last synced: 6 months ago
Packages
- Total packages: 1
-
Total downloads:
- cargo 325 total
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 1
- Total maintainers: 1
crates.io: similarity-trait
Similarity trait Rust crate: compare input values, such as two or more items, then return an output value, such as a mesure of similarity, or correlation, or overlap.
- Documentation: https://docs.rs/similarity-trait/
- License: MIT OR Apache-2.0 OR GPL-2.0 OR GPL-3.0 OR BSD-3-Clause
-
Latest release: 1.0.0
published 8 months ago