/** {@inheritDoc} */ @Override public BayesianNetwork getLearntBayesianNetwork() { // Normalize the sufficient statistics SufficientStatistics normalizedSS = efBayesianNetwork.createZeroSufficientStatistics(); normalizedSS.copy(sumSS); normalizedSS.divideBy(dataInstanceCount.get()); efBayesianNetwork.setMomentParameters(normalizedSS); return efBayesianNetwork.toBayesianNetwork(dag); }
/** {@inheritDoc} */ @Override public void runLearning() { this.initLearning(); efBayesianNetwork = new EF_BayesianNetwork(dag); Stream<DataInstance> stream = null; if (parallelMode) { stream = dataStream.parallelStream(batchSize); } else { stream = dataStream.stream(); } dataInstanceCount = new AtomicDouble(0); sumSS = stream .peek( w -> { dataInstanceCount.getAndAdd(1.0); }) .map(efBayesianNetwork::getSufficientStatistics) .reduce( efBayesianNetwork.createZeroSufficientStatistics(), SufficientStatistics::sumVector); }
public boolean equal_efBN(EF_BayesianNetwork ef_bayesianNetwork, double threshold) { for (EF_ConditionalDistribution this_dist : this.getDistributionList()) { EF_ConditionalDistribution ef_dist = ef_bayesianNetwork.getDistribution(this_dist.getVariable()); if (!this_dist.getClass().getName().equals(ef_dist.getClass().getName())) return false; List<Variable> this_Vars = this_dist.getConditioningVariables(); List<Variable> ef_Vars = ef_dist.getConditioningVariables(); if (this_Vars.size() != ef_Vars.size()) return false; for (Variable var : this_Vars) { if (!ef_Vars.contains(var)) return false; } } return this.getNaturalParameters() .equalsVector(ef_bayesianNetwork.getNaturalParameters(), threshold); }
/** {@inheritDoc} */ @Override public void initLearning() { dataInstanceCount = new AtomicDouble(0); efBayesianNetwork = new EF_BayesianNetwork(dag); sumSS = efBayesianNetwork.createZeroSufficientStatistics(); }