-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGTCext.py
More file actions
108 lines (89 loc) · 3.03 KB
/
Copy pathGTCext.py
File metadata and controls
108 lines (89 loc) · 3.03 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import GTC
import numpy as np
def inv(a): #this function is added cause of error in original linear algebra file
b = np.identity(a.shape[0], a.dtype)
return GTC.LU.invab(a, b)
def python_list_transposition(list_2D):
np_list=np.array(list_2D)
return np.transpose(np_list).tolist()
def convert_value_to_2Dlist(value):
if isinstance(value, int) or isinstance(value, float): # check if list is single value
value = [[value]]
else:
# find size of value_list
try:
len(value[0])
except: # if list is 1D convert to 2D
value = [value]
return value
def urealext(value_list, unc_list=0.0, k=2, array_label='X', df=GTC.inf):
# INPUT variables:
# for value_list are:
# <class 'list'>
# <class 'numpy.ndarray'>
# <class 'int'>
# <class 'float'>
# for unc_list are:
# <class 'list'>
# <class 'numpy.ndarray'>
# <class 'int'>
# <class 'float'>
# for k are:
# <class 'int'>
# <class 'float'>
# for value_name are:
# <class 'string'>
value_list=convert_value_to_2Dlist(value_list)
unc_list2D =convert_value_to_2Dlist(unc_list)
n_rows = len(value_list)
n_cols = len(value_list[0])
if df == 'N':
df = n_rows * n_cols - 1
realnumber_list = [[0 for x in range(n_cols)] for x in range(n_rows)]
for i in range(n_rows):
for j in range(n_cols):
label = array_label + str(i) + '_' + str(j)
if isinstance(unc_list, int) or isinstance(unc_list, float):
unc_std = unc_list / k
else:
unc_std = unc_list2D[i][j] / k
realnumber_list[i][j] = GTC.ureal(x=value_list[i][j], u=unc_std, label=label, df=df)
unc_array = GTC.la.uarray(realnumber_list)
return unc_array
def isGTC(value):
typeGTC = type(GTC.ureal(0, 0))
if type(value) == typeGTC:
return True
else:
return False
# converting float type to GTC uncertainty type
def float2GTC(value):
if isGTC(value):
return value
else:
return GTC.ureal(value, 0)
def calculate_func_from_UncertainArray(function_name, uncertain_array):
"""
:param function_name: name of function to calculate form ureal type argument
:param uncertain_array: array built from UrealArray type
:return: values of function calculated for each UrealArray element
"""
n_rows = len(uncertain_array)
n_cols = len(uncertain_array[0])
output_array = [[0 for x in range(n_cols)] for x in range(n_rows)]
for i in range(n_rows):
for j in range(n_cols):
output_array[i][j] = function_name(uncertain_array[i][j])
return output_array
def pinv(GTC_array):
# A+=(AtxA)^1 x At
A=GTC_array
At = GTC.la.transpose(A)
AtA = GTC.la.matmul(At, A)
invAtA = inv(AtA) #corrected version of GTC inv
pinvA = GTC.la.matmul(invAtA, At)
return pinvA
def psolve(A,B):
pinvA=pinv(A)
result=GTC.la.matmul(pinvA,B)
return result