Java Matrix Max Value maxDistance(double[][] _values)

Here you can find the source of maxDistance(double[][] _values)

Description

Computes the maximun distance between vectors in a double[][]

License

Open Source License

Parameter

Parameter Description
_values The array containing the vectors

Return

The maximun distance between vectors in a double[][]

Declaration

public static double maxDistance(double[][] _values) 

Method Source Code

//package com.java2s;
/***********************************************************************

 This file is part of KEEL-software, the Data Mining tool for regression, 
 classification, clustering, pattern mining and so on.

 Copyright (C) 2004-2010/*from   ww  w .  ja  va2 s .  co m*/
    
 F. Herrera (herrera@decsai.ugr.es)
 L. S?nchez (luciano@uniovi.es)
 J. Alcal?-Fdez (jalcala@decsai.ugr.es)
 S. Garc?a (sglopez@ujaen.es)
 A. Fern?ndez (alberto.fernandez@ujaen.es)
 J. Luengo (julianlm@decsai.ugr.es)

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see http://www.gnu.org/licenses/
    
 **********************************************************************/

public class Main {
    /**
     * <p>
     * Computes the maximun distance between vectors in a double[][]
     * </p>
     * @param _values The array containing the vectors
     * @return The maximun distance between vectors in a double[][]
     */
    public static double maxDistance(double[][] _values) {
        double toRet = 0;
        double distancia;
        int numDatos = _values.length;
        for (int i = 0; i < numDatos; ++i) {
            for (int j = i + 1; j < numDatos; ++j) {
                distancia = euclidean(_values[i], _values[j]);
                toRet = (distancia > toRet) ? distancia : toRet;
            }
        }
        return toRet;
    }

    /**
     * <p>
     * Computes the euclidean distance between two vector of doubles with equal size.
     * </p>
     * @param _a First vector
     * @param _b Second vector
     * @return A double that is the euclidean distance.
     */
    public static double euclidean(double[] _a, double[] _b) {
        double toRet = 0;
        if (_a.length != _b.length) {
            System.out
                    .println("ERROR: Euclidean can not be used if vectors have different size!");
            toRet = -1;
        } else {
            for (int i = 0; i < _a.length; ++i) {
                toRet += (_a[i] - _b[i]) * (_a[i] - _b[i]);
            }
            toRet = Math.sqrt(toRet);
        }
        return toRet;
    }
}

Related

  1. max(float a[][][])
  2. max(float[][] a)
  3. max(float[][] originalValues, float[][] newValues, int[] indexArray, float value)
  4. max_abs(double[][] matrix)
  5. maxDifffer(double[][] pos)
  6. maxIndices(double M[][])
  7. maxInRowIndex(double[][] M, int row)
  8. maxtrixPermutation(int beforeArray[][])