reflexive 2.1.0__py3-none-any.whl → 2.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,10 @@ from functools import partial
7
7
  import tarfile
8
8
  import json
9
9
  import os
10
- import numpy as np
10
+ from numpy import (
11
+ asarray,
12
+ dot
13
+ )
11
14
  from numpy.linalg import norm
12
15
  from itertools import chain
13
16
  from graph_tool.all import (
@@ -15,6 +18,7 @@ from graph_tool.all import (
15
18
  similarity,
16
19
  adjacency)
17
20
 
21
+
18
22
  ### PIPELINE FUNCTIONS
19
23
 
20
24
  # Clean text using supplied function and calculate text length
@@ -165,7 +169,7 @@ def _create_adj_matrix(weights:dict[tuple,float])->list[list[float]]:
165
169
  matrix.append(row)
166
170
  return matrix
167
171
 
168
- ### GRAPH ANALYSIS
172
+ ### SIMILARITY ANALYSIS
169
173
 
170
174
  def _jaccard_similarity(g1:Graph,g2:Graph)->float:
171
175
  return similarity(g1, g2,
@@ -173,10 +177,67 @@ def _jaccard_similarity(g1:Graph,g2:Graph)->float:
173
177
  #label1=g1.vp['v_labels'], label2=g2.vp['v_labels'],
174
178
  norm=True, p=1.0, distance=False, asymmetric=False)
175
179
 
176
- def _cosine_similarity(m1,m2)->float:
177
- v1 = list(chain.from_iterable(m1))
178
- v2 = list(chain.from_iterable(m2))
179
- return np.dot(v1,v2)/(norm(v1)*norm(v2))
180
+ # def _cosine_similarity(m1,m2)->float:
181
+ # v1 = list(chain.from_iterable(m1))
182
+ # v2 = list(chain.from_iterable(m2))
183
+ # return np.dot(v1,v2)/(norm(v1)*norm(v2))
184
+
185
+ def _vectorise_adj(matrix):
186
+ return list(chain.from_iterable((matrix[i][j] for j in range(i,5)) for i in range(5)))
187
+
188
+ def zero_pos(am):
189
+ nm = []
190
+ for r,row in enumerate(am):
191
+ nr = []
192
+ for c,weight in enumerate(row):
193
+ if r < 3 or c < 3:
194
+ nr.append(weight)
195
+ else:
196
+ nr.append(0)
197
+ nm.append(nr)
198
+ return nm
199
+
200
+ def zero_mod(am):
201
+ nm = []
202
+ for r,row in enumerate(am):
203
+ nr = []
204
+ for c,weight in enumerate(row):
205
+ if r >= 3 or c >= 3:
206
+ nr.append(weight)
207
+ else:
208
+ nr.append(0)
209
+ nm.append(nr)
210
+ return nm
211
+
212
+ def _adj_vector(adj_matrix):
213
+ return _vectorise_adj(adj_matrix)
214
+
215
+ def _positional_vector(adj_matrix):
216
+ return _vectorise_adj(zero_pos(adj_matrix))
217
+
218
+ def _modal_vector(adj_matrix):
219
+ return _vectorise_adj(zero_mod(adj_matrix))
220
+
221
+ def _cosine(A,B):
222
+ return dot(A,B)/(norm(A)*norm(B))
223
+
224
+ def _am4idx(df,idx:int):
225
+ return df.res_adj_matrix[idx]
226
+
227
+ def _similarity(m1,m2,vector_func):
228
+ return float(_cosine(vector_func(m1),vector_func(m2)))
229
+
230
+ def _res_similarity(df,idx1,idx2,vector_func):
231
+ return _similarity(_am4idx(df,idx1),_am4idx(df,idx2),vector_func)
232
+
233
+ _interaction_similarity = partial(_res_similarity,vector_func=_adj_vector)
234
+ _positional_similarity = partial(_res_similarity,vector_func=_positional_vector)
235
+ _modal_similarity = partial(_res_similarity,vector_func=_modal_vector)
236
+
237
+ def _similarities(df,idx1,idx2):
238
+ return {"interaction": _interaction_similarity(df,idx1,idx2),
239
+ "positional": _positional_similarity(df,idx1,idx2),
240
+ "modal":_modal_similarity(df,idx1,idx2)}
180
241
 
181
242
 
182
243
 
reflexive/res_analysis.py CHANGED
@@ -23,7 +23,7 @@ from reflexive.analysis_functions import (
23
23
  _add_semantic_weights,
24
24
  _add_res_adj_matrix,
25
25
  _jaccard_similarity,
26
- _cosine_similarity,
26
+ _similarities,
27
27
  _date_string,
28
28
  _create_local_dir
29
29
  )
@@ -131,8 +131,9 @@ class RES_analyser:
131
131
  def get_jaccard_similarity(self,g1,g2):
132
132
  return _jaccard_similarity(g1,g2)
133
133
 
134
- def get_cosine_similarity(self,m1,m2):
135
- return _cosine_similarity(m1,m2)
134
+ def get_cosine_similarities(self,df,idx1,idx2):
135
+ return _similarities(df,idx1,idx2)
136
+
136
137
 
137
138
  ############################################################
138
139
  # UTILITY METHODS
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reflexive
3
- Version: 2.1.0
3
+ Version: 2.2.0
4
4
  Summary: Supports AWS Reflexive Expressions Systems (RES) Analysis
5
5
  Project-URL: Repository, https://github.com/nlytx/reflexive.git
6
6
  Author-email: Andrew Gibson <andrew@nlytx.io>
@@ -0,0 +1,9 @@
1
+ reflexive/__init__.py,sha256=UkA6xvSu40CGYguUuiBqBMnPBkld0h0GR9UnZrptdZI,167
2
+ reflexive/analysis_functions.py,sha256=ufB2AGaJyFZKYHppa7T30YYdONEotHVvLkrxMHFfKJE,16191
3
+ reflexive/display_functions.py,sha256=2LdkINOgmZfiV7nkW0x_IeimxW3J80YIOOnjX21-RJA,5699
4
+ reflexive/res_analysis.py,sha256=ZeXMA8ckRo1UCct4F4tjCwLbU3iBwShiIvnVGwP-x7E,7453
5
+ reflexive/service.py,sha256=O0MX2BCHTSNG_eW6LHBN1FOjaNTCGgYgh7vsk58NNAk,1927
6
+ reflexive-2.2.0.dist-info/METADATA,sha256=FNVFaVGcF8Oi7KuvM18RenUG5f4wNeVZSRY-ae7P_5s,574
7
+ reflexive-2.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
+ reflexive-2.2.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
9
+ reflexive-2.2.0.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- reflexive/__init__.py,sha256=UkA6xvSu40CGYguUuiBqBMnPBkld0h0GR9UnZrptdZI,167
2
- reflexive/analysis_functions.py,sha256=Qlod0svjBu9kRtGwPL-tPWnrYKLO-QTe07jSrxHZ6-k,14468
3
- reflexive/display_functions.py,sha256=2LdkINOgmZfiV7nkW0x_IeimxW3J80YIOOnjX21-RJA,5699
4
- reflexive/res_analysis.py,sha256=1W7Mph30s4qiV63CsN3IDxIydvYelOu28aVdsmF8gcs,7442
5
- reflexive/service.py,sha256=O0MX2BCHTSNG_eW6LHBN1FOjaNTCGgYgh7vsk58NNAk,1927
6
- reflexive-2.1.0.dist-info/METADATA,sha256=ulz3xZXF5W41XSq6ZEVF5Nfyi_18vBQ4ie6FA1F7bdo,574
7
- reflexive-2.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
- reflexive-2.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
9
- reflexive-2.1.0.dist-info/RECORD,,