Skip to content

Commit

Permalink
Nonsubstantive code edits
Browse files Browse the repository at this point in the history
  • Loading branch information
peteroupc committed Nov 3, 2024
1 parent 78e0df1 commit 65efddb
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 219 deletions.
141 changes: 0 additions & 141 deletions betadist.py

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion binomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
realIsLess,
)


class BinomialSampler:
def __init__(self, rg=None):
self.rg = randomgen.RandomGen() if rg == None else rg
Expand Down
2 changes: 0 additions & 2 deletions fixed.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import decimal as dec
import math


class Fixed:
"""
Fixed-point numbers, represented using integers that store multiples
Expand Down Expand Up @@ -758,7 +757,6 @@ def __str__(self):
def __repr__(self):
return str(dec.Decimal(self.value) / dec.Decimal((1 << Fixed.BITS)))


if __name__ == "__main__":

def asserteq(a, b):
Expand Down
4 changes: 0 additions & 4 deletions interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# precision in bits.
#


class FInterval:
"""An interval of two Fractions. x.sup holds the upper bound, and x.inf holds
the lower bound."""
Expand Down Expand Up @@ -344,7 +343,6 @@ def cos(self, precision):
def __repr__(self):
return "[%s, %s]" % (float(self.inf), float(self.sup))


def _polynomialProduct(a, b):
# Finds the product of two polynomials. Each polynomial
# is a list of the following form:
Expand All @@ -356,15 +354,13 @@ def _polynomialProduct(a, b):
ret[i + j] += a[i] * b[j]
return ret


def _polynomialProductA(a, b0, b1):
ret = [0 for i in range(len(a) + 1)]
for i in range(len(a)):
ret[i] += a[i] * b0 # b0 is 0th-order coefficient
ret[i + 1] += a[i] * b1 # b1 is 1st-order coefficient
return ret


def _polynomialIntegral(p, x=1):
# Finds the integral of a polynomial at the point x.
if x == 1:
Expand Down
7 changes: 0 additions & 7 deletions keaneobrien.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from sympy import *
import random


def roughmaxiopen(func, x):
# Rough version of maxiopen that samples points
# in the open interval (0, 1) to find an approximate
Expand All @@ -10,7 +9,6 @@ def roughmaxiopen(func, x):
*[ceiling(func.subs(x, S(i) / 100) * 100000) / 100000 for i in range(1, 100)]
)


def maxi(func, x):
# Finds the maximum of a function whose domain is [0,1].
# Unfortunately, SymPy's 'maximum' does not always work
Expand All @@ -22,7 +20,6 @@ def maxi(func, x):
# func=target function; x=variable used in 'func'
return maximum(func, x, Interval(0, 1))


def maxiopen(func, x):
# Finds the maximum of a function whose domain is (0,1).
# Unfortunately, SymPy's 'maximum' does not always work
Expand All @@ -34,7 +31,6 @@ def maxiopen(func, x):
# func=target function; x=variable used in 'func'
return maximum(func, x, Interval.open(0, 1))


def bernpoly(a, x):
# Create a polynomial in Bernstein form using the given
# array of coefficients and the symbol x. The polynomial's
Expand All @@ -49,7 +45,6 @@ def bernpoly(a, x):
ret += a[i] * bino * pt**i * (1 - pt) ** (n - i)
return ret


def kobevents(func, p, numpolys=12):
# Generates 'func', a Bernoulli factory function,
# as a convex combination of polynomials
Expand Down Expand Up @@ -150,7 +145,6 @@ def kobevents(func, p, numpolys=12):
# plot(*[r[2] for r in results], (p, 0, 1))
return fevents


def kob(fevents, p):
# Simulates a convex combination of polynomials
# returned by kobevents, which will generally be an
Expand All @@ -166,7 +160,6 @@ def kob(fevents, p):
s = sum(1 if random.random() < p else 0 for i in range(len(fevents[geo]) - 1))
return fevents[geo][s]


p = symbols("p") # Variable used in the example function
# Example function
ofunc = sin(2 * pi * p) / 4 + S.Half + S(1) / 100
Expand Down
11 changes: 0 additions & 11 deletions logconcave.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import math
import random


class TConcaveDiscreteSampler:
"""
Generates a random variate that follows a
Expand Down Expand Up @@ -100,7 +99,6 @@ def codegen(self, name, pdfcall=None):
ret += " if u*u <= %s(ret): return ret\n\n" % (pdfcall)
return ret


class TConcaveSampler:
"""
Generates a random variate that follows a
Expand Down Expand Up @@ -232,7 +230,6 @@ def _simplesampleOne(self):
if u * u <= self.f(ret):
return ret


class LogConcaveSampler:
"""
Generates a random variate that follows a distribution
Expand Down Expand Up @@ -357,7 +354,6 @@ def sampleOne(self):
elif logchi <= pr:
return ret


class UnimodalSampler:
"""
Generates a random variate that follows a unimodal distribution
Expand Down Expand Up @@ -433,7 +429,6 @@ def sampleOne(self):
self.mode, self.mode + 1, self.modecdf, self.modecdfright
)


class LogConcaveSampler2:
"""
Generates a random variate that follows a distribution
Expand Down Expand Up @@ -490,7 +485,6 @@ def sampleOne(self):
if ret != None:
return ret


class LogConcaveSamplerMonotone:
"""
Generates a random variate that follows a distribution
Expand Down Expand Up @@ -668,7 +662,6 @@ def sampleOne(self):
if ret != None:
return ret


class NormalDist:
def __init__(self, mu=0, sigma=1):
psi = lambda x: -(x * x) / (2 * sigma * sigma)
Expand All @@ -678,7 +671,6 @@ def __init__(self, mu=0, sigma=1):
def sample(self, n):
return [x + self.mu for x in self.sampler.sample(n)]


class GenInvGaussianAlphaBeta:
def __init__(self, lamda, alpha, beta):
# Three-parameter version (Hörmann, W., Leydold, J.,
Expand All @@ -697,7 +689,6 @@ def fromLambdaPsiChi(lamda, psi, chi):
lamda, math.sqrt(psi / chi), math.sqrt(psi * chi)
)


class GammaDist:
# Devroye 2014
def __init__(self, a):
Expand All @@ -722,7 +713,6 @@ def sample(self, n):
for x in self.sampler.sample(n)
]


class GenInvGaussian:
def __init__(self, lamda, omega):
# omega>0, lamda>=0. Two-parameter version described in Devroye 2014
Expand All @@ -741,7 +731,6 @@ def _trans(self, v):
def sample(self, n):
return [self._trans(x) for x in self.sampler.sample(n)]


if __name__ == "__main__":

def bucket(v, ls, buckets):
Expand Down
Loading

0 comments on commit 65efddb

Please sign in to comment.