Skip to content

Instantly share code, notes, and snippets.

'
' #DEBUG ERROR ON
' (If you "uncomment" the statement above, don't forget to un-comment the "ON ERROR GOTO...")
'
' Changed RotRec to 1000 - May 28, 2011 (Teams to keep track of for Pitching Rotations)
' Changed RotRec to 1500 - June 4, 2011
' Changed WLRec to 1500 - June 4, 2011 (Teams to keep track of in Standings)
' If more than 300 teams involved, user needs to use STAT-TEAM-LIMIT= in .CMD
'
'
@pqnelson
pqnelson / neural-network.clj
Created July 27, 2015 00:02
A simple linear-threshold neural network, with an XOR neural net factory.
(ns user.neural-network
(:import [java.lang.reflect Array]))
;; So far, this handles linear threshold nodes, specifically examining
;; Minsky and Papert's XOR dilemma. The make-xor-network is a factory function
;; which produces such a network.
;;
;; It's fairly optimized, using deftypes and whatnot. One could add an
;; activation function for further generality, or add a logistic function
;; and add some training routines to further improve things.
@pqnelson
pqnelson / half_inning.clj
Last active August 29, 2015 14:24
Expected runs for number of successful plays in a half-inning
(ns half-inning)
(defn- int->play [i]
(let [i (mod i 5)]
(condp = i
0 :BB
1 :H1
2 :H2
3 :H3
4 :HR)))

Tuning JVM GC for a big, mathy, STMful Clojure app

by Bryce Nyeggen

As part of my “real job”, I’m developing a Clojure-based app that does a significant amount of number crunching. The inner loop continuously ref-sets random portions of a large array of refs (when I say “large”, I mean that I can plausibly fire off a 50gb heap). I had a tough time getting it performant, and it’s an interesting enough story that I thought I’d relate it here.

After the standard futzing with algorithms and data structures, the thing that ended up holding me back was excessive time in GC. I started with the “throughput” collector (hey, I’m doing number crunching, I don’t have real-time requirements, throughput is awesome!). Somewhat surprisingly, I saw worse and worse performance as my app ran, ending in a kind of sawtoothed purgatory of GC. What little information I found about Clojure-specific GC tuning uniformly showed using the CMS / low-latency / concurrent collector as a good choice. Cu

@q This file defines standard C++ namespaces and classes @>
@q Please send corrections to saroj-tamasa@@worldnet.att.net @>
@s std int
@s rel_ops int
@s bitset int
@s char_traits int
@s deque int
@s list int
@s map int
@pqnelson
pqnelson / fcmp.d
Last active August 29, 2015 14:19
Floating Point Comparison Helpers
import std.math;
// based on http://fcmp.sourceforge.net/
immutable real sqrtEpsilon = sqrt(real.epsilon); /* on x86, about 3.29272253991359623327e-10 */
int floatCompare(real x1, real x2, real epsilon = sqrtEpsilon) {
int exponent;
real delta;
real difference;
@pqnelson
pqnelson / sproof.sty
Last active November 28, 2015 22:44
Structured Proof Style
%% This is an attempt at making Leslie Lamport's structured proof macros
%% more accessible, compatible with amsmath macros, and more "free form"
%% (so a \step in a proof is more like an \item in a list).
%%
%% Example usage:
%%
%% \begin{spf}
%% \Assume $\sqrt{2}\in\mathbb{Q}$ (for contradiction).
%% \Consider $m,n\in\mathbb{Z}$ such that
%% \begin{equation}
@pqnelson
pqnelson / biology.md
Last active December 10, 2019 20:22
Reading List

Everything biology related...

Biology

  • Hernan G. Garcia, Jané Kondev, Nigel Orme, Julie A. Theriot, Rob Phillips, "A First Exposure to Statistical Mechanics for Life Scientists". arXiv:0708.1899
  • Alex H. Lang, Charles K. Fisher, Thierry Mora, Pankaj Mehta, "Thermodynamics of statistical inference by cells". arXiv:1405.4001
@pqnelson
pqnelson / automated-thm-todo.md
Last active June 13, 2020 20:51
Running To Do List

Theorem Prover Coding/Writing

  • Fix typos in my notes on DPLL
    • Fixing the getLiterals code snippet to match the code
  • Rewrite notes on DP algorithm after examining Knuth's drafts more thoroughly
    • Clearly explain the DP & DPLL algorithms in pseudocode
    • Clearly explain the backjumping optimization
      • Is it possible to do a more thorough algorithmic analysis of it? (I.e., do a better job!)
  • Explore possibility that monads can be used for backjumping?
  • Resolution space for random 3-SAT proves "with high probability" that "the total resolution space is quadratic".
% a simple lewis diagram of a phospholipid
numeric u;
u = 1pc;
beginfig(0)
% hydrophilic head
label(btex ${\rm CH}_{2}$ etex, (0,0));
draw (u, 0)--(1.75u,0);
label(btex ${\rm CH}$ etex, (2.5u, 0));
draw (3.25u, 0)--(4u, 0);