cytomining / copairs

Find pairs and compute metrics between them.
BSD 3-Clause "New" or "Revised" License
6 stars 4 forks source link

Allow absolute cosine similarity #55

Closed shntnu closed 2 weeks ago

shntnu commented 10 months ago

Sometimes both, strong positive and strong negative correlations are meaningful, so we should allow for that.

One way to do this is to add a boolean absolute_value argument to pairwise_cosine

https://github.com/cytomining/copairs/blob/c10c93e1371c2209975b2ef3603fb34fd597d107/src/copairs/compute.py#L65-L69

def pairwise_cosine(x_sample: np.ndarray, y_sample: np.ndarray, absolute_value: bool = False) -> np.ndarray:
    x_norm = x_sample / np.linalg.norm(x_sample, axis=1)[:, np.newaxis]
    y_norm = y_sample / np.linalg.norm(y_sample, axis=1)[:, np.newaxis]
    c_sim = np.sum(x_norm * y_norm, axis=1)
    if absolute_value:
        c_sim = np.abs(c_sim)
    return c_sim
shntnu commented 10 months ago

One way to do this is to add a boolean absolute_value argument to pairwise_cosine

Is that reasonable?