當前位置: 首頁>>代碼示例>>Java>>正文


Java DistanceMeasure類代碼示例

本文整理匯總了Java中com.rapidminer.tools.math.similarity.DistanceMeasure的典型用法代碼示例。如果您正苦於以下問題:Java DistanceMeasure類的具體用法?Java DistanceMeasure怎麽用?Java DistanceMeasure使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DistanceMeasure類屬於com.rapidminer.tools.math.similarity包,在下文中一共展示了DistanceMeasure類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: computeClusterDistances

import com.rapidminer.tools.math.similarity.DistanceMeasure; //導入依賴的package包/類
private void computeClusterDistances(DistanceMatrix centroidDistances, double[] s, CentroidClusterModel model,
		DistanceMeasure measure) {
	for (int i = 0; i < model.getNumberOfClusters(); i++) {
		s[i] = Double.POSITIVE_INFINITY;
	}
	for (int i = 0; i < model.getNumberOfClusters(); i++) {
		for (int j = i + 1; j < model.getNumberOfClusters(); j++) {
			final double d = measure.calculateDistance(model.getCentroidCoordinates(i), model.getCentroidCoordinates(j));
			if (d < s[i]) {
				s[i] = d;
			}
			if (d < s[j]) {
				s[j] = d;
			}
			centroidDistances.set(i, j, d);
		}
	}
	for (int i = 0; i < model.getNumberOfClusters(); i++) {
		s[i] = 0.5 * s[i];
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:22,代碼來源:FastKMeans.java

示例2: SimilarityTable

import com.rapidminer.tools.math.similarity.DistanceMeasure; //導入依賴的package包/類
public SimilarityTable(DistanceMeasure measure, ExampleSet exampleSet) {
	GridBagLayout layout = new GridBagLayout();
	setLayout(layout);
	GridBagConstraints c = new GridBagConstraints();
	c.fill = GridBagConstraints.BOTH;
	c.weightx = 1;
	c.weighty = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;

	similarityTable = new ExtendedJTable();
	SimilarityTableModel model = new SimilarityTableModel(measure, exampleSet);
	similarityTable.setModel(model);

	JScrollPane tablePane = new ExtendedJScrollPane(similarityTable);
	tablePane.setBorder(null);
	layout.setConstraints(tablePane, c);
	add(tablePane);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:19,代碼來源:SimilarityTable.java

示例3: generateInternalClusterModel

import com.rapidminer.tools.math.similarity.DistanceMeasure; //導入依賴的package包/類
@Override
protected ClusterModel generateInternalClusterModel(ExampleSet eSet) throws OperatorException {

	DistanceMeasure measure = getInitializedMeasure(eSet);
	int k_max = getParameterAsInt(PARAMETER_K_Max);
	int k_min = getParameterAsInt(PARAMETER_K_Min);
	boolean kpp = getParameterAsBoolean(KMeanspp.PARAMETER_USE_KPP);
	String fast_k = getParameterAsString(ClusteringAlgorithms.PARAMETER_CLUSTERING_ALGORITHM);
	int maxOptimizationSteps = getParameterAsInt(PARAMETER_MAX_OPTIMIZATION_STEPS);
	int maxRuns = getParameterAsInt(PARAMETER_MAX_RUNS);

	XMeansCore xm = new XMeansCore(eSet, k_min, k_max, kpp, maxOptimizationSteps, maxRuns, Description, measure, fast_k);
	xm.setExecutingOperator(this);

	return xm.doXMean();
}
 
開發者ID:rapidminer,項目名稱:rapidminer-studio,代碼行數:17,代碼來源:XMeans.java

示例4: XMeansCore

import com.rapidminer.tools.math.similarity.DistanceMeasure; //導入依賴的package包/類
/**
 * Initialization of X-Mean
 * 
 * @param eSet ExamleSet to cluster
 * @param k_min minimal number of cluster
 * @param k_max maximal number of cluster
 * @param kpp using K++-Algorithem to determin the first centroids
 * @param maxOptimizationSteps maximal optimationsteps of k-Means
 * @param maxRuns The maximal number of runs of k-Means with random initialization that are performed.
 * @param description
 * @param measure MeasureType to use
 * @param cluster_alg Clustering Algorithm to use
 */
public XMeansCore(ExampleSet eSet, int k_min, int k_max, boolean kpp,
		int maxOptimizationSteps, int maxRuns,
		OperatorDescription description, DistanceMeasure measure,
		String cluster_alg) {
	super(description);

	this.exampleSet = eSet;
	this.measure = measure;
	this.k_max = k_max;
	this.k_min = k_min;
	this.kpp = kpp;
	this.maxOptimizationSteps = maxOptimizationSteps;
	this.maxRuns = maxRuns;
	this.description = description;
	this.centroidAssignments = new int[exampleSet.size()];
	this.ClusteringAlgorithm = cluster_alg;
}
 
開發者ID:rapidminer,項目名稱:rapidminer-5,代碼行數:31,代碼來源:XMeansCore.java

示例5: computeClusterDistances

import com.rapidminer.tools.math.similarity.DistanceMeasure; //導入依賴的package包/類
private void computeClusterDistances(DistanceMatrix centroidDistances, double[] s, 
		CentroidClusterModel model,  DistanceMeasure measure) {
	for (int i = 0; i < model.getNumberOfClusters(); i++){
		s[i] = Double.POSITIVE_INFINITY;
	}
	for (int i = 0; i < model.getNumberOfClusters(); i++){
		for (int j = i+1; j < model.getNumberOfClusters(); j++){
			final double d = measure.calculateDistance(model.getCentroidCoordinates(i), model.getCentroidCoordinates(j));
			if (d < s[i]){
				s[i] = d;
			}
			if (d < s[j]){
				s[j] = d;
			}
			centroidDistances.set(i, j, d);
		}
	}
	for (int i = 0; i < model.getNumberOfClusters(); i++){
		s[i] = 0.5 * s[i];
	}
}
 
開發者ID:rapidminer,項目名稱:rapidminer-5,代碼行數:22,代碼來源:FastKMeans.java

示例6: SimilarityTable

import com.rapidminer.tools.math.similarity.DistanceMeasure; //導入依賴的package包/類
public SimilarityTable(DistanceMeasure measure, ExampleSet exampleSet) {
	GridBagLayout layout = new GridBagLayout();
	setLayout(layout);
	GridBagConstraints c = new GridBagConstraints();
	c.fill = GridBagConstraints.BOTH;
	c.weightx = 1;
	c.weighty = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	
	similarityTable = new ExtendedJTable();
	SimilarityTableModel model = new SimilarityTableModel(measure, exampleSet);
	similarityTable.setModel(model);
	
	JScrollPane tablePane = new ExtendedJScrollPane(similarityTable);
	layout.setConstraints(tablePane, c);
	add(tablePane);
}
 
開發者ID:rapidminer,項目名稱:rapidminer-5,代碼行數:18,代碼來源:SimilarityTable.java

示例7: SimilarityExampleSet

import com.rapidminer.tools.math.similarity.DistanceMeasure; //導入依賴的package包/類
public SimilarityExampleSet(ExampleSet parent, DistanceMeasure measure) {
	this.parent = parent;

	this.parentIdAttribute = parent.getAttributes().getId();
	this.attributes = new SimpleAttributes();

	Attribute firstIdAttribute = null;
	Attribute secondIdAttribute = null;
	firstIdAttribute = AttributeFactory.createAttribute("FIRST_ID", this.parentIdAttribute.getValueType());
	secondIdAttribute = AttributeFactory.createAttribute("SECOND_ID", this.parentIdAttribute.getValueType());

	this.attributes.addRegular(firstIdAttribute);
	this.attributes.addRegular(secondIdAttribute);
	firstIdAttribute.setTableIndex(0);
	secondIdAttribute.setTableIndex(1);

	// copying mapping of original id attribute
	if (parentIdAttribute.isNominal()) {
		NominalMapping mapping = parentIdAttribute.getMapping();
		firstIdAttribute.setMapping((NominalMapping) mapping.clone());
		secondIdAttribute.setMapping((NominalMapping) mapping.clone());
	}

	String name = "SIMILARITY";
	if (measure.isDistance()) {
		name = "DISTANCE";
	}

	Attribute similarityAttribute = AttributeFactory.createAttribute(name, Ontology.REAL);
	this.attributes.addRegular(similarityAttribute);
	similarityAttribute.setTableIndex(2);

	this.measure = measure;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:35,代碼來源:SimilarityExampleSet.java

示例8: getAverageWithinDistance

import com.rapidminer.tools.math.similarity.DistanceMeasure; //導入依賴的package包/類
private double[] getAverageWithinDistance(CentroidClusterModel model, ExampleSet exampleSet) throws OperatorException {
	DistanceMeasure measure = new SquaredEuclideanDistance();
	measure.init(exampleSet);
	int numberOfClusters = model.getNumberOfClusters();

	// counting distances within
	double[] result = new double[numberOfClusters + 1];
	int[] clusterSizes = new int[numberOfClusters];

	int[] clusterIndices = model.getClusterAssignments(exampleSet);

	int i = 0;
	for (Example example : exampleSet) {
		clusterSizes[clusterIndices[i]]++;
		result[clusterIndices[i]] += measure.calculateDistance(example, model.getCentroidCoordinates(clusterIndices[i]));
		i++;
	}

	// averaging by cluster sizes and sum over all
	int totalSize = 0;
	for (i = 0; i < numberOfClusters; i++) {
		result[numberOfClusters] += result[i];
		result[i] /= clusterSizes[i];
		totalSize += clusterSizes[i];
	}
	result[numberOfClusters] /= totalSize;

	return result;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:30,代碼來源:CentroidBasedEvaluator.java

示例9: withinClusterAvgSim

import com.rapidminer.tools.math.similarity.DistanceMeasure; //導入依賴的package包/類
private double[] withinClusterAvgSim(ClusterModel clusterModel, ExampleSet exampleSet, DistanceMeasure measure) {
	Attribute id = exampleSet.getAttributes().getId();

	double[] result = new double[clusterModel.getNumberOfClusters() + 1];

	for (Example example : exampleSet) {
		int clusterIndex = id.isNominal() ? clusterModel.getClusterIndexOfId(example.getValueAsString(id))
				: clusterModel.getClusterIndexOfId(example.getValue(id));
		for (Example compExample : exampleSet) {
			int compClusterIndex = id.isNominal() ? clusterModel.getClusterIndexOfId(compExample.getValueAsString(id))
					: clusterModel.getClusterIndexOfId(compExample.getValue(id));
			if (clusterIndex == compClusterIndex) {
				double v = measure.calculateSimilarity(example, compExample);
				result[clusterIndex] += v;
			}
		}
	}

	double sum = 0.0;
	int totalCount = 0;
	for (int i = 0; i < clusterModel.getNumberOfClusters(); i++) {
		sum += result[i];
		int clusterSize = clusterModel.getCluster(i).getNumberOfExamples();
		result[i] = result[i] /= clusterSize;
		totalCount += clusterSize;
		;
	}
	result[clusterModel.getNumberOfClusters()] = sum / totalCount;
	return result;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:31,代碼來源:ClusterDensityEvaluator.java

示例10: doWork

import com.rapidminer.tools.math.similarity.DistanceMeasure; //導入依賴的package包/類
@Override
public void doWork() throws OperatorException {
	ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
	Tools.checkAndCreateIds(exampleSet);

	DistanceMeasure measure = measureHelper.getInitializedMeasure(exampleSet);
	exampleSetOutput.deliver(new SimilarityExampleSet(exampleSet, measure));
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:9,代碼來源:ExampleSet2SimilarityExampleSet.java

示例11: doWork

import com.rapidminer.tools.math.similarity.DistanceMeasure; //導入依賴的package包/類
@Override
public void doWork() throws OperatorException {
	ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
	// needed for some measures
	Tools.checkAndCreateIds(exampleSet);

	DistanceMeasure measure = measureHelper.getInitializedMeasure(exampleSet);
	SimilarityMeasureObject measureObject = new SimilarityMeasureObject(measure, exampleSet);

	ObjectVisualizerService.addObjectVisualizer(measureObject, new ExampleVisualizer(exampleSet));

	similarityOutput.deliver(measureObject);
	exampleSetOutput.deliver(exampleSet);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:15,代碼來源:ExampleSet2Similarity.java

示例12: CentroidClusterModel

import com.rapidminer.tools.math.similarity.DistanceMeasure; //導入依賴的package包/類
public CentroidClusterModel(IExampleSet exampleSet, int k, Collection<String> dimensionNames,
							DistanceMeasure distanceMeasure, boolean addClusterAsLabel, boolean removeUnknown) {
	super(exampleSet, k, addClusterAsLabel, removeUnknown);
	this.distanceMeasure = distanceMeasure;
	this.dimensionNames = dimensionNames;
	centroids = new ArrayList<Centroid>(k);
	for (int i = 0; i < k; i++) {
		centroids.add(new Centroid(dimensionNames.size()));
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:11,代碼來源:CentroidClusterModel.java

示例13: generateClusterModel

import com.rapidminer.tools.math.similarity.DistanceMeasure; //導入依賴的package包/類
@Override
public ClusterModel generateClusterModel(ExampleSet eSet) throws OperatorException {

	DistanceMeasure measure = measureHelper.getInitializedMeasure(eSet);
	int k_max = getParameterAsInt(PARAMETER_K_Max);
	int k_min = getParameterAsInt(PARAMETER_K_Min);
	boolean kpp = getParameterAsBoolean(KMeanspp.PARAMETER_USE_KPP);
	String fast_k = getParameterAsString(ClusteringAlgorithms.PARAMETER_CLUSTERING_ALGORITHM);
	int maxOptimizationSteps = getParameterAsInt(PARAMETER_MAX_OPTIMIZATION_STEPS);
	int maxRuns = getParameterAsInt(PARAMETER_MAX_RUNS);

	XMeansCore xm = new XMeansCore(eSet, k_min, k_max, kpp, maxOptimizationSteps, maxRuns, Description, measure, fast_k);

	return xm.doXMean();
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:16,代碼來源:XMeans.java

示例14: getNeighbourhood

import com.rapidminer.tools.math.similarity.DistanceMeasure; //導入依賴的package包/類
private LinkedList<Integer> getNeighbourhood(Example centerExample, ExampleSet exampleSet, DistanceMeasure measure,
		double epsilon) {
	LinkedList<Integer> neighbourhood = new LinkedList<Integer>();
	int i = 0;
	for (Example example : exampleSet) {
		double distance = measure.calculateDistance(centerExample, example);
		if (distance < epsilon) {
			neighbourhood.add(i);
		}
		i++;
	}
	return neighbourhood;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:14,代碼來源:DBScan.java

示例15: createHistogramPlotter

import com.rapidminer.tools.math.similarity.DistanceMeasure; //導入依賴的package包/類
private Plotter createHistogramPlotter(SimilarityMeasureObject sim, ExampleSet exampleSet) {
	DistanceMeasure measure = sim.getDistanceMeasure();
	DataTable dataTable = new SimpleDataTable("Histogram", new String[] { "Histogram" });
	double sampleRatio = Math.min(1.0d, 500.0d / exampleSet.size());

	Random random = new Random();
	int i = 0;
	for (Example example : exampleSet) {
		int j = 0;
		for (Example comExample : exampleSet) {
			if (j != i && random.nextDouble() < sampleRatio) {
				double simValue;
				if (measure.isDistance()) {
					simValue = measure.calculateDistance(example, comExample);
				} else {
					simValue = measure.calculateSimilarity(example, comExample);
				}
				dataTable.add(new SimpleDataTableRow(new double[] { simValue }));
			}
			j++;
		}
		i++;
	}
	PlotterConfigurationModel settings = new PlotterConfigurationModel(PlotterConfigurationModel.HISTOGRAM_PLOT,
			dataTable);

	settings.enablePlotColumn(0);
	settings.setParameterAsInt(HistogramChart.PARAMETER_NUMBER_OF_BINS, 100);

	return settings.getPlotter();
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:32,代碼來源:SimilarityHistogramRenderer.java


注:本文中的com.rapidminer.tools.math.similarity.DistanceMeasure類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。