In [20]:
using Distributions
using PyPlot
In [1]:
import Base: +
+(x::Integer, y::ASCIIString) = x + parse(Int, y)
Out[1]:
In [13]:
super(Array)
super(DenseArray{Int, 3})
super(AbstractArray{Int, 3})
super(AbstractVector{Int64})
Out[13]:
In [14]:
function sum_array(x)
sum = 0.0
for i in 1:length(x)
sum += x[i]
end
return sum
end
Out[14]:
In [17]:
x = linspace(0, 1, 1e6)
y = Any[i/1e6 for i in 0:1e6]
@time sum_array(x)
@time sum_array(y)
Out[17]:
In [30]:
type AR1
a::Real
b::Real
sigma::Real
phi::Distribution
end
function simulate(m::AR1, initial::Real=0.0, repeat::Int=100)
x_list = Array{Float64}(repeat)
eps_list = rand(m.phi, repeat)
x = initial
for i in 1:repeat
x_list[i] = m.a * x + m.b + m.sigma * eps_list[i]
x = x_list[i]
end
return x_list
end
Out[30]:
In [31]:
srand(620)
m = AR1(0.8, 0, 1, Normal(0, 1))
xs = simulate(m, 0, 500)
for x in xs[1:20]
println(x)
end
In [32]:
plot(xs)
Out[32]: