/* * _______ _ ____ _ _ * |__ __| | | / ____| | | | * | | __ _ _ __ ___ ___ ___| | | (___ | |___| | * | |/ _` | '__/ __|/ _ \/ __| | \___ \| ___ | * | | (_| | | \__ \ (_) \__ \ |____ ____) | | | | * |_|\__,_|_| |___/\___/|___/_____/|_____/|_| |_| * * ----------------------------------------------------------- * * TarsosLSH is developed by Joren Six at * The School of Arts, * University College Ghent, * Hoogpoort 64, 9000 Ghent - Belgium * * ----------------------------------------------------------- * * Info : http://tarsos.0110.be/tag/TarsosLSH * Github : https://github.com/JorenSix/TarsosLSH * Releases: http://tarsos.0110.be/releases/TarsosLSH/ * */ package be.tarsos.lsh.families; import be.tarsos.lsh.Vector; /** * This distance measure calculates the city block distance between two vectors. This distance metric also known as the Manhattan distance or L1 distance. * Wikipedia calls it "Taxicab geometry": *
* Taxicab geometry, considered by Hermann Minkowski in the 19th * century, is a form of geometry in which the usual distance function or metric * of Euclidean geometry is replaced by a new metric in which the distance * between two points is the sum of the absolute differences of their * coordinates. The taxicab metric is also known as rectilinear distance, L1 * distance or norm (see Lp space), city block distance, Manhattan distance, or * Manhattan length, with corresponding variations in the name of the * geometry. The latter names allude to the grid layout of most streets on * the island of Manhattan, which causes the shortest path a car could take * between two intersections in the borough to have length equal to the * intersections' distance in taxicab geometry. ** * @author Joren Six * */ public class CityBlockDistance implements DistanceMeasure { /* (non-Javadoc) * @see be.hogent.tarsos.lsh.families.DistanceMeasure#distance(be.hogent.tarsos.lsh.Vector, be.hogent.tarsos.lsh.Vector) */ @Override public double distance(Vector one, Vector other) { double distance = 0; for (int d = 0; d < one.getDimensions(); d++) { distance += Math.abs(one.get(d) - other.get(d)); } return distance; } }