public static double[][] computeWeightMatrix(final int quanth,final int quants,final int quantb){
  final int dim=quanth * quants * quantb;
  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 chx=Math.cos((hx + .5) / quanth * MathUtil.TWOPI);
      final double chy=Math.cos((hy + .5) / quanth * MathUtil.TWOPI);
      final double shx=MathUtil.cosToSin((hx + .5) / quanth * MathUtil.TWOPI,chx);
      final double shy=MathUtil.cosToSin((hy + .5) / quanth * MathUtil.TWOPI,chy);
      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. - Math.sqrt((db * db + sin * sin + cos * cos) / 5);
      m[x][y]=m[y][x]=val;
    }
  }
  return m;
}

public static double [ ] [ ] computeWeightMatrix ( final int quanth , final int quants , final int quantb ) { final int dim = quanth * quants * quantb ; 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 chx = Math . cos ( ( hx + .5 ) / quanth * MathUtil . TWOPI ) ; final double chy = Math . cos ( ( hy + .5 ) / quanth * MathUtil . TWOPI ) ; final double shx = MathUtil . cosToSin ( ( hx + .5 ) / quanth * MathUtil . TWOPI , chx ) ; final double shy = MathUtil . cosToSin ( ( hy + .5 ) / quanth * MathUtil . TWOPI , chy ) ; 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. - Math . sqrt ( ( db * db + sin * sin + cos * cos ) / 5 ) ; m [ x ] [ y ] = m [ y ] [ x ] = val ; } } return m ; }
compute the weight matrix for hsb similarity .
