Skip to content

Commit

Permalink
Fixed mistake in doc. Added is_numeric property for variables
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsch420 committed Aug 27, 2024
1 parent 56db722 commit 9272d4f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/conceptual_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ The complement of a simple event is given by
```{math}
:label: eq-complement-product-sigma-algebra
(A \times B)^c = (A^c \times B) \cup (A \times B) \cup (A \times B^c).
(A \times B)^c = (A^c \times B) \cup (A \times B^c) \cup (A^c \times B^c).
```
{cite}`hunter2011data`
````
Expand Down
24 changes: 23 additions & 1 deletion src/random_events/variable.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from abc import abstractmethod

from typing_extensions import Self, Type, Dict, Any, Union, Optional

from .interval import Interval, SimpleInterval, reals
from .interval import Interval, reals
from .set import Set, SetElement
from .sigma_algebra import AbstractCompositeSet
from .utils import SubclassJSONSerializer
Expand Down Expand Up @@ -49,6 +51,14 @@ def to_json(self) -> Dict[str, Any]:
def _from_json(cls, data: Dict[str, Any]) -> Self:
return cls(data["name"], AbstractCompositeSet.from_json(data["domain"]))

@property
@abstractmethod
def is_numeric(self):
"""
:return: Rather, this variable has a numeric domain or not.
"""
raise NotImplementedError


class Continuous(Variable):
"""
Expand All @@ -61,6 +71,10 @@ class Continuous(Variable):
def __init__(self, name: str, domain=None):
super().__init__(name, reals())

@property
def is_numeric(self):
return True


class Symbolic(Variable):
"""
Expand Down Expand Up @@ -93,6 +107,10 @@ def __init__(self, name: Optional[str] = None, domain: Union[Type[SetElement], S
def domain_type(self) -> Type[SetElement]:
return self.domain.simple_sets[0].all_elements

@property
def is_numeric(self):
return False


class Integer(Variable):
"""
Expand All @@ -104,3 +122,7 @@ class Integer(Variable):

def __init__(self, name: str, domain=None):
super().__init__(name, reals())

@property
def is_numeric(self):
return True

0 comments on commit 9272d4f

Please sign in to comment.