Skip to content

Instantly share code, notes, and snippets.

GCBallesteros /
Last active November 11, 2022 11:52
Batched Dataloader in pytorch
import numpy as np
import as data
class SimpleDataset(data.Dataset):
def __init__(self):
super().__init__() = np.random.randn(1000, 5)
def __getitem__(self, idxs):
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
GCBallesteros /
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__(
GCBallesteros /
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
GCBallesteros / cryptopals_utils.ts
Created July 14, 2020 07:48
Utility functions to solve the cryptopals challenges
import fs from "fs"
export enum ByteEncoding {
export function hexToBuff(data: string): Buffer {
return Buffer.from(data, "hex");
GCBallesteros / latex_template.tex
Last active July 19, 2019 22:11
LaTex Template For
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 /
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 /
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):
MNBS : int
If less than MNBS evaluations are left we do
vanilla MC.
GCBallesteros /
Created May 31, 2019 09:22
Vanilla Monte Carlo Integration
def MonteCarloIntegral(f, N, dim, fractional_error_tolerance=0.05):
relative_error = 1.
function_evaluations = list()
while relative_error > fractional_error_tolerance:
for _ in range(int(N)):
F = f(np.random.rand(dim))
GCBallesteros /
Created September 28, 2018 06:25
Example usage of autocommit
# Modified example from mlflow-example/
import os
import warnings
import sys
from git_autocommit import autocommit
import pandas as pd
import numpy as np