"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/main/java/com/rapidminer/example/Tools.java" between
rapidminer-studio-9.4.1-src.tar.gz and rapidminer-studio-9.5.0-src.tar.gz

About: RapidMiner Studio is a code-free environment for designing advanced analytic processes with machine learning, data mining, text mining, predictive analytics and business analytics. Java source.

Tools.java  (rapidminer-studio-9.4.1-src):Tools.java  (rapidminer-studio-9.5.0-src)
skipping to change at line 56 skipping to change at line 56
import com.rapidminer.tools.RandomGenerator; import com.rapidminer.tools.RandomGenerator;
import com.rapidminer.tools.math.sampling.OrderedSamplingWithoutReplacement; import com.rapidminer.tools.math.sampling.OrderedSamplingWithoutReplacement;
/** /**
* Provides some tools for calculation of certain measures and feature generatio n. * Provides some tools for calculation of certain measures and feature generatio n.
* *
* @author Simon Fischer, Ingo Mierswa * @author Simon Fischer, Ingo Mierswa
*/ */
public class Tools { public class Tools {
/**
* Thrown as a {@link UserError#getErrorIdentifier()} by {@link #onlyFini
teValues}
* @since 9.5.0
*/
public static String INFINITE_VALUES = "infinite_values";
// ====================================================================== ========== // ====================================================================== ==========
// -------------------- Tools -------------------- // -------------------- Tools --------------------
// ====================================================================== ========== // ====================================================================== ==========
public static String[] getAllAttributeNames(ExampleSet exampleSet) { public static String[] getAllAttributeNames(ExampleSet exampleSet) {
String[] attributeNames = new String[exampleSet.getAttributes().a llSize()]; String[] attributeNames = new String[exampleSet.getAttributes().a llSize()];
int counter = 0; int counter = 0;
Iterator<Attribute> a = exampleSet.getAttributes().allAttributes( ); Iterator<Attribute> a = exampleSet.getAttributes().allAttributes( );
while (a.hasNext()) { while (a.hasNext()) {
Attribute attribute = a.next(); Attribute attribute = a.next();
skipping to change at line 437 skipping to change at line 443
/** /**
* The data set is not allowed to contain non-finite values. If it does, a {@link UserError} is * The data set is not allowed to contain non-finite values. If it does, a {@link UserError} is
* thrown. * thrown.
* *
* @param exampleSet * @param exampleSet
* the {@link ExampleSet} to check * the {@link ExampleSet} to check
* @param task * @param task
* will be shown as the origin of the error * will be shown as the origin of the error
* @param operator * @param operator
* the offending operator. Can be <code>null</code> * the offending operator. Can be <code>null</code>
* @throws UserError with {@link UserError#getErrorIdentifier()} {@link # INFINITE_VALUES} in case of infinite values
* @since 7.6 * @since 7.6
**/ **/
public static void onlyFiniteValues(ExampleSet exampleSet, String task, O perator operator) public static void onlyFiniteValues(ExampleSet exampleSet, String task, O perator operator)
throws ProcessStoppedException, UserError { throws ProcessStoppedException, UserError {
onlyFiniteValues(exampleSet, false, task, operator); onlyFiniteValues(exampleSet, false, task, operator);
} }
/** /**
* The data set is not allowed to contain infinite and, if indicated, mis sing values. If it * The data set is not allowed to contain infinite and, if indicated, mis sing values. If it
* does, a {@link UserError} is thrown. * does, a {@link UserError} is thrown.
* *
* @param exampleSet * @param exampleSet
* the {@link ExampleSet} to check * the {@link ExampleSet} to check
* @param allowMissing * @param allowMissing
* indicates whether {@link Double#NaN} should be ignored * indicates whether {@link Double#NaN} should be ignored
* @param task * @param task
* will be shown as the origin of the error * will be shown as the origin of the error
* @param operator * @param operator
* the offending operator. Can be <code>null</code> * the offending operator. Can be <code>null</code>
* @throws UserError with {@link UserError#getErrorIdentifier()} {@link # INFINITE_VALUES} in case of infinite values
* @since 7.6 * @since 7.6
**/ **/
public static void onlyFiniteValues(ExampleSet exampleSet, boolean allowM issing, String task, Operator operator) public static void onlyFiniteValues(ExampleSet exampleSet, boolean allowM issing, String task, Operator operator)
throws ProcessStoppedException, UserError { throws ProcessStoppedException, UserError {
List<String> specialAttList = new LinkedList<>(); List<String> specialAttList = new LinkedList<>();
Iterator<AttributeRole> specialAttributes = exampleSet.getAttribu tes().specialAttributes(); Iterator<AttributeRole> specialAttributes = exampleSet.getAttribu tes().specialAttributes();
while (specialAttributes.hasNext()) { while (specialAttributes.hasNext()) {
specialAttList.add(specialAttributes.next().getSpecialNam e()); specialAttList.add(specialAttributes.next().getSpecialNam e());
} }
onlyFiniteValues(exampleSet, task, operator, specialAttList.toArr ay(new String[specialAttList.size()])); onlyFiniteValues(exampleSet, task, operator, specialAttList.toArr ay(new String[specialAttList.size()]));
skipping to change at line 483 skipping to change at line 491
* *
* @param exampleSet * @param exampleSet
* the {@link ExampleSet} to check * the {@link ExampleSet} to check
* @param task * @param task
* will be shown as the origin of the error * will be shown as the origin of the error
* @param operator * @param operator
* the offending operator. Can be <code>null</code> * the offending operator. Can be <code>null</code>
* @param specialAttributes * @param specialAttributes
* contains the special attributes which have to be checked. I f a listed attribute * contains the special attributes which have to be checked. I f a listed attribute
* does not exist or contains non-finite values, a {@link User Error} is thrown * does not exist or contains non-finite values, a {@link User Error} is thrown
* @throws UserError with {@link UserError#getErrorIdentifier()} {@link # INFINITE_VALUES} in case of infinite values
* @since 7.6 * @since 7.6
**/ **/
public static void onlyFiniteValues(ExampleSet exampleSet, String task, O perator operator, String... specialAttributes) public static void onlyFiniteValues(ExampleSet exampleSet, String task, O perator operator, String... specialAttributes)
throws ProcessStoppedException, UserError { throws ProcessStoppedException, UserError {
onlyFiniteValues(exampleSet, false, task, operator, specialAttrib utes); onlyFiniteValues(exampleSet, false, task, operator, specialAttrib utes);
} }
/** /**
* The data set is not allowed to contain infinite and, if indicated, mis sing values. If it * The data set is not allowed to contain infinite and, if indicated, mis sing values. If it
* does, a {@link UserError} is thrown. Special attributes will be ignore d, except they are * does, a {@link UserError} is thrown. Special attributes will be ignore d, except they are
skipping to change at line 507 skipping to change at line 516
* the {@link ExampleSet} to check * the {@link ExampleSet} to check
* @param allowMissing * @param allowMissing
* indicates whether {@link Double#NaN} should be ignored * indicates whether {@link Double#NaN} should be ignored
* @param task * @param task
* will be shown as the origin of the error * will be shown as the origin of the error
* @param operator * @param operator
* the offending operator. Can be <code>null</code> * the offending operator. Can be <code>null</code>
* @param specialAttributes * @param specialAttributes
* contains the special attributes which have to be checked. I f a listed attribute * contains the special attributes which have to be checked. I f a listed attribute
* does not exist or contains not-allowed values, a {@link Use rError} is thrown * does not exist or contains not-allowed values, a {@link Use rError} is thrown
* @since 7.6 * @throws UserError with {@link UserError#getErrorIdentifier()} {@link #
INFINITE_VALUES} in case of infinite values
* @since 7.6
**/ **/
public static void onlyFiniteValues(ExampleSet exampleSet, boolean allowM issing, String task, Operator operator, public static void onlyFiniteValues(ExampleSet exampleSet, boolean allowM issing, String task, Operator operator,
String... specialAttributes) throws ProcessStoppedExcepti on, UserError { String... specialAttributes) throws ProcessStoppedExcepti on, UserError {
HashSet<Attribute> specialToCheck = new HashSet<>(); HashSet<Attribute> specialToCheck = new HashSet<>();
for (int i = 0; i < specialAttributes.length; i++) { for (int i = 0; i < specialAttributes.length; i++) {
Attribute att = exampleSet.getAttributes().getSpecial(spe cialAttributes[i]); Attribute att = exampleSet.getAttributes().getSpecial(spe cialAttributes[i]);
if (att != null) { if (att != null) {
specialToCheck.add(att); specialToCheck.add(att);
} else { } else {
skipping to change at line 533 skipping to change at line 543
while (allRoles.hasNext()) { while (allRoles.hasNext()) {
if (operator != null) { if (operator != null) {
operator.checkForStop(); operator.checkForStop();
} }
AttributeRole role = allRoles.next(); AttributeRole role = allRoles.next();
if (!role.isSpecial() || specialToCheck.contains(role.get Attribute())) { if (!role.isSpecial() || specialToCheck.contains(role.get Attribute())) {
Attribute attribute = role.getAttribute(); Attribute attribute = role.getAttribute();
for (Example example : exampleSet) { for (Example example : exampleSet) {
double value = example.getValue(attribute ); double value = example.getValue(attribute );
if (Double.isInfinite(value)) { if (Double.isInfinite(value)) {
throw new UserError(operator, "in finite_values", task); throw new UserError(operator, INF INITE_VALUES, task);
} }
if (!allowMissing && Double.isNaN(value)) { if (!allowMissing && Double.isNaN(value)) {
throw new UserError(operator, 139 , task); throw new UserError(operator, 139 , task);
} }
} }
} }
} }
} }
/** /**
skipping to change at line 557 skipping to change at line 567
* the example set * the example set
* @throws UserError * @throws UserError
*/ */
public static void onlyNumericalAttributes(ExampleSet es, String task) th rows UserError { public static void onlyNumericalAttributes(ExampleSet es, String task) th rows UserError {
onlyNumericalAttributes(es.getAttributes(), task); onlyNumericalAttributes(es.getAttributes(), task);
} }
/** /**
* The attributes all have to be numerical. * The attributes all have to be numerical.
* *
* @param es * @param attributes
* the example set * the attributes
* @param task task name used for the error message
* @throws UserError * @throws UserError
*/ */
public static void onlyNumericalAttributes(Attributes attributes, String task) throws UserError { public static void onlyNumericalAttributes(Attributes attributes, String task) throws UserError {
for (Attribute attribute : attributes) { for (Attribute attribute : attributes) {
if (!Ontology.ATTRIBUTE_VALUE_TYPE.isA(attribute.getValue Type(), Ontology.NUMERICAL)) { if (!Ontology.ATTRIBUTE_VALUE_TYPE.isA(attribute.getValue Type(), Ontology.NUMERICAL)) {
throw new UserError(null, 104, task, attribute.ge tName()); throw new UserError(null, 104, task, attribute.ge tName());
} }
} }
} }
/** /**
* The attributes all have to be nominal or binary. * The attributes all have to be nominal or binary.
* *
* @param es * @param es
* the example set * the example set
* @param task task name used for the error message
* @throws UserError * @throws UserError
*/ */
public static void onlyNominalAttributes(ExampleSet es, String task) thro ws UserError { public static void onlyNominalAttributes(ExampleSet es, String task) thro ws UserError {
onlyNominalAttributes(es.getAttributes(), task); onlyNominalAttributes(es.getAttributes(), task);
} }
/** /**
* The attributes all have to be nominal or binary. * The attributes all have to be nominal or binary.
* *
* @param attributes
* the attributes
* @param task task name used for the error message
* @throws UserError * @throws UserError
*/ */
public static void onlyNominalAttributes(Attributes attributes, String ta sk) throws UserError { public static void onlyNominalAttributes(Attributes attributes, String ta sk) throws UserError {
for (Attribute attribute : attributes) { for (Attribute attribute : attributes) {
if (!Ontology.ATTRIBUTE_VALUE_TYPE.isA(attribute.getValue Type(), Ontology.NOMINAL)) { if (!Ontology.ATTRIBUTE_VALUE_TYPE.isA(attribute.getValue Type(), Ontology.NOMINAL)) {
throw new UserError(null, 103, task, attribute.ge tName()); throw new UserError(null, 103, task, attribute.ge tName());
} }
} }
} }
/** /**
* The attributes all have to be nominal and have a maximum of two values or binominal. * The attributes all have to be nominal and have a maximum of two values or binominal.
* *
* @param exampleSet * @param exampleSet
* the example set * the example set
* @param task task name used for the error message
* @throws UserError * @throws UserError
* *
*/ */
public static void maximumTwoNominalAttributes(ExampleSet exampleSet, Str ing task) throws UserError { public static void maximumTwoNominalAttributes(ExampleSet exampleSet, Str ing task) throws UserError {
for (Attribute attribute : exampleSet.getAttributes()) { for (Attribute attribute : exampleSet.getAttributes()) {
int valueType = attribute.getValueType(); int valueType = attribute.getValueType();
boolean throwError = false; boolean throwError = false;
if (!Ontology.ATTRIBUTE_VALUE_TYPE.isA(valueType, Ontolog y.NOMINAL)) { if (!Ontology.ATTRIBUTE_VALUE_TYPE.isA(valueType, Ontolog y.NOMINAL)) {
throwError = true; throwError = true;
} }
 End of changes. 10 change blocks. 
4 lines changed or deleted 22 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)