update print and output json statements
This commit is contained in:
@@ -102,6 +102,7 @@ class TaskModel():
|
||||
mask = ~np.isnan(labels)
|
||||
labels = labels[mask]
|
||||
features = features[mask]
|
||||
# features = str(features)
|
||||
self.model.fit(features, labels)
|
||||
y_pred = self.model.predict(features)
|
||||
perf = self.metric_func(labels, y_pred)
|
||||
@@ -136,7 +137,7 @@ class TaskModel():
|
||||
print(f'{self.task_name} performance: {perf}')
|
||||
return perf
|
||||
|
||||
def __call__(self, smiles_list):
|
||||
def __call(self, smiles_list):
|
||||
fps = []
|
||||
mask = []
|
||||
for i,smiles in enumerate(smiles_list):
|
||||
@@ -153,6 +154,54 @@ class TaskModel():
|
||||
scores = scores * np.array(mask)
|
||||
return np.float32(scores)
|
||||
|
||||
def __call__(self, graph_list):
|
||||
# def read_adj_ops_from_json(filename):
|
||||
# with open(filename, 'r') as json_file:
|
||||
# data = json.load(json_file)
|
||||
|
||||
# adj_ops_pairs = []
|
||||
# for item in data:
|
||||
# adj_matrix = np.array(item['adj_matrix'])
|
||||
# ops = item['ops']
|
||||
# acc = item['train'][0]['accuracy']
|
||||
# adj_ops_pairs.append((adj_matrix, ops, acc))
|
||||
|
||||
# return adj_ops_pairs
|
||||
def feature_from_adj_and_ops(ops, adj):
|
||||
return np.concatenate([adj.flatten(), ops])
|
||||
# filename = '/home/stud/hanzhang/nasbenchDiT/graph_dit/nasbench-201-graph.json'
|
||||
# graphs = read_adj_ops_from_json(filename)
|
||||
# adjs = []
|
||||
# opss = []
|
||||
# accs = []
|
||||
# features = []
|
||||
# for graph in graphs:
|
||||
# adj, ops, acc=graph
|
||||
# op_code = [op_type[op] for op in ops]
|
||||
# adjs.append(adj)
|
||||
# opss.append(op_code)
|
||||
# accs.append(acc)
|
||||
features = []
|
||||
print(f"graphlist: {graph_list[0]}")
|
||||
print(f"len graphlist: {len(graph_list)}")
|
||||
for op_code, adj in graph_list:
|
||||
features.append(feature_from_adj_and_ops(op_code, adj))
|
||||
print(f"len features: {len(features)}")
|
||||
# print(f"features: {features[0].shape}")
|
||||
features = np.stack(features)
|
||||
features = features.astype(np.float32)
|
||||
print(f"features shape: {features.shape}")
|
||||
|
||||
|
||||
fps = features
|
||||
if 'classification' in self.task_type:
|
||||
scores = self.model.predict_proba(fps)[:, 1]
|
||||
else:
|
||||
scores = self.model.predict(fps)
|
||||
# scores = scores * np.array(mask)
|
||||
return np.float32(scores)
|
||||
|
||||
|
||||
@classmethod
|
||||
def fingerprints_from_mol(cls, mol): # use ECFP4
|
||||
features_vec = AllChem.GetMorganFingerprintAsBitVect(mol, 2, nBits=2048)
|
||||
|
Reference in New Issue
Block a user