new GaussianDiscriminantAnalysis(data.getAttributes()) .setDiagonal(false) .setClassName("DiscreteVar0") .setWindowSize(100); gda.updateModel(data); for (DataOnMemory<DataInstance> batch : data.iterableOverBatches(100)) { gda.updateModel(batch); System.out.println(gda.getModel()); System.out.println(gda.getDAG()); d.setValue(gda.getClassVar(), Utils.missingValue()); Multinomial posteriorProb = gda.predict(d); System.out.println(posteriorProb.toString());
@Override public boolean isValidConfiguration(){ boolean isValid = true; long numReal = vars.getListOfVariables().stream() .filter( v -> v.getStateSpaceTypeEnum().equals(StateSpaceTypeEnum.REAL)) .count(); long numFinite = vars.getListOfVariables().stream() .filter( v -> v.getStateSpaceTypeEnum().equals(StateSpaceTypeEnum.FINITE_SET)) .count(); if(numFinite != 1 || numReal != vars.getNumberOfVars()-1) { isValid = false; String errorMsg = "Invalid configuration: wrong number types of variables domains. It should contain 1 discrete variable and the rest shoud be real"; this.setErrorMessage(errorMsg); } return isValid; }
/** * Builds the DAG over the set of variables given with the naive Bayes structure */ @Override protected void buildDAG() { //We create a standard naive Bayes dag = new DAG(vars); dag.getParentSets().stream().filter(w -> !w.getMainVar().equals(classVar)).forEach(w -> w.addParent(classVar)); // if it is not diagonal add the links between the attributes (features) if(!isDiagonal()) { List<Variable> attrVars = vars.getListOfVariables().stream().filter(v -> !v.equals(classVar)).collect(Collectors.toList()); for (int i=0; i<attrVars.size()-1; i++){ for(int j=i+1; j<attrVars.size(); j++) { // Add the links dag.getParentSet(attrVars.get(i)).addParent(attrVars.get(j)); } } } } /*