use of jskills.numerics.GaussianDistribution in project ACManager by kun368.
the class PlayerPriorValuesToSkillsLayer method buildLayer.
@Override
public void buildLayer() {
for (ITeam currentTeam : teams) {
List<KeyedVariable<IPlayer, GaussianDistribution>> currentTeamSkills = new ArrayList<>();
for (Entry<IPlayer, Rating> currentTeamPlayer : currentTeam.entrySet()) {
KeyedVariable<IPlayer, GaussianDistribution> playerSkill = createSkillOutputVariable(currentTeamPlayer.getKey());
AddLayerFactor(createPriorFactor(currentTeamPlayer.getKey(), currentTeamPlayer.getValue(), playerSkill));
currentTeamSkills.add(playerSkill);
}
addOutputVariableGroup(currentTeamSkills);
}
}
use of jskills.numerics.GaussianDistribution in project ACManager by kun368.
the class TeamDifferencesComparisonLayer method buildLayer.
@Override
public void buildLayer() {
for (int i = 0; i < getInputVariablesGroups().size(); i++) {
boolean isDraw = (teamRanks[i] == teamRanks[i + 1]);
Variable<GaussianDistribution> teamDifference = getInputVariablesGroups().get(i).get(0);
GaussianFactor factor = isDraw ? (GaussianFactor) new GaussianWithinFactor(epsilon, teamDifference) : new GaussianGreaterThanFactor(epsilon, teamDifference);
AddLayerFactor(factor);
}
}
use of jskills.numerics.GaussianDistribution in project ACManager by kun368.
the class GaussianGreaterThanFactor method getLogNormalization.
@Override
public double getLogNormalization() {
GaussianDistribution marginal = getVariables().get(0).getValue();
GaussianDistribution message = getMessages().get(0).getValue();
GaussianDistribution messageFromVariable = divide(marginal, message);
return -logProductNormalization(messageFromVariable, message) + Math.log(cumulativeTo((messageFromVariable.getMean() - epsilon) / messageFromVariable.getStandardDeviation()));
}
use of jskills.numerics.GaussianDistribution in project ACManager by kun368.
the class GaussianPriorFactor method updateMessage.
@Override
protected double updateMessage(Message<GaussianDistribution> message, Variable<GaussianDistribution> variable) {
GaussianDistribution oldMarginal = new GaussianDistribution(variable.getValue());
Message<GaussianDistribution> oldMessage = message;
GaussianDistribution newMarginal = GaussianDistribution.fromPrecisionMean(oldMarginal.getPrecisionMean() + newMessage.getPrecisionMean() - oldMessage.getValue().getPrecisionMean(), oldMarginal.getPrecision() + newMessage.getPrecision() - oldMessage.getValue().getPrecision());
variable.setValue(newMarginal);
message.setValue(newMessage);
return sub(oldMarginal, newMarginal);
}
use of jskills.numerics.GaussianDistribution in project ACManager by kun368.
the class GaussianWeightedSumFactor method UpdateHelper.
private double UpdateHelper(double[] weights, double[] weightsSquared, List<Message<GaussianDistribution>> messages, List<Variable<GaussianDistribution>> variables) {
// Potentially look at http://mathworld.wolfram.com/NormalSumDistribution.html for clues as
// to what it's doing
GaussianDistribution message0 = new GaussianDistribution(messages.get(0).getValue());
GaussianDistribution marginal0 = new GaussianDistribution(variables.get(0).getValue());
// The math works out so that 1/newPrecision = sum of a_i^2 /marginalsWithoutMessages[i]
double inverseOfNewPrecisionSum = 0.0;
double anotherInverseOfNewPrecisionSum = 0.0;
double weightedMeanSum = 0.0;
double anotherWeightedMeanSum = 0.0;
for (int i = 0; i < weightsSquared.length; i++) {
// These flow directly from the paper
inverseOfNewPrecisionSum += weightsSquared[i] / (variables.get(i + 1).getValue().getPrecision() - messages.get(i + 1).getValue().getPrecision());
GaussianDistribution diff = divide(variables.get(i + 1).getValue(), messages.get(i + 1).getValue());
anotherInverseOfNewPrecisionSum += weightsSquared[i] / diff.getPrecision();
weightedMeanSum += weights[i] * (variables.get(i + 1).getValue().getPrecisionMean() - messages.get(i + 1).getValue().getPrecisionMean()) / (variables.get(i + 1).getValue().getPrecision() - messages.get(i + 1).getValue().getPrecision());
anotherWeightedMeanSum += weights[i] * diff.getPrecisionMean() / diff.getPrecision();
}
double newPrecision = 1.0 / inverseOfNewPrecisionSum;
double anotherNewPrecision = 1.0 / anotherInverseOfNewPrecisionSum;
double newPrecisionMean = newPrecision * weightedMeanSum;
double anotherNewPrecisionMean = anotherNewPrecision * anotherWeightedMeanSum;
GaussianDistribution oldMarginalWithoutMessage = divide(marginal0, message0);
GaussianDistribution newMessage = GaussianDistribution.fromPrecisionMean(newPrecisionMean, newPrecision);
GaussianDistribution anotherNewMessage = GaussianDistribution.fromPrecisionMean(anotherNewPrecisionMean, anotherNewPrecision);
if (!newMessage.equals(anotherNewMessage))
throw new RuntimeException("newMessage and anotherNewMessage aren't the same");
GaussianDistribution newMarginal = mult(oldMarginalWithoutMessage, newMessage);
// Update the message and marginal
messages.get(0).setValue(newMessage);
variables.get(0).setValue(newMarginal);
// Return the difference in the new marginal
return sub(newMarginal, marginal0);
}
Aggregations