001    /*
002     * Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
003     *
004     * This software is the confidential and proprietary information of
005     * ChemAxon. You shall not disclose such Confidential Information
006     * and shall use it only in accordance with the terms of the agreements
007     * you entered into with ChemAxon.
008     *
009     */
010    
011    package com.chemaxon.overlap.unguarded;
012    
013    import java.io.Serializable;
014    
015    /**
016     * Unguarded square of euclidean comparator for <code>float[]</code> vectors.
017     *
018     * <p><b>Use with extreme care!</b> This implementation wont check vector length equality.</p>
019     *
020     * @author Gabor Imre
021     */
022    public class UnguardedFloatVectorEuclidSqr implements UnguardedDissimilarityCalculator<float[]>, Serializable {
023    
024        /**
025         * Serial version.
026         */
027        private static final long serialVersionUID = 0;
028    
029        @Override
030        public double dissimilarity(float[] target, float[] query) {
031            double r = 0;
032            for (int i = 0; i < target.length; i++) {
033                // Note that Math.min/max handles NaN and negative zero correctly; we wont need it
034                final double d = target[i] - query[i];
035                r += d * d;
036            }
037            return r;
038        }
039    
040        @Override
041        public String toString() {
042            return "Sqr of euclidean dissimilarity of float[] vectors.";
043        }
044    
045    }