-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_utility.py
executable file
·39 lines (34 loc) · 1.06 KB
/
my_utility.py
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
"""
my utility
"""
import os
import numpy as np
def read_uncertainty(f_n_1, f_n_2, exclude=None):
"""
read in uncertainty and normalize
"""
u_const = np.loadtxt(f_n_1, dtype=float, delimiter=',', comments='#')
u_random = np.loadtxt(f_n_2, dtype=float, delimiter=',', comments='#')
# data modification, logendre polynomial is orthonormal in the range of
# (-1, 1)
for i, _ in enumerate(u_const):
# species case when u_const is 1.0
if u_const[i] == 1.0:
u_random[:, i] = u_random[:, i] * 0.0
continue
u_random[:, i] = (u_random[:, i] - 1 / u_const[i]) \
/ (u_const[i] - 1 / u_const[i])
u_random[:, i] = u_random[:, i] * 2 - 1
if exclude is not None:
include = []
for i in range(len(u_const)):
if i not in exclude:
include.append(i)
u_random = u_random[:, include]
return u_random
def read_target(f_n):
"""
read in target
"""
target = np.loadtxt(f_n, dtype=float, delimiter=',', comments='#')
return target