Skip to content

Instantly share code, notes, and snippets.

View jparkhill's full-sized avatar

John Parkhill jparkhill

View GitHub Profile
@jparkhill
jparkhill / gist:b16e3c0055b9dd29146d9c4300f5a7d3
Created July 10, 2019 23:19
Kelly Sizing Optimizer for Monte Carlo Samples in Pytorch
def kelly_loss(c_assets, r_assets, spreads, spread_loss):
"""
Maximizes exponential rate of wealth growth
NOTE: the samples must be in the same order.
the assumption is that the returns are realized
in the same way.
Args:
// Do a shifted/scaled fourier transform of polarization in each direction.
mat Fourier(const mat& pol, double zoom = 1.0/20.0, int axis=0, bool dering=true) const
{
cout << "Computing Fourier Transform ..." << endl;
mat tore;
double dt = pol(3,0)-pol(2,0);
{
int ndata = (pol.n_rows%2==0)? pol.n_rows : pol.n_rows-1; // Keep an even amount of data
for (int r=1; r<ndata; ++r)
@jparkhill
jparkhill / gist:3dab42ce495a44298d5bcf4f686c2dde
Created March 7, 2021 23:29
Slerp for quaternions in TF
def slerp(v0, v1, t=0.05):
"""
Interpolate between quaternions v0 and v1.
"""
v0 = safe_normalize(v0)
v1 = safe_normalize(v1)
dot = tf.reduce_sum(v0*v1,axis=-1,keepdims=True)
# If the dot product is negative, slerp won't take
# the shorter path. Note that v1 and -v1 are equivalent when
# the negation is applied to all four components. Fix by
@jparkhill
jparkhill / phonecase
Created March 9, 2021 16:24
phone holder
// ****************************************************************************
// Customizable Smartphone Holders
// to mount your smartphone to a tripod or elsewhere using an action cam hook
// Author: Peter Holzwarth
// ****************************************************************************
// https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language
SmartphoneHolder([PhoneName, PhoneWidth, PhoneHeight, PhoneDepth,
PhoneCornerRoundingRadius, PhoneEdgeRoundingRadius,
PhoneCamPos, CamSlotHeight], MountPos);
@jparkhill
jparkhill / gist:34851d8c3cfe63eff241891f9eadbb70
Created April 30, 2021 18:51
Two Ansatze modules for Pytorch PDEs.
class Neural_Density(torch.nn.Module):
"""
A neural model of a time dependent probability density on
a vector valued state-space.
ie: rho(t,{x_0, x_1, ... x_{state_dim}})
for now, I'm not even enforcing normalization.
could with a gaussian mixture or whatever.
"""