Files
semantic-kernel/docs/EUCLIDEAN_DISTANCE.md
T
Ryan Reyes 0781cbae22 Update EUCLIDEAN_DISTANCE.md (#6625)
Corrected the capitalization of the page header/title. I also removed
the manually typed math and replaced it with inline LaTeX display math
to make the formulas easier to read as well as to add a more
professional look.

For some reason, when using the `$$` LaTeX delimiter, GitHub sometimes
cuts off the vertical portion of large square root symbols. I sort of
see that happening here with the second formula, but when I zoom in and
out, it corrects itself, so I'm unsure if it's how the browser is
drawing the formula, or if the issue originates solely with GitHub. If
it's present on the screen of any reviewers, please let me know and I'll
switch the code to use the single `$` LaTeX delimiter which doesn't have
this problem. The only downfall with the single `$` delimiter is that it
defaults to left alignment instead of center alignment, but I'm pretty
sure that can be manually adjusted.

Take Care

### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
1. Why is this change required? The manually typed math looked a tad
sloppy and was a bit difficult to read.
2. What problem does it solve? It makes the math formulas easier to read
and understand because LaTeX formats the formulas properly as well as
providing accessibility options for users who need to tweak how the
formulas are displayed.
3. What scenario does it contribute to? Being able to read the documents
without any confusion.
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
2024-06-19 09:38:06 +00:00

2.8 KiB

Euclidean Distance

Euclidean distance is a mathematical concept that measures the straight-line distance between two points in a Euclidean space. It is named after the ancient Greek mathematician Euclid, who is often referred to as the "father of geometry". The formula for calculating Euclidean distance is based on the Pythagorean Theorem and can be expressed as:

d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}

For higher dimensions, this formula can be generalized to:

d(p, q) = \sqrt{\sum\limits_{i\=1}^{n} (q_i - p_i)^2}

Euclidean distance has many applications in computer science and artificial intelligence, particularly when working with embeddings. Embeddings are numerical representations of data that capture the underlying structure and relationships between different data points. They are commonly used in natural language processing, computer vision, and recommendation systems.

When working with embeddings, it is often necessary to measure the similarity or dissimilarity between different data points. This is where Euclidean distance comes into play. By calculating the Euclidean distance between two embeddings, we can determine how similar or dissimilar they are.

One common use case for Euclidean distance in AI is in clustering algorithms such as K-means. In this algorithm, data points are grouped together based on their proximity to one another in a multi-dimensional space. The Euclidean distance between each point and the centroid of its cluster is used to determine which points belong to which cluster.

Another use case for Euclidean distance is in recommendation systems. By calculating the Euclidean distance between different items' embeddings, we can determine how similar they are and make recommendations based on that information.

Overall, Euclidean distance is an essential tool for software developers working with AI and embeddings. It provides a simple yet powerful way to measure the similarity or dissimilarity between different data points in a multi-dimensional space.

Applications

Some examples about Euclidean distance applications.

  1. Recommender systems: Euclidean distance can be used to measure the similarity between items in a recommender system, helping to provide more accurate recommendations.

  2. Image recognition: By calculating the Euclidean distance between image embeddings, it is possible to identify similar images or detect duplicates.

  3. Natural Language Processing: Measuring the distance between word embeddings can help with tasks such as semantic similarity and word sense disambiguation.

  4. Clustering: Euclidean distance is commonly used as a metric for clustering algorithms, allowing them to group similar data points together.

  5. Anomaly detection: By calculating the distance between data points, it is possible to identify outliers or anomalies in a dataset.