Skip to content

Instantly share code, notes, and snippets.

using Optim, Calculus
# Let's try with a polynomial. It has very simple Hessian, as there are no cross
# products, only quadratic terms. Hence the Hessian is a diagonal matrix where
# diag(H) = [2, 2, ..., 2]. Let's try to see if that's what we get!
function large_polynomial(x::Vector)
res = zero(x[1])
for i in 1:250
res += (i - x[i])^2
end
return res
This file has been truncated, but you can view the full file.
intersect at /home/pkm/julia/julia/src/subtype.c:1628
intersect_ufirst at /home/pkm/julia/julia/src/subtype.c:1032 [inlined]
intersect_var at /home/pkm/julia/julia/src/subtype.c:1100
intersect at /home/pkm/julia/julia/src/subtype.c:1628
intersect_ufirst at /home/pkm/julia/julia/src/subtype.c:1032 [inlined]
intersect_var at /home/pkm/julia/julia/src/subtype.c:1100
intersect at /home/pkm/julia/julia/src/subtype.c:1628
intersect_ufirst at /home/pkm/julia/julia/src/subtype.c:1032 [inlined]
intersect_var at /home/pkm/julia/julia/src/subtype.c:1100
intersect at /home/pkm/julia/julia/src/subtype.c:1628
julia> Profile.print()
11 ./event.jl:68; (::Base.REPL.##3#4{Base.REPL.REPLBackend})()
11 ./REPL.jl:95; macro expansion
11 ./REPL.jl:64; eval_user_input(::Any, ::Base.REPL.REPLBackend)
11 ./boot.jl:234; eval(::Module, ::Any)
11 ./<missing>:?; anonymous
11 ./profile.jl:16; macro expansion;
11 /home/pkm/.julia/v0.5/MDPTools/src/solution/solve.jl:39; solve!;
11 /home/pkm/.julia/v0.5/MDPTools/src/solution/solve.jl:40; #solve!#58;
11 ./<missing>:0; (::MDPTools.#kw##solve!)(::Array{Any,1}, ::MDPTools.#solve!, ::MDPTools.LinearUtility{Float64}, ::MDP...
pkm@pkm:~/.julia/v0.6/RemPiO2$ julia6 -O3 test/runtests.jl
Testing speed and accuracy of rempio2 in [-pi*9/4, pi*9/4]
----------------------------------------------------------
Numbers below are elapsed time returned from @belapsed
Every number is checked between the two implementations
using a @test such that any difference results in termi-
nation of the program.
Pkg.add("BenchmarkTools")
using BenchmarkTools
function inplace_sq_mat(m::Array{Float64, 2}, n::Array{Float64, 2})
s = size(m, 1)
t = s+1
v = zeros(t)
@inbounds for i=1:s
for j=1:s
v[j] = m[j, i]
@pkofod
pkofod / tauchen.jl
Created September 15, 2017 13:47
tauchen
function tauchen(ρ, σₛ, m, N)
const Φ = normcdf # CDF of standard normal
s̃₁, s̃ₙ = -m*σₛ, m*σₛ # end points
s̃ = linspace(s̃₁, s̃ₙ, N) # grid
w = (s̃[2]-s̃[1])/2 # half distance between grid points
F = zeros(N, N) # empty transition matrix
F[:, 1] = Φ.((s̃[1]-ρ.*s̃+w)/sqrt(σₛ))
F[:, N] = 1-Φ.((s̃[end]-ρ.*s̃-w)/sqrt(σₛ))
for j = 2:N-1
for i = 1:N
@pkofod
pkofod / working.jl
Created September 20, 2017 12:24
working.jl
pkm@pkm:~/.julia$ mkdir fakepkg
pkm@pkm:~/.julia$ julia
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: https://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.6.0 (2017-06-19 13:05 UTC)
_/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-pc-linux-gnu
# Adapted from https://tpapp.github.io/post/log1p/
# consistent random numbers
T = Float32
srand(UInt32[0xfd909253, 0x7859c364, 0x7cd42419, 0x4c06a3b6])
"""
err(x, [prec])
Return two values, which are the log2 relative errors for calculating
`log(x)`, using `Base.log` and `Base.Math.JuliaLibm.log`.
Benchmarking 0.0
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 3.992 ns (0.00% GC)
median time: 4.586 ns (0.00% GC)
mean time: 4.647 ns (0.00% GC)
maximum time: 18.766 ns (0.00% GC)
--------------