public Pair<INDArray, Double> computeGaussianKernel(INDArray distances, double beta, int k) {
        // Compute Gaussian kernel row
        INDArray currP = Nd4j.create(k);
        for (int m = 0; m < k; m++)
            currP.putScalar(m, FastMath.exp(-beta * distances.getDouble(m + 1)));

        double sum = currP.sum(Integer.MAX_VALUE).getDouble(0);
        double h = 0.0;
        for (int m = 0; m < k; m++)
            h += beta * (distances.getDouble(m + 1) * currP.getDouble(m));

        h = (h / sum) + FastMath.log(sum);

        return new Pair<>(currP, h);
    }
public Pair < INDArray , Double > computeGaussianKernel ( INDArray distances , double beta , int k ) { INDArray currP = Nd4j . create ( k ) ; for ( int m = 0 ; m < k ; m ++ ) currP . putScalar ( m , FastMath . exp ( - beta * distances . getDouble ( m + 1 ) ) ) ; double sum = currP . sum ( Integer . MAX_VALUE ) . getDouble ( 0 ) ; double h = 0.0 ; for ( int m = 0 ; m < k ; m ++ ) h += beta * ( distances . getDouble ( m + 1 ) * currP . getDouble ( m ) ) ; h = ( h / sum ) + FastMath . log ( sum ) ; return new Pair < > ( currP , h ) ; }
Computes a gaussian kernel
given a vector of squared distance distances

@param distances
@param beta
@return