2016-12-12 23:10:39 +08:00
|
|
|
"""
|
|
|
|
|
==============================
|
|
|
|
|
Beta-divergence loss functions
|
|
|
|
|
==============================
|
|
|
|
|
|
|
|
|
|
A plot that compares the various Beta-divergence loss functions supported by
|
2020-06-16 16:44:13 +08:00
|
|
|
the Multiplicative-Update ('mu') solver in :class:`~sklearn.decomposition.NMF`.
|
2021-10-22 21:33:22 +08:00
|
|
|
|
2016-12-12 23:10:39 +08:00
|
|
|
"""
|
2021-10-22 21:33:22 +08:00
|
|
|
|
2016-12-12 23:10:39 +08:00
|
|
|
import numpy as np
|
|
|
|
|
import matplotlib.pyplot as plt
|
2019-10-28 22:46:16 +08:00
|
|
|
from sklearn.decomposition._nmf import _beta_divergence
|
2016-12-12 23:10:39 +08:00
|
|
|
|
|
|
|
|
x = np.linspace(0.001, 4, 1000)
|
|
|
|
|
y = np.zeros(x.shape)
|
|
|
|
|
|
|
|
|
|
colors = "mbgyr"
|
|
|
|
|
for j, beta in enumerate((0.0, 0.5, 1.0, 1.5, 2.0)):
|
|
|
|
|
for i, xi in enumerate(x):
|
|
|
|
|
y[i] = _beta_divergence(1, xi, 1, beta)
|
|
|
|
|
name = "beta = %1.1f" % beta
|
|
|
|
|
plt.plot(x, y, label=name, color=colors[j])
|
|
|
|
|
|
|
|
|
|
plt.xlabel("x")
|
|
|
|
|
plt.title("beta-divergence(1, x)")
|
|
|
|
|
plt.legend(loc=0)
|
|
|
|
|
plt.axis([0, 4, 0, 3])
|
|
|
|
|
plt.show()
|