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
-- Desc: A simple gradient descent algorithm in Haskell | |
-- Author: Garrett Bluma | |
-- Date: March 12, 2013 | |
gradientDescent :: Double -> Double -> Double -> Double -> (Double -> Double) -> Double | |
gradientDescent goal step x x_prev f | |
| (abs(x-x_prev) > goal) = gradientDescent goal step (x - step * (f x)) x f | |
| otherwise = x | |
main = do |
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
-- Desc: A direct port of SICP half-interval-method. | |
-- Author: Garrett Bluma | |
-- Date: March 17, 2013 | |
average a b = (a + b) / 2.0 | |
close_enough a b = abs (b - a) < 0.001 | |
search f neg_point pos_point = |
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
#lang slideshow | |
;; a function to draw a nice node | |
(define (node name prob) | |
(rb-superimpose ; attach to right-bottom of box | |
(text (string-append prob " ") ; add label for failure probability | |
null 9 0) | |
(cc-superimpose ; center pictures on top of eachother | |
(text name) ; output text | |
(rectangle 100 35)))) ; draw box |
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
#lang plai | |
(define-type AE | |
[num (n number?)] | |
[add (lhs AE?) (rhs AE?)] | |
[sub (lhs AE?) (rhs AE?)]) | |
(define (parse sexp) | |
(cond | |
[(number? sexp) (num sexp)] |
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
good_enough(f, guess) := | |
if (cabs(f(guess))<1E-15) then true | |
else false$ | |
improve(f, guess) := | |
guess - (f(guess)/(at (diff (f(z), z, 1), [z = guess])))$ | |
newton(f,guess) := | |
if (good_enough(f,guess)=true) | |
then guess |
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
(defun inner (k n) | |
(cond | |
((> (* k k) n) 1) | |
((= 0 (mod n k)) 0) | |
(t (inner (+ k 2) n)))) | |
(defun is_prime (n) | |
(cond | |
((= n 2) 1) | |
((< n 2) 0) |
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 zlib, os, sys | |
def getsize(s): | |
return len(zlib.compress(s)) | |
def dist(a, b): | |
n1 = getsize(a); n2=getsize(b) | |
return (min(getsize(a+b), getsize(b+a)) - min(n1,n2))/float(max(n1,n2)) |
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
<?php | |
class Matcher { | |
private $cases = array(); | |
function __construct($target, $source) { | |
$this->target = $target; | |
$this->source = $source; | |
} |
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
#lang typed/racket | |
;; We get exhaustive pattern matching | |
(: f ((U String Integer) -> Boolean)) | |
(define (f x) | |
(cond | |
[(string? x) (string=? x "hi")] ; covers string needs | |
[(exact-nonnegative-integer? x) (= x 7)] ; covers positive integers | |
[(even? x) (= x -8)] ; we can actually cover a subset of negative integers |
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
:syntax on | |
"Syntax Support | |
au BufRead,BufNewFile *.md set syntax=tex | |
:autocmd FileType * set formatoptions=tcql nocindent comments& | |
:autocmd FileType c,cpp set formatoptions=croql cindent comments=sr:/*,mb:*,ex:*/,:// | |
au FileType htm,html,xhtml,xml so ~/.vim/ftplugin/html_autoclosetag.vim | |
au BufRead,BufNewFile *.fs,*.fsx set filetype=fs | |
au BufRead,BufNewFile *.fs,*.fsx set syntax=ocaml | |
au! BufRead,BufNewFile *.gsl setfiletype gsl |