/** * Returns the index of an Attribute. * * @param att, the attribute. */ protected int indexOf(Attribute att) { return this.hsAttributesIndices.get(att.name()); }
public static String getClassNameString(InstancesHeader context) { if (context == null) { return "[class]"; } return "[class:" + context.classAttribute().name() + "]"; }
public static String getClassNameString(InstancesHeader context) { if (context == null) { return "[class]"; } return "[class:" + context.classAttribute().name() + "]"; }
/** * Completes the hashset with attributes indices. */ private void computeAttributesIndices() { this.hsAttributesIndices = new HashMap<String, Integer>(); // iterates through all existing attributes // and sets an unique identifier for each one of them for (int i = 0; i < this.numAttributes(); i++) { hsAttributesIndices.put(this.attribute(i).name(), i); } }
@Override public String getStaticOutput(InstanceInformation instanceInformation) { StringBuffer sb = new StringBuffer(); if(this.literalStatistics!=null){ for(int i=0; i<this.literalStatistics.length; i++){ sb.append( instanceInformation.outputAttribute(outputsToLearn[i]).name() + ": " + literalStatistics[i].getValue(1)/literalStatistics[i].getValue(0) + " " ); // } } return sb.toString(); }
@Override public String getStaticOutput(InstanceInformation instanceInformation) { StringBuffer sb = new StringBuffer(); if(this.literalStatistics!=null){ for(int i=0; i<this.literalStatistics.length; i++){ sb.append(instanceInformation.outputAttribute(outputsToLearn[i]).name() + ": " + literalStatistics[i].getValue(1)/literalStatistics[i].getValue(0) + " "); } } return sb.toString(); }
public static String getInputAttributeNameString(InstancesHeader context, int attIndex) { if ((context == null) || (attIndex >= context.numInputAttributes())) { return "[att " + (attIndex + 1) + "]"; } int instAttIndex = attIndex; return "[att " + (attIndex + 1) + ":" + context.inputAttribute(instAttIndex).name() + "]"; }
public Attribute attribute(String name) { for (int i = 0; i < numAttributes(); i++) { if (attribute(i).name().equals(name)) { return attribute(i); } } return null; }
public Attribute attribute(String name) { for (int i = 0; i < numAttributes(); i++) { if (attribute(i).name().equals(name)) { return attribute(i); } } return null; }
text.append(ARFF_ATTRIBUTE).append(" ").append(Utils.quote(this.name())).append(" ");
@Override public void getDescription(StringBuilder sb, int indent, InstanceInformation instInformation) { if (instInformation!=null){ if(isEqualOrLower) StringUtils.appendIndented(sb, indent+1, instInformation.inputAttribute(inputAttributeIndex).name() + " <= " + attributeValue); else StringUtils.appendIndented(sb, indent+1, instInformation.inputAttribute(inputAttributeIndex).name() + " > " + attributeValue); } else getDescription(sb,indent); }
/** * 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; } }
public static String getAttributeNameString(InstancesHeader context, int attIndex) { if ((context == null) || (attIndex >= context.numAttributes())) { return "[att " + (attIndex + 1) + "]"; } int instAttIndex = attIndex < context.classIndex() ? attIndex : attIndex + 1; return "[att " + (attIndex + 1) + ":" + context.attribute(instAttIndex).name() + "]"; }
public static String getAttributeNameString(InstancesHeader context, int attIndex) { if ((context == null) || (attIndex >= context.numAttributes())) { return "[att " + (attIndex + 1) + "]"; } int instAttIndex = attIndex < context.classIndex() ? attIndex : attIndex + 1; return "[att " + (attIndex + 1) + ":" + context.attribute(instAttIndex).name() + "]"; }
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); }
continue; result.append(m_headerInfo.attribute(w).name()).append("\t"); for (int c = 0; c < m_numClasses; c++) { double value = m_wordTotalForClass[c].getValue(w);
@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); }
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()); }
public void getModelDescription(StringBuilder out, int indent) { for (int i = 0; i < tree.getModelContext().numOutputAttributes(); i++) { StringUtils.appendIndented(out, indent, " [" + tree.getModelContext().outputAttribute(i).name() + "]"); if (getModelContext() != null) { for (int j = 0; j < getModelContext().numOutputAttributes(); j++) { if (getModelContext().attribute(j).isNumeric()) { out.append((j == 0 || weights[i][j] < 0) ? " " : " + "); out.append(String.format("%.4f", weights[i][j])); out.append(" * "); out.append(getAttributeNameString(j)); } } out.append(" + " + weights[i][getModelContext().numOutputAttributes()]); } StringUtils.appendNewline(out); } } }
if (this.ruleSet.get(k).predicateSet.size() == 1) { if (this.ruleSet.get(k).predicateSet.get(i).getSymbol() == 0.0) { String nam = this.instance.attribute((int)this.ruleSet.get(k).predicateSet.get(i).getAttributeValue()).name(); String val = this.instance.attribute((int)this.ruleSet.get(k).predicateSet.get(i).getAttributeValue()).value((int)this.ruleSet.get(k).predicateSet.get(i).getValue()); StringUtils.appendIndented(out, indent, nam+" = "+val+" --> "+this.instance.classAttribute().value((int)getRuleMajorityClassIndex(this.ruleSet.get(k)))); StringUtils.appendNewline(out); } else if (this.ruleSet.get(k).predicateSet.get(i).getSymbol() == -1.0){ String nam = this.instance.attribute((int)this.ruleSet.get(k).predicateSet.get(i).getAttributeValue()).name(); StringUtils.appendIndented(out, indent, nam+" <= "+this.ruleSet.get(k).predicateSet.get(i).getValue()+" --> "+this.instance.classAttribute().value((int)ruleClassIndex.getValue(k))); StringUtils.appendNewline(out); } else { String nam = this.instance.attribute((int)this.ruleSet.get(k).predicateSet.get(i).getAttributeValue()).name(); StringUtils.appendIndented(out, indent, nam+" > "+this.ruleSet.get(k).predicateSet.get(i).getValue()+" --> "+this.instance.classAttribute().value((int)this.ruleClassIndex.getValue(k))); StringUtils.appendNewline(out); String nam = this.instance.attribute((int)this.ruleSet.get(k).predicateSet.get(i).getAttributeValue()).name(); String val = this.instance.attribute((int)this.ruleSet.get(k).predicateSet.get(i).getAttributeValue()).value((int)this.ruleSet.get(k).predicateSet.get(i).getValue()); StringUtils.appendIndented(out, indent, nam+" = "+val+" "); } else if (this.ruleSet.get(k).predicateSet.get(i).getSymbol()==-1.0){ String nam = this.instance.attribute((int)this.ruleSet.get(k).predicateSet.get(i).getAttributeValue()).name(); StringUtils.appendIndented(out, indent, nam+" <= "+this.ruleSet.get(k).predicateSet.get(i).getValue()+" "); } else { String nam = this.instance.attribute((int)this.ruleSet.get(k).predicateSet.get(i).getAttributeValue()).name(); StringUtils.appendIndented(out, indent, nam+" > "+this.ruleSet.get(k).predicateSet.get(i).getValue()+" ");