Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added interface files and a few changes for clarity
- Loading branch information
Showing
5 changed files
with
34 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
val run_mod_bessel : int -> float -> float |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
val gamma : float -> float | ||
val e : float |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |