Skip to content

Instantly share code, notes, and snippets.

@GCBallesteros
GCBallesteros / run_command.sh
Created August 19, 2024 19:38
Monitoring and uploading local changes to the remote
git ls-files --exclude-standard | entr -p ./scp-git-file 'root@10.187.0.59' /_
@GCBallesteros
GCBallesteros / homography_reduction.py
Created August 7, 2024 14:40
Sample code for the MaxwellRules post "An unexpected matrix trick" showing how to reduce the dimension of a homography given a fixed coordinate along a dimension.
import numpy as np
DIM = 4 # Dimension of matrix which represents the homography
IGNORE_DIM = 2 # This would be t on the blog post example
# We can't remove the last dim of the homography because it's
# special.
assert 0 <= IGNORE_DIM <= (DIM - 2)
assert IGNORE_DIM
@GCBallesteros
GCBallesteros / batched_dataloader_example.py
Last active November 11, 2022 11:52
Batched Dataloader in pytorch
import numpy as np
import torch.utils.data as data
class SimpleDataset(data.Dataset):
def __init__(self):
super().__init__()
self.data = np.random.randn(1000, 5)
def __getitem__(self, idxs):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@GCBallesteros
GCBallesteros / sklearn_pycox_wrapper.py
Created November 29, 2020 21:42
Simple wrapper for a DeepSURV model
from sklearn.base import BaseEstimator
import torchtuples as tt
class DeepSURVSklearnAdapter(BaseEstimator):
def __init__(
self,
learning_rate=1e-4,
batch_norm=True,
@GCBallesteros
GCBallesteros / regression_error_plot.py
Last active July 23, 2020 21:36
Regression error plot with holoviews
import numpy as np
import pandas as pd
import holoviews as hv
from holoviews import opts
from bokeh.models import HoverTool
from holoviews import streams
hv.extension("bokeh")
@GCBallesteros
GCBallesteros / cryptopals_utils.ts
Created July 14, 2020 07:48
Utility functions to solve the cryptopals challenges
import fs from "fs"
export enum ByteEncoding {
Base64,
Hex,
}
export function hexToBuff(data: string): Buffer {
return Buffer.from(data, "hex");
}
@GCBallesteros
GCBallesteros / latex_template.tex
Last active July 19, 2019 22:11
LaTex Template For cg.py
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Transformation matrix from $|jm>$ to $|m_1 m_2>$ basis
This is not the actual matrix; elements are represented as in the
CG tables. Do element-wise sqrt but keep the sign for the matrix.
@GCBallesteros
GCBallesteros / cg.py
Last active July 21, 2019 13:55
Transforming spin-orbit coupling from the total angular momentum base to m1 m2
import sympy as sp
import sympy.physics.quantum as spq
from sympy.matrices.dense import matrix_multiply_elementwise as mme
import numpy as np
import itertools
from fractions import Fraction
from argparse import ArgumentParser
@GCBallesteros
GCBallesteros / miser_1.py
Created June 14, 2019 21:34
init and main methods of the MISER class
from numpy.random import uniform
class MISER:
def __init__(self, miser_params):
"""
Parameters
----------
MNBS : int
If less than MNBS evaluations are left we do
vanilla MC.