Exemple #1
0
def evaluateCombinedTotalRocCurves(predictions, true, methods):
	res = "{0: <20}          {1: <19} {2: <19} {3: <19}\n".format(" ", "auc", "auc forward", "auc feedbacks")
	plt.figure(figsize=(35, 12))
	best_auc = 0
	subplot_i, subplot_k = getSubplots(3)
	for f in methods:
		y_true, y_pred = true[f], predictions[f]
		feedbacks_y_true = np.reshape([getFeedbackLinks(temp) for temp in y_true], (-1, 1))
		feedbacks_y_pred = np.reshape([getFeedbackLinks(temp) for temp in y_pred], (-1, 1))
		forward_y_true = np.reshape([getForwardLinks(temp) for temp in y_true], (-1, 1))
		forward_y_pred = np.reshape([getForwardLinks(temp) for temp in y_pred], (-1, 1))
		combined_y_pred = np.reshape(y_pred, (-1, 1))
		combined_y_true = np.reshape(y_true, (-1, 1))
		plt.subplot(subplot_i, subplot_k, 1)
		roc_auc = plotROC(combined_y_true, combined_y_pred, f)
		if roc_auc > best_auc and roc_auc < 0.99:
			best_auc = roc_auc
		plt.subplot(subplot_i, subplot_k, 2)
		roc_auc_forward = plotROC(forward_y_true, forward_y_pred, f)
		plt.title('ROC for forward only')
		plt.subplot(subplot_i, subplot_k, 3)
		roc_auc_feedbacks = plotROC(feedbacks_y_true, feedbacks_y_pred, f)
		plt.title('ROC for feedbacks only')
		res += "{0: <20} {1:16.3f} {2:16.3f}  {3:16.3f}\n".format(f, roc_auc, roc_auc_forward, roc_auc_feedbacks)
	plt.savefig(join(PROJECT_DIR, 'output', 'evaluation', s_timestamp() + '.pdf'))

	with open(join(PROJECT_DIR, 'output', 'evaluation', s_timestamp() + '.txt'), 'w') as pout:
		pout.write(res)
	return best_auc
Exemple #2
0
def plotRocForDataset(d, methods=methods):
	plt.figure(figsize=(6, 5))
	for f in methods:
		y_true, y_pred = evaluateMethod(d, methods[f], normalize=False)
		combined_y_pred = np.reshape(y_pred, (-1, 1))
		combined_y_true = np.reshape(y_true, (-1, 1))
		roc_auc = plotROC(combined_y_true, combined_y_pred, f)
	plt.grid()
	plt.savefig(join(PROJECT_DIR, 'output', 'roc', s_timestamp() + '.pdf'))
	def plotAll(self, sampler):
		font = {'size': 38}
		plt.rc('font', **font)
		plt.rcParams['lines.linewidth'] = 3
		plt.rcParams['axes.linewidth'] = 3

		with PdfPages(
				join(PROJECT_DIR, 'output', 'visualization_graph_and_time_series', s_timestamp() + '.pdf')) as pdf:
			for i in range(self.n_instances):
				instance = self.get(i)
				for n_time_idx in range(instance.n_time_series):
					istsv = instance.getViewForTimeSeries(n_time_idx, sampler)
					istsv.plot()
					plt.title(instance.time_series[n_time_idx].inhibit)
					pdf.savefig(dpi=100)
					plt.close()

		font = {'size': 12}
		plt.rc('font', **font)
Exemple #4
0
def plotPredictions(dataset, method, predict_n):
	cmap = plt.cm.Accent
	with PdfPages(join(PROJECT_DIR, 'output', 'visualization_graph_predictions_really', s_timestamp() + '.pdf')) as pdf:
		for idx_instance in range(dataset.n_instances):
			instance = dataset.get(idx_instance)
			plt.figure(figsize=(20, 14))
			subplot_i, subplot_k = getSubplots(instance.n_time_series + 1)
			labels = ['Pulse', '1 Inhibition', '2 Inhibitions', 'Oscilatory', 'Oscilatory+1 Inhibition']

			plt.subplot(subplot_i, subplot_k, 1)
			instance.plotDiGraphViaGraphViz_(cmap)
			for idx_time_series in range(instance.n_time_series):
				plt.subplot(subplot_i, subplot_k, idx_time_series + 2)
				instance.setx(idx_time_series)
				y_pred = method(instance)
				for idx_node in range(instance.n_nodes):
					y_pred[idx_node][idx_node] = 0
				y_pred = y_pred.reshape(-1, )
				plotPredicted(y_pred, labels[idx_time_series], predict_n, cmap, instance.n_nodes, instance.pos,
				              instance.labels)
			pdf.savefig()  # saves the current figure into a pdf page
			plt.close()
Exemple #5
0
def evaluateIndividualRocCurvesAndPredictions(d, predictions, true, predict_n, methods):
	with PdfPages(join(PROJECT_DIR, 'output', 'visualization_graph_predictions', s_timestamp() + '.pdf')) as pdf:
		cmap = plt.cm.Accent
		for idx_instance in range(d.n_instances):
			instance = d.get(idx_instance)
			n_nodes = instance.n_nodes
			node_labels = instance.labels
			plt.figure(figsize=(40, 20))
			subplot_i, subplot_k = getSubplots(len(predictions) + 4)
			for subplot_idx, f in enumerate(methods):
				y_true = true[f][idx_instance][:]
				y_pred = predictions[f][idx_instance][:]

				# plot the roc curve for the instance
				plt.subplot(subplot_i, subplot_k, len(predictions) + 1)
				plotROC(y_true, y_pred, f)

				# plot the roc curve for the feedbacks only
				plt.subplot(subplot_i, subplot_k, len(predictions) + 2)
				plotROC(getFeedbackLinks(y_true), getFeedbackLinks(y_pred), f)
				plt.title('ROC for feedbacks only')

				# plot the roc curve for the feedbacks only
				plt.subplot(subplot_i, subplot_k, len(predictions) + 3)
				plotROC(getForwardLinks(y_true), getForwardLinks(y_pred), f)
				plt.title('ROC for forward only')

				# plot the predicted networks
				plt.subplot(subplot_i, subplot_k, subplot_idx + 1)
				plotPredicted(y_pred, f, predict_n, cmap, n_nodes, instance.pos, node_labels)

			plt.subplot(subplot_i, subplot_k, len(predictions) + 4)
			instance.plotTimeSeries_(cmap)

			pdf.savefig()  # saves the current figure into a pdf page
			plt.close()