• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Instance类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.yahoo.labs.samoa.instances.Instance的典型用法代码示例。如果您正苦于以下问题:Java Instance类的具体用法?Java Instance怎么用?Java Instance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Instance类属于com.yahoo.labs.samoa.instances包,在下文中一共展示了Instance类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: run

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
public void run(int numInstances, boolean isTesting){
	Classifier learner = new HoeffdingTree();
	RandomRBFGenerator stream = new RandomRBFGenerator();
	stream.prepareForUse();

	learner.setModelContext(stream.getHeader());
	learner.prepareForUse();

	int numberSamplesCorrect = 0;
	int numberSamples = 0;
	long evaluateStartTime = TimingUtils.getNanoCPUTimeOfCurrentThread();
	while (stream.hasMoreInstances() && numberSamples < numInstances) {
		Instance trainInst = stream.nextInstance().getData();
		if (isTesting) {
			if (learner.correctlyClassifies(trainInst)){
				numberSamplesCorrect++;
			}
		}
		numberSamples++;
		learner.trainOnInstance(trainInst);
	}
	double accuracy = 100.0 * (double) numberSamplesCorrect/ (double) numberSamples;
	double time = TimingUtils.nanoTimeToSeconds(TimingUtils.getNanoCPUTimeOfCurrentThread()- evaluateStartTime);
	System.out.println(numberSamples + " instances processed with " + accuracy + "% accuracy in "+time+" seconds.");
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:26,代码来源:MOA.java


示例2: addResult

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
/**
 * @param inst       MOAInstance representing the cepEvent
 * @param classVotes Prediction votes for each class label
 */
public void addResult(Instance inst, double[] classVotes) {
    if (this.numClasses == -1) {
        this.reset(inst.numClasses());
    }
    double weight = inst.weight();
    int trueClass = (int) inst.classValue();

    if (weight > 0.0D) {
        if (this.weightObserved == 0.0D) {
            this.reset(inst.numClasses());
        }
        this.weightObserved += weight;
        int predictedClass = CoreUtils.argMaxIndex(classVotes);
        if (predictedClass == trueClass) {
            this.weightCorrect += weight;
        }
    }
}
 
开发者ID:wso2-extensions,项目名称:siddhi-gpl-execution-streamingml,代码行数:23,代码来源:ClassifierPrequentialModelEvaluation.java


示例3: evaluationTrainOnEvent

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
/**
 * @param modelEvaluation Prequential Model Evaluator.
 * @param cepEvent        event data
 * @param classValue      class label of the cepEvent
 * @return Prequential accuracy
 */
public double evaluationTrainOnEvent(ClassifierPrequentialModelEvaluation modelEvaluation,
                                     double[] cepEvent, String classValue) {
    int classIndex = cepEvent.length - 1;

    //create instance with only the feature attributes
    double[] test = Arrays.copyOfRange(cepEvent, 0, classIndex);
    Instance testInstance = createMOAInstance(test);

    double[] votes = hoeffdingAdaptiveTree.getVotesForInstance(testInstance);

    cepEvent[classIndex] = getClasses().indexOf(classValue);
    Instance trainInstance = createMOAInstance(cepEvent);

    hoeffdingAdaptiveTree.trainOnInstanceImpl(trainInstance);
    modelEvaluation.addResult(trainInstance, votes);
    return MathUtil.roundOff(modelEvaluation.getFractionCorrectlyClassified(), 3);
}
 
开发者ID:wso2-extensions,项目名称:siddhi-gpl-execution-streamingml,代码行数:24,代码来源:AdaptiveHoeffdingTreeModel.java


示例4: getVotesForInstance

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
@Override
public double[] getVotesForInstance(Instance inst) {
    if (this.testChunk == null) {
        this.testChunk = new ArrayList();
    }
    this.addInstance(this.testChunk, inst);
    if (this.index++ == testFrequencyOption.getValue()) {
        this.index = 0;
        ClassifierKS cs = this.getPreviousClassifier(
                this.classifier, this.testChunk);
        if (cs != null) {
            this.classifier = cs.getClassifier();
        }
    }
    return this.classifier.getVotesForInstance(inst);
}
 
开发者ID:Waikato,项目名称:moa,代码行数:17,代码来源:RCD.java


示例5: debuganomaly

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
protected void debuganomaly(Instance instance, double uni, double multi, double probability) {
	double atribSum = 0.0;
	double atribSquredSum = 0.0;

	for (int x = 0; x < instance.numAttributes() - 1; x++) {
		int instAttIndex = AMRulesRegressorOld.modelAttIndexToInstanceAttIndex(x, instance);
		atribSum = perceptron.perceptronattributeStatistics.getValue(x);
		atribSquredSum = perceptron.squaredperceptronattributeStatistics.getValue(x);
		double mean = atribSum / perceptron.getInstancesSeen();
		double sd = computeSD(
				atribSquredSum,
				atribSum,
				perceptron.getInstancesSeen()
				);
		debug("Attribute : " + x, 5);
		debug("Value : " + instance.value(instAttIndex), 5);
		debug("Mean : " + mean, 5);
		debug("SD : " + sd, 5);
		debug("Probability : " + probability, 5);
		debug("Univariate : " + uni, 5);
		debug("Multivariate : " + multi, 5);
		debug("Anomaly in rule :" + this.owner.ruleNumberID, 5);
	}
}
 
开发者ID:Waikato,项目名称:moa,代码行数:25,代码来源:RuleActiveRegressionNode.java


示例6: learnFromInstance

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
@Override
public void learnFromInstance(Instance inst, HoeffdingOptionTree hot) {
    int trueClass = (int) inst.classValue();
    boolean blCorrect = false;
    if (this.observedClassDistribution.maxIndex() == trueClass) {
        this.mcCorrectWeight += inst.weight();
        if (this.mcCorrectWeight > this.nbCorrectWeight) {
            blCorrect = true;
        }
    }
    if (Utils.maxIndex(NaiveBayes.doNaiveBayesPrediction(inst,
            this.observedClassDistribution, this.attributeObservers)) == trueClass) {
        this.nbCorrectWeight += inst.weight();
        if (this.mcCorrectWeight <= this.nbCorrectWeight) {
            blCorrect = true;
        }
    }
    if (blCorrect == true) {
        this.CorrectWeight += alpha * (1.0 - this.CorrectWeight); //EWMA
    } else {
        this.CorrectWeight -= alpha * this.CorrectWeight; //EWMA
    }
    super.learnFromInstance(inst, hot);
}
 
开发者ID:Waikato,项目名称:moa,代码行数:25,代码来源:AdaHoeffdingOptionTree.java


示例7: trainOnInstanceImpl

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
@Override
public void trainOnInstanceImpl(Instance instance) {
    timestamp++;
    
    //TODO check if instance contains label
    if(root == null){
        numberDimensions = instance.numAttributes();
        root = new Node(numberDimensions, 0);
    }
    else{
        if(numberDimensions!=instance.numAttributes())
            System.out.println("Wrong dimensionality, expected:"+numberDimensions+ "found:"+instance.numAttributes());
    }

    ClusKernel newPointAsKernel = new ClusKernel(instance.toDoubleArray(), numberDimensions);
    insert(newPointAsKernel, new SimpleBudget(1000),timestamp);
}
 
开发者ID:Waikato,项目名称:moa,代码行数:18,代码来源:ClusTree.java


示例8: Iadem3Subtree

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
public Iadem3Subtree(Node node,
        int treeLevel,
        Iadem3 mainTree,
        Instance instance) {
    // subtree configuration from main tree
    this.numericEstimatorOption.setValueViaCLIString(mainTree.numericEstimatorOption.getValueAsCLIString());
    this.gracePeriodOption.setValue(mainTree.gracePeriodOption.getValue());
    this.splitCriterionOption.setChosenIndex(mainTree.splitCriterionOption.getChosenIndex());
    this.splitConfidenceOption.setValue(mainTree.splitConfidenceOption.getValue());
    this.splitTestsOption.setChosenIndex(mainTree.splitTestsOption.getChosenIndex());
    this.leafPredictionOption.setChosenIndex(mainTree.leafPredictionOption.getChosenIndex());
    this.driftDetectionMethodOption.setValueViaCLIString(mainTree.driftDetectionMethodOption.getValueAsCLIString());
    this.attributeDiferentiation.setValue(mainTree.attributeDiferentiation.getValue());
    this.maxNestingLevelOption.setValue(mainTree.maxNestingLevelOption.getValue());
    this.maxSubtreesPerNodeOption.setValue(mainTree.maxSubtreesPerNodeOption.getValue());
    
    // subtree inicializations
    this.estimator = mainTree.getEstimatorCopy();
    this.errorEstimator = mainTree.getEstimatorCopy();
    this.nodo = node;
    this.mainTree = mainTree;
    this.mainTree.updateNumberOfLeaves(1);
    this.mainTree.updateNumberOfNodes(1);
    createRoot(instance);
}
 
开发者ID:Waikato,项目名称:moa,代码行数:26,代码来源:Iadem3Subtree.java


示例9: formatInstance

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
public Instance formatInstance(Instance original) {

        //Copy the original instance
        Instance converted = (Instance) original.copy();
        converted.setDataset(null);

        //Delete all class attributes
        for (int j = 0; j < m_L; j++) {
            converted.deleteAttributeAt(0);
        }

        //Add one of those class attributes at the begginning
        converted.insertAttributeAt(0);

        //Hopefully setting the dataset will configure that attribute properly
        converted.setDataset(m_InstancesTemplate);

        return converted;

    }
 
开发者ID:Waikato,项目名称:moa,代码行数:21,代码来源:Converter.java


示例10: doNaiveBayesPrediction

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
public static double[] doNaiveBayesPrediction(Instance inst,
        DoubleVector observedClassDistribution,
        AutoExpandVector<AttributeClassObserver> attributeObservers) {
    double[] votes = new double[observedClassDistribution.numValues()];
    double observedClassSum = observedClassDistribution.sumOfValues();
    for (int classIndex = 0; classIndex < votes.length; classIndex++) {
        votes[classIndex] = observedClassDistribution.getValue(classIndex)
                / observedClassSum;
        for (int attIndex = 0; attIndex < inst.numAttributes() - 1; attIndex++) {
            int instAttIndex = modelAttIndexToInstanceAttIndex(attIndex,
                    inst);
            AttributeClassObserver obs = attributeObservers.get(attIndex);
            if ((obs != null) && !inst.isMissing(instAttIndex)) {
                votes[classIndex] *= obs.probabilityOfAttributeValueGivenClass(inst.value(instAttIndex), classIndex);
            }
        }
    }
    // TODO: need logic to prevent underflow?
    return votes;
}
 
开发者ID:Waikato,项目名称:moa,代码行数:21,代码来源:NaiveBayes.java


示例11: branchForInstance

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
@Override
public int branchForInstance(Instance inst) {
	int instAttIndex = this.attIndex < inst.classIndex() ? this.attIndex
			: this.attIndex + 1;
	if (inst.isMissing(instAttIndex)) {
		return -1;
	}
	double v = inst.value(instAttIndex);
	int ret = 0;
	switch (this.operator) {
	case 0:
		ret = (v == this.attValue) ? 0 : 1;
		break;
	case 1:
		ret = (v <= this.attValue) ? 0 : 1;
		break;
	case 2:
		ret = (v > this.attValue) ? 0 : 1;
	}
	return ret;
}
 
开发者ID:Waikato,项目名称:moa,代码行数:22,代码来源:NumericAttributeBinaryRulePredicate.java


示例12: addResult

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
@Override
   public void addResult(Example<Instance> example, double[] prediction) {
Instance inst = example.getData();
       if (inst.weight() > 0.0) {
           if (prediction.length > 0) {
               double meanTarget = this.weightObserved != 0 ? 
                           this.sumTarget / this.weightObserved : 0.0;
               this.squareError += (inst.classValue() - prediction[0]) * (inst.classValue() - prediction[0]);
               this.averageError += Math.abs(inst.classValue() - prediction[0]);
               this.squareTargetError += (inst.classValue() - meanTarget) * (inst.classValue() - meanTarget);
               this.averageTargetError += Math.abs(inst.classValue() - meanTarget);
               this.sumTarget += inst.classValue();
               this.weightObserved += inst.weight();
           }
          //System.out.println(inst.classValue()+", "+prediction[0]);
       }
   }
 
开发者ID:Waikato,项目名称:moa,代码行数:18,代码来源:BasicRegressionPerformanceEvaluator.java


示例13: filterInstanceToLeaves

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
public void filterInstanceToLeaves(Instance inst, SplitNode myparent,
        int parentBranch, List<FoundNode> foundNodes,
        boolean updateSplitterCounts) {
    if (updateSplitterCounts) {
        this.observedClassDistribution.addToValue((int) inst.classValue(), inst.weight());
    }
    int childIndex = instanceChildIndex(inst);
    if (childIndex >= 0) {
        Node child = getChild(childIndex);
        if (child != null) {
            ((NewNode) child).filterInstanceToLeaves(inst, this, childIndex,
                    foundNodes, updateSplitterCounts);
        } else {
            foundNodes.add(new FoundNode(null, this, childIndex));
        }
    }
    if (this.alternateTree != null) {
        ((NewNode) this.alternateTree).filterInstanceToLeaves(inst, this, -999,
                foundNodes, updateSplitterCounts);
    }
}
 
开发者ID:Waikato,项目名称:moa,代码行数:22,代码来源:HoeffdingAdaptiveTree.java


示例14: LeafNode

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
public LeafNode(Iadem2 tree,
        Node parent,
        long instTreeCountSinceVirtual,
        long instNodeCountSinceVirtual,
        double[] initialClassCount,
        IademNumericAttributeObserver numericAttClassObserver,
        boolean onlyMultiwayTest,
        boolean onlyBinaryTest,
        Instance instance) {
    super(tree, parent, initialClassCount);
    this.instNodeCountSinceVirtual = instNodeCountSinceVirtual;
    this.instTreeCountSinceReal = 0;
    this.instNodeCountSinceReal = 0;
    this.split = true;
    createVirtualNodes(numericAttClassObserver,
            onlyMultiwayTest,
            onlyBinaryTest,
            instance);
}
 
开发者ID:Waikato,项目名称:moa,代码行数:20,代码来源:Iadem2.java


示例15: trainOnEvent

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
/**
 * @param cepEvent   event data
 * @param classLabel class  label of the cepEvent
 */
public void trainOnEvent(double[] cepEvent, String classLabel) {
    cepEvent[noOfFeatures - 1] = addClass(classLabel);
    Instance trainInstance = createMOAInstance(cepEvent);
    trainInstance.setClassValue(cepEvent[noOfFeatures - 1]);
    //training on the event instance
    hoeffdingAdaptiveTree.trainOnInstanceImpl(trainInstance);
}
 
开发者ID:wso2-extensions,项目名称:siddhi-gpl-execution-streamingml,代码行数:12,代码来源:AdaptiveHoeffdingTreeModel.java


示例16: getPrediction

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
/**
 * @param cepEvent Event data.
 * @return predicted class index, probability of the prediction.
 */
public Object[] getPrediction(double[] cepEvent) {
    Instance testInstance = createMOAInstance(cepEvent);
    double[] votes = hoeffdingAdaptiveTree.getVotesForInstance(testInstance);
    int classIndex = CoreUtils.argMaxIndex(votes);
    double confidenceLevel = getPredictionConfidence(votes);
    return new Object[]{classIndex, confidenceLevel};
}
 
开发者ID:wso2-extensions,项目名称:siddhi-gpl-execution-streamingml,代码行数:12,代码来源:AdaptiveHoeffdingTreeModel.java


示例17: createMOAInstance

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
/**
 * @param cepEvent Event Data
 * @return represents a single Event
 */
private Instance createMOAInstance(double[] cepEvent) {
    Instance instance = new DenseInstance(1.0D, cepEvent);
    //set schema header for the instance
    instance.setDataset(streamHeader);
    return instance;
}
 
开发者ID:wso2-extensions,项目名称:siddhi-gpl-execution-streamingml,代码行数:11,代码来源:AdaptiveHoeffdingTreeModel.java


示例18: trainOnEvent

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
/**
 * @param cepEvent event data
 */
@Override
public double trainOnEvent(double[] cepEvent) {
    Instance trainInstance = createMOAInstance(cepEvent);
    trainInstance.setClassValue(cepEvent[cepEvent.length - 1]);
    trainInstance.setDataset(streamHeader);

    double truth = cepEvent[cepEvent.length - 1];
    double prediction = MathUtil.roundOff(amRulesRegressor.getVotesForInstance(trainInstance)[0], 3);

    //training on the event instance
    amRulesRegressor.trainOnInstanceImpl(trainInstance);
    return calMeanSquaredError(truth, prediction);
}
 
开发者ID:wso2-extensions,项目名称:siddhi-gpl-execution-streamingml,代码行数:17,代码来源:AdaptiveModelRulesModel.java


示例19: getInclusionProbability

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
/**
 * Provides the probability of the argument instance belonging to the density grid in question.
 * 
 * @return 1.0 if the instance equals the density grid's coordinates; 0.0 otherwise.
 */
@Override
public double getInclusionProbability(Instance instance) {
	for (int i = 0 ; i < this.dimensions ; i++)
	{
		if ((int) instance.value(i) != this.coordinates[i])
			return 0.0;
	}
	
	return 1.0;
}
 
开发者ID:richard-moulton,项目名称:D-Stream,代码行数:16,代码来源:DensityGrid.java


示例20: getInclusionProbability

import com.yahoo.labs.samoa.instances.Instance; //导入依赖的package包/类
/**
 * Iterates through the DensityGrids in the cluster and calculates the inclusion probability for each.
 * 
 * @return 1.0 if instance matches any of the density grids; 0.0 otherwise.
 */
@Override
public double getInclusionProbability(Instance instance) {
	Iterator<Map.Entry<DensityGrid, Boolean>> gridIter = grids.entrySet().iterator();
	
	while(gridIter.hasNext())
	{
		Map.Entry<DensityGrid, Boolean> grid = gridIter.next();
		DensityGrid dg = grid.getKey();
		if(dg.getInclusionProbability(instance) == 1.0)
			return 1.0;
	}
	
	return 0.0;
}
 
开发者ID:richard-moulton,项目名称:D-Stream,代码行数:20,代码来源:GridCluster.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RefCountedMemory类代码示例发布时间:2022-05-23
下一篇:
Java CredentialsProvider类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap