Skip to content

Instantly share code, notes, and snippets.

@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.
@GCBallesteros
GCBallesteros / vanilla_monte_carlo.py
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))
function_evaluations.append(F)
@GCBallesteros
GCBallesteros / example_usage_autocommit.py
Created September 28, 2018 06:25
Example usage of autocommit
# Modified example from mlflow-example/train.py
import os
import warnings
import sys
from git_autocommit import autocommit
import pandas as pd
import numpy as np