-
Notifications
You must be signed in to change notification settings - Fork 0
/
avgChi.py
executable file
·26 lines (20 loc) · 862 Bytes
/
avgChi.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
#this file uses the batch Chi^2 score files created by Chi.py and averages out the scores across batches to obtain approximate gloabl Chi^2 scores
import os
import numpy as np
import pandas as pd
numBatches = 20 #specify number of batches
files = []
for r, d, f in os.walk("batches/"):#get files containing Chi2 scores from folder "batches"
for file in f:
if 'chi' in file:
files.append(os.path.join(r, file))
sum = np.zeros(pd.read_csv(files[0]).fillna(0).to_numpy(dtype=float).shape, dtype=float)
for file in files: #sum scores over files while replacing NaNs with 0
sum = np.add(sum, pd.read_csv(file).fillna(0).to_numpy(dtype=float))
sum/=float(numBatches)#divide scores by number of batchs to obtain average scores
#save average scores
fp = open("globalChi.csv", "w")
for i in sum:
fp.write(str(i[0])+"\n")
fp.close()
print("DONE")