Skip to content

Instantly share code, notes, and snippets.

View whilo's full-sized avatar

Christian Weilbach whilo

View GitHub Profile
(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)]
@whilo
whilo / antidote.clj
Last active July 14, 2017 17:28
Antidote Clojure Playground
(ns clj-antidote.core
(:import [eu.antidotedb.client AntidoteClient Host
BatchRead BatchReadResult Bucket CounterRef
InteractiveTransaction SetRef]))
(def client (AntidoteClient. [(Host. "localhost" 8087)]))
(def bucket (Bucket/create "testbucket"))
(ns datanaive.core)
;; https://courses.cs.washington.edu/courses/cse544/16au/lectures/lecture05-datalog.pdf
;; slide 7
;; Actor(344759,‘Douglas’, ‘ Fowley ’).
;; Casts(344759, 29851).
;; Casts(355713, 29000).
;; Movie(7909, ‘A Night in Armour ’, 1910).