Skip to content

Instantly share code, notes, and snippets.

import numpy as np
import jax
from jax import numpy as jnp
def _run_argsort_numpy(args) -> jnp.ndarray:
jax.debug.print("Run argsort using Numpy")
arr, axis = args
return np.argsort(arr, axis=axis).astype(np.int32)
def run_argsort_numpy(arr:jnp.ndarray, axis=None) -> jnp.ndarray:
@sjdv1982
sjdv1982 / aptool-dump.py
Created February 5, 2023 19:54
dump ActivePaper data directory as .npy
# Author: Sjoerd de Vries, CNRS
# license: public domain
import sys
import os
import h5py
import numpy as np
active_paper_file = sys.argv[1]
target_directory = sys.argv[2]
"""
11 cards, 55 points in total
S = current score
K = cards remaining
score increase = (chance to draw a non-joker * average value of non-joker) - (chance to draw a joker * S)
= (K-1)/K * (55-S)/(K-1) - 1/K * S
= (55-S)/K - S/K
= (55 - 2S)/K
"""
Parses the biological assemblies of a mmCIF file
For each assembly.
a list of 4x4 transformation matrices is computed, and returned together
with a list of chains
Each transformation matrix is to be applied to each chain in the list
Biological assemblies may contain non-protein or fantasy chains; it is possible
to pass in a list of interesting chains, and the returned chain lists will
then be filtered accordingly
"""fivethirtyeight.com Riddler Classic, Dec 11
https://fivethirtyeight.com/features/how-high-can-you-count-with-menorah-math/
'''
From Alex van den Brandhof comes a matter of life and death:
The Potentate of Puzzles decides to give five unlucky citizens a test. The potentate has countless red hats, green hats and blue hats. She says to the citizens, “Tomorrow, you will all be blindfolded as I place one of these hats on each of your heads. Once all the hats are placed, your blindfolds will be removed. At this point, there will be no communication between any of you! As soon as I give a signal, everyone must guess — at the same time — the color of the hat atop their own head. If at least one of you guesses correctly, all of you will survive! Otherwise …”
The potentate continues: “The good news is that there’s a little more information you’ll have. I will be arranging you into two rows facing each other, with two of you in one row and three of you in the other. Citizens in the same row cannot see each other,
@sjdv1982
sjdv1982 / cryoEM-galactosidase.ipynb
Last active January 28, 2020 13:07
MDFF-like (Wilson-regime) cross-correlation for simulated cryo-EM density maps of beta-galactosidase
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
fragments = np.load("fragments_clust.npy")
redun = np.load("redundancy-masks/1.0-seqclust-50.npy").astype(bool)
fragments = fragments[redun]
fragments_aa = np.array([f for f in fragments if f["motif"] == b"AAA"])
clus = [f for f in fragments_aa if f["clust1.0"] == 700]
print(clus)
"""
Recursive Bayesian approach to create optimal tournament schedules
Solution for The Riddler Classic, July 19: https://fivethirtyeight.com/features/can-you-construct-the-optimal-tournament/
Results:
4 players, 4 games:
Game 1. Player A vs player B, winner becomes the favorite.
Game 2. Favorite vs player C.
import numpy as np
from collections import namedtuple
### Convenience functions
variables = (
"rank", # 0 for no bid, 1 for 1 clubs, 2 for 1 diamonds, ..., 5 for 1 no-trump, ..., 35 for 7 no-trump
"passes", # 0 - 4 consecutive passes
"turn", # whose turn it is; 0 for the team who opens the bidding, 1 for the other
"contractor", # the team who did the last bidding; 0 for the team who opens the bidding, 1 for the other
"doubles" # the number of doubles (0,1,2)
1. Hex:
wget http://hex.loria.fr/dist800/hex-8.0.0-x64-mint14.run
chmod +x ./hex-8.0.0-x64-mint14.run
./hex-8.0.0-x64-mint14.run
Press Enter if there is any default value (in [...] )
Otherwise, type "y"