Skip to content

Instantly share code, notes, and snippets.

View fbkarsdorp's full-sized avatar
💭
🦔

Folgert Karsdorp fbkarsdorp

💭
🦔
View GitHub Profile
@fbkarsdorp
fbkarsdorp / overestimation-animation.py
Created February 16, 2023 10:28
Manim video showing the overestimating effect of applying the wrong unseen species estimator
import random
def sailor_legend(color, text):
text = Text(text, color=BLACK, font_size=24)
sailor = ImageMobject(f"sailor-{color}.png").scale(0.15)
return Group(sailor, text).arrange(RIGHT)
rng = np.random.RandomState(2029) #1989 #2019
class ShipScene(SpaceScene):
@fbkarsdorp
fbkarsdorp / newick.py
Created October 21, 2020 15:42
Convert scipy tree format to newick format (e.g. for working with figtree)
from scipy.cluster import hierarchy
def tree2newick(node, newick, parentdist, leaf_names):
if node.is_leaf():
return f"{leaf_names[node.id]}:{parentdist - node.dist:.2f}{newick}"
else:
if len(newick) > 0:
newick = f"):{parentdist - node.dist:.2f}{newick}"
else:
newick = ");"
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.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fbkarsdorp
fbkarsdorp / conformity-distinctiveness.ipynb
Created April 28, 2019 08:32
Python code for "Social conformity despite individual preferences for distinctiveness"
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fbkarsdorp
fbkarsdorp / interactive_plot.py
Last active August 29, 2015 14:07
Class for interactive plots
import matplotlib.pyplot as plt
class InteractivePlot(object):
def __init__(self, id, xlabel, ylabel):
self.id = id
plt.figure(id)
plt.ion()
self.xlabel = xlabel
self.ylabel = ylabel
@fbkarsdorp
fbkarsdorp / pml.py
Created August 29, 2013 12:47
Parsimonious Language Model in Python
#! /usr/bin/env python
import numpy as np
from heapq import nlargest
from itertools import izip
from sklearn.feature_extraction.text import CountVectorizer
old_settings = np.seterr(all='ignore')
def logsum(x):