Skip to content

Instantly share code, notes, and snippets.

View whilo's full-sized avatar

Christian Weilbach whilo

View GitHub Profile

Contributor License Agreement

By clicking "I agree" below, You agree to the following terms for Your Contributions to this Project:

Grant of Rights:

You grant a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable license to:

  • Reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions
  • Distribute Your Contributions under the Apache License 2.0
  • Distribute Your Contributions under commercial license terms
"""
Toy Free‑Form Flow (FFF) training demo on a 2D mixture of Gaussians.
Requires:
pip install matplotlib
pip install -e third_party/FFF
"""
import torch
from torch import optim
from torch.utils.data import DataLoader, Dataset
(ns types.datahike-unify
(:require [datahike.api :as d]))
;; Schema Definition
(def schema
[{:db/ident :type/const
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :type/type-app
:db/valueType :db.type/ref
@whilo
whilo / openai.clj
Last active March 17, 2024 02:59
OpenAI calls from Clojure
(ns openai.example
(:require [clojure.java.io :as io]
[libpython-clj2.require :refer [require-python]]
[libpython-clj2.python :refer [py. py.. py.-] :as py]
[taoensso.timbre :as log]))
(require-python '[openai :refer [OpenAI]])
(def client (OpenAI :api_key "..."))
@whilo
whilo / cnf_playground.jl
Last active April 17, 2019 23:20
CNF playground with nested Jacobian not working.
using DifferentialEquations
using Distributions
using Flux, DiffEqFlux
using Flux.Tracker
function f(z, p)
α, β = p
tanh.(α.*z .+ β)
end
@whilo
whilo / forward.clj
Created July 13, 2018 22:45
forward autodiff experiments
(ns autodiff.forward
"Experiments for forward differentiation.")
;; Alternative idea: encode tabular SSA structure of Griewank chapter 3.1
;; Questions:
;; what SSA representation is good to implement compiler optimizations?
@whilo
whilo / anglican_experiment.clj
Created June 6, 2018 12:23
Klipse Anglican experiment.
(ns anglican.runtime$macros
"Runtime library"
(:require [clojure.string :as str]
[clojure.core.matrix :as m]
[clojure.core.matrix.linear :as ml]
[anglican.runtime :refer [distribution]]
#?(:cljs [goog.string.format]))
)
@whilo
whilo / trans_stm.clj
Created April 5, 2018 00:16
Clojure STM example
(def accounts
(into {} (for [i (range 1000001)]
[i (ref 1000)])))
(time
(let [fs (dotimes [offset 10]
(future
(doseq [i (shuffle (range (* offset 100000)
(* (inc offset) 100000)))]
(dosync
@whilo
whilo / sghmc.py
Created August 28, 2017 20:19
SGHMC port from matlab.
import torch
import torch.nn.functional as F
import torch.autograd as autograd
import torch.optim as optim
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import os
import math
from torch.autograd import Variable
(let [f (fn [args]
(let [w1 (nth args 0)
w2 (nth args 1)
x (nth args 2)
y (nth args 3)
h1 (mmul w1 x)
h2 (mmul w2 h1)
;; TODO dot with vector of ones yields sum
;; this is euclidian distance or squared error
error (** (- (dot [1 1] h2) y) 2)]