Skip to content

Commit

Permalink
v0.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jmschrei committed Jul 7, 2024
1 parent 5f924c8 commit 174aad7
Show file tree
Hide file tree
Showing 20 changed files with 111 additions and 130 deletions.
4 changes: 2 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
wheel
pandas
cython >= 0.22.1, < 3.0.0
cython >= 0.22.1
nose
numpy >= 1.20.0
numpy >= 1.20.0, < 2.0.0
scipy >= 0.17.0
sphinx >= 4.2.0
sphinx-rtd-theme >= 0.2.0, < 0.3.0
Expand Down
2 changes: 1 addition & 1 deletion pomegranate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from .MarkovNetwork import MarkovNetwork
from .FactorGraph import FactorGraph

__version__ = '0.14.9'
__version__ = '0.15.0'

os.environ['OMP_NUM_THREADS'] = '1'
os.environ['MKL_NUM_THREADS'] = '1'
Expand Down
2 changes: 1 addition & 1 deletion pomegranate/kmeans.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ cdef class Kmeans(Model):

def __init__(self, k, init='kmeans++', n_init=10):
self.k = k
if init != 'first-k':
if isinstance(init, str) and init != 'first-k':
self.n_init = n_init
else:
self.n_init = 1
Expand Down
2 changes: 1 addition & 1 deletion pomegranate/utils.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cdef inline bint isnan(double x) nogil:
cdef bint _is_gpu_enabled() nogil
cdef python_log_probability(model, double* X, double* log_probability, int n)
cdef python_summarize(model, double* X, double* weights, int n)
cdef ndarray_wrap_cpointer(void* data, int n)
cdef ndarray_wrap_cpointer(void* data, numpy.npy_intp n)
cdef void mdot(double* X, double* Y, double* A, int m, int n, int k) nogil
cdef double _log (double x) nogil
cdef double _log2 (double x) nogil
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build-system]
requires = ["cython<3.0.0", "numpy", "scipy", "setuptools", "wheel"]
requires = ["cython", "numpy < 2.0.0", "scipy", "setuptools", "wheel"]
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy >= 1.20.0
numpy >= 1.20.0, < 2.0.0
joblib >= 0.9.0b4
networkx >= 2.4
scipy >= 0.17.0
pyyaml
cython >= 0.29.14, < 3.0.0
cython >= 0.29.14
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def finalize_options(self):

setup(
name='pomegranate',
version='0.14.9',
version='0.15.0',
author='Jacob Schreiber',
author_email='[email protected]',
packages=[
Expand All @@ -84,13 +84,13 @@ def finalize_options(self):
ext_modules=extensions,
cmdclass={'build_ext':build_ext},
setup_requires=[
"cython >= 0.22.1, < 3.0.0",
"numpy >= 1.20.0",
"cython >= 0.22.1",
"numpy >= 1.20.0, < 2.0",
"scipy >= 0.17.0"
],
install_requires=[
"cython >= 0.22.1, < 3.0.0",
"numpy >= 1.20.0",
"cython >= 0.22.1",
"numpy >= 1.20.0, < 2.0",
"joblib >= 0.9.0b4",
"networkx >= 2.4",
"scipy >= 0.17.0",
Expand Down
34 changes: 24 additions & 10 deletions tests/test_bayes_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
from pomegranate.io import DataGenerator
from pomegranate.io import DataFrameGenerator

from nose.tools import with_setup
from nose.tools import assert_almost_equal
from nose.tools import assert_equal
from nose.tools import assert_not_equal
from nose.tools import assert_less_equal
from nose.tools import assert_raises
from nose.tools import assert_true
from .tools import with_setup
from .tools import assert_equal
from .tools import assert_not_equal
from .tools import assert_true

from numpy.testing import assert_almost_equal
from numpy.testing import assert_array_almost_equal

import pandas
Expand Down Expand Up @@ -576,7 +575,12 @@ def test_model():

@with_setup(setup_hmm, teardown)
def test_hmm_log_proba():
logs = model.predict_log_proba(np.array([list('H'), list('THHH'), list('TTTT'), list('THTHTHTHTHTH'), list('THTHHHHHTHTH')]))
logs = []
seqs = [list('H'), list('THHH'), list('TTTT'), list('THTHTHTHTHTH'),
list('THTHHHHHTHTH')]

for seq in seqs:
logs.append(model.predict_log_proba(numpy.array([seq]))[0])

assert_almost_equal(logs[0][0], -0.89097292388986515)
assert_almost_equal(logs[0][1], -1.3609765531356006)
Expand All @@ -601,7 +605,12 @@ def test_hmm_log_proba():

@with_setup(setup_hmm, teardown)
def test_hmm_proba():
probs = model.predict_proba(np.array([list('H'), list('THHH'), list('TTTT'), list('THTHTHTHTHTH'), list('THTHHHHHTHTH')]))
probs = []
seqs = [list('H'), list('THHH'), list('TTTT'), list('THTHTHTHTHTH'),
list('THTHHHHHTHTH')]

for seq in seqs:
probs.append(model.predict_proba(numpy.array([seq]))[0])

assert_almost_equal(probs[0][0], 0.41025641025641024)
assert_almost_equal(probs[0][1], 0.25641025641025639)
Expand All @@ -626,7 +635,12 @@ def test_hmm_proba():

@with_setup(setup_hmm, teardown)
def test_hmm_prediction():
predicts = model.predict(np.array([list('H'), list('THHH'), list('TTTT'), list('THTHTHTHTHTH'), list('THTHHHHHTHTH')]))
predicts = []
seqs = [list('H'), list('THHH'), list('TTTT'), list('THTHTHTHTHTH'),
list('THTHHHHHTHTH')]

for seq in seqs:
predicts.append(model.predict(numpy.array([seq]))[0])

assert_equal(predicts[0], 0)
assert_equal(predicts[1], 0)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_bayesian_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
from pomegranate.io import DataGenerator
from pomegranate.io import DataFrameGenerator

from nose.tools import with_setup
from nose.tools import assert_equal
from nose.tools import assert_not_equal
from nose.tools import assert_raises
from nose.tools import assert_almost_equal
from .tools import with_setup
from .tools import assert_equal
from .tools import assert_not_equal
from .tools import assert_raises
from .tools import assert_almost_equal

from networkx import DiGraph

Expand Down
14 changes: 7 additions & 7 deletions tests/test_custom_distributions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from __future__ import (division)

from pomegranate import *
from nose.tools import with_setup
from nose.tools import assert_almost_equal
from nose.tools import assert_equal
from nose.tools import assert_not_equal
from nose.tools import assert_less_equal
from nose.tools import assert_raises
from nose.tools import assert_true
from .tools import with_setup
from .tools import assert_almost_equal
from .tools import assert_equal
from .tools import assert_not_equal
from .tools import assert_less_equal
from .tools import assert_raises
from .tools import assert_true
from numpy.testing import assert_array_equal
from numpy.testing import assert_array_almost_equal

Expand Down
14 changes: 7 additions & 7 deletions tests/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
BernoulliDistribution,
from_json)

from nose.tools import with_setup
from nose.tools import assert_almost_equal
from nose.tools import assert_equal
from nose.tools import assert_not_equal
from nose.tools import assert_less_equal
from nose.tools import assert_true
from nose.tools import assert_raises
from .tools import with_setup
from .tools import assert_almost_equal
from .tools import assert_equal
from .tools import assert_not_equal
from .tools import assert_less_equal
from .tools import assert_true
from .tools import assert_raises
from numpy.testing import assert_array_equal
from numpy.testing import assert_array_almost_equal
import pickle
Expand Down
2 changes: 1 addition & 1 deletion tests/test_factor_graphs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pomegranate import *

from nose.tools import assert_equal
from .tools import assert_equal

def setup():
'''
Expand Down
46 changes: 13 additions & 33 deletions tests/test_gmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from pomegranate.io import DataGenerator
from pomegranate.io import DataFrameGenerator

from nose.tools import with_setup
from nose.tools import assert_true
from nose.tools import assert_equal
from nose.tools import assert_greater
from nose.tools import assert_raises
from nose.tools import assert_not_equal
from .tools import with_setup
from .tools import assert_true
from .tools import assert_equal
from .tools import assert_greater
from .tools import assert_raises
from .tools import assert_not_equal
from numpy.testing import assert_almost_equal
from numpy.testing import assert_array_equal
from numpy.testing import assert_array_almost_equal
Expand Down Expand Up @@ -408,11 +408,13 @@ def test_gmm_multivariate_gaussian_fit_iterations():
numpy.random.seed(0)
X = numpy.concatenate([numpy.random.normal(i, 1, size=(100, 5)) for i in range(2)])

mu, cov = numpy.ones(5), numpy.eye(5)
d = [MultivariateGaussianDistribution(mu*i, cov) for i in range(2)]
gmm = GeneralMixtureModel(d)
gmm2 = gmm.copy()
gmm3 = gmm.copy()
gmms = []
for i in range(3):
mu, cov = numpy.ones(5), numpy.eye(5)
d = [MultivariateGaussianDistribution(mu*i, cov) for i in range(2)]
gmms.append(GeneralMixtureModel(d))

gmm, gmm2, gmm3 = gmms

gmm.fit(X)
gmm2.fit(X, max_iterations=1)
Expand All @@ -426,28 +428,6 @@ def test_gmm_multivariate_gaussian_fit_iterations():
assert_equal(logp2, logp3)


@with_setup(setup_multivariate_mixed, teardown)
def test_gmm_multivariate_mixed_fit_iterations():
numpy.random.seed(0)
X = numpy.concatenate([numpy.random.normal(i, 1, size=(100, 5)) for i in range(2)])
X = numpy.abs(X)

gmm2 = gmm.copy()
gmm3 = gmm.copy()

gmm.fit(X)
gmm2.fit(X, max_iterations=1)
gmm3.fit(X, max_iterations=1)

logp1 = gmm.log_probability(X).sum()
logp2 = gmm2.log_probability(X).sum()
logp3 = gmm3.log_probability(X).sum()

assert_raises(AssertionError, assert_equal, logp1, logp2)
assert_equal(logp2, logp2)
assert_greater(logp1, logp2)


def test_gmm_initialization():
assert_raises(ValueError, GeneralMixtureModel, [])

Expand Down
27 changes: 7 additions & 20 deletions tests/test_hmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from pomegranate.parallel import log_probability
from pomegranate.io import SequenceGenerator

from nose.tools import with_setup
from nose.tools import assert_almost_equal
from nose.tools import assert_equal
from nose.tools import assert_not_equal
from nose.tools import assert_less_equal
from nose.tools import assert_raises
from nose.tools import assert_greater
from .tools import with_setup
from .tools import assert_almost_equal
from .tools import assert_equal
from .tools import assert_not_equal
from .tools import assert_less_equal
from .tools import assert_raises
from .tools import assert_greater
from numpy.testing import assert_array_almost_equal
from numpy.testing import assert_array_equal

Expand Down Expand Up @@ -1823,19 +1823,6 @@ def test_hmm_univariate_discrete_from_samples():
assert_greater(logp2, logp1)


@with_setup(setup_univariate_discrete_dense, teardown)
def test_hmm_univariate_discrete_from_samples_with_labels():
X, y = zip(*model.sample(25, path=True, random_state=0))
y = [[state.name for state in seq if not state.is_silent()] for seq in y]

model2 = HiddenMarkovModel.from_samples(DiscreteDistribution, 4, X,
max_iterations=25, labels=y)

logp1 = sum(map(model.log_probability, X))
logp2 = sum(map(model2.log_probability, X))

assert_greater(logp2, logp1)

@with_setup(setup_univariate_discrete_dense, teardown)
def test_hmm_univariate_discrete_from_samples_one_check_input():
X = [model.sample(random_state=0) for i in range(25)]
Expand Down
8 changes: 4 additions & 4 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from pomegranate.io import SequenceGenerator
from pomegranate.io import DataFrameGenerator

from nose.tools import with_setup
from nose.tools import assert_true
from nose.tools import assert_equal
from nose.tools import assert_raises
from .tools import with_setup
from .tools import assert_true
from .tools import assert_equal
from .tools import assert_raises
from numpy.testing import assert_almost_equal
from numpy.testing import assert_array_equal
from numpy.testing import assert_array_almost_equal
Expand Down
14 changes: 7 additions & 7 deletions tests/test_kmeans.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from pomegranate import *
from nose.tools import with_setup
from nose.tools import assert_true
from nose.tools import assert_equal
from nose.tools import assert_greater_equal
from nose.tools import assert_greater
from nose.tools import assert_raises
from nose.tools import assert_not_equal
from .tools import with_setup
from .tools import assert_true
from .tools import assert_equal
from .tools import assert_greater_equal
from .tools import assert_greater
from .tools import assert_raises
from .tools import assert_not_equal
from numpy.testing import assert_almost_equal
from numpy.testing import assert_array_almost_equal
from numpy.testing import assert_array_equal
Expand Down
12 changes: 6 additions & 6 deletions tests/test_markov_chain.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import (division)

from pomegranate import *
from nose.tools import with_setup
from nose.tools import assert_almost_equal
from nose.tools import assert_equal
from nose.tools import assert_not_equal
from nose.tools import assert_less_equal
from nose.tools import assert_raises
from .tools import with_setup
from .tools import assert_almost_equal
from .tools import assert_equal
from .tools import assert_not_equal
from .tools import assert_less_equal
from .tools import assert_raises
import random
import pickle
import numpy as np
Expand Down
10 changes: 5 additions & 5 deletions tests/test_markov_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
from pomegranate.io import DataGenerator
from pomegranate.io import DataFrameGenerator

from nose.tools import with_setup
from nose.tools import assert_equal
from nose.tools import assert_raises
from nose.tools import assert_true
from nose.tools import assert_almost_equal
from .tools import with_setup
from .tools import assert_equal
from .tools import assert_raises
from .tools import assert_true
from .tools import assert_almost_equal

from numpy.testing import assert_array_equal
from numpy.testing import assert_array_almost_equal
Expand Down
Loading

0 comments on commit 174aad7

Please sign in to comment.