Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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",
]
8 changes: 3 additions & 5 deletions src/pymaxent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down