All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.tsingjyujing.geo.basic.operations.Jaccardable.scala Maven / Gradle / Ivy

There is a newer version: 2.8.9-2.11
Show newest version
package com.github.tsingjyujing.geo.basic.operations

/**
  * Object which can get jaccard similarity and distance
  *
  * @author [email protected]
  * @tparam T Type to compare with
  */
trait Jaccardable[T <: Jaccardable[T]] {

    def jaccardSimilarity(x: T): Double

    /**
      * Auto get a fake distance by similarity
      *
      * @param x
      * @return
      */
    def jaccardDistance(x: T): Double = {
        val similarity = jaccardSimilarity(x)
        math.exp(-similarity * similarity)
    }
}

object Jaccardable {
    /**
      * J(A,B) = count(A & B)/count(A | B)*100%
      *
      * @param s1 Set1
      * @param s2 Set2
      * @tparam U similarity
      * @return
      */
    def commonJaccard[U](s1: Set[U], s2: Set[U]): Double = (s1 intersect s2).size * 1.0 / (s1 union s2).size
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy