Skip to content

Instantly share code, notes, and snippets.

@genmeblog
genmeblog / core.clj
Last active May 18, 2023 14:52
Matrix ops comparison
(ns matrix-comp.core)
(require '[clojure.math :refer (sqrt)])
(require '[clojure.core.matrix :refer (matrix mget add mul inverse det set-current-implementation dot mmul eseq)])
(require '[clojure.core.matrix.linear :refer (norm)])
(require '[criterium.core :refer :all])
(require '[fastmath.matrix :as fm])
(require '[fastmath.vector :as fv])
(import '[mikera.matrixx Matrix Matrixx])
(import '[mikera.vectorz Vector])
@genmeblog
genmeblog / init.el
Last active May 27, 2022 07:32
Emacs config
;;
(setq gc-cons-threshold 10000000)
;; Restore after startup
(add-hook 'after-init-hook
(lambda ()
(setq gc-cons-threshold 1000000)
(message "gc-cons-threshold restored to %S"
gc-cons-threshold)))
@genmeblog
genmeblog / init.el
Last active March 29, 2022 14:47
Emacs config
;;
(setq gc-cons-threshold 10000000)
;; Restore after startup
(add-hook 'after-init-hook
(lambda ()
(setq gc-cons-threshold 1000000)
(message "gc-cons-threshold restored to %S"
gc-cons-threshold)))
@genmeblog
genmeblog / select_by_index.clj
Last active March 21, 2021 18:39
Using TreeMap index to subselect datasets
(require '[clojure.set]
'[tablecloth.api :as api])
(defprotocol IndexProto
(slice-idx [idx ks] [idx from to] [idx from from-inclusive? to to-inclusive?]
"Slice by keys or range")
(select-by-idx [idx ks] [idx from to]
"Select by keys or range"))
;; TreeMap as an index
@genmeblog
genmeblog / format_sequence.clj
Last active June 18, 2020 09:56
Format sequence of doubles to seq of aligned strings
(ns format-sequence
"Format sequence of doubles"
(:require [clojure.pprint :refer [cl-format]]
[clojure.test :refer [deftest is]]))
(set! *warn-on-reflection* true)
(set! *unchecked-math* :warn-on-boxed)
;; maximum double power for precise calculations
(def ^:private ^:const ^long kp-max 22)
@genmeblog
genmeblog / testing_dataset.clj
Last active April 22, 2020 18:05
tech.ml.dataset in action (compared to R data.table) ---> https://github.com/genmeblog/techtest/blob/master/src/techtest/core.clj
;; MOVED! https://github.com/genmeblog/techtest/blob/master/src/techtest/core.clj
(ns testing.dataset
(:require [tech.ml.dataset :as ds]
[tech.ml.dataset.column :as col]
[tech.v2.datatype.functional :as dfn]))
;; Working thrugh R `data.table` type and confronting with tech.ml.dataset
;; https://cran.r-project.org/web/packages/data.table/vignettes/datatable-intro.html
@genmeblog
genmeblog / tablesaw_test.clj
Created March 6, 2020 11:43
Tablesaw join test
(ns tablesaw-test
(:import [tech.tablesaw.io.csv CsvReadOptions CsvReader]))
(def ^CsvReader csv-reader (CsvReader.))
(defn load-csv-data
([file] (load-csv-data file nil))
([^String file {:keys [separator line-ending header?]
:or {separator \, line-ending "\n" header? true}}]
(let [builder (doto (CsvReadOptions/builder file)
@genmeblog
genmeblog / temperature.clj
Created November 19, 2019 15:37
Black body temperature to color converter
;; Better interpolation functions for calculating temperature colors
;; Reference: http://www.zombieprototypes.com/?p=210
;; Data: http://www.vendian.org/mncharity/dir3/blackbody/UnstableURLs/bbr_color.html
;; use fastmath and clojure2d libraries
(ns black-body.temperature
(:require [fastmath.core :as m]
[fastmath.interpolation :as i]
@genmeblog
genmeblog / gff.pde
Last active October 15, 2019 09:55
Gaussian Free Field
int gffSize = 30; // field density
int rays = 150;
float rsteps = TWO_PI / rays;
float[][] gff;
void setup() {
size(800,800);
smooth(8);
noStroke();
fill(235);
@genmeblog
genmeblog / popcorn_vf.pde
Last active September 3, 2018 20:32
Popcorn over vector fields
ArrayList<PVector> points = new ArrayList<PVector>();
float step = random(0.01, 0.05); // random step
Folds vector_field = new Folds(); // random vector field
float noise_scale = random(-2,2); // noise scaler
void setup() {
size(600, 600);
noStroke();
smooth(8);