コード例 #1
0
	def biasedMixtures(self, role=None, strategy=None, bias=.9):
		"""
		Gives mixtures where the input strategy has %bias weight for its role.

		Probability for that role's remaining strategies is distributed
		uniformly, as is probability for all strategies of other roles.

		Returns a list even when a single role & strategy are specified, since
		the main use case is starting replicator dynamics from several mixtures.
		"""
		assert 0 <= bias <= 1, "probabilities must be between zero and one"
		if self.maxStrategies == 1:
			return [self.uniformMixture()]
		if role == None:
			return flatten([self.biasedMixtures(r, strategy, bias) for r \
					in filter(lambda r: self.numStrategies[self.index(r)] \
					> 1, self.roles)])
		if strategy == None:
			return flatten([self.biasedMixtures(role, s, bias) for s in \
					self.strategies[role]])
		i = self.array_index(role, strategy, dtype=float)
		m = 1. - self.mask - i
		m /= m.sum(1).reshape(m.shape[0], 1)
		m[self.index(role)] *= (1. - bias)
		m += i*bias
		return [m]
コード例 #2
0
def is_mixed_profile(prof):
	if not isinstance(prof, h_dict):
		return False
	flat = flatten([v.values() for v in prof.values()])
	return all([prob >= 0 for prob in flat]) and \
			np.allclose(sum(flat), len(prof))
コード例 #3
0
def is_pure_profile(prof):
	if not isinstance(prof, h_dict):
		return False
	flat = flatten([v.values() for v in prof.values()])
	return all([isinstance(count, int) and count >= 0 for count in flat])