本文整理汇总了Java中weka.classifiers.bayes.BayesNet.getParentSet方法的典型用法代码示例。如果您正苦于以下问题:Java BayesNet.getParentSet方法的具体用法?Java BayesNet.getParentSet怎么用?Java BayesNet.getParentSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weka.classifiers.bayes.BayesNet
的用法示例。
在下文中一共展示了BayesNet.getParentSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findBestArcToDelete
import weka.classifiers.bayes.BayesNet; //导入方法依赖的package包/类
/**
* find best (or least bad) arc deletion operation
*
* @param bayesNet Bayes network to delete arc from
* @param instances data set
* @param oBestOperation
* @return Operation containing best arc to delete, or null if no deletion can
* be made (happens when there is no arc in the network yet).
*/
Operation findBestArcToDelete(BayesNet bayesNet, Instances instances,
Operation oBestOperation) {
int nNrOfAtts = instances.numAttributes();
// find best arc to delete
for (int iNode = 0; iNode < nNrOfAtts; iNode++) {
ParentSet parentSet = bayesNet.getParentSet(iNode);
for (int iParent = 0; iParent < parentSet.getNrOfParents(); iParent++) {
Operation oOperation = new Operation(parentSet.getParent(iParent),
iNode, Operation.OPERATION_DEL);
if (m_Cache.get(oOperation) > oBestOperation.m_fDeltaScore) {
if (isNotTabu(oOperation)) {
oBestOperation = oOperation;
oBestOperation.m_fDeltaScore = m_Cache.get(oOperation);
}
}
}
}
return oBestOperation;
}
示例2: findBestArcToReverse
import weka.classifiers.bayes.BayesNet; //导入方法依赖的package包/类
/**
* find best (or least bad) arc reversal operation
*
* @param bayesNet Bayes network to reverse arc in
* @param instances data set
* @param oBestOperation
* @return Operation containing best arc to reverse, or null if no reversal is
* allowed (happens if there is no arc in the network yet, or when any
* such reversal introduces a cycle).
*/
Operation findBestArcToReverse(BayesNet bayesNet, Instances instances,
Operation oBestOperation) {
int nNrOfAtts = instances.numAttributes();
// find best arc to reverse
for (int iNode = 0; iNode < nNrOfAtts; iNode++) {
ParentSet parentSet = bayesNet.getParentSet(iNode);
for (int iParent = 0; iParent < parentSet.getNrOfParents(); iParent++) {
int iTail = parentSet.getParent(iParent);
// is reversal allowed?
if (reverseArcMakesSense(bayesNet, instances, iNode, iTail)
&& bayesNet.getParentSet(iTail).getNrOfParents() < m_nMaxNrOfParents) {
// go check if reversal results in the best step forward
Operation oOperation = new Operation(parentSet.getParent(iParent),
iNode, Operation.OPERATION_REVERSE);
if (m_Cache.get(oOperation) > oBestOperation.m_fDeltaScore) {
if (isNotTabu(oOperation)) {
oBestOperation = oOperation;
oBestOperation.m_fDeltaScore = m_Cache.get(oOperation);
}
}
}
}
}
return oBestOperation;
}
示例3: findBestArcToDelete
import weka.classifiers.bayes.BayesNet; //导入方法依赖的package包/类
/**
* find best (or least bad) arc deletion operation
*
* @param bayesNet Bayes network to delete arc from
* @param instances data set
* @param oBestOperation
* @return Operation containing best arc to delete, or null if no deletion can
* be made (happens when there is no arc in the network yet).
* @throws Exception of something goes wrong
*/
Operation findBestArcToDelete(BayesNet bayesNet, Instances instances,
Operation oBestOperation) throws Exception {
int nNrOfAtts = instances.numAttributes();
// find best arc to delete
for (int iNode = 0; iNode < nNrOfAtts; iNode++) {
ParentSet parentSet = bayesNet.getParentSet(iNode);
for (int iParent = 0; iParent < parentSet.getNrOfParents(); iParent++) {
Operation oOperation = new Operation(parentSet.getParent(iParent),
iNode, Operation.OPERATION_DEL);
double fScore = calcScoreWithMissingParent(oOperation.m_nHead,
oOperation.m_nTail);
if (fScore > oBestOperation.m_fScore) {
if (isNotTabu(oOperation)) {
oBestOperation = oOperation;
oBestOperation.m_fScore = fScore;
}
}
}
}
return oBestOperation;
}
示例4: findBestArcToDelete
import weka.classifiers.bayes.BayesNet; //导入方法依赖的package包/类
/**
* find best (or least bad) arc deletion operation
*
* @param bayesNet Bayes network to delete arc from
* @param instances data set
* @param oBestOperation
* @return Operation containing best arc to delete, or null if no deletion can be made
* (happens when there is no arc in the network yet).
*/
Operation findBestArcToDelete(BayesNet bayesNet, Instances instances, Operation oBestOperation) {
int nNrOfAtts = instances.numAttributes();
// find best arc to delete
for (int iNode = 0; iNode < nNrOfAtts; iNode++) {
ParentSet parentSet = bayesNet.getParentSet(iNode);
for (int iParent = 0; iParent < parentSet.getNrOfParents(); iParent++) {
Operation oOperation = new Operation(parentSet.getParent(iParent), iNode, Operation.OPERATION_DEL);
if (m_Cache.get(oOperation) > oBestOperation.m_fDeltaScore) {
if (isNotTabu(oOperation)) {
oBestOperation = oOperation;
oBestOperation.m_fDeltaScore = m_Cache.get(oOperation);
}
}
}
}
return oBestOperation;
}
示例5: findBestArcToReverse
import weka.classifiers.bayes.BayesNet; //导入方法依赖的package包/类
/**
* find best (or least bad) arc reversal operation
*
* @param bayesNet Bayes network to reverse arc in
* @param instances data set
* @param oBestOperation
* @return Operation containing best arc to reverse, or null if no reversal is allowed
* (happens if there is no arc in the network yet, or when any such reversal introduces
* a cycle).
*/
Operation findBestArcToReverse(BayesNet bayesNet, Instances instances, Operation oBestOperation) {
int nNrOfAtts = instances.numAttributes();
// find best arc to reverse
for (int iNode = 0; iNode < nNrOfAtts; iNode++) {
ParentSet parentSet = bayesNet.getParentSet(iNode);
for (int iParent = 0; iParent < parentSet.getNrOfParents(); iParent++) {
int iTail = parentSet.getParent(iParent);
// is reversal allowed?
if (reverseArcMakesSense(bayesNet, instances, iNode, iTail) &&
bayesNet.getParentSet(iTail).getNrOfParents() < m_nMaxNrOfParents) {
// go check if reversal results in the best step forward
Operation oOperation = new Operation(parentSet.getParent(iParent), iNode, Operation.OPERATION_REVERSE);
if (m_Cache.get(oOperation) > oBestOperation.m_fDeltaScore) {
if (isNotTabu(oOperation)) {
oBestOperation = oOperation;
oBestOperation.m_fDeltaScore = m_Cache.get(oOperation);
}
}
}
}
}
return oBestOperation;
}
示例6: findBestArcToDelete
import weka.classifiers.bayes.BayesNet; //导入方法依赖的package包/类
/**
* find best (or least bad) arc deletion operation
*
* @param bayesNet Bayes network to delete arc from
* @param instances data set
* @param oBestOperation
* @return Operation containing best arc to delete, or null if no deletion can be made
* (happens when there is no arc in the network yet).
* @throws Exception of something goes wrong
*/
Operation findBestArcToDelete(BayesNet bayesNet, Instances instances, Operation oBestOperation) throws Exception {
int nNrOfAtts = instances.numAttributes();
// find best arc to delete
for (int iNode = 0; iNode < nNrOfAtts; iNode++) {
ParentSet parentSet = bayesNet.getParentSet(iNode);
for (int iParent = 0; iParent < parentSet.getNrOfParents(); iParent++) {
Operation oOperation = new Operation(parentSet.getParent(iParent), iNode, Operation.OPERATION_DEL);
double fScore = calcScoreWithMissingParent(oOperation.m_nHead, oOperation.m_nTail);
if (fScore > oBestOperation.m_fScore) {
if (isNotTabu(oOperation)) {
oBestOperation = oOperation;
oBestOperation.m_fScore = fScore;
}
}
}
}
return oBestOperation;
}
示例7: findBestArcToReverse
import weka.classifiers.bayes.BayesNet; //导入方法依赖的package包/类
/**
* find best (or least bad) arc reversal operation
*
* @param bayesNet Bayes network to reverse arc in
* @param instances data set
* @param oBestOperation
* @return Operation containing best arc to reverse, or null if no reversal is allowed
* (happens if there is no arc in the network yet, or when any such reversal introduces
* a cycle).
* @throws Exception if something goes wrong
*/
Operation findBestArcToReverse(BayesNet bayesNet, Instances instances, Operation oBestOperation) throws Exception {
int nNrOfAtts = instances.numAttributes();
// find best arc to reverse
for (int iNode = 0; iNode < nNrOfAtts; iNode++) {
ParentSet parentSet = bayesNet.getParentSet(iNode);
for (int iParent = 0; iParent < parentSet.getNrOfParents(); iParent++) {
int iTail = parentSet.getParent(iParent);
// is reversal allowed?
if (reverseArcMakesSense(bayesNet, instances, iNode, iTail) &&
bayesNet.getParentSet(iTail).getNrOfParents() < m_nMaxNrOfParents) {
// go check if reversal results in the best step forward
Operation oOperation = new Operation(parentSet.getParent(iParent), iNode, Operation.OPERATION_REVERSE);
double fScore = calcScoreWithReversedParent(oOperation.m_nHead, oOperation.m_nTail);
if (fScore > oBestOperation.m_fScore) {
if (isNotTabu(oOperation)) {
oBestOperation = oOperation;
oBestOperation.m_fScore = fScore;
}
}
}
}
}
return oBestOperation;
}
示例8: generateRandomNet
import weka.classifiers.bayes.BayesNet; //导入方法依赖的package包/类
void generateRandomNet(BayesNet bayesNet, Instances instances) {
int nNodes = instances.numAttributes();
// clear network
for (int iNode = 0; iNode < nNodes; iNode++) {
ParentSet parentSet = bayesNet.getParentSet(iNode);
while (parentSet.getNrOfParents() > 0) {
parentSet.deleteLastParent(instances);
}
}
// initialize as naive Bayes?
if (getInitAsNaiveBayes()) {
int iClass = instances.classIndex();
// initialize parent sets to have arrow from classifier node to
// each of the other nodes
for (int iNode = 0; iNode < nNodes; iNode++) {
if (iNode != iClass) {
bayesNet.getParentSet(iNode).addParent(iClass, instances);
}
}
}
// insert random arcs
int nNrOfAttempts = m_random.nextInt(nNodes * nNodes);
for (int iAttempt = 0; iAttempt < nNrOfAttempts; iAttempt++) {
int iTail = m_random.nextInt(nNodes);
int iHead = m_random.nextInt(nNodes);
if (bayesNet.getParentSet(iHead).getNrOfParents() < getMaxNrOfParents()
&& addArcMakesSense(bayesNet, instances, iHead, iTail)) {
bayesNet.getParentSet(iHead).addParent(iTail, instances);
}
}
}
示例9: findBestArcToReverse
import weka.classifiers.bayes.BayesNet; //导入方法依赖的package包/类
/**
* find best (or least bad) arc reversal operation
*
* @param bayesNet Bayes network to reverse arc in
* @param instances data set
* @param oBestOperation
* @return Operation containing best arc to reverse, or null if no reversal is
* allowed (happens if there is no arc in the network yet, or when any
* such reversal introduces a cycle).
* @throws Exception if something goes wrong
*/
Operation findBestArcToReverse(BayesNet bayesNet, Instances instances,
Operation oBestOperation) throws Exception {
int nNrOfAtts = instances.numAttributes();
// find best arc to reverse
for (int iNode = 0; iNode < nNrOfAtts; iNode++) {
ParentSet parentSet = bayesNet.getParentSet(iNode);
for (int iParent = 0; iParent < parentSet.getNrOfParents(); iParent++) {
int iTail = parentSet.getParent(iParent);
// is reversal allowed?
if (reverseArcMakesSense(bayesNet, instances, iNode, iTail)
&& bayesNet.getParentSet(iTail).getNrOfParents() < m_nMaxNrOfParents) {
// go check if reversal results in the best step forward
Operation oOperation = new Operation(parentSet.getParent(iParent),
iNode, Operation.OPERATION_REVERSE);
double fScore = calcScoreWithReversedParent(oOperation.m_nHead,
oOperation.m_nTail);
if (fScore > oBestOperation.m_fScore) {
if (isNotTabu(oOperation)) {
oBestOperation = oOperation;
oBestOperation.m_fScore = fScore;
}
}
}
}
}
return oBestOperation;
}
示例10: generateRandomNet
import weka.classifiers.bayes.BayesNet; //导入方法依赖的package包/类
/**
*
* @param bayesNet
* @param instances
*/
void generateRandomNet(BayesNet bayesNet, Instances instances) {
int nNodes = instances.numAttributes();
// clear network
for (int iNode = 0; iNode < nNodes; iNode++) {
ParentSet parentSet = bayesNet.getParentSet(iNode);
while (parentSet.getNrOfParents() > 0) {
parentSet.deleteLastParent(instances);
}
}
// initialize as naive Bayes?
if (getInitAsNaiveBayes()) {
int iClass = instances.classIndex();
// initialize parent sets to have arrow from classifier node to
// each of the other nodes
for (int iNode = 0; iNode < nNodes; iNode++) {
if (iNode != iClass) {
bayesNet.getParentSet(iNode).addParent(iClass, instances);
}
}
}
// insert random arcs
int nNrOfAttempts = m_random.nextInt(nNodes * nNodes);
for (int iAttempt = 0; iAttempt < nNrOfAttempts; iAttempt++) {
int iTail = m_random.nextInt(nNodes);
int iHead = m_random.nextInt(nNodes);
if (bayesNet.getParentSet(iHead).getNrOfParents() < getMaxNrOfParents()
&& addArcMakesSense(bayesNet, instances, iHead, iTail)) {
bayesNet.getParentSet(iHead).addParent(iTail, instances);
}
}
}
示例11: generateRandomNet
import weka.classifiers.bayes.BayesNet; //导入方法依赖的package包/类
void generateRandomNet(BayesNet bayesNet, Instances instances) {
int nNodes = instances.numAttributes();
// clear network
for (int iNode = 0; iNode < nNodes; iNode++) {
ParentSet parentSet = bayesNet.getParentSet(iNode);
while (parentSet.getNrOfParents() > 0) {
parentSet.deleteLastParent(instances);
}
}
// initialize as naive Bayes?
if (getInitAsNaiveBayes()) {
int iClass = instances.classIndex();
// initialize parent sets to have arrow from classifier node to
// each of the other nodes
for (int iNode = 0; iNode < nNodes; iNode++) {
if (iNode != iClass) {
bayesNet.getParentSet(iNode).addParent(iClass, instances);
}
}
}
// insert random arcs
int nNrOfAttempts = m_random.nextInt(nNodes * nNodes);
for (int iAttempt = 0; iAttempt < nNrOfAttempts; iAttempt++) {
int iTail = m_random.nextInt(nNodes);
int iHead = m_random.nextInt(nNodes);
if (bayesNet.getParentSet(iHead).getNrOfParents() < getMaxNrOfParents() &&
addArcMakesSense(bayesNet, instances, iHead, iTail)) {
bayesNet.getParentSet(iHead).addParent(iTail, instances);
}
}
}
示例12: generateRandomNet
import weka.classifiers.bayes.BayesNet; //导入方法依赖的package包/类
/**
*
* @param bayesNet
* @param instances
*/
void generateRandomNet(BayesNet bayesNet, Instances instances) {
int nNodes = instances.numAttributes();
// clear network
for (int iNode = 0; iNode < nNodes; iNode++) {
ParentSet parentSet = bayesNet.getParentSet(iNode);
while (parentSet.getNrOfParents() > 0) {
parentSet.deleteLastParent(instances);
}
}
// initialize as naive Bayes?
if (getInitAsNaiveBayes()) {
int iClass = instances.classIndex();
// initialize parent sets to have arrow from classifier node to
// each of the other nodes
for (int iNode = 0; iNode < nNodes; iNode++) {
if (iNode != iClass) {
bayesNet.getParentSet(iNode).addParent(iClass, instances);
}
}
}
// insert random arcs
int nNrOfAttempts = m_random.nextInt(nNodes * nNodes);
for (int iAttempt = 0; iAttempt < nNrOfAttempts; iAttempt++) {
int iTail = m_random.nextInt(nNodes);
int iHead = m_random.nextInt(nNodes);
if (bayesNet.getParentSet(iHead).getNrOfParents() < getMaxNrOfParents() &&
addArcMakesSense(bayesNet, instances, iHead, iTail)) {
bayesNet.getParentSet(iHead).addParent(iTail, instances);
}
}
}
示例13: reverseArcMakesSense
import weka.classifiers.bayes.BayesNet; //导入方法依赖的package包/类
/**
* reverseArcMakesSense checks whether the arc from iAttributeTail to
* iAttributeHead exists and reversing does not introduce a cycle
*
* @param bayesNet
* @param instances
* @param iAttributeHead index of the attribute that is head of the arrow
* @param iAttributeTail index of the attribute that is tail of the arrow
* @return true if the arc from iAttributeTail to iAttributeHead exists and
* reversing does not introduce a cycle
*/
protected boolean reverseArcMakesSense(BayesNet bayesNet,
Instances instances, int iAttributeHead, int iAttributeTail) {
if (iAttributeHead == iAttributeTail) {
return false;
}
// sanity check: arc should be in parent set already
if (!isArc(bayesNet, iAttributeHead, iAttributeTail)) {
return false;
}
// sanity check: arc should not introduce a cycle
int nNodes = instances.numAttributes();
boolean[] bDone = new boolean[nNodes];
for (int iNode = 0; iNode < nNodes; iNode++) {
bDone[iNode] = false;
}
// check for cycles
bayesNet.getParentSet(iAttributeTail).addParent(iAttributeHead, instances);
for (int iNode = 0; iNode < nNodes; iNode++) {
// find a node for which all parents are 'done'
boolean bFound = false;
for (int iNode2 = 0; !bFound && iNode2 < nNodes; iNode2++) {
if (!bDone[iNode2]) {
ParentSet parentSet = bayesNet.getParentSet(iNode2);
boolean bHasNoParents = true;
for (int iParent = 0; iParent < parentSet.getNrOfParents(); iParent++) {
if (!bDone[parentSet.getParent(iParent)]) {
// this one has a parent which is not 'done' UNLESS it is the arc
// to be reversed
if (!(iNode2 == iAttributeHead && parentSet.getParent(iParent) == iAttributeTail)) {
bHasNoParents = false;
}
}
}
if (bHasNoParents) {
bDone[iNode2] = true;
bFound = true;
}
}
}
if (!bFound) {
bayesNet.getParentSet(iAttributeTail).deleteLastParent(instances);
return false;
}
}
bayesNet.getParentSet(iAttributeTail).deleteLastParent(instances);
return true;
}
示例14: doMarkovBlanketCorrection
import weka.classifiers.bayes.BayesNet; //导入方法依赖的package包/类
/**
* for each node in the network make sure it is in the Markov blanket of the
* classifier node, and if not, add arrows so that it is. If the node is an
* ancestor of the classifier node, add arrow pointing to the classifier node,
* otherwise, add arrow pointing to attribute node.
*
* @param bayesNet
* @param instances
*/
protected void doMarkovBlanketCorrection(BayesNet bayesNet,
Instances instances) {
// Add class node as parent if it is not in the Markov Boundary
int iClass = instances.classIndex();
ParentSet ancestors = new ParentSet();
int nOldSize = 0;
ancestors.addParent(iClass, instances);
while (nOldSize != ancestors.getNrOfParents()) {
nOldSize = ancestors.getNrOfParents();
for (int iNode = 0; iNode < nOldSize; iNode++) {
int iCurrent = ancestors.getParent(iNode);
ParentSet p = bayesNet.getParentSet(iCurrent);
for (int iParent = 0; iParent < p.getNrOfParents(); iParent++) {
if (!ancestors.contains(p.getParent(iParent))) {
ancestors.addParent(p.getParent(iParent), instances);
}
}
}
}
for (int iAttribute = 0; iAttribute < instances.numAttributes(); iAttribute++) {
boolean bIsInMarkovBoundary = (iAttribute == iClass)
|| bayesNet.getParentSet(iAttribute).contains(iClass)
|| bayesNet.getParentSet(iClass).contains(iAttribute);
for (int iAttribute2 = 0; !bIsInMarkovBoundary
&& iAttribute2 < instances.numAttributes(); iAttribute2++) {
bIsInMarkovBoundary = bayesNet.getParentSet(iAttribute2).contains(
iAttribute)
&& bayesNet.getParentSet(iAttribute2).contains(iClass);
}
if (!bIsInMarkovBoundary) {
if (ancestors.contains(iAttribute)) {
if (bayesNet.getParentSet(iClass).getCardinalityOfParents() < 1024) {
bayesNet.getParentSet(iClass).addParent(iAttribute, instances);
} else {
// too bad
}
} else {
bayesNet.getParentSet(iAttribute).addParent(iClass, instances);
}
}
}
}
示例15: reverseArcMakesSense
import weka.classifiers.bayes.BayesNet; //导入方法依赖的package包/类
/**
* reverseArcMakesSense checks whether the arc from iAttributeTail to
* iAttributeHead exists and reversing does not introduce a cycle
*
* @param bayesNet
* @param instances
* @param iAttributeHead index of the attribute that is head of the arrow
* @param iAttributeTail index of the attribute that is tail of the arrow
* @return true if the arc from iAttributeTail to iAttributeHead exists and reversing does not introduce a cycle
*/
protected boolean reverseArcMakesSense(
BayesNet bayesNet,
Instances instances,
int iAttributeHead,
int iAttributeTail) {
if (iAttributeHead == iAttributeTail) {
return false;
}
// sanity check: arc should be in parent set already
if (!isArc(bayesNet, iAttributeHead, iAttributeTail)) {
return false;
}
// sanity check: arc should not introduce a cycle
int nNodes = instances.numAttributes();
boolean[] bDone = new boolean[nNodes];
for (int iNode = 0; iNode < nNodes; iNode++) {
bDone[iNode] = false;
}
// check for cycles
bayesNet.getParentSet(iAttributeTail).addParent(iAttributeHead, instances);
for (int iNode = 0; iNode < nNodes; iNode++) {
// find a node for which all parents are 'done'
boolean bFound = false;
for (int iNode2 = 0; !bFound && iNode2 < nNodes; iNode2++) {
if (!bDone[iNode2]) {
ParentSet parentSet = bayesNet.getParentSet(iNode2);
boolean bHasNoParents = true;
for (int iParent = 0; iParent < parentSet.getNrOfParents(); iParent++) {
if (!bDone[parentSet.getParent(iParent)]) {
// this one has a parent which is not 'done' UNLESS it is the arc to be reversed
if (!(iNode2 == iAttributeHead && parentSet.getParent(iParent) == iAttributeTail)) {
bHasNoParents = false;
}
}
}
if (bHasNoParents) {
bDone[iNode2] = true;
bFound = true;
}
}
}
if (!bFound) {
bayesNet.getParentSet(iAttributeTail).deleteLastParent(instances);
return false;
}
}
bayesNet.getParentSet(iAttributeTail).deleteLastParent(instances);
return true;
}