Class Posterior
- java.lang.Object
-
- ch.idsia.crema.inference.approxlp2.Posterior
-
- All Implemented Interfaces:
ObjectiveFunction<Move,Solution>
,Comparator<Solution>
public class Posterior extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static double
BAD
protected org.apache.commons.math3.optim.nonlinear.scalar.GoalType
goal
protected GraphicalModel<? extends GenericFactor>
model
protected int[]
sequence
protected int
x0
protected int
x0state
-
Constructor Summary
Constructors Constructor Description Posterior(GraphicalModel<? extends GenericFactor> model, org.apache.commons.math3.optim.nonlinear.scalar.GoalType dir, int x0, int x0state, gnu.trove.map.TIntIntMap evidence)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected BayesianFactor
calcMarginal(Solution sol, int[] query)
protected BayesianFactor
calcPosterior(Solution sol, int[] query, gnu.trove.map.TIntIntMap ev)
int
compare(Solution sol1, Solution sol2)
protected LinearFractionalSolver
createSolver(int free)
double
eval(Solution solution)
This might and should be mapped to eval(solution, null); Evaluation of a solution should really be cached.double
eval(Solution from, Move doing)
Evaluate the value for a move and get the new vertexprotected void
fixNotMoving(Solution from, Move move)
Make non vertex changing moves illegal.org.apache.commons.math3.optim.nonlinear.scalar.GoalType
getGoal()
protected BayesianFactor
getX0factor()
This is a custom bayesian factor over x0 with a 1 for x0state.boolean
isBound(double value)
Test whether the provided score is a bound.boolean
isImprovement(double change)
since we did not specify if a positive change is good or bad here we can get that informationboolean
isImprovement(double from, double to)
since we did not specify if a positive change is good or bad here we can get that information.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Field Detail
-
BAD
public static final double BAD
- See Also:
- Constant Field Values
-
model
protected GraphicalModel<? extends GenericFactor> model
-
goal
protected org.apache.commons.math3.optim.nonlinear.scalar.GoalType goal
-
x0
protected int x0
-
x0state
protected int x0state
-
sequence
protected int[] sequence
-
-
Constructor Detail
-
Posterior
public Posterior(GraphicalModel<? extends GenericFactor> model, org.apache.commons.math3.optim.nonlinear.scalar.GoalType dir, int x0, int x0state, gnu.trove.map.TIntIntMap evidence)
-
-
Method Detail
-
createSolver
protected LinearFractionalSolver createSolver(int free)
-
eval
public double eval(Solution from, Move doing)
Evaluate the value for a move and get the new vertexdoing
- if null from will be evaluated- Returns:
-
eval
public double eval(Solution solution)
Description copied from interface:ObjectiveFunction
This might and should be mapped to eval(solution, null); Evaluation of a solution should really be cached. This method might be called multiple times for a solution- Returns:
-
getGoal
public org.apache.commons.math3.optim.nonlinear.scalar.GoalType getGoal()
-
getX0factor
protected BayesianFactor getX0factor()
This is a custom bayesian factor over x0 with a 1 for x0state. The value is cached.- Returns:
-
fixNotMoving
protected void fixNotMoving(Solution from, Move move)
Make non vertex changing moves illegal.- Parameters:
from
-move
-
-
calcMarginal
protected BayesianFactor calcMarginal(Solution sol, int[] query)
-
calcPosterior
protected BayesianFactor calcPosterior(Solution sol, int[] query, gnu.trove.map.TIntIntMap ev)
-
compare
public int compare(Solution sol1, Solution sol2)
- Specified by:
compare
in interfaceComparator<Solution>
-
isImprovement
public boolean isImprovement(double change)
Description copied from interface:ObjectiveFunction
since we did not specify if a positive change is good or bad here we can get that information- Specified by:
isImprovement
in interfaceObjectiveFunction<Move,Solution>
- Returns:
-
isImprovement
public boolean isImprovement(double from, double to)
Description copied from interface:ObjectiveFunction
since we did not specify if a positive change is good or bad here we can get that information. If any of the inputs is NaN the other must be an improvement. If both are NaN it should not be an improvement.- Specified by:
isImprovement
in interfaceObjectiveFunction<Move,Solution>
- Returns:
-
isBound
public boolean isBound(double value)
Description copied from interface:ObjectiveFunction
Test whether the provided score is a bound. This will be used to test if we reached a known upper/lower bound and should not continue.- Specified by:
isBound
in interfaceObjectiveFunction<Move,Solution>
- Parameters:
value
- a score- Returns:
- true if the score is a bound in the optimizing direction
-
-