Skip to content

Instantly share code, notes, and snippets.

View andreydung's full-sized avatar

Dzung Nguyen andreydung

View GitHub Profile
@andreydung
andreydung / hessianChecking.py
Created April 19, 2017 22:09
Hessian Checking from gradient
from __future__ import print_function
import numpy as np
def hessianChecking(grad, hessian, w, *args):
N = w.shape[0]
H = hessian(w, *args)
numericalHessian = np.zeros_like(H)
# check symmetry of Hessian first
@andreydung
andreydung / softmax_grad_hw_withtest.m
Last active April 19, 2017 16:39
Starter code for 4.3 with gradient checking test.
function softmax_grad_demo_hw()
% softmax_grad_demo_hw - when complete reproduces Figure 4.3 from Chapter 4
% of the text
%%% load data
[X,y] = load_data();
%%% run gradient descent
w = softmax_gradient_descent(X,y);
% OSX
cat /dev/cu.usbmodem1421 | gawk '{x="'"`gdate +%s%3N`"'"; printf "%s,%s\n",x,$0 }' | tee data.csv
% Ubuntu
cat /dev/cu.usbmodem1421 | awk '{x="'"`date +%s%3N`"'"; printf "%s,%s\n",x,$0 }' | tee data.csv
/*
* Clock.c
*
* Created: 5/25/2016 1:01:13 AM
* Author : andrey
*/
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
# Kadane's algorithm
def largest(a):
max_current = -100
maxvalue = -100
for i in range(len(a)):
if (max_current < 0):
max_current = a[i]
currenti = i
currentj = i
package main
import (
"bufio"
"fmt"
"net"
"os"
"strconv"
"strings"
)
import numpy as np
def integral(mask):
"""
calculate integral image for quick histogram
"""
assert(mask.dtype == bool)
M, N = mask.shape
integral = np.zeros((M + 1, N + 1)).astype(int)
compatible = 0
N = len(s1)
for i in range(N):
for j in range(i + 1, N):
if (s1[i] == s1[i] and s2[i] == s2[j]) or (s1[i] != s1[j] and s2[i] != s2[j]):
compatible += 1
return compatible/(N*(N - 1)/2)