Skip to content

Instantly share code, notes, and snippets.

View sdewaele's full-sized avatar

Stijn de Waele sdewaele

View GitHub Profile
@sdewaele
sdewaele / expm.jl
Last active February 28, 2019 16:30 — forked from matthiasschabel/expm.jl
Julia translation of MATLAB expm function (matrix exponential) and test code in Julia and MATLAB
using LinearAlgebra
import Base.exp
import LinearAlgebra.exp!
function expmchk()
# EXPMCHK Check the class of input A and
# initialize M_VALS and THETA accordingly.
m_vals = [3 5 7 9 13];
# theta_m for m=1:13.
theta = [#3.650024139523051e-008
@sdewaele
sdewaele / getindex-zygote.jl
Last active January 25, 2020 12:42
setindex with copy to enable Zygote autodiff
using ZygoteRules:@adjoint
using Zygote
using Random
function ngradient(f, xs::AbstractArray...)
grads = zero.(xs)
for (x, Δ) in zip(xs, grads), i in 1:length(x)
δ = sqrt(eps())
tmp = x[i]
x[i] = tmp - δ/2
@sdewaele
sdewaele / zscore-transform.jl
Last active November 26, 2020 21:05
Generic StatsBase.ZScoreTransform
using CUDA
using StatsBase
import StatsBase: fit, transform!, reconstruct!, mean_and_std
"""
Standardization (Z-score transformation)
"""
struct ZScoreTransformGeneric{T<:Real,U<:AbstractVector{T}} <: AbstractDataTransform
len::Int
dims::Int