- # Compute colors for each neighbor (from darkest to lightest)
- sorted_dists = sort(-log(pred$getParams(index)$weights), index.return=TRUE)
- nn = min(limit, length(sorted_dists$x))
- min_dist = min(sorted_dists$x[1:nn])
- max_dist = max(sorted_dists$x[1:nn])
- color_values = floor(19.5*(sorted_dists$x[1:nn]-min_dist)/(max_dist-min_dist)) + 1
- colors = gray.colors(20,0.1,0.9)[color_values] #TODO: 20 == magic number
+ nn <- min(limit, length(weights))
+ sorted_dists = sort(-log(weights), index.return=TRUE)
+ # Compute colors for each neighbor (from darkest to lightest), if weights differ
+ if ( any( weights != weights[1] ) )
+ {
+ min_dist = min(sorted_dists$x[1:nn])
+ max_dist = max(sorted_dists$x[1:nn])
+ color_values = floor(19.5*(sorted_dists$x[1:nn]-min_dist)/(max_dist-min_dist)) + 1
+ colors = gray.colors(20,0.1,0.9)[color_values] #TODO: 20 == magic number
+ }
+ else
+ colors <- rep(colors()[17], length(weights))