sdbrgo commited on
Commit
262d143
·
verified ·
1 Parent(s): 83648c5

Update phase/compute.py

Browse files

placed noncomparable components into a separate dictionary (components_2)

Files changed (1) hide show
  1. phase/compute.py +16 -12
phase/compute.py CHANGED
@@ -6,7 +6,8 @@ class ParticipationAdoptionIndex:
6
  self.feedback_volume = feedback_volume
7
  self.w_pos = w_pos
8
  self.w_neg = w_neg
9
- self.components = {}
 
10
 
11
  # ---------- helper functions ----------
12
  def _compute_pci(self, participants_by_group):
@@ -22,20 +23,20 @@ class ParticipationAdoptionIndex:
22
  return sum(s ** 2 for s in shares)
23
 
24
  def _normalize_components(self):
25
- total = sum(abs(v["value"]) for v in self.components.values())
26
 
27
  if total == 0:
28
- for k in self.components:
29
- if self.components[k]["value"] is not None:
30
- self.components[k]["value"] = 0.0
31
  else:
32
- for k in self.components:
33
- self.components[k]["value"] /= total
34
 
35
  def _sort_components(self):
36
  return dict(
37
  sorted(
38
- self.components.items(),
39
  key=lambda item: abs(item[1]["value"]),
40
  reverse=True
41
  )
@@ -65,15 +66,18 @@ class ParticipationAdoptionIndex:
65
  # SPA: Sentiment Participation Assymetry
66
  # PEG: Participation-to-Expression Gap
67
 
68
- self.components = {
69
  "PCR": {"value": pcr, "description": "Participation Ratio"},
70
- "PCI": {"value": pci, "description": "Participation Concentration"},
71
  "SPI-A": {"value": spi_a, "description": "Silent Non-Adoption"},
72
  "SPI-B": {"value": spi_b, "description": "Silent Adoption"},
73
- "SPA": {"value": spa, "description": "Sentiment Asymmetry"},
74
  "PEG": {"value": peg, "description": "Participation-to-Expression Gap"}
75
  }
76
 
 
 
 
 
 
77
  self._normalize_components()
78
 
79
- return self._sort_components()
 
6
  self.feedback_volume = feedback_volume
7
  self.w_pos = w_pos
8
  self.w_neg = w_neg
9
+ self.components_1 = {}
10
+ self.components_2 = {}
11
 
12
  # ---------- helper functions ----------
13
  def _compute_pci(self, participants_by_group):
 
23
  return sum(s ** 2 for s in shares)
24
 
25
  def _normalize_components(self):
26
+ total = sum(abs(v["value"]) for v in self.components_1.values())
27
 
28
  if total == 0:
29
+ for k in self.components_1:
30
+ if self.components_1[k]["value"] is not None:
31
+ self.components_1[k]["value"] = 0.0
32
  else:
33
+ for k in self.components_1:
34
+ self.components_1[k]["value"] /= total
35
 
36
  def _sort_components(self):
37
  return dict(
38
  sorted(
39
+ self.components_1.items(),
40
  key=lambda item: abs(item[1]["value"]),
41
  reverse=True
42
  )
 
66
  # SPA: Sentiment Participation Assymetry
67
  # PEG: Participation-to-Expression Gap
68
 
69
+ self.components_1 = {
70
  "PCR": {"value": pcr, "description": "Participation Ratio"},
 
71
  "SPI-A": {"value": spi_a, "description": "Silent Non-Adoption"},
72
  "SPI-B": {"value": spi_b, "description": "Silent Adoption"},
 
73
  "PEG": {"value": peg, "description": "Participation-to-Expression Gap"}
74
  }
75
 
76
+ self.components_2 = {
77
+ "PCI": {"value": pci, "description": "Participation Concentration"},
78
+ "SPA": {"value": spa, "description": "Sentiment Asymmetry"},
79
+ }
80
+
81
  self._normalize_components()
82
 
83
+ return self._sort_components(), self.components_2