本文整理汇总了Java中weka.classifiers.bayes.BayesNet类的典型用法代码示例。如果您正苦于以下问题:Java BayesNet类的具体用法?Java BayesNet怎么用?Java BayesNet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BayesNet类属于weka.classifiers.bayes包,在下文中一共展示了BayesNet类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: JunctionTreeSeparator
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
JunctionTreeSeparator(Set<Integer> separator, BayesNet bayesNet,
JunctionTreeNode childNode, JunctionTreeNode parentNode) {
// ////////////////////
// initialize node set
m_nNodes = new int[separator.size()];
int iPos = 0;
m_nCardinality = 1;
for (Integer element : separator) {
int iNode = element;
m_nNodes[iPos++] = iNode;
m_nCardinality *= bayesNet.getCardinality(iNode);
}
m_parentNode = parentNode;
m_childNode = childNode;
m_bayesNet = bayesNet;
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:17,代码来源:MarginCalculator.java
示例2: JunctionTreeNode
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
JunctionTreeNode(Set<Integer> clique, BayesNet bayesNet, boolean[] bDone) {
m_bayesNet = bayesNet;
m_children = new Vector<JunctionTreeNode>();
// ////////////////////
// initialize node set
m_nNodes = new int[clique.size()];
int iPos = 0;
m_nCardinality = 1;
for (Integer integer : clique) {
int iNode = integer;
m_nNodes[iPos++] = iNode;
m_nCardinality *= bayesNet.getCardinality(iNode);
}
// //////////////////////////////
// initialize potential function
calculatePotentials(bayesNet, clique, bDone);
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:18,代码来源:MarginCalculator.java
示例3: initCPTs
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
/**
* initCPTs reserves space for CPTs and set all counts to zero
*
* @param bayesNet the bayes net to use
* @throws Exception if something goes wrong
*/
@Override
public void initCPTs(BayesNet bayesNet) throws Exception {
// Reserve space for CPTs
int nMaxParentCardinality = 1;
for (int iAttribute = 0; iAttribute < bayesNet.m_Instances.numAttributes(); iAttribute++) {
if (bayesNet.getParentSet(iAttribute).getCardinalityOfParents() > nMaxParentCardinality) {
nMaxParentCardinality = bayesNet.getParentSet(iAttribute)
.getCardinalityOfParents();
}
}
// Reserve plenty of memory
bayesNet.m_Distributions = new Estimator[bayesNet.m_Instances
.numAttributes()][nMaxParentCardinality];
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:23,代码来源:BMAEstimator.java
示例4: updateClassifier
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
/**
* Updates the classifier with the given instance.
*
* @param bayesNet the bayes net to use
* @param instance the new training instance to include in the model
* @throws Exception if the instance could not be incorporated in the model.
*/
@Override
public void updateClassifier(BayesNet bayesNet, Instance instance)
throws Exception {
for (int iAttribute = 0; iAttribute < bayesNet.m_Instances.numAttributes(); iAttribute++) {
double iCPT = 0;
for (int iParent = 0; iParent < bayesNet.getParentSet(iAttribute)
.getNrOfParents(); iParent++) {
int nParent = bayesNet.getParentSet(iAttribute).getParent(iParent);
iCPT = iCPT * bayesNet.m_Instances.attribute(nParent).numValues()
+ instance.value(nParent);
}
bayesNet.m_Distributions[iAttribute][(int) iCPT].addValue(
instance.value(iAttribute), instance.weight());
}
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:26,代码来源:SimpleEstimator.java
示例5: initCPTs
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
/**
* initCPTs reserves space for CPTs and set all counts to zero
*
* @param bayesNet the bayes net to use
* @throws Exception if something goes wrong
*/
@Override
public void initCPTs(BayesNet bayesNet) throws Exception {
Instances instances = bayesNet.m_Instances;
// Reserve space for CPTs
int nMaxParentCardinality = 1;
for (int iAttribute = 0; iAttribute < instances.numAttributes(); iAttribute++) {
if (bayesNet.getParentSet(iAttribute).getCardinalityOfParents() > nMaxParentCardinality) {
nMaxParentCardinality = bayesNet.getParentSet(iAttribute)
.getCardinalityOfParents();
}
}
// Reserve plenty of memory
bayesNet.m_Distributions = new Estimator[instances.numAttributes()][nMaxParentCardinality];
// estimate CPTs
for (int iAttribute = 0; iAttribute < instances.numAttributes(); iAttribute++) {
for (int iParent = 0; iParent < bayesNet.getParentSet(iAttribute)
.getCardinalityOfParents(); iParent++) {
bayesNet.m_Distributions[iAttribute][iParent] = new DiscreteEstimatorBayes(
instances.attribute(iAttribute).numValues(), m_fAlpha);
}
}
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:32,代码来源:SimpleEstimator.java
示例6: search
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
/**
* search determines the network structure/graph of the network with the Taby
* algorithm.
*
* @param bayesNet the network to use
* @param instances the data to use
* @throws Exception if something goes wrong
*/
@Override
protected void search(BayesNet bayesNet, Instances instances)
throws Exception {
initCache(bayesNet, instances);
// go do the search
Operation oOperation = getOptimalOperation(bayesNet, instances);
while ((oOperation != null) && (oOperation.m_fDeltaScore > 0)) {
performOperation(bayesNet, instances, oOperation);
oOperation = getOptimalOperation(bayesNet, instances);
}
// free up memory
m_Cache = null;
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:24,代码来源:HillClimber.java
示例7: getOptimalOperation
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
/**
* getOptimalOperation finds the optimal operation that can be performed on
* the Bayes network that is not in the tabu list.
*
* @param bayesNet Bayes network to apply operation on
* @param instances data set to learn from
* @return optimal operation found
* @throws Exception if something goes wrong
*/
Operation getOptimalOperation(BayesNet bayesNet, Instances instances)
throws Exception {
Operation oBestOperation = new Operation();
// Add???
oBestOperation = findBestArcToAdd(bayesNet, instances, oBestOperation);
// Delete???
oBestOperation = findBestArcToDelete(bayesNet, instances, oBestOperation);
// Reverse???
if (getUseArcReversal()) {
oBestOperation = findBestArcToReverse(bayesNet, instances, oBestOperation);
}
// did we find something?
if (oBestOperation.m_fDeltaScore == -1E100) {
return null;
}
return oBestOperation;
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:30,代码来源:HillClimber.java
示例8: findBestArcToAdd
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
/**
* find best (or least bad) arc addition operation
*
* @param bayesNet Bayes network to add arc to
* @param instances data set
* @param oBestOperation
* @return Operation containing best arc to add, or null if no arc addition is
* allowed (this can happen if any arc addition introduces a cycle, or
* all parent sets are filled up to the maximum nr of parents).
*/
Operation findBestArcToAdd(BayesNet bayesNet, Instances instances,
Operation oBestOperation) {
int nNrOfAtts = instances.numAttributes();
// find best arc to add
for (int iAttributeHead = 0; iAttributeHead < nNrOfAtts; iAttributeHead++) {
if (bayesNet.getParentSet(iAttributeHead).getNrOfParents() < m_nMaxNrOfParents) {
for (int iAttributeTail = 0; iAttributeTail < nNrOfAtts; iAttributeTail++) {
if (addArcMakesSense(bayesNet, instances, iAttributeHead,
iAttributeTail)) {
Operation oOperation = new Operation(iAttributeTail,
iAttributeHead, Operation.OPERATION_ADD);
if (m_Cache.get(oOperation) > oBestOperation.m_fDeltaScore) {
if (isNotTabu(oOperation)) {
oBestOperation = oOperation;
oBestOperation.m_fDeltaScore = m_Cache.get(oOperation);
}
}
}
}
}
}
return oBestOperation;
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:34,代码来源:HillClimber.java
示例9: 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;
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:29,代码来源:HillClimber.java
示例10: 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;
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:36,代码来源:HillClimber.java
示例11: getOptimalOperation
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
/**
* getOptimalOperation finds the optimal operation that can be performed on
* the Bayes network that is not in the tabu list.
*
* @param bayesNet Bayes network to apply operation on
* @param instances data set to learn from
* @return optimal operation found
* @throws Exception if something goes wrong
*/
Operation getOptimalOperation(BayesNet bayesNet, Instances instances)
throws Exception {
Operation oBestOperation = new Operation();
// Add???
oBestOperation = findBestArcToAdd(bayesNet, instances, oBestOperation);
// Delete???
oBestOperation = findBestArcToDelete(bayesNet, instances, oBestOperation);
// Reverse???
if (getUseArcReversal()) {
oBestOperation = findBestArcToReverse(bayesNet, instances, oBestOperation);
}
// did we find something?
if (oBestOperation.m_fScore == -1E100) {
return null;
}
return oBestOperation;
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:30,代码来源:HillClimber.java
示例12: findBestArcToAdd
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
/**
* find best (or least bad) arc addition operation
*
* @param bayesNet Bayes network to add arc to
* @param instances data set
* @param oBestOperation
* @return Operation containing best arc to add, or null if no arc addition is
* allowed (this can happen if any arc addition introduces a cycle, or
* all parent sets are filled up to the maximum nr of parents).
* @throws Exception if something goes wrong
*/
Operation findBestArcToAdd(BayesNet bayesNet, Instances instances,
Operation oBestOperation) throws Exception {
int nNrOfAtts = instances.numAttributes();
// find best arc to add
for (int iAttributeHead = 0; iAttributeHead < nNrOfAtts; iAttributeHead++) {
if (bayesNet.getParentSet(iAttributeHead).getNrOfParents() < m_nMaxNrOfParents) {
for (int iAttributeTail = 0; iAttributeTail < nNrOfAtts; iAttributeTail++) {
if (addArcMakesSense(bayesNet, instances, iAttributeHead,
iAttributeTail)) {
Operation oOperation = new Operation(iAttributeTail,
iAttributeHead, Operation.OPERATION_ADD);
double fScore = calcScoreWithExtraParent(oOperation.m_nHead,
oOperation.m_nTail);
if (fScore > oBestOperation.m_fScore) {
if (isNotTabu(oOperation)) {
oBestOperation = oOperation;
oBestOperation.m_fScore = fScore;
}
}
}
}
}
}
return oBestOperation;
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:37,代码来源:HillClimber.java
示例13: 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;
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:32,代码来源:HillClimber.java
示例14: leaveOneOutCV
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
/**
* LeaveOneOutCV returns the accuracy calculated using Leave One Out cross
* validation. The dataset used is m_Instances associated with the Bayes
* Network.
*
* @param bayesNet : Bayes Network containing structure to evaluate
* @return accuracy (in interval 0..1) measured using leave one out cv.
* @throws Exception passed on by updateClassifier
*/
public double leaveOneOutCV(BayesNet bayesNet) throws Exception {
m_BayesNet = bayesNet;
double fAccuracy = 0.0;
double fWeight = 0.0;
Instances instances = bayesNet.m_Instances;
bayesNet.estimateCPTs();
for (int iInstance = 0; iInstance < instances.numInstances(); iInstance++) {
Instance instance = instances.instance(iInstance);
instance.setWeight(-instance.weight());
bayesNet.updateClassifier(instance);
fAccuracy += accuracyIncrease(instance);
fWeight += instance.weight();
instance.setWeight(-instance.weight());
bayesNet.updateClassifier(instance);
}
return fAccuracy / fWeight;
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:27,代码来源:GlobalScoreSearchAlgorithm.java
示例15: missingArcs
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
/**
* Count nr of arcs missing from other network compared to current network
* Note that an arc is not 'missing' if it is reversed.
*
* @param other network to compare with
* @return nr of missing arcs
*/
public int missingArcs(BayesNet other) {
try {
Sync(other);
int nMissing = 0;
for (int iAttribute = 0; iAttribute < m_Instances.numAttributes(); iAttribute++) {
for (int iParent = 0; iParent < m_ParentSets[iAttribute]
.getNrOfParents(); iParent++) {
int nParent = m_ParentSets[iAttribute].getParent(iParent);
if (!other.getParentSet(m_order[iAttribute]).contains(
m_order[nParent])
&& !other.getParentSet(m_order[nParent]).contains(
m_order[iAttribute])) {
nMissing++;
}
}
}
return nMissing;
} catch (Exception e) {
System.err.println(e.getMessage());
return 0;
}
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:30,代码来源:BIFReader.java
示例16: extraArcs
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
/**
* Count nr of exta arcs from other network compared to current network Note
* that an arc is not 'extra' if it is reversed.
*
* @param other network to compare with
* @return nr of missing arcs
*/
public int extraArcs(BayesNet other) {
try {
Sync(other);
int nExtra = 0;
for (int iAttribute = 0; iAttribute < m_Instances.numAttributes(); iAttribute++) {
for (int iParent = 0; iParent < other.getParentSet(m_order[iAttribute])
.getNrOfParents(); iParent++) {
int nParent = m_order[other.getParentSet(m_order[iAttribute])
.getParent(iParent)];
if (!m_ParentSets[iAttribute].contains(nParent)
&& !m_ParentSets[nParent].contains(iAttribute)) {
nExtra++;
}
}
}
return nExtra;
} catch (Exception e) {
System.err.println(e.getMessage());
return 0;
}
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:29,代码来源:BIFReader.java
示例17: reversedArcs
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
/**
* Count nr of reversed arcs from other network compared to current network
*
* @param other network to compare with
* @return nr of missing arcs
*/
public int reversedArcs(BayesNet other) {
try {
Sync(other);
int nReversed = 0;
for (int iAttribute = 0; iAttribute < m_Instances.numAttributes(); iAttribute++) {
for (int iParent = 0; iParent < m_ParentSets[iAttribute]
.getNrOfParents(); iParent++) {
int nParent = m_ParentSets[iAttribute].getParent(iParent);
if (!other.getParentSet(m_order[iAttribute]).contains(
m_order[nParent])
&& other.getParentSet(m_order[nParent]).contains(
m_order[iAttribute])) {
nReversed++;
}
}
}
return nReversed;
} catch (Exception e) {
System.err.println(e.getMessage());
return 0;
}
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:29,代码来源:BIFReader.java
示例18: initCPTs
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
/**
* initCPTs reserves space for CPTs and set all counts to zero
*
* @param bayesNet the bayes net to use
* @throws Exception if something goes wrong
*/
public void initCPTs(BayesNet bayesNet) throws Exception {
Instances instances = bayesNet.m_Instances;
// Reserve space for CPTs
int nMaxParentCardinality = 1;
for (int iAttribute = 0; iAttribute < instances.numAttributes(); iAttribute++) {
if (bayesNet.getParentSet(iAttribute).getCardinalityOfParents() > nMaxParentCardinality) {
nMaxParentCardinality = bayesNet.getParentSet(iAttribute).getCardinalityOfParents();
}
}
// Reserve plenty of memory
bayesNet.m_Distributions = new Estimator[instances.numAttributes()][nMaxParentCardinality];
// estimate CPTs
for (int iAttribute = 0; iAttribute < instances.numAttributes(); iAttribute++) {
for (int iParent = 0; iParent < bayesNet.getParentSet(iAttribute).getCardinalityOfParents(); iParent++) {
bayesNet.m_Distributions[iAttribute][iParent] =
new DiscreteEstimatorBayes(instances.attribute(iAttribute).numValues(), m_fAlpha);
}
}
}
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:29,代码来源:SimpleEstimator.java
示例19: buildStructure
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
/**
*
* @param bayesNet
* @param instances the instances to work with
* @throws Exception if attribute from BIF file could not be found
*/
public void buildStructure (BayesNet bayesNet, Instances instances) throws Exception {
// read network structure in BIF format
BIFReader bifReader = new BIFReader();
bifReader.processFile(m_sBIFFile);
// copy parent sets
for (int iAttribute = 0; iAttribute < instances.numAttributes(); iAttribute++) {
int iBIFAttribute = bifReader.getNode(bayesNet.getNodeName(iAttribute));
ParentSet bifParentSet = bifReader.getParentSet(iBIFAttribute);
for (int iBIFParent = 0; iBIFParent < bifParentSet.getNrOfParents(); iBIFParent++) {
String sParent = bifReader.getNodeName(bifParentSet.getParent(iBIFParent));
int iParent = 0;
while (iParent < instances.numAttributes() && !bayesNet.getNodeName(iParent).equals(sParent)) {
iParent++;
}
if (iParent >= instances.numAttributes()) {
throw new Exception("Could not find attribute " + sParent + " from BIF file in data");
}
bayesNet.getParentSet(iAttribute).addParent(iParent, instances);
}
}
}
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:28,代码来源:FromFile.java
示例20: search
import weka.classifiers.bayes.BayesNet; //导入依赖的package包/类
/**
* search determines the network structure/graph of the network
* with the Taby algorithm.
*
* @param bayesNet the network to use
* @param instances the data to use
* @throws Exception if something goes wrong
*/
protected void search(BayesNet bayesNet, Instances instances) throws Exception {
initCache(bayesNet, instances);
// go do the search
Operation oOperation = getOptimalOperation(bayesNet, instances);
while ((oOperation != null) && (oOperation.m_fDeltaScore > 0)) {
performOperation(bayesNet, instances, oOperation);
oOperation = getOptimalOperation(bayesNet, instances);
if(Thread.interrupted())
break;
}
// free up memory
m_Cache = null;
}
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:24,代码来源:HillClimber.java
注:本文中的weka.classifiers.bayes.BayesNet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论