INAIO Guide Stage 1 10Coordinate Geometry and Vectors
10.4 Dot product and cosine similarity
Use dot products and norms to measure alignment, then normalize to compare directions with cosine similarity.
Two vectors can have similar directions even when their lengths differ greatly. The dot product combines their components; cosine similarity removes the effect of length. These ideas appear in geometry and in comparing numeric feature vectors.
This is intermediate vector algebra. Study the dot-product section of OpenStax's vector lesson after practising vector components and norms.
A basic idea: alignment
For and ,
For nonzero vectors, , where is the angle between them. A positive dot product means the angle is acute, zero means perpendicular, and a negative one means obtuse.
A quick tour of properties
For nonzero vectors, cosine similarity is , from to inclusive. It is undefined if either vector is zero. Scaling a vector by a positive number leaves its cosine similarity with another unchanged; the dot product is multiplied by that number. Dot product is symmetric and distributes over addition.
Application 1: geometric projection
Let and . Then and , . Cosine similarity is . Because is a unit horizontal vector, the dot product is also the signed horizontal component of .
Application 2: compare feature directions
Let a query feature vector be , and two candidates be and . The dot products are and . Their cosine similarities are for and for . Candidate points in exactly the query's direction. If were , its dot product with would be , far above 's , but its cosine similarity would still be . Similarity alone does not tell you whether either candidate is useful for the real task.
Resources
| Source | Title | Why read it |
|---|---|---|
| OpenStax | Vectors | Learn the dot product and angle interpretation. |
Finished this module? Mark it done.
Comments
Stuck on something, spotted a mistake, or found a resource that helped you? Tell us below.
Loading comments