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


Java MathFunctions.ld方法代码示例

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


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

示例1: startCounting

import com.rapidminer.tools.math.MathFunctions; //导入方法依赖的package包/类
/** Calculates the margin. */
@Override
public void startCounting(ExampleSet exampleSet, boolean useExampleWeights) throws OperatorException {
	super.startCounting(exampleSet, useExampleWeights);
	// compute margin
	Iterator<Example> reader = exampleSet.iterator();
	this.value = 0.0d;
	Attribute labelAttr = exampleSet.getAttributes().getLabel();
	Attribute weightAttribute = null;
	if (useExampleWeights) {
		weightAttribute = exampleSet.getAttributes().getWeight();
	}
	while (reader.hasNext()) {
		Example example = reader.next();
		String trueLabel = example.getNominalValue(labelAttr);
		double confidence = example.getConfidence(trueLabel);
		double weight = 1.0d;
		if (weightAttribute != null) {
			weight = example.getValue(weightAttribute);
		}
		this.value -= weight * MathFunctions.ld(confidence);

		this.counter += weight;
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:26,代码来源:CrossEntropy.java

示例2: startCounting

import com.rapidminer.tools.math.MathFunctions; //导入方法依赖的package包/类
/** Calculates the margin. */
@Override
public void startCounting(ExampleSet exampleSet, boolean useExampleWeights) throws OperatorException {
	super.startCounting(exampleSet, useExampleWeights);
	// compute margin
	Iterator<Example> reader = exampleSet.iterator();
	this.value = 0.0d;
	Attribute labelAttr = exampleSet.getAttributes().getLabel();
       Attribute weightAttribute = null;
       if (useExampleWeights)
       	weightAttribute = exampleSet.getAttributes().getWeight();
	while (reader.hasNext()) {
		Example example = reader.next();
		String trueLabel = example.getNominalValue(labelAttr);
		double confidence = example.getConfidence(trueLabel);
           double weight = 1.0d;
           if (weightAttribute != null)
           	weight = example.getValue(weightAttribute);
		this.value -= weight * MathFunctions.ld(confidence);
		
           this.counter += weight;
	}
}
 
开发者ID:rapidminer,项目名称:rapidminer-5,代码行数:24,代码来源:CrossEntropy.java

示例3: getMatrixValue

import com.rapidminer.tools.math.MathFunctions; //导入方法依赖的package包/类
/** Calculates the mutual information for both attributes. */
@Override
public double getMatrixValue(ExampleSet exampleSet, Attribute firstAttribute, Attribute secondAttribute) {
	// init
	double[] firstProbabilites = new double[firstAttribute.getMapping().size()];
	double[] secondProbabilites = new double[secondAttribute.getMapping().size()];
	double[][] jointProbabilities = new double[firstAttribute.getMapping().size()][secondAttribute.getMapping().size()];
	double firstCounter = 0.0d;
	double secondCounter = 0.0d;
	double firstSecondCounter = 0.0d;

	// count values
	for (Example example : exampleSet) {
		double firstValue = example.getValue(firstAttribute);
		if (!Double.isNaN(firstValue)) {
			firstProbabilites[(int) firstValue]++;
			firstCounter++;
		}
		double secondValue = example.getValue(secondAttribute);
		if (!Double.isNaN(secondValue)) {
			secondProbabilites[(int) secondValue]++;
			secondCounter++;
		}
		if (!Double.isNaN(firstValue) && !Double.isNaN(secondValue)) {
			jointProbabilities[(int) firstValue][(int) secondValue]++;
			firstSecondCounter++;
		}
	}

	// transform to probabilities
	for (int i = 0; i < firstProbabilites.length; i++) {
		firstProbabilites[i] /= firstCounter;
	}
	for (int i = 0; i < secondProbabilites.length; i++) {
		secondProbabilites[i] /= secondCounter;
	}
	for (int i = 0; i < jointProbabilities.length; i++) {
		for (int j = 0; j < jointProbabilities[i].length; j++) {
			jointProbabilities[i][j] /= firstSecondCounter;
		}
	}

	double firstEntropy = 0.0d;
	for (int i = 0; i < firstProbabilites.length; i++) {
		if (firstProbabilites[i] > 0.0d) {
			firstEntropy += firstProbabilites[i] * MathFunctions.ld(firstProbabilites[i]);
		}
	}
	firstEntropy *= -1;

	double secondEntropy = 0.0d;
	for (int i = 0; i < secondProbabilites.length; i++) {
		if (secondProbabilites[i] > 0.0d) {
			secondEntropy += secondProbabilites[i] * MathFunctions.ld(secondProbabilites[i]);
		}
	}
	secondEntropy *= -1;

	double jointEntropy = 0.0d;
	for (int i = 0; i < jointProbabilities.length; i++) {
		for (int j = 0; j < jointProbabilities[i].length; j++) {
			if (jointProbabilities[i][j] > 0.0d) {
				jointEntropy += jointProbabilities[i][j] * MathFunctions.ld(jointProbabilities[i][j]);
			}
		}
	}
	jointEntropy *= -1;

	return firstEntropy + secondEntropy - jointEntropy;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:71,代码来源:MutualInformationMatrixOperator.java

示例4: getMatrixValue

import com.rapidminer.tools.math.MathFunctions; //导入方法依赖的package包/类
/** Calculates the mutual information for both attributes. */
@Override
public double getMatrixValue(ExampleSet exampleSet, Attribute firstAttribute, Attribute secondAttribute) {
	// init
	double[] firstProbabilites    = new double[firstAttribute.getMapping().size()];
	double[] secondProbabilites   = new double[secondAttribute.getMapping().size()];
	double[][] jointProbabilities = new double[firstAttribute.getMapping().size()][secondAttribute.getMapping().size()];
	double firstCounter = 0.0d;
	double secondCounter = 0.0d;
	double firstSecondCounter = 0.0d;
	
	// count values
	for (Example example : exampleSet) {
		double firstValue = example.getValue(firstAttribute);
		if (!Double.isNaN(firstValue)) {
			firstProbabilites[(int)firstValue]++;
			firstCounter++;
		}
		double secondValue = example.getValue(secondAttribute);
		if (!Double.isNaN(secondValue)) {
			secondProbabilites[(int)secondValue]++;
			secondCounter++;
		}
		if (!Double.isNaN(firstValue) && !Double.isNaN(secondValue)) {
			jointProbabilities[(int)firstValue][(int)secondValue]++;
			firstSecondCounter++;
		}
	}
	
	// transform to probabilities
	for (int i = 0; i < firstProbabilites.length; i++) {
		firstProbabilites[i] /= firstCounter;
	}
	for (int i = 0; i < secondProbabilites.length; i++) {
		secondProbabilites[i] /= secondCounter;
	}
	for (int i = 0; i < jointProbabilities.length; i++) {
		for (int j = 0; j < jointProbabilities[i].length; j++) {
			jointProbabilities[i][j] /= firstSecondCounter;
		}
	}
	
	double firstEntropy = 0.0d;
	for (int i = 0; i < firstProbabilites.length; i++) {
		if (firstProbabilites[i] > 0.0d)
			firstEntropy += firstProbabilites[i] * MathFunctions.ld(firstProbabilites[i]);
	}
	firstEntropy *= -1;

	double secondEntropy = 0.0d;
	for (int i = 0; i < secondProbabilites.length; i++) {
		if (secondProbabilites[i] > 0.0d)
			secondEntropy += secondProbabilites[i] * MathFunctions.ld(secondProbabilites[i]);
	}
	secondEntropy *= -1;
	
	double jointEntropy = 0.0d;
	for (int i = 0; i < jointProbabilities.length; i++) {
		for (int j = 0; j < jointProbabilities[i].length; j++) {
			if (jointProbabilities[i][j] > 0.0d)
				jointEntropy += jointProbabilities[i][j] * MathFunctions.ld(jointProbabilities[i][j]);
		}
	}
	jointEntropy *= -1;
	
	return firstEntropy + secondEntropy - jointEntropy;
}
 
开发者ID:rapidminer,项目名称:rapidminer-5,代码行数:68,代码来源:MutualInformationMatrixOperator.java


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