text:
module IniFile
using Compat
using Base

import Base.get,
       Base.haskey,
       Base.read,
       Base.write,
       Base.show

export Inifile,
       defaults,
       get,
       set,
       get_bool,
       get_int,
       get_float,
       has_section,
       read,
       write,
       section,
       sections,
       show

@compat typealias INIVAL Union{AbstractString,Number,Bool,Void}
typealias HTSS Dict{AbstractString,INIVAL}

type Inifile
    sections::Dict{AbstractString,HTSS}
    defaults::HTSS
end

Inifile() = Inifile(Dict{AbstractString,HTSS}(), HTSS())

defaults(inifile::Inifile) = inifile.defaults

sections(inifile::Inifile) = inifile.sections

function read(inifile::Inifile, stream::IO)
    current_section = inifile.defaults
    for line in EachLine(stream)
        s = strip(line)
        # comments start with # or ;
        if length(s) < 3 || s[1] == '#' || s[1] == ';'
            continue
        elseif s[1] == '[' && s[end] == ']'
            section = s[2:end-1]
            if !haskey(inifile.sections, section)
                inifile.sections[section] = HTSS()
            end
            current_section = inifile.sections[section]
        else
            i = search(s, '=')
            j = search(s, ':')
            if i == 0 && j == 0
                # TODO: allow multiline values
                println("skipping malformed line: $s")
            else
                idx = min(i, j)
                if idx == 0
                    idx = max(i, j)
                end
                key = rstrip(s[1:idx-1])
                val = lstrip(s[idx+1:end])
                current_section[key] = val
            end
        end
    end
    inifile
end

function read(inifile::Inifile, filename::AbstractString)
    open(filename) do f
        read(inifile, f)
    end
    inifile
end

show(io::IO, inifile::Inifile) = write(io, inifile)
function write(io::IO, inifile::Inifile)
    for (key, value) in defaults(inifile)
        println(io, "$key=$value")
    end
    for (name, htss) in sections(inifile)
        println(io, "[$name]")
        for (key, value) in htss
            println(io, "$key=$value")
        end
    end
end

get(inifile::Inifile, section::AbstractString, key::AbstractString) = get(inifile, section, key, :notfound)

function get(inifile::Inifile, section::AbstractString, key::AbstractString, notfound)
    if haskey(inifile.sections, section) && haskey(inifile.sections[section], key)
        return inifile.sections[section][key]
    elseif haskey(inifile.defaults, key)
        return inifile.defaults[key]
    end
    notfound
end

# This get function uses the defaults section
get(inifile::Inifile, key::AbstractString) = get(inifile, key, :notfound)

function get(inifile::Inifile,  key::AbstractString, notfound)
    if haskey(inifile.defaults, key)
        return inifile.defaults[key]
    end
    notfound
end

function set(inifile::Inifile, section::AbstractString, key::AbstractString, val::INIVAL)
    if !haskey(inifile.sections, section)
        (val == nothing) && return val
        inifile.sections[section] = HTSS()
    end

    sec = inifile.sections[section]
    if val == nothing
        if haskey(sec, key)
            delete!(sec, key)
        end
        return val
    end
    sec[key] = val
    val
end

# This set function uses the defaults section
function set(inifile::Inifile, key::AbstractString, val::INIVAL)
    sec = inifile.defaults
    if val == nothing
        if haskey(sec, key)
            delete!(sec, key)
        end
        return val
    end
    sec[key] = val
    val
end

get_bool(inifile::Inifile, section::AbstractString, key::AbstractString) =
    lowercase(get(inifile, section, key)) == "true"

get_int(inifile::Inifile, section::AbstractString, key::AbstractString) =
    parse(Int, get(inifile, section, key))

get_float(inifile::Inifile, section::AbstractString, key::AbstractString) =
    parse(Float64, get(inifile, section, key))

haskey(inifile::Inifile, section::AbstractString, key::AbstractString) =
    haskey(inifile.sections, section) && haskey(inifile.sections[section], key)

has_section(inifile::Inifile, section::AbstractString) = haskey(inifile.sections, section)

section(inifile::Inifile, section::AbstractString) = inifile.sections[section]

end # module


text:
include("required.jl")

## Conditional argument
# save_additional_data = false
# save_additional_data = true

## Run analysis on raw data
outcome = "raw"
include("04_full-extent.jl")

# Assemble results
raw = (
    Y=Y,
    richness=richness_full,
    richness_plot=richness_plot,
    lcbd=lcbd_full,
    beta_total=beta_full,
    lcbd_plot=lcbd_plot,
    rel_plot=rel2d_plot,
)

## Run analysis on sdm data
outcome = "bart"
include("04_full-extent.jl")

# Assemble results
sdm = (
    Y=Y,
    richness=richness_full,
    richness_plot=richness_plot,
    lcbd=lcbd_full,
    beta_total=beta_full,
    lcbd_plot=lcbd_plot,
    rel_plot=rel2d_plot,
)

## Recalculate LCBD values on same sites

# Get indices in common (with values for both raw & sdm)
inds_common = intersect(_indsobs(raw.Y), _indsobs(sdm.Y))

# Recalculate LCBD values on same sites
function common_lcbd(Y, layer, inds_common)
    Ycommon = copy(Y)
    Ycommon[Not(inds_common), :] .= nothing
    lcbd_common = lcbd(Ycommon, layer; relative=false)
    return lcbd_common
end
lcbdcom_raw = common_lcbd(raw.Y, raw.lcbd, inds_common)
lcbdcom_sdm = common_lcbd(sdm.Y, sdm.lcbd, inds_common)

# Add to NamedTuples
raw = (raw..., lcbdcom=lcbdcom_raw)
sdm = (sdm..., lcbdcom=lcbdcom_sdm)

# Export to JLD2
if (@isdefined save_additional_data) && save_additional_data == true
    # Export to JLD2
    jld_path = joinpath("data", "jld2", "comparison-results.jld2")
    @save jld_path raw sdm
    # Update placeholder file (as file is too big for version control)
    placeholder_path = joinpath("data", "jld2", "comparison-results_placeholder.jld2")
    open(placeholder_path, "w") do io
        write(io, string(Dates.now()))
    end
end

## Prepare data for GLMs

# Assemble in DataFrame
results = DataFrame([raw.richness, raw.lcbdcom, sdm.richness, sdm.lcbdcom])
rename!(
    results, :x1 => :richness_raw, :x2 => :lcbd_raw, :x3 => :richness_sdm, :x4 => :lcbd_sdm,
)

# Remove lines with missing values
dropmissing!(results)

# Convert to Float64 (cannot write to CSV otherwise)
results = convert.(Float64, results)

# Export to CSV
if (@isdefined save_additional_data) && save_additional_data == true
    CSV.write(joinpath("data", "proc", "comparison-results.csv"), results; delim="\t")
end

ext: jl

max_stars_repo_name: gabrieldansereau/betadiversity-hotspots

max_issues_repo_name: gabrieldansereau/betadiversity-hotspots

max_forks_repo_name: gabrieldansereau/betadiversity-hotspots


text:
using Test, ModelConstructors, UnPack

m = GenericModel()
m <= parameter(:a, 1., (0., 1.), (0., 1.), Untransformed(), fixed = false)
m <= parameter(:b, 1., (0., 1.), (0., 1.), Untransformed(), fixed = false, scaling = x -> x / 100.)

@testset "UnPack works with AbstractModel" begin
    @unpack a, b = m
    @test a == 1.
    @test b == 1e-2
    @unpack a = m
    @unpack b = m
    @test a == 1.
    @test b == 1e-2
end

max_stars_repo_name: FRBNY-DSGE/ModelConstructors

max_issues_repo_name: FRBNY-DSGE/ModelConstructors

max_forks_repo_name: FRBNY-DSGE/ModelConstructors


text:
# ---
# title: 1370. Increasing Decreasing String
# id: problem1370
# author: Tian Jun
# date: 2020-10-31
# difficulty: Easy
# categories: String, Sort
# link: <https://leetcode.com/problems/increasing-decreasing-string/description/>
# hidden: true
# ---
#
# Given a string `s`. You should re-order the string using the following
# algorithm:
#
#   1. Pick the **smallest** character from `s` and **append** it to the result.
#   2. Pick the **smallest** character from `s` which is greater than the last appended character to the result and **append** it.
#   3. Repeat step 2 until you cannot pick more characters.
#   4. Pick the **largest**  character from `s` and **append** it to the result.
#   5. Pick the **largest**  character from `s` which is smaller than the last appended character to the result and **append** it.
#   6. Repeat step 5 until you cannot pick more characters.
#   7. Repeat the steps from 1 to 6 until you pick all characters from `s`.
#
# In each step, If the smallest or the largest character appears more than once
# you can choose any occurrence and append it to the result.
#
# Return _the result string_ after sorting `s` with this algorithm.
#
#
#
# **Example 1:**
#
#
#
#     Input: s = "aaaabbbbcccc"
#     Output: "abccbaabccba"
#     Explanation: After steps 1, 2 and 3 of the first iteration, result = "abc"
#     After steps 4, 5 and 6 of the first iteration, result = "abccba"
#     First iteration is done. Now s = "aabbcc" and we go back to step 1
#     After steps 1, 2 and 3 of the second iteration, result = "abccbaabc"
#     After steps 4, 5 and 6 of the second iteration, result = "abccbaabccba"
#
#
# **Example 2:**
#
#
#
#     Input: s = "rat"
#     Output: "art"
#     Explanation: The word "rat" becomes "art" after re-ordering it with the mentioned algorithm.
#
#
# **Example 3:**
#
#
#
#     Input: s = "leetcode"
#     Output: "cdelotee"
#
#
# **Example 4:**
#
#
#
#     Input: s = "ggggggg"
#     Output: "ggggggg"
#
#
# **Example 5:**
#
#
#
#     Input: s = "spo"
#     Output: "ops"
#
#
#
#
# **Constraints:**
#
#   * `1 <= s.length <= 500`
#   * `s` contains only lower-case English letters.
#
#
## @lc code=start
using LeetCode

## add your code here:
## @lc code=end


text:
function linsolve_pcg( Lmat::SparseMatrixCSC{Float64,Int64},
                       prec::SparseMatrixCSC{Float64,Int64},
                       b::Array{Float64,1};
                       x0 = nothing,
                       NiterMax = 1000, TOL=5.e-10,
                       convmsg=false, showprogress=false )
    #
    Npoints = size(b)[1]
    if x0 == nothing
        x = zeros( Float64, Npoints )
    else
        x = copy(x0)
    end
    #
    r = zeros( Float64, Npoints )
    p = zeros( Float64, Npoints )
    z = zeros( Float64, Npoints )
    #
    nabla2_x = Lmat*x
    r = b - nabla2_x
    z = apply_prec_ilu0( prec, r)
    p = copy(z)

    rsold = dot( r, z )

    for iter = 1 : NiterMax
        #
        nabla2_x = Lmat*p
        #
        alpha = rsold/dot( p, nabla2_x )
        #
        x = x + alpha * p
        r = r - alpha * nabla2_x
        z = apply_prec_ilu0( prec, r)
        #
        rsnew = dot( z, r )
        # deltars = rsold - rsnew
        if showprogress
            @printf("%8d %18.10e\n", iter, sqrt(abs(rsnew)))
        end
        #
        if sqrt(abs(rsnew)) < TOL
            if convmsg
                @printf("#Convergence achieved in linsolve_pcg: %8d iterations.\n", iter)
            end
            break
        end
        #
        p = z + (rsnew/rsold) * p
        #
        rsold = rsnew
    end
    #
    return x
    #
end # of function


text:
struct StaticState{T} <: LinesearchState
    alpha::T
    StaticState(alpha::T = 1.0) where {T} = new{T}(alpha)
end

StaticState(args...; alpha = 1.0, kwargs...) = StaticState(alpha)
StaticState(::AbstractObjective; alpha = 1.0, kwargs...) = StaticState(alpha)

LinesearchState(algorithm::Static, objective::AbstractObjective; kwargs...) = StaticState(algorithm.alpha)

Base.show(io::IO, ls::StaticState) = print(io, "Static")

(ls::StaticState)() = ls.alpha

(ls::StaticState)(x::AbstractVector, δx::AbstractVector) = x .+= ls.alpha .* δx


text:
using Behavior
using Behavior.Gherkin
using Niancat.Languages

column(t::Gherkin.DataTable) = [row[1] for row in t]

@when("finding anagrams for {String}") do context, word
    dictionary = context[:dictionary]
    anagrams = findanagrams(dictionary, word)
    context[:anagrams] = anagrams
end

@when("seeing if {String} is in the dictionary") do context, word
    dictionary = context[:dictionary]
    context[:isindictionary] = word in dictionary
end

@then("these words are found") do context
    words = [lowercase(w) for w in column(context.datatable)]
    @expect sort(words) == sort(context[:anagrams])
end

@then("no words are found") do context
    @expect context[:anagrams] == []
end

@then("the answer is yes") do context
    @expect context[:isindictionary] == true
end

@then("the answer is no") do context
    @expect context[:isindictionary] == false
end


text:
## wrapper and line command script to get GAIA votable in a conesearch
using Printf, ArgParse
using PyCall

gaia= pyimport("astroquery.gaia")
u= pyimport("astropy.units")
coord= pyimport("astropy.coordinates")

##
## parse getgaia options/flags
##
function parse_commandline()
    s = ArgParseSettings()

    @add_arg_table s begin
        "-f"
            help = "Field name"
            arg_type = String
            default= "gaia"
        "--resolv", "-r"
            help = "To resolv the field name on the sky"
            action = :store_true
        "--rad"
            help = "Radius on sky in degrees."
            arg_type = Float64
            default= 2.0
        "--tol"
            help = "Tolerance on Gaia data."
            arg_type = Float64
            default= 0.2
        "-l"
            help = "Galactic longitud"
            arg_type = Float64
        "-b"
            help = "Galactic latitude"
            arg_type = Float64
        "--ra"
            help = "Right Ascension in degrees"
            arg_type = Float64
        "--dec"
            help = "Declination in degrees"
            arg_type = Float64

    end

    return parse_args(s)
end
## query the gaia data and save then
function get_gaia_data(radius, tol, ra, dec, name, table= "gaiaedr3.gaia_source")

    adql= @sprintf("SELECT * FROM %s WHERE CONTAINS(POINT('ICRS',%s.ra, %s.dec),
    CIRCLE('ICRS',%f, %f, %f)) = 1  AND abs(pmra_error/pmra)<  %3.3f AND abs(pmdec_error/pmdec)< %3.3f
    AND abs(parallax_error/parallax)< %3.3f;", table, table, table, ra, dec, radius, tol, tol, tol )

    println("## Downloading data...")
    println(adql)
    job= gaia.Gaia.launch_job_async(adql, dump_to_file=true)
    outfile= job.outputFile
    filedst= @sprintf("%s-%2.1fdeg.vot",name, radius)
    mv(outfile, filedst , force=true)
    println("## Votable saved in: $filedst")

end
function coord_galactic(longi, lati)
    c = coord.SkyCoord(l=longi*u.degree, b=lati*u.degree,frame="galactic")
    ct= c.transform_to("fk5")
    return(ct.ra[1], ct.dec[1])
end
#################################### MAIN###############################
let
    args = parse_commandline()

    fname= args["f"]
    l= args["l"]
    b= args["b"]
    ra= args["ra"]
    dec= args["dec"]
    rad= args["rad"]
    tol= args[ "tol"]
    resolv= args[ "resolv"]

    iscoord= false
    if l != nothing && b != nothing
        longi, lati= coord_galactic(l, b)
        iscoord= true
    elseif ra != nothing && dec != nothing
        longi= ra ; lati= dec
        iscoord= true
    elseif resolv
        println("## Resolving name...")
        try
            c= coord.get_icrs_coordinates(fname)
            longi= c.ra[1] ; lati= c.dec[1]
            iscoord= true
        catch err
            @printf("## failed to resolve %s \n", fname)
        end
    end

    if iscoord
        get_gaia_data(rad, tol, longi, lati, fname)
    else
        println("No coordinates defined...")
    end
end

max_stars_repo_name: bosscha/gaia-shock

max_issues_repo_name: bosscha/gaia-shock

max_forks_repo_name: bosscha/gaia-shock


text:
# This file was generated by the Julia Swagger Code Generator
# Do not modify this file directly. Modify the swagger specification instead.

struct NetworkInterfacesApi <: SwaggerApi
    client::Swagger.Client
end

"""

Get the specified network interface in a virtual machine scale set.
Param: resourceGroupName::String (required)
Param: virtualMachineScaleSetName::String (required)
Param: virtualmachineIndex::String (required)
Param: networkInterfaceName::String (required)
Param: api_version::String (required)
Param: subscriptionId::String (required)
Param: expand::String
Return: NetworkInterface
"""
function networkInterfacesGetVirtualMachineScaleSetNetworkInterface(_api::NetworkInterfacesApi, resourceGroupName::String, virtualMachineScaleSetName::String, virtualmachineIndex::String, networkInterfaceName::String, api_version::String, subscriptionId::String; expand=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", NetworkInterface, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.Compute/virtualMachineScaleSets/{virtualMachineScaleSetName}/virtualMachines/{virtualmachineIndex}/networkInterfaces/{networkInterfaceName}", ["azure_auth"])
    Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName)  # type String
    Swagger.set_param(_ctx.path, "virtualMachineScaleSetName", virtualMachineScaleSetName)  # type String
    Swagger.set_param(_ctx.path, "virtualmachineIndex", virtualmachineIndex)  # type String
    Swagger.set_param(_ctx.path, "networkInterfaceName", networkInterfaceName)  # type String
    Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId)  # type String
    Swagger.set_param(_ctx.query, "api-version", api_version)  # type String
    Swagger.set_param(_ctx.query, "\$expand", expand)  # type String
    Swagger.set_header_accept(_ctx, ["application/json", "text/json"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json", "text/json"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

Gets all network interfaces in a virtual machine scale set.
Param: resourceGroupName::String (required)
Param: virtualMachineScaleSetName::String (required)
Param: api_version::String (required)
Param: subscriptionId::String (required)
Return: NetworkInterfaceListResult
"""
function networkInterfacesListVirtualMachineScaleSetNetworkInterfaces(_api::NetworkInterfacesApi, resourceGroupName::String, virtualMachineScaleSetName::String, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", NetworkInterfaceListResult, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.Compute/virtualMachineScaleSets/{virtualMachineScaleSetName}/networkInterfaces", ["azure_auth"])
    Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName)  # type String
    Swagger.set_param(_ctx.path, "virtualMachineScaleSetName", virtualMachineScaleSetName)  # type String
    Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId)  # type String
    Swagger.set_param(_ctx.query, "api-version", api_version)  # type String
    Swagger.set_header_accept(_ctx, ["application/json", "text/json"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json", "text/json"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

Gets information about all network interfaces in a virtual machine in a virtual machine scale set.
Param: resourceGroupName::String (required)
Param: virtualMachineScaleSetName::String (required)
Param: virtualmachineIndex::String (required)
Param: api_version::String (required)
Param: subscriptionId::String (required)
Return: NetworkInterfaceListResult
"""
function networkInterfacesListVirtualMachineScaleSetVMNetworkInterfaces(_api::NetworkInterfacesApi, resourceGroupName::String, virtualMachineScaleSetName::String, virtualmachineIndex::String, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", NetworkInterfaceListResult, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.Compute/virtualMachineScaleSets/{virtualMachineScaleSetName}/virtualMachines/{virtualmachineIndex}/networkInterfaces", ["azure_auth"])
    Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName)  # type String
    Swagger.set_param(_ctx.path, "virtualMachineScaleSetName", virtualMachineScaleSetName)  # type String
    Swagger.set_param(_ctx.path, "virtualmachineIndex", virtualmachineIndex)  # type String
    Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId)  # type String
    Swagger.set_param(_ctx.query, "api-version", api_version)  # type String
    Swagger.set_header_accept(_ctx, ["application/json", "text/json"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json", "text/json"] : [_mediaType])
    Swagger.exec(_ctx)
end

export networkInterfacesGetVirtualMachineScaleSetNetworkInterface, networkInterfacesListVirtualMachineScaleSetNetworkInterfaces, networkInterfacesListVirtualMachineScaleSetVMNetworkInterfaces


text:
using HDF5,JLD,KUparser,KUnet,Base.Test

# Load data
@date @load "acl11.trn.jld4"
ncpu = 20
nbatch = 99999
ndeps = length(deprel)
ft = Flist.acl11eager
pt = ArcEager13
p0 = pt(1,ndeps)
s1 = corpus[1]
net = newnet(relu, flen(p0,s1,ft), 20000, p0.nmove; learningRate=1)
net[end].f = logp

# Multi-cpu processing
@date p7=gparse(pt, corpus, ndeps, ft, net, nbatch, ncpu)
@date pxy8=gparse(pt, corpus, ndeps, ft, net, nbatch, ncpu; xy=true)
@show map(size, pxy8)
@test @show isequal(p7, pxy8[1])


text:
using HPAT

#HPAT.CaptureAPI.set_debug_level(3)
#HPAT.DomainPass.set_debug_level(3)
#HPAT.DataTablePass.set_debug_level(3)

@acc hpat function q25(d_date, file_name)
    store_sales = DataSource(DataTable{:ss_customer_sk=Int64, :ss_ticket_number=Int64, :ss_sold_date_sk=Int64, :ss_net_paid=Float64}, HDF5, file_name)

    store_agg = aggregate(store_sales, :cid = :ss_customer_sk,
                                           :frequency = length(unique(:ss_ticket_number)),
                                           :most_recent_date = maximum(:ss_sold_date_sk),
                                           :amount = sum(:ss_net_paid))

    return store_agg[:cid], store_agg[:frequency], store_agg[:most_recent_date], store_agg[:amount]
end

using HDF5
using MPI
if MPI.Comm_rank(MPI.COMM_WORLD)==0
    h5write("test_q25.hdf5", "/ss_customer_sk", [1,1,2,2,1])
    h5write("test_q25.hdf5", "/ss_ticket_number", [0,3,5,6,0])
    h5write("test_q25.hdf5", "/ss_sold_date_sk", [37580,34000,35000,36000,37600])
    h5write("test_q25.hdf5", "/ss_net_paid", [101.0,24.0,3.5,50.0,3.2])
end

c, f, m, a = q25("33000", "test_q25.hdf5")
println(c,f,m,a)

using Base.Test
@test c==[1,2]
@test f==[2,2]
@test m==[37600,36000]
@test_approx_eq a [128.2,53.5]


text:
using Plots

include(string(pwd(), "/src/gensys.jl"))
include(string(pwd(), "/gali_bayesian.jl"))

sol = gensys(GAMMA_0,GAMMA_1,PSI,PI)

irfs = irf(sol,15,0.25)

Plots.plot(4*irfs[:,1], label = "Inflação",w=3)
Plots.plot!(4*irfs_true[2:15,1], label = "Inflation True", line = :dash,w=3)

Plots.plot(irfs[:,2], label = "Output Gap",w=3)
Plots.plot!(irfs_true[2:15,2], label = "Output Gap True",line = :dash,w=3)

Plots.plot(4*irfs[:,3], label = "Juros",w=3)
Plots.plot!(4*irfs_true[2:15,3], label = "Juros True",w=3,line = :dash)

Plots.plot(irfs[:,4], label = "v",w=3)
Plots.plot!(irfs_true[2:15,4], label = "v True",w=3,line = :dash)

max_stars_repo_name: danmrc/DSGE-HMC

max_issues_repo_name: danmrc/DSGE-HMC

max_forks_repo_name: danmrc/DSGE-HMC


text:
### A Pluto.jl notebook ###
# v0.15.0

using Markdown
using InteractiveUtils

# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
    quote
        local el = $(esc(element))
        global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : missing
        el
    end
end

# ╔═╡ ada79ea0-f796-11ea-1aa2-eddd747b2c83
begin
	using PlutoUI
	using CEDICT
	using LightGraphs
	using Plots, GraphPlot
end

# ╔═╡ fc1f2d1e-f799-11ea-2606-f5046723c160
using LongestPaths

# ╔═╡ 6269f9b0-f778-11ea-2004-394d3bf5ff7c
md"""
# Making 成語接龍

## Idiom Source
Here, I've just filtered the CEDICT for only entries that have "(idiom)" in one of the definitions.
"""

# ╔═╡ 89e768e0-f775-11ea-02b9-5b07cf88d0b4
dict = ChineseDictionary();

# ╔═╡ 04c116f0-f77c-11ea-305e-cf13b0d83a8f
trad_idioms = [entry.trad for entry in idioms(dict)]

# ╔═╡ afabceb0-f778-11ea-0b9a-bb3cbcdf2836
md"""
## Creating the Graph
Now, to make the computations easier, I'm going to represent all the 成語 that I have in a graph. We could make the graph have an edge between idiom A and idiom B if the last character in A is the first character in B. There can be different ideas of being the "same": being the exact same character, have the exact same pronounciation, having the same primary pronounciation but a different tone, etc.

But this graph is awkward to create (to add an edge from an idiom, I need to scan through all the other **terminal characters** (ones either at the beginning or the end of idioms) to figure out which ones to add as destinations. This would be a slow $O(n^2)$ algorithm. Instead, the vertices will represent terminal characters, and an idiom is represented as an edge from its starting character to its ending character.

Because LightGraphs is optimized for integer-like vertices, first we'll create some mappings between the traditional terminal characters and the first $n$ positive natural numbers (where $n$ is the number of these characters).
"""

# ╔═╡ d62e2d50-f77b-11ea-0f69-ab7371ff50d6
terminal_chars = union(
	# initials
	Set(first(idiom) for idiom in trad_idioms),
	# finals
	Set(last(idiom) for idiom in trad_idioms)
)

# ╔═╡ e94d86d0-f783-11ea-0e6c-5d774a41d58c
num2term = collect(terminal_chars)

# ╔═╡ ef8a82f0-f783-11ea-3e6c-d5591033c789
term2num = Dict(term_char => UInt16(index) for (index, term_char) in pairs(num2term))

# ╔═╡ 85e6c400-f77c-11ea-27f5-e7f9846cadcb
let num_idioms = length(trad_idioms), num_term_chars = length(terminal_chars)
	md"""
	*Brief aside*: It's a little interesting to me that even though there are $num_idioms idioms in the dictionary, there are only $num_term_chars total terminal characters. That means on average each terminal character is repeated $(round(2*num_idioms/num_term_chars; digits=2)) times.
	"""
end

# ╔═╡ 021f2dce-f77a-11ea-3bc3-1770604ce10a
idiom_graph = SimpleDiGraph(UInt16(length(terminal_chars)));

# ╔═╡ 3417ba30-f786-11ea-2d30-a9df1f9ca6a0
edge_idioms = Dict{Tuple{Char, Char}, Vector{String}}();

# ╔═╡ c670e330-f776-11ea-22c6-598dabb22ca4
for idiom in trad_idioms
	edge = (first(idiom), last(idiom))
	add_edge!(idiom_graph, term2num[first(edge)], term2num[last(edge)])

	if haskey(edge_idioms, edge)
		push!(edge_idioms[edge], idiom)
	else
		edge_idioms[edge] = [idiom]
	end

end

# ╔═╡ dd133a30-f784-11ea-1d08-c9224043fcd8
md"""
Now to use the graph to access information about the connectedness of different idioms, we can do things like query the neighbors (converting between our graph vertices as needed).
"""

# ╔═╡ 9d70c340-f787-11ea-3b52-4302490de06a
initial = '叫';

# ╔═╡ e7634a5e-f780-11ea-1bab-8308a9188fd7
initial_outneighbors = num2term[outneighbors(idiom_graph, term2num[initial])]

# ╔═╡ 0a65dba2-f785-11ea-2112-ad09bee3f657
md"""
Here, this means that there are idioms that start with 叫 and end with either 天 or 迭. To see which ones, we'll have to query the `edge_idioms` dictionary.
"""

# ╔═╡ a1395970-f786-11ea-3273-c3cabe974073
[edge_idioms[(initial, final)] for final in initial_outneighbors]

# ╔═╡ 863059b0-f788-11ea-1466-173304238a3c
md"""
So there are two idioms for each final terminal character in this case.

We can also figure out what idioms end with that character.
"""

# ╔═╡ d8490b20-f788-11ea-0dc4-f31128f26958
initial_inneighbors = num2term[inneighbors(idiom_graph, term2num[initial])]

# ╔═╡ edda218e-f788-11ea-087e-63329996b830
[edge_idioms[(final, initial)] for final in initial_inneighbors]

# ╔═╡ 207b4070-f789-11ea-2f23-6945d91c5dc7
md"""
## Basic Chains
We can just iterate through the graph, choosing a random path to go down in order to create some Markov chain dragons.

First, let's figure out how to get to the next idiom.
"""

# ╔═╡ 59036480-f78f-11ea-1d45-9f33c884a7d1
function random_idiom(prev_idiom)
	# get the last character of the previous idiom
	first_char = last(prev_idiom)

	# all possible end characters
	end_chars = outneighbors(idiom_graph, term2num[first_char])
	length(end_chars) == 0 && return nothing

	# out of all possible end characters, choose a random one
	last_char = num2term[rand(end_chars)]

	# all possible idioms that start and end with these characters
	possible_idioms = edge_idioms[(first_char, last_char)]
	length(possible_idioms) == 0 && return nothing

	# choose randomly from all possible idioms that start and end with these chars
	rand(possible_idioms)
end;

# ╔═╡ d3786f40-f793-11ea-28f4-83043da67d5c
md"""
(A slight issue with this implementation is that all idioms starting with a certain character are not necessarily chosen with equal probability.)

Now, let's try it out on some idioms from our list.
"""

# ╔═╡ 6b7a0340-f789-11ea-2677-b967a8665cce
initial_idiom = rand(trad_idioms)

# ╔═╡ fbc7ad60-f790-11ea-2396-2d60b71ebb36
random_idiom(initial_idiom)

# ╔═╡ 73a9207e-f78b-11ea-3bd3-29cc530a2cdb
md"To make it repeat the process..."

# ╔═╡ 7adba030-f78b-11ea-2833-6d4cfe471978
function random_idiom_walk(idiom, len = 100)
	idioms = Vector{String}()
	i = 0
	while idiom != nothing && i <= len
		push!(idioms, idiom)
		i += 1
		idiom = random_idiom(idiom)
	end
	idioms
end;

# ╔═╡ a2c3faa0-f792-11ea-01c6-1fa82522f5ea
random_idiom_walk(initial_idiom)

# ╔═╡ 97e74cc0-f794-11ea-25f5-e73f194a7d6e
md"""
Wait a minute! These are all really short! It's really hard to actually connect them, even when repeating this experiment many times:
"""

# ╔═╡ 87d1cc50-f796-11ea-1777-1f8e16901fd9
maximum(length.(random_idiom_walk.(rand(trad_idioms, 100))))

# ╔═╡ a4cd7ee0-f795-11ea-0532-211a33e21562
md"""
Let's plot the distributions as histograms to see what's going on.
"""

# ╔═╡ c109a010-f796-11ea-170b-5de0f28d25b3
md"""
Number of Samples:
$(@bind samples Slider(10:2000, default=20, show_value=true))
"""

# ╔═╡ d1048c40-f797-11ea-3c3d-6383874745c1
md"""
Maximum Number of Iterations:
$(@bind len Slider(20:500, default=250, show_value=true))
"""

# ╔═╡ 56e84882-f796-11ea-0720-d1ee3698265e
histogram(length.(random_idiom_walk.(rand(trad_idioms, samples), len)), bins=15)

# ╔═╡ 13bf3850-f798-11ea-0591-57e00345f4c2
md"""
So it's very rare in general that we ever hit the limit on the number of iterations. Although when we do, we *really* hit it, so maybe there's something else going on, like it's a cycle in the graph (which we currently don't detect).
"""

# ╔═╡ e96e21a0-f798-11ea-3f54-ff0b05d1eb35
md"""
# Longest Cycles & Paths
If we want to prove there is a cycle, the easiest way is to see if there's an idiom that starts and ends with the same character (these are actually already excluded as LightGraphs graphs by default exclude self-loops).
"""

# ╔═╡ 42d03620-f799-11ea-3669-69a09bd1facf
[idiom for idiom in trad_idioms if first(idiom) == last(idiom)]

# ╔═╡ c4de4760-f799-11ea-21cf-d9d374c89e67
md"""
Voila! So there are already some self-loops (technically, we could have self-loops, but no cycles of length 2, but that's unlikely, so we'll just keep moving on).

What's more interesting is the longest cycle in this graph. However, this (and the similar longest path problem) is an NP-hard problem. We can still try the brute force method and hope our graph is sufficiently small and well-behaved.
"""

# ╔═╡ 1aa5b380-f79b-11ea-0a27-b5b7d7091b9f
find_longest_cycle(idiom_graph)

# ╔═╡ 33068bc0-f79b-11ea-1c88-e9d151c04ead
find_longest_path(idiom_graph)

# ╔═╡ cafc4c00-f7a8-11ea-205d-2f425d554032
gplot(idiom_graph)

# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[compat]
CEDICT = "~0.2.1"
GraphPlot = "~0.4.4"
LightGraphs = "~1.3.5"
LongestPaths = "~0.1.0"
Plots = "~1.16.6"
PlutoUI = "~0.7.9"

[deps]
CEDICT = "76a33514-0aea-4d2f-abaf-6a43b94fc20c"
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
LongestPaths = "3a25c17e-307c-411a-a047-890a9a5fbb4d"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
"""

# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised

[[Adapt]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "84918055d15b3114ede17ac6a7182f68870c16f7"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "3.3.1"

[[ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"

[[ArnoldiMethod]]
deps = ["LinearAlgebra", "Random", "StaticArrays"]
git-tree-sha1 = "f87e559f87a45bece9c9ed97458d3afe98b1ebb9"
uuid = "ec485272-7323-5ecc-a04f-4719b315124d"
version = "0.1.0"

[[Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[BenchmarkTools]]
deps = ["JSON", "Logging", "Printf", "Statistics", "UUIDs"]
git-tree-sha1 = "01ca3823217f474243cc2c8e6e1d1f45956fe872"
uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
version = "1.0.0"

[[BinaryProvider]]
deps = ["Libdl", "Logging", "SHA"]
git-tree-sha1 = "ecdec412a9abc8db54c0efc5548c64dfce072058"
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
version = "0.5.10"

[[Bzip2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "c3598e525718abcc440f69cc6d5f60dda0a1b61e"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.6+5"

[[CEDICT]]
deps = ["LazyArtifacts", "Pipe"]
git-tree-sha1 = "bc1353298886fea3126be2c440a0d6455d68c6b2"
uuid = "76a33514-0aea-4d2f-abaf-6a43b94fc20c"
version = "0.2.1"

[[Cairo_jll]]
deps = ["Artifacts", "Bzip2_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "e2f47f6d8337369411569fd45ae5753ca10394c6"
uuid = "83423d85-b0ee-5818-9007-b63ccbeb887a"
version = "1.16.0+6"

[[Cbc]]
deps = ["BinaryProvider", "Libdl", "MathOptInterface", "MathProgBase", "SparseArrays", "Test"]
git-tree-sha1 = "62d80f448b5d77b3f0a59cecf6197aad2a3aa280"
uuid = "9961bab8-2fa3-5c5a-9d89-47fab24efd76"
version = "0.6.7"

[[Clp]]
deps = ["BinaryProvider", "Clp_jll", "Libdl", "LinearAlgebra", "MathOptInterface", "MathProgBase", "SparseArrays"]
git-tree-sha1 = "08ca3c2fb7321ccab2f512f4fb77291e696a7d9b"
uuid = "e2554f3b-3117-50c0-817c-e040a3ddf72d"
version = "0.7.2"

[[Clp_jll]]
deps = ["Artifacts", "CoinUtils_jll", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "OpenBLAS32_jll", "Osi_jll", "Pkg"]
git-tree-sha1 = "d9eca9fa2435959b5542b13409a8ec5f64c947c8"
uuid = "06985876-5285-5a41-9fcb-8948a742cc53"
version = "1.17.6+7"

[[CodecBzip2]]
deps = ["Bzip2_jll", "Libdl", "TranscodingStreams"]
git-tree-sha1 = "2e62a725210ce3c3c2e1a3080190e7ca491f18d7"
uuid = "523fee87-0ab8-5b00-afb7-3ecf72e48cfd"
version = "0.7.2"

[[CodecZlib]]
deps = ["TranscodingStreams", "Zlib_jll"]
git-tree-sha1 = "ded953804d019afa9a3f98981d99b33e3db7b6da"
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
version = "0.7.0"

[[CoinUtils_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "OpenBLAS32_jll", "Pkg"]
git-tree-sha1 = "5186155a8609b71eae7e104fa2b8fbf6ecd5d9bb"
uuid = "be027038-0da8-5614-b30d-e42594cb92df"
version = "2.11.3+4"

[[ColorSchemes]]
deps = ["ColorTypes", "Colors", "FixedPointNumbers", "Random", "StaticArrays"]
git-tree-sha1 = "c8fd01e4b736013bc61b704871d20503b33ea402"
uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
version = "3.12.1"

[[ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "32a2b8af383f11cbb65803883837a149d10dfe8a"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.10.12"

[[Colors]]
deps = ["ColorTypes", "FixedPointNumbers", "Reexport"]
git-tree-sha1 = "417b0ed7b8b838aa6ca0a87aadf1bb9eb111ce40"
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
version = "0.12.8"

[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "dc7dedc2c2aa9faf59a55c622760a25cbefbe941"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.31.0"

[[CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"

[[Compose]]
deps = ["Base64", "Colors", "DataStructures", "Dates", "IterTools", "JSON", "LinearAlgebra", "Measures", "Printf", "Random", "Requires", "Statistics", "UUIDs"]
git-tree-sha1 = "c6461fc7c35a4bb8d00905df7adafcff1fe3a6bc"
uuid = "a81c6b42-2e10-5240-aca2-a61377ecd94b"
version = "0.9.2"

[[Contour]]
deps = ["StaticArrays"]
git-tree-sha1 = "9f02045d934dc030edad45944ea80dbd1f0ebea7"
uuid = "d38c429a-6771-53c6-b99e-75d170b6e991"
version = "0.5.7"

[[DataAPI]]
git-tree-sha1 = "ee400abb2298bd13bfc3df1c412ed228061a2385"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.7.0"

[[DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "4437b64df1e0adccc3e5d1adbc3ac741095e4677"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.9"

[[DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464"
version = "1.0.0"

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[Downloads]]
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"

[[EarCut_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "92d8f9f208637e8d2d28c664051a00569c01493d"
uuid = "5ae413db-bbd1-5e63-b57d-d24a61df00f5"
version = "2.1.5+1"

[[Expat_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b3bfd02e98aedfa5cf885665493c5598c350cd2f"
uuid = "2e619515-83b5-522b-bb60-26c02a35a201"
version = "2.2.10+0"

[[FFMPEG]]
deps = ["FFMPEG_jll"]
git-tree-sha1 = "b57e3acbe22f8484b4b5ff66a7499717fe1a9cc8"
uuid = "c87230d0-a227-11e9-1b43-d7ebe4e7570a"
version = "0.4.1"

[[FFMPEG_jll]]
deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "JLLWrappers", "LAME_jll", "LibVPX_jll", "Libdl", "Ogg_jll", "OpenSSL_jll", "Opus_jll", "Pkg", "Zlib_jll", "libass_jll", "libfdk_aac_jll", "libvorbis_jll", "x264_jll", "x265_jll"]
git-tree-sha1 = "3cc57ad0a213808473eafef4845a74766242e05f"
uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5"
version = "4.3.1+4"

[[FixedPointNumbers]]
deps = ["Statistics"]
git-tree-sha1 = "335bfdceacc84c5cdf16aadc768aa5ddfc5383cc"
uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
version = "0.8.4"

[[Fontconfig_jll]]
deps = ["Artifacts", "Bzip2_jll", "Expat_jll", "FreeType2_jll", "JLLWrappers", "Libdl", "Libuuid_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "35895cf184ceaab11fd778b4590144034a167a2f"
uuid = "a3f928ae-7b40-5064-980b-68af3947d34b"
version = "2.13.1+14"

[[Formatting]]
deps = ["Printf"]
git-tree-sha1 = "8339d61043228fdd3eb658d86c926cb282ae72a8"
uuid = "59287772-0a20-5a39-b81b-1366585eb4c0"
version = "0.4.2"

[[FreeType2_jll]]
deps = ["Artifacts", "Bzip2_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "cbd58c9deb1d304f5a245a0b7eb841a2560cfec6"
uuid = "d7e528f0-a631-5988-bf34-fe36492bcfd7"
version = "2.10.1+5"

[[FriBidi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "aa31987c2ba8704e23c6c8ba8a4f769d5d7e4f91"
uuid = "559328eb-81f9-559d-9380-de523a88c83c"
version = "1.0.10+0"

[[GLFW_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libglvnd_jll", "Pkg", "Xorg_libXcursor_jll", "Xorg_libXi_jll", "Xorg_libXinerama_jll", "Xorg_libXrandr_jll"]
git-tree-sha1 = "dba1e8614e98949abfa60480b13653813d8f0157"
uuid = "0656b61e-2033-5cc2-a64a-77c0f6c09b89"
version = "3.3.5+0"

[[GR]]
deps = ["Base64", "DelimitedFiles", "GR_jll", "HTTP", "JSON", "Libdl", "LinearAlgebra", "Pkg", "Printf", "Random", "Serialization", "Sockets", "Test", "UUIDs"]
git-tree-sha1 = "b83e3125048a9c3158cbb7ca423790c7b1b57bea"
uuid = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
version = "0.57.5"

[[GR_jll]]
deps = ["Artifacts", "Bzip2_jll", "Cairo_jll", "FFMPEG_jll", "Fontconfig_jll", "GLFW_jll", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Libtiff_jll", "Pixman_jll", "Pkg", "Qt5Base_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "e14907859a1d3aee73a019e7b3c98e9e7b8b5b3e"
uuid = "d2c73de3-f751-5644-a686-071e5b155ba9"
version = "0.57.3+0"

[[GeometryBasics]]
deps = ["EarCut_jll", "IterTools", "LinearAlgebra", "StaticArrays", "StructArrays", "Tables"]
git-tree-sha1 = "4136b8a5668341e58398bb472754bff4ba0456ff"
uuid = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
version = "0.3.12"

[[Gettext_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "XML2_jll"]
git-tree-sha1 = "9b02998aba7bf074d14de89f9d37ca24a1a0b046"
uuid = "78b55507-aeef-58d4-861c-77aaff3498b1"
version = "0.21.0+0"

[[Glib_jll]]
deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "47ce50b742921377301e15005c96e979574e130b"
uuid = "7746bdde-850d-59dc-9ae8-88ece973131d"
version = "2.68.1+0"

[[GraphPlot]]
deps = ["ArnoldiMethod", "ColorTypes", "Colors", "Compose", "DelimitedFiles", "LightGraphs", "LinearAlgebra", "Random", "SparseArrays"]
git-tree-sha1 = "dd8f15128a91b0079dfe3f4a4a1e190e54ac7164"
uuid = "a2cc645c-3eea-5389-862e-a155d0052231"
version = "0.4.4"

[[Grisu]]
git-tree-sha1 = "53bb909d1151e57e2484c3d1b53e19552b887fb2"
uuid = "42e2da0e-8278-4e71-bc24-59509adca0fe"
version = "1.0.2"

[[HTTP]]
deps = ["Base64", "Dates", "IniFile", "MbedTLS", "NetworkOptions", "Sockets", "URIs"]
git-tree-sha1 = "86ed84701fbfd1142c9786f8e53c595ff5a4def9"
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
version = "0.9.10"

[[Inflate]]
git-tree-sha1 = "f5fc07d4e706b84f72d54eedcc1c13d92fb0871c"
uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9"
version = "0.1.2"

[[IniFile]]
deps = ["Test"]
git-tree-sha1 = "098e4d2c533924c921f9f9847274f2ad89e018b8"
uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f"
version = "0.5.0"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[IterTools]]
git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18"
uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
version = "1.3.0"

[[IteratorInterfaceExtensions]]
git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856"
uuid = "82899510-4779-5014-852e-03e436cf321d"
version = "1.0.0"

[[JLLWrappers]]
deps = ["Preferences"]
git-tree-sha1 = "642a199af8b68253517b80bd3bfd17eb4e84df6e"
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
version = "1.3.0"

[[JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "81690084b6198a2e1da36fcfda16eeca9f9f24e4"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.1"

[[JSONSchema]]
deps = ["HTTP", "JSON", "ZipFile"]
git-tree-sha1 = "b84ab8139afde82c7c65ba2b792fe12e01dd7307"
uuid = "7d188eb4-7ad8-530c-ae41-71a32a6d4692"
version = "0.3.3"

[[JpegTurbo_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "d735490ac75c5cb9f1b00d8b5509c11984dc6943"
uuid = "aacddb02-875f-59d6-b918-886e6ef4fbf8"
version = "2.1.0+0"

[[LAME_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "f6250b16881adf048549549fba48b1161acdac8c"
uuid = "c1c5ebd0-6772-5130-a774-d5fcae4a789d"
version = "3.100.1+0"

[[LZO_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "e5b909bcf985c5e2605737d2ce278ed791b89be6"
uuid = "dd4b983a-f0e5-5f8d-a1b7-129d4a5fb1ac"
version = "2.10.1+0"

[[LaTeXStrings]]
git-tree-sha1 = "c7f1c695e06c01b95a67f0cd1d34994f3e7db104"
uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
version = "1.2.1"

[[Latexify]]
deps = ["Formatting", "InteractiveUtils", "LaTeXStrings", "MacroTools", "Markdown", "Printf", "Requires"]
git-tree-sha1 = "a4b12a1bd2ebade87891ab7e36fdbce582301a92"
uuid = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
version = "0.15.6"

[[LazyArtifacts]]
deps = ["Artifacts", "Pkg"]
uuid = "4af54fe1-eca0-43a8-85a7-787d91b784e3"

[[LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"

[[LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"

[[LibGit2]]
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[LibSSH2_jll]]
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"

[[LibVPX_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "12ee7e23fa4d18361e7c2cde8f8337d4c3101bc7"
uuid = "dd192d2f-8180-539f-9fb4-cc70b1dcf69a"
version = "1.10.0+0"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[Libffi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "761a393aeccd6aa92ec3515e428c26bf99575b3b"
uuid = "e9f186c6-92d2-5b65-8a66-fee21dc1b490"
version = "3.2.2+0"

[[Libgcrypt_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgpg_error_jll", "Pkg"]
git-tree-sha1 = "64613c82a59c120435c067c2b809fc61cf5166ae"
uuid = "d4300ac3-e22c-5743-9152-c294e39db1e4"
version = "1.8.7+0"

[[Libglvnd_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll", "Xorg_libXext_jll"]
git-tree-sha1 = "7739f837d6447403596a75d19ed01fd08d6f56bf"
uuid = "7e76a0d4-f3c7-5321-8279-8d96eeed0f29"
version = "1.3.0+3"

[[Libgpg_error_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "c333716e46366857753e273ce6a69ee0945a6db9"
uuid = "7add5ba3-2f88-524e-9cd5-f83b8a55f7b8"
version = "1.42.0+0"

[[Libiconv_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "42b62845d70a619f063a7da093d995ec8e15e778"
uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531"
version = "1.16.1+1"

[[Libmount_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "9c30530bf0effd46e15e0fdcf2b8636e78cbbd73"
uuid = "4b2f31a3-9ecc-558c-b454-b3730dcb73e9"
version = "2.35.0+0"

[[Libtiff_jll]]
deps = ["Artifacts", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Pkg", "Zlib_jll", "Zstd_jll"]
git-tree-sha1 = "340e257aada13f95f98ee352d316c3bed37c8ab9"
uuid = "89763e89-9b03-5906-acba-b20f662cd828"
version = "4.3.0+0"

[[Libuuid_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "7f3efec06033682db852f8b3bc3c1d2b0a0ab066"
uuid = "38a345b3-de98-5d2b-a5d3-14cd9215e700"
version = "2.36.0+0"

[[LightGraphs]]
deps = ["ArnoldiMethod", "DataStructures", "Distributed", "Inflate", "LinearAlgebra", "Random", "SharedArrays", "SimpleTraits", "SparseArrays", "Statistics"]
git-tree-sha1 = "432428df5f360964040ed60418dd5601ecd240b6"
uuid = "093fc24a-ae57-5d10-9952-331d41423f4d"
version = "1.3.5"

[[LinearAlgebra]]
deps = ["Libdl"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[LongestPaths]]
deps = ["Cbc", "Clp", "LightGraphs", "MathProgBase", "Printf", "Random", "SparseArrays", "Test"]
git-tree-sha1 = "a1224131e9193721a56abbfbc44825c120a2bc8e"
uuid = "3a25c17e-307c-411a-a047-890a9a5fbb4d"
version = "0.1.0"

[[MacroTools]]
deps = ["Markdown", "Random"]
git-tree-sha1 = "6a8a2a625ab0dea913aba95c11370589e0239ff0"
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
version = "0.5.6"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[MathOptInterface]]
deps = ["BenchmarkTools", "CodecBzip2", "CodecZlib", "JSON", "JSONSchema", "LinearAlgebra", "MutableArithmetics", "OrderedCollections", "SparseArrays", "Test", "Unicode"]
git-tree-sha1 = "575644e3c05b258250bb599e57cf73bbf1062901"
uuid = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
version = "0.9.22"

[[MathProgBase]]
deps = ["LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "9abbe463a1e9fc507f12a69e7f29346c2cdc472c"
uuid = "fdba3010-5040-5b88-9595-932c9decdf73"
version = "0.7.8"

[[MbedTLS]]
deps = ["Dates", "MbedTLS_jll", "Random", "Sockets"]
git-tree-sha1 = "1c38e51c3d08ef2278062ebceade0e46cefc96fe"
uuid = "739be429-bea8-5141-9913-cc70e7f3736d"
version = "1.0.3"

[[MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"

[[Measures]]
git-tree-sha1 = "e498ddeee6f9fdb4551ce855a46f54dbd900245f"
uuid = "442fdcdd-2543-5da2-b0f3-8c86c306513e"
version = "0.3.1"

[[Missings]]
deps = ["DataAPI"]
git-tree-sha1 = "4ea90bd5d3985ae1f9a908bd4500ae88921c5ce7"
uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
version = "1.0.0"

[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"

[[MutableArithmetics]]
deps = ["LinearAlgebra", "SparseArrays", "Test"]
git-tree-sha1 = "3927848ccebcc165952dc0d9ac9aa274a87bfe01"
uuid = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
version = "0.2.20"

[[NaNMath]]
git-tree-sha1 = "bfe47e760d60b82b66b61d2d44128b62e3a369fb"
uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
version = "0.3.5"

[[NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"

[[Ogg_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "7937eda4681660b4d6aeeecc2f7e1c81c8ee4e2f"
uuid = "e7412a2a-1a6e-54c0-be00-318e2571c051"
version = "1.3.5+0"

[[OpenBLAS32_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "ba4a8f683303c9082e84afba96f25af3c7fb2436"
uuid = "656ef2d0-ae68-5445-9ca0-591084a874a2"
version = "0.3.12+1"

[[OpenSSL_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "15003dcb7d8db3c6c857fda14891a539a8f2705a"
uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
version = "1.1.10+0"

[[Opus_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "51a08fb14ec28da2ec7a927c4337e4332c2a4720"
uuid = "91d4177d-7536-5919-b921-800302f37372"
version = "1.3.2+0"

[[OrderedCollections]]
git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.4.1"

[[Osi_jll]]
deps = ["Artifacts", "CoinUtils_jll", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "OpenBLAS32_jll", "Pkg"]
git-tree-sha1 = "ef540e28c9b82cb879e33c0885e1bbc9a1e6c571"
uuid = "7da25872-d9ce-5375-a4d3-7a845f58efdd"
version = "0.108.5+4"

[[PCRE_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b2a7af664e098055a7529ad1a900ded962bca488"
uuid = "2f80f16e-611a-54ab-bc61-aa92de5b98fc"
version = "8.44.0+0"

[[Parsers]]
deps = ["Dates"]
git-tree-sha1 = "c8abc88faa3f7a3950832ac5d6e690881590d6dc"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "1.1.0"

[[Pipe]]
git-tree-sha1 = "6842804e7867b115ca9de748a0cf6b364523c16d"
uuid = "b98c9c47-44ae-5843-9183-064241ee97a0"
version = "1.3.0"

[[Pixman_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b4f5d02549a10e20780a24fce72bea96b6329e29"
uuid = "30392449-352a-5448-841d-b1acce4e97dc"
version = "0.40.1+0"

[[Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[PlotThemes]]
deps = ["PlotUtils", "Requires", "Statistics"]
git-tree-sha1 = "a3a964ce9dc7898193536002a6dd892b1b5a6f1d"
uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a"
version = "2.0.1"

[[PlotUtils]]
deps = ["ColorSchemes", "Colors", "Dates", "Printf", "Random", "Reexport", "Statistics"]
git-tree-sha1 = "ae9a295ac761f64d8c2ec7f9f24d21eb4ffba34d"
uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043"
version = "1.0.10"

[[Plots]]
deps = ["Base64", "Contour", "Dates", "FFMPEG", "FixedPointNumbers", "GR", "GeometryBasics", "JSON", "Latexify", "LinearAlgebra", "Measures", "NaNMath", "PlotThemes", "PlotUtils", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "Requires", "Scratch", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs"]
git-tree-sha1 = "a680b659a1ba99d3663a40aa9acffd67768a410f"
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
version = "1.16.6"

[[PlutoUI]]
deps = ["Base64", "Dates", "InteractiveUtils", "JSON", "Logging", "Markdown", "Random", "Reexport", "Suppressor"]
git-tree-sha1 = "44e225d5837e2a2345e69a1d1e01ac2443ff9fcb"
uuid = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
version = "0.7.9"

[[Preferences]]
deps = ["TOML"]
git-tree-sha1 = "00cfd92944ca9c760982747e9a1d0d5d86ab1e5a"
uuid = "21216c6a-2e73-6563-6e65-726566657250"
version = "1.2.2"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[Qt5Base_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Fontconfig_jll", "Glib_jll", "JLLWrappers", "Libdl", "Libglvnd_jll", "OpenSSL_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libxcb_jll", "Xorg_xcb_util_image_jll", "Xorg_xcb_util_keysyms_jll", "Xorg_xcb_util_renderutil_jll", "Xorg_xcb_util_wm_jll", "Zlib_jll", "xkbcommon_jll"]
git-tree-sha1 = "ad368663a5e20dbb8d6dc2fddeefe4dae0781ae8"
uuid = "ea2cea3b-5b76-57ae-a6ef-0a8af62496e1"
version = "5.15.3+0"

[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[RecipesBase]]
git-tree-sha1 = "b3fb709f3c97bfc6e948be68beeecb55a0b340ae"
uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
version = "1.1.1"

[[RecipesPipeline]]
deps = ["Dates", "NaNMath", "PlotUtils", "RecipesBase"]
git-tree-sha1 = "9b8e57e3cca8828a1bc759840bfe48d64db9abfb"
uuid = "01d81517-befc-4cb6-b9ec-a95719d0359c"
version = "0.3.3"

[[Reexport]]
git-tree-sha1 = "5f6c21241f0f655da3952fd60aa18477cf96c220"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "1.1.0"

[[Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "4036a3bd08ac7e968e27c203d45f5fff15020621"
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.1.3"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[Scratch]]
deps = ["Dates"]
git-tree-sha1 = "0b4b7f1393cff97c33891da2a0bf69c6ed241fda"
uuid = "6c6a2e73-6563-6170-7368-637461726353"
version = "1.1.0"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[SharedArrays]]
deps = ["Distributed", "Mmap", "Random", "Serialization"]
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"

[[Showoff]]
deps = ["Dates", "Grisu"]
git-tree-sha1 = "91eddf657aca81df9ae6ceb20b959ae5653ad1de"
uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f"
version = "1.0.3"

[[SimpleTraits]]
deps = ["InteractiveUtils", "MacroTools"]
git-tree-sha1 = "daf7aec3fe3acb2131388f93a4c409b8c7f62226"
uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
version = "0.9.3"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[SortingAlgorithms]]
deps = ["DataStructures"]
git-tree-sha1 = "2ec1962eba973f383239da22e75218565c390a96"
uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
version = "1.0.0"

[[SparseArrays]]
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[StaticArrays]]
deps = ["LinearAlgebra", "Random", "Statistics"]
git-tree-sha1 = "745914ebcd610da69f3cb6bf76cb7bb83dcb8c9a"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.2.4"

[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[StatsAPI]]
git-tree-sha1 = "1958272568dc176a1d881acb797beb909c785510"
uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
version = "1.0.0"

[[StatsBase]]
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"]
git-tree-sha1 = "2f6792d523d7448bbe2fec99eca9218f06cc746d"
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
version = "0.33.8"

[[StructArrays]]
deps = ["Adapt", "DataAPI", "Tables"]
git-tree-sha1 = "44b3afd37b17422a62aea25f04c1f7e09ce6b07f"
uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
version = "0.5.1"

[[Suppressor]]
git-tree-sha1 = "a819d77f31f83e5792a76081eee1ea6342ab8787"
uuid = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
version = "0.2.0"

[[TOML]]
deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[[TableTraits]]
deps = ["IteratorInterfaceExtensions"]
git-tree-sha1 = "c06b2f539df1c6efa794486abfb6ed2022561a39"
uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c"
version = "1.0.1"

[[Tables]]
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"]
git-tree-sha1 = "8ed4a3ea724dac32670b062be3ef1c1de6773ae8"
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
version = "1.4.4"

[[Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"

[[Test]]
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[TranscodingStreams]]
deps = ["Random", "Test"]
git-tree-sha1 = "7c53c35547de1c5b9d46a4797cf6d8253807108c"
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
version = "0.9.5"

[[URIs]]
git-tree-sha1 = "97bbe755a53fe859669cd907f2d96aee8d2c1355"
uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
version = "1.3.0"

[[UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[Wayland_jll]]
deps = ["Artifacts", "Expat_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg", "XML2_jll"]
git-tree-sha1 = "3e61f0b86f90dacb0bc0e73a0c5a83f6a8636e23"
uuid = "a2964d1f-97da-50d4-b82a-358c7fce9d89"
version = "1.19.0+0"

[[Wayland_protocols_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Wayland_jll"]
git-tree-sha1 = "2839f1c1296940218e35df0bbb220f2a79686670"
uuid = "2381bf8a-dfd0-557d-9999-79630e7b1b91"
version = "1.18.0+4"

[[XML2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "1acf5bdf07aa0907e0a37d3718bb88d4b687b74a"
uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a"
version = "2.9.12+0"

[[XSLT_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgcrypt_jll", "Libgpg_error_jll", "Libiconv_jll", "Pkg", "XML2_jll", "Zlib_jll"]
git-tree-sha1 = "91844873c4085240b95e795f692c4cec4d805f8a"
uuid = "aed1982a-8fda-507f-9586-7b0439959a61"
version = "1.1.34+0"

[[Xorg_libX11_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxcb_jll", "Xorg_xtrans_jll"]
git-tree-sha1 = "5be649d550f3f4b95308bf0183b82e2582876527"
uuid = "4f6342f7-b3d2-589e-9d20-edeb45f2b2bc"
version = "1.6.9+4"

[[Xorg_libXau_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "4e490d5c960c314f33885790ed410ff3a94ce67e"
uuid = "0c0b7dd1-d40b-584c-a123-a41640f87eec"
version = "1.0.9+4"

[[Xorg_libXcursor_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXfixes_jll", "Xorg_libXrender_jll"]
git-tree-sha1 = "12e0eb3bc634fa2080c1c37fccf56f7c22989afd"
uuid = "935fb764-8cf2-53bf-bb30-45bb1f8bf724"
version = "1.2.0+4"

[[Xorg_libXdmcp_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "4fe47bd2247248125c428978740e18a681372dd4"
uuid = "a3789734-cfe1-5b06-b2d0-1dd0d9d62d05"
version = "1.1.3+4"

[[Xorg_libXext_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "b7c0aa8c376b31e4852b360222848637f481f8c3"
uuid = "1082639a-0dae-5f34-9b06-72781eeb8cb3"
version = "1.3.4+4"

[[Xorg_libXfixes_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "0e0dc7431e7a0587559f9294aeec269471c991a4"
uuid = "d091e8ba-531a-589c-9de9-94069b037ed8"
version = "5.0.3+4"

[[Xorg_libXi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXext_jll", "Xorg_libXfixes_jll"]
git-tree-sha1 = "89b52bc2160aadc84d707093930ef0bffa641246"
uuid = "a51aa0fd-4e3c-5386-b890-e753decda492"
version = "1.7.10+4"

[[Xorg_libXinerama_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXext_jll"]
git-tree-sha1 = "26be8b1c342929259317d8b9f7b53bf2bb73b123"
uuid = "d1454406-59df-5ea1-beac-c340f2130bc3"
version = "1.1.4+4"

[[Xorg_libXrandr_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll"]
git-tree-sha1 = "34cea83cb726fb58f325887bf0612c6b3fb17631"
uuid = "ec84b674-ba8e-5d96-8ba1-2a689ba10484"
version = "1.5.2+4"

[[Xorg_libXrender_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "19560f30fd49f4d4efbe7002a1037f8c43d43b96"
uuid = "ea2f1a96-1ddc-540d-b46f-429655e07cfa"
version = "0.9.10+4"

[[Xorg_libpthread_stubs_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "6783737e45d3c59a4a4c4091f5f88cdcf0908cbb"
uuid = "14d82f49-176c-5ed1-bb49-ad3f5cbd8c74"
version = "0.1.0+3"

[[Xorg_libxcb_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "XSLT_jll", "Xorg_libXau_jll", "Xorg_libXdmcp_jll", "Xorg_libpthread_stubs_jll"]
git-tree-sha1 = "daf17f441228e7a3833846cd048892861cff16d6"
uuid = "c7cfdc94-dc32-55de-ac96-5a1b8d977c5b"
version = "1.13.0+3"

[[Xorg_libxkbfile_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "926af861744212db0eb001d9e40b5d16292080b2"
uuid = "cc61e674-0454-545c-8b26-ed2c68acab7a"
version = "1.1.0+4"

[[Xorg_xcb_util_image_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xcb_util_jll"]
git-tree-sha1 = "0fab0a40349ba1cba2c1da699243396ff8e94b97"
uuid = "12413925-8142-5f55-bb0e-6d7ca50bb09b"
version = "0.4.0+1"

[[Xorg_xcb_util_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxcb_jll"]
git-tree-sha1 = "e7fd7b2881fa2eaa72717420894d3938177862d1"
uuid = "2def613f-5ad1-5310-b15b-b15d46f528f5"
version = "0.4.0+1"

[[Xorg_xcb_util_keysyms_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xcb_util_jll"]
git-tree-sha1 = "d1151e2c45a544f32441a567d1690e701ec89b00"
uuid = "975044d2-76e6-5fbe-bf08-97ce7c6574c7"
version = "0.4.0+1"

[[Xorg_xcb_util_renderutil_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xcb_util_jll"]
git-tree-sha1 = "dfd7a8f38d4613b6a575253b3174dd991ca6183e"
uuid = "0d47668e-0667-5a69-a72c-f761630bfb7e"
version = "0.3.9+1"

[[Xorg_xcb_util_wm_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xcb_util_jll"]
git-tree-sha1 = "e78d10aab01a4a154142c5006ed44fd9e8e31b67"
uuid = "c22f9ab0-d5fe-5066-847c-f4bb1cd4e361"
version = "0.4.1+1"

[[Xorg_xkbcomp_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxkbfile_jll"]
git-tree-sha1 = "4bcbf660f6c2e714f87e960a171b119d06ee163b"
uuid = "35661453-b289-5fab-8a00-3d9160c6a3a4"
version = "1.4.2+4"

[[Xorg_xkeyboard_config_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xkbcomp_jll"]
git-tree-sha1 = "5c8424f8a67c3f2209646d4425f3d415fee5931d"
uuid = "33bec58e-1273-512f-9401-5d533626f822"
version = "2.27.0+4"

[[Xorg_xtrans_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "79c31e7844f6ecf779705fbc12146eb190b7d845"
uuid = "c5fb5394-a638-5e4d-96e5-b29de1b5cf10"
version = "1.4.0+3"

[[ZipFile]]
deps = ["Libdl", "Printf", "Zlib_jll"]
git-tree-sha1 = "c3a5637e27e914a7a445b8d0ad063d701931e9f7"
uuid = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"
version = "0.9.3"

[[Zlib_jll]]
deps = ["Libdl"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"

[[Zstd_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "cc4bf3fdde8b7e3e9fa0351bdeedba1cf3b7f6e6"
uuid = "3161d3a3-bdf6-5164-811a-617609db77b4"
version = "1.5.0+0"

[[libass_jll]]
deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "acc685bcf777b2202a904cdcb49ad34c2fa1880c"
uuid = "0ac62f75-1d6f-5e53-bd7c-93b484bb37c0"
version = "0.14.0+4"

[[libfdk_aac_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "7a5780a0d9c6864184b3a2eeeb833a0c871f00ab"
uuid = "f638f0a6-7fb0-5443-88ba-1cc74229b280"
version = "0.1.6+4"

[[libpng_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "94d180a6d2b5e55e447e2d27a29ed04fe79eb30c"
uuid = "b53b4c65-9356-5827-b1ea-8c7a1a84506f"
version = "1.6.38+0"

[[libvorbis_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Ogg_jll", "Pkg"]
git-tree-sha1 = "c45f4e40e7aafe9d086379e5578947ec8b95a8fb"
uuid = "f27f6e37-5d2b-51aa-960f-b287f2bc3b7a"
version = "1.3.7+0"

[[nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"

[[p7zip_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"

[[x264_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "d713c1ce4deac133e3334ee12f4adff07f81778f"
uuid = "1270edf5-f2f9-52d2-97e9-ab00b5d0237a"
version = "2020.7.14+2"

[[x265_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "487da2f8f2f0c8ee0e83f39d13037d6bbf0a45ab"
uuid = "dfaa095f-4041-5dcd-9319-2fabd8486b76"
version = "3.0.0+3"

[[xkbcommon_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Wayland_jll", "Wayland_protocols_jll", "Xorg_libxcb_jll", "Xorg_xkeyboard_config_jll"]
git-tree-sha1 = "ece2350174195bb31de1a63bea3a41ae1aa593b6"
uuid = "d8fb68d0-12a3-5cfd-a85a-d49703b185fd"
version = "0.9.1+5"
"""

# ╔═╡ Cell order:
# ╠═ada79ea0-f796-11ea-1aa2-eddd747b2c83
# ╟─6269f9b0-f778-11ea-2004-394d3bf5ff7c
# ╠═89e768e0-f775-11ea-02b9-5b07cf88d0b4
# ╠═04c116f0-f77c-11ea-305e-cf13b0d83a8f
# ╟─afabceb0-f778-11ea-0b9a-bb3cbcdf2836
# ╠═d62e2d50-f77b-11ea-0f69-ab7371ff50d6
# ╠═e94d86d0-f783-11ea-0e6c-5d774a41d58c
# ╠═ef8a82f0-f783-11ea-3e6c-d5591033c789
# ╟─85e6c400-f77c-11ea-27f5-e7f9846cadcb
# ╠═021f2dce-f77a-11ea-3bc3-1770604ce10a
# ╠═3417ba30-f786-11ea-2d30-a9df1f9ca6a0
# ╠═c670e330-f776-11ea-22c6-598dabb22ca4
# ╟─dd133a30-f784-11ea-1d08-c9224043fcd8
# ╠═9d70c340-f787-11ea-3b52-4302490de06a
# ╠═e7634a5e-f780-11ea-1bab-8308a9188fd7
# ╟─0a65dba2-f785-11ea-2112-ad09bee3f657
# ╠═a1395970-f786-11ea-3273-c3cabe974073
# ╟─863059b0-f788-11ea-1466-173304238a3c
# ╠═d8490b20-f788-11ea-0dc4-f31128f26958
# ╠═edda218e-f788-11ea-087e-63329996b830
# ╟─207b4070-f789-11ea-2f23-6945d91c5dc7
# ╠═59036480-f78f-11ea-1d45-9f33c884a7d1
# ╟─d3786f40-f793-11ea-28f4-83043da67d5c
# ╠═6b7a0340-f789-11ea-2677-b967a8665cce
# ╠═fbc7ad60-f790-11ea-2396-2d60b71ebb36
# ╟─73a9207e-f78b-11ea-3bd3-29cc530a2cdb
# ╠═7adba030-f78b-11ea-2833-6d4cfe471978
# ╠═a2c3faa0-f792-11ea-01c6-1fa82522f5ea
# ╟─97e74cc0-f794-11ea-25f5-e73f194a7d6e
# ╠═87d1cc50-f796-11ea-1777-1f8e16901fd9
# ╟─a4cd7ee0-f795-11ea-0532-211a33e21562
# ╟─c109a010-f796-11ea-170b-5de0f28d25b3
# ╟─d1048c40-f797-11ea-3c3d-6383874745c1
# ╠═56e84882-f796-11ea-0720-d1ee3698265e
# ╟─13bf3850-f798-11ea-0591-57e00345f4c2
# ╟─e96e21a0-f798-11ea-3f54-ff0b05d1eb35
# ╟─42d03620-f799-11ea-3669-69a09bd1facf
# ╟─c4de4760-f799-11ea-21cf-d9d374c89e67
# ╠═fc1f2d1e-f799-11ea-2606-f5046723c160
# ╠═1aa5b380-f79b-11ea-0a27-b5b7d7091b9f
# ╠═33068bc0-f79b-11ea-1c88-e9d151c04ead
# ╠═cafc4c00-f7a8-11ea-205d-2f425d554032
# ╟─00000000-0000-0000-0000-000000000001
# ╟─00000000-0000-0000-0000-000000000002


text:
# function ParentId()
#     return ParentId(Vector{SingleId}())
# end

# ----------


text:
mutable struct ParallelJacobiPreconditioner{Tv, Ti} <: AbstractPreconditioner{Tv,Ti}
    A::ExtendableSparseMatrix{Tv,Ti}
    invdiag::Array{Tv,1}
    function ParallelJacobiPreconditioner{Tv,Ti}() where {Tv,Ti}
        p=new()
        p.invdiag=zeros(Tv,0)
        p
    end
end

function update!(precon::ParallelJacobiPreconditioner{Tv,Ti}) where {Tv,Ti}
    flush!(precon.A)
    cscmatrix=precon.A.cscmatrix
    if length(precon.invdiag)==0
        precon.invdiag=Array{Tv,1}(undef,cscmatrix.n)
    end
    invdiag=precon.invdiag
    n=cscmatrix.n
    Threads.@threads for i=1:n
        @inbounds  invdiag[i]=1.0/cscmatrix[i,i]
    end
    precon
end

"""
```
ParallelJacobiPreconditioner(;valuetype=Float64, indextype=Int64)
ParallelJacobiPreconditioner(matrix)
```

Parallel Jacobi preconditioner
"""
ParallelJacobiPreconditioner(;valuetype::Type=Float64, indextype::Type=Int64)=ParallelJacobiPreconditioner{valuetype,indextype}()

function  LinearAlgebra.ldiv!(u::AbstractArray{T,1} where T, precon::ParallelJacobiPreconditioner, v::AbstractArray{T,1} where T)
    invdiag=precon.invdiag
    n=length(invdiag)
    Threads.@threads for i=1:n
        @inbounds u[i]=invdiag[i]*v[i]
    end
end

function LinearAlgebra.ldiv!(precon::ParallelJacobiPreconditioner, v::AbstractArray{T,1} where T)
    ldiv!(v, precon, v)
end


text:
function process_arg!(srcs_used, dos_ex, ::Type{Select}, ex, index, primary)::Void
    res_field, value_ex = result_column(ex)
    f_ex, ai = build_f_ex!(srcs_used, value_ex, index, primary)
    push!(dos_ex.args,
          Expr(:call, Select, res_field, f_ex, ai))
    return
end


text:
@muladd function perform_step!(integrator,cache::EMConstantCache,f=integrator.f)
  @unpack t,dt,uprev,u,W,p = integrator

  K = uprev .+ dt .* integrator.f(uprev,p,t)

  if is_split_step(integrator.alg)
    u_choice = K
  else
    u_choice = uprev
  end

  if !is_diagonal_noise(integrator.sol.prob) || typeof(W.dW) <: Number
    noise = integrator.g(u_choice,p,t)*W.dW
  else
    noise = integrator.g(u_choice,p,t).*W.dW
  end

  u = K + noise
  integrator.u = u
end

@muladd function perform_step!(integrator,cache::EMCache,f=integrator.f)
  @unpack rtmp1,rtmp2 = cache
  @unpack t,dt,uprev,u,W,p = integrator
  integrator.f(rtmp1,uprev,p,t)

  @.. u = uprev + dt * rtmp1

  if is_split_step(integrator.alg)
    u_choice = u
  else
    u_choice = uprev
  end

  integrator.g(rtmp2,u_choice,p,t)

  if is_diagonal_noise(integrator.sol.prob)
    @.. rtmp2 *= W.dW
    @.. u += rtmp2
  else
    mul!(rtmp1,rtmp2,W.dW)
    @.. u += rtmp1
  end
end

@muladd function perform_step!(integrator,cache::EulerHeunConstantCache,f=integrator.f)
  @unpack t,dt,uprev,u,W,p = integrator
  ftmp = integrator.f(uprev,p,t)
  gtmp = integrator.g(uprev,p,t)
  if is_diagonal_noise(integrator.sol.prob)
    noise = gtmp.*W.dW
  else
    noise = gtmp*W.dW
  end
  tmp = @.. uprev + dt * ftmp + noise
  gtmp2 = (gtmp .+ integrator.g(tmp,p,t+dt)) ./ 2
  if is_diagonal_noise(integrator.sol.prob)
    noise2 = gtmp2.*W.dW
  else
    noise2 = gtmp2*W.dW
  end
  u = uprev .+ (dt / 2) .* (ftmp .+ integrator.f(tmp,p,t+dt)) .+ noise2
  integrator.u = u
end

@muladd function perform_step!(integrator,cache::EulerHeunCache,f=integrator.f)
  @unpack ftmp1,ftmp2,gtmp1,gtmp2,tmp,nrtmp = cache
  @unpack t,dt,uprev,u,W,p = integrator
  integrator.f(ftmp1,uprev,p,t)
  integrator.g(gtmp1,uprev,p,t)

  if is_diagonal_noise(integrator.sol.prob)
    @.. nrtmp=gtmp1*W.dW
  else
    mul!(nrtmp,gtmp1,W.dW)
  end

  @.. tmp = uprev + dt * ftmp1 + nrtmp

  integrator.f(ftmp2,tmp,p,t+dt)
  integrator.g(gtmp2,tmp,p,t+dt)

  if is_diagonal_noise(integrator.sol.prob)
    @.. nrtmp=(1/2)*W.dW*(gtmp1+gtmp2)
  else
    @.. gtmp1 = (1/2)*(gtmp1+gtmp2)
    mul!(nrtmp,gtmp1,W.dW)
  end

  dto2 = dt / 2
  @.. u = uprev + dto2 * (ftmp1 + ftmp2) + nrtmp
end

@muladd function perform_step!(integrator,cache::RandomEMConstantCache,f=integrator.f)
  @unpack t,dt,uprev,u,W,p = integrator
  u = uprev .+ dt .* integrator.f(uprev,p,t,W.curW)
  integrator.u = u
end

@muladd function perform_step!(integrator,cache::RandomEMCache,f=integrator.f)
  @unpack rtmp = cache
  @unpack t,dt,uprev,u,W,p = integrator
  integrator.f(rtmp,uprev,p,t,W.curW)
  @.. u = uprev + dt * rtmp
end

# weak approximation EM
@muladd function perform_step!(integrator,cache::SimplifiedEMConstantCache,f=integrator.f)
  @unpack t,dt,uprev,u,W,p = integrator

  K = uprev .+ dt .* integrator.f(uprev,p,t)

  _dW = map(x -> calc_twopoint_random(integrator, x),  W.dW)

  if !is_diagonal_noise(integrator.sol.prob) || typeof(W.dW) <: Number
    noise = integrator.g(uprev,p,t)*_dW
  else
    noise = integrator.g(uprev,p,t).*_dW
  end

  u = K + noise
  integrator.u = u
end

@muladd function perform_step!(integrator,cache::SimplifiedEMCache,f=integrator.f)
  @unpack rtmp1,rtmp2, _dW = cache
  @unpack t,dt,uprev,u,W,p = integrator

  integrator.f(rtmp1,uprev,p,t)

  @.. u = uprev + dt * rtmp1

  integrator.g(rtmp2,uprev,p,t)

  if typeof(W.dW) <: Union{SArray,Number}
    _dW = map(x -> calc_twopoint_random(integrator, x),  W.dW)
  else
    calc_twopoint_random!(_dW, integrator, W.dW)
  end

  if is_diagonal_noise(integrator.sol.prob)
    @.. rtmp2 *= _dW
    @.. u += rtmp2
  else
    mul!(rtmp1,rtmp2,_dW)
    @.. u += rtmp1
  end
end

@muladd function perform_step!(integrator,cache::RKMilConstantCache,f=integrator.f)
  @unpack t,dt,uprev,u,W,p = integrator
  du1 = integrator.f(uprev,p,t)
  K = @.. uprev + dt * du1
  L = integrator.g(uprev,p,t)
  mil_correction = zero(u)
  if alg_interpretation(integrator.alg) == :Ito
    utilde =  K + L*integrator.sqdt
    ggprime = (integrator.g(utilde,p,t).-L)./(integrator.sqdt)
    mil_correction = ggprime.*(W.dW.^2 .- dt)./2
  elseif alg_interpretation(integrator.alg) == :Stratonovich
    utilde = uprev + L*integrator.sqdt
    ggprime = (integrator.g(utilde,p,t).-L)./(integrator.sqdt)
    mil_correction = ggprime.*(W.dW.^2)./2
  end
  u = K+L.*W.dW+mil_correction
  if integrator.opts.adaptive
    du2 = integrator.f(K,p,t+dt)
    Ed = dt*(du2 - du1)/2
    En = W.dW.^3 .* ((du2-L)/(integrator.sqdt)).^2 / 6

    resids = calculate_residuals(Ed, En, uprev, u, integrator.opts.abstol,
                                 integrator.opts.reltol, integrator.opts.delta,
                                 integrator.opts.internalnorm, t)
    integrator.EEst = integrator.opts.internalnorm(resids, t)
  end
  integrator.u = u
end

#=
@muladd function perform_step!(integrator,cache::RKMilCache,f=integrator.f)
  @unpack du1,du2,K,tmp,L = cache
  @unpack t,dt,uprev,u,W,p = integrator
  integrator.f(du1,uprev,p,t)
  integrator.g(L,uprev,p,t)
  @.. K = uprev + dt * du1
  @.. tmp = K + integrator.sqdt * L
  integrator.g(du2,tmp,p,t)
  if alg_interpretation(integrator.alg) == :Ito
    @.. tmp = (du2-L)/(2integrator.sqdt)*(W.dW^2 - dt)
  elseif alg_interpretation(integrator.alg) == :Stratonovich
    @.. tmp = (du2-L)/(2integrator.sqdt)*(W.dW^2)
  end
  @.. u = K+L*W.dW + tmp
  if integrator.opts.adaptive
    @.. tmp = (tmp)/(integrator.opts.abstol + max(integrator.opts.internalnorm(uprev,t),integrator.opts.internalnorm(u,t))*integrator.opts.reltol)
    integrator.EEst = integrator.opts.internalnorm(tmp,t)
  end
  integrator.u = u
end
=#

@muladd function perform_step!(integrator,cache::RKMilCache,f=integrator.f)
  @unpack du1,du2,K,tmp,L = cache
  @unpack t,dt,uprev,u,W,p = integrator
  integrator.f(du1,uprev,p,t)
  integrator.g(L,uprev,p,t)
  @.. K = uprev + dt * du1
  @.. du2 = zero(eltype(u)) # This makes it safe to re-use the array
  if alg_interpretation(integrator.alg) == :Ito
    @.. tmp = K + integrator.sqdt * L
    integrator.g(du2,tmp,p,t)
    @.. tmp = (du2-L)/(2integrator.sqdt)*(W.dW.^2 - dt)
  elseif alg_interpretation(integrator.alg) == :Stratonovich
    @.. tmp = uprev + integrator.sqdt * L
    integrator.g(du2,tmp,p,t)
    @.. tmp = (du2-L)/(2integrator.sqdt)*(W.dW.^2)
  end
  @.. u = K+L*W.dW + tmp
  if integrator.opts.adaptive
    @.. tmp = integrator.opts.internalnorm(W.dW^3,t)*
             integrator.opts.internalnorm((du2-L)/(integrator.sqdt),t)^2 / 6
    integrator.f(du2,K,p,t+dt)
    @.. tmp += integrator.opts.internalnorm(integrator.opts.delta * dt * (du2 - du1)/2,t)

    calculate_residuals!(tmp, tmp, uprev, u, integrator.opts.abstol,
                         integrator.opts.reltol, integrator.opts.internalnorm, t)
    integrator.EEst = integrator.opts.internalnorm(tmp, t)
  end
end

@muladd function perform_step!(integrator,cache::RKMilCommuteCache,f=integrator.f)
  @unpack du1,du2,K,gtmp,L = cache
  @unpack t,dt,uprev,u,W,p = integrator
  @unpack WikJ,mil_correction,Kj,Dgj,tmp = cache
  dW = W.dW; sqdt = integrator.sqdt
  f = integrator.f; g = integrator.g

  ggprime_norm = 0.0

  @.. mil_correction = zero(u)
  if alg_interpretation(integrator.alg) == :Ito
    WikJ .= 0.5 .* (vec(dW) .* vec(dW)'  .- dt .* Eye{eltype(W.dW)}(length(W.dW)))
  else
    WikJ .= 0.5 .* vec(dW) .* vec(dW)'
  end

  integrator.f(du1,uprev,p,t)
  integrator.g(L,uprev,p,t)

  @.. K = uprev + dt*du1
  for j = 1:length(dW)
    @.. Kj = K + sqdt*@view(L[:,j]) # This works too
    #Kj .= uprev .+ sqdt*L[:,j]
    g(gtmp,Kj,p,t)
    @.. Dgj = (gtmp - L)/sqdt
    if integrator.opts.adaptive
        ggprime_norm += integrator.opts.internalnorm(Dgj,t)
    end
    mul!(tmp,Dgj,@view(WikJ[:,j]))
    mil_correction .+= tmp
  end
  mul!(tmp,L,dW)
  @.. u .= uprev + dt*du1 + tmp + mil_correction

  if integrator.opts.adaptive
      En = integrator.opts.internalnorm(W.dW,t)^3*ggprime_norm^2 / 6
      integrator.f(du2,K,p,t+dt)
      @.. tmp = integrator.opts.internalnorm(integrator.opts.delta * dt * (du2 - du1) / 2,t) + En

      calculate_residuals!(tmp, tmp, uprev, u, integrator.opts.abstol,
                           integrator.opts.reltol, integrator.opts.internalnorm, t)
      integrator.EEst = integrator.opts.internalnorm(tmp,t)

  end
end

@muladd function perform_step!(integrator,cache::RKMil_GeneralConstantCache,f=integrator.f)
  @unpack t,dt,uprev,u,W,p = integrator
  Wik = cache.WikJ
  dW = W.dW

  WikJ = get_iterated_I!(dt, dW, Wik, integrator.alg.c)

  if alg_interpretation(integrator.alg) == :Ito
    if typeof(dW) <: Number || is_diagonal_noise(integrator.sol.prob)
      WikJ = WikJ .- 1//2 .* dt
    else
      WikJ -= 1//2 .* dt .* Eye{eltype(dW)}(length(dW))
    end
  end

  du₁ = integrator.f(uprev,p,t)
  L = integrator.g(uprev,p,t)
  mil_correction = zero(u)
  ggprime_norm = zero(eltype(u)) #0
  # sqdt = integrator.sqdt

  if typeof(dW) <: Number || is_diagonal_noise(integrator.sol.prob)
    K = @.. uprev + dt*du₁
    utilde = (alg_interpretation(integrator.alg) == :Ito ? K : uprev) + L*integrator.sqdt
    ggprime = (integrator.g(utilde,p,t) .- L) ./ (integrator.sqdt)
    mil_correction = ggprime .* WikJ
    u = K + L .* dW + mil_correction
  else
    for i in 1:length(dW)
      K = uprev + dt*du₁ + integrator.sqdt*@view(L[:,i])
      gtmp = integrator.g(K,p,t)
      ggprime = @.. (gtmp - L)/integrator.sqdt
      ggprime_norm = zero(eltype(u))
      if integrator.opts.adaptive
        ggprime_norm += integrator.opts.internalnorm(ggprime, t)
      end
      mil_correction += ggprime*@view(WikJ[:,i])
    end
    if integrator.opts.adaptive
      K = @.. uprev + dt*du₁
      u = K + L*dW + mil_correction
    else
      u = uprev + dt*du₁ + L*dW + mil_correction
    end
  end

  if integrator.opts.adaptive
    du₂ = integrator.f(K,p,t+dt)
    if typeof(dW) <: Number || is_diagonal_noise(integrator.sol.prob)
      tmp  = dt*(du₂ -du₁)/2
      En = W.dW.^3 .* ((du₂-L)/(integrator.sqdt)).^2 / 6
    else
      En = integrator.opts.internalnorm(W.dW,t)^3*ggprime_norm^2 / 6
      tmp = integrator.opts.internalnorm((@.. dt*(du₂ - du₁)/2),t)
    end
    tmp = calculate_residuals(tmp, En, uprev, u, integrator.opts.abstol,
              integrator.opts.reltol, integrator.opts.delta, integrator.opts.internalnorm, t)
    integrator.EEst = integrator.opts.internalnorm(tmp, t)
  end
  integrator.u = u
end

@muladd function perform_step!(integrator,cache::RKMil_GeneralCache,f=integrator.f)
  @unpack du₁, du₂, K, tmp, ggprime, L, mil_correction = cache
  @unpack t,dt,uprev,u,W,p = integrator
  dW = W.dW;
  sqdt = integrator.sqdt
  Wik = cache.WikJ
  get_iterated_I!(dt, dW, Wik, integrator.alg.c)
  WikJ = Wik.WikJ

  integrator.f(du₁,uprev,p,t)
  integrator.g(L,uprev,p,t)
  @.. mil_correction = zero(eltype(u))
  ggprime_norm = zero(eltype(ggprime))

  if alg_interpretation(integrator.alg) == :Ito
    if typeof(dW) <: Number || is_diagonal_noise(integrator.sol.prob)
      @.. WikJ -= 1//2*dt
    else
      WikJ .-= 1//2 .* dt .* Eye{eltype(dW)}(length(dW))
    end
  end

  if typeof(dW) <: Number || is_diagonal_noise(integrator.sol.prob)
    @.. K = uprev + dt*du₁
    @.. du₂ = zero(eltype(u))
    tmp .= (alg_interpretation(integrator.alg) == :Ito ? K : uprev) .+ integrator.sqdt .* L
    integrator.g(du₂,tmp,p,t)
    @.. ggprime = (du₂ - L)/sqdt
    ggprime_norm = integrator.opts.internalnorm(ggprime,t)
    @.. u = K + L*dW + ggprime*WikJ
  else
    for i in 1:length(dW)
      @.. K = uprev + dt*du₁ + sqdt*@view(L[:,i])
      integrator.g(ggprime, K, p, t)
      @.. ggprime = (ggprime - L)/sqdt
      if integrator.opts.adaptive
        ggprime_norm += integrator.opts.internalnorm(ggprime,t)
      end
      mul!(tmp,ggprime,@view(WikJ[:,i]))
      @.. mil_correction += tmp
    end
    mul!(tmp,L,dW)
    if integrator.opts.adaptive
      @.. K = uprev + dt*du₁
      @.. u = K + tmp + mil_correction
    else
      @.. u = uprev + dt*du₁ + tmp + mil_correction
    end
  end

  if integrator.opts.adaptive
      En = integrator.opts.internalnorm(W.dW,t)^3*ggprime_norm^2 / 6
      integrator.f(du₂,K,p,t+dt)
      @.. tmp = integrator.opts.internalnorm(integrator.opts.delta * dt * (du₂ - du₁) / 2,t) + En

      calculate_residuals!(tmp, tmp, uprev, u, integrator.opts.abstol,
                           integrator.opts.reltol, integrator.opts.internalnorm, t)
      integrator.EEst = integrator.opts.internalnorm(tmp,t)
  end

  integrator.u = u
end


text:
export solveConvexMAP

"""
function solveConvexMAP

Find global MAP estimate using Gurobi

Input:

	1. param - StrainReconParam

Keyword arguments:

	2. pwr - exponent in the likelihood (must be 1.0 or 2.0)
	3. out - output flag for Gurobi solver
	4. tol - MIPGap tolerance parameter for Gurobi solver

Output:

	1. M      - estimated binary matrix
	2. w      - estimated frequency vector
    3. status - return code of the Gurobi solver
"""

function solveConvexMAP(param::StrainReconParam;pwr::Float64=param.pwr,out::Int=0,tol::Float64=1e-6)

    pwr = Int(pwr)

    m = param.m
    n = param.n
    p = param.p
    q = m*(p-1)
    d = param.d
    dRp = diag(param.R).^pwr

    model = Model(solver=GurobiSolver(OutputFlag=out,MIPGap=tol))
    @variable(model, 0 <= w[1:n] <=1)
    @variable(model, 0 <= W[1:q,1:n] <=1)
    @variable(model, 0 <= M[1:q,1:n] <=1,Int)
    if pwr == 1
        @variable(model, zplus[1:q] >= 0)
        @variable(model, zminus[1:q] >= 0)
    end

    @constraint(model,W.<=M)
    for k=1:n
        @constraint(model,W[:,k].<= w[k])
        @constraint(model,W[:,k].>= M[:,k] + w[k]-1)
    end
    for k=1:n-1
        @constraint(model,w[k]>=w[k+1])
    end
    @constraint(model, sum(w)==1)
    if pwr == 1
        @constraint(model, M*w-d .== zminus+zplus)
    end

    if p > 2
        for k=1:n
            for j=1:m
                @constraint(model, sum(M[(j-1)*(p-1)+1 : j*(p-1), k]) <= 1)
            end
        end
    end

    e = ones(n)

    if pwr == 2
        JuMP.setobjective(model,:Min, dRp'*(W*e-d).^2 );
    elseif pwr == 1
        JuMP.setobjective(model,:Min, dRp'*(zplus+zminus) );
    end

    status = solve(model)

    return BitArray(getvalue(M)), getvalue(w), status

end


text:
### OneToRange
Base.step(::OneToRange{T}) where {T} = one(T)

### AbstractStepRangeLen
Base.step(::StepSRangeLen{T,Tr,Ts,R,S,L,F}) where {T,Tr,Ts,R,S,L,F} = convert(T, S)
Base.step_hp(::StepSRangeLen{T,Tr,Ts,R,S}) where {T,Tr,Ts<:TwicePrecision,R,S} = convert(Ts, S)
Base.step_hp(::StepSRangeLen{T,Tr,Ts,R,S}) where {T,Tr,Ts,R,S} = S

Base.step_hp(r::StepMRangeLen) = getfield(r, :step)
Base.step(r::StepMRangeLen{T}) where {T} = T(step_hp(r))
Base.step(r::AbstractLinRange) = (last(r)-first(r)) / lendiv(r)

"stephi(x::AbstractStepRangeLen) - Returns the `hi` component of a twice precision step"
stephi(::StepSRangeLen{T,Tr,Ts,R,S}) where {T,Tr,Ts<:TwicePrecision,R,S} = gethi(S)
stephi(r::StepMRangeLen{T,R,S}) where {T,R,S<:TwicePrecision} = r.step.hi
stephi(r::StepRangeLen{T,R,S}) where {T,R,S<:TwicePrecision} = r.step.hi

"steplo(x::AbstractStepRangeLen) - Returns the `lo` component of a twice precision step"
steplo(::StepSRangeLen{T,Tr,Ts,R,S}) where {T,Tr,Ts<:TwicePrecision,R,S} = getlo(S)
steplo(r::StepMRangeLen{T,R,S}) where {T,R,S<:TwicePrecision} = r.step.lo
steplo(r::StepRangeLen{T,R,S}) where {T,R,S<:TwicePrecision} = r.step.lo

### AbstractStepRange
Base.step(r::StepSRange{T,Ts,F,S,L}) where {T,Ts,F,S,L} = S
Base.step(r::StepMRange) = getfield(r, :step)

"""
    has_step(x) -> Bool

Returns `true` if type of `x` has `step` method defined.
"""
has_step(::T) where {T} = has_step(T)
has_step(::Type{T}) where {T} = false
has_step(::Type{T}) where {T<:AbstractRange} = true

"""
    can_set_step(x) -> Bool

Returns `true` if type of `x` has `step` field that can be set.
"""
can_set_step(::T) where {T} = can_set_step(T)
can_set_step(::Type{T}) where {T} = false
can_set_step(::Type{T}) where {T<:StepMRange} = true
can_set_step(::Type{T}) where {T<:StepMRangeLen} = true

"""
    set_step!(x, st)

Sets the `step` of `x` to `val`.
"""
set_step!(x::UnitMRange, st) = error("Step size of UnitMRange type can only be 1.")
set_step!(x::OneToMRange, st) = error("Step size of OneToMRange type can only be 1.")
function set_step!(x::Union{StepMRange{T,S},StepMRangeLen{T,S}}, st) where {T,S}
    return set_step!(x, convert(S, st))
end
function set_step!(r::StepMRange{T,S}, st::S) where {T,S}
    setfield!(r, :step, st)
    setfield!(r, :stop, Base.steprange_last(first(r), st, last(r)))
    return r
end
function set_step!(r::StepMRangeLen{T,R,S}, st::S) where {T,R,S}
    setfield!(r, :step, st)
    return r
end


text:
const observables = [
    "Nuclear_NFkB"
]

function observables_index(observable_name::String)::Int

    return findfirst(isequal(observable_name),observables)
end

max_stars_repo_name: himoto/paramEstim

max_issues_repo_name: himoto/paramEstim


text:
#=
example3:
- Julia version:
- Author: Ashley Sommer
- Date: 2020-01-03

This example gets all the Calibration records for a given Cosmoz station
=#

using Printf
using JSON
using HTTP

const COSMOZ_API_URL = "https://esoil.io/cosmoz-data-pipeline/rest/"  # Keep the trailing slash on here.
const STATION_NUMBER = 21
# Endpoint to get a station's calibrations is "pipeline/rest/stations/{id}/calibration"
stations_endpoint = COSMOZ_API_URL * "stations"
station_endpoint = stations_endpoint * "/" * string(STATION_NUMBER)
station_cal_endpoint = station_endpoint * "/calibration"
# Add a header to specifically ask for JSON output
request_headers = Dict("Accept"=>"application/json",)
# Construct a GET request, with that URL and those headers
r = HTTP.request("GET", station_cal_endpoint, request_headers)
payload = JSON.parse(String(r.body))
println("Showing raw payload")
println(payload)
println()
count = payload["meta"]["count"]
println("Found $count calibrations for site $(string(STATION_NUMBER))")
for (i, c) in enumerate(payload["calibrations"])
    println("Calibration $i")
    for (k,v) in c
        println("\t$(string(k)): $(string(v))")
    end
end


text:
module VisualCircuits

# Implement math for two-tuples
import Base: +, -, *, /, getindex, connect
using Compose, Colors, Measures

include("TupleMath.jl")
include("core.jl")
export Block, IC

include("LogicGates.jl")
export Gate

include("BlockUtils.jl")
export connect, dots, render, autosize

end # module


text:
using ChainRulesCore
using ChainRulesTestUtils
using FiniteDifferences
using ITensors
using Random

#
# For ITensor compatibility with FiniteDifferences
#

function FiniteDifferences.to_vec(A::ITensor)
  # TODO: generalize to sparse tensors
  # TODO: define `itensor([1.0])` as well
  # as `itensor([1.0], ())` to help with generic code.
  function vec_to_ITensor(x)
    return isempty(inds(A)) ? ITensor(x[]) : itensor(x, inds(A))
  end
  return vec(array(A)), vec_to_ITensor
end

function FiniteDifferences.to_vec(x::Index)
  return (Bool[], _ -> x)
end

function FiniteDifferences.to_vec(x::Tuple{Vararg{Index}})
  return (Bool[], _ -> x)
end

function FiniteDifferences.to_vec(x::Pair{<:Tuple{Vararg{Index}},<:Tuple{Vararg{Index}}})
  return (Bool[], _ -> x)
end

function ChainRulesTestUtils.rand_tangent(rng::AbstractRNG, A::ITensor)
  # TODO: generalize to sparse tensors
  return isempty(inds(A)) ? ITensor(randn(eltype(A))) : randomITensor(eltype(A), inds(A))
end

function ChainRulesTestUtils.rand_tangent(rng::AbstractRNG, x::Index)
  return NoTangent()
end

function ChainRulesTestUtils.rand_tangent(rng::AbstractRNG, x::Tuple{Vararg{Index}})
  return NoTangent()
end

function ChainRulesTestUtils.rand_tangent(
  rng::AbstractRNG, x::Pair{<:Tuple{Vararg{Index}},<:Tuple{Vararg{Index}}}
)
  return NoTangent()
end