This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code is a Julia translation of the C code from Openlibm (http://www.openlibm.org/) | |
# with the following license: | |
# Copyright (c) 2011 David Schultz <[email protected]> | |
# All rights reserved. | |
# | |
# Redistribution and use in source and binary forms, with or without | |
# modification, are permitted provided that the following conditions | |
# are met: | |
# 1. Redistributions of source code must retain the above copyright |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
julia> @profile res = optimize(fung, x0, LBFGS(), Optim.Options(show_trace=false,iterations=100_000,g_tol=1e-6,f_tol=1e-20)) | |
Profile.print()Results of Optimization Algorithm | |
* Algorithm: L-BFGS | |
* Starting Point: [0.5611813319535237,0.3528280830687891, ...] | |
* Minimizer: [0.063775434544103,0.49327292600719447, ...] | |
* Minimum: 3.682547e+03 | |
* Iterations: 11 | |
* Convergence: true | |
* |x - x'| ≤ 0.0e+00: false | |
|x - x'| = 1.18e-09 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
β = 0.9995 | |
Wₕ = 100 | |
W̄ₕ = Wₕ/(1-β) | |
Wₗ = 50 | |
W̄ₗ = Wₗ/(1-β) | |
pₕ = 0.35 | |
pₗ = 0.65 | |
Bₖ = 0.6*Wₗ | |
U(x) = sqrt(x) | |
Uₕ = U(Bₖ-1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
frexp_exp(x) | |
Compute ``exp(x)``, scaled to avoid spurious overflow. An exponent is | |
returned separately in ``expt``. | |
# Examples | |
```jldoctest | |
julia> frexp_exp(1354.9) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- Benchmarking 0.0 | |
BenchmarkTools.Trial: | |
memory estimate: 0 bytes | |
allocs estimate: 0 | |
-------------- | |
minimum time: 3.977 ns (0.00% GC) | |
median time: 4.582 ns (0.00% GC) | |
mean time: 4.687 ns (0.00% GC) | |
maximum time: 19.703 ns (0.00% GC) | |
-------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
-------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |