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


Java SortedExampleSet类代码示例

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


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

示例1: apply

import com.rapidminer.example.set.SortedExampleSet; //导入依赖的package包/类
@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {

	ArrayList<Integer> indicesCollection = new ArrayList<Integer>(exampleSet.size());
	for (int i = 0; i < exampleSet.size(); i++) {
		indicesCollection.add(i);
	}

	Collections.shuffle(indicesCollection, RandomGenerator.getRandomGenerator(this));

	int[] indices = new int[exampleSet.size()];
	for (int i = 0; i < exampleSet.size(); i++) {
		indices[i] = indicesCollection.get(i);
	}

	return new SortedExampleSet(exampleSet, indices);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:18,代码来源:PermutationOperator.java

示例2: apply

import com.rapidminer.example.set.SortedExampleSet; //导入依赖的package包/类
@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {
	int sortingDirection = getParameterAsInt(PARAMETER_SORTING_DIRECTION);
	Attribute sortingAttribute = exampleSet.getAttributes().get(getParameterAsString(PARAMETER_ATTRIBUTE_NAME));
	// some checks
	if (sortingAttribute == null) {
		throw new AttributeNotFoundError(this, PARAMETER_ATTRIBUTE_NAME, getParameterAsString(PARAMETER_ATTRIBUTE_NAME));
	}

	ExampleSet result = new SortedExampleSet(exampleSet, sortingAttribute, sortingDirection);

	return result;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:14,代码来源:Sorting.java

示例3: getParameterTypes

import com.rapidminer.example.set.SortedExampleSet; //导入依赖的package包/类
@Override
public List<ParameterType> getParameterTypes() {
	List<ParameterType> types = super.getParameterTypes();
	types.add(new ParameterTypeAttribute(PARAMETER_ATTRIBUTE_NAME,
			"Indicates the attribute which should be used for determining the sorting.", getExampleSetInputPort(), false));
	types.add(new ParameterTypeCategory(PARAMETER_SORTING_DIRECTION, "Indicates the direction of the sorting.",
			SortedExampleSet.SORTING_DIRECTIONS, SortedExampleSet.INCREASING, false));
	return types;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:10,代码来源:Sorting.java

示例4: apply

import com.rapidminer.example.set.SortedExampleSet; //导入依赖的package包/类
@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {
	int sortingDirection = getParameterAsInt(PARAMETER_SORTING_DIRECTION);
	Attribute sortingAttribute = exampleSet.getAttributes().get(getParameterAsString(PARAMETER_ATTRIBUTE_NAME));
	// some checks
	if (sortingAttribute == null) {
		throw new AttributeNotFoundError(this, PARAMETER_ATTRIBUTE_NAME, getParameterAsString(PARAMETER_ATTRIBUTE_NAME));
	}

	ExampleSet result = new SortedExampleSet(exampleSet, sortingAttribute, sortingDirection, getProgress());

	return result;
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:14,代码来源:Sorting.java

示例5: getParameterTypes

import com.rapidminer.example.set.SortedExampleSet; //导入依赖的package包/类
@Override
public List<ParameterType> getParameterTypes() {
	List<ParameterType> types = super.getParameterTypes();
	types.add(new ParameterTypeAttribute(PARAMETER_ATTRIBUTE_NAME,
			"Indicates the attribute which should be used for determining the sorting.", getExampleSetInputPort(),
			false));
	types.add(new ParameterTypeCategory(PARAMETER_SORTING_DIRECTION, "Indicates the direction of the sorting.",
			SortedExampleSet.SORTING_DIRECTIONS, SortedExampleSet.INCREASING, false));
	return types;
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:11,代码来源:Sorting.java

示例6: apply

import com.rapidminer.example.set.SortedExampleSet; //导入依赖的package包/类
@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {         
	
	ArrayList<Integer> indicesCollection = new ArrayList<Integer>(exampleSet.size());
	for (int i = 0; i < exampleSet.size(); i++)
		indicesCollection.add(i);
	
	Collections.shuffle(indicesCollection, RandomGenerator.getRandomGenerator(this));
	
	int[] indices = new int[exampleSet.size()];
	for (int i = 0; i < exampleSet.size(); i++)
		indices[i] = indicesCollection.get(i);
	
	return new SortedExampleSet(exampleSet, indices);
}
 
开发者ID:rapidminer,项目名称:rapidminer-5,代码行数:16,代码来源:PermutationOperator.java

示例7: apply

import com.rapidminer.example.set.SortedExampleSet; //导入依赖的package包/类
@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {		
	int sortingDirection = getParameterAsInt(PARAMETER_SORTING_DIRECTION);
	Attribute sortingAttribute = exampleSet.getAttributes().get(getParameterAsString(PARAMETER_ATTRIBUTE_NAME));
	// some checks
	if (sortingAttribute == null) {
		throw new UserError(this, 111, getParameterAsString(PARAMETER_ATTRIBUTE_NAME));
	}

	ExampleSet result = new SortedExampleSet(exampleSet, sortingAttribute, sortingDirection);

	return result;
}
 
开发者ID:rapidminer,项目名称:rapidminer-5,代码行数:14,代码来源:Sorting.java

示例8: getParameterTypes

import com.rapidminer.example.set.SortedExampleSet; //导入依赖的package包/类
@Override
public List<ParameterType> getParameterTypes() {
	List<ParameterType> types = super.getParameterTypes();
	types.add(new ParameterTypeAttribute(PARAMETER_ATTRIBUTE_NAME, "Indicates the attribute which should be used for determining the sorting.", getExampleSetInputPort(), false));
	types.add(new ParameterTypeCategory(PARAMETER_SORTING_DIRECTION, "Indicates the direction of the sorting.", SortedExampleSet.SORTING_DIRECTIONS, SortedExampleSet.INCREASING, false));
	return types;
}
 
开发者ID:rapidminer,项目名称:rapidminer-5,代码行数:8,代码来源:Sorting.java

示例9: doWork

import com.rapidminer.example.set.SortedExampleSet; //导入依赖的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

示例10: getBestSplit

import com.rapidminer.example.set.SortedExampleSet; //导入依赖的package包/类
public Split getBestSplit(ExampleSet inputSet, Attribute attribute, String labelName) {
	SortedExampleSet exampleSet = new SortedExampleSet((ExampleSet) inputSet.clone(), attribute,
			SortedExampleSet.INCREASING);

	Attribute labelAttribute = exampleSet.getAttributes().getLabel();
	int labelIndex = labelAttribute.getMapping().mapString(labelName);

	double oldLabel = Double.NaN;
	double bestSplit = Double.NaN;
	double lastValue = Double.NaN;
	double bestBenefit = Double.NEGATIVE_INFINITY;
	double bestTotalWeight = 0;
	int bestSplitType = Split.LESS_SPLIT;

	// initiating online counting of benefit: only 2 Datascans needed then
	criterion.reinitOnlineCounting(exampleSet);
	for (Example e : exampleSet) {
		double currentValue = e.getValue(attribute);
		double label = e.getValue(labelAttribute);
		if ((Double.isNaN(oldLabel)) || (oldLabel != label) && (lastValue != currentValue)) {
			double splitValue = (lastValue + currentValue) / 2.0d;

			double[] benefits;
			if (labelName == null) {
				benefits = criterion.getOnlineBenefit(e);
			} else {
				benefits = criterion.getOnlineBenefit(e, labelIndex);
			}
			// online method returns both possible relations in one array(greater / smaller) in
			// one array
			if ((benefits[0] > minValue)
					&& (benefits[0] > 0)
					&& (benefits[1] > 0)
					&& ((benefits[0] > bestBenefit) || ((benefits[0] == bestBenefit) && (benefits[1] > bestTotalWeight)))) {
				bestBenefit = benefits[0];
				bestSplit = splitValue;
				bestTotalWeight = benefits[1];
				bestSplitType = Split.LESS_SPLIT;
			}
			if ((benefits[2] > minValue)
					&& (benefits[2] > 0)
					&& (benefits[3] > 0)
					&& ((benefits[2] > bestBenefit) || ((benefits[2] == bestBenefit) && (benefits[3] > bestTotalWeight)))) {
				bestBenefit = benefits[2];
				bestSplit = splitValue;
				bestTotalWeight = benefits[3];
				bestSplitType = Split.GREATER_SPLIT;
			}
			oldLabel = label;
		}
		lastValue = currentValue;
		criterion.update(e);
	}
	return new Split(bestSplit, new double[] { bestBenefit, bestTotalWeight }, bestSplitType);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:56,代码来源:NumericalSplitter.java

示例11: createPreprocessingModel

import com.rapidminer.example.set.SortedExampleSet; //导入依赖的package包/类
@Override
public PreprocessingModel createPreprocessingModel(ExampleSet exampleSet) throws OperatorException {
	HashMap<Attribute, double[]> ranges = new HashMap<Attribute, double[]>();
	// Get and check parametervalues
	boolean useSqrt = getParameterAsBoolean(PARAMETER_USE_SQRT_OF_EXAMPLES);
	int numberOfBins = 0;
	if (!useSqrt) {
		// if not automatic sizing of bins, use parametervalue
		numberOfBins = getParameterAsInt(PARAMETER_NUMBER_OF_BINS);
		if (numberOfBins >= (exampleSet.size() - 1)) {
			throw new UserError(this, 116, PARAMETER_NUMBER_OF_BINS,
					"number of bins must be smaller than number of examples (here: " + exampleSet.size() + ")");
		}
	} else {
		exampleSet.recalculateAllAttributeStatistics();
	}

	for (Attribute currentAttribute : exampleSet.getAttributes()) {
		if (useSqrt) {
			numberOfBins = (int) Math.round(Math.sqrt(exampleSet.size()
					- (int) exampleSet.getStatistics(currentAttribute, Statistics.UNKNOWN)));
		}
		double[] attributeRanges = new double[numberOfBins];
		ExampleSet sortedSet = new SortedExampleSet(exampleSet, currentAttribute, SortedExampleSet.INCREASING);

		// finding ranges
		double examplesPerBin = exampleSet.size() / (double) numberOfBins;
		double currentBinSpace = examplesPerBin;
		double lastValue = Double.NaN;
		int currentBin = 0;

		for (Example example : sortedSet) {
			double value = example.getValue(currentAttribute);
			if (!Double.isNaN(value)) {
				// change bin if full and not last
				if (currentBinSpace < 1 && currentBin < numberOfBins && value != lastValue) {
					if (!Double.isNaN(lastValue)) {
						attributeRanges[currentBin] = (lastValue + value) / 2;
						currentBin++;
						currentBinSpace += examplesPerBin; // adding because same values might
															// cause binspace to be negative
						if (currentBinSpace < 1) {
							throw new UserError(this, 944, currentAttribute.getName());
						}
					}
				}
				currentBinSpace--;
				lastValue = value;
			}
		}
		attributeRanges[numberOfBins - 1] = Double.POSITIVE_INFINITY;
		ranges.put(currentAttribute, attributeRanges);
	}
	DiscretizationModel model = new DiscretizationModel(exampleSet);

	// determine number of digits
	int numberOfDigits = -1;
	if (getParameterAsBoolean(PARAMETER_AUTOMATIC_NUMBER_OF_DIGITS) == false) {
		numberOfDigits = getParameterAsInt(PARAMETER_NUMBER_OF_DIGITS);
	}

	model.setRanges(ranges, "range", getParameterAsInt(PARAMETER_RANGE_NAME_TYPE), numberOfDigits);
	return model;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:65,代码来源:FrequencyDiscretization.java

示例12: createPreprocessingModel

import com.rapidminer.example.set.SortedExampleSet; //导入依赖的package包/类
@Override
public PreprocessingModel createPreprocessingModel(ExampleSet exampleSet) throws OperatorException {
	DiscretizationModel model = new DiscretizationModel(exampleSet);

	exampleSet.recalculateAllAttributeStatistics();
	// calculating number of bins
	int sizeOfBins = getParameterAsInt(PARAMETER_SIZE_OF_BINS);
	int numberOfBins = exampleSet.size() / sizeOfBins;
	int numberOfExamples = exampleSet.size();
	// add one bin if a remainder exists
	if (numberOfBins * sizeOfBins < numberOfExamples) {
		numberOfBins++;
	}
	HashMap<Attribute, double[]> ranges = new HashMap<Attribute, double[]>();

	int sortingDirection = getParameterAsInt(PARAMETER_SORTING_DIRECTION);

	for (Attribute attribute : exampleSet.getAttributes()) {
		if (attribute.isNumerical()) { // skip nominal and date attributes
			ExampleSet sortedSet = new SortedExampleSet(exampleSet, attribute, sortingDirection);
			double[] binRange = new double[numberOfBins];
			for (int i = 0; i < numberOfBins - 1; i++) {
				int offset = (i + 1) * sizeOfBins - 1;
				double infimum = sortedSet.getExample(offset).getValue(attribute);
				offset++;
				double supremum = sortedSet.getExample(offset).getValue(attribute);
				// if targets equal values: Search for next different value
				while (infimum == supremum && offset < numberOfExamples) {
					supremum = sortedSet.getExample(offset).getValue(attribute);
					offset++;
				}
				if (sortingDirection == SortedExampleSet.DECREASING) {
					binRange[numberOfBins - 2 - i] = (infimum + supremum) / 2d;
				} else {
					binRange[i] = (infimum + supremum) / 2d;
				}
			}
			binRange[numberOfBins - 1] = Double.POSITIVE_INFINITY;
			ranges.put(attribute, binRange);
		}
	}

	// determine number of digits
	int numberOfDigits = -1;
	if (getParameterAsBoolean(PARAMETER_AUTOMATIC_NUMBER_OF_DIGITS) == false) {
		numberOfDigits = getParameterAsInt(PARAMETER_NUMBER_OF_DIGITS);
	}

	model.setRanges(ranges, "range", getParameterAsInt(PARAMETER_RANGE_NAME_TYPE), numberOfDigits);
	return (model);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:52,代码来源:AbsoluteDiscretization.java

示例13: doWork

import com.rapidminer.example.set.SortedExampleSet; //导入依赖的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

示例14: getBestSplit

import com.rapidminer.example.set.SortedExampleSet; //导入依赖的package包/类
public Split getBestSplit(ExampleSet inputSet, Attribute attribute, String labelName) {
	SortedExampleSet exampleSet = new SortedExampleSet(inputSet, attribute, SortedExampleSet.INCREASING);

	Attribute labelAttribute = exampleSet.getAttributes().getLabel();
	int labelIndex = labelAttribute.getMapping().mapString(labelName);

	double oldLabel = Double.NaN;
	double bestSplit = Double.NaN;
	double lastValue = Double.NaN;
	double bestBenefit = Double.NEGATIVE_INFINITY;
	double bestTotalWeight = 0;
	int bestSplitType = Split.LESS_SPLIT;

	// initiating online counting of benefit: only 2 Datascans needed then
	criterion.reinitOnlineCounting(exampleSet);
	for (Example e : exampleSet) {
		double currentValue = e.getValue(attribute);
		double label = e.getValue(labelAttribute);
		if ((Double.isNaN(oldLabel)) || (oldLabel != label) && (lastValue != currentValue)) {
			double splitValue = (lastValue + currentValue) / 2.0d;

			double[] benefits;
			if (labelName == null) {
				benefits = criterion.getOnlineBenefit(e);
			} else {
				benefits = criterion.getOnlineBenefit(e, labelIndex);
			}
			// online method returns both possible relations in one array(greater / smaller) in
			// one array
			if ((benefits[0] > minValue)
					&& (benefits[0] > 0)
					&& (benefits[1] > 0)
					&& ((benefits[0] > bestBenefit) || ((benefits[0] == bestBenefit) && (benefits[1] > bestTotalWeight)))) {
				bestBenefit = benefits[0];
				bestSplit = splitValue;
				bestTotalWeight = benefits[1];
				bestSplitType = Split.LESS_SPLIT;
			}
			if ((benefits[2] > minValue)
					&& (benefits[2] > 0)
					&& (benefits[3] > 0)
					&& ((benefits[2] > bestBenefit) || ((benefits[2] == bestBenefit) && (benefits[3] > bestTotalWeight)))) {
				bestBenefit = benefits[2];
				bestSplit = splitValue;
				bestTotalWeight = benefits[3];
				bestSplitType = Split.GREATER_SPLIT;
			}
			oldLabel = label;
		}
		lastValue = currentValue;
		criterion.update(e);
	}
	return new Split(bestSplit, new double[] { bestBenefit, bestTotalWeight }, bestSplitType);
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:55,代码来源:NumericalSplitter.java

示例15: doWork

import com.rapidminer.example.set.SortedExampleSet; //导入依赖的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.example.set.SortedExampleSet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。