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

Wrong summation in code for Figure 2.6 #13

Open
martinandrovich opened this issue Jun 15, 2022 · 2 comments
Open

Wrong summation in code for Figure 2.6 #13

martinandrovich opened this issue Jun 15, 2022 · 2 comments

Comments

@martinandrovich
Copy link

martinandrovich commented Jun 15, 2022

For Figure 2.6, is the summation not wrong here? In the book, equation (2.36) states that:

image

where in the code (both Python and MATLAB), the value of s is computed as

s = 0;
for i in range(0,len(X)-1):
s = np.power(X[i+1]-X[i]-mu*dt,2)
sigma = np.sqrt(s/(m*dt))
print('Estimated parameters are: mu = {0} and sigma = {1}'.format(mu,sigma))

but shouldn't it instead be:

s = 0
for i in range(0, len(X) - 1):
	s = s + np.power(X[i+1] - X[i] - mu * dt, 2)

In our implementation, we get

$$\hat{\mu} = 0.0014 \quad , \quad \hat{\sigma} = 0.0318$$

using

mu = 1/(m * dt) * (X[-1] - X[0])
s = 1/(m * dt) * np.sum([(X[i + 1] - X[i] - mu * dt) ** 2 for i in range(len(X) - 1)])
sigma = sqrt(s)
@martinandrovich
Copy link
Author

Resulting plot:

image

@LechGrzelak
Copy link
Owner

LechGrzelak commented Jun 23, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants