submitted

This commit is contained in:
aj 2021-01-05 11:10:29 +00:00
parent afb259bd6d
commit 029789a67c
6 changed files with 1294 additions and 436 deletions

File diff suppressed because one or more lines are too long

View File

@ -53,7 +53,7 @@ plt.show()
# %%
for obs in observations:
print(f'{obs} -> State 1: {gaussian(obs, state1.mean, state1.std_dev)},',
'State 2: {gaussian(obs, state2.mean, state2.std_dev)}')
f'State 2: {gaussian(obs, state2.mean, state2.std_dev)}')
# %%
@ -357,33 +357,39 @@ plt.show()
# # Multiple Iterations
# %%
iterations = 5
iterations = 50
mean = [state1.mean, state2.mean]
var = [state1.variance, state2.variance]
fig = plt.figure(dpi=fig_dpi, tight_layout=True)
ax = fig.add_subplot(1, 1, 1, xmargin=0, ymargin=0)
plt.plot(x, [gaussian(i, mean[0], sqrt(var[0])) for i in x], '--', c='r', linewidth=1.0)
plt.plot(x, [gaussian(i, mean[1], sqrt(var[1])) for i in x], '--', c='b', linewidth=1.0)
iter_mean = [state1.mean, state2.mean]
iter_var = [state1.variance, state2.variance]
iter_state_transitions = state_transition
ax.plot(x, [gaussian(i, iter_mean[0], sqrt(iter_var[0])) for i in x], '--', c='r', linewidth=1.0)
ax.plot(x, [gaussian(i, iter_mean[1], sqrt(iter_var[1])) for i in x], '--', c='b', linewidth=1.0)
label1=None
label2=None
for i in range(iterations):
model = MarkovModel(states=[State(mean[0], var[0], state1.entry, state1.exit),
State(mean[1], var[1], state2.entry, state2.exit)],
observations=observations,
state_transitions=state_transition)
model.populate()
iter_model = MarkovModel(states=[State(iter_mean[0], iter_var[0], state1.entry, state1.exit),
State(iter_mean[1], iter_var[1], state2.entry, state2.exit)],
observations=observations,
state_transitions=iter_state_transitions).populate()
mean = model.reestimated_mean()
var = model.reestimated_variance()
# NEW PARAMETERS
iter_mean = iter_model.reestimated_mean()
iter_var = iter_model.reestimated_variance()
iter_state_transitions[1:3, 1:3] = iter_model.reestimated_state_transitions()
print(f"mean ({i}): ", mean)
print(f"var ({i}): ", var)
print(f"mean ({i}): ", iter_mean)
print(f"var ({i}): ", iter_var)
print(iter_model.reestimated_state_transitions())
print()
state_1_y = [gaussian(i, mean[0], sqrt(var[0])) for i in x]
state_2_y = [gaussian(i, mean[1], sqrt(var[1])) for i in x]
state_1_y = [gaussian(i, iter_mean[0], sqrt(iter_var[0])) for i in x]
state_2_y = [gaussian(i, iter_mean[1], sqrt(iter_var[1])) for i in x]
style = '--'
linewidth = 1.0
@ -393,22 +399,19 @@ for i in range(iterations):
label1='State 1'
label2='State 2'
plt.plot(x, state_1_y, style, c='r', label=label1, linewidth=linewidth)
plt.plot(x, state_2_y, style, c='b', label=label2, linewidth=linewidth)
ax.plot(x, state_1_y, style, c='r', label=label1, linewidth=linewidth)
ax.plot(x, state_2_y, style, c='b', label=label2, linewidth=linewidth)
plt.title("Probability Density Function Iterations")
ax.set_title("Probability Density Function Iterations")
plt.xlabel(x_label)
plt.ylabel(y_label)
plt.grid(linestyle="--")
plt.legend()
ax.set_xlabel(x_label)
ax.set_ylabel(y_label)
ax.grid(linestyle="--")
ax.legend()
fig = matplotlib.pyplot.gcf()
fig.set_dpi(fig_dpi)
fig.set_tight_layout(True)
if fig_export or True:
if fig_export:
savefig("report/res/iterated-pdfs.png")
plt.show()
fig.show()
# %% [markdown]
# # Baum-Welch State Transition Re-estimations
@ -419,6 +422,11 @@ model = MarkovModel(states=[state1, state2],
state_transitions=state_transition).populate()
print(a_matrix)
print(model.reestimated_state_transitions())
model.reestimated_state_transitions()
# %%

View File

@ -1,6 +1,7 @@
% Encoding: UTF-8
@comment{x-kbibtex-encoding=utf-8}
@misc{towards-data-science-markov-intro,
author = {Rocca, Joseph},
author = {Joseph Rocca},
howpublished = {Online},
month = feb,
organization = {Towards Data Science},
@ -10,52 +11,116 @@
year = {2019}
}
@Article{numpy,
author = {Charles R. Harris and K. Jarrod Millman and St{'{e}}fan J. van der Walt and Ralf Gommers and Pauli Virtanen and David Cournapeau and Eric Wieser and Julian Taylor and Sebastian Berg and Nathaniel J. Smith and Robert Kern and Matti Picus and Stephan Hoyer and Marten H. van Kerkwijk and Matthew Brett and Allan Haldane and Jaime Fern{'{a}}ndez del R{'{\i}}o and Mark Wiebe and Pearu Peterson and Pierre G{'{e}}rard-Marchant and Kevin Sheppard and Tyler Reddy and Warren Weckesser and Hameer Abbasi and Christoph Gohlke and Travis E. Oliphant},
journal = {Nature},
title = {Array programming with {NumPy}},
year = {2020},
month = sep,
number = {7825},
pages = {357--362},
volume = {585},
doi = {10.1038/s41586-020-2649-2},
publisher = {Springer Science and Business Media {LLC}},
url = {https://doi.org/10.1038/s41586-020-2649-2},
urldate = {2021-1-1},
@article{numpy,
author = {Charles R. Harris and K. Jarrod Millman and St{'{e}}fan J. van der Walt and Ralf Gommers and Pauli Virtanen and David Cournapeau and Eric Wieser and Julian Taylor and Sebastian Berg and Nathaniel J. Smith and Robert Kern and Matti Picus and Stephan Hoyer and Marten H. van Kerkwijk and Matthew Brett and Allan Haldane and Jaime Fern{'{a}}ndez del R{'ı}o and Mark Wiebe and Pearu Peterson and Pierre G{'{e}}rard-Marchant and Kevin Sheppard and Tyler Reddy and Warren Weckesser and Hameer Abbasi and Christoph Gohlke and Travis E. Oliphant},
doi = {10.1038/s41586-020-2649-2},
journal = {Nature},
month = sep,
number = {7825},
pages = {357362},
publisher = {Springer Science and Business Media {LLC}},
title = {Array programming with {NumPy}},
url = {https://doi.org/10.1038/s41586-020-2649-2},
urldate = {2021-1-1},
volume = {585},
year = {2020}
}
@Misc{python,
author = {Van Rossum, Guido and others},
howpublished = {Online},
title = {Python 3 Documentation},
year = {2008},
url = {https://docs.python.org/3/},
urldate = {2021-1-1},
@misc{python,
author = {Guido {Van Rossum} and others},
howpublished = {Online},
title = {Python 3 Documentation},
url = {https://docs.python.org/3/},
urldate = {2021-1-1},
year = {2008}
}
@InProceedings{jupyter,
author = {Thomas Kluyver and Benjamin Ragan-Kelley and Fernando P{\'e}rez and Brian Granger and Matthias Bussonnier and Jonathan Frederic and Kyle Kelley and Jessica Hamrick and Jason Grout and Sylvain Corlay and Paul Ivanov and Dami{\'a}n Avila and Safia Abdalla and Carol Willing and Jupyter development team},
booktitle = {Positioning and Power in Academic Publishing: Players, Agents and Agendas},
title = {Jupyter Notebooks - a publishing format for reproducible computational workflows},
year = {2016},
address = {Netherlands},
editor = {Fernando Loizides and Birgit Scmidt},
pages = {87--90},
publisher = {IOS Press},
abstract = {It is increasingly necessary for researchers in all fields to write computer code, and in order to reproduce research results, it is important that this code is published. We present Jupyter notebooks, a document format for publishing code, results and explanations in a form that is both readable and executable. We discuss various tools and use cases for notebook documents.},
url = {https://eprints.soton.ac.uk/403913/},
urldate = {2021-1-1},
@inproceedings{jupyter,
abstract = {It is increasingly necessary for researchers in all fields to write computer code, and in order to reproduce research results, it is important that this code is published. We present Jupyter notebooks, a document format for publishing code, results and explanations in a form that is both readable and executable. We discuss various tools and use cases for notebook documents.},
address = {Netherlands},
author = {Thomas Kluyver and Benjamin Ragan-Kelley and Fernando Pérez and Brian Granger and Matthias Bussonnier and Jonathan Frederic and Kyle Kelley and Jessica Hamrick and Jason Grout and Sylvain Corlay and Paul Ivanov and Damián Avila and Safia Abdalla and Carol Willing and Jupyter development team},
booktitle = {Positioning and Power in Academic Publishing: Players, Agents and Agendas},
editor = {Fernando Loizides and Birgit Scmidt},
pages = {8790},
publisher = {IOS Press},
title = {Jupyter Notebooks - a publishing format for reproducible computational workflows},
url = {https://eprints.soton.ac.uk/403913/},
urldate = {2021-1-1},
year = {2016}
}
@Book{standford-hmm-book,
author = {Dan Jurafsky and James H. Martin},
title = {Speech and Language Processing},
year = {2020},
edition = {3 (Draft)},
chapter = {A},
url = {https://web.stanford.edu/~jurafsky/slp3/},
urldate = {2021-1-3},
@book{standford-hmm-book,
author = {Dan Jurafsky and James H. Martin},
chapter = {A},
edition = {3 (Draft)},
title = {Speech and Language Processing},
url = {https://web.stanford.edu/~jurafsky/slp3/A.pdf},
urldate = {2021-1-3},
year = {2020}
}
@comment{jabref-meta: databaseType:bibtex;}
@article{pj-h-forward-backward,
author = {Philip Jackson},
journaltitle = {EEEM030 - Speech \& Audio Processing \& Recognition},
month = nov,
number = {H},
organization = {University of Surrey},
pages = {H.4, H.6, H.12},
title = {HMM Likelihoods},
year = {2020}
}
@article{pj-h-baum-welch,
author = {Philip Jackson},
journaltitle = {EEEM030 - Speech \& Audio Processing \& Recognition},
month = nov,
number = {K},
organization = {University of Surrey},
pages = {K.13, K.14, K.15},
title = {HMM Training},
year = {2020}
}
@article{pj-h-pdf-re-estimate,
author = {Philip Jackson},
journaltitle = {EEEM030 - Speech \& Audio Processing \& Recognition},
month = nov,
number = {N},
organization = {University of Surrey},
pages = {N.8, N.12, N.13},
title = {Continuous HMM},
year = {2020}
}
@article{wolfram-gaussian,
author = {Eric W. Weisstein},
journalsubtitle = {A Wolfram Web Resource},
journaltitle = {MathWorld},
title = {Gaussian Function},
url = {https://mathworld.wolfram.com/GaussianFunction.html},
urldate = {2020-1-4}
}
@article{wolfram-monotone,
author = {Christopher Stover},
journalsubtitle = {A Wolfram Web Resource},
journaltitle = {MathWorld},
title = {Monotonic Function},
url = {https://mathworld.wolfram.com/MonotonicFunction.html},
urldate = {2020-1-5}
}
@article{hunter2007matplotlib,
author = {John D Hunter},
doi = {10.1109/MCSE.2007.55},
journal = {Computing in science \& engineering},
number = {3},
pages = {9095},
publisher = {IEEE},
title = {Matplotlib: A 2D graphics environment},
volume = {9},
year = {2007}
}
@Comment{jabref-meta: databaseType:bibtex;}

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 107 KiB

After

Width:  |  Height:  |  Size: 120 KiB

File diff suppressed because one or more lines are too long