@Override public InstancesHeader getHeader() { return new InstancesHeader(this.instances); }
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 getClassLabelString(InstancesHeader context, int classLabelIndex) { if ((context == null) || (classLabelIndex >= context.numClasses())) { return "<class " + (classLabelIndex + 1) + ">"; } return "<class " + (classLabelIndex + 1) + ":" + context.classAttribute().value(classLabelIndex) + ">"; }
@Override public String describeConditionForBranch(int branch, InstancesHeader context) { return InstancesHeader.getAttributeNameString(context, this.attIndex) + " = " + InstancesHeader.getNominalValueString(context, this.attIndex, branch); }
@Override public String describeConditionForBranch(int branch, InstancesHeader context) { if ((branch == 0) || (branch == 1)) { return InstancesHeader.getInputAttributeNameString(context, this.attIndex) + (branch == 0 ? " = " : " != ") + InstancesHeader.getNominalValueString(context, this.attIndex, this.attValue); } throw new IndexOutOfBoundsException(); }
if (newContext.numClasses() < originalContext.numClasses()) { return false; // rule 1 if (newContext.numAttributes() < originalContext.numAttributes()) { return false; // rule 2 while (oPos < originalContext.numAttributes()) { if (oPos == originalContext.classIndex()) { oPos++; if (!(oPos < originalContext.numAttributes())) { break; if (nPos == newContext.classIndex()) { nPos++; if (originalContext.attribute(oPos).isNominal()) { if (!newContext.attribute(nPos).isNominal()) { return false; // rule 4 if (newContext.attribute(nPos).numValues() < originalContext .attribute(oPos).numValues()) { return false; // rule 3 assert (originalContext.attribute(oPos).isNumeric()); if (!newContext.attribute(nPos).isNumeric()) { return false; // rule 4
private void generateHeader() { ArrayList<String> classLabels = new ArrayList(); for (int i = 0; i < 2; i++) { classLabels.add("class" + (i + 1)); } ArrayList<Attribute> attributes = new ArrayList(); for (int i = 0; i < this.numAttsOption.getValue(); i++) { attributes.add(new Attribute("att" + (i + 1), classLabels)); } attributes.add(new Attribute("class", classLabels)); this.streamHeader = new InstancesHeader(new Instances( getCLICreationString(InstanceStream.class), attributes, 0)); this.streamHeader.setClassIndex(this.streamHeader.numAttributes() - 1); }
dataset=(new InstancesHeader(ds)); dataset.setClassIndex(h); System.out.println(""+dataset); System.out.println("classIndex : "+dataset.classIndex()); System.out.println("numClasses : "+dataset.numClasses()); System.out.println("numInstances: "+dataset.numInstances()); System.out.println("numAttribute: "+dataset.numAttributes());
for(int i = 0; i < originalHeader.numAttributes(); i++){ Attribute att = originalHeader.attribute(i); if(att != originalHeader.classAttribute()) { attributes.add(att); if(originalHeader.classIndex() != -1){ attributes.add(originalHeader.attribute(originalHeader.classIndex())); newHeader = new InstancesHeader(format);
@Override public int classIndex() { return instanceInformation.classIndex(); }
@Override public String describeConditionForBranch(int branch, InstancesHeader context) { if ((branch == 0) || (branch == 1)) { char compareChar = branch == 0 ? '<' : '>'; int equalsBranch = this.equalsPassesTest ? 0 : 1; return InstancesHeader.getAttributeNameString(context, this.attIndex) + ' ' + compareChar + (branch == equalsBranch ? "= " : " ") + InstancesHeader.getNumericValueString(context, this.attIndex, this.attValue); } throw new IndexOutOfBoundsException(); }
public void getModelDescription(StringBuilder out, int indent) { StringUtils.appendIndented(out, indent, getClassNameString() + " ="); if (getModelContext() != null) { for (int j = 0; j < getModelContext().numAttributes() - 1; j++) { if (getModelContext().attribute(j).isNumeric()) { out.append((j == 0 || weightAttribute.getValue(j) < 0) ? " " : " + "); out.append(String.format("%.4f", weightAttribute.getValue(j))); out.append(" * "); out.append(getAttributeNameString(j)); } } out.append(" + " + weightAttribute.getValue((getModelContext().numAttributes() - 1))); } StringUtils.appendNewline(out); } }
/** * Helper method to set the model context, i.e. how many attributes they are and what is the class index * @param ih */ private void setModelContext(InstancesHeader ih){ //TODO possibly refactored if ((ih != null) && (ih.classIndex() < 0)) { throw new IllegalArgumentException( "Context for a classifier must include a class to learn"); } //TODO: check flag for checking whether training has started or not //model context is used to describe the model logger.trace("Model context: {}", ih.toString()); }
@Override public Attribute attribute(int instAttIndex) { return this.instanceInformation.attribute(instAttIndex); }
/** * Num classes. * * @return the int */ @Override public int numClasses() { return this.instanceHeader.numClasses(); }
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); } } }
@Override public int numAttributes() { return this.instanceInformation.numAttributes(); }
/** * Gets the name of a label of the class from the header. * * @param classLabelIndex the label index * @return the name of the label of the class */ public String getClassLabelString(int classLabelIndex) { return InstancesHeader.getClassLabelString(this.modelContext, classLabelIndex); }
/** * Gets the name of an attribute from the header. * * @param attIndex the attribute index * @return the name of the attribute */ public String getAttributeNameString(int attIndex) { return InstancesHeader.getAttributeNameString(this.modelContext, attIndex); }
/** * Gets the name of a value of an attribute from the header. * * @param attIndex the attribute index * @param valIndex the value of the attribute * @return the name of the value of the attribute */ public String getNominalValueString(int attIndex, int valIndex) { return InstancesHeader.getNominalValueString(this.modelContext, attIndex, valIndex); }