def validate( ratings ):
	#print "all:", ratings.keys()	
	
	global ndcgs
	
	user_ndcgs = []
	
	# this is L for a user
	max_split_i = min( max_train_size, min_items_for_ndcg + 1 - len( ratings ) )
	print " ", max_split_i
	
	# ratings in random order
	tmp = ratings.items()
	shuffle( tmp )
	ratings = OrderedDict( tmp )
	
	for split_i in range( 1, max_split_i ):	
		train = ratings.keys()[:split_i]
		test = ratings.keys()[split_i:]
		
		# a recommender gets some ratings and returns a list of recommended get_ranked_ids
		# the length of the list is ndcg_k + len( train )
		# in case the recommender returns items from the train set
		ranked_ids = rec.get_ranked_ids( train, ndcg_k + len( train ))
		
		# recommender might return ids in train - filter them out
		ranked_ids = [ x for x in ranked_ids if x not in train ]
		ranked_ids = ranked_ids[:ndcg_k]
		
		relevances = get_relevances( ratings, ranked_ids )	
		best_relevances = get_best_relevances( ratings, test, ndcg_k )

		# when given None as worst_relevances, 
		# get_ndcg_2() will assume that the worst possible DCG is zero
		worst_relevances = None
		
		ndcg = get_ndcg_2( relevances, best_relevances, worst_relevances, ndcg_k )
		
		# nans when all ratings in test are the same, e.g. (2, 2, 2)
		if not np.isnan( ndcg ):
			ndcgs[split_i].append( ndcg )
	
#
dataset/ETHPy150Open zygmuntz/evaluating-recommenders/validate.py/validate/swapped operands of `-`