How to use the pomegranate.BayesianNetwork.from_json function in pomegranate

To help you get started, we’ve selected a few pomegranate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DAI-Lab / SDGym / synthetic_data_benchmark / evaluator / evaluate.py View on Github external
def default_bayesian_likelihood(dataset, trainset, testset, meta):
    struct = glob.glob("data/*/{}_structure.json".format(dataset))
    assert len(struct) == 1
    bn1 = BayesianNetwork.from_json(struct[0])

    trainset_mapped = mapper(trainset, meta)
    testset_mapped = mapper(testset, meta)
    prob = []
    for item in trainset_mapped:
        try:
            prob.append(bn1.probability(item))
        except:
            prob.append(1e-8)
    l1 = np.mean(np.log(np.asarray(prob) + 1e-8))

    bn2 = BayesianNetwork.from_structure(trainset_mapped, bn1.structure)
    prob = []
    for item in testset_mapped:
        try:
            prob.append(bn2.probability(item))
github DAI-Lab / SDGym / sdgym / evaluate.py View on Github external
def _evaluate_bayesian_likelihood(train, test, metadata):
    LOGGER.info('Evaluating using Bayesian Likelihood.')
    structure_json = json.dumps(metadata['structure'])
    bn1 = BayesianNetwork.from_json(structure_json)

    train_mapped = _mapper(train, metadata)
    test_mapped = _mapper(test, metadata)
    prob = []
    for item in train_mapped:
        try:
            prob.append(bn1.probability(item))
        except Exception:
            prob.append(1e-8)

    l1 = np.mean(np.log(np.asarray(prob) + 1e-8))

    bn2 = BayesianNetwork.from_structure(train_mapped, bn1.structure)
    prob = []

    for item in test_mapped:
github fabric8-analytics / fabric8-analytics-stack-analysis / util / data_store / local_filesystem.py View on Github external
def read_pomegranate_model(self, filename):
        """Deserialize the model from the file."""
        with open(os.path.join(self.src_dir, filename), 'rb') as ik:
            model = BayesianNetwork.from_json(pickle.load(ik))
        return model
github replicahq / doppelganger / doppelganger / bayesnets.py View on Github external
def from_json(json_string, segmenter=None):
        """Create BayesianNetworkModel from the given json blob in string format

        Args:
            json_string (unicode): the string created by `from_json`

        Returns:
            BayesianNetworkModel: generative model equivalent to stored model
        """
        json_blob = json.loads(json_string)
        type_to_network = {}
        for type_, network_json in json_blob['type_to_network'].items():
            type_to_network[type_] = BayesianNetwork.from_json(json.dumps(network_json))
        fields = list(json_blob['fieldnames'])
        return BayesianNetworkModel(type_to_network, fields, segmenter)