uk.co.agena.minerva.util.nptgenerator
Class NPTGenerator

java.lang.Object
  extended by uk.co.agena.minerva.util.nptgenerator.NPTGenerator
All Implemented Interfaces:
Progressable

public class NPTGenerator
extends java.lang.Object
implements Progressable

This class holds a list of functions for generating an NPT for a node. This will now allow every parent state combination of a node to have a different function defined for it. That means that we can have multiple model nodes once the GUI has the ability to add this.


Field Summary
static java.util.Map functionParametersMap
          Map of functions along with their parameter names.
protected  int lengthOfProgressableTask
          Represnts the length of the operation which is currently being monitored in this class.
protected  int progress
          Represnts the current progress of any operation which is currently being monitored in this class.
static int PROGRESSABLE_GENERATE_NPT
          To indicate we are monitoring the GenerateNPT operation.
protected  boolean progressableTaskDone
          When set to true the current task being monitored will have been completed.
protected  boolean terminateProgressableTask
          When set to true the current propagation will be terminated/cancelled.
 
Constructor Summary
NPTGenerator(ExtendedBN ebn, ExtendedNode functionNode)
           
 
Method Summary
 boolean createFunctionListForModelNodes(java.util.List choosenModelNodes, java.util.List modelFunctions)
          This method creates a full list of Functions (function array) whoses length is equal to the noOfParentsStateCombinations.
 void generateNPT(boolean autoExtendStatesAsRequired, boolean autoRestrictStates, boolean imitateNewEvidence, boolean duringDD)
          This will actually create the NPT for the Node which has a Funtions Defined on it.
 int getCurrentProgress()
          Represents the current progress of any operation which is currently being monitored in this class.
 ExtendedNodeFunction getFunctionFromArray(int[] pattern, int[][] stateCombos, java.util.List allFunctions)
          Similar to putFunctionInArray but instead when we find the first occurance of the pattern in the state combination array we return the ExtendedNodeFunction at the appropiate position in the allFunctions List.
static java.util.Map getFunctionParametersMap()
           
 int getLengthOfProgressableTask()
          The length of the current task being monitored.
static int getMaxNumParameters()
           
static int getNumParameters(java.lang.String function)
           
 int[] getTrueOrderStateCode(java.util.List userSelectedModelNodes, int[] userStateCombo, java.util.List reqNodeOrder)
          The order in which the user selected model nodes are added to the specified list may not be the correct order in which the Model nodes exist in the reqNodeOrder List.
 int howManyFunctionsDoINeed()
          This returns the Number of Functions that is required before we can generate the NPT.
 boolean isCanContinueFromError()
          Flag used by the method createFunctionListForModelNodes to indicate when throwing an exception whether it is one from which the calling method can continue from.
 boolean isProgressableTaskDone()
          When set to true the current task being monitored will have been completed.
 void populateStateCombinationArray(int[][] combos, int noOfCombinations, java.util.List parentsOfInterest)
          Builds up an array of ints that can be used to uniquly represent each possible state combination for all the specifed parents.
 void resetProgressableTask()
          Reset the variables used in the monitoring of the current task.
 void setFunctions(Function[] functions)
          Sets the functions used for this node.
 void setFunctions(java.lang.String functionType, java.util.List functionParams)
          Convience method, applys the specified function to the NPT generator, using the specified parameters.
 void terminateProgressableTask()
          Stop the current progressable task.
 void updateCurrentProgress(int inc)
          Increment the currentProgress by the specified value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

functionParametersMap

public static java.util.Map functionParametersMap
Map of functions along with their parameter names.


lengthOfProgressableTask

protected int lengthOfProgressableTask
Represnts the length of the operation which is currently being monitored in this class.


progress

protected int progress
Represnts the current progress of any operation which is currently being monitored in this class.


progressableTaskDone

protected boolean progressableTaskDone
When set to true the current task being monitored will have been completed.


terminateProgressableTask

protected boolean terminateProgressableTask
When set to true the current propagation will be terminated/cancelled.


PROGRESSABLE_GENERATE_NPT

public static final int PROGRESSABLE_GENERATE_NPT
To indicate we are monitoring the GenerateNPT operation.

See Also:
Constant Field Values
Constructor Detail

NPTGenerator

public NPTGenerator(ExtendedBN ebn,
                    ExtendedNode functionNode)
             throws ExtendedBNException,
                    InconsistentEvidenceException
Parameters:
functionNode -
Throws:
ExtendedBNException
InconsistentEvidenceException
Method Detail

getFunctionParametersMap

public static java.util.Map getFunctionParametersMap()

getNumParameters

public static int getNumParameters(java.lang.String function)

getMaxNumParameters

public static int getMaxNumParameters()

howManyFunctionsDoINeed

public int howManyFunctionsDoINeed()
This returns the Number of Functions that is required before we can generate the NPT.

Returns:

setFunctions

public void setFunctions(Function[] functions)
                  throws NPTGeneratorException
Sets the functions used for this node.

Parameters:
functions -
Throws:
NPTGeneratorException

setFunctions

public void setFunctions(java.lang.String functionType,
                         java.util.List functionParams)
                  throws NPTGeneratorException,
                         NPTGeneratorException,
                         InconsistentEvidenceException
Convience method, applys the specified function to the NPT generator, using the specified parameters.

Parameters:
functionType -
functionParams -
Throws:
NPTGeneratorException
NPTGeneratorException
InconsistentEvidenceException

generateNPT

public void generateNPT(boolean autoExtendStatesAsRequired,
                        boolean autoRestrictStates,
                        boolean imitateNewEvidence,
                        boolean duringDD)
                 throws InconsistentEvidenceException,
                        NPTGeneratorInsufficientStateRangeException,
                        NPTGeneratorException
This will actually create the NPT for the Node which has a Funtions Defined on it. By this state the user is reponsible for having defined the Functions array. Some assumptions are made at this point, which the user of this function is responsible for ensuring are correct. 1) The function node in each of there functions is the same as the function node in this. 2) The single column NPT has been created within the Function. 3) The functions arrive in the correct order for the parentStateConfigurations. NOTE: if a node is autoRestricting then it must also be auto extending.

Parameters:
autoExtendStatesAsRequired - This flag should be set to true if you require the node to automatically change its state ranges if an NPTGeneratorInsufficientStateRangeException is encountered. Setting this to false will cause the Exception to be thrown up.
imitateNewEvidence - TODO
duringDD - TODO
Throws:
InconsistentEvidenceException
NPTGeneratorInsufficientStateRangeException
NPTGeneratorException

populateStateCombinationArray

public void populateStateCombinationArray(int[][] combos,
                                          int noOfCombinations,
                                          java.util.List parentsOfInterest)
Builds up an array of ints that can be used to uniquly represent each possible state combination for all the specifed parents. So for a 2 Parent example where each has 2 states there are 4 possible state combinations the array would look like this: 0 0 1 1 0 1 0 1

Parameters:
combos - The array to populate.
noOfCombinations - The nunmber of state combinations.
parentsOfInterest - The parents ExtendedNodes we are building the array for.

getTrueOrderStateCode

public int[] getTrueOrderStateCode(java.util.List userSelectedModelNodes,
                                   int[] userStateCombo,
                                   java.util.List reqNodeOrder)
The order in which the user selected model nodes are added to the specified list may not be the correct order in which the Model nodes exist in the reqNodeOrder List. This method uses the user selected list to build an array which represents the true order of the state combination specifed based on the required node order. Example: Required Node Order List: A B C User Selcted Model Node List: C B State Combination: [0, 1] Resultant array: [-1, 1, 0] -1 represents a value we don't know.

Parameters:
userSelectedModelNodes - The user selected model nodes
userStateCombo - The state combination we are trying to re order.
reqNodeOrder - The order the node are required to follow
Returns:
The true state combination order.

getFunctionFromArray

public ExtendedNodeFunction getFunctionFromArray(int[] pattern,
                                                 int[][] stateCombos,
                                                 java.util.List allFunctions)
                                          throws NPTGeneratorException,
                                                 InconsistentEvidenceException
Similar to putFunctionInArray but instead when we find the first occurance of the pattern in the state combination array we return the ExtendedNodeFunction at the appropiate position in the allFunctions List.

Parameters:
pattern - The pattern we are looking for.
stateCombos - The state combination array we are searching.
allFunctions - The list we get the appropiate function from if a match is found.
Returns:
The ExtendedNodeFunction is a match is found null otherwise.
Throws:
NPTGeneratorException
InconsistentEvidenceException

createFunctionListForModelNodes

public boolean createFunctionListForModelNodes(java.util.List choosenModelNodes,
                                               java.util.List modelFunctions)
                                        throws InconsistentEvidenceException,
                                               NPTGeneratorException
This method creates a full list of Functions (function array) whoses length is equal to the noOfParentsStateCombinations. This is done by taking a Model nodes and List of ExtendedNodeFunctions. There is one function in this list per state combination for the selected model nodes. So if there were 3 parent nodes but only 2 model nodes each with 2 states there would be 4 functions one for each of the 4 state combinations. These Functions are then duplicated in the appropiate place in order to fill the full list of Functions needed.

Returns:
false is returned if there were not enough functions stored for the selected Model Nodes and general case default functions could not be used to make up the gaps; true is returned otherwise.
Throws:
InconsistentEvidenceException
NPTGeneratorException

isCanContinueFromError

public boolean isCanContinueFromError()
Flag used by the method createFunctionListForModelNodes to indicate when throwing an exception whether it is one from which the calling method can continue from.

Returns:
Returns the canContinueFromError.

getCurrentProgress

public int getCurrentProgress()
Represents the current progress of any operation which is currently being monitored in this class.

Specified by:
getCurrentProgress in interface Progressable
Returns:
The current progress value (int)

getLengthOfProgressableTask

public int getLengthOfProgressableTask()
The length of the current task being monitored.

Specified by:
getLengthOfProgressableTask in interface Progressable
Returns:
The length of the task being monitored as an int.

terminateProgressableTask

public void terminateProgressableTask()
Stop the current progressable task.

Specified by:
terminateProgressableTask in interface Progressable

isProgressableTaskDone

public boolean isProgressableTaskDone()
When set to true the current task being monitored will have been completed.

Specified by:
isProgressableTaskDone in interface Progressable
Returns:
The status of the done flag which should be set to indicate the task is over whether is has been terminated or finished.

resetProgressableTask

public void resetProgressableTask()
Reset the variables used in the monitoring of the current task.

Specified by:
resetProgressableTask in interface Progressable

updateCurrentProgress

public void updateCurrentProgress(int inc)
Increment the currentProgress by the specified value.

Parameters:
inc - The amount by which we are updating the Current Progress.


Copyright © 2006 Agena Ltd. All Rights Reserved.