Skip to content

Instantly share code, notes, and snippets.

View mschauer's full-sized avatar

Moritz Schauer mschauer

View GitHub Profile
import Base.Random.rand
immutable RandIntGen2{T<:Integer, U<:Unsigned}
a::T # first element of the range
k::U # range length
u::U # maximum multiple of k within the domain of U
RandIntGen2(a::T, k::U) = new(a, k, div(typemax(U),k)*k)
RandIntGen2(a::Uint64, k::Uint64) = new(a, k, div(( k >> 32 != 0)*0xFFFFFFFF00000000 + 0x00000000FFFFFFFF ,k)*k )
RandIntGen2(a::Int64, k::Int64) = new(a, k, div(( k >> 32 != 0)*0xFFFFFFFF00000000 + 0x00000000FFFFFFFF ,k)*k )
@mschauer
mschauer / ft.jl
Last active August 29, 2015 13:56
Hangs if call to consr gets uncommented
abstract FingerTree{T}
immutable Node23{T}
child::NTuple{Any, T}
end
Node23{T}(a::T...) = Node23{T}(a)
immutable DeepFT{T} <: FingerTree{T}
left::NTuple{Any, T}
succ::Union(FingerTree{Node23{T}},(),Node23{T})
@mschauer
mschauer / lyap.jl
Created June 27, 2014 09:59
Lyapunov equation and xtrsyl wrapper
using Base.LinAlg.LAPACK
import Base.LinAlg: BlasFloat, BlasChar, BlasInt, LAPACK.liblapack, LAPACK.@assertargsok, LAPACK.chkstride1
for (fn, elty) in ((:dtrsyl_, :Float64),
(:strsyl_, :Float32),
(:ztrsyl_, :Complex128),
(:ctrsyl_, :Complex64))
@eval begin
function trsyl!(transa::BlasChar, transb::BlasChar, A::StridedMatrix{$elty}, B::StridedMatrix{$elty}, C::StridedMatrix{$elty}, isgn::BlasInt=1)
@mschauer
mschauer / Kalman.jl
Last active May 4, 2021 11:52
Kalman filter, Rauch-Tung-Striebel smoother and parameter estimation with EM procedure for the state space model (Shumway, Stoffer)
module Kalman
using Distributions
export LinearDS, generate, kalmanfilter, kalmanfilter!, kalmanrts, kalmanrts!, kalmanEM, randmvn
"""
Sampling singular semidefinite multivariate normal distributions
x = randmvn(S)
@mschauer
mschauer / ring.jl
Last active August 29, 2015 14:20
Shape preservation for blocked cholesky
import Base: ctranspose, *, -, *, \, zero, showlimited, print, show, writemime, showcompact, showcompact_lim, inv, one
import Base.display
import Base.LinAlg.chol!
import Base.LinAlg.chol
const Dadd = Dict(
('L','L') => 'L',
('U','U') => 'U',
('L','U') => 'A',
@mschauer
mschauer / pr.md
Last active September 2, 2015 08:49 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@mschauer
mschauer / expm3
Created September 3, 2015 06:41
computes exp(t a), a a 3x3 double matrix
int expm3(double t, double *a, double *aa, double X[3], double dis)
/*
computes exp(t a)
input
t double
a 3x3 double matrix
aa a*a
@mschauer
mschauer / bracketcalculus.md
Last active January 13, 2016 19:41
Bracket calculus

Bracket calculus

This formalizes a bit an indexing calculus with brackets which incorporates array construction, array comprehension, slicing and mapping of arrays. Note: ... is the splatting operator and is etcetera.

Guiding principles

1.[…] or T[…] is a shape preserving array construction operator (T a type)

2.f[…] respective A[…] is a map or array indexing operator (A an array, f a function)

@mschauer
mschauer / iter.md
Last active October 5, 2016 21:23
Iterator traits

Iterator traits

In julia version 0.5 there are some changes how iterators are used in julia. The julia iteration protocol based on the methods start, size, next was already used in an intermediate step in the process of translating the general for syntax

    for elem in iter
        # do something
    end
@mschauer
mschauer / gamma.jl
Created June 29, 2017 13:22
gamma.jl
abstract type LevyProcess{T} <: ContinuousTimeProcess{T} end
"""
GammaProcess
A *GammaProcess* with jump rate `γ` and inverse jump size `λ` has increments `Gamma(t*γ, 1/λ)` and Levy measure
```math
ν(x)=γ x^{-1}\\exp(-λ x),