This file contains 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 testsleep() | |
sleeptimes = logspace(-3,1,50) | |
actual_sleeptimes = map(sleeptimes) do st | |
@elapsed sleep(st) | |
end | |
sleeptimes, actual_sleeptimes | |
end | |
sleeptimes, actual_sleeptimes = testsleep() | |
diff = actual_sleeptimes-sleeptimes | |
plot(sleeptimes, [diff diff./sleeptimes], xlabel="Sleeptimes", ylabel=["Absolute difference" "Relative difference"], |
This file contains 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
using ControlSystems | |
G = tf(1,[1,1]) | |
bodeplot(G) | |
nyquistplot(G) | |
nicholsplot(G, linewidth=5) | |
lsimplot(G, 5+0.1randn(100), 0:0.1:9.9) | |
pzmap(G) | |
gangoffourplot(G,G) | |
G = tf(1,[1,1]) |
This file contains 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
using Flux | |
using Flux: back!, truncate!, treelike, train!, mse | |
N = 200 | |
n = 2 | |
function generate_data() | |
A = randn(n,n) | |
A = expm(A - A') | |
A = 0.999A | |
A = [0.999 1; 0 0.8] |
This file contains 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
@sync begin # Enusres that both operations below are finished before leaving this scope | |
@async begin # Enusres that the last running job does not stop the next parallel operation from starting | |
info("Launching forward only") | |
result1 = pmap(35:-2:5) do it # Start heaviest job (35) first | |
do_something(it) # Execution time proportional to it | |
end | |
end | |
@async begin | |
info("Launching forward inverse") |
This file contains 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
#I would like to use Cassette.jl to implement a compiler pass. The task is to (conditioned on types) translate code that contains a branch into a map over a function that contains the branch. An example of the transformation I would like to do is from | |
code = Meta.@lower if x > 0 | |
return x^2 | |
else | |
return -x^2 | |
end | |
#to | |
code2 = Meta.@lower map(x.particles) do x | |
if x > 0 | |
return x^2 |
This file contains 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
using StatsBase, Distributions | |
Base.@kwdef struct AlphaStable{T} <: Distributions.ContinuousUnivariateDistribution | |
α::T = 1.5 | |
β::T = 0.0 | |
scale::T = 1.0 | |
location::T = 0.0 | |
end | |
This file contains 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
""" | |
γ, u, v = sinkhorn(C, a, b; β=1e-1, iters=1000) | |
The Sinkhorn algorithm. `C` is the cost matrix and `a,b` are vectors that sum to one. Returns the optimal plan and the dual potentials. See also [`IPOT`](@ref). | |
""" | |
function sinkhorn(C, a, b; β=1e-1, iters=1000) | |
K = exp.(.-C ./ β) | |
v = one.(b) | |
u = a ./ (K * v) | |
v = b ./ (K' * u) |
This file contains 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
cd(@__DIR__) | |
using Pkg | |
pkg"activate ." | |
# pkg"add Turing, NamedTupleTools, MonteCarloMeasurements, StatsPlots" | |
# pkg"dev Turing2MonteCarloMeasurements" | |
using Turing, Turing2MonteCarloMeasurements, NamedTupleTools, MonteCarloMeasurements | |
## Some helper functions stolen from Soss ====================================== |
This file contains 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
using Soss | |
struct MarkovChain{P,D} | |
pars :: P | |
dist :: D | |
end | |
function Distributions.logpdf(chain::MarkovChain, x::AbstractVector{X}) where {X} | |
@inbounds x1 = (pars=chain.pars,state=x[1]) | |
length(x) == 1 && return logpdf(chain.dist, x1.state) |
This file contains 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
using Printf, Base.Iterators | |
root = "/home/$(ENV["USER"])/.julia/dev/" | |
# root = "/home/$(ENV["USER"])/.julia/packages/" | |
const regs = [ | |
r"(\w+)\s?->\w+\(\1\)[,\b]", # Finds x->f(x) | |
r"\w+\s?==\s?(true|false)", # Finds x == true | |
] | |
function findem(root, regs; extension=".jl", pad=80) |
OlderNewer