Module es.upm.fi.cig.multictbnc
Class BNHillClimbing
java.lang.Object
es.upm.fi.cig.multictbnc.learning.structure.optimisation.hillclimbing.implementation.BNHillClimbing
- All Implemented Interfaces:
HillClimbingImplementation
- Direct Known Subclasses:
BNHillClimbingHybridAlgorithm
,BNTabuSearch
Implements hill climbing algorithm for BNs.
-
Constructor Summary
ConstructorDescriptionBNHillClimbing
(BNScoreFunction scoreFunction) Constructor that receives the score function to optimise. -
Method Summary
Modifier and TypeMethodDescriptionprotected double
computeScore
(BN<? extends Node> bn, boolean[][] adjacencyMatrix) Computes the score of a structure given an adjacency matrix.protected void
findBestNeighbor
(BN<? extends Node> bn, HillClimbingSolution bestSolution, double[] scores, boolean[][][] adjacencyMatrices, String operation) Finds the best neighbour of the adjacency matrix "bestStructure" given an operation to perform (addition, deletion or reversal of arcs).findStructure
(PGM<? extends Node> pgm) Finds a structure for a given PGM.findStructure
(PGM<? extends Node> pgm, int idxNode) Finds the local structure of a given node of a PGM.findStructure
(PGM<? extends Node> pgm, List<Integer> idxNodes) Finds the local structure of some given nodes of a PGM.Returns a unique identifier for the hill climbing-based algorithm.Returns aMap
with the name of the score function that is optimised and the name of the applied penalisation function (if any).int
Returns the number of edges that have been evaluated so far.Returns the parameters that are used by the hill climbing implementation.protected void
Increases the number of evaluated edges in one.protected boolean
isScoreImproved
(HillClimbingSolution solution, boolean[][][] adjacencyMatrices, int idxBestOperation, double iterationBestScore) Checks if a solution given by the hill climbing algorithm in a certain iteration is better than the current solution.protected void
Sets to zero the number of evaluated edges.
-
Constructor Details
-
BNHillClimbing
Constructor that receives the score function to optimise.- Parameters:
scoreFunction
- score function for Bayesian networks
-
-
Method Details
-
isScoreImproved
protected boolean isScoreImproved(HillClimbingSolution solution, boolean[][][] adjacencyMatrices, int idxBestOperation, double iterationBestScore) Checks if a solution given by the hill climbing algorithm in a certain iteration is better than the current solution.- Parameters:
solution
- current solutionadjacencyMatrices
- best adjacency matrices given by each possible operationidxBestOperation
- index of the best operationiterationBestScore
- score of the iteration solution- Returns:
true
if the solution of the iteration is better than the current solution,false
otherwise
-
findStructure
Description copied from interface:HillClimbingImplementation
Finds a structure for a given PGM.- Specified by:
findStructure
in interfaceHillClimbingImplementation
- Parameters:
pgm
- a probabilistic graphical model- Returns:
- solution given by the hill climbing algorithm
-
findBestNeighbor
protected void findBestNeighbor(BN<? extends Node> bn, HillClimbingSolution bestSolution, double[] scores, boolean[][][] adjacencyMatrices, String operation) Finds the best neighbour of the adjacency matrix "bestStructure" given an operation to perform (addition, deletion or reversal of arcs).- Parameters:
bn
- Bayesian network whose structure is being learntbestSolution
- best structure so farscores
- two-dimensionaldouble
array containing the structure scores after applying each of the possible operations over the adjacency matrixadjacencyMatrices
- three-dimensionalboolean
array containing the resulting adjacency matrices after applying each of the possible operations over the original matrixoperation
- operation to perform over the adjacency matrix
-
computeScore
Computes the score of a structure given an adjacency matrix.- Parameters:
bn
- Bayesian network whose structure is being learntadjacencyMatrix
- adjacency matrix of the structure- Returns:
- score of the structure
-
getInfoScoreFunction
Description copied from interface:HillClimbingImplementation
Returns aMap
with the name of the score function that is optimised and the name of the applied penalisation function (if any).- Specified by:
getInfoScoreFunction
in interfaceHillClimbingImplementation
- Returns:
- a
Map
with the name of the score function that is optimised and the name of the penalisation function that is applied
-
findStructure
Description copied from interface:HillClimbingImplementation
Finds the local structure of a given node of a PGM.- Specified by:
findStructure
in interfaceHillClimbingImplementation
- Parameters:
pgm
- a probabilistic graphical modelidxNode
- node index- Returns:
- a
HillClimbingSolution
-
findStructure
Description copied from interface:HillClimbingImplementation
Finds the local structure of some given nodes of a PGM.- Specified by:
findStructure
in interfaceHillClimbingImplementation
- Parameters:
pgm
- a probabilistic graphical modelidxNodes
- node indexes- Returns:
- a
HillClimbingSolution
-
increaseNumEdgesTested
protected void increaseNumEdgesTested()Increases the number of evaluated edges in one. -
resetNumEdgesTested
protected void resetNumEdgesTested()Sets to zero the number of evaluated edges. -
getNumEdgesTested
public int getNumEdgesTested()Returns the number of edges that have been evaluated so far.- Returns:
- number of edges that have been evaluated so far
-
getIdentifier
Description copied from interface:HillClimbingImplementation
Returns a unique identifier for the hill climbing-based algorithm.- Specified by:
getIdentifier
in interfaceHillClimbingImplementation
- Returns:
- unique identifier for the hill climbing-based algorithm
-
getParametersAlgorithm
Description copied from interface:HillClimbingImplementation
Returns the parameters that are used by the hill climbing implementation.- Specified by:
getParametersAlgorithm
in interfaceHillClimbingImplementation
- Returns:
- a
Map
with the parameters used by the algorithm
-