# SimilarityMeasures

Library "SimilarityMeasures"
Similarity measures are statistical methods used to quantify the distance between different data sets
or strings. There are various types of similarity measures, including those that compare:
- data points (SSD, Euclidean, Manhattan, Minkowski, Chebyshev, Correlation, Cosine, Camberra, MAE, MSE, Lorentzian, Intersection, Penrose Shape, Meehl),
- strings (Edit(Levenshtein), Lee, Hamming, Jaro),
- probability distributions (Mahalanobis, Fidelity, Bhattacharyya, Hellinger),
- sets (Kumar Hassebrook, Jaccard, Sorensen, Chi Square).
---
These measures are used in various fields such as data analysis, machine learning, and pattern recognition. They
help to compare and analyze similarities and differences between different data sets or strings, which
can be useful for making predictions, classifications, and decisions.
---
References:
en.wikipedia.org/wik...i/Similarity_measure
cran.r-project.org/w...yMeasures/index.html
numerics.mathdotnet.com/Distance
github.com/ngmarchant/comparator
github.com/drostlab/...74fb/src/distances.h
github.com/scipy/sci.../spatial/distance.py
Encyclopedia of Distances, doi.org/10.1007/978-3-662-52844-0

ssd(p, q)
Sum of squared difference for N dimensions.
Parameters:
p (float): `array<float>` Vector with first numeric distribution.
q (float): `array<float>` Vector with second numeric distribution.
Returns: Measure of distance that calculates the squared euclidean distance.

euclidean(p, q)
Euclidean distance for N dimensions.
Parameters:
p (float): `array<float>` Vector with first numeric distribution.
q (float): `array<float>` Vector with second numeric distribution.
Returns: Measure of distance that calculates the straight-line (or Euclidean).

manhattan(p, q)
Manhattan distance for N dimensions.
Parameters:
p (float): `array<float>` Vector with first numeric distribution.
q (float): `array<float>` Vector with second numeric distribution.
Returns: Measure of absolute differences between both points.

minkowski(p, q, p_value)
Minkowsky Distance for N dimensions.
Parameters:
p (float): `array<float>` Vector with first numeric distribution.
q (float): `array<float>` Vector with second numeric distribution.
p_value (float): `float` P value, default=1.0(1: manhatan, 2: euclidean), does not support chebychev.
Returns: Measure of similarity in the normed vector space.

chebyshev(p, q)
Chebyshev distance for N dimensions.
Parameters:
p (float): `array<float>` Vector with first numeric distribution.
q (float): `array<float>` Vector with second numeric distribution.
Returns: Measure of maximum absolute difference.

correlation(p, q)
Correlation distance for N dimensions.
Parameters:
p (float): `array<float>` Vector with first numeric distribution.
q (float): `array<float>` Vector with second numeric distribution.
Returns: Measure of maximum absolute difference.

cosine(p, q)
Cosine distance between provided vectors.
Parameters:
p (float): `array<float>` 1D Vector.
q (float): `array<float>` 1D Vector.
Returns: The Cosine distance between vectors `p` and `q`.

---
angiogenesis.dkfz.de...cs_clust/cluster.htm

camberra(p, q)
Camberra distance for N dimensions.
Parameters:
p (float): `array<float>` Vector with first numeric distribution.
q (float): `array<float>` Vector with second numeric distribution.
Returns: Weighted measure of absolute differences between both points.

mae(p, q)
Mean absolute error is a normalized version of the sum of absolute difference (manhattan).
Parameters:
p (float): `array<float>` Vector with first numeric distribution.
q (float): `array<float>` Vector with second numeric distribution.
Returns: Mean absolute error of vectors `p` and `q`.

mse(p, q)
Mean squared error is a normalized version of the sum of squared difference.
Parameters:
p (float): `array<float>` Vector with first numeric distribution.
q (float): `array<float>` Vector with second numeric distribution.
Returns: Mean squared error of vectors `p` and `q`.

lorentzian(p, q)
Lorentzian distance between provided vectors.
Parameters:
p (float): `array<float>` Vector with first numeric distribution.
q (float): `array<float>` Vector with second numeric distribution.
Returns: Lorentzian distance of vectors `p` and `q`.

---
angiogenesis.dkfz.de...cs_clust/cluster.htm

intersection(p, q)
Intersection distance between provided vectors.
Parameters:
p (float): `array<float>` Vector with first numeric distribution.
q (float): `array<float>` Vector with second numeric distribution.
Returns: Intersection distance of vectors `p` and `q`.

---
angiogenesis.dkfz.de...cs_clust/cluster.htm

penrose(p, q)
Penrose Shape distance between provided vectors.
Parameters:
p (float): `array<float>` Vector with first numeric distribution.
q (float): `array<float>` Vector with second numeric distribution.
Returns: Penrose shape distance of vectors `p` and `q`.

---
angiogenesis.dkfz.de...cs_clust/cluster.htm

meehl(p, q)
Meehl distance between provided vectors.
Parameters:
p (float): `array<float>` Vector with first numeric distribution.
q (float): `array<float>` Vector with second numeric distribution.
Returns: Meehl distance of vectors `p` and `q`.

---
angiogenesis.dkfz.de...cs_clust/cluster.htm

edit(x, y)
Edit (aka Levenshtein) distance for indexed strings.
Parameters:
x (int): `array<int>` Indexed array.
y (int): `array<int>` Indexed array.
Returns: Number of deletions, insertions, or substitutions required to transform source string into target string.

---
generated description:
The Edit distance is a measure of similarity used to compare two strings. It is defined as the minimum number of
operations (insertions, deletions, or substitutions) required to transform one string into another. The operations
are performed on the characters of the strings, and the cost of each operation depends on the specific algorithm
used.
The Edit distance is widely used in various applications such as spell checking, text similarity, and machine
translation. It can also be used for other purposes like finding the closest match between two strings or
identifying the common prefixes or suffixes between them.

---
github.com/disha2sin...ing/EditDistance.cpp
www.red-gate.com/sim...venshtein-algorithm/
planetcalc.com/1721/

lee(x, y, dsize)
Distance between two indexed strings of equal length.
Parameters:
x (int): `array<int>` Indexed array.
y (int): `array<int>` Indexed array.
dsize (int): `int` Dictionary size.
Returns: Distance between two strings by accounting for dictionary size.

---
www.johndcook.com/bl...nce-codes-and-music/

hamming(x, y)
Distance between two indexed strings of equal length.
Parameters:
x (int): `array<int>` Indexed array.
y (int): `array<int>` Indexed array.
Returns: Length of different components on both sequences.

---
en.wikipedia.org/wiki/Hamming_distance

jaro(x, y)
Distance between two indexed strings.
Parameters:
x (int): `array<int>` Indexed array.
y (int): `array<int>` Indexed array.
Returns: Measure of two strings' similarity: the higher the value, the more similar the strings are.
The score is normalized such that `0` equates to no similarities and `1` is an exact match.

---
rosettacode.org/wiki/Jaro_similarity

mahalanobis(p, q, VI)
Mahalanobis distance between two vectors with population inverse covariance matrix.
Parameters:
p (float): `array<float>` 1D Vector.
q (float): `array<float>` 1D Vector.
VI (matrix<float>): `matrix<float>` Inverse of the covariance matrix.
Returns: The mahalanobis distance between vectors `p` and `q`.

---
people.revoledu.com/...lanobisDistance.html
stat.ethz.ch/R-manua...tml/mahalanobis.html
docs.scipy.org/doc/s...nce.mahalanobis.html

fidelity(p, q)
Fidelity distance between provided vectors.
Parameters:
p (float): `array<float>` 1D Vector.
q (float): `array<float>` 1D Vector.
Returns: The Bhattacharyya Coefficient between vectors `p` and `q`.

---
en.wikipedia.org/wik...ty_of_quantum_states

bhattacharyya(p, q)
Bhattacharyya distance between provided vectors.
Parameters:
p (float): `array<float>` 1D Vector.
q (float): `array<float>` 1D Vector.
Returns: The Bhattacharyya distance between vectors `p` and `q`.

---
en.wikipedia.org/wik...attacharyya_distance

hellinger(p, q)
Hellinger distance between provided vectors.
Parameters:
p (float): `array<float>` 1D Vector.
q (float): `array<float>` 1D Vector.
Returns: The hellinger distance between vectors `p` and `q`.

---
en.wikipedia.org/wik...i/Hellinger_distance
jamesmccaffrey.wordp...utions-using-python/

kumar_hassebrook(p, q)
Kumar Hassebrook distance between provided vectors.
Parameters:
p (float): `array<float>` 1D Vector.
q (float): `array<float>` 1D Vector.
Returns: The Kumar Hassebrook distance between vectors `p` and `q`.

---
github.com/drostlab/...74fb/src/distances.h

jaccard(p, q)
Jaccard distance between provided vectors.
Parameters:
p (float): `array<float>` 1D Vector.
q (float): `array<float>` 1D Vector.
Returns: The Jaccard distance between vectors `p` and `q`.

---
github.com/drostlab/...74fb/src/distances.h

sorensen(p, q)
Sorensen distance between provided vectors.
Parameters:
p (float): `array<float>` 1D Vector.
q (float): `array<float>` 1D Vector.
Returns: The Sorensen distance between vectors `p` and `q`.

---
people.revoledu.com/...yCurtisDistance.html

chi_square(p, q, eps)
Chi Square distance between provided vectors.
Parameters:
p (float): `array<float>` 1D Vector.
q (float): `array<float>` 1D Vector.
eps (float)
Returns: The Chi Square distance between vectors `p` and `q`.

---
uw.pressbooks.pub/ap...r/distance-measures/
stats.stackexchange....-chi-square-distance
www.itl.nist.gov/div.../section3/eda35f.htm

kulczynsky(p, q, eps)
Kulczynsky distance between provided vectors.
Parameters:
p (float): `array<float>` 1D Vector.
q (float): `array<float>` 1D Vector.
eps (float)
Returns: The Kulczynsky distance between vectors `p` and `q`.

---
github.com/drostlab/...74fb/src/distances.h
파인 라이브러리

트레이딩뷰 정신에 따라 오써는 이 파인 코드를 오픈 소스 라이브러리로 퍼블리쉬하여 당사 커뮤니티의 다른 파인 프로그래머들이 쓸 수 있도록 하였습니다. 오써에게 찬사를! 여러분은 이 라이브러리를 프라이빗 또는 오픈 소스 퍼블리케이션에 쓸 수 있지만 퍼블리케이션에 재사용은 하우스룰을 따릅니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

이 라이브러리를 쓰시겠습니까?

텍스트를 클립보드에 카피한 뒤 님의 스크립트에 붙여 넣기.