Esempio n. 1
0
 def betapdf(x):
     if x.sup < 0 or x.inf >= 1:
         return FInterval(0)
     x = x.clamp(0, 1)
     alpha = FInterval(9.7)
     beta = FInterval(3)
     return (1 - x) ** (alpha) * x ** (beta)
Esempio n. 2
0
 def osciexpo(x, a=1.0 / 8, b=9.0 / 20, c=1.0 / 2):
     axb = a * x ** b
     rt = 1 + c * (axb * (b * FInterval.pi(5)).tan(5)).sin(5)
     ret = (axb).exp(5) * (rt)
     ret = ret.clampleft(0)
     if ret.sup < 0:
         return FInterval(0)
     return ret
Esempio n. 3
0
 def normalroupaving(coord):
     a = normalroupt(
         FInterval(coord[0][0], coord[0][1]), FInterval(coord[1][0], coord[1][1]), 1
     )
     if a.sup < 0:
         return 1
     if a.inf > 0:
         return -1
     return 0
Esempio n. 4
0
 def __init__(self, pdf, mn, mx, numLabels=1, bitAccuracy=53):
     if not isinstance(mn, list):
         mn = [mn]
     if not isinstance(mx, list):
         mx = [mx]
     if len(mn) != len(mx):
         raise ValueError("mn and mx have different lengths")
     # Check whether minimums and maximums are proper
     for i in range(len(mn)):
         if mn[i] >= mx[i]:
             raise ValueError("A minimum is not less than a maximum")
     self.pdf = pdf
     self.bitAccuracy = bitAccuracy
     self.queue = []
     self.boxes = []
     self.weights = []
     self.transdim = numLabels > 1
     for label in range(numLabels):
         box = [FInterval(mn[i], mx[i]) for i in range(len(mn))]
         boxkey, boxrange, boxweight = self._boxInfo(box, label)
         heapq.heappush(self.queue, (boxkey, len(self.boxes)))
         self.boxes.append((box, boxrange, self._boxToISD(box), label))
         self.weights.append(boxweight)
     self._regenTable()
     self.rg = RandomGen()
     self.accepts = 0
     self.totaltrials = 0
Esempio n. 5
0
 def continuous_bernoulli(x, lamda=0.01):
     """
     Reference: Loaiza-Ganem, G., Cunningham, J., "The
     continuous Bernoulli: fixing a pervasive error
     in variational autoencoders", 2019."""
     lamda = FInterval(lamda)  # Parameter in (0, 1)
     return lamda ** x * (1 - lamda) ** (1 - x)
Esempio n. 6
0
 def _bisect(self):
     # Pop the item with the smallest key
     _, boxindex = heapq.heappop(self.queue)
     box, boxrange, _, label = self.boxes[boxindex]
     # Find dimension with the greatest width
     # NOTE: The use of width is not rigorous, but
     # accuracy is not crucial here
     dim = 0
     dimbest = 0
     if len(box) >= 2:
         for i in range(0, len(box)):
             if box[i].width() > dimbest:
                 dimbest = box[i].width()
                 dim = i
     # Split chosen dimension in two
     leftbox = [x for x in box]
     rightbox = [x for x in box]
     fsup = Fraction(box[dim].sup)
     finf = Fraction(box[dim].inf)
     mid = finf + (fsup - finf) / 2
     # Left box
     leftbox[dim] = FInterval(box[dim].inf, mid)
     newBoxIndex = boxindex  # Replace chosen box with left box
     if leftbox[dim].inf != leftbox[dim].sup:
         boxkey, boxrange, boxweight = self._boxInfo(leftbox, label)
         heapq.heappush(self.queue, (boxkey, newBoxIndex))
         self.boxes[newBoxIndex] = (
             leftbox,
             boxrange,
             self._boxToISD(leftbox),
             label,
         )
         self.weights[newBoxIndex] = boxweight
         newBoxIndex = len(self.boxes)  # Add right box
     else:
         # Weight is 0, since the old box was removed
         self.weights[newBoxIndex] = 0
     # Right box
     rightbox[dim] = FInterval(mid, box[dim].sup)
     if rightbox[dim].inf != rightbox[dim].sup:
         boxkey, boxrange, boxweight = self._boxInfo(rightbox, label)
         heapq.heappush(self.queue, (boxkey, newBoxIndex))
         box = (rightbox, boxrange, self._boxToISD(rightbox), label)
         self.boxes.append(box)
         self.weights.append(boxweight)
Esempio n. 7
0
 def normalroupt(u, v, s):
     if v.inf == 0:
         return FInterval(0)
     wid = v.width()
     n = 5
     while wid < 1:
         wid *= 8
         n += 1
     return (u / v) ** 2 + 4 * (v).log(n)
Esempio n. 8
0
 def student_t(x, lam=0.5):
     lam = FInterval(lam)
     return (lam + x * x) ** (-lam / 2 - FInterval(0.5))
Esempio n. 9
0
 def geninvgaussian(x, lamda, chi, psi):
     if x.sup <= 0:
         return FInterval(0)
     ret = x ** (lamda - 1) * (-(chi / x + psi * x) / 2).exp()
     return ret
Esempio n. 10
0
 def _intvsample(self, kx):
     if isinstance(kx, list):
         return [FInterval(v) for v in kx]
     else:
         return FInterval(kx)