Skip to content

Instantly share code, notes, and snippets.

View arthurmensch's full-sized avatar

Arthur Mensch arthurmensch

View GitHub Profile
import json
import math
import time
import numpy as np
import torch
import matplotlib.pyplot as plt
import seaborn as sns
import os
import json
import math
import time
import numpy as np
import torch
import matplotlib.pyplot as plt
import seaborn as sns
import os
@arthurmensch
arthurmensch / continuous.py
Created February 8, 2019 12:36
Geometric potentials in Pytorch
import torch
import torch.nn as nn
import torch.nn.functional as F
def duality_gap(f, fn):
diff = f - fn
return (torch.max(diff, dim=1)[0] - torch.min(diff, dim=1)[
0]).mean().item()
@arthurmensch
arthurmensch / orchestra_dask.py
Created September 17, 2018 21:15
MCTS + dask
import threading as thr
from concurrent.futures import ThreadPoolExecutor
from concurrent.futures import as_completed as thr_as_completed
from queue import Queue as ThrQueue
from time import sleep
import numpy as np
import tornado
from distributed import Client, Queue, as_completed, Pub, Sub, get_client, \
get_worker
@arthurmensch
arthurmensch / double_backward.py
Created May 19, 2018 10:25
Custom twice differentiable functions in Pytorch.
"""
Custom twice differentiable functions in Pytorch.
Author: Arthur Mensch
"""
import torch
import torch.nn as nn
@arthurmensch
arthurmensch / lbfgs.py
Last active October 20, 2023 06:33
LBFGS wrapper for Pytorch
"""
Copyright (c) 2017 Arthur Mensch
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@arthurmensch
arthurmensch / liblinear_vs_lightning.py
Created March 2, 2017 08:12
SAGAClassifier vs sklearn liblinear
import numpy as np
from lightning.classification import SAGAClassifier
from scipy import sparse
from sklearn.datasets import load_iris, make_classification
from sklearn.linear_model.logistic import (
LogisticRegression,
)
@arthurmensch
arthurmensch / MongoDB+sacred_MongoDB.ipynb
Created January 24, 2017 15:04
MongoDB tutorial + sacred examples
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@arthurmensch
arthurmensch / nifti.py
Created January 24, 2017 09:26
Monkey patch nilearn and joblib to have reliable cache with Nifti1Image
import os
import nibabel
import numpy as np
import sklearn.externals.joblib as joblib
from nibabel import Nifti1Image as NibabelNifti1Image
from nibabel import load as nibabel_load
from sklearn.externals.joblib.func_inspect import filter_args
from sklearn.externals.joblib.hashing import NumpyHasher, Hasher
@arthurmensch
arthurmensch / Svg_latex_to_pdf.md
Created June 2, 2016 17:23
SVG + latex to png/pdf converter

SVG + Latex to PDF/PNG converter

Usage: make will yield pdf for all SVG file in the directory. make png will rasterize them to png