Skip to content

Commit

Permalink
Improving clustering plots.
Browse files Browse the repository at this point in the history
  • Loading branch information
roim committed Nov 2, 2015
1 parent 810e030 commit 3276d35
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion clustering/kde.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015 Rodrigo Roim Ferreira
# Copyright 2015 Rodrigo Roim Ferreira
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
25 changes: 20 additions & 5 deletions plotting/clustering.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015 Rodrigo Roim Ferreira
# Copyright 2015 Rodrigo Roim Ferreira
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -18,19 +18,34 @@
import matplotlib.pyplot as _pl
import numpy as _np

import clustering as _clst
import clustering.kde as _kde


# Sample data (Ode to Joy): x = _np.array([5.129283017, 4, 5.044394119, 4, 4, 3.906890596, 4.857980995, 3.906890596, 5.129283017, 5.129283017, 5.087462841, 3.807354922, 5.044394119, 4, 4.087462841, 4, 4.700439718, 3.906890596, 4.087462841, 4, 4.857980995, 4.584962501, 3.906890596, 3.321928095, 3.807354922, 3.807354922, 3.807354922, 4.169925001, 2.807354922, 3.807354922, 3.906890596, 3.906890596, 4.169925001, 3.906890596, 3.700439718, 3.700439718, 5.129283017])
def plot_kde(x, bw=0.15, bounds=(1,12)):
# Sample data (Ode to Joy): x = _np.log2([20, 23, 21, 23, 23, 22, 24, 22, 22, 20, 22, 22, 34, 10, 44, 21, 21, 21, 23, 23, 22, 25, 22, 50, 22, 22, 33, 10, 50, 21, 21, 20, 25, 22, 10, 11, 25, 25, 22, 10, 10, 24, 22, 25, 22, 26, 44, 23, 20, 22, 22, 21, 20, 11, 10, 50, 22, 24, 33, 11, 53])
def plot_histogram(x, bounds=(1, 12)):
"""Plots a histogram for a given array."""
plot_width = bounds[1] - bounds[0]
hist_points = _np.linspace(bounds[0], bounds[1], 10*plot_width)
_pl.hist(x, bins=hist_points, range=bounds, fc='gray', histtype='stepfilled', alpha=0.5, normed=False)

_pl.xlabel("Duração (lg da quantidade de janelas)")
_pl.ylabel("Quantidade de notas")
_pl.show()
return


def plot_kde(x, bw=0.15, bounds=(1, 12)):
"""Plots a histogram and the KDE for a given array."""
plot_width = bounds[1] - bounds[0]

hist_points = _np.linspace(bounds[0], bounds[1], 10*plot_width)
_pl.hist(x, bins=hist_points, range=bounds, fc='gray', histtype='stepfilled', alpha=0.5, normed=True)

kde_points = _np.linspace(bounds[0], bounds[1], 100*plot_width)
pdf = _clst.kde(x, kde_points, bw)
pdf = _kde.kde(x, kde_points, bw)
_pl.plot(kde_points, pdf, color='red', alpha=0.75, lw=2)

_pl.xlabel("Duração (lg da quantidade de janelas)")
_pl.ylabel("Quantidade de notas (normalizada)")
_pl.show()
return

0 comments on commit 3276d35

Please sign in to comment.