public BayesianNetwork getModel(){ if (learningAlgorithm !=null){ return this.learningAlgorithm.getLearntBayesianNetwork(); } if (learningAlgorithmFlink!=null) return this.learningAlgorithmFlink.getLearntBayesianNetwork(); return null; }
public BayesianNetwork getModel(){ if (learningAlgorithm !=null){ this.learningAlgorithm.setDAG(plateauLDA.getDagLDA()); return this.learningAlgorithm.getLearntBayesianNetwork(); } if (learningAlgorithmFlink!=null) { this.learningAlgorithmFlink.setDAG(plateauLDAFlink.getDagLDA()); return this.learningAlgorithmFlink.getLearntBayesianNetwork(); } return null; }
public static void main(String[] args) throws Exception { //We can open the data stream using the static class DataStreamLoader DataStream<DataInstance> data = DataStreamLoader.open("datasets/simulated/WasteIncineratorSample.arff"); //We create a ParameterLearningAlgorithm object with the MaximumLikehood builder ParameterLearningAlgorithm parameterLearningAlgorithm = new ParallelMaximumLikelihood(); //We fix the DAG structure parameterLearningAlgorithm.setDAG(getNaiveBayesStructure(data,0)); //We should invoke this method before processing any data parameterLearningAlgorithm.initLearning(); //Then we show how we can perform parameter learnig by a sequential updating of data batches. for (DataOnMemory<DataInstance> batch : data.iterableOverBatches(100)){ parameterLearningAlgorithm.updateModel(batch); } //And we get the model BayesianNetwork bnModel = parameterLearningAlgorithm.getLearntBayesianNetwork(); //We print the model System.out.println(bnModel.toString()); }
public <E extends UnivariateDistribution> E getPosteriorDistribution(String varName) { if (learningAlgorithm !=null){ return (E)this.learningAlgorithm.getLearntBayesianNetwork() .getConditionalDistribution(dag.getVariables().getVariableByName(varName)); } else if (learningAlgorithmFlink != null ){ return (E)this.learningAlgorithmFlink.getLearntBayesianNetwork() .getConditionalDistribution(dag.getVariables().getVariableByName(varName)); } return null; }
/** * Updates the classifier with the given instance. * * @param instance the new training instance to include in the model * @exception Exception if the instance could not be incorporated in the * model. */ public void updateClassifier(Instance instance) throws Exception { DataOnMemoryListContainer<DataInstance> batch_ = new DataOnMemoryListContainer(attributes_); batch_.add(new DataInstanceFromDataRow(new DataRowWeka(instance, this.attributes_))); parameterLearningAlgorithm_.updateModel(batch_); bnModel_ = parameterLearningAlgorithm_.getLearntBayesianNetwork(); inferenceAlgorithm_.setModel(bnModel_); }
/** * Updates the classifier with the given instance. * * @param instance the new training instance to include in the model * @exception Exception if the instance could not be incorporated in the * model. */ public void updateClassifier(Instance instance) throws Exception { DataOnMemoryListContainer<DataInstance> batch_ = new DataOnMemoryListContainer(attributes_); batch_.add(new DataInstanceFromDataRow(new DataRowWeka(instance, this.attributes_))); parameterLearningAlgorithm_.updateModel(batch_); bnModel_ = parameterLearningAlgorithm_.getLearntBayesianNetwork(); inferenceAlgorithm_.setModel(bnModel_); }
@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_); }
parameterLearningAlgorithm_.runLearning(); bnModel_ = parameterLearningAlgorithm_.getLearntBayesianNetwork();
bnModel_ = parameterLearningAlgorithm_.getLearntBayesianNetwork();
/** * {@inheritDoc} */ @Override public void trainOnInstanceImpl(Instance instance) { DataInstance dataInstance = new DataInstanceFromDataRow(new DataRowWeka(instance, this.attributes_)); if(batch_.getNumberOfDataInstances() < getBatchSize_()-1) { //store batch_.add(dataInstance); }else{ //store & learn batch_.add(dataInstance); if(bnModel_==null) { //parameterLearningAlgorithm_.setParallelMode(isParallelMode_()); parameterLearningAlgorithm_.setDAG(dag); parameterLearningAlgorithm_.initLearning(); parameterLearningAlgorithm_.updateModel(batch_); }else{ parameterLearningAlgorithm_.updateModel(batch_); } bnModel_ = parameterLearningAlgorithm_.getLearntBayesianNetwork(); predictions_.setModel(bnModel_); batch_ = new DataOnMemoryListContainer(attributes_); } }
/** * {@inheritDoc} */ @Override public void trainOnInstanceImpl(Instance instance) { DataInstance dataInstance = new DataInstanceFromDataRow(new DataRowWeka(instance, this.attributes_)); if(batch_.getNumberOfDataInstances() < getBatchSize_()-1) { //store batch_.add(dataInstance); }else{ //store & learn batch_.add(dataInstance); if(bnModel_==null) { //parameterLearningAlgorithm_.setParallelMode(isParallelMode_()); parameterLearningAlgorithm_.setDAG(dag); parameterLearningAlgorithm_.initLearning(); parameterLearningAlgorithm_.updateModel(batch_); }else{ parameterLearningAlgorithm_.updateModel(batch_); } bnModel_ = parameterLearningAlgorithm_.getLearntBayesianNetwork(); predictions_.setModel(bnModel_); batch_ = new DataOnMemoryListContainer(attributes_); } }
bnModel_ = parameterLearningAlgorithm_.getLearntBayesianNetwork(); predictions_.setModel(bnModel_);