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


Java Instance.value方法代码示例

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


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

示例1: instanceToDenseDMatrix

import weka.core.Instance; //导入方法依赖的package包/类
public static DMatrix instanceToDenseDMatrix(Instance instance) throws XGBoostError {
    Attribute classAttribute = instance.classAttribute();
    int classAttrIndex = classAttribute.index();

    int colNum = instance.numAttributes()-1;
    int rowNum = 1;

    float[] data = new float[colNum*rowNum];

    Enumeration<Attribute> attributeEnumeration = instance.enumerateAttributes();
    int dataIndex = 0;
    while (attributeEnumeration.hasMoreElements()) {
        Attribute attribute = attributeEnumeration.nextElement();
        int attrIndex = attribute.index();
        if(attrIndex == classAttrIndex){
            continue;
        }
        data[dataIndex]= (float) instance.value(attribute);
        dataIndex++;
    }

    return new DMatrix(data, rowNum, colNum);
}
 
开发者ID:SigDelta,项目名称:weka-xgboost,代码行数:24,代码来源:DMatrixLoader.java

示例2: getTopPositiveWekaFeaturesInReport

import weka.core.Instance; //导入方法依赖的package包/类
protected List<FeatureWeight> getTopPositiveWekaFeaturesInReport(Instance reportInstance,
		HashMap<String, Integer> featureIndexMap, String[][] featureWeightTable, int topKwords) throws Exception {
	List<FeatureWeight> topPositiveFeatureList = new ArrayList<>();
	int iFeature = 0;
	double weight;
	FeatureWeight featureWeight;
	while(topPositiveFeatureList.size() < topKwords &&
			iFeature < featureIndexMap.size()) {
		weight = Double.parseDouble(featureWeightTable[iFeature][1]); 
		if(weight > 0 &&
				reportInstance.value(featureIndexMap.get(featureWeightTable[iFeature][0]) + 1) == 1) { // reportID is the first att in reportInstance
			featureWeight = new FeatureWeight();
			featureWeight.setTerm(featureWeightTable[iFeature][0]);
			featureWeight.setWeight(weight);
			topPositiveFeatureList.add(featureWeight);
		}
		iFeature++;
	}
	return topPositiveFeatureList;
}
 
开发者ID:NLPReViz,项目名称:emr-nlp-server,代码行数:21,代码来源:Report_Controller.java

示例3: mergeInstanceIntoTuple

import weka.core.Instance; //导入方法依赖的package包/类
private void mergeInstanceIntoTuple(Instance instance, Tuple tuple) throws DbException {
   	// Merge the tuple and the instance. Only values in dropFields will
   	// change; the other values of the tuple will be unchanged by the
   	// imputation.
   	Iterator<Entry<Integer, Integer>> indexIt = this.dropFieldsIndicesMap.entrySet().iterator();
   	while (indexIt.hasNext()){
   		Entry<Integer, Integer> map = indexIt.next();
   		int k = map.getKey(); // index in Instance
   		int v = map.getValue(); // index in Tuple

   		double value = instance.value(k);

		if (td.getFieldType(v) == Type.INT_TYPE){
			tuple.setField(v, new IntField((int) value));
		} else if (td.getFieldType(v) == Type.DOUBLE_TYPE){
			tuple.setField(v, new DoubleField(value));
		} else {
			throw new DbException("Field type not implemented.");
		}
   	}
}
 
开发者ID:mitdbg,项目名称:imputedb,代码行数:22,代码来源:ImputeRegressionTree.java

示例4: classifyInstance

import weka.core.Instance; //导入方法依赖的package包/类
@Override
public double classifyInstance(Instance sample) throws Exception {
	// transform instance to sequence
	MonoDoubleItemSet[] sequence = new MonoDoubleItemSet[sample.numAttributes() - 1];
	int shift = (sample.classIndex() == 0) ? 1 : 0;
	for (int t = 0; t < sequence.length; t++) {
		sequence[t] = new MonoDoubleItemSet(sample.value(t + shift));
	}
	SymbolicSequence seq = new SymbolicSequence(sequence);

	double minD = Double.MAX_VALUE;
	String classValue = null;
	seq.LB_KeoghFillUL(bestWarpingWindow, U, L);
	
	for (int i = 0; i < train.length; i++) {
		SymbolicSequence s = train[i];
		if (SymbolicSequence.LB_KeoghPreFilled(s, U, L) < minD) {
			double tmpD = seq.DTW(s,bestWarpingWindow, warpingMatrix);
			if (tmpD < minD) {
				minD = tmpD;
				classValue = classMap[i];
			}
		}
	}
	// System.out.println(prototypes.size());
	return sample.classAttribute().indexOfValue(classValue);
}
 
开发者ID:ChangWeiTan,项目名称:FastWWSearch,代码行数:28,代码来源:NaiveDTW.java

示例5: computeOmegaDelta

import weka.core.Instance; //导入方法依赖的package包/类
private static double computeOmegaDelta(M5P model, M5P modelPi, Instances omega) throws Exception{
	double retval = 0., y;
	Enumeration<Instance> enu = omega.enumerateInstances();
	int idxClass = omega.classIndex();
	Instance ins;
	while(enu.hasMoreElements()){
		ins = enu.nextElement();
		y = ins.value(idxClass);
		retval += Math.pow(y-model.classifyInstance(ins), 2)-Math.pow(y-modelPi.classifyInstance(ins), 2);
	}
	return retval;
}
 
开发者ID:zhuyuqing,项目名称:bestconf,代码行数:13,代码来源:COMT2.java

示例6: coveredInstance

import weka.core.Instance; //导入方法依赖的package包/类
public boolean coveredInstance(Instance instanceIn){
           
           if (isCategorial()) {
               return instanceIn.value((int) attributeIndex) == attributeValue;
           }else if(isNumeric()){
               return (upperBoundNumeric >= instanceIn.value((int) attributeIndex) && lowerBoundNumeric < instanceIn.value((int) attributeIndex));
           }
           
           return false;
}
 
开发者ID:thienle2401,项目名称:GeneralisedRulesAlgorithm,代码行数:11,代码来源:GRules.java

示例7: instancesToDenseDMatrix

import weka.core.Instance; //导入方法依赖的package包/类
public static DMatrix instancesToDenseDMatrix(Instances instances) throws XGBoostError {
    int colNum = instances.numAttributes()-1;
    int rowNum = instances.size();

    float[] data = new float[colNum*rowNum];
    float[] labels = new float[instances.size()];
    Attribute classAttribute = instances.classAttribute();
    int classAttrIndex = classAttribute.index();

    for(int i=0, dataIndex = 0; i<instances.size(); i++) {
        Instance instance = instances.get(i);

        labels[i] = (float) instance.classValue();
        Enumeration<Attribute> attributeEnumeration = instance.enumerateAttributes();
        while (attributeEnumeration.hasMoreElements()) {
            Attribute attribute = attributeEnumeration.nextElement();
            int attrIndex = attribute.index();
            if(attrIndex == classAttrIndex){
                continue;
            }
            data[dataIndex]= (float) instance.value(attribute);
            dataIndex++;
        }
    }


    DMatrix dMatrix = new DMatrix(data, rowNum, colNum);

    dMatrix.setLabel(labels);
    return dMatrix;

}
 
开发者ID:SigDelta,项目名称:weka-xgboost,代码行数:33,代码来源:DMatrixLoader.java

示例8: processInstance

import weka.core.Instance; //导入方法依赖的package包/类
protected static void processInstance(Instance instance, List<Float> dataList, List<Integer> colList ){
        Attribute classAttribute = instance.classAttribute();
        int classAttrIndex = classAttribute.index();
        Enumeration<Attribute> attributeEnumeration = instance.enumerateAttributes();
        while (attributeEnumeration.hasMoreElements()) {
            Attribute attribute = attributeEnumeration.nextElement();
//            System.out.print(attribute.name()+", ");
            int attrIndex = attribute.index();

            if(attrIndex == classAttrIndex){
                continue;
            }
            double value = instance.value(attribute);

            if (value == 0) {
                continue;
            }

            dataList.add((float) value);

            if (attrIndex < classAttrIndex) {
                colList.add(attrIndex);
            }else{
                colList.add(attrIndex+1);
            }

        }
//        System.out.println();
    }
 
开发者ID:SigDelta,项目名称:weka-xgboost,代码行数:30,代码来源:DMatrixLoader.java

示例9: scoreInstance

import weka.core.Instance; //导入方法依赖的package包/类
private double scoreInstance(Instance instance) {
	// bias
	double score = 1 * this.weights[0];
	// ignore id and topic and class label
	for (int i = 2; i < instance.numAttributes() - 1; i++) {
		score += this.weights[i - 1] * instance.value(i);
	}
	return score;
}
 
开发者ID:UKPLab,项目名称:ijcnlp2017-cmaps,代码行数:10,代码来源:RankingSVM.java

示例10: calculateProbabilityOfOccurence

import weka.core.Instance; //导入方法依赖的package包/类
private double calculateProbabilityOfOccurence(RuleTerm ruleTerm, ArrayList<Instance> dataset, double classification ){
	
	int totalNoInstancesCoveredByRuleTerm = 0;
	int totalNoInstancesCoveredByRuleTermWithClassification = 0;
	List<Instance> instancesList = new ArrayList<>(dataset);
	
	for (Instance instance : instancesList) {
                          
		if(instance.value(ruleTerm.attribute) == ruleTerm.value){

			totalNoInstancesCoveredByRuleTerm++;
			
			// check if ruleTerm covered instance for specific classification
			if(instance.classValue() == classification){
				totalNoInstancesCoveredByRuleTermWithClassification++;
			}
			
		}
	}
	
	double probabilityOfOccurencesForClassification = (double) totalNoInstancesCoveredByRuleTermWithClassification / (double) totalNoInstancesCoveredByRuleTerm;
	
	
	return Double.isNaN(probabilityOfOccurencesForClassification) ? 0.0d : probabilityOfOccurencesForClassification;
}
 
开发者ID:thienle2401,项目名称:G-eRules,代码行数:26,代码来源:GeRules.java

示例11: scaleDownMindists

import weka.core.Instance; //导入方法依赖的package包/类
private static ArrayList<Attribute> scaleDownMindists(Instances previousSet, Instance center){
	ArrayList<Attribute> localAtts = new ArrayList<Attribute>();
	int attNum = center.numAttributes();
	
	int pos = previousSet.attribute(PerformanceAttName).index();
	
	//traverse each dimension
	Enumeration<Instance> enu;
	double minDis;
	for(int i=0;i<attNum;i++){
		if(i==pos)
			continue;
		
		enu = previousSet.enumerateInstances();
		minDis = Double.MAX_VALUE;
		
		while(enu.hasMoreElements()){
			Instance ins = enu.nextElement();
			if(!ins.equals(center))
				minDis = Math.min((double)((int)(Math.abs(ins.value(i)-center.value(i))*1000))/1000.0, minDis);
		}
		
		//now we set the range
		Properties p1 = new Properties();
		double upper = center.value(i)+minDis, lower=center.value(i)-minDis;
		
		TreeSet<Double> detourSet = new TreeSet<Double>();
		detourSet.add(upper);
		detourSet.add(lower);
		detourSet.add(previousSet.attribute(i).getUpperNumericBound());
		detourSet.add(previousSet.attribute(i).getLowerNumericBound());
		switch(detourSet.size()){
		case 1:
			upper=lower=detourSet.first();
			break;
		case 2:
			upper = detourSet.last();
			lower = detourSet.first();
			break;
		case 3:
			upper=lower=detourSet.higher(detourSet.first());
			break;
		default://case 4:
			upper=detourSet.lower(detourSet.last());
			lower=detourSet.higher(detourSet.first());
			break;
		}
		
		p1.setProperty("range", "["+String.valueOf(lower)+","+String.valueOf(upper)+"]");
		ProtectedProperties prop1 = new ProtectedProperties(p1);
		
		localAtts.add(new Attribute(previousSet.attribute(i).name(), prop1));
	}
	
	return localAtts;
}
 
开发者ID:zhuyuqing,项目名称:BestConfig,代码行数:57,代码来源:ConfigSampler.java

示例12: scaleDownNeighbordists

import weka.core.Instance; //导入方法依赖的package包/类
private static ArrayList<Attribute> scaleDownNeighbordists(Instances previousSet, Instance center){
	ArrayList<Attribute> localAtts = new ArrayList<Attribute>();
	int attNum = center.numAttributes();
	
	int pos = -1;
	if(previousSet.attribute(PerformanceAttName)!=null)
		pos = previousSet.attribute(PerformanceAttName).index();
	
	//traverse each dimension
	Enumeration<Instance> enu;
	double[] minDists = new double[2];
	double val;
	for(int i=0;i<attNum;i++){
		if(i==pos)
			continue;
		
		enu = previousSet.enumerateInstances();
		minDists[0] = 1-Double.MAX_VALUE;
		minDists[1] = Double.MAX_VALUE;
		
		while(enu.hasMoreElements()){
			Instance ins = enu.nextElement();
			if(!ins.equals(center)){
				val = ins.value(i)-center.value(i);
				if(val<0)
					minDists[0] = Math.max((double)((int)((ins.value(i)-center.value(i))*1000))/1000.0, minDists[0]);
				else
					minDists[1] = Math.min((double)((int)((ins.value(i)-center.value(i))*1000))/1000.0, minDists[1]);
			}
		}
		
		//now we set the range
		Properties p1 = new Properties();
		double upper = center.value(i)+minDists[1], lower=center.value(i)+minDists[0];
		
		TreeSet<Double> detourSet = new TreeSet<Double>();
		detourSet.add(upper);
		detourSet.add(lower);
		detourSet.add(previousSet.attribute(i).getUpperNumericBound());
		detourSet.add(previousSet.attribute(i).getLowerNumericBound());
		switch(detourSet.size()){
		case 1:
			upper=lower=detourSet.first();
			break;
		case 2:
			upper = detourSet.last();
			lower = detourSet.first();
			break;
		case 3:
			upper=lower=detourSet.higher(detourSet.first());
			break;
		default://case 4:
			upper=detourSet.lower(detourSet.last());
			lower=detourSet.higher(detourSet.first());
			break;
		}
		
		p1.setProperty("range", "["+String.valueOf(lower)+","+String.valueOf(upper)+"]");
		ProtectedProperties prop1 = new ProtectedProperties(p1);
		
		localAtts.add(new Attribute(previousSet.attribute(i).name(), prop1));
	}
	
	return localAtts;
}
 
开发者ID:zhuyuqing,项目名称:bestconf,代码行数:66,代码来源:ConfigSampler.java

示例13: scaleDownDetour

import weka.core.Instance; //导入方法依赖的package包/类
public static ArrayList<Attribute> scaleDownDetour(Instances previousSet, Instance center){
	ArrayList<Attribute> localAtts = new ArrayList<Attribute>();
	int attNum = center.numAttributes();
	
	int pos = previousSet.attribute(PerformanceAttName).index();
	
	//traverse each dimension
	Enumeration<Instance> enu;
	double minDis;
	for(int i=0;i<attNum;i++){
		if(i==pos)
			continue;
		
		enu = previousSet.enumerateInstances();
		minDis = Double.MAX_VALUE;
		
		while(enu.hasMoreElements()){
			Instance ins = enu.nextElement();
			if(!ins.equals(center))
				minDis = Math.min((double)((int)(Math.abs(ins.value(i)-center.value(i))*100))/100.0, minDis);
		}
		
		//now we set the range
		Properties p1 = new Properties();
		double upper = center.value(i)+minDis, lower=center.value(i)-minDis;
		
		TreeSet<Double> detourSet = new TreeSet<Double>();
		detourSet.add(upper);
		detourSet.add(lower);
		detourSet.add(previousSet.attribute(i).getUpperNumericBound());
		detourSet.add(previousSet.attribute(i).getLowerNumericBound());
		switch(detourSet.size()){
		case 1:
			upper=lower=detourSet.first();
			break;
		case 2:
			upper = detourSet.last();
			lower = detourSet.first();
			break;
		case 3:
			upper=lower=detourSet.higher(detourSet.first());
			break;
		default://case 4:
			upper=detourSet.lower(detourSet.last());
			lower=detourSet.higher(detourSet.first());
			break;
		}
		
		p1.setProperty("range", "["+String.valueOf(lower)+","+String.valueOf(upper)+"]");
		ProtectedProperties prop1 = new ProtectedProperties(p1);
		
		localAtts.add(new Attribute(previousSet.attribute(i).name(), prop1));
	}
	
	return localAtts;
}
 
开发者ID:zhuyuqing,项目名称:bestconf,代码行数:57,代码来源:BestConf.java

示例14: buildClassifier

import weka.core.Instance; //导入方法依赖的package包/类
@Override
public void buildClassifier(Instances data) throws Exception {
   	// Initialise training dataset
	Attribute classAttribute = data.classAttribute();
	
	classedData = new HashMap<>();
	classedDataIndices = new HashMap<>();
	for (int c = 0; c < data.numClasses(); c++) {
		classedData.put(data.classAttribute().value(c), new ArrayList<SymbolicSequence>());
		classedDataIndices.put(data.classAttribute().value(c), new ArrayList<Integer>());
	}

	train = new SymbolicSequence[data.numInstances()];
	classMap = new String[train.length];
	maxLength = 0;
	for (int i = 0; i < train.length; i++) {
		Instance sample = data.instance(i);
		MonoDoubleItemSet[] sequence = new MonoDoubleItemSet[sample.numAttributes() - 1];
		maxLength = Math.max(maxLength, sequence.length);
		int shift = (sample.classIndex() == 0) ? 1 : 0;
		for (int t = 0; t < sequence.length; t++) {
			sequence[t] = new MonoDoubleItemSet(sample.value(t + shift));
		}
		train[i] = new SymbolicSequence(sequence);
		String clas = sample.stringValue(classAttribute);
		classMap[i] = clas;
		classedData.get(clas).add(train[i]);
		classedDataIndices.get(clas).add(i);
	}
			
	warpingMatrix = new double[maxLength][maxLength];
	U = new double[maxLength];
	L = new double[maxLength];
	U1 = new double[maxLength];
	L1 = new double[maxLength];
	
	maxWindow = Math.round(1 * maxLength);
	searchResults = new String[maxWindow+1];
	nns = new int[maxWindow+1][train.length];
	dist = new double[train.length][train.length];

	cache = new SequenceStatsCache(train, maxWindow);
	
	lazyUCR = new LazyAssessNNEarlyAbandon[train.length][train.length];
	
	for (int i = 0; i < train.length; i++) {
		for (int j  = 0; j < train.length; j++) {
			lazyUCR[i][j] = new LazyAssessNNEarlyAbandon(cache);
		}
	}
	
	// Start searching for the best window
	searchBestWarpingWindow();

	// Saving best windows found
	System.out.println("Windows found=" + bestWarpingWindow + " Best Acc=" + (1-bestScore));
}
 
开发者ID:ChangWeiTan,项目名称:FastWWSearch,代码行数:58,代码来源:UCRSuitePrunedDTW.java


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