jitesh commited on
Commit
f5d1284
1 Parent(s): cb63a4b
Files changed (1) hide show
  1. src/probability_emote.py +71 -30
src/probability_emote.py CHANGED
@@ -26,6 +26,30 @@ def get_pe(w, ec=0.86, f=0.50):
26
  # print(f'f = {result}')
27
  return result
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  xdata1 = np.arange(0, 1.1, step=0.01)
31
  # rand = np.random.random_sample()
@@ -56,41 +80,54 @@ def get_text():
56
 
57
 
58
  @st.cache
59
- def get_equation_text(w=0.5, ec=0.7, rand=None, emotion_frequency=None):
60
- text = f'''
61
- #### Equation
62
- ```
63
- frequency_penalty = 1 - emotion_frequency
64
- probability_emote = w * emotion_confidence + (1 - w) * frequency_penalty
65
- ```
66
- **probability_emote** = {proper_float(w)} * {proper_float(ec)} + {proper_float(1-w)} * frequency_penalty
67
-
68
- '''
69
- if rand is not None:
70
- frequency_penalty = proper_float(1-emotion_frequency)
71
- probability_emote = proper_float((w)*(ec)+(1-w)*frequency_penalty)
72
  text = f'''
73
- #### Equation
74
- ```
75
- frequency_penalty = 1 - emotion_frequency = 1 - {proper_float(emotion_frequency)} = {frequency_penalty}
76
- probability_emote = w * emotion_confidence + (1 - w) * frequency_penalty
77
- probability_emote = {proper_float(w)} * {proper_float(ec)} + {proper_float(1-w)} * {frequency_penalty}
78
- ```
79
- **probability_emote** = {probability_emote}
80
- ```
81
- Show_Emotion
82
- = probability_emote > (Random value between 0 and 1)
83
- Random value = {rand}
84
- Show_Emotion = {probability_emote} > {rand}
85
- ```
86
- **Show_Emotion** = {probability_emote > rand}
87
- '''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  return text
89
 
90
 
91
 
92
 
93
  def run_probability_emote(container_param):
 
94
  w = set_input(container_param,
95
  label='Weight w', key_slider='w_slider', key_input='w_input',
96
  min_value=0.,
@@ -127,7 +164,7 @@ def run_probability_emote(container_param):
127
  emotion_frequency = 'emotion_frequency'
128
  rand = None
129
  st.markdown(get_equation_text(w=w, ec=score, rand=rand,
130
- emotion_frequency=emotion_frequency))
131
  fig = go.Figure()
132
  # fig.add_trace(go.Scatter(x=xdata1, y=np.ones_like(xdata1)*rand,
133
  # mode='markers', name='Random',
@@ -149,8 +186,12 @@ def run_probability_emote(container_param):
149
  mode='lines',
150
  line=dict(color='#ee00ee', width=8)
151
  ),)
 
 
 
 
152
  fig.add_trace(go.Scatter(
153
- x=xdata1, y=get_pe(w=w, f=xdata1, ec=score),
154
  mode='lines',
155
  name='Probability-Emote',
156
  line=dict(color='#00eeee', width=4)
 
26
  # print(f'f = {result}')
27
  return result
28
 
29
+ @st.cache
30
+ def get_pe2(w, ec=0.86, f=0.50):
31
+ result = 1-np.exp(-w*ec/(f+0.0001))
32
+ result = result
33
+ # result = np.clip(result, 0, 1)
34
+ # print(f'f = {result}')
35
+ return result
36
+
37
+ @st.cache(suppress_st_warning=True)
38
+ def get_pe3(w, ec=0.86, f=0.50):
39
+ result_np = np.zeros((len(f), len(f)))
40
+ st.markdown(result_np)
41
+ st.markdown(result_np[0])
42
+ for i, fi in enumerate(f):
43
+ result = 1-np.exp(-ec/f)
44
+ result = w*result
45
+ if i ==0:
46
+ result_np[i]=w*result
47
+ else:
48
+ result_np[i]=w*result + (1-w)*result_np[i-1]
49
+ # result = np.clip(result, 0, 1)
50
+ # print(f'f = {result}')
51
+ return result
52
+
53
 
54
  xdata1 = np.arange(0, 1.1, step=0.01)
55
  # rand = np.random.random_sample()
 
80
 
81
 
82
  @st.cache
83
+ def get_equation_text(w=0.5, ec=0.7, rand=None, emotion_frequency=None, graph_eq='PE1'):
84
+ if graph_eq=='PE1':
 
 
 
 
 
 
 
 
 
 
 
85
  text = f'''
86
+ #### Equation
87
+ ```
88
+ frequency_penalty = 1 - emotion_frequency
89
+ probability_emote = w * emotion_confidence + (1 - w) * frequency_penalty
90
+ ```
91
+ **probability_emote** = {proper_float(w)} * {proper_float(ec)} + {proper_float(1-w)} * frequency_penalty
92
+
93
+ '''
94
+ if rand is not None:
95
+ frequency_penalty = proper_float(1-emotion_frequency)
96
+ probability_emote = proper_float((w)*(ec)+(1-w)*frequency_penalty)
97
+ text = f'''
98
+ #### Equation
99
+ ```
100
+ frequency_penalty = 1 - emotion_frequency = 1 - {proper_float(emotion_frequency)} = {frequency_penalty}
101
+ probability_emote = w * emotion_confidence + (1 - w) * frequency_penalty
102
+ probability_emote = {proper_float(w)} * {proper_float(ec)} + {proper_float(1-w)} * {frequency_penalty}
103
+ ```
104
+ **probability_emote** = {probability_emote}
105
+ ```
106
+ Show_Emotion
107
+ = probability_emote > (Random value between 0 and 1)
108
+ Random value = {rand}
109
+ Show_Emotion = {probability_emote} > {rand}
110
+ ```
111
+ **Show_Emotion** = {probability_emote > rand}
112
+ '''
113
+ elif graph_eq=='PE2' or graph_eq=='PE3':
114
+ # probability_emote = 1 - e ^ (frequency / emotion_confidence)
115
+ text = f'''
116
+ #### Equation
117
+ ```
118
+ probability_emote = 1 - e ^ (- w * emotion_confidence / frequency)
119
+ ```
120
+ **probability_emote** = 1 - e ^ (- {proper_float(w)} * {proper_float(ec)} / frequency)
121
+
122
+ '''
123
+
124
  return text
125
 
126
 
127
 
128
 
129
  def run_probability_emote(container_param):
130
+ graph_eq = container_param.selectbox('Select Equation', ['PE1', 'PE2', 'PE3'])
131
  w = set_input(container_param,
132
  label='Weight w', key_slider='w_slider', key_input='w_input',
133
  min_value=0.,
 
164
  emotion_frequency = 'emotion_frequency'
165
  rand = None
166
  st.markdown(get_equation_text(w=w, ec=score, rand=rand,
167
+ emotion_frequency=emotion_frequency, graph_eq=graph_eq))
168
  fig = go.Figure()
169
  # fig.add_trace(go.Scatter(x=xdata1, y=np.ones_like(xdata1)*rand,
170
  # mode='markers', name='Random',
 
186
  mode='lines',
187
  line=dict(color='#ee00ee', width=8)
188
  ),)
189
+
190
+ if graph_eq=='PE1': get_result = get_pe
191
+ elif graph_eq=='PE2': get_result = get_pe2
192
+ elif graph_eq=='PE3': get_result = get_pe3
193
  fig.add_trace(go.Scatter(
194
+ x=xdata1, y=get_result(w=w, f=xdata1, ec=score),
195
  mode='lines',
196
  name='Probability-Emote',
197
  line=dict(color='#00eeee', width=4)