Skip to content

Commit

Permalink
Updated code style to black
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick committed Sep 26, 2024
1 parent 0622223 commit 50473e4
Show file tree
Hide file tree
Showing 11 changed files with 2,167 additions and 1,810 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Testing

on: [push, pull_request]

Expand Down
72 changes: 39 additions & 33 deletions pba/cbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,52 @@
from .pbox import Pbox
else:
from pbox import Pbox

import numpy as np
from matplotlib import pyplot as plt
from typing import List, Tuple, Union

__all__ = ['Cbox']
__all__ = ["Cbox"]


class Cbox(Pbox):
"""
Confidence boxes (c-boxes) are imprecise generalisations of traditional confidence distributions
They have a different interpretation to p-boxes but rely on the same underlying mathematics. As such in pba-for-python c-boxes inhert most of their methods from Pbox.
They have a different interpretation to p-boxes but rely on the same underlying mathematics. As such in pba-for-python c-boxes inhert most of their methods from Pbox.
Args:
Pbox (_type_): _description_
"""
def __init__(self,*args,**kwargs):
if len(args) == 1 and isinstance(args[0],Pbox):
super().__init__(**vars(args[0]))

def __init__(self, *args, **kwargs):
if len(args) == 1 and isinstance(args[0], Pbox):

super().__init__(**vars(args[0]))

else:
super().__init__(*args,**kwargs)

super().__init__(*args, **kwargs)

def __repr__(self):
if self.mean_left == self.mean_right:
mean_text = f'{round(self.mean_left, 4)}'
mean_text = f"{round(self.mean_left, 4)}"
else:
mean_text = f'[{round(self.mean_left, 4)}, {round(self.mean_right, 4)}]'
mean_text = f"[{round(self.mean_left, 4)}, {round(self.mean_right, 4)}]"

if self.var_left == self.var_right:
var_text = f'{round(self.var_left, 4)}'
var_text = f"{round(self.var_left, 4)}"
else:
var_text = f'[{round(self.var_left, 4)}, {round(self.var_right, 4)}]'
var_text = f"[{round(self.var_left, 4)}, {round(self.var_right, 4)}]"

range_text = f'[{round(np.min([self.left, self.right]), 4), round(np.max([self.left, self.right]), 4)}'
range_text = f"[{round(np.min([self.left, self.right]), 4), round(np.max([self.left, self.right]), 4)}"

if self.shape is None:
shape_text = ' '
shape_text = " "
else:
shape_text = f' {self.shape}' # space to start; see below lacking space
shape_text = f" {self.shape}" # space to start; see below lacking space

return f'Cbox: ~ {shape_text} (range={range_text}, mean={mean_text}, var={var_text})'
return f"Cbox: ~ {shape_text} (range={range_text}, mean={mean_text}, var={var_text})"

__str__ = __repr__

Expand All @@ -66,8 +67,8 @@ def __radd__(self, other):
else:
return Cbox(super().__radd__(other))

def add(self,other, method = 'f'):
return Cbox(super().add(other, method = method))
def add(self, other, method="f"):
return Cbox(super().add(other, method=method))

def __sub__(self, other):
if isinstance(other, Cbox):
Expand All @@ -85,8 +86,8 @@ def __rsub__(self, other):
else:
return Cbox(super().__rsub__(other))

def sub(self,other, method = 'f'):
return Cbox(super().sub(other, method = method))
def sub(self, other, method="f"):
return Cbox(super().sub(other, method=method))

def __mul__(self, other):
if isinstance(other, Cbox):
Expand All @@ -104,8 +105,8 @@ def __rmul__(self, other):
else:
return Cbox(super().__rmul__(other))

def mul(self,other, method = 'f'):
return Cbox(super().mul(other, method = method))
def mul(self, other, method="f"):
return Cbox(super().mul(other, method=method))

def __truediv__(self, other):
if isinstance(other, Cbox):
Expand All @@ -123,16 +124,21 @@ def __rtruediv__(self, other):
else:
return Cbox(super().__rtruediv__(other))

def div(self,other, method = 'f'):
return Cbox(super().div(other, method = method))
def div(self, other, method="f"):
return Cbox(super().div(other, method=method))

def __neg__(self):
return Cbox(super().__neg__())

def recip(self):
return Cbox(super().recip())

def singh(cboxes: List[Cbox], theta: Union[float, List[float]], figax: Tuple[plt.Figure, plt.Axes] = None) -> Tuple[plt.Figure, plt.Axes]:


def singh(
cboxes: List[Cbox],
theta: Union[float, List[float]],
figax: Tuple[plt.Figure, plt.Axes] = None,
) -> Tuple[plt.Figure, plt.Axes]:
"""
Generates a singh plot. Create s
Expand All @@ -143,7 +149,7 @@ def singh(cboxes: List[Cbox], theta: Union[float, List[float]], figax: Tuple[plt
Returns:
tuple: A tuple containing the Matplotlib figure and axes objects used for plotting.
"""
x = np.linspace(0, 1, 1001)

Expand All @@ -164,6 +170,6 @@ def singh(cboxes: List[Cbox], theta: Union[float, List[float]], figax: Tuple[plt

ax.plot([0] + list(x) + [1], [0] + left + [1])
ax.plot([0] + list(x) + [1], [0] + right + [1])
ax.plot([0, 1], [0, 1], 'k--', lw=2)
ax.plot([0, 1], [0, 1], "k--", lw=2)

return fig, ax
Loading

0 comments on commit 50473e4

Please sign in to comment.