/** * GetxfromInstances - Extract attributes as a double x[] from an Instance. */ public static double[] getxfromInstance(Instance xy) { int L = xy.classIndex(); double xy_[] = xy.toDoubleArray(); return Arrays.copyOfRange(xy_,L,xy_.length); }
/** * Instance with L labels to double[] of length L, where L = x.classIndex(). * Rounds to the nearest whole number. */ public static final double[] toDoubleArray(Instance x) { int L = x.classIndex(); return toDoubleArray(x,L); }
/** Clear Labels -- set the value of all label attributes to 0.0 */ public static void clearLabels(Instance x) { int L = x.classIndex(); for(int j = 0; j < L; j++) x.setValue(j,0.0); }
@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; }
public static final double[] toDoubleArray(Instance x) { double y[] = new double[x.classIndex()]; for(int j = 0; j < y.length; j++) { y[j] = x.value(j); } return y; }
@Override public void updateClassifier(Instance x) throws Exception { int L = x.classIndex(); super.updateCount(x,L); }
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); confidences = new double[L]; root.classify(x); double y[] = new double[L*2]; for(int j = 0; j < L; j++) { y[j] = x.value(j); y[j+L] = confidences[j]; // <--- this is the extra line } return y; }
/** * SampleForInstance. * predict y[j] stochastically rather than deterministically (as with distributionForInstance(Instance x)). * @param x test Instance * @param r Random */ public double[] sampleForInstance(Instance x, Random r) throws Exception { int L = x.classIndex(); root.sample(x,r); return MLUtils.toDoubleArray(x); }
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); if (m_Counter < m_Limit) { // return most common combination return mlu.distributionForInstance(x); } else { // return PS prediction return super.distributionForInstance(x); } }
@Override public double[] distributionForInstance(Instance instance) throws Exception { int c = instance.classIndex(); double result[] = new double[c]; Instance finstances[] = convertInstance(instance,c); for (int i = 0; i < c; i++) { result[i] = m_MultiClassifiers[i].classifyInstance(finstances[i]); //result[i] = m_MultiClassifiers[i].distributionForInstance(finstances[i])[1]; } return result; }
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); root.classify(x); return MLUtils.toDoubleArray(x,L); }
@Override public double[] distributionForInstance(Instance instance) throws Exception { int c = instance.classIndex(); double result[] = new double[c]; Instance finstances[] = convertInstance(instance,c); for (int i = 0; i < c; i++) { result[i] = m_MultiClassifiers[i].classifyInstance(finstances[i]); //result[i] = m_MultiClassifiers[i].distributionForInstance(finstances[i])[1]; } return result; }
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); double y[] = new double[L]; for(int j : m_Chain) { // h_j : x,pa_j -> y_j y[j] = nodes[j].classify((Instance)x.copy(),y); } return y; }
@Override public double[] distributionForInstance(Instance TestInstance) throws Exception { int c = TestInstance.classIndex(); //if there is only one class (as for e.g. in some hier. mtds) predict it if(c == 1) return new double[]{1.0}; Instance mlInstance = convertInstance(TestInstance,c); mlInstance.setDataset(m_InstancesTemplate); //Get a classification return convertDistribution(m_Classifier.distributionForInstance(mlInstance),c); }
@Override public void updateClassifier(Instance x) throws Exception { int L = x.classIndex(); for (int j = 0; j < L; j++) { if(x.value(j) > 0.0) { Instance x_j = convertInstance(x); x_j.setClassValue(j); ((UpdateableClassifier)m_Classifier).updateClassifier(x_j); } } }
public static final Instance setTemplate(Instance x, Instances instancesTemplate) { int L = x.classIndex(); int L_t = instancesTemplate.classIndex(); x = (Instance)x.copy(); x.setDataset(null); for (int i = L_t; i < L; i++) x.deleteAttributeAt(0); x.setDataset(instancesTemplate); return x; }
@Override public double[] distributionForInstance(Instance instance) throws Exception { int L = instance.classIndex(); Instance x = F.meka2mulan((Instance)instance.copy(),L); x.setDataset(m_InstancesTemplate); double y[] = m_MULAN.makePrediction(x).getConfidences(); return y; }
@Override public double[] distributionForInstance(Instance mlInstance) throws Exception { int c = mlInstance.classIndex(); //if there is only one class (as for e.g. in some hier. mtds) predict it if(c == 1) return new double[]{1.0}; Instance slInstance = convertInstance(mlInstance,c); slInstance.setDataset(m_InstancesTemplate); //Get a classification double result[] = new double[slInstance.numClasses()]; result[(int)m_Classifier.classifyInstance(slInstance)] = 1.0; return convertDistribution(result,c); }
@Override public double[] distributionForInstance(Instance xy) throws Exception { int L = xy.classIndex(); double z[] = dbm.prob_z(MLUtils.getxfromInstance(xy)); Instance zy = (Instance)m_InstancesTemplate.firstInstance().copy(); MLUtils.setValues(zy,z,L); zy.setDataset(m_InstancesTemplate); return m_Classifier.distributionForInstance(zy); }
@Override public double[] distributionForInstance(Instance xy) throws Exception { int L = xy.classIndex(); double z[] = dbm.prob_z(MLUtils.getxfromInstance(xy)); Instance zy = (Instance)m_InstancesTemplate.firstInstance().copy(); MLUtils.setValues(zy,z,L); zy.setDataset(m_InstancesTemplate); return m_Classifier.distributionForInstance(zy); }