set

Set

Methods

jaccard

(static) jaccard(sa, sb) → {number}

Computes the Jaccard distance between input sets sa and sb. This distance is always between 0 and 1.

Example
// Set for :-)
var sa = new Set( ':-)' );
// Set for :-(
var sb = new Set( ':-(' );
jaccard( sa, sb );
// -> 0.5
Parameters
Name Type Description
sa set

the first set.

sb set

the second set.

Returns

the Jaccard distance between sa and sb.

Type
number

tversky

(static) tversky(sa, sb, alphaopt, betaopt) → {number}

Computes the tversky distance between input sets sa and sb. This distance is always between 0 and 1. Tversky calls sa as prototype and sb as variant. The alpha corresponds to the weight of prototype, whereas beta corresponds to the weight of variant.

Example
// Set for :-)
var sa = new Set( ':-)' );
// Set for :p
var sb = new Set( ':p' );
tversky( sa, sb, 1, 0 );
// -> 0.6666666666666667
tversky( sa, sb );
// -> 0.6
tversky( sa, sb, 0.5, 0.5 );
// -> 0.6
tversky( sa, sb, 0, 1 );
// -> 0.5
Parameters
Name Type Attributes Default Description
sa set

the first set or the prototype.

sb set

the second set or the variant.

alpha number <optional>
0.5

the prototype weight.

beta number <optional>
0.5

the variant weight.

Returns

the tversky distance between sa and sb.

Type
number