Skip to content

Instantly share code, notes, and snippets.

View lukego's full-sized avatar

Luke Gorrie lukego

View GitHub Profile
@lukego
lukego / uct.lisp
Created September 27, 2021 15:32
UCT Monte Carlo Tree Search in Lisp
;;; UCT Monte Carlo Tree Search
(defpackage :uct
(:use :common-lisp :alexandria :serapeum)
(:import-from :nuddy #:⊥))
(in-package :uct)
(defstruct search-tree
(mode :tree :type (member :tree :playout))
@lukego
lukego / bo.lisp
Last active September 28, 2021 09:48
Bayesian Optimization
(defpackage bo
(:use :common-lisp :alexandria :serapeum :trivia))
(in-package :bo)
;;;; Bayesian Optimization based on Tree-structured Parzen Estimator and naive-Bayes.
;;;
;;; based on Rust code at https://docs.rs/tpe/0.1.1/tpe/
;;; which is inspired by https://optuna.org/
;;; which is inspired by http://hyperopt.github.io/hyperopt/
;;; which is described in https://proceedings.neurips.cc/paper/2011/file/86e8f7ab32cfd12577bc2619bc635690-Paper.pdf
@lukego
lukego / sbperf.lisp
Last active September 21, 2021 10:36
Linux perf jitdump generator for SBCL (not debugged)
;;; SBCL integration with Linxu perf jitdump interface
(defpackage :sbperf
(:use :common-lisp))
(in-package :sbperf)
;;;; perf map
(defun write-perfmap ()
@lukego
lukego / defwrappers.lisp
Last active September 19, 2021 12:44
DEFWRAPPERS for typed math
;;;; Double float math
(defparameter *standard-operators*
'(+ - * / 1+ 1- exp expt log sqrt abs
sin cos tan cis asin acos
atan sinh cosh tanh asinh acosh atanh))
(defmacro defwrappers (type prefix &optional (operators *standard-operators*))
"Define TYPE-specific macros for OPERATORS named with PREFIX.
The prefixed operators coerce all values (operands and results) to TYPE."
(defmacro def.wrapper (f args)
"Make (.F ARGS...) a double-float version of (F ARGS...)."
(flet ((coercer (x) `(coerce ,x 'double-float)))
`(defun ,(symbolicate "." f) ,args
,(coercer `(,f ,@(mapcar #'coercer args))))))
(def.wrapper + (x y))
==>
(DEFUN .+ (X Y)
(COERCE (+ (COERCE X 'DOUBLE-FLOAT) (COERCE Y 'DOUBLE-FLOAT)) 'DOUBLE-FLOAT))
@lukego
lukego / sb-sprof.txt
Created September 19, 2021 09:37
sb-sprof no samples
BO> (sb-sprof:reset)
; No value
BO> (sb-sprof:with-sampling ()
(time (hyper-test :n 400)))
Evaluation took:
5.349 seconds of real time
5.552335 seconds of total run time (5.392896 user, 0.159439 system)
[ Run times consist of 0.644 seconds GC time, and 4.909 seconds non-GC time. ]
103.80% CPU
10,657,575,260 processor cycles
# This file is machine generated. Do not edit it!
{ fetchurl }:
let
qlReleases =
{
"1am" = {
archive = fetchurl {
url = "http://beta.quicklisp.org/archive/1am/2014-11-06/1am-20141106-git.tgz";
sha256 = "0vnnqd4fiq9z34i1k9gqczg3j6xllwba1f6nx0b82sgsdccmsly6";
};
#! /usr/bin/env nix-shell
#! nix-shell bootstrap.nix --run generate
# This script uses ql2nix to generate dependency definitions as Nix
# expressions in the current directory. Quicklisp and all packages are
# installed in a temporary directory.
# Quicklisp packages default root set.
let default-packages = [
"1am"
@lukego
lukego / sbcl-casify.diff
Created September 5, 2021 09:23
sbcl casify diff
diff --git a/src/code/print.lisp b/src/code/print.lisp
index 92fbb3e76..be4e0037d 100644
--- a/src/code/print.lisp
+++ b/src/code/print.lisp
@@ -568,8 +568,8 @@ variable: an unreadable object representing the error is printed instead.")
code (char-code current)
bits (cond ; FIXME
((< code 160) (aref attributes code))
- ((upper-case-p current) uppercase-attribute)
- ((lower-case-p current) lowercase-attribute)
(defparameter *brackets*
"()[]{}⦅⦆⦅⦆〚〛⦃⦄⟦⟧⟨⟩⟪⟫⟮⟯⟬⟭⌈⌉⌊⌋⦇⦈⦉⦊❨❩❪❫❴❵❬❭❮❯❰❱❲❳〈〉⦑⦒⧼⧽")
(loop for i from 0 below (length *brackets*) by 2
for open = (elt *brackets* i)
for close = (elt *brackets* (1+ i))
do (format t "~&pairing ~a with ~a~%" open close)
do (set-syntax-from-char close #\))
do (set-macro-character close (get-macro-character #\)) nil)
do (set-macro-character open