示例#1
0
	def _calculateNewRating(self, gameInfo, selfRating, opponentRating, comparison):
		drawMargin = getDrawMarginFromDrawProbability(gameInfo.drawProbability, gameInfo.beta)
		c = sqrt((selfRating.standardDeviation**2.0) + (opponentRating.standardDeviation**2.0) + 2.0*(gameInfo.beta**2.0))
		winningMean = selfRating.mean
		losingMean = opponentRating.mean
		if comparison == PairwiseComparison.LOSE:
			winningMean = opponentRating.mean
			losingMean = selfRating.mean
		meanDelta = winningMean - losingMean
		v = None
		w = None
		rankMultiplier = None
		if comparison != PairwiseComparison.DRAW:
			v = vExceedsMargin(meanDelta, drawMargin, c)
			w = wExceedsMargin(meanDelta, drawMargin, c)
			rankMultiplier = comparison
		else:
			v = vWithinMargin(meanDelta, drawMargin, c)
			w = wWithinMargin(meanDelta, drawMargin, c)
			rankMultiplier = 1.0
		meanMultiplier = ((selfRating.standardDeviation**2.0) + (gameInfo.dynamicsFactor**2.0)) / c
		varianceWithDynamics = (selfRating.standardDeviation**2) + (gameInfo.dynamicsFactor**2)
		stdDevMultiplier = varianceWithDynamics/(c**2.0)
		newMean = selfRating.mean + (rankMultiplier*meanMultiplier*v)
		newStdDev = sqrt(varianceWithDynamics*(1 - w*stdDevMultiplier))
		return Rating(newMean, newStdDev)
示例#2
0
	def _updatePlayerRatings(self, gameInfo, newPlayerRatings, selfTeam, otherTeam, selfToOtherComparison):
		drawMargin = getDrawMarginFromDrawProbability(gameInfo.drawProbability, gameInfo.beta)
		betaSquared = gameInfo.beta**2.0
		tauSquared = gameInfo.dynamicsFactor**2.0

		totalPlayers = selfTeam.size + otherTeam.size
		
		selfTeamMeanSum = selfTeam.meanSum
		otherTeamMeanSum = otherTeam.meanSum
		selfTeamStandardDeviationSum = selfTeam.standardDeviationSquaredSum
		otherTeamStandardDeviationSum = otherTeam.standardDeviationSquaredSum
		
		c = sqrt(selfTeamStandardDeviationSum + otherTeamStandardDeviationSum + totalPlayers*betaSquared)
		winningMean = selfTeamMeanSum
		losingMean = otherTeamMeanSum
		if selfToOtherComparison == PairwiseComparison.LOSE:
			winningMean = otherTeamMeanSum
			losingMean = selfTeamMeanSum
		meanDelta = winningMean - losingMean
		
		v = None
		w = None
		rankMultiplier = None
		if selfToOtherComparison != PairwiseComparison.DRAW:
			v = vExceedsMargin(meanDelta, drawMargin, c)
			w = wExceedsMargin(meanDelta, drawMargin, c)
			rankMultiplier = selfToOtherComparison
		else:
			v = vWithinMargin(meanDelta, drawMargin, c)
			w = wWithinMargin(meanDelta, drawMargin, c)
			rankMultiplier = 1
		
		for playerTuple in selfTeam.asListOfTuples:
			previousPlayerRating = playerTuple[1]
			meanMultiplier = ((previousPlayerRating.standardDeviation**2.0) + tauSquared) / c
			stdDevMultiplier = ((previousPlayerRating.standardDeviation**2.0) + tauSquared) / (c**2.0)
			playerMeanDelta = rankMultiplier*meanMultiplier*v
			newMean = previousPlayerRating.mean + playerMeanDelta
			newStdDev = sqrt(((previousPlayerRating.standardDeviation**2.0) + tauSquared) * (1 - w*stdDevMultiplier))
			newPlayerRatings.append((playerTuple[0], Rating(newMean, newStdDev)))
示例#3
0
	def _updateMessageInternal(self, message, variable):
		oldMarginal = deepcopy(variable.value)
		oldMessage = deepcopy(message.value)
		messageFromVar = oldMarginal/oldMessage
		
		c = messageFromVar.precision
		d = messageFromVar.precisionMean
		sqrtC = sqrt(c)
		dOnSqrtC = d/sqrtC
		epsilonTimesSqrtC = self._epsilon*sqrtC
		
		denom = 1.0 - wExceedsMargin(dOnSqrtC, epsilonTimesSqrtC)
		
		newPrecision = c/denom
		newPrecisionMean = (d + sqrtC*vExceedsMargin(dOnSqrtC, epsilonTimesSqrtC))/denom
		
		newMarginal = fromPrecisionMean(newPrecisionMean, newPrecision)
		newMessage = oldMessage*newMarginal/oldMarginal
		
		message.value = newMessage
		variable.value = newMarginal
		
		return newMarginal - oldMarginal