当前位置: 首页>>代码示例>>Java>>正文


Java Instances.iterator方法代码示例

本文整理汇总了Java中weka.core.Instances.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java Instances.iterator方法的具体用法?Java Instances.iterator怎么用?Java Instances.iterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weka.core.Instances的用法示例。


在下文中一共展示了Instances.iterator方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: calculateSupport

import weka.core.Instances; //导入方法依赖的package包/类
/**
 * Calculate support value of a given rule on the dataset
 * 
 * @param dataset the dataset
 * @param bodySide left-side or BODY part of the rule
 * @return support value for the rule on the given dataset
 */
public double calculateSupport(Instances dataset, List<Term> bodySide){
    
    Iterator<Instance> datasetIterator = dataset.iterator();
    int supportCount = 0;
    
    while(datasetIterator.hasNext()){
        
        Instance anInstance = datasetIterator.next();
        
        if(instanceCoveredByTermsList(anInstance,bodySide)){
            supportCount++;
        }
        
    }
    return !dataset.isEmpty() ? (double) supportCount / (double) dataset.size() : 0.0d;
}
 
开发者ID:thienle2401,项目名称:GeneralisedRulesAlgorithm,代码行数:24,代码来源:GRules.java

示例2: calcualteConfidence

import weka.core.Instances; //导入方法依赖的package包/类
/**
 * Calculate confidence value of a given rule on the dataset
 * 
 * @param dataset the dataset
 * @param bodySide left-side or BODY part of the rule
 * @param HeadSide right-side or HEAD part of the rule
 * @return confidence value for the rule on the given dataset
 */
public double calcualteConfidence(Instances dataset, List<Term> bodySide, List<Term> HeadSide){
    Iterator<Instance> datasetIterator = dataset.iterator();
    int confidenceCount = 0;
    int supportCount = 0;
    while(datasetIterator.hasNext()){
        
        Instance anInstance = datasetIterator.next();
        
        if(instanceCoveredByTermsList(anInstance,bodySide)){
            supportCount++;
            if(instanceCoveredByTermsList(anInstance,HeadSide)){
                confidenceCount++;
            }
        }
        
    }
    return !dataset.isEmpty() ? (double) confidenceCount / (double) supportCount : 0.0d;
}
 
开发者ID:thienle2401,项目名称:GeneralisedRulesAlgorithm,代码行数:27,代码来源:GRules.java

示例3: allInstancesCoveredByTermsBothSides

import weka.core.Instances; //导入方法依赖的package包/类
/**
 * check if all instances from a given dataset is covered/ satisfied by both BODY and HEAD
 * 
 * @param dataset instances to be checked
 * @param leftHandSide these rule term(s) represent the BODY
 * @param rightHandside these rule term(s) represent the HEAD
 * @return true if all instances covered by the rule, false otherwise
 */

public boolean allInstancesCoveredByTermsBothSides(Instances dataset, List<Term> leftHandSide, List<Term> rightHandside){
    
    if(rightHandside.isEmpty() || leftHandSide.isEmpty()){
        return false;
    }
    
    Iterator<Instance> datasetIterator = dataset.iterator();
    while(datasetIterator.hasNext()){
        Instance anInstance = datasetIterator.next();
        
        // 1st check if the instance is totally covered by the right hand-side
       for (int termI = 0; termI < rightHandside.size(); termI++) {
           if(rightHandside.get(termI).coveredInstance(anInstance) == false){
               return false;
           }
       }
       
       // 2nd check if the instance is totally covered by the right hand-side
        for (int termI = 0; termI < leftHandSide.size(); termI++) {
           if(leftHandSide.get(termI).coveredInstance(anInstance) == false){
               return false;
           }
       }
       
    }
    
    return true;
}
 
开发者ID:thienle2401,项目名称:GeneralisedRulesAlgorithm,代码行数:38,代码来源:GRules.java

示例4: calcuateFalsePositiveRate

import weka.core.Instances; //导入方法依赖的package包/类
/**
 * Calculate false positive rate,
 * the false positive rate is calculated by no. false positive / total negative
 * 
 * @param dataset the dataset that will be used for the calculation
 * @param selectedRules the rule that is used for the calculation
 * @return false positive for the given rules and the input dataset
 */
public double calcuateFalsePositiveRate(Instances dataset, List<Rule> selectedRules){
    
     // calculate total negative example
    int falsePostive = 0;    
    int trueNegative = 0;
    
    Iterator<Instance> instancesIterator;   
    
     // go through each selected rule
    for (Rule aRule : selectedRules) {
        
        // got HEAD from the rules
        List<Term> HeadTerms = aRule.getRightSdie();
        List<Term> bodyTerm = aRule.getLeftSide();
        
        // check whether this rule is positive (covered by the HEAD only)
        instancesIterator = dataset.iterator();
        
        while(instancesIterator.hasNext()){
            
            Instance anInstance = instancesIterator.next();
            
            if(instanceCoveredByTermsList(anInstance, bodyTerm) == true && instanceCoveredByTermsList(anInstance, HeadTerms) == false){
                falsePostive++;
            }
            
            if(instanceCoveredByTermsList(anInstance, bodyTerm) == false && instanceCoveredByTermsList(anInstance, HeadTerms) == false){
                trueNegative++;
            }                
            
        }
    }       
    
    double falsePositiveRate = (double) falsePostive / (double) (falsePostive + trueNegative);
    
    return falsePositiveRate;
}
 
开发者ID:thienle2401,项目名称:GeneralisedRulesAlgorithm,代码行数:46,代码来源:GRules.java

示例5: collectPerfs

import weka.core.Instances; //导入方法依赖的package包/类
@Override
public Instances collectPerfs(Instances samplePoints, String perfAttName) {
	Instances retVal = null;
	
	if(samplePoints.attribute(perfAttName) == null){
		Attribute performance = new Attribute(perfAttName);
		samplePoints.insertAttributeAt(performance, samplePoints.numAttributes());
	}
	
	File perfFolder = new File(perfsfilepath);
	int tot=0;
	if(perfFolder.exists()){
		//let's get all the name set for the sample points
		Iterator<Instance> itr = samplePoints.iterator();
		TreeSet<String> insNameSet = new TreeSet<String>();
		HashMap<String, Integer> mapping = new HashMap<String, Integer>();
		int pos=0;
		while(itr.hasNext()){
			String mdstr = getMD5(itr.next());
			insNameSet.add(mdstr);
			mapping.put(mdstr, new Integer(pos++));
		}
		
		//now we collect
		File[] perfFiles = perfFolder.listFiles(new PerfsFileFilter(insNameSet));
		tot = perfFiles.length;
		if(tot > 0) isInterrupt = true;
		for(int i=0;i<tot;i++){
			Instance ins = samplePoints.get(mapping.get(perfFiles[i].getName()));
			double[] results = getPerf(perfFiles[i].getAbsolutePath());
			if(results!=null){
				ins.setValue(samplePoints.numAttributes()-1, results[0]);
			}
		}
	}
	retVal = samplePoints;
	retVal.setClassIndex(retVal.numAttributes()-1);
	System.out.println("Total number of collected performances is : "+tot);
	return retVal;
}
 
开发者ID:zhuyuqing,项目名称:bestconf,代码行数:41,代码来源:AutoTestAdjust.java

示例6: removeInstancesCoveredByRule

import weka.core.Instances; //导入方法依赖的package包/类
/**
 * Remove all data instances from the dataset for a given rule
 * 
 * @param dataset the input dataset
 * @param aRule the rule is used to classify instances and these instances will be removed from the dataset
 */
public void removeInstancesCoveredByRule(Instances dataset, Rule aRule){
    
    List<Term> aLeftSide = aRule.getLeftSide();
    List<Term> aRightSide = aRule.getRightSdie();
    
    Iterator<Instance> datasetIterator = dataset.iterator();
    
    while(datasetIterator.hasNext()){
        
        Instance anInstance = datasetIterator.next();
        
        if(instanceCoveredByTermsList(anInstance, aLeftSide) == true &&
                instanceCoveredByTermsList(anInstance, aRightSide) == true){
            datasetIterator.remove();
            
        }
    }
}
 
开发者ID:thienle2401,项目名称:GeneralisedRulesAlgorithm,代码行数:25,代码来源:GRules.java

示例7: calcualteTruePostiveRate

import weka.core.Instances; //导入方法依赖的package包/类
/**
 * Calculate true positive rate, 
 * The rate of true positive is calculated by no. true positive / total positive
 * 
 * @param dataset
 * @param selectedRules
 * @return 
 */

public double calcualteTruePostiveRate(Instances dataset, List<Rule> selectedRules){
    
    // calculate total postive example
    int truePositive = 0;
    int falseNegative = 0;
    
    Iterator<Instance> instancesIterator;
    
    // go through each selected rule
    for (Rule aRule : selectedRules) {
        
        // got HEAD from the rules
        List<Term> HeadTerms = aRule.getRightSdie();
        List<Term> bodyTerm = aRule.getLeftSide();
        
        // check whether this rule is positive (covered by the HEAD only)
        instancesIterator = dataset.iterator();
        
        while(instancesIterator.hasNext()){
            
            Instance anInstance = instancesIterator.next();
            
            if(instanceCoveredByTermsList(anInstance, HeadTerms) == true && instanceCoveredByTermsList(anInstance, bodyTerm) == true){
                truePositive++;
            }
            
            if(instanceCoveredByTermsList(anInstance, HeadTerms) == false && instanceCoveredByTermsList(anInstance, bodyTerm) == true){
                falseNegative++;
            }
        }
    }
           
    double truePostitveRate = (double) truePositive / (double) (truePositive + falseNegative);
    
    return truePostitveRate;
    
}
 
开发者ID:thienle2401,项目名称:GeneralisedRulesAlgorithm,代码行数:47,代码来源:GRules.java


注:本文中的weka.core.Instances.iterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。