# GenreTree Distance¶

## Overview¶

Compares the Paths created by munin.provider.genre.GenreTreeProvider.

## Example¶

>>> dfunc = GenreTreeDistance(genre_tree_provider)
>>> dfunc.compare_single_path((190, 1, 0), (190, 1, 1))
0.333
>>> dfunc.compare_single_path((190, 0, 1), (190, 1, 1))
0.666
>>> dfunc(
...     [(190, 1, 0), (190, 1, 1)],
...     [(190, 1, 1), (190, 0, 1)]
... )
0.333 # Take the lowest possible distance. (Complete Link)


## Reference¶

class munin.distance.genre.GenreTreeAvgDistance(provider=None)[source]

Like munin.distance.genre.GenreTreeDistance, but use Average Linkage instead of Single Linkage.

This is recommended if you have long genre descriptions, like produced by munin.provider.genre.DiscogsGenreProvider.

This class is supposed to be overriden, but can also be used as fallback.

__call__ is implemented as shortcut to compute()

Parameters: name (String.) – Name of the DistanceFunction (used for display)
class munin.distance.genre.GenreTreeDistance(provider=None)[source]

DistanceFunction Calculator for comparing two lists of GenrePaths.

(Lists of GenrePaths as returned by the GenreTree Provider)

This class is supposed to be overriden, but can also be used as fallback.

__call__ is implemented as shortcut to compute()

Parameters: name (String.) – Name of the DistanceFunction (used for display)
do_compute(lefts, rights)[source]

Calculate distance between two genre paths by using complete linkage.

Parameters: lefts – A list of Genre Paths. rights – A list of Genre Paths to compare with. A distance between 0.0 and 1.0 (max diversity.)
munin.distance.genre.compare_single_path(left, right)[source]

Compare a single path with another.

Returns: The ratio of matching numbers divided by max. length of both.