Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stationary estimator and smapler #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/p5ab-hairpin/generate-figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def run(nstates, nsamples):

# Initialize MLHMM.
print "Initializing MLHMM with "+str(nstates)+" states."
estimator = bhmm.MLHMM(O, nstates)
estimator = bhmm.MLHMM(O, nstates,stationary=True)

# Plot initial guess.
plots.plot_state_assignments(estimator.hmm, None, O[0], time_units=time_units, obs_label=obs_label, tau=tau,
Expand All @@ -49,7 +49,7 @@ def run(nstates, nsamples):

# Initialize BHMM, using MLHMM model as initial model.
print "Initializing BHMM and running with "+str(nsamples)+" samples."
sampler = bhmm.BHMM(O, nstates, initial_model=mle)
sampler = bhmm.BHMM(O, nstates, initial_model=mle, stationary=True)

# Sample models.
bhmm_models = sampler.sample(nsamples=nsamples, save_hidden_state_trajectory=False)
Expand Down
4 changes: 2 additions & 2 deletions examples/p5ab-hairpin/hairpin-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def run(nstates, nsamples):

# Initialize MLHMM.
print "Initializing MLHMM with "+str(nstates)+" states."
estimator = bhmm.MLHMM(O, nstates)
estimator = bhmm.MLHMM(O, nstates, stationary=True)

# Plot initial guess.
plots.plot_state_assignments(estimator.hmm, None, O[0], time_units=time_units, obs_label=obs_label, tau=tau,
Expand All @@ -50,7 +50,7 @@ def run(nstates, nsamples):

# Initialize BHMM, using MLHMM model as initial model.
print "Initializing BHMM and running with "+str(nsamples)+" samples."
sampler = bhmm.BHMM(O, nstates, initial_model=mle)
sampler = bhmm.BHMM(O, nstates, initial_model=mle, stationary=True)

# Sample models.
bhmm_models = sampler.sample(nsamples=nsamples, save_hidden_state_trajectory=False)
Expand Down
2 changes: 1 addition & 1 deletion examples/rnase-h-d10a/generate-figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def run(nstates, nsamples):

# Initialize MLHMM.
print "Initializing MLHMM with "+str(nstates)+" states."
estimator = bhmm.MLHMM(O, nstates)
estimator = bhmm.MLHMM(O, nstates, stationary=True)

# Plot initial guess.
plots.plot_state_assignments(estimator.hmm, None, O[0], time_units=time_units, obs_label=obs_label, tau=tau,
Expand Down
6 changes: 4 additions & 2 deletions examples/synthetic-three-state-model/generate-figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def analyze_data(O, nstates, nsamples=1000, nobservations=None):

# Generate MLHMM.
print "Generating MLHMM..."
estimator = bhmm.MLHMM(O, nstates)
estimator = bhmm.MLHMM(O, nstates, stationary=True)

print "Initial guess:"
print str(estimator.hmm.output_model)
Expand All @@ -89,7 +89,7 @@ def analyze_data(O, nstates, nsamples=1000, nobservations=None):

# Initialize BHMM with MLHMM model.
print "Sampling models from BHMM..."
sampler = bhmm.BHMM(O, nstates, initial_model=mle)
sampler = bhmm.BHMM(O, nstates, initial_model=mle, stationary=True)
bhmm_models = sampler.sample(nsamples=nsamples, save_hidden_state_trajectory=False)

# Generate a sample saving a hidden state trajectory.
Expand Down Expand Up @@ -164,6 +164,8 @@ def generate_latex_table(true_hmm, sampled_hmm_list, conf=0.95, dt=1, time_unit=
table += '\t\tEquilibrium probability '
table += '\t\t& $\pi_{%d}$ & $%0.3f$' % (i+1, true_hmm.stationary_distribution[i])
for sampled_hmm in sampled_hmm_list:
print sampled_hmm
print 'trying to find distribution mean'
p = sampled_hmm.stationary_distribution_mean
p_lo, p_hi = sampled_hmm.stationary_distribution_conf
table += ' & $%0.3f_{\:%0.3f}^{\:%0.3f}$ ' % (p[i], p_lo[i], p_hi[i])
Expand Down
6 changes: 3 additions & 3 deletions examples/synthetic-three-state-model/synthetic-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import argparse

import bhmm
from bhmm.util import testsystems
import bhmm.util.testsystems as testsystems
from bhmm.util.analysis import generate_latex_table


Expand Down Expand Up @@ -36,7 +36,7 @@ def run(nstates, nsamples):

# Generate MLHMM.
print "Generating MLHMM..."
estimator = bhmm.MLHMM(O, nstates)
estimator = bhmm.MLHMM(O, nstates, stationary=True)

print "Initial guess:"
print str(estimator.hmm.output_model)
Expand All @@ -61,7 +61,7 @@ def run(nstates, nsamples):

# Initialize BHMM with MLHMM model.
print "Sampling models from BHMM..."
sampler = bhmm.BHMM(O, nstates, initial_model=mle)
sampler = bhmm.BHMM(O, nstates, initial_model=mle, stationary=True)
bhmm_models = sampler.sample(nsamples=nsamples, save_hidden_state_trajectory=False)

# Generate a sample saving a hidden state trajectory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,43 @@
\hline
& & & \multicolumn{3}{c}{\bf Estimated Model Parameters} \\ \cline{4-6}
\multicolumn{2}{l}{\bf Property} & \bf True Value & \bf 1 000 observations & \bf 10 000 observations & \bf 100 000 observations\\ \hline
Equilibrium probability & $\pi_{1}$ & $0.385$ & $0.678_{\:0.367}^{\:0.889}$ & $0.533_{\:0.442}^{\:0.629}$ & $0.517_{\:0.486}^{\:0.549}$ \\
& $\pi_{2}$ & $0.094$ & $0.246_{\:0.069}^{\:0.546}$ & $0.351_{\:0.264}^{\:0.434}$ & $0.381_{\:0.353}^{\:0.410}$ \\
& $\pi_{3}$ & $0.521$ & $0.077_{\:0.029}^{\:0.156}$ & $0.116_{\:0.091}^{\:0.144}$ & $0.101_{\:0.093}^{\:0.110}$ \\
\hline
Transition probability ($\Delta t = $1.0 ms) & $T_{11}$ & $0.980$ & $0.991_{\:0.981}^{\:0.997}$ & $0.989_{\:0.986}^{\:0.992}$ & $0.989_{\:0.988}^{\:0.990}$ \\
& $T_{12}$ & $0.015$ & $0.001_{\:0.000}^{\:0.006}$ & $0.003_{\:0.002}^{\:0.005}$ & $0.004_{\:0.003}^{\:0.004}$ \\
& $T_{13}$ & $0.005$ & $0.009_{\:0.003}^{\:0.018}$ & $0.008_{\:0.006}^{\:0.010}$ & $0.007_{\:0.006}^{\:0.008}$ \\
& $T_{21}$ & $0.063$ & $0.003_{\:0.000}^{\:0.017}$ & $0.005_{\:0.003}^{\:0.008}$ & $0.005_{\:0.004}^{\:0.005}$ \\
& $T_{22}$ & $0.900$ & $0.967_{\:0.932}^{\:0.988}$ & $0.976_{\:0.970}^{\:0.982}$ & $0.978_{\:0.977}^{\:0.980}$ \\
& $T_{23}$ & $0.037$ & $0.030_{\:0.010}^{\:0.068}$ & $0.019_{\:0.014}^{\:0.025}$ & $0.017_{\:0.015}^{\:0.018}$ \\
& $T_{31}$ & $0.003$ & $0.079_{\:0.029}^{\:0.146}$ & $0.036_{\:0.026}^{\:0.047}$ & $0.036_{\:0.033}^{\:0.040}$ \\
& $T_{32}$ & $0.007$ & $0.093_{\:0.028}^{\:0.193}$ & $0.057_{\:0.043}^{\:0.072}$ & $0.063_{\:0.058}^{\:0.068}$ \\
& $T_{33}$ & $0.990$ & $0.828_{\:0.711}^{\:0.920}$ & $0.907_{\:0.887}^{\:0.925}$ & $0.901_{\:0.894}^{\:0.907}$ \\
\hline
\hline
Transition rate (ms$^{-1}$) & $k_{12}$ & $0.015$ & $0.001_{\:0.000}^{\:0.006}$ & $0.003_{\:0.002}^{\:0.005}$ & $0.004_{\:0.003}^{\:0.004}$ \\
& $k_{13}$ & $0.005$ & $0.009_{\:0.003}^{\:0.018}$ & $0.008_{\:0.006}^{\:0.010}$ & $0.007_{\:0.006}^{\:0.008}$ \\
& $k_{21}$ & $0.063$ & $0.003_{\:0.000}^{\:0.017}$ & $0.005_{\:0.003}^{\:0.008}$ & $0.005_{\:0.004}^{\:0.005}$ \\
& $k_{23}$ & $0.037$ & $0.030_{\:0.010}^{\:0.068}$ & $0.019_{\:0.014}^{\:0.025}$ & $0.017_{\:0.015}^{\:0.018}$ \\
& $k_{31}$ & $0.003$ & $0.079_{\:0.029}^{\:0.146}$ & $0.036_{\:0.026}^{\:0.047}$ & $0.036_{\:0.033}^{\:0.040}$ \\
& $k_{32}$ & $0.007$ & $0.093_{\:0.028}^{\:0.193}$ & $0.057_{\:0.043}^{\:0.072}$ & $0.063_{\:0.058}^{\:0.068}$ \\
\hline
State mean lifetime (ms) & $t_{1}$ & $49.498$ & $128.116_{\:55.334}^{\:309.568}$ & $91.902_{\:70.769}^{\:120.147}$ & $93.429_{\:86.014}^{\:101.962}$ \\
& $t_{2}$ & $9.491$ & $36.448_{\:15.042}^{\:92.972}$ & $42.545_{\:33.175}^{\:54.544}$ & $45.889_{\:42.634}^{\:49.415}$ \\
& $t_{3}$ & $99.499$ & $5.986_{\:3.065}^{\:13.200}$ & $10.396_{\:8.396}^{\:12.904}$ & $9.555_{\:8.969}^{\:10.219}$ \\
\hline
Relaxation time (ms) & $\tau_{1}$ & $56.704$ & $54.467_{\:26.737}^{\:109.929}$ & $51.201_{\:41.887}^{\:62.042}$ & $53.387_{\:50.301}^{\:56.513}$ \\
& $\tau_{2}$ & $8.377$ & $5.191_{\:2.656}^{\:10.780}$ & $8.855_{\:7.255}^{\:10.815}$ & $8.335_{\:7.857}^{\:8.866}$ \\
\hline
\hline
State force mean (pN) & $\mu_{1}$ & $3.000$ & $5.603_{\:5.588}^{\:5.619}$ & $5.600_{\:5.595}^{\:5.606}$ & $5.599_{\:5.597}^{\:5.600}$ \\
& $\mu_{2}$ & $4.700$ & $2.950_{\:2.818}^{\:3.085}$ & $3.003_{\:2.970}^{\:3.039}$ & $2.996_{\:2.986}^{\:3.007}$ \\
& $\mu_{3}$ & $5.600$ & $4.706_{\:4.598}^{\:4.822}$ & $4.712_{\:4.694}^{\:4.731}$ & $4.700_{\:4.694}^{\:4.706}$ \\
\hline
State force std dev (pN) & $s_{1}$ & $1.000$ & $0.198_{\:0.188}^{\:0.209}$ & $0.198_{\:0.195}^{\:0.202}$ & $0.200_{\:0.198}^{\:0.201}$ \\
& $s_{2}$ & $0.300$ & $1.011_{\:0.918}^{\:1.114}$ & $0.994_{\:0.970}^{\:1.018}$ & $0.998_{\:0.991}^{\:1.005}$ \\
& $s_{3}$ & $0.200$ & $0.417_{\:0.290}^{\:0.524}$ & $0.291_{\:0.277}^{\:0.305}$ & $0.298_{\:0.294}^{\:0.303}$ \\
Equilibrium probability & $\pi_{1}$ & $0.385$ & $0.609_{\:0.247}^{\:0.896}$ & $0.576_{\:0.479}^{\:0.672}$ & $0.527_{\:0.495}^{\:0.559}$ \\
& $\pi_{2}$ & $0.094$ & $0.124_{\:0.039}^{\:0.270}$ & $0.323_{\:0.240}^{\:0.416}$ & $0.093_{\:0.085}^{\:0.101}$ \\
& $\pi_{3}$ & $0.521$ & $0.267_{\:0.047}^{\:0.613}$ & $0.101_{\:0.076}^{\:0.132}$ & $0.379_{\:0.351}^{\:0.409}$ \\
\hline
Transition probability ($\Delta t = $1.0 ms) & $T_{11}$ & $0.980$ & $0.993_{\:0.985}^{\:0.998}$ & $0.990_{\:0.987}^{\:0.993}$ & $0.990_{\:0.989}^{\:0.991}$ \\
& $T_{12}$ & $0.015$ & $0.006_{\:0.002}^{\:0.014}$ & $0.003_{\:0.002}^{\:0.004}$ & $0.006_{\:0.006}^{\:0.007}$ \\
& $T_{13}$ & $0.005$ & $0.001_{\:0.000}^{\:0.004}$ & $0.007_{\:0.005}^{\:0.009}$ & $0.003_{\:0.003}^{\:0.004}$ \\
& $T_{21}$ & $0.063$ & $0.032_{\:0.010}^{\:0.074}$ & $0.005_{\:0.003}^{\:0.008}$ & $0.036_{\:0.033}^{\:0.040}$ \\
& $T_{22}$ & $0.900$ & $0.933_{\:0.880}^{\:0.970}$ & $0.977_{\:0.971}^{\:0.982}$ & $0.901_{\:0.894}^{\:0.908}$ \\
& $T_{23}$ & $0.037$ & $0.035_{\:0.009}^{\:0.084}$ & $0.018_{\:0.014}^{\:0.023}$ & $0.063_{\:0.058}^{\:0.068}$ \\
& $T_{31}$ & $0.003$ & $0.002_{\:0.000}^{\:0.011}$ & $0.039_{\:0.029}^{\:0.051}$ & $0.005_{\:0.004}^{\:0.005}$ \\
& $T_{32}$ & $0.007$ & $0.017_{\:0.005}^{\:0.040}$ & $0.058_{\:0.045}^{\:0.075}$ & $0.015_{\:0.014}^{\:0.017}$ \\
& $T_{33}$ & $0.990$ & $0.981_{\:0.956}^{\:0.994}$ & $0.903_{\:0.882}^{\:0.921}$ & $0.980_{\:0.978}^{\:0.981}$ \\
\hline
\hline
Transition rate (ms$^{-1}$) & $k_{12}$ & $0.015$ & $0.006_{\:0.002}^{\:0.014}$ & $0.003_{\:0.002}^{\:0.004}$ & $0.006_{\:0.006}^{\:0.007}$ \\
& $k_{13}$ & $0.005$ & $0.001_{\:0.000}^{\:0.004}$ & $0.007_{\:0.005}^{\:0.009}$ & $0.003_{\:0.003}^{\:0.004}$ \\
& $k_{21}$ & $0.063$ & $0.032_{\:0.010}^{\:0.074}$ & $0.005_{\:0.003}^{\:0.008}$ & $0.036_{\:0.033}^{\:0.040}$ \\
& $k_{23}$ & $0.037$ & $0.035_{\:0.009}^{\:0.084}$ & $0.018_{\:0.014}^{\:0.023}$ & $0.063_{\:0.058}^{\:0.068}$ \\
& $k_{31}$ & $0.003$ & $0.002_{\:0.000}^{\:0.011}$ & $0.039_{\:0.029}^{\:0.051}$ & $0.005_{\:0.004}^{\:0.005}$ \\
& $k_{32}$ & $0.007$ & $0.017_{\:0.005}^{\:0.040}$ & $0.058_{\:0.045}^{\:0.075}$ & $0.015_{\:0.014}^{\:0.017}$ \\
\hline
State mean lifetime (ms) & $t_{1}$ & $49.498$ & $185.195_{\:68.381}^{\:556.289}$ & $103.364_{\:78.952}^{\:136.436}$ & $101.562_{\:92.914}^{\:111.068}$ \\
& $t_{2}$ & $9.491$ & $16.424_{\:8.007}^{\:36.775}$ & $42.709_{\:33.876}^{\:54.814}$ & $9.574_{\:8.919}^{\:10.348}$ \\
& $t_{3}$ & $99.499$ & $65.388_{\:23.763}^{\:168.941}$ & $9.914_{\:8.011}^{\:12.252}$ & $49.227_{\:45.544}^{\:53.111}$ \\
\hline
Relaxation time (ms) & $\tau_{1}$ & $56.704$ & $84.338_{\:40.682}^{\:174.791}$ & $52.374_{\:43.244}^{\:63.413}$ & $56.871_{\:53.479}^{\:60.398}$ \\
& $\tau_{2}$ & $8.377$ & $13.226_{\:6.719}^{\:25.925}$ & $8.564_{\:7.041}^{\:10.344}$ & $8.443_{\:7.908}^{\:9.080}$ \\
\hline
\hline
State force mean (pN) & $\mu_{1}$ & $3.000$ & $5.596_{\:5.581}^{\:5.611}$ & $5.599_{\:5.594}^{\:5.604}$ & $5.600_{\:5.599}^{\:5.602}$ \\
& $\mu_{2}$ & $4.700$ & $4.659_{\:4.604}^{\:4.715}$ & $3.005_{\:2.969}^{\:3.041}$ & $4.699_{\:4.692}^{\:4.705}$ \\
& $\mu_{3}$ & $5.600$ & $2.967_{\:2.842}^{\:3.087}$ & $4.702_{\:4.682}^{\:4.721}$ & $2.999_{\:2.988}^{\:3.008}$ \\
\hline
State force std dev (pN) & $s_{1}$ & $1.000$ & $0.192_{\:0.181}^{\:0.204}$ & $0.200_{\:0.196}^{\:0.204}$ & $0.200_{\:0.199}^{\:0.202}$ \\
& $s_{2}$ & $0.300$ & $0.320_{\:0.284}^{\:0.362}$ & $1.009_{\:0.985}^{\:1.033}$ & $0.302_{\:0.297}^{\:0.306}$ \\
& $s_{3}$ & $0.200$ & $1.074_{\:0.990}^{\:1.164}$ & $0.307_{\:0.292}^{\:0.323}$ & $0.997_{\:0.990}^{\:1.005}$ \\
\hline
\hline
\end{tabular*}
Expand Down
Loading