This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ### steps #### | |
| # verify the system has a cuda-capable gpu | |
| # download and install the nvidia cuda toolkit and cudnn | |
| # setup environmental variables | |
| # verify the installation | |
| ### | |
| ### to verify your gpu is cuda enable check |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def conv_out_shape(in_shape: tuple, kernel_size:int, dilation:int, stride:int, padding:int): | |
| """ | |
| Convenience function for computing the output shape of an image tensor, when applying symmetric kernels, strides, etc. | |
| """ | |
| out_dim = [] | |
| for d in in_shape: | |
| _d_out = d + 2 * padding - dilation * (kernel_size - 1) - 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def make_grid(arr: np.ndarray, nrows: int, pad_size: int = 2, pad_value: int = 0): | |
| """ | |
| Expected array layout is (N, C, H, W) | |
| """ | |
| arr = np.pad(arr, | |
| ((0,0), | |
| (0,0), | |
| (pad_size // 2, pad_size // 2), | |
| (pad_size // 2, pad_size // 2)), | |
| constant_values=(pad_value,)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from torch.autograd.gradcheck import zero_gradients | |
| def compute_jacobian(inputs, output): | |
| """ | |
| :param inputs: Batch X Size (e.g. Depth X Width X Height) | |
| :param output: Batch X Classes | |
| :return: jacobian: Batch X Classes X Size | |
| """ | |
| assert inputs.requires_grad |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| open Graph | |
| open Core | |
| open Owl | |
| module G = Persistent.Graph.Concrete( | |
| struct | |
| type t = int | |
| let equal a b = phys_equal a b | |
| let compare a b = Pervasives.compare a b | |
| let hash a = a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (** The fundamental idea behind this sort algorithm is to iteratively remove nodes from a DAG | |
| * who do not possess ancestors and hence can be considered roots. We add them to an ordered list | |
| * and get a topological sort of the dependency graph. *) | |
| open Core | |
| open Graph.Pack.Digraph | |
| (** Simple helper to create a OCamlGraph with directionality *) | |
| let create_digraph nodes edges = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (* | |
| This is a simple solution to the Run-Length Encoding problem described | |
| in Watrophy #24 (http://www.watrophy.com/posts/24-Run-Length-Encoding.html) | |
| *) | |
| open Core | |
| let rle int_list = | |
| let increment tup n = | |
| match tup with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (* | |
| The Evolution Strategy Optimizer is a Hill-Climbing routine based on stochastic gradient | |
| estimation (not to be confused with stochastic gradient descent optimization). The basic idea | |
| is to perturb the current best parameter value using Gaussian noise and explore the function | |
| values of the blackbox objective in the vicinity of the parameters. From these explorations one | |
| can estimate the gradient and perform a gradient update step. | |
| More information can be found in: | |
| - T. Salimans et al. Evolution Strategies as a Scalable Alternative to Reinforcement Learning, | |
| arXiv:1703.03864, https://arxiv.org/pdf/1703.03864.pdf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import seaborn as sns | |
| import numpy as np | |
| import numpy.random as rd | |
| import matplotlib.pyplot as plt | |
| from scipy.spatial import distance as dist | |
| import scipy.linalg as la | |
| import itertools as it | |
| %matplotlib inline |