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
| pick_heaviest_loaf <- function( loaves=100) { | |
| bread <- rnorm( loaves, 950, 50) | |
| return( max( bread)) | |
| } | |
| loaves_over_a_year <- function( loaves=100) { | |
| days <- 365 | |
| poincare_loaves <- vector() | |
| for (i in 1:days ) { | |
| heaviest_loaf <- pick_heaviest_loaf(loaves) |
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
| evaluate_a_monty_hall_scenario <- function(switch=FALSE) { | |
| options <- c(1,2,3) | |
| car <- sample( 1:3, 1) | |
| pick <- sample( 1:3, 1) | |
| opened <- options[!(options %in% c( car, pick))] | |
| closed <- options[!(options %in% c( pick, opened[ 1]))] | |
| if (switch == TRUE) { pick = closed[ 1]} | |
| return( car == pick) | |
| } |
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 random import randint | |
| def evaluate_a_monty_hall_scenario(switch=False): | |
| options = set([1, 2, 3]) | |
| car = randint( 1, 3) | |
| pick = randint( 1, 3) | |
| opened = list( options.difference( set([car])).difference( set([pick])))[0] | |
| closed = list( options.difference( set([pick])).difference( set([opened])))[0] | |
| if switch: | |
| pick = closed |
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 sales-data [ | |
| {:person_id 1 | |
| :deal_id 2 | |
| :date "2013-01-04"} | |
| {:person_id 1 | |
| :deal_id 3 | |
| :date "2013-01-05"} | |
| {:person_id 1 | |
| :deal_id 4 | |
| :date "2013-01-05"} |
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 'generator' | |
| samples = [ | |
| { :xs => [ 1.0, 0.25], :y => 0.98}, | |
| { :xs => [ 1.0, 0.49], :y => 0.82}, | |
| { :xs => [ 1.0, 0.60], :y => 0.41}, | |
| { :xs => [ 1.0, 0.89], :y => 0.31} | |
| ] | |
| # line is the sum of the dot product of the weight (thetas) |
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
| (ns osx | |
| (:use seesaw.core) | |
| (:import | |
| [com.apple.eawt Application ApplicationListener] | |
| [java.awt.image BufferedImage])) | |
| ;; mostly for use with Seesaw | |
| ;; https://github.com/daveray/seesaw | |
| (defn event-not-handled [e] (.setHandled e false)) |
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
| (ns codelesson.mars-rovers-threaded) | |
| ;; Mars Rovers | |
| ;; Steve Butcher ([email protected]) | |
| ;; Code Lesson - Week 3 | |
| ;; | |
| ;; Utility functions | |
| ;; This function will take a map and switch the keys and values | |
| ;; The input map should have unique value as well as keys. |
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
| (ns banking) | |
| (defn zip [& rest] (apply map vector rest)) | |
| (defn rand-in-range [x y] | |
| "returns a random int in the range x (inclusive) and y (exclusive)" | |
| (+ x (rand-int (- y x)))) | |
| (defn rand-date [start-date end-date] | |
| "generates a random date between the start-date and the end-date. Each should be a string |
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
| (defn get-user-command [game-state] | |
| (let [ command (read-line) | |
| [function & args] (conj (into [] (.split command " ")) "game-state")] | |
| (do | |
| (println function args) | |
| (apply (symbol function) args)))) |
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
| object Instance { | |
| def parseCSV( instanceAsCSVString: String): Instance = { | |
| def extractFeatureValues( tokenizedFeatures: List[ String]): List[ Option[Double]] = { | |
| tokenizedFeatures.map { token => | |
| try { | |
| Some( token.toDouble) | |
| } catch { | |
| case nfe: NumberFormatException => { | |
| if ( token == "?") { | |
| None |