/** * Returns a string representation of value. If the numberOfDigits is greater than 0 this number * is used to format the string. Otherwise the value of the system property * rapidminer.gui.fractiondigits.numbers will be used (see {@link com.rapidminer.tools.Tools} in * case of DEFAULT_NUMBER_OF_DIGITS or an unlimited number of digits in case of * UNLIMITED_NUMBER_OF_DIGITS. For the value NaN a "?" will be returned. */ public String getAsString(double value, int numberOfDigits, boolean quoteNominal) { if (Double.isNaN(value)) { return "?"; } else { switch (numberOfDigits) { case UNLIMITED_NUMBER_OF_DIGITS: return Double.toString(value); case DEFAULT_NUMBER_OF_DIGITS: return com.rapidminer.tools.Tools.formatIntegerIfPossible(value, -1); default: return com.rapidminer.tools.Tools.formatIntegerIfPossible(value, numberOfDigits); } } }
@Override public String toString() { StringBuffer buffer = new StringBuffer(); if ((classPositive != null) && (classNegative != null)) buffer.append( "Hyperplane seperating " + classPositive + " and " + classNegative + "." + Tools.getLineSeparator()); else buffer.append("Hyperplane for linear regression." + Tools.getLineSeparator()); buffer.append("Intercept: "); buffer.append(Double.toString(intercept)); buffer.append(Tools.getLineSeparator()); buffer.append("Coefficients: " + Tools.getLineSeparator()); int counter = 0; for (double value : coefficients) { buffer.append( "w(" + coefficientNames[counter] + ") = " + Tools.formatIntegerIfPossible(value, 3) + Tools.getLineSeparator()); counter++; } buffer.append(Tools.getLineSeparator()); return buffer.toString(); }
@Override public void updateStatistics(final ExampleSet exampleSet) { final String days = WHITESPACE + I18N.getMessage( I18N.getGUIBundle(), "gui.label.attribute_statistics.statistics.days.label"); final String hours = WHITESPACE + I18N.getMessage( I18N.getGUIBundle(), "gui.label.attribute_statistics.statistics.hours.label"); long minMilliseconds = (long) exampleSet.getStatistics(getAttribute(), Statistics.MINIMUM); long maxMilliseconds = (long) exampleSet.getStatistics(getAttribute(), Statistics.MAXIMUM); long difference = maxMilliseconds - minMilliseconds; String dura = ""; if (getAttribute().getValueType() == Ontology.DATE) { // days dura += com.rapidminer.tools.Tools.formatIntegerIfPossible( Math.floor(difference / (H_IN_D * M_IN_H * S_IN_M * MS_IN_S)), 3) + days; } else if (getAttribute().getValueType() == Ontology.TIME) { // hours dura += com.rapidminer.tools.Tools.formatIntegerIfPossible( Math.floor(difference / (M_IN_H * S_IN_M * MS_IN_S)), 3) + hours; } else if (getAttribute().getValueType() == Ontology.DATE_TIME) { // days + hours + minutes + seconds dura += com.rapidminer.tools.Tools.formatIntegerIfPossible( Math.floor(difference / (H_IN_D * M_IN_H * S_IN_M * MS_IN_S)), 3) + SHORT_DAY; dura += WHITESPACE; double leftoverMilliSeconds = difference % (H_IN_D * M_IN_H * S_IN_M * MS_IN_S); dura += com.rapidminer.tools.Tools.formatIntegerIfPossible( Math.floor(leftoverMilliSeconds / (M_IN_H * S_IN_M * MS_IN_S)), 3) + SHORT_HOUR; dura += WHITESPACE; leftoverMilliSeconds = leftoverMilliSeconds % (M_IN_H * S_IN_M * MS_IN_S); dura += com.rapidminer.tools.Tools.formatIntegerIfPossible( Math.floor(leftoverMilliSeconds / (S_IN_M * MS_IN_S)), 3) + SHORT_MINUTE; dura += WHITESPACE; leftoverMilliSeconds = leftoverMilliSeconds % (S_IN_M * MS_IN_S); dura += com.rapidminer.tools.Tools.formatIntegerIfPossible( Math.floor(leftoverMilliSeconds / MS_IN_S), 3) + SHORT_SECOND; } String minResult = null; String maxResult = null; if (getAttribute().getValueType() == Ontology.DATE) { minResult = FORMAT_DATE.format(new Date(minMilliseconds)); maxResult = FORMAT_DATE.format(new Date(maxMilliseconds)); } else if (getAttribute().getValueType() == Ontology.TIME) { minResult = FORMAT_TIME.format(new Date(minMilliseconds)); maxResult = FORMAT_TIME.format(new Date(maxMilliseconds)); } else if (getAttribute().getValueType() == Ontology.DATE_TIME) { minResult = FORMAT_DATE_TIME.format(new Date(minMilliseconds)); maxResult = FORMAT_DATE_TIME.format(new Date(maxMilliseconds)); } missing = exampleSet.getStatistics(getAttribute(), Statistics.UNKNOWN); from = minResult; until = maxResult; duration = dura; fireStatisticsChangedEvent(); }
public String getValueString() { return Tools.formatIntegerIfPossible(this.value); }
private void addEdges() { // remove old edges if available Iterator<String> e = edgeLabelMap.keySet().iterator(); while (e.hasNext()) { graph.removeEdge(e.next()); } edgeLabelMap.clear(); boolean isDistance = measure.isDistance(); Attribute id = exampleSet.getAttributes().getId(); List<SortableEdge> sortableEdges = new LinkedList<SortableEdge>(); for (int i = 0; i < exampleSet.size(); i++) { Example example = exampleSet.getExample(i); for (int j = i + 1; j < exampleSet.size(); j++) { Example comExample = exampleSet.getExample(j); if (isDistance) sortableEdges.add( new SortableEdge( example.getValueAsString(id), comExample.getValueAsString(id), null, measure.calculateDistance(example, comExample), SortableEdge.DIRECTION_INCREASE)); else sortableEdges.add( new SortableEdge( example.getValueAsString(id), comExample.getValueAsString(id), null, measure.calculateSimilarity(example, comExample), SortableEdge.DIRECTION_DECREASE)); } } Collections.sort(sortableEdges); int numberOfEdges = distanceSlider.getValue(); int counter = 0; double minStrength = Double.POSITIVE_INFINITY; double maxStrength = Double.NEGATIVE_INFINITY; Map<String, Double> strengthMap = new HashMap<String, Double>(); for (SortableEdge sortableEdge : sortableEdges) { if (counter > numberOfEdges) break; String idString = edgeFactory.create(); graph.addEdge( idString, sortableEdge.getFirstVertex(), sortableEdge.getSecondVertex(), EdgeType.UNDIRECTED); edgeLabelMap.put(idString, Tools.formatIntegerIfPossible(sortableEdge.getEdgeValue())); double strength = sortableEdge.getEdgeValue(); minStrength = Math.min(minStrength, strength); maxStrength = Math.max(maxStrength, strength); strengthMap.put(idString, strength); counter++; } for (Entry<String, Double> entry : strengthMap.entrySet()) { edgeStrengthMap.put( entry.getKey(), (entry.getValue() - minStrength) / (maxStrength - minStrength)); } }