Skip to content

Instantly share code, notes, and snippets.

Exercises

Is it okay to initialize all the weights to the same value as long as that value is selected randomly using He initialization?

No. All weights should be initialized to different random values and should not have the same initial value. If weights are symmetrical, meaning they have the same value, it makes it almost impossible for backpropagation to converge to a good solution.

Think of it this way: if all the weights are the same, it's like having just one neuron per layer, but much slower.

The technique we use to break this symmetry is to sample weights randomly.

@byelipk
byelipk / fetch_batch.py
Created March 22, 2017 15:23
Helpful for mini-batch optimizers
import numpy as np
def fetch_batch(X, y, epoch, n_batches, batch_index, batch_size):
"""
A generic function that returns the next batch of data to train on.
Parameters
==========
:X: The training examples
@byelipk
byelipk / take_n.py
Created April 1, 2017 16:15
Return index position of first N items that match a test condition.
from collections import Counter
def take_n(data, n, test_condition=lambda x: True):
"""
Return index position of first N items that match a test condition.
Parameters
==========
:data: An enumerable, such as a list.
@byelipk
byelipk / download_m3u8.rb
Created May 30, 2017 17:18
A utility written in Ruby to download video from M3U8 files. Requires ffmpeg and the Clipboard gem.
# A utility written in Ruby to download video from M3U8 files.
#
# From Wikipedia:
#
# An M3U file is a plain text file that specifies the locations of one or more
# media files. The file is saved with the "m3u" filename extension if the text
# is encoded in the local system's default non-Unicode encoding (e.g., a
# Windows codepage), or with the "m3u8" extension if the text is UTF-8 encoded.
require 'optparse'
@byelipk
byelipk / timer.rb
Created June 3, 2017 13:57
Simple timer app in Ruby
def time_diff(start_time, end_time)
seconds_diff = (start_time - end_time).to_i.abs
hours = seconds_diff / 3600
seconds_diff -= hours * 3600
minutes = seconds_diff / 60
seconds_diff -= minutes * 60
seconds = seconds_diff
@byelipk
byelipk / time-complexity.md
Created June 5, 2017 14:23
Common time complexity operations

O(1)

This denotes constant time. Running a statement like if (true) {...} is constant time. Another example of constant time is looking up a value in an object, array, or a hash table.

O(log n)

This denotes logrithmic time. Divide and conquer or recursive algorithms have a O(log n) time complexity.

O(n)

.code-snippet {
background-color: #2B394D;
.line-number {
color: #636d83;
font-size: 1.25rem;
}
.line {
color: white;
font-size: 1.25rem;
}
@byelipk
byelipk / csrf.md
Last active July 5, 2017 21:02
CSRF Study Notes

What is a CSRF?

This attack works by including malicous code, usually a link, in a website that accesses another site the user is believed to be authenticated with. If that user session is still authenticated, the attacker may execute unauthroized commands.

Most web applications store session data in a cookie. Browsers will automatically send the cookie on every request to a domain, if it can find the cookie for the domain. The catch is that if the request comes from a different domain, the browser will still send along the cookie.

@byelipk
byelipk / congestion.md
Created August 8, 2017 13:42
TCP and the Congestion Avoidance Window

The Transmission Control Protocol (TCP) was designed to be courteous to the different traffic uses on a network. This notion is at the heart of what makes TCP so reliable, even in the face of competing demands for resources on the poorest of networks.

What makes TCP so reliable? Under the hood, TCP implements a concept called the congestion window. The congrstion window is the number of packets the sender can transmit over the wire until it receives an acknowledgment from the receiver. For example, if we set the congestion window to 1, the sender could send 1 packet to the reciever, then it would have to wait to recieve an acknowledgment. Only then could it send a second packet.

@byelipk
byelipk / tls-everywhere.md
Last active August 9, 2017 19:06
TLS Everywhere

The SSL protocol was implement by Netscape back in the day to facilitate commerce over the internet. E-commerce, as it became known as, required encryption to ensure that customer's personal information was kept safe, and the proper authentication and integrity guarentees were in place.

When SSL is used correctly, a third party cannot read or modify any of the actual data sent over the connection.

The TLS protocol is designed to provide three services to all applications running above it:

  1. Encryption
  2. Authentication