import utils
import box_count
import numpy as np
samples=50
t, x_t = utils.solve_lorenz(N=samples, t_max=1000)
fd = []
for i in range(1, samples+1):
d = box_count.dimension(np.concatenate(x_t[:i,:,:], axis=0))
fd.append(d)
print(fd)
# plt.style.use('bmh')
# fig, ax = plt.subplots(figsize=(12, 6))
# ax.set_xlabel("Samples")
# ax.set_ylabel("Dimension")
# ax.scatter(range(1, samples+1), fd, c="red")
[1.8635608934203145, 1.909981795491712, 1.9240813111083666, 1.915462633736645, 1.9199653098025773, 1.9243238325235146, 1.9317248185659917, 1.9370702419007708, 1.9412620485232914, 1.942884008212188, 1.9452061095452091, 1.946612320752239, 1.9507488671352418, 1.9524750661495784, 1.9548112682070908, 1.9553309695750827, 1.9569142463243825, 1.9556927841407072, 1.9545802794952774, 1.9560342227385972, 1.9572719055615382, 1.9610193229466226, 1.9609629662226753, 1.9635126798988216, 1.9628429272198156, 1.9641744669430896, 1.9649548162683659, 1.9669347850313825, 1.970052131357251, 1.9715477887340467, 1.972467820527119, 1.971680501469601, 1.9720052763952425, 1.9726633766005748, 1.972677165226421, 1.972919085021015, 1.9734376559545617, 1.9739105767216112, 1.9732404804968822, 1.9730009515586548, 1.9723358178315433, 1.9721838062552708, 1.972083039381057, 1.973244981566599, 1.9727081695802744, 1.9731336594854825, 1.9764305798103343, 1.9772778115883793, 1.9770188819938774, 1.9771218852383943]
import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
def fit_function(xd, a, b, n):
return a * xd ** n / (xd ** n + b)
x = np.arange(1., samples + 1.)
popt, pcov = curve_fit(fit_function, x, fd)
plt.style.use('bmh')
fig, ax = plt.subplots(figsize=(12, 6))
plt.scatter(x, fd)
plt.plot(x, fit_function(x, *popt), 'r-')
plt.show()
# Standard deviation errors on the parameters
sd = np.sqrt(np.diag(pcov))
# Optimal values
print(f"Fitted parameters: a = {popt[0]:.3f} ± {sd[0]:.2f}, b = {popt[1]:.3f}, n = {popt[2]:.3f}")
print(f" {sd}")
Fitted parameters: a = 2.056 ± 0.02, b = 0.098, n = 0.231 [0.02106361 0.01009685 0.04051956]