Skip to content

Instantly share code, notes, and snippets.

View rversteegen's full-sized avatar

Ralph Versteegen rversteegen

View GitHub Profile
@rversteegen
rversteegen / x87_64bit_mode.c
Created January 17, 2021 23:02
Code snippet to put the x87 FPU into double precision mode for portability
/////////////////////// Put x87 FPU in double-precision mode //////////////////
// For cross-platform portability, force x87 floating-point calculations to be
// done with intermediate results stored in double precision (53 bit mantissa)
// instead of extended double precision (64 bit mantissa) registers. We change
// the x87 control register to accomplish this. But it only affects the
// mantissa, not the exponent, so does not remove all inconsistencies.
//
// See http://yosefk.com/blog/consistency-how-to-defeat-the-purpose-of-ieee-floating-point.html
// and http://christian-seiler.de/projekte/fpmath/
@rversteegen
rversteegen / KunzEgg.py
Created December 9, 2022 12:53
KunzEgg's Forward-Forward example in numpy
# using the Forward-Forward algorithm to train a neural network to classify positive and negative data
# the positive data is real data and the negative data is generated by the network itself
# the network is trained to have high goodness for positive data and low goodness for negative data
# the goodness is measured by the sum of the squared activities in a layer
# the network is trained to correctly classify input vectors as positive data or negative data
# the probability that an input vector is positive is given by applying the logistic function, σ to the goodness, minus some threshold, θ
# the negative data may be predicted by the neural net using top-down connections, or it may be supplied externally
import numpy as np
@rversteegen
rversteegen / grub_linux_manual.py
Created July 19, 2023 00:08
My GRUB linux boot entry generation script
#!/usr/bin/env python3
#exec tail -n +3 $0
# Be careful not to change
# the 'exec tail' line above.
# This script lives in /etc/grub.d/
# 2015,2022 Ralph Versteegen
# The menuentry template was orginally generated by /etc/grub.d/10_linux