Skip to content

Commit

Permalink
Merge pull request #11 from Dani-dB/toy-models
Browse files Browse the repository at this point in the history
Example files update
  • Loading branch information
HadrienNU authored May 30, 2024
2 parents 403e9f7 + b01cf00 commit 15f62c3
Show file tree
Hide file tree
Showing 5 changed files with 599 additions and 781 deletions.
7 changes: 4 additions & 3 deletions examples/toy_models/plot_1D_Double_Well.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@
axs[1].plot(xfa, model_simu.diffusion(xfa.reshape(-1, 1)), label="Exact")
trainforce = fl.functions.Polynomial(deg=3, coefficients=np.array([0, 0, 0, 0]))
trainmodel = fl.models.Overdamped(force=trainforce, diffusion=fl.functions.Polynomial(deg=0, coefficients=np.asarray([0.9])), has_bias=False)
for name, transitioncls in zip(
for name,marker, transitioncls in zip(
["Euler", "Ozaki", "ShojiOzaki", "Elerian", "Kessler", "Drozdov"],
["x", "|",".","1","2","3"],
[
fl.EulerDensity,
fl.OzakiDensity,
Expand All @@ -82,8 +83,8 @@
estimator = fl.LikelihoodEstimator(transitioncls(trainmodel))
res = estimator.fit_fetch(data)
print(res.coefficients)
axs[0].plot(xfa, res.force(xfa.reshape(-1, 1)), label=name)
axs[1].plot(xfa, res.diffusion(xfa.reshape(-1, 1)), label=name)
axs[0].plot(xfa, res.force(xfa.reshape(-1, 1)),marker=marker, label=name)
axs[1].plot(xfa, res.diffusion(xfa.reshape(-1, 1)), marker=marker,label=name)
axs[0].legend()
axs[1].legend()
plt.show()
7 changes: 4 additions & 3 deletions examples/toy_models/plot_biased_1D_Double_Well.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@
model_simu.remove_bias()
axs[0].plot(xfa, model_simu.force(xfa.reshape(-1, 1)), label="Exact")
axs[1].plot(xfa, model_simu.diffusion(xfa.reshape(-1, 1)), label="Exact")
for name, transitioncls in zip(
for name,marker, transitioncls in zip(
["Euler", "Ozaki", "ShojiOzaki", "Elerian", "Kessler", "Drozdov"],
["x", "|",".","1","2","3"],
[
fl.EulerDensity,
fl.OzakiDensity,
Expand All @@ -84,8 +85,8 @@
res = estimator.fit_fetch(data)
print(name, res.coefficients)
res.remove_bias()
axs[0].plot(xfa, res.force(xfa.reshape(-1, 1)), label=name)
axs[1].plot(xfa, res.diffusion(xfa.reshape(-1, 1)), label=name)
axs[0].plot(xfa, res.force(xfa.reshape(-1, 1)),marker=marker, label=name)
axs[1].plot(xfa, res.diffusion(xfa.reshape(-1, 1)),marker=marker, label=name)
axs[0].legend()
axs[1].legend()
plt.show()
27 changes: 11 additions & 16 deletions examples/toy_models/plot_biased_2D_Double_Well.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,16 @@ def colvar(x, y):
axs[1].set_ylabel("$D(x)$")
axs[1].grid()

res_vec = []
names = []

KM_Estimator = fl.KramersMoyalEstimator(deepcopy(trainmodel))
res_KM = KM_Estimator.fit_fetch(deepcopy(proj_data))
res_vec.append(res_KM)
names.append("KramersMoyal")
axs[0].plot(xfa, res_KM.force(xfa.reshape(-1, 1)), label="KM")
axs[1].plot(xfa, res_KM.diffusion(xfa.reshape(-1, 1)), label="KM")
for name, transitioncls in zip(
res_KM = KM_Estimator.fit_fetch(proj_data)

axs[0].plot(xfa, res_KM.force(xfa.reshape(-1, 1)), marker="x",label="KramersMoyal")
axs[1].plot(xfa, res_KM.diffusion(xfa.reshape(-1, 1)), marker="x",label="KramersMoyal")
print("KramersMoyal ", res_KM.coefficients)
for name,marker, transitioncls in zip(
["Euler", "Elerian", "Kessler", "Drozdov"],
["|","1","2","3"],
[
fl.EulerDensity,
fl.ElerianDensity,
Expand All @@ -167,17 +167,12 @@ def colvar(x, y):
):
estimator = fl.LikelihoodEstimator(transitioncls(deepcopy(trainmodel)))
res = estimator.fit_fetch(deepcopy(proj_data))
res_vec.append(res)
names.append(name)
res.remove_bias()
axs[0].plot(xfa, res.force(xfa.reshape(-1, 1)), label=name)
axs[1].plot(xfa, res.diffusion(xfa.reshape(-1, 1)), label=name)
print(name, res.coefficients)
axs[0].plot(xfa, res.force(xfa.reshape(-1, 1)),marker=marker, label=name)
axs[1].plot(xfa, res.diffusion(xfa.reshape(-1, 1)),marker=marker, label=name)

axs[0].legend()
axs[1].legend()

for i in range(len(res_vec)):
print(names[i], res_vec[i].coefficients)
checkpoint3 = time.time()

print("Training time =", checkpoint3 - checkpoint2, "seconds")
Expand Down
Loading

0 comments on commit 15f62c3

Please sign in to comment.