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
| # Mocha.js test runner support | |
| # https://github.com/jfirebaugh/konacha | |
| Konacha.configure do |config| | |
| config.spec_dir = "spec/javascripts/mocha" | |
| config.spec_matcher = /_spec\.|_test\./ | |
| # driver names a Capybara driver used for the run task (try :poltergeist, after installing PhantomJS). | |
| # Without this directive, konacha will try to run this in Firefox | |
| require 'capybara/poltergeist' | |
| config.driver = :poltergeist |
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
| # Create the wrapped function with 5 retries | |
| command = @commands.retry('connectToProvider', attempts: 5) | |
| # Create the wrapped function with unlimited retries | |
| command = @commands.retry('connectToProvider') | |
| # Essentially a promise is returned with another method attached | |
| promise = command('yahoo', username: 'x', password: 'y') | |
| # Some bad shit happens |
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
| require 'squeel' | |
| class RealtimeMessage < ActiveRecord::Base | |
| # These attributes are "mass-assignable", that is, they come in directly from the serial port as XML | |
| attr_accessible :src, :dsb, :time, :tmprF, :sensor_num, :sensor_type, :radio_id, :ch1_watts, :ch2_watts, :ch3_watts, :mac_address | |
| def self.this_month | |
| now = Time.now | |
| first_of_month = Date.civil(now.year, now.month, 1) | |
| last_of_month = Date.civil(now.year, now.month, -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
| # Thanks Seth Darlington! | |
| price_per_kwh = 0.1248 # dollars | |
| query = RealtimeMessage.this_month | |
| previous = query.first | |
| usage = query[1..query.count].reduce(0) do |sum, message| | |
| elapsed_seconds = (message.created_at - previous.created_at) | |
| elapsed_hours = elapsed_seconds/3600 |
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
| function g = sigmoid(z) | |
| g = sigmoid = 1.0 ./ (1.0 + exp(-z)); | |
| end | |
| function g = sigmoidGradient(z) | |
| g = sigmoid(z) .* (1 - sigmoid(z)); | |
| end |
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
| regularization = lambda/(2*m) * ( ... | |
| sum(sum((Theta1(:,2:end)).^2)) + ... | |
| sum(sum((Theta2(:,2:end)).^2)) ... | |
| ); | |
| J = (1/m) * sum( ... | |
| sum((-y .* log(h))-((1-y) .* log(1-h))) ... | |
| ); | |
| J = J + regularization; |
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
| J = (1/m) * sum( ... | |
| sum((-y .* log(h))-((1-y) .* log(1-h))) ... | |
| ); |
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
| m = size(X, 1); | |
| a1 = [ones(m, 1) X]; % Add the biases to the input matrix | |
| z2 = a1 * Theta1'; | |
| a2 = sigmoid(z2); | |
| n = size(a2, 1); | |
| a2 = [ones(n,1) a2]; % Add the biases | |
| z3 = a2 * Theta2'; |
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
| function g = sigmoid(z) | |
| % Compute the sigmoid of z. | |
| % z can be a matrix, vector or scalar. | |
| g = 1.0 ./ (1.0 + exp(-z)); | |
| % 1./ (1 + e.^-z); <-- this is equivalent | |
| end | |
| hypothesis = sigmoid(X*theta); |
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
| function [J, grad] = costFunction(theta, X, y) | |
| % Logistic Regression cost function and partial derivative (gradient) | |
| m = length(y); % number of training examples | |
| cost = (y' * log(h)) + ((1-y')*log(1-h)); | |
| J = -1/m * cost; | |
| grad = 1/m * (X' * (h - y)); |