Skip to content

Instantly share code, notes, and snippets.

View numpde's full-sized avatar

numpde

View GitHub Profile
@numpde
numpde / peer_learning.md
Last active July 7, 2017 16:46
Reinforcement learning through imitation of successful peers

Reinforcement learning through imitation of successful peers

Introduction

Reinforcement learning is a mode of machine learning driven by the feedback from the environment on how good a string of actions of the learning agent turns out to be.

We consider here a reinforcement learning mechanism for neural networks

@numpde
numpde / rndseg.py
Last active November 9, 2017 03:56
Segment extraction and expansion by words
#!/usr/bin/python3
# CC-BY-4.0
import sys, argparse
from random import shuffle, randrange, choice
# Collate lines, separating them by a space
s = ' '.join(sys.stdin.readlines())
# Remove non-text
@numpde
numpde / histo.py
Last active May 29, 2017 13:08
Histograms for the number of types V(N) within the first N tokens
#!/usr/bin/python3
# Histograms for the number of types V(N) within the first N tokens.
# Comparison of natives vs learners.
# R. Andreev, 2017-05-11 (first version), CC BY 4.0
# Designed for the ANGLISH corpus [Tortel 2008, via N. Ballier & P. Lisson]
# The texts are expected to be located in ./ANGLISH/*.txt
@numpde
numpde / add_path_by_variable.sh
Last active November 9, 2017 04:00
Write [addpath PATH "/some/path"] instead of [export PATH="/some/path:$PATH"]
#/bin/bash
# License-free
# Example: addpath PATH "/usr/bin"
addpath() {
varname=$1
export $1="$2:${!varname}"
}
@numpde
numpde / renice.m
Last active November 9, 2017 03:58
Try to make a MATLAB plot a little nicer
function h = renice(h)
% function h = renice(h)
%
% h is a handle returned by PLOT and such
%
% RA, Apr 2008 -- Aug 2016
%
% License: CC-BY-4.0
set(0, 'DefaultTextInterpreter', 'tex');
@numpde
numpde / betti.py
Last active March 22, 2023 15:06
Compute the Betti numbers of a graph
def betti(G, C=None, verbose=False):
# G is a networkx graph
# C is networkx.find_cliques(G)
# RA, 2017-11-03, CC-BY-4.0
# Ref:
# A. Zomorodian, Computational topology (Notes), 2009
# http://www.ams.org/meetings/short-courses/zomorodian-notes.pdf
@numpde
numpde / binary_rank.py
Last active November 8, 2017 09:23
Find the rank of a binary matrix over Z/2Z
# Find the rank of a binary matrix over Z/2Z
# (conceptual implementation)
#
# RA, 2017-11-07 (CC-BY-4.0)
#
# Adapted from
# https://triangleinequality.wordpress.com/2014/01/23/computing-homology/
#
def binary_rank(M) :
@numpde
numpde / betti_bin.py
Last active March 18, 2019 11:02
Compute the Betti numbers of a graph over Z/2Z
# Compute the Betti numbers of a graph over Z/2Z.
#
# If G is a networkx graph then set
# C = networkx.find_cliques(G)
# This enumerates maximal cliques.
#
# Pass C to the function betti_bin,
# which returns a list of Betti numbers.
#
# RA, 2017-11-08 (CC-BY-4.0)
@numpde
numpde / tunnel.sh
Last active January 17, 2018 12:35
Create an ssh tunnel using a local port
#!/bin/bash
# Suppose you wish to connect to a server X on port 23
# but you have to do this via another server Y like this:
#
# localhost> ssh -p 22 username@Y
# Y> ssh -p 23 username@X
#
# Instead, you can create an ssh tunnel on a local port, say 9999:
# localhost> ssh -nNT -L 9999:X:23 -p 22 username@Y
@numpde
numpde / template_for_datascience.py
Last active October 25, 2018 03:57
A python template for a data science script
#!/usr/bin/python3
# AUTHOR, DATE
## ================== IMPORTS :
pass
import inspect