Skip to content

Instantly share code, notes, and snippets.

@cossio
cossio / midpoint.jl
Created November 6, 2018 22:03
midpoint of interval
"""midpoint of the interval [a,b]"""
function midpoint(a::Float64, b::Float64)
#= Based on F. Goualard. 2014, Table VII
DOI: 10.1145/2493882 =#
if !(a ≤ b)
return NaN
elseif a == -Inf
if b == Inf
return 0.
(Proj) pkg> rm Sp┌ Error: Error in the keymap
│ exception =
│ type Nothing has no field ver
│ Stacktrace:
│ [1] getproperty(::Any, ::Symbol) at ./sysimg.jl:18
│ [2] __installed(::Pkg.Types.PackageMode) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Pkg/src/API.jl:284
│ [3] complete_installed_package at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Pkg/src/REPLMode.jl:773 [inlined]
│ [4] complete_argument(::String, ::Int64, ::Int64, ::Pkg.REPLMode.CommandKind, ::Bool) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Pkg/src/REPLMode.jl:821
│ [5] completions(::String, ::Int64) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Pkg/src/REPLMode.jl:853
│ [6] complete_line(::Pkg.REPLMode.PkgCompletionProvider, ::REPL.LineEdit.PromptState) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Pkg/src/REPLMode.jl:761
@cossio
cossio / orphaned_procs.sh
Last active November 23, 2018 19:49
To find the list of processes with PPID = 1.
pgrep -P 1 -u cossio # lists the PID of processes with PPID = 1
pgrep -P 1 -u cossio | xargs ps -p # prints the PID and some more info
pgrep -P 1 -u cossio -f julia | xargs ps -o pid,ppid,command -p # print orphaned julia procs
pgrep -P 1 -u cossio -f julia | xargs kill # kill them
@cossio
cossio / checked.jl
Last active January 14, 2020 13:53
Checks for type stability the first time a function is called with a type signature.
macro checked(fdef)
d = splitdef(fdef)
f = d[:name]
args = d[:args]
whereparams = d[:whereparams]
d[:name] = gensym()
shadow_fdef = combinedef(d)
M = __module__
@cossio
cossio / undropdims.jl
Created May 4, 2020 14:30
undropdims: type stable inverse of dropdims
function mix_dims(dims1, dims2, t)
if in(t[1], dims2)
return (1, mix_dims(dims1, Base.tail(dims2), Base.tail(t))...)
else
return (dims1[1], mix_dims(Base.tail(dims1), dims2, Base.tail(t))...)
end
end
function mix_dims(dims1, dims2, t::Tuple{})
return ()
end
#= reparameterized truncated normal =#
using Random
using Zygote, Distributions, Plots, SpecialFunctions
import Zygote: @adjoint, Numeric
import Base.Broadcast: broadcasted
"""
ndtr(a)
# Rejection sampler based on algorithm from Robert (1995)
#
# - Available at http://arxiv.org/abs/0907.4010
#
# Copied this implementation from Distributions.jl, with few modifications
# to make it generic.
using Random, Statistics
Δ2(x, y) = (x - y) * (x + y)
@cossio
cossio / erfcx.nb
Created May 23, 2020 01:30
Scaled complementary error function, erfcx(x), in Mathematica
Erfcx[x_] := 2/Sqrt[Pi] HermiteH[-1, x]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-dc0f2ac96f27> in <module>
15 RBM.fit(all_data[in_train][order_train], weights= all_weights[in_train][order_train], batch_size = batch_size,
16 n_iter = n_iter, l1b = l1b, N_MC = N_MC,
---> 17 decay_after = decay_after, verbose = 0,vverbose=1 )
~/work/PGM/source/rbm.py in fit(self, data, batch_size, learning_rate, extra_params, init, optimizer, batch_norm, CD, N_PT, N_MC, nchains, n_iter, MoI, MoI_h, MoI_tau, PTv, PTh, interpolate_z, degree_interpolate_z, zero_track_RBM, only_sampling, lr_decay, lr_final, decay_after, l1, l1b, l1c, l2, l2_fields, reg_delta, no_fields, weights, adapt_PT, AR_min, adapt_MC, tau_max, update_every, N_PT_max, N_MC_max, from_hidden, learning_rate_multiplier, update_betas, record_acceptance, shuffle_data, epsilon, verbose, vverbose, record, record_interval, data_test, weights_test, l1_custom, l1b_cust
@cossio
cossio / mylog_rrule.jl
Created October 1, 2021 11:56
Testing rrules
using ChainRulesCore, ChainRulesTestUtils, Test
function mylog(x::Real)
r = log(abs(x))
if x > 0
return r
else
return oftype(r, -Inf)
end
end