Package net.sf.tweety.math.opt
Class NewtonRootFinder
- java.lang.Object
-
- net.sf.tweety.math.opt.RootFinder
-
- net.sf.tweety.math.opt.NewtonRootFinder
-
public class NewtonRootFinder extends RootFinder
This class implements the Newton method for finding zeros of a function.- Author:
- Matthias Thimm
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.util.List<Term>>jacobianThe jacobian of the function.static intMAX_FIX_ITERATIONSThe maximum number of fixing iterations.static doublePRECISIONThe precision of the approximation.
-
Constructor Summary
Constructors Constructor Description NewtonRootFinder(java.util.List<Term> functions, java.util.Map<Variable,Term> startingPoint)Creates a new Newton root finder for the given starting point and the given (multi-dimensional) functionNewtonRootFinder(Term function, java.util.Map<Variable,Term> startingPoint)Creates a new Newton root finder for the given starting point and the given function
-
Method Summary
Modifier and Type Method Description private java.util.List<java.lang.Double>approximate(java.util.List<java.util.List<java.lang.Double>> currentJacobianValue, java.util.List<java.lang.Double> currentVector, java.util.List<java.lang.Double> currentValue)Solves the linear equation currentJacobianValue * (X-currentVector) = - currentValue.private java.util.List<java.util.List<java.lang.Double>>evaluateMatrix(java.util.List<java.util.List<Term>> functions, java.util.Map<Variable,? extends Term> mapping)Evaluates each function in the given matrix with the given values for variables.private java.util.Map<Variable,Term>midpoint(java.util.Map<Variable,Term> m1, java.util.Map<Variable,Term> m2)Computes the midpoint of the two mapsjava.util.Map<Variable,Term>randomRoot()Determines the values for the variables appearing in the function such the function evaluates to zero.-
Methods inherited from class net.sf.tweety.math.opt.RootFinder
getFunctions, getStartingPoint, setStartingPoint
-
-
-
-
Field Detail
-
jacobian
private java.util.List<java.util.List<Term>> jacobian
The jacobian of the function.
-
PRECISION
public static final double PRECISION
The precision of the approximation. The actual used precision depends on the number of variables.- See Also:
- Constant Field Values
-
MAX_FIX_ITERATIONS
public static final int MAX_FIX_ITERATIONS
The maximum number of fixing iterations.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NewtonRootFinder
public NewtonRootFinder(Term function, java.util.Map<Variable,Term> startingPoint)
Creates a new Newton root finder for the given starting point and the given function- Parameters:
function- a functionstartingPoint- the starting point
-
NewtonRootFinder
public NewtonRootFinder(java.util.List<Term> functions, java.util.Map<Variable,Term> startingPoint)
Creates a new Newton root finder for the given starting point and the given (multi-dimensional) function- Parameters:
functions- a list of functionsstartingPoint- the starting point
-
-
Method Detail
-
randomRoot
public java.util.Map<Variable,Term> randomRoot() throws GeneralMathException
Description copied from class:RootFinderDetermines the values for the variables appearing in the function such the function evaluates to zero.- Specified by:
randomRootin classRootFinder- Returns:
- a map from variables to terms such that "function" evaluates to zero.
- Throws:
GeneralMathException- if something went wrong.
-
midpoint
private java.util.Map<Variable,Term> midpoint(java.util.Map<Variable,Term> m1, java.util.Map<Variable,Term> m2)
Computes the midpoint of the two maps- Parameters:
m1- a mapm2- a map- Returns:
- the midpoint of the two maps
-
approximate
private java.util.List<java.lang.Double> approximate(java.util.List<java.util.List<java.lang.Double>> currentJacobianValue, java.util.List<java.lang.Double> currentVector, java.util.List<java.lang.Double> currentValue) throws GeneralMathExceptionSolves the linear equation currentJacobianValue * (X-currentVector) = - currentValue.- Parameters:
currentJacobianValue- the current Jacobian valuecurrentVector- the current vectorcurrentValue- the current value- Returns:
- the next guess for the approximation.
- Throws:
GeneralMathException
-
evaluateMatrix
private java.util.List<java.util.List<java.lang.Double>> evaluateMatrix(java.util.List<java.util.List<Term>> functions, java.util.Map<Variable,? extends Term> mapping)
Evaluates each function in the given matrix with the given values for variables.- Parameters:
functions- a list of functionsmapping- a map mapping variables to terms- Returns:
- the matrix of values
-
-