-
Notifications
You must be signed in to change notification settings - Fork 0
/
soc_run_skew.ml
57 lines (46 loc) · 2.11 KB
/
soc_run_skew.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
open Common
include Sgraph
let socDay = Socday.socDay Suds.socUserDaySum
type socRun = { alphaSR : float; betaSR : float; gammaSR : float;
socInitSR : float;
useInAllSR : bool; inAllDownSR : bool;
byMassSR : bool; skewTimesSR : int;
maxDaysSR : int option }
let optSocRun : socRun =
{ alphaSR = 0.1; betaSR = 0.5; gammaSR = 0.5;
socInitSR = 1.0;
useInAllSR = true; inAllDownSR = false;
byMassSR = false; skewTimesSR = 8;
maxDaysSR = None }
let paramSC {alphaSR =a; betaSR =b; gammaSR =g;
useInAllSR =use_in_all; inAllDownSR =in_all_down;
byMassSR =by_mass; skewTimesSR =skew_times} =
(a, b, g, use_in_all, in_all_down, by_mass, skew_times)
let socRun dreps dments opts =
let params = paramSC opts in
let socInit = opts.socInitSR in
let ustats = usersHash () in
let dcaps = usersHash () in
let dskews = usersHash () in
let sgraph = sgraphInit dreps dments ustats in
let dstarts,(firstDay,lastDay) = Dranges.startsRange dreps dments in
let lastDay = match opts.maxDaysSR with
| None -> lastDay
| Some n -> min lastDay (firstDay + n - 1) in
leprintfln "%d total users, doing days from %d to %d" (H.length dstarts) firstDay lastDay;
(* inject the users first appearing in this cycle *)
let tick ts day =
let ustats = sgraph.ustatsSG in
let newUsers = H.find dstarts day in
leprintfln "adding %d users on day %d" (List.length newUsers) day;
List.iter (fun user -> H.add ustats user (newUserStats socInit day)) newUsers;
leprintfln "now got %d" (H.length ustats);
let _,skews = socDay sgraph params day in
let t = Some (sprintf "day %d timing: " day) |> getTiming in
H.iter (updateFromUStats dcaps statSoc day) ustats;
H.iter (updateUserDaily dskews day) skews;
t::ts in
let theDays = Enum.seq firstDay succ (fun x -> x <= lastDay) in
(* this is a two-headed eagle, imperative in sgraph, functional in timings *)
let timings = Enum.fold tick [] theDays in
sgraph,dcaps,dskews,timings