Skip to content

Instantly share code, notes, and snippets.

View christiaanjs's full-sized avatar

Christiaan Swanepoel christiaanjs

  • Auckland, New Zealand
View GitHub Profile
import org.ejml.data.DMatrixRMaj;
import org.ejml.dense.row.CommonOps_DDRM;
import org.ejml.simple.SimpleMatrix;
public class BFGSOptimizer implements Optimizer {
private double decreaseTol = 0.001; //(0, 0.5)
private double curvatureTol = 0.9; //(decreaseTol, 1.0)
private double gradTol = 1e-6;
@christiaanjs
christiaanjs / latent-gp-poison.ipynb
Last active January 16, 2018 00:58
Latent GP Poisson model
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@christiaanjs
christiaanjs / distribution-test.ipynb
Created November 22, 2018 19:53
Bootstrap multivariate two-sample test for distribution
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from xml.etree import ElementTree
data_xml_filename = '311spp_5genes.xml'
xml_root = ElementTree.parse(data_xml_filename)
flat_dict = [{ 'alignment': alignment.attrib['id'], 'taxon': sequence.find('taxon').attrib['idref'], 'sequence': sequence.find('taxon').tail.strip() } for alignment in xml_root.findall('alignment') for sequence in alignment.findall('sequence') ]
taxa_dict = { taxon: { value['alignment']: value['sequence'] for value in values } for taxon, values in groupby(sorted(flat_dict, key=key_func), key=key_func) }
print(taxa_dict)
@christiaanjs
christiaanjs / skygrid-test.ipynb
Last active July 27, 2019 00:55
Skygrid + Beagle test
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@christiaanjs
christiaanjs / bijectors.ipynb
Created September 18, 2019 23:47
Truncated Lognormal distribution in Tensorflow Probability
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@christiaanjs
christiaanjs / phylo-model.py
Created January 29, 2020 00:48
Phylo model
model = tfd.JointDistributionNamed(dict(
frequencies=tfd.Dirichlet(concentration=[4,4,4,4]),
kappa=tfd.LogNormal(loc=0, scale=1),
pop_size=tfd.LogNormal(loc=0, scale=1),
tree=lambda pop_size: treeflow.coalescent.ConstantCoalescent(pop_size=pop_size, sampling_times=sampling_times),
sequences=lambda tree, kappa, frequencies: treeflow.sequences.PhyloCTMC(tree=tree, q=HKY(frequencies=frequencies, kappa=kappa))
))
@christiaanjs
christiaanjs / tf-likelihood-test.ipynb
Last active May 14, 2020 09:33
Making Tensorflow likelihood gradients work in function mode
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.