Posts

Showing posts with the label vectors

mathajax

Cosine Similarity

Image
The Java code measure the similarity between two vectors using cosine similarity formula. The vector's element can be integer or double of Java datatype. The cosine similarity of two vectors found by a ratio of  dot product of those vectors and their magnitude. Cosine Similarity Dot product of 2-D Vector Dot product of N-D Vector Vector Magnitude Cosine Similarity of 2-D vectors A class Cosine defined two member functions named " similarity " with parameter type difference, in order to support  parameters  type int and double 2-D vectors.  . Both class (static) member function similarity can be invoked with two array parameters, which represents the  vectors  to measure similarity between them. These vectors must have 2 elements. for example the vectors A =[2 3], B=[3 1] Dot product of two vectors A.B A.B = 2x3 + 3x1 = 6 + 3 A.B = 9 Magnitude o...

Vector Dot Product

Image
The Java code finds the dot product of two vectors v1 and v2 .   it is also called as scalar product or inner product and  defined as sum of  product of  respective axis element of  the two vectors . Their vector's element can be integer or double of java datatype. Dot product of 2-D vectors Dot product of N-D vectors Dot product of 2D vectors A class Vector defined two member functions named " dot-product " with parameter type difference, in order to support  parameters  int or double type 2D vectors.  . Both member function can be invoked with two array parameters, which represents the vectors to be dot-product. These vectors must have 2 elements. for example  below shows how to calculate dot product two vectors A and B using above equation Vector A = [1 5] Vector B = [2 3] A.B = 1x2 + 5x3 = 2 + 15 A.B = 17     import jav...

Chebyshev distance between two points

Image
The java program finds distance between two points using chebyshev distance equation . The points can be a scalar or a vector . 1D distance metric It measures distance between two points by absolute difference between them. Each point has one element. 2-Dimensional distance metric It measures distance between two points (2D vector) by selecting maximum absolute difference on 2D vector element absolute difference. N-Dimensional distance metric It measures distance between two N-Dimensional vector by selecting maximum absolute difference on the two N-D vector element. Example Calculation on 2D vectors This is an example calculation shown below explain how to find the distance between two vectors using Chebyshev distance formula. A vector,array of elements declared and initialized in Java using one dimensional array. int A[] = { 2 ,6 }; // 2D vector A int B[] = { 4,1 }; // 2D vector B max - operators finds greatest val...

Metric - Minkowski distance between two points

Image
The java program finds distance between two points using minkowski distance equation . when power is set P=1, minkowski metric results as same as manhattan distance equation and when set P=2, minkowski metric results as same as euclidean distance equation. 1-Dimensional distance It measures the distance between two points . Each point lies on a line and has one element. 2-Dimensional distance It measures the distance between two points. Each point lies on 2D cartesian plane and has 2 elements. N-Dimensional distance It measures the distance between two points and each point has N elements. Example Calculation This is an example calculation shown below explain how to find the distance between two vectors using Minkowski distance formula . A vector,array of elements declared and initialized in java using one dimensional array. int A[] = { 5 ,3 }; // 2D vector A int B[] = { 2,1 }; // 2D vector B int P =3; P th ...

Metric - Manhattan Distance between two points

Image
The java program finds distance between two points using manhattan distance equation.  The points can be a scalar or vector and the passed to function as arguments can be integer or double datatype. 1D distance between two points It measures distance between two points on a line (1D) by absolute difference between them and the points are scalar value. Two points on 2D cartesian space It measures distance between two points on a plane. The points are vectors and each has two elements. The resulting distance equals sum of the difference of each element on the vectors . Two points on N-Dimensional cartesian space It measures d istance between two points or vectors on N-dimensional space . The points are vectors and each has N elements.The resulting distance equals sum of the difference of each element on the vectors. This is an example calculation shown below explain how to find the distance between two vectors using Manhat...

Distance Metric - Euclidean Distance

Image
The java program finds distance between two points by Euclidean distance metric and the points can be a scalar (single element) or a vector (more than one element). The Euclidean distance between two points is measured based on Pythagoras theorem on right angle triangle. AC 2 = AB 2 + BC 2 AC 2 - area of hypotenous AB 2 – area of base BC 2 – area of perpendicular Euclidean distance= AC = sqrt( AB ^2 +BC ^2 ) Euclidean distance - on 1-D The points x and y are scalar on 1-dimension and each point has one element. It is consider that the points on a measuring scale in case of 1-Dimension. The distance between these two points are measured by the following formula. ID-Euclidean  Euclidean distance - on 2-D The points x and y are vector on 2-dimension and each point has two elements.It is consider that the points on a Cartesian 2-D coordinate graph in case of ...