def evaluate(self, pred): 
		""" Convert state sequences into negative and positive regions
			and check for true- and false positives (fscore, precision, etc pp). 
			Warning! This only work for 2-state problems.
		"""

		N = self.samples
		# assume 'pred' to be correspinding to 'y'
		if len(pred)!=N:
			print len(pred)
			raise Exception('Wrong number of examples!')

		all_tp = all_fp = all_tn = all_fn = 0.0

		err_exm = {}
		err_exm['fscore'] = []
		err_exm['sensitivity'] = []
		err_exm['specificity'] = []
		err_exm['precision'] = []
		for i in xrange(N):
			loss1 = self.calc_loss(i, pred[i])
			loss2 = self.calc_loss(i, -pred[i]+1)
			#print('{2}: loss1={0} loss2={1}'.format(loss1, loss2, i))

			#  convert into genic and intergenic regions
			seq_true = np.uint(np.sign(self.y[i]))
			seq_pred = np.uint(np.sign(pred[i]))
			if loss2<loss1:
				# switch states
				seq_pred = np.uint(np.sign(-pred[i]+1))
			lens = len(seq_pred[0,:])

			# error measures
			tp = fp = tn = fn = 0.0
			isPosAvail = False
			for t in xrange(lens):
				if (seq_true[0,t]==1):
					isPosAvail = True
				fp += float(seq_true[0,t]==0 and seq_pred[0,t]==1)
				fn += float(seq_true[0,t]==1 and seq_pred[0,t]==0)
				tp += float(seq_true[0,t]==1 and seq_pred[0,t]==1)
				tn += float(seq_true[0,t]==0 and seq_pred[0,t]==0)
			if tp+fp+tn+fn!=lens:
				print 'error'

			all_fn += fn
			all_tn += tn
			all_fp += fp
			all_tp += tp


			if tp+fn>0:
				sensitivity = float(tp) / float(tp+fn)
			else:
				sensitivity = 1.0
				if isPosAvail:
					sensitivity = 0.0

			if tn+fp>0:
				specificity = float(tn) / float(tn+fp)
			else:
				specificity = 0.0

			if tp+fp>0:
				precision = float(tp) / float(tp+fp)
			else:
				precision = 1.0
				if isPosAvail:
					precision = 0.0
			
			if precision+sensitivity>0.0:
				fscore = 2.0*precision*sensitivity / float(precision+sensitivity)
			else:
				fscore = 0.0

			err_exm['fscore'].append(fscore)
			err_exm['sensitivity'].append(sensitivity)
			err_exm['specificity'].append(specificity)
			err_exm['precision'].append(precision)

		if all_tp+all_fn>0:
			sensitivity = float(all_tp) / float(all_tp+all_fn)
		else:
			sensitivity = 0.0
		if all_tn+all_fp>0:
			specificity = float(all_tn) / float(all_tn+fp)
		else:
			specificity = 0.0
		if all_tp+all_fp>0:
			precision = float(all_tp) / float(all_tp+all_fp)
		else:
			precision = 0.0
		err = {}
		if precision+sensitivity>0.0:
			err['fscore'] = 2.0*precision*float(precision+sensitivity) / sensitivity
		else:
			err['fscore'] = 0.0
		err['sensitivity'] = sensitivity
		err['specificity'] = specificity
		err['precision'] = precision


		return (err, err_exm)
dataset/ETHPy150Open nicococo/tilitools/so_hmm.py/SOHMM.evaluate/swapped operands of `/`