Created
February 15, 2016 11:35
-
-
Save Killavus/411e3c3308c4d4245102 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fix_similarity_symmetricity(vertices_map): | |
| fixed_records = 0 | |
| unequal_records = 0 | |
| for v1key in vertices_map: | |
| v1 = vertices_map[v1key] | |
| for v1index, v1similar in enumerate(v1['similars']): | |
| v2key, v1v2similar = v1similar | |
| if v2key not in vertices_map: | |
| continue | |
| v2 = vertices_map[v2key] | |
| is_symmetric = False | |
| for v2index, v2similar in enumerate(v2['similars']): | |
| vskey, v2v1similar = v2similar | |
| if vskey != v1key: | |
| continue | |
| else: | |
| is_symmetric = True | |
| vertices_map[v1key]['similars'][v1index] = [v2key, max(v1v2similar, v2v1similar)] | |
| vertices_map[v2key]['similars'][v2index] = [v1key, max(v1v2similar, v2v1similar)] | |
| if math.fabs(v1v2similar - v2v1similar) >= 0.0001: | |
| unequal_records += 1 | |
| if not is_symmetric: | |
| vertices_map[v2key]['similars'].append([v1key, v1v2similar]) | |
| fixed_records += 1 | |
| return fixed_records, unequal_records |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment