Skip to content

Instantly share code, notes, and snippets.

@nbro
nbro / double_bridge.md
Last active March 12, 2017 22:41
In-place double-bridge or 4-opt move

I've implemented a double-bridge (or 4-opt) move in place, i.e. without any additional containers than the original. I'm sharing it with you first because I would like to know if it's correct or if I can improve it and second because I thought it could be helpful to someone else (since I have not found anything on the web).

/*
 * DOUBLE-BRIDGE-COMPUTE-GAIN
 *
 * Computes and returns the gain of a random double-bridge move.
 * The indices of the vertices used are also returnd as 2nd, 3rd and 4th parametrs of the array returned.
 * */
std::array<int, 4> double_bridge_in_place_compute_gain(const MatrixGraph &m, const VectorTour &t) {
@nbro
nbro / policy_iteration.py
Created December 16, 2017 15:59
Simple example of policy iteration on a grid/maze world (using Python/NumPy)
import numpy as np
E = EMPTY = 0
B = BLOCKED = 1
G = GOAL = 2
# The maze from the assignment
MAZE = np.array(
[[0, 0, 0, 0, 0, 0, 0],
[0, 0, B, 0, 0, 0, 0],

channel operator quick reference

direct discussion about administrative action away from the main channel and into #reddit-diabetes-ops to minimise disruption. our -ops channel is the place where users should come to ask for our help. examples:

  • any sort of operator request or discussion of channel administration in the main channel
  • PMs asking why a ban was set
  • reports of harassment (unless the user is confiding in you)
  • any request for operator action

changing channel access permissions

@nbro
nbro / template.tex
Created October 21, 2018 19:03
Code to be made a template
\begin{tikzpicture}[-, >=stealth', level/.style={sibling distance = 8cm/#1, level distance = 2cm}]
\node [circle_node] (A) {$+$}
child { node [square_node] (B) {-}
child { node [circle_node] (E) {+}
child { node [square_node] (L) {-}
child [sibling distance = 1cm] { node [circle_node] (V) {$7$} }
child [sibling distance = 1cm] { node [circle_node] (W) {$4$} }
}
child { node [square_node] (M) {-}
child [sibling distance = 1cm] { node [circle_node] (X) {$2$} }
@nbro
nbro / main.tex
Created October 21, 2018 20:39
Main file which imports the template in the file game-tree.tex
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage[margin=0.6in]{geometry}
% Define a few styles for the nodes
\tikzset{
tree_node/.style = {align=center, inner sep=0pt, text centered, font=\sffamily},
square_node/.style = {tree_node, rectangle, draw=black, minimum width=1.5em, minimum height=1.5em, very thick},
@nbro
nbro / game-tree.tex
Created October 21, 2018 20:41
Game tree template to be included in main.tex
\def\alphabetadiagram{
\begin{tikzpicture}[-, >=stealth', level/.style={sibling distance = 8cm/#1, level distance = 2cm}]
\node [circle_node] (A) {$+$}
child { node [square_node] (B) {-}
child { node [circle_node] (E) {+}
child { node [square_node] (L) {-}
child [sibling distance = 1cm] { node [circle_node] (V) {$7$} }
child [sibling distance = 1cm] { node [circle_node] (W) {$4$} }
}
@nbro
nbro / mnist_example.py
Last active January 5, 2019 21:20
PyTorch example to train a CNN on MNIST using VisualDL for logging
# It takes about 8 minutes to train this model and obtain 99% accuracy.
from __future__ import print_function
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torchvision import datasets, transforms
import time
import datetime
import argparse

Mounting VirtualBox shared folders on Ubuntu Server 16.04 LTS

This guide will walk you through steps on how to setup a VirtualBox shared folder inside your Ubuntu Server guest. Tested on Ubuntu Server 16.04.3 LTS (Xenial Xerus)

Steps:

  1. Open VirtualBox
  2. Right-click your VM, then click Settings
  3. Go to Shared Folders section
  4. Add a new shared folder
  5. On Add Share prompt, select the Folder Path in your host that you want to be accessible inside your VM.
@nbro
nbro / dictionary_as_model_output.py
Created January 31, 2020 12:31
In TF 2.1 (at least), you can create a model by passing to the outputs parameter a dictionary.
def example1():
# TensorFlow 2.1
import tensorflow as tf
import numpy as np
Input_1 = tf.keras.layers.Input(shape=(1,))
x = tf.keras.layers.Dense(100, activation='relu')(Input_1)
targets = ["out1", "out2", "out3"]
@nbro
nbro / test_trainable_prior.py
Created April 17, 2020 16:24 — forked from cboulay/test_trainable_prior.py
Some testing code for tensorflow-probability trainable priors
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import tensorflow.keras.layers as tfkl
from tensorflow.keras import backend as K
import tensorflow_probability as tfp
tfd = tfp.distributions
tfpl = tfp.layers
tfb = tfp.bijectors