Skip to content

Instantly share code, notes, and snippets.

@albertotb
albertotb / pair.py
Created April 21, 2021 12:02
Szudzik pairing for negative numbers
import math
from typing import Tuple
def pair_negative(x: int) -> int:
return 2 * x if x >= 0 else -2 * x - 1
def unpair_negative(z: int) -> int:
return int(z / 2) if z % 2 == 0 else int((z + 1) / -2)
def pair_szudzik(x: int, y: int) -> int:
@albertotb
albertotb / macros.js
Created April 6, 2019 22:10
Xaringan remark.js macros
remark.macros.scale = function (percentage) {
var url = this;
return '<img src="' + url + '" style="width: ' + percentage + '" />';
};
remark.macros.vspace = function (percentage) {
return `<div style="height: ${percentage}%"></div>`
};
remark.macros.centerScale = function (percentage) {
if __name__ == "__main__":
if len(sys.argv) < 3 or len(sys.argv) > 4:
print "usage: {0} TRAIN TEST VAL".format(sys.argv[0])
sys.exit(1)
train = np.loadtxt(sys.argv[1])
test = np.loadtxt(sys.argv[2])
val = np.loadtxt(sys.argv[3])
#!/usr/bin/env julia
soft_thresholding(x, α) = sign(x).*max(abs(x)-α, 0)
function lasso(X, y, λ, maxiter=10000, tol=1e-9)
keep_going = true
(n, m) = size(X)
G = X'*X
import time
import numpy as np
from scipy import linalg, io, sparse
import matplotlib.pyplot as plt
from sklearn.externals.joblib import Memory
from sklearn.linear_model import lasso_path
from sklearn.datasets.mldata import fetch_mldata
from sklearn import datasets
[I 11:41:27.812 NotebookApp] Using existing profile dir: u''
[I 11:41:27.818 NotebookApp] Using MathJax:
[I 11:41:27.846 NotebookApp] Serving notebooks from local directory:
[I 11:41:27.846 NotebookApp] 0 active kernels
[I 11:41:27.846 NotebookApp] The IPython Notebook is running at: https://[all ip addresses on your system]:9999/
[I 11:41:27.846 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[I 11:41:36.389 NotebookApp] 302 GET / () 0.67ms
[I 11:41:40.188 NotebookApp] Creating new notebook in
[E 11:41:40.199 NotebookApp] Error while saving file: Untitled.ipynb disk I/O error
Traceback (most recent call last):
[I 2015-04-10 19:04:23.453 JupyterHub app:515] Loading cookie_secret from /home/alberto/jupyterhub-master/jupyterhub_cookie_secret
[W 2015-04-10 19:04:23.502 JupyterHub app:251]
Generating CONFIGPROXY_AUTH_TOKEN. Restarting the Hub will require restarting the proxy.
Set CONFIGPROXY_AUTH_TOKEN env or JupyterHub.proxy_auth_token config to avoid this message.
[I 2015-04-10 19:04:23.703 JupyterHub app:608] Not using whitelist. Any authenticated user will be allowed.
[I 2015-04-10 19:04:23.719 JupyterHub app:743] Starting proxy @ http://*:9000/
19:04:24.200 - info: [ConfigProxy] Proxying http://*:9000 to http://localhost:8081
19:04:24.202 - info: [ConfigProxy] Proxy API at http://localhost:9001/api/routes
[I 2015-04-10 19:04:24.296 JupyterHub app:1008] Hub API listening on http://localhost:8081/hub/
[E 20:32:59.036 NotebookApp] Error while saving file: /Untitled.ipynb disk I/O error
Traceback (most recent call last):
File "/scratch/gaa/local/src/anaconda/lib/python2.7/site-packages/IPython/html/services/contents/filemanager.py", line 383, in save
self.check_and_sign(nb, path)
File "/scratch/gaa/local/src/anaconda/lib/python2.7/site-packages/IPython/html/services/contents/manager.py", line 428, in check_and_sign
self.notary.sign(nb)
File "/scratch/gaa/local/src/anaconda/lib/python2.7/site-packages/IPython/nbformat/sign.py", line 248, in sign
self.store_signature(signature, nb)
File "/scratch/gaa/local/src/anaconda/lib/python2.7/site-packages/IPython/nbformat/sign.py", line 251, in store_signature
if self.db is None:
Warning: git information unavailable; versioning information limited
Warning: git information unavailable; versioning information limited
Warning: git information unavailable; versioning information limited
which: no patchelf in (/scratch/gaa/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/slurm-2.4.3/bin:/scratch/gaa/local/src/libsvm-3.18)
/scratch/gaa/local/src/julia-v0.3.0/deps/openblas-v0.2.10/lapack/laswp/x86_64
/scratch/gaa/local/src/julia-v0.3.0/deps/openblas-v0.2.10/lapack/laswp/x86_64
/scratch/gaa/local/src/julia-v0.3.0/deps/openblas-v0.2.10/lapack/laswp/x86_64
/scratch/gaa/local/src/julia-v0.3.0/deps/openblas-v0.2.10/lapack/laswp/x86_64
/scratch/gaa/local/src/julia-v0.3.0/deps/openblas-v0.2.10/lapack/laswp/x86_64
/scratch/gaa/local/src/julia-v0.3.0/deps/openblas-v0.2.10/lapack/laswp/x86_64
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by LLVM configure 3.3, which was
generated by GNU Autoconf 2.60. Invocation command line was
$ ../configure --prefix=/scratch/gaa/local/src/julia-v0.3.0/usr --build=x86_64-redhat-linux --libdir=/scratch/gaa/local/src/julia-v0.3.0/usr/lib F77=gfortran -m64 CC=gcc -m64 CXX=g++ -m64 --disable-profiling --enable-shared --enable-static --enable-targets=host --disable-bindings --disable-docs --disable-assertions --enable-optimized --disable-threads --with-python=/scratch/gaa/local/src/anaconda/bin/python
## --------- ##
## Platform. ##