-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompare_root.py
More file actions
51 lines (45 loc) · 2.02 KB
/
Compare_root.py
File metadata and controls
51 lines (45 loc) · 2.02 KB
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
49
50
51
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 27 20:06:51 2020
@author: sr917
"""
import numpy as np
import pandas as pd
import ast as ast
def obtained_roots(filename,decimal_places):
"""
Obatain roots from our homotopy continuation in format required
"""
df = pd.read_csv(filename)
roots = df['Roots']
roots = [np.around(ast.literal_eval(roots[i]), decimal_places) for i in range(len(roots))]
return roots
def checking_roots(filename, decimal_places):
"""
Obtain roots from the julia implementation in format required
"""
datadf = pd.read_csv(filename, header=None)
return [[np.around(complex(datadf[j][i].replace("im", "j").replace(" ", "")), decimal_places) for j in datadf.columns] for i in range(len(datadf))]
def compare_values(filename1, filename2, decimal_places):
"""
Compares the 2 sets of roots from our implementation and that from the julia implemenation.
Returns the array of similar roots
filename1: Filename of our implementation
filename2: Filename of julia implemenatation
"""
roots_we_found = obtained_roots(filename1, decimal_places)
print('Number of our implementation Homotopy Roots : {}'.format(len(roots_we_found)))
roots_by_other_implementation = checking_roots(filename2, decimal_places)
print('Number of roots by Julia Implementation : {}'.format(len(roots_by_other_implementation)))
number_of_different_roots=0
numer_of_similar_roots=0
same_result = []
for i in range(len(roots_we_found)):
for j in range(len(roots_by_other_implementation)):
if len(set(roots_we_found[i]) & set(roots_by_other_implementation[j])) != len(roots_we_found[i]):
number_of_different_roots +=1
else:
numer_of_similar_roots += 1
same_result.append(set(roots_we_found[i]) & set(roots_by_other_implementation[j]))
print('Number of similar roots found : {}'.format(numer_of_similar_roots))
return same_result