Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dice formula correction #186

Merged
merged 2 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cpp/include/raft/sparse/distance/bin_distance.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class jaccard_expanded_distances_t : public distances_t<value_t> {

/**
* Dice distance using the expanded form:
* 1 - ((2 * sum(x_k * y_k)) / (sum(x_k)^2 + sum(y_k)^2))
* 1 - ((2 * sum(x_k * y_k)) / (sum(x_k) + sum(y_k)))
*/
template <typename value_idx = int, typename value_t = float>
class dice_expanded_distances_t : public distances_t<value_t> {
Expand Down Expand Up @@ -183,8 +183,10 @@ class dice_expanded_distances_t : public distances_t<value_t> {
b_indices, b_data, config_->b_nnz, config_->a_nrows, config_->b_nrows,
config_->handle, config_->allocator, config_->stream,
[] __device__ __host__(value_t dot, value_t q_norm, value_t r_norm) {
value_t q_r_union = (q_norm * q_norm) + (r_norm * r_norm);
return (2 * dot) / q_r_union;
value_t q_r_union = q_norm + r_norm;
// deal with potential for 0 in denominator by forcing 0/1 instead
return 1 -
((q_r_union != 0) * (2 * dot)) / ((q_r_union == 0) + q_r_union);
});
}

Expand Down
1 change: 1 addition & 0 deletions cpp/include/raft/sparse/distance/distance.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void pairwiseDistance(value_t *out,
break;
case raft::distance::DistanceType::DiceExpanded:
dice_expanded_distances_t<value_idx, value_t>(input_config).compute(out);
break;

default:
THROW("Unsupported distance: %d", metric);
Expand Down