From b78170595a7dd8ca10404b63f3b342a58ef55e0e Mon Sep 17 00:00:00 2001 From: Kyle Douglass Date: Tue, 17 Jan 2023 11:19:24 +0100 Subject: [PATCH 1/3] Add pyproject.toml to make project pip installable --- pyproject.toml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b0f0f17 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,18 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "PyMaxEnt" +version = "1.0.0" +authors = [ + {name = "Tony Saad", email = "tony.saad@chemeng.utah.edu"}, + {name = "Giovanna Ruai"}, +] +license = { text = "MIT" } +description = "Implements a maximum entropy reconstruction of distributions with known moments." + +dependencies = [ + "numpy", + "scipy", +] From f7f4713cf6c2cd5b3924ed162a7f3df9735c4732 Mon Sep 17 00:00:00 2001 From: Kyle Douglass Date: Tue, 17 Jan 2023 11:42:57 +0100 Subject: [PATCH 2/3] Fix minor errors in the code and README --- README.md | 2 +- src/pymaxent.py | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ecd417d..1995332 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Below are some examples of using the \MaxEnt software. Starting with an example from pymaxent import * mu = [1,3.5] x = [1,2,3,4,5,6] -sol, lambdas = reconstruct(mu,ivars=x) +sol, lambdas = reconstruct(mu,rndvar=x) ``` Similarly, for a continuous distribution, one passes a list of input moments. diff --git a/src/pymaxent.py b/src/pymaxent.py index 5effc0e..def3d89 100644 --- a/src/pymaxent.py +++ b/src/pymaxent.py @@ -56,7 +56,7 @@ def moments_d(f,k,x): for i in range(0,k): xp = np.power(x,i) # compute x^p xpf = np.dot(xp,f) # compute x^p * f(x) - mom.append(np.sum(xpf)) # compute moment: sum(x^p * f(x)) + moms.append(np.sum(xpf)) # compute moment: sum(x^p * f(x)) return np.array(moms) def moments(f, k, rndvar=None, bnds=None): @@ -101,14 +101,13 @@ def integrand(x, lamb, k=0, discrete=False): else: return x**k * np.exp(np.dot(lamb, xi)) -def residual_d(lamb,x,k,mu): +def residual_d(lamb,x,mu): ''' Calculates the residual of the moment approximation function. Parameters: lamb (array): an array of Lagrange constants used to approximate the distribution x (array): - k (integer): order of the moment mu (array): an array of the known moments needed to approximate the distribution function Returns: @@ -133,8 +132,7 @@ def maxent_reconstruct_d(rndvar, mu): ''' lambguess = np.zeros(len(mu)) lambguess[0] = -np.log(np.sqrt(2*np.pi)) - k = len(mu) - lambsol = fsolve(residual_d, lambguess, args = (rndvar,k,mu)) + lambsol = fsolve(residual_d, lambguess, args = (rndvar,mu)) probabilites = integrand(rndvar, lambsol, k=0, discrete=True) return probabilites, lambsol From 864d51e451c4261240040e1a1ba8b09e4d35070a Mon Sep 17 00:00:00 2001 From: Kyle Douglass Date: Tue, 17 Jan 2023 11:19:24 +0100 Subject: [PATCH 3/3] Add pyproject.toml to make project pip installable --- pyproject.toml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b0f0f17 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,18 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "PyMaxEnt" +version = "1.0.0" +authors = [ + {name = "Tony Saad", email = "tony.saad@chemeng.utah.edu"}, + {name = "Giovanna Ruai"}, +] +license = { text = "MIT" } +description = "Implements a maximum entropy reconstruction of distributions with known moments." + +dependencies = [ + "numpy", + "scipy", +]