forked from anonymous-ACE-KL/ACE-KL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_acekl.py
46 lines (38 loc) · 1013 Bytes
/
run_acekl.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
40
41
42
43
44
45
46
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from sklearn import preprocessing
import pandas as pd
import sys
from scipy.stats import spearmanr, describe
from ace import ace_explainer_pt
import csv
import cPickle as cpkl
import pdb
def main():
"""
load data
"""
X = np.load(sys.argv[1])
X = np.where(X == 0, -1, 1).astype(np.float32)
# print X
y = np.load(sys.argv[2])
y = -np.log(y).astype(np.float32)
examed_example = X[0]
input_dim = len(examed_example)
# pdb.set_trace()
"""
acekl
"""
acekl_explner = ace_explainer_pt.AceExplainer(examed_example, input_dim, is_usekl=True)
print 'Training ACE-KL...'
acekl_exp = acekl_explner.explain_instance(X, y)
print 'Trained ACE-KL.'
print acekl_exp.as_map()
acekl_res = sorted(acekl_exp.as_map(), key=lambda x: x[0])
print acekl_res
# pdb.set_trace()
if __name__ == '__main__':
main()