-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
weighted_heat_imputer.go
48 lines (40 loc) · 1006 Bytes
/
weighted_heat_imputer.go
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
package treemap
// WeightedHeatImputer will make color of parent to weighted sum of colors of its children.
type WeightedHeatImputer struct {
EmptyLeafHeat float64
}
func (s WeightedHeatImputer) ImputeHeat(t Tree) {
s.ImputeHeatNode(t, t.Root)
}
func (s WeightedHeatImputer) ImputeHeatNode(t Tree, node string) {
var heats []float64
var sizes []float64
for _, child := range t.To[node] {
s.ImputeHeatNode(t, child)
if t.Nodes[child].HasHeat {
sizes = append(sizes, t.Nodes[child].Size)
heats = append(heats, t.Nodes[child].Heat)
}
}
if n, ok := t.Nodes[node]; !ok || !n.HasHeat {
v := s.EmptyLeafHeat
if len(t.To[node]) > 0 {
var totalSize float64
for _, childSize := range sizes {
totalSize += childSize
}
v = 0.0
for i := range sizes {
v += heats[i] * sizes[i]
}
v /= totalSize
}
t.Nodes[node] = Node{
Path: t.Nodes[node].Path,
Name: t.Nodes[node].Name,
Size: t.Nodes[node].Size,
Heat: v,
HasHeat: true,
}
}
}