Anaconda vs Julia Autocorrelation


Ross Mariano:

I am trying to use Julia to do autocorrelation and compare results in Python. Why do they give different results?

Julia code

using StatsBase

t = range(0, stop=10, length=10)
test_data = sin.(exp.(t.^2))

acf = StatsBase.autocor(test_data)

Give

10-element Array{Float64,1}:
  1.0                   
  0.13254954979179642   
 -0.2030283419321465    
  0.00029587850872956104
 -0.06629381497277881   
  0.031309038331589614  
 -0.16633393452504994   
 -0.08482388975165675   
  0.0006905628640697538 
 -0.1443650483145533

Python code

from statsmodels.tsa.stattools import acf
import numpy as np

t = np.linspace(0,10,10)
test_data = np.sin(np.exp(t**2))

acf_result = acf(test_data)

Give

array([ 1.        ,  0.14589844, -0.10412699,  0.07817509, -0.12916543,
       -0.03469143, -0.129255  , -0.15982435, -0.02067688, -0.14633346])
Jacob Neeson:

This is because you test_dataare different:

python:

array([ 0.84147098, -0.29102733,  0.96323736,  0.75441021, -0.37291918,
        0.85600145,  0.89676529, -0.34006519, -0.75811102, -0.99910501])

Julia:

[0.8414709848078965, -0.2910273263243299, 0.963237364649543, 0.7544102058854344,
 -0.3729191776326039, 0.8560014512776061, 0.9841238290665676, 0.1665709194875013,
 -0.7581110212957692, -0.9991050130774393]

sinThis is because of the huge numbers you are taking . For example, with the number t10 in the past, it exp(10^2)is ~2.7 x 10^43. At this scale, floating point inaccuracy is about 3*10^9. So if even the least significant bit is different for Python and Julia, the sinvalue will be the way to go.

In fact, we can examine the underlying binary value of the initial array t. For example, they differ in the third-to-last value:

Julia:

julia> reinterpret(Int, range(0, stop=10, length=10)[end-2])
4620443017702830535

python:

>>> import struct
>>> s = struct.pack('>d', np.linspace(0,10,10)[-3])
>>> struct.unpack('>q', s)[0]
4620443017702830536

Indeed, we can see that they disagree with exactly one machine precision. If we use Julia to take sinthe value obtained by Python:

julia> sin(exp(reinterpret(Float64, 4620443017702830536)^2))
-0.3400651855865199

We get the same value Python does.

Related


Anaconda vs Julia Autocorrelation

Ross Mariano: I am trying to use Julia to do autocorrelation and compare results in Python. Why do they give different results? Julia code using StatsBase t = range(0, stop=10, length=10) test_data = sin.(exp.(t.^2)) acf = StatsBase.autocor(test_data) Give

Anaconda vs Julia Autocorrelation

Ross Mariano: I am trying to use Julia to do autocorrelation and compare results in Python. Why do they give different results? Julia code using StatsBase t = range(0, stop=10, length=10) test_data = sin.(exp.(t.^2)) acf = StatsBase.autocor(test_data) give

Anaconda vs Julia Autocorrelation

Ross Mariano: I am trying to use Julia to do autocorrelation and compare results in Python. Why do they give different results? Julia code using StatsBase t = range(0, stop=10, length=10) test_data = sin.(exp.(t.^2)) acf = StatsBase.autocor(test_data) give

Anaconda vs Julia Autocorrelation

Ross Mariano: I am trying to use Julia to do autocorrelation and compare results in Python. Why do they give different results? Julia code using StatsBase t = range(0, stop=10, length=10) test_data = sin.(exp.(t.^2)) acf = StatsBase.autocor(test_data) give

Anaconda vs Julia Autocorrelation

Ross Mariano: I am trying to use Julia to do autocorrelation and compare results in Python. Why do they give different results? Julia code using StatsBase t = range(0, stop=10, length=10) test_data = sin.(exp.(t.^2)) acf = StatsBase.autocor(test_data) give

How to install Julia in Anaconda environment?

Robert Smith One of the main features of Anaconda is that it is language agnostic as stated in their blog : You can create environments with any binary dependency tree (different versions of Python, R, Julia, etc.). Recently, I switched from using virtualenv t

How to install Julia in Anaconda environment?

Robert Smith One of the main features of Anaconda is that it is language agnostic as stated in their blog : You can create environments with any binary dependency tree (different versions of Python, R, Julia, etc.). Recently, I switched from using virtualenv t

How to install Julia in Anaconda environment?

Robert Smith One of the main features of Anaconda is that it is language agnostic as stated in their blog : You can create environments with any binary dependency tree (different versions of Python, R, Julia, etc.). Recently, I switched from using virtualenv t

How to install Julia in Anaconda environment?

Robert Smith One of the main features of Anaconda is that it is language agnostic as stated in their blog : You can create environments with any binary dependency tree (different versions of Python, R, Julia, etc.). Recently, I switched from using virtualenv t

Anaconda environment on VS Code

username I'm new to python in general, so please keep it simple. I've started coding with Spyder because of the easy installation of libraries using Anaconda. Now we're going to switch to VS Code for version control. I've switched the interpreter and python pa

Activate Anaconda on VS Code

Hello After installing Anaconda and running my code VS Code I got the following in the terminal. But why does my terminal execute the code first without activating the virtual environment? This is a bug, how can I fix it? C:\Users\test>python -u "c:\Users\test

Anaconda environment on VS Code

username I'm new to python in general, so please keep it simple. I've started coding with Spyder because of the easy installation of libraries using Anaconda. Now we're going to switch to VS Code for version control. I've switched the interpreter and python pa

Anaconda not working in VS Code

Jithakrishna Prakash I installed Anaconda 3 in "C:\Anaconda3" and manually added the paths "C:\Anaconda3\Scripts", "C:\Anaconda3" in the PATH variable. I installed VS Code through the Anaconda navigator which also installed the Anaconda extension package for V

Activate Anaconda on VS Code

Hello After installing Anaconda and running my code VS Code I got the following in the terminal. But why does my terminal execute the code first without activating the virtual environment? This is a bug, how can I fix it? C:\Users\test>python -u "c:\Users\test

Anaconda environment on VS Code

username I'm new to python in general, so please keep it simple. I've started coding with Spyder because of the easy installation of libraries using Anaconda. Now we're going to switch to VS Code for version control. I've switched the interpreter and python pa

Activate Anaconda on VS Code

Hello After installing Anaconda and running my code VS Code I got the following in the terminal. But why does my terminal execute the code first without activating the virtual environment? This is a bug, how can I fix it? C:\Users\test>python -u "c:\Users\test

Anaconda environment on VS Code

username I'm new to python in general, so please keep it simple. I've started coding with Spyder because of the easy installation of libraries using Anaconda. Now we're going to switch to VS Code for version control. I've switched the interpreter and python pa

Anaconda environment on VS Code

username I'm new to python in general, so please keep it simple. I've started coding with Spyder because of the easy installation of libraries using Anaconda. Now we're going to switch to VS Code for version control. I've switched the interpreter and python pa

Activate Anaconda on VS Code

Hello After installing Anaconda and running my code VS Code I got the following in the terminal. But why does my terminal execute the code first without activating the virtual environment? This is a bug, how can I fix it? C:\Users\test>python -u "c:\Users\test

Anaconda environment on VS Code

username I'm new to python in general, so please keep it simple. I've started coding with Spyder because of the easy installation of libraries using Anaconda. Now we're going to switch to VS Code for version control. I've switched the interpreter and python pa

Activate Anaconda on VS Code

Hello After installing Anaconda and running my code VS Code I got the following in the terminal. But why does my terminal execute the code first without activating the virtual environment? This is a bug, how can I fix it? C:\Users\test>python -u "c:\Users\test

Activate Anaconda on VS Code

Hello After installing Anaconda and running my code VS Code I got the following in the terminal. But why does my terminal execute the code first without activating the virtual environment? This is a bug, how can I fix it? C:\Users\test>python -u "c:\Users\test

Anaconda not working in VS Code

Jithakrishna Prakash I installed Anaconda 3 in "C:\Anaconda3" and manually added the paths "C:\Anaconda3\Scripts", "C:\Anaconda3" in the PATH variable. I installed VS Code through the Anaconda navigator which also installed the Anaconda extension package for V

Download Julia from Anaconda or julialang.org

David I want to download Julia from Anaconda (latest version is 1.0). However, you can download it from https://julialang.org/ . My question is: what is the difference between the two ways of installing Julia? For example, if I choose Anaconda , can I install