Search in sources :

Example 16 with DoubleWrapper

use of net.jafama.DoubleWrapper in project elki by elki-project.

the class HSBHistogramQuadraticDistanceFunction method computeWeightMatrix.

/**
 * Compute the weight matrix for HSB similarity.
 *
 * @param quanth H bins
 * @param quants S bins
 * @param quantb B bins
 * @return Weight matrix
 */
public static double[][] computeWeightMatrix(final int quanth, final int quants, final int quantb) {
    final int dim = quanth * quants * quantb;
    // To return cosine
    final DoubleWrapper tmp = new DoubleWrapper();
    assert (dim > 0);
    final double[][] m = new double[dim][dim];
    for (int x = 0; x < dim; x++) {
        final int hx = x / (quantb * quants);
        final int sx = (x / quantb) % quants;
        final int bx = x % quantb;
        for (int y = x; y < dim; y++) {
            final int hy = y / (quantb * quants);
            final int sy = (y / quantb) % quants;
            final int by = y % quantb;
            final double shx = FastMath.sinAndCos((hx + .5) / quanth * MathUtil.TWOPI, tmp);
            final double chx = tmp.value;
            final double shy = FastMath.sinAndCos((hy + .5) / quanth * MathUtil.TWOPI, tmp);
            final double chy = tmp.value;
            final double cos = chx * (sx + .5) / quants - chy * (sy + .5) / quants;
            final double sin = shx * (sx + .5) / quants - shy * (sy + .5) / quants;
            final double db = (bx - by) / (double) quantb;
            final double val = 1. - FastMath.sqrt((db * db + sin * sin + cos * cos) / 5);
            m[x][y] = m[y][x] = val;
        }
    }
    return m;
}
Also used : DoubleWrapper(net.jafama.DoubleWrapper) ListSizeConstraint(de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ListSizeConstraint)

Aggregations

DoubleWrapper (net.jafama.DoubleWrapper)16 Reference (de.lmu.ifi.dbs.elki.utilities.documentation.Reference)4 ListSizeConstraint (de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ListSizeConstraint)1 CanvasSize (de.lmu.ifi.dbs.elki.visualization.projections.CanvasSize)1 SVGPath (de.lmu.ifi.dbs.elki.visualization.svg.SVGPath)1