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
data NewFloat a = F a deriving (Eq,Ord,Show) | |
instance RealFloat a => Num (NewFloat a) where | |
F x + F y = F (x + y) | |
F x - F y = F (x - y) | |
F x * F y = F (x * y) | |
fromInteger n = F (fromInteger n) | |
abs = newAbs | |
signum = newSignum |
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
-- A semi-fast isPrime algorithm | |
noDivs factors n = foldr (\f r -> f*f > n || (rem n f /= 0 && r)) | |
True factors | |
primesTD = 2 : 3 : filter (noDivs $ tail primesTD) [5,7..] | |
isPrime n = n > 1 && noDivs primesTD n | |
divides a b = b `mod` a == 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
{-# LANGUAGE MultiParamTypeClasses #-} | |
import Data.Maybe | |
import Data.List as List | |
-- Group stuff | |
class Group g where | |
eye :: g | |
(%) :: g -> g -> g |
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 [T Y] = relent(Tspan) | |
%% Configuration | |
leg = {'Species 1','Species 2'}; | |
opts = odeset(); | |
opts.AbsTol = 1e-8; | |
opts.RelTol = 1e-4; |
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
module Module1 where | |
import Control.Monad.Reader | |
data Config = Config { arg :: Int } | |
initialize :: IO Config | |
initialize = do | |
n <- getLine | |
return $ Config (read n) |
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
{-# LANGUAGE ViewPatterns, GADTs, ScopedTypeVariables #-} | |
-- Functions to fold and unfold. We are using ViewPatterns to make the symmetry between fold and unfold explicity. | |
foldr2 :: (Either (a,b) () -> b) -> [a] -> b | |
foldr2 f [] = f $ Right () | |
foldr2 f (x:xs) = f $ Left (x, foldr2 f xs) | |
unfoldr2 :: (b -> Either (a,b) ()) -> b -> [a] | |
unfoldr2 f (f -> Right () ) = [] |
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 [plate cellLocs] = simCancer(sz,pDiv,maxCells) | |
directions = [1 0; -1 0; 0 1; 0 -1]; % Possible grid directions | |
plate = zeros(sz); % Initial state of the plate | |
cellLocs = zeros(sz*sz,2); % (x,y) location of cells | |
numCells = 1; % Initial number of cells | |
generation = 1; % Initial generation |
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
%Uniform distribution | |
x1 = randi(10,1000,1); | |
[n1 xout1] = hist(x1); | |
%Sum of uniform distribution | |
x2 = sum(randi(10,1000,12),2); | |
m = mean(x2); | |
s = std(x2); | |
[n2 xout2] = hist(x2); |
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
State Winner Confidence | |
California DEM 100% | |
Connecticut DEM 100% | |
District of Columbia DEM 100% | |
Massachusetts DEM 100% | |
New York DEM 100% | |
Vermont DEM 100% | |
Maryland DEM 100% | |
Washington DEM 100% | |
Hawaii DEM 100% |
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 em(X,theta) | |
% Expectation maximization, P coins | |
% | |
% X is TxN matrix of coin flip results (1 = heads, 0 = tails) | |
% theta is 1xP vector of probabilities (0 < theta < 1) | |
% Convergence criterion (relative difference) | |
tol = 1e-6; | |
% Compute parameters of distribution assigning coins to outputs |