/** * Builds the DAG over the set of variables given with the naive Bayes structure */ @Override protected void buildDAG() { dag = new DAG(vars); dag.getParentSets().stream().filter(w -> !w.getMainVar().equals(classVar)).forEach(w -> w.addParent(classVar)); }
/** * 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)); } } } } /*
/** * Builds the DAG over the set of variables given with the structure of the model */ @Override protected void buildDAG() { hiddenVar = vars.newMultinomialVariable("HiddenVar",numStatesHiddenVar); //We create a standard naive Bayes dag = new DAG(vars); dag.getParentSets().stream().filter(w -> !w.getMainVar().equals(hiddenVar)).forEach(w -> w.addParent(hiddenVar)); // if it is not diagonal add the links between the attributes (features) if(!isDiagonal()) { List<Variable> attrVars = vars.getListOfVariables().stream().filter(v -> !v.equals(hiddenVar)).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)); } } } }
/** * This method returns a DAG object with naive Bayes structure for the attributes of the passed data stream. * @param dataStream object of the class DataStream<DataInstance> * @param classIndex integer value indicating the position of the class * @return object of the class DAG */ public static DAG getNaiveBayesStructure(DataStream<DataInstance> dataStream, int classIndex){ //We create a Variables object from the attributes of the data stream Variables modelHeader = new Variables(dataStream.getAttributes()); //We define the predicitive class variable Variable classVar = modelHeader.getVariableById(classIndex); //Then, we create a DAG object with the defined model header DAG dag = new DAG(modelHeader); //We set the linkds of the DAG. dag.getParentSets().stream().filter(w -> w.getMainVar() != classVar).forEach(w -> w.addParent(classVar)); return dag; }
dag.getParentSets() .stream() .filter(w -> w.getMainVar() != classVariable) .forEach(w -> w.addParent(globalHiddenDiscrete)); dag.getParentSets() .stream() .filter(w -> w.getMainVar() != classVariable) .forEach(w -> w.addParent(globalHiddenGaussian)); dag.getParentSets() .stream() .filter(w -> w.getMainVar() != classVariable)
dag.getParentSets() .stream() .filter(w -> w.getMainVar() != classVar) .forEach(w -> w.addParent(globalHiddenVar)); dag.getParentSets() .stream() .filter(w -> w.getMainVar() != classVar) .forEach(w -> w.addParent(globalHiddenGaussian)); dag.getParentSets() .stream() .filter(w -> w.getMainVar() != classVar)
dag.getParentSets() .stream() .filter(w -> w.getMainVar() != classVar) .forEach(w -> w.addParent(globalHiddenVar)); dag.getParentSets() .stream() .filter(w -> w.getMainVar() != classVar) .forEach(w -> w.addParent(globalHiddenGaussian)); dag.getParentSets() .stream() .filter(w -> w.getMainVar() != classVar)
@Override protected void buildDAG() { Variable superParentVar = vars.newMultinomialVariable("superParentVar",getNumStates()); dag = new DAG(vars); dag.getParentSets() .stream() .filter(w -> !w.getMainVar().equals(classVar)) .filter(w -> !w.getMainVar().equals(superParentVar)) .forEach(w -> { w.addParent(classVar); w.addParent(superParentVar); }); dag.getParentSet(superParentVar).addParent(classVar); }
List<EF_ConditionalDistribution> dists = dagLDA.getParentSets().stream() .map(pSet -> pSet.getMainVar().getDistributionType().<EF_ConditionalDistribution>newEFConditionalDistribution(pSet.getParents())) .collect(Collectors.toList());
List<EF_ConditionalDistribution> dists = dagLDA.getParentSets().stream() .map(pSet -> pSet.getMainVar().getDistributionType().<EF_ConditionalDistribution>newEFConditionalDistribution(pSet.getParents())) .collect(Collectors.toList());
dag.getParentSets().stream() .filter(parentSet -> !parentSet.getMainVar().equals(classVar) && !parentSet.getMainVar().getName().startsWith("GaussianSPVar_") && !parentSet.getMainVar().getName().startsWith("DiscreteSPVar"))
dag.getParentSets().stream() .filter(parentSet -> !parentSet.getMainVar().equals(classVar) && !parentSet.getMainVar().getName().startsWith("GaussianSPVar_") && !parentSet.getMainVar().getName().startsWith("DiscreteSPVar"))
dag.getParentSets().stream() .filter(parentSet -> !parentSet.getMainVar().equals(classVar) && !parentSet.getMainVar().getName().startsWith("GaussianSPVar_") && !parentSet.getMainVar().getName().startsWith("DiscreteSPVar"))
dag.getParentSets().parallelStream() .filter(w -> w.getMainVar().getVarID() != clusterVar_.getVarID()) .forEach(w -> w.addParent(clusterVar_)); dag.getParentSets().stream() .filter(w -> w.getMainVar().getVarID() != clusterVar_.getVarID()) .filter(w -> w.getMainVar().isObservable())
@Override public void buildClusterer(Instances data) throws Exception { attributes_ = Converter.convertAttributes(data.enumerateAttributes()); Variables modelHeader = new Variables(attributes_); clusterVar_ = modelHeader.newMultinomialVariable("clusterVar", this.numberOfClusters()); inferenceAlgorithm_ = new ImportanceSampling(); inferenceAlgorithm_.setSeed(this.getSeed()); dag = new DAG(modelHeader); /* Set DAG structure. */ /* Add the hidden cluster variable as a parent of all the predictive attributes. */ dag.getParentSets().stream() .filter(w -> w.getMainVar().getVarID() != clusterVar_.getVarID()) .filter(w -> w.getMainVar().isObservable()) .forEach(w -> w.addParent(clusterVar_)); System.out.println(dag.toString()); parameterLearningAlgorithm_ = new SVB(); parameterLearningAlgorithm_.setDAG(dag); DataOnMemoryListContainer<DataInstance> batch_ = new DataOnMemoryListContainer(attributes_); data.stream().forEach(instance -> batch_.add(new DataInstanceFromDataRow(new DataRowWeka(instance, this.attributes_))) ); parameterLearningAlgorithm_.setDataStream(batch_); parameterLearningAlgorithm_.initLearning(); parameterLearningAlgorithm_.runLearning(); bnModel_ = parameterLearningAlgorithm_.getLearntBayesianNetwork(); System.out.println(bnModel_); inferenceAlgorithm_.setModel(bnModel_); }
dag.getParentSets().parallelStream() .filter(w -> w.getMainVar().getVarID() != targetVar_.getVarID()) .filter(w -> w.getMainVar().isObservable()) dag.getParentSets().stream() .filter(w -> w.getMainVar().getVarID() != targetVar_.getVarID()) .filter(w -> w.getMainVar().isObservable())
dag.getParentSets().parallelStream() .filter(w -> w.getMainVar().getVarID() != classVar_.getVarID()) .filter(w -> w.getMainVar().isObservable()) dag.getParentSets().stream() .filter(w -> w.getMainVar().getVarID() != classVar_.getVarID()) .filter(w -> w.getMainVar().isObservable())
dag.getParentSets().stream() .filter(w -> w.getMainVar().getVarID() != classVar_.getVarID()) .filter(w -> w.getMainVar().isObservable())