public void initHeader(Instances dataset) { int numLabels = this.numOldLabelsOption.getValue(); Attribute target = dataset.classAttribute(); List<String> possibleValues = new ArrayList<String>(); int n = target.numValues(); for (int i = 0; i < n; i++) { possibleValues.add(target.value(i)); } ArrayList<Attribute> attrs = new ArrayList<Attribute>(numLabels + dataset.numAttributes()); for (int i = 0; i < numLabels; i++) { attrs.add(new Attribute(target.name() + "_" + i, possibleValues)); } for (int i = 0; i < dataset.numAttributes(); i++) { Attribute attr = dataset.attribute(i); Attribute newAttribute = null; if (attr.isNominal() == true) { newAttribute = new Attribute(attr.name(), attr.getAttributeValues()); } if (attr.isNumeric() == true) { newAttribute = new Attribute(attr.name()); } if (newAttribute != null) { attrs.add(newAttribute); } } this.header = new Instances("extended_" + dataset.getRelationName(), attrs, 0); this.header.setClassIndex(numLabels + dataset.classIndex()); }
|| streamTokenizer.ttype == 34)) { boolean isNumeric = attributes.get(numAttribute).isNumeric(); double value; if ("?".equals(streamTokenizer.sval)) { value = Double.valueOf(streamTokenizer.sval).doubleValue(); } else { value = this.instanceInformation.attribute(numAttribute).indexOfValue(streamTokenizer.sval);
public static String getNumericValueString(InstancesHeader context, int attIndex, double value) { if (context != null) { int instAttIndex = attIndex < context.classIndex() ? attIndex : attIndex + 1; if (instAttIndex < context.numAttributes()) { if (context.attribute(instAttIndex).isDate()) { return context.attribute(instAttIndex).formatDate(value); } } } return Double.toString(value); }
/** * Weka attribute. * * @param index the index * @param attribute the attribute * @return the weka.core. attribute */ protected weka.core.Attribute wekaAttribute(int index, Attribute attribute) { weka.core.Attribute wekaAttribute; if (attribute.isNominal()) { wekaAttribute = new weka.core.Attribute(attribute.name(), attribute.getAttributeValues(), index); } else { wekaAttribute = new weka.core.Attribute(attribute.name(), index); } //System.out.println(wekaAttribute.name()); //System.out.println(wekaAttribute.isNominal()); return wekaAttribute; } }
@Override public void getDescription(StringBuilder sb, int indent, InstanceInformation instInformation) { if (instInformation!=null){ if(isEqual) StringUtils.appendIndented(sb, indent+1, instInformation.inputAttribute(inputAttributeIndex).name() + " == " + instInformation.inputAttribute(inputAttributeIndex).value((int)attributeValue)); else StringUtils.appendIndented(sb, indent+1, instInformation.inputAttribute(inputAttributeIndex).name() + " <> " + instInformation.inputAttribute(inputAttributeIndex).value((int)attributeValue)); } else getDescription(sb,indent); }
/** * Text representation of a InstanceImpl. */ @Override public String toString() { StringBuilder str = new StringBuilder(); for (int attIndex = 0; attIndex < this.numAttributes(); attIndex++) { if (!this.isMissing(attIndex)) { if (this.attribute(attIndex).isNominal()) { int valueIndex = (int) this.value(attIndex); String stringValue = this.attribute(attIndex).value(valueIndex); str.append(stringValue).append(","); } else if (this.attribute(attIndex).isNumeric()) { str.append(this.value(attIndex)).append(","); } else if (this.attribute(attIndex).isDate()) { SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); str.append(dateFormatter.format(this.value(attIndex))).append(","); } } else { str.append("?,"); } } return str.toString(); }
public static String getNominalValueString(InstancesHeader context, int attIndex, int valIndex) { if (context != null) { int instAttIndex = attIndex < context.classIndex() ? attIndex : attIndex + 1; if ((instAttIndex < context.numAttributes()) && (valIndex < context.attribute(instAttIndex).numValues())) { return "{val " + (valIndex + 1) + ":" + context.attribute(instAttIndex).value(valIndex) + "}"; } } return "{val " + (valIndex + 1) + "}"; }
private Attribute defaultNumericAttribute() { if (this.defaultNumericAttribute == null) { this.defaultNumericAttribute = new Attribute("default"); } return this.defaultNumericAttribute; }
/** * Returns an enumeration of all the attribute's values if the * attribute is nominal, null otherwise. * * @return enumeration of all the attribute's values */ public final /*@ pure @*/ Enumeration enumerateValues() { if (this.isNominal()) { return Collections.enumeration(this.attributeValues); } return null; } }
/** * * @return */ public int numValues() { if (isNumeric()) { return 0; } else { return attributeValues.size(); } }
public int numClasses() { return this.attributes.get(this.classIndex()).numValues(); }
for (int i = 0; i < instance.numAttributes(); i++) { if (instance.classIndex() != i && instance.attribute(i).isNominal()) { if ((!sort.isEmpty()) && (i == sort.first())) { sort.remove(new Integer(sort.first())); && instance.attribute(i).isNumeric()) { virtualChildren.set(i, new AdaptiveNumericVirtualNode((Iadem3) tree, this,
/** * Computes the utility of a single child with respect to this node * * @param child the child for which to compute the utility * @return the utility of the child with respect to this node * @throws Exception if something goes wrong */ protected double categoryUtilityChild(CNode child) {//throws Exception { double sum = 0; for (int i = 0; i < m_numAttributes; i++) { if (m_clusterInstances.attribute(i).isNominal()) { for (int j = 0; j < m_clusterInstances.attribute(i).numValues(); j++) { double x = child.getProbability(i, j); double y = getProbability(i, j); sum += (x * x) - (y * y); } } else { // numeric attribute sum += ((m_normal / child.getStandardDev(i)) - (m_normal / getStandardDev(i))); } } return (child.m_totalInstances / m_totalInstances) * sum; }
private void setSparseValue(Instance instance, List<Integer> indexValues, List<Double> attributeValues, int numAttribute, double value, boolean isNumber) { double valueAttribute; if (isNumber && this.instanceInformation.attribute(numAttribute).isNominal) { valueAttribute = this.instanceInformation.attribute(numAttribute).indexOfValue(Double.toString(value)); } else { valueAttribute = value; } //if (this.instanceInformation.classIndex() == numAttribute) { // setClassValue(instance, valueAttribute); //} else { //instance.setValue(numAttribute, valueAttribute); indexValues.add(numAttribute); attributeValues.add(valueAttribute); //} //System.out.println(numAttribute+":"+valueAttribute+","+this.instanceInformation.classIndex()+","+value); }
protected void printAnomaly(Instance inst, double anomaly) { StringBuffer sb= new StringBuffer(); for(int i=0; i<inst.numInputAttributes(); i++){ if(inst.attribute(i).isNumeric()){ double [] stats; //Attribute name sb.append("Attribute " + i +" (" + inst.attribute(i).name()+ ") - "); //Val for instance double val=inst.valueInputAttribute(i); sb.append("Value: ").append(val); stats=sufficientStatistics.get(i); double mean=stats[0]/weightSeen; double std=Utils.computeSD(stats[1], stats[0], weightSeen); double prob=probabilityFunction.getProbability(mean, Utils.computeSD(stats[1], stats[0], weightSeen), val); //Mean sb.append(" - Prob: ").append(prob); //Mean sb.append(" - Mean: ").append(mean); //SD sb.append(" - Std: ").append(std).append("\n"); } } sb.append("Score - ").append(anomaly); System.out.println(sb); }
/** * Returns the index of an Attribute. * * @param att, the attribute. */ protected int indexOf(Attribute att) { return this.hsAttributesIndices.get(att.name()); }
public static String getClassLabelString(InstancesHeader context, int classLabelIndex) { if ((context == null) || (classLabelIndex >= context.numClasses())) { return "<class " + (classLabelIndex + 1) + ">"; } return "<class " + (classLabelIndex + 1) + ":" + context.classAttribute().value(classLabelIndex) + ">"; }
public String toStringArff() { StringBuilder text = new StringBuilder(); text.append(ARFF_RELATION).append(" ") .append(Utils.quote(getRelationName())).append("\n\n"); for (int i = 0; i < numAttributes(); i++) { text.append(attribute(i).toString()).append("\n"); } text.append("\n").append(ARFF_DATA).append("\n"); text.append(toString()); return text.toString(); } }
public static String getNominalValueString(InstancesHeader context, int attIndex, int valIndex) { if (context != null) { int instAttIndex = attIndex < context.classIndex() ? attIndex : attIndex + 1; if ((instAttIndex < context.numAttributes()) && (valIndex < context.attribute(instAttIndex).numValues())) { return "{val " + (valIndex + 1) + ":" + context.attribute(instAttIndex).value(valIndex) + "}"; } } return "{val " + (valIndex + 1) + "}"; }
/** * Get Samoa attribute from a weka attribute. * * @param index the index * @param attribute the attribute * @return the attribute */ protected Attribute samoaAttribute(int index, weka.core.Attribute attribute) { Attribute samoaAttribute; if (attribute.isNominal()) { Enumeration enu = attribute.enumerateValues(); List<String> attributeValues = new ArrayList<String>(); while (enu.hasMoreElements()) { attributeValues.add((String) enu.nextElement()); } samoaAttribute = new Attribute(attribute.name(), attributeValues); } else { samoaAttribute = new Attribute(attribute.name()); } return samoaAttribute; } }