-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
47 lines (37 loc) · 1.59 KB
/
utils.py
File metadata and controls
47 lines (37 loc) · 1.59 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
import os
import pandas as pd
# Write from a dictionary to a file
def writeDictionary(dictionary, filename):
with open(filename, 'w') as file:
for key, value in dictionary.items():
file.write('%s;%s\n' % (key, value))
# Read all from a file to a dictionary
def readDictonary(filename):
dictionary = {}
if not os.path.isfile(filename):
return dictionary
with open(filename, 'r') as file:
for line in file:
key, value = line.split(';')
# Check if the value is a float
dictionary[key] = float(value)
return dictionary
def mifs_caching_init(path, df_filename, discreteDf_filename, entropyFilename, jointEntropyFilename):
discreteDf_filename = df_filename[:-4] + '_' + discreteDf_filename
entropyFilename = df_filename[:-4] + '_' + entropyFilename
jointEntropyFilename = df_filename[:-4] + '_' + jointEntropyFilename
discreteDf = None
try:
discreteDf = pd.read_csv(path + discreteDf_filename)
except FileNotFoundError:
pass
if discreteDf is None:
entropyCache = {}
jointEntropyCache = {}
else:
entropyCache = readDictonary(path + entropyFilename)
jointEntropyCache = readDictonary(path + jointEntropyFilename)
return discreteDf, entropyCache, jointEntropyCache, discreteDf_filename, entropyFilename, jointEntropyFilename
def mifs_caching_flush(path, entropyCache, jointEntropyCache, entropyFilename, jointEntropyFilename):
writeDictionary(entropyCache, path + entropyFilename)
writeDictionary(jointEntropyCache, path + jointEntropyFilename)