This file contains 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
function J = computeCost(X, y, theta) | |
%COMPUTECOST Compute cost for linear regression | |
% J = COMPUTECOST(X, y, theta) computes the cost of using theta as the | |
% parameter for linear regression to fit the data points in X and y | |
% Initialize some useful values | |
m = length(y); % number of training examples | |
% We need to return the following variable |
This file contains 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
function [X_norm, mu, sigma] = featureNormalize(X) | |
%FEATURENORMALIZE Normalizes the features in X | |
% FEATURENORMALIZE(X) returns a normalized version of X where | |
% the mean value of each feature is 0 and the standard deviation | |
% is 1. This is often a good preprocessing step to do when | |
% working with learning algorithms. | |
% Initialize some useful values | |
X_norm = X; | |
mu = zeros(1, size(X, 2)); |
This file contains 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
function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters) | |
%GRADIENTDESCENT Performs gradient descent to learn theta | |
% theta = GRADIENTDESENT(X, y, theta, alpha, num_iters) updates theta by | |
% taking num_iters gradient steps with learning rate alpha | |
% Initialize some useful values | |
m = length(y); % number of training examples | |
J_history = zeros(num_iters, 1); | |
for iter = 1:num_iters |
This file contains 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
# -*- coding: utf-8 -*- | |
""" | |
Spider to crawl WhoScored web pages. | |
""" | |
import re | |
from scrapy.contrib.spiders import CrawlSpider, Rule | |
from scrapy.utils.project import get_project_settings |
This file contains 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 math | |
class CollidingCircles(object): | |
def get_expected_value(self, radii, steps_count): | |
return math.pi * self.__get_expected_value_for_step(radii, steps_count) | |
def __get_expected_value_for_step(self, radii_set, step_idx): | |
if step_idx == 0: | |
return sum(radius * radius for radius in radii_set) |
This file contains 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 _get_next_words(self, word): | |
if word not in self.next_words_dict: | |
self._generate_next_words_list(word) | |
return self.next_words_dict[word] | |
def _generate_next_words_list(self, word): | |
next_words = [] | |
word_array = list(word) | |
for i in range(len(word_array)): |
This file contains 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 _bfs(self): | |
word_queue = [(self.begin_word, 1)] | |
word_enqueued = {self.begin_word: True} | |
while word_queue: | |
word, level = word_queue.pop(0) | |
self.word_levels[word] = level | |
if word == self.end_word: return level |
This file contains 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
queue = [hit] | |
pop hit, enqueue hot | |
queue = [hot] | |
pop hot, enqueue dot, lot | |
queue = [dot, lot] | |
pop dot, enqueue dog, ignore lot | |
queue = [lot, dog] |
This file contains 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
begin_word = "hit" | |
end_word = "cog" | |
dictionary = "hot", "dot", "dog", "lot", "log", "cog" |
This file contains 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
class WeightedQuickUnion(object): | |
def __init__(self, size): | |
self.group_count = self.size= size | |
self.group = [i for i in range(size)] | |
self.tree_size = [1] * size | |
def union(self, child, parent): | |
child_root = self.find(child) | |
parent_root = self.find(parent) |
NewerOlder