Skip to content

Instantly share code, notes, and snippets.

View Joshuaalbert's full-sized avatar

Joshua George Albert Joshuaalbert

View GitHub Profile
@Joshuaalbert
Joshuaalbert / lm_to_pixel_relation.py
Last active June 17, 2024 02:03
Shows that pixel x and pixel y are the same thing scaled by 180/pi
import sympy as sp
pi = sp.pi
def perley_lmn_from_icrs(alpha, dec, alpha0, dec0):
dra = alpha - alpha0
l = sp.cos(dec) * sp.sin(dra)
m = sp.sin(dec) * sp.cos(dec0) - sp.cos(dec) * sp.sin(dec0) * sp.cos(dra)
@Joshuaalbert
Joshuaalbert / enu_frame.py
Last active April 21, 2024 22:14
ENU (East-North-Up) astropy frame
from __future__ import (absolute_import, unicode_literals, division, print_function)
from astropy.coordinates import AltAz
from astropy.coordinates.attributes import (TimeAttribute, EarthLocationAttribute)
from astropy.coordinates.baseframe import (BaseCoordinateFrame, RepresentationMapping, frame_transform_graph)
from astropy.coordinates.representation import (CartesianRepresentation)
from astropy.coordinates.transformations import FunctionTransform
class ENU(BaseCoordinateFrame):
@Joshuaalbert
Joshuaalbert / fair_async_rlock.py
Last active June 14, 2023 08:45
Fair AsyncIO RLock implementation
import asyncio
from collections import deque
class FairAsyncRLock:
"""
A fair reentrant lock for async programming. Fair means that it respects the order of acquisition.
"""
def __init__(self):
self._owner: asyncio.Task | None = None
self._count = 0
@Joshuaalbert
Joshuaalbert / fill_in_empty_cells.py
Created November 8, 2021 17:43
Fills in empty voxels
def fill_in_empty_cells(voxels, length_scale_voxels=3, support=9, zero_threshold=1e-5):
"""
Fill in zero-values (or values less than zero_threshold) with smoothed values.
Leave the non-zero bins as they are.
Args:
voxels: [batch, voxels_per_dimension, voxels_per_dimension, voxels_per_dimension, num_properties]
support: float, length scale for exponential kernel how "near" in pixels to interpolate.
support: int, how big to make the kernel, should be big enough that there are no regions of this size without a value.
@Joshuaalbert
Joshuaalbert / bfgs_speed_test.py
Created June 4, 2021 20:10
Regression Test BFGS speed test against jax and jaxlib versions.
def speed_test_jax():
import numpy as np
from jax import jit, value_and_grad, random, numpy as jnp
from jax.scipy.optimize import minimize as minimize_jax
from scipy.optimize import minimize as minimize_np
import pylab as plt
from timeit import default_timer
import jax
JAX_VERSION = jax.__version__
@Joshuaalbert
Joshuaalbert / speed_test_jax.py
Last active October 16, 2020 15:20
Tests speed of N-D Least squares + L1 regularisation with various backends
def speed_test_jax():
import numpy as np
from jax import jit,value_and_grad, random
from jax.scipy.optimize import minimize as minimize_jax
from scipy.optimize import minimize as minimize_np
import pylab as plt
from timeit import default_timer
S = 3
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-65-a4128a1c8e7f> in <module>()
14 gp = pm.gp.Marginal(cov_func=cov_func)
15 f = gp.marginal_likelihood('f',X,y,0.1)
---> 16 f_star = gp.conditional('fstar',Xnew)
17
~/anaconda3/envs/kerastf/lib/python3.6/site-packages/pymc3-3.3rc2-py3.6.egg/pymc3/gp/gp.py in conditional(self, name, Xnew, pred_noise, given, **kwargs)
501
import numpy as np
import tensorflow as tf
from gpflow.likelihoods import Likelihood
from gpflow import densities
from gpflow.decors import params_as_tensors
from gpflow.params import Parameter
from gpflow.transforms import Transform, positive, Chain
from gpflow import settings
@Joshuaalbert
Joshuaalbert / cholesky-issues.py
Last active November 16, 2017 23:04
TF Cholesky fail on RBF pos-def matrix
import gpflow as gp
import numpy as np
import pylab as plt
import tensorflow as tf
X = np.array([[ 1.16527441e+09],
[ 1.16527442e+09],
[ 1.16527443e+09],
[ 1.16527443e+09],
[ 1.16527444e+09],
@Joshuaalbert
Joshuaalbert / validationError.java
Last active June 10, 2017 00:24
gives a null pointer at some point
package com.tactico.tm.bugs;
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
import org.deeplearning4j.nn.conf.BackpropType;
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.Updater;
import org.deeplearning4j.nn.conf.inputs.InputType;
import org.deeplearning4j.nn.conf.layers.RnnOutputLayer;
import org.deeplearning4j.nn.weights.WeightInit;