/** * Method to set the class variable. Note that it should be multinomial * @param className String with the name of the class variable * @throws WrongConfigurationException is thrown when the variable is not a multinomial. */ public T setClassName(String className) throws WrongConfigurationException { setClassVar(vars.getVariableByName(className)); return ((T) this); }
/** * Method to set the class variable. Note that it should be multinomial * @param classVar object of the type {@link Variable} indicating which is the class variable * @throws WrongConfigurationException is thrown when the variable is not a multinomial. */ public T setClassVar(Variable classVar) throws WrongConfigurationException { if(!classVar.isMultinomial()) { setErrorMessage("class variable is not a multinomial"); throw new WrongConfigurationException(errorMessage); } this.classVar = classVar; dag = null; return ((T) this); }
/** * Predicts the class membership probabilities for a given instance. * @param instance the data instance to be classified. The value associated to the class variable must be * a missing value (i.e. a NaN) * @return the posterior probability of the class variable */ public Multinomial predict(DataInstance instance) { if (!Utils.isMissingValue(instance.getValue(classVar))) System.out.println("Class Variable can not be set."); inferenceAlgoPredict.setModel(this.getModel()); this.inferenceAlgoPredict.setEvidence(instance); //System.out.println(instance); this.inferenceAlgoPredict.runInference(); return this.inferenceAlgoPredict.getPosterior(classVar); }