/** * BuildCC - Build a CC of chain-order 's' on dataset 'D'. */ protected CC buildCC(int s[], Instances D) throws Exception { // a new classifier chain CC h = new CC(); // build this chain h.prepareChain(s); h.setClassifier(m_Classifier); h.buildClassifier(new Instances(D)); return h; }
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); double y_long[] = Arrays.copyOf(super.distributionForInstance(x),L*2); Arrays.fill(y_long,L,y_long.length,1.0); return y_long; }
/** * Prepare a Chain. Set the specified 'chain'. * It must contain all indices [0,...,L-1] (but in any order) * @param chain a specified chain */ public void prepareChain(int chain[]) { m_Chain = Arrays.copyOf(chain,chain.length); if(getDebug()) System.out.println("Chain s="+Arrays.toString(m_Chain)); }
@Override public void setOptions(String[] options) throws Exception { setSeed(OptionUtils.parse(options, 'S', getDefaultSeed())); super.setOptions(options); }
@Override public double[] distributionForInstance(Instance x) throws Exception { // Start with a good guess int max = Utils.maxIndex(w); double y[] = h[max].distributionForInstance(x); double wm = A.product(h[max].probabilityForInstance(x,y)); for(int t = 0; t < m_Iy; t++) { // m ~ p(m|w) int m = A.samplePMF(w,m_R); // y ~ p(y|x,m) double y_[] = h[m].sampleForInstance(x,m_R); // <-- TODO: can do this faster, see #MCC // w = prod_j p(y[j]|x,m) double w_ = A.product(h[m].getConfidences()); // accept ? if (w_ > wm) { wm = w_; y = y_; } } return y; }
@Override public void buildClassifier(Instances D) throws Exception { testCapabilities(D); int L = D.classIndex(); prepareChain(L); /* * make a classifier node for each label, taking the parents of all previous nodes */ if(getDebug()) System.out.print(":- Chain ("); nodes = new CNode[L]; int pa[] = new int[]{}; for(int j : m_Chain) { if (getDebug()) System.out.print(" "+D.attribute(j).name()); nodes[j] = new CNode(j, null, pa); nodes[j].build(D, m_Classifier); pa = A.append(pa,j); } if (getDebug()) System.out.println(" ) -:"); // to store posterior probabilities (confidences) confidences = new double[L]; }
@Override public Enumeration listOptions() { Vector result = new Vector(); OptionUtils.addOption(result, seedTipText(), "" + getDefaultSeed(), 'S'); OptionUtils.add(result, super.listOptions()); return OptionUtils.toEnumeration(result); }
public EM() { // default classifier for GUI this.m_Classifier = new CC(); }
@Override public String [] getOptions() { List<String> result = new ArrayList<>(); OptionUtils.add(result, 'X', getDependencyType()); OptionUtils.add(result, super.getOptions()); return OptionUtils.toArray(result); }
@Override public Enumeration listOptions() { Vector result = new Vector(); result.addElement(new Option("\tThe way to measure dependencies.\n\tdefault: "+m_DependencyType+" (frequencies only)", "X", 1, "-X <value>")); OptionUtils.add(result, super.listOptions()); return OptionUtils.toEnumeration(result); }
@Override public String [] getOptions() { List<String> result = new ArrayList<>(); OptionUtils.add(result, 'S', getSeed()); OptionUtils.add(result, super.getOptions()); return OptionUtils.toArray(result); }
/** * Description to display in the GUI. * * @return the description */ @Override public String globalInfo() { return "Classifier Chains. " + "For more information see:\n" + getTechnicalInformation().toString(); }
super.buildClassifier(D);
@Override public double[] distributionForInstance(Instance x) throws Exception { // Start with a good guess int max = Utils.maxIndex(w); double y[] = h[max].distributionForInstance(x); double wm = A.product(h[max].probabilityForInstance(x,y)); for(int t = 0; t < m_Iy; t++) { // m ~ p(m|w) int m = A.samplePMF(w,m_R); // y ~ p(y|x,m) double y_[] = h[m].sampleForInstance(x,m_R); // <-- TODO: can do this faster, see #MCC // w = prod_j p(y[j]|x,m) double w_ = A.product(h[m].getConfidences()); // accept ? if (w_ > wm) { wm = w_; y = y_; } } return y; }
@Override public void buildClassifier(Instances D) throws Exception { testCapabilities(D); int L = D.classIndex(); prepareChain(L); /* * make a classifier node for each label, taking the parents of all previous nodes */ if(getDebug()) System.out.print(":- Chain ("); nodes = new CNode[L]; int pa[] = new int[]{}; for(int j : m_Chain) { if (getDebug()) System.out.print(" "+D.attribute(j).name()); nodes[j] = new CNode(j, null, pa); nodes[j].build(D, m_Classifier); pa = A.append(pa,j); } if (getDebug()) System.out.println(" ) -:"); // to store posterior probabilities (confidences) confidences = new double[L]; }
@Override public Enumeration listOptions() { Vector result = new Vector(); OptionUtils.addOption(result, seedTipText(), "" + getDefaultSeed(), 'S'); OptionUtils.add(result, super.listOptions()); return OptionUtils.toEnumeration(result); }
@Override public void setOptions(String[] options) throws Exception { setSeed(OptionUtils.parse(options, 'S', getDefaultSeed())); super.setOptions(options); }
public EM() { // default classifier for GUI this.m_Classifier = new CC(); }
@Override public String [] getOptions() { List<String> result = new ArrayList<>(); OptionUtils.add(result, 'X', getDependencyType()); OptionUtils.add(result, super.getOptions()); return OptionUtils.toArray(result); }
@Override public Enumeration listOptions() { Vector result = new Vector(); result.addElement(new Option("\tThe way to measure dependencies.\n\tdefault: "+m_DependencyType+" (frequencies only)", "X", 1, "-X <value>")); OptionUtils.add(result, super.listOptions()); return OptionUtils.toEnumeration(result); }