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


Java BoundedPriorityQueue类代码示例

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


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

示例1: doWork

import com.rapidminer.tools.math.container.BoundedPriorityQueue; //导入依赖的package包/类
@Override
public void doWork() throws OperatorException {
	ExampleSet requestSet = requestSetInput.getData(ExampleSet.class);
	ExampleSet documentSet = referenceSetInput.getData(ExampleSet.class);
	Tools.checkAndCreateIds(requestSet);
	Tools.checkAndCreateIds(documentSet);

	DistanceMeasure measure = DistanceMeasures.createMeasure(this);
	measure.init(requestSet.getAttributes(), documentSet.getAttributes());

	Attribute oldRequestId = requestSet.getAttributes().getId();
	Attribute oldDocumentId = documentSet.getAttributes().getId();

	// creating new exampleSet
	Attribute requestId = AttributeFactory.createAttribute("request", oldRequestId.getValueType());
	Attribute documentId = AttributeFactory.createAttribute("document", oldDocumentId.getValueType());
	Attribute distance = AttributeFactory.createAttribute("distance", Ontology.REAL);

	List<Attribute> newAttributes = new LinkedList<Attribute>();
	Collections.addAll(newAttributes, requestId, documentId, distance);
	MemoryExampleTable table = new MemoryExampleTable(newAttributes);

	double searchModeFactor = getParameterAsInt(PARAMETER_SEARCH_MODE) == MODE_FARTHEST ? -1d : 1d;
	boolean computeSimilarity = getParameterAsBoolean(PARAMETER_COMPUTE_SIMILARITIES);

	for (Example request : requestSet) {
		Collection<Tupel<Double, Double>> distances;
		if (getParameterAsBoolean(PARAMETER_USE_K)) {
			distances = new BoundedPriorityQueue<Tupel<Double, Double>>(getParameterAsInt(PARAMETER_K));
		} else {
			distances = new ArrayList<Tupel<Double, Double>>();
		}

		// calculating distance
		for (Example document : documentSet) {
			if (computeSimilarity) {
				distances.add(new Tupel<Double, Double>(measure.calculateSimilarity(request, document)
						* searchModeFactor, document.getValue(oldDocumentId)));
			} else {
				distances.add(new Tupel<Double, Double>(measure.calculateDistance(request, document) * searchModeFactor,
						document.getValue(oldDocumentId)));
			}
			checkForStop();
		}

		// writing into table
		DataRowFactory factory = new DataRowFactory(DataRowFactory.TYPE_DOUBLE_ARRAY, '.');
		double requestIdValue = request.getValue(oldRequestId);
		if (oldRequestId.isNominal()) {
			requestIdValue = requestId.getMapping().mapString(request.getValueAsString(oldRequestId));
		}

		for (Tupel<Double, Double> tupel : distances) {
			double documentIdValue = tupel.getSecond();
			if (oldDocumentId.isNominal()) {
				documentIdValue = documentId.getMapping().mapString(
						oldDocumentId.getMapping().mapIndex((int) documentIdValue));
			}
			DataRow row = factory.create(3);
			row.set(distance, tupel.getFirst() * searchModeFactor);
			row.set(requestId, requestIdValue);
			row.set(documentId, documentIdValue);
			table.addDataRow(row);
			checkForStop();
		}
	}

	// sorting set
	ExampleSet result = new SortedExampleSet(table.createExampleSet(), distance,
			searchModeFactor == -1d ? SortedExampleSet.DECREASING : SortedExampleSet.INCREASING);

	requestSetOutput.deliver(requestSet);
	referenceSetOutput.deliver(documentSet);
	resultSetOutput.deliver(result);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:76,代码来源:CrossDistancesOperator.java

示例2: doWork

import com.rapidminer.tools.math.container.BoundedPriorityQueue; //导入依赖的package包/类
@Override
public void doWork() throws OperatorException {
	ExampleSet requestSet = requestSetInput.getData(ExampleSet.class);
	ExampleSet documentSet = referenceSetInput.getData(ExampleSet.class);
	Tools.checkAndCreateIds(requestSet);
	Tools.checkAndCreateIds(documentSet);

	DistanceMeasure measure = DistanceMeasures.createMeasure(this);
	measure.init(requestSet.getAttributes(), documentSet.getAttributes());

	Attribute oldRequestId = requestSet.getAttributes().getId();
	Attribute oldDocumentId = documentSet.getAttributes().getId();

	// creating new exampleSet
	Attribute requestId = AttributeFactory.createAttribute("request", oldRequestId.getValueType());
	Attribute documentId = AttributeFactory.createAttribute("document", oldDocumentId.getValueType());
	Attribute distance = AttributeFactory.createAttribute("distance", Ontology.REAL);

	List<Attribute> newAttributes = new LinkedList<Attribute>();
	Collections.addAll(newAttributes, requestId, documentId, distance);
	ExampleSetBuilder builder = ExampleSets.from(newAttributes);

	double searchModeFactor = getParameterAsInt(PARAMETER_SEARCH_MODE) == MODE_FARTHEST ? -1d : 1d;
	boolean computeSimilarity = getParameterAsBoolean(PARAMETER_COMPUTE_SIMILARITIES);
	boolean useK = getParameterAsBoolean(PARAMETER_USE_K);
	int k = getParameterAsInt(PARAMETER_K);

	for (Example request : requestSet) {
		Collection<Tupel<Double, Double>> distances;
		if (useK) {
			distances = new BoundedPriorityQueue<Tupel<Double, Double>>(k);
		} else {
			distances = new ArrayList<Tupel<Double, Double>>();
		}

		// calculating distance
		for (Example document : documentSet) {
			if (computeSimilarity) {
				distances
						.add(new Tupel<Double, Double>(measure.calculateSimilarity(request, document) * searchModeFactor,
								document.getValue(oldDocumentId)));
			} else {
				distances.add(new Tupel<Double, Double>(measure.calculateDistance(request, document) * searchModeFactor,
						document.getValue(oldDocumentId)));
			}
			checkForStop();
		}

		// writing into table
		DataRowFactory factory = new DataRowFactory(DataRowFactory.TYPE_DOUBLE_ARRAY, '.');
		double requestIdValue = request.getValue(oldRequestId);
		if (oldRequestId.isNominal()) {
			requestIdValue = requestId.getMapping().mapString(request.getValueAsString(oldRequestId));
		}

		for (Tupel<Double, Double> tupel : distances) {
			double documentIdValue = tupel.getSecond();
			if (oldDocumentId.isNominal()) {
				documentIdValue = documentId.getMapping()
						.mapString(oldDocumentId.getMapping().mapIndex((int) documentIdValue));
			}
			DataRow row = factory.create(3);
			row.set(distance, tupel.getFirst() * searchModeFactor);
			row.set(requestId, requestIdValue);
			row.set(documentId, documentIdValue);
			builder.addDataRow(row);
			checkForStop();
		}
	}

	// sorting set
	ExampleSet result = new SortedExampleSet(builder.build(), distance,
			searchModeFactor == -1d ? SortedExampleSet.DECREASING : SortedExampleSet.INCREASING);

	requestSetOutput.deliver(requestSet);
	referenceSetOutput.deliver(documentSet);
	resultSetOutput.deliver(result);
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:79,代码来源:CrossDistancesOperator.java

示例3: doWork

import com.rapidminer.tools.math.container.BoundedPriorityQueue; //导入依赖的package包/类
@Override
public void doWork() throws OperatorException {
    ExampleSet requestSet = requestSetInput.getData(ExampleSet.class);
    ExampleSet documentSet = referenceSetInput.getData(ExampleSet.class);
    Tools.checkAndCreateIds(requestSet);
    Tools.checkAndCreateIds(documentSet);

    DistanceMeasure measure = DistanceMeasures.createMeasure(this);
    measure.init(requestSet.getAttributes(), documentSet.getAttributes());

    Attribute oldRequestId = requestSet.getAttributes().getId();
    Attribute oldDocumentId = documentSet.getAttributes().getId();

    // creating new exampleSet
    Attribute requestId = AttributeFactory.createAttribute("request", oldRequestId.getValueType());
    Attribute documentId = AttributeFactory.createAttribute("document", oldDocumentId.getValueType());
    Attribute distance = AttributeFactory.createAttribute("distance", Ontology.REAL);

    List<Attribute> newAttributes = new LinkedList<Attribute>();
    Collections.addAll(newAttributes, requestId, documentId, distance);
    MemoryExampleTable table = new MemoryExampleTable(newAttributes);

    double searchModeFactor = getParameterAsInt(PARAMETER_SEARCH_MODE) == MODE_FARTHEST ? -1d : 1d;
    boolean computeSimilarity = getParameterAsBoolean(PARAMETER_COMPUTE_SIMILARITIES);

    for (Example request: requestSet) {
        Collection<Tupel<Double, Double>> distances;
        if (getParameterAsBoolean(PARAMETER_USE_K))
            distances = new BoundedPriorityQueue<Tupel<Double,Double>>(getParameterAsInt(PARAMETER_K));
        else
            distances = new ArrayList<Tupel<Double,Double>>();

        // calculating distance
        for (Example document: documentSet) {
            if (computeSimilarity)
                distances.add(new Tupel<Double, Double>(measure.calculateSimilarity(request, document) * searchModeFactor, document.getValue(oldDocumentId)));
            else
                distances.add(new Tupel<Double, Double>(measure.calculateDistance(request, document) * searchModeFactor, document.getValue(oldDocumentId)));
            checkForStop();
        }

        // writing into table
        DataRowFactory factory = new DataRowFactory(DataRowFactory.TYPE_DOUBLE_ARRAY, '.');
        double requestIdValue = request.getValue(oldRequestId);
        if (oldRequestId.isNominal())
            requestIdValue = requestId.getMapping().mapString(request.getValueAsString(oldRequestId));

        for (Tupel<Double, Double> tupel: distances) {
            double documentIdValue = tupel.getSecond();
            if (oldDocumentId.isNominal())
                documentIdValue = documentId.getMapping().mapString(oldDocumentId.getMapping().mapIndex((int) documentIdValue));
            DataRow row = factory.create(3);
            row.set(distance, tupel.getFirst() *  searchModeFactor);
            row.set(requestId, requestIdValue);
            row.set(documentId, documentIdValue);
            table.addDataRow(row);
            checkForStop();
        }
    }

    // sorting set
    ExampleSet result = new SortedExampleSet(table.createExampleSet(), distance, searchModeFactor == -1d ? SortedExampleSet.DECREASING : SortedExampleSet.INCREASING);

    requestSetOutput.deliver(requestSet);
    referenceSetOutput.deliver(documentSet);
    resultSetOutput.deliver(result);
}
 
开发者ID:rapidminer,项目名称:rapidminer-5,代码行数:68,代码来源:CrossDistancesOperator.java


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