-
Notifications
You must be signed in to change notification settings - Fork 0
/
socday.ml
68 lines (55 loc) · 2.51 KB
/
socday.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
58
59
60
61
62
63
64
65
66
67
68
open Common
open Sgraph
let version = "normalizing"
let socDay socUserDaySum sgraph params day =
let (alpha, beta, gamma, use_in_all, in_all_down, by_mass, skew_times) = params in
let {ustatsSG =ustats} = sgraph in
(* TODO how do we employ const |_ ... instead of the lambda below? *)
let termsStats = H.map (socUserDaySum sgraph day) ustats in
let sumTerms = termsStats |> H.values |> enumCatMaybes in
let outSum,inSumBack,inSumAll = Enum.fold (fun (x,y,z) (x',y',z') -> (x+.x',y+.y',z+.z'))
(0.,0.,0.) sumTerms in
(* instead of inSumAll *. inSumAll /. inSumBack, we divide first, then multiply, to limit range;
NB: when playing with negative capital, in order to preserve the final sign, don't use fabs! *)
let inSumAll = if in_all_down then inSumAll /. inSumBack *. inSumAll else inSumAll in
let norms = outSum,inSumBack,inSumAll in
leprintfln "day %d norms: [%F %F %F]" day (fst3 norms) (snd3 norms) (trd3 norms);
let skews = usersHash () in
(* : user -> ((float * float * float) option * ustats) -> ustats *)
let tick : user -> ustats -> terms_stat -> ustats =
fun user stats numers ->
let {socUS =soc; insUS =ins; outsUS =outs} = stats in
let soc' =
match numers with
| Some numers ->
let (outs', insBack', insAll') =
safeDivide3 numers norms
in
let ins' =
if use_in_all then
gamma *. insBack' +. (1. -. gamma) *. insAll'
else
insBack'
in
alpha *. soc +. (1. -. alpha) *.
(beta *. outs' +. (1. -. beta) *.
ins')
| None -> alpha *. soc in
let stats' = {stats with socUS = soc'} in
(* TODO we might just keep the pairs as yet anotehr hastbatle;
we may then finally optimize data structure by sharing inverted pairs...
*)
if not (H.is_empty ins) then
begin (* TODO outs are from dm's, ins are from dr's! Revert? *)
let rewards_contributions = H.map begin fun mentioner nments ->
let nreps = H.find_default outs mentioner 0 in
nreps,nments
end ins |> H.values |> A.of_enum in
A.sort compPairDesc2 rewards_contributions;
let rewards, contributions = array_split rewards_contributions in
let skew' = Skew.skew ~by_mass ~skew_times rewards contributions in
if skew' <> [] then skews <-- (user,skew') else ()
end else ();
stats' in
hashUpdateWithImp tick ustats termsStats;
norms,skews