Skip to content

Commit

Permalink
added interface files and a few changes for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
cyocum committed Nov 30, 2010
1 parent 8e24fcb commit 383975a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
@@ -1,5 +1,5 @@
build:
ocamlfind ocamlopt -package batteries -linkpkg -o football lanczos.ml bessel.ml skellam.ml
ocamlfind ocamlopt -package batteries -linkpkg -o football lanczos.mli bessel.mli lanczos.ml bessel.ml skellam.ml

clean:
rm *.cm* *.o football
9 changes: 4 additions & 5 deletions bessel.ml
@@ -1,24 +1,23 @@
let factorial n =
let rec f n a =
let rec fact_aux n a =
match n with
| 0 -> a
| _ -> f (n-1) (n*a)
| _ -> fact_aux (n-1) (n*a)
in
f n 1
fact_aux n 1

let mod_bessel_first m a =
(1. /. ((float (factorial m)) *. (Lanczos.gamma (float (m + a + 1)))))

let mod_bessel_second m x a =
x /. 2. ** (float (2 * m + a))
(x /. 2.) ** (float (2 * m + a))

let mod_bessel m a x =
(mod_bessel_first m a) *. (mod_bessel_second m x a)

let run_mod_bessel a x =
let range = (BatList.of_enum (BatEnum.range 0 ~until:50)) in
let ans_list = BatList.map (fun m -> mod_bessel m a x) range in
(*List.iter (fun x -> print_endline (string_of_float x)) ans_list;*)
List.fold_left (+.) 0. ans_list


1 change: 1 addition & 0 deletions bessel.mli
@@ -0,0 +1 @@
val run_mod_bessel : int -> float -> float
2 changes: 2 additions & 0 deletions lanczos.mli
@@ -0,0 +1,2 @@
val gamma : float -> float
val e : float
29 changes: 26 additions & 3 deletions skellam.ml
@@ -1,10 +1,33 @@
let home_team_gpm = (float_of_string Sys.argv.(1))
let away_team_gpm = (float_of_string Sys.argv.(2))

let skellam k u1 u2 =
let first = Lanczos.e ** -.(u1 +. u2) in
let second = (u1 /. u2) ** ((float k) /. 2.) in
let third = 2. *. sqrt (u1 +. u2) in
first *. second *. (Bessel.run_mod_bessel (abs k) third)

let cartesian_product xs ys =
List.rev
(List.fold_left (fun acc x ->
List.fold_left (fun acc y ->
(x,y) :: acc)
acc ys)
[] xs)

let run_prediction = function
(home, away) -> skellam (home-away) home_team_gpm away_team_gpm

let print_predictions pred scores =
match scores with
(home, away) ->
let home_str = string_of_int home in
let away_str = string_of_int away in
let pred_str = string_of_float pred in
print_endline (home_str ^ " - " ^ away_str ^ " --> " ^ pred_str)

let _ =
let blah = -1 in
let output = skellam blah 1.5 2.0 in
print_endline (string_of_float output)
let range = BatList.of_enum (BatEnum.range 0 ~until:5) in
let scores = cartesian_product range range in
let predictions = BatList.map run_prediction scores in
BatList.iter2 print_predictions predictions scores

0 comments on commit 383975a

Please sign in to comment.