From b2419f6cd819ff1419facedb31ac7efd56255018 Mon Sep 17 00:00:00 2001 From: David Hadka Date: Tue, 10 Sep 2024 21:04:35 +0000 Subject: [PATCH] Add documentation --- rhodium/decorators.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/rhodium/decorators.py b/rhodium/decorators.py index 4903008..3df6afd 100644 --- a/rhodium/decorators.py +++ b/rhodium/decorators.py @@ -24,6 +24,20 @@ LogNormalUncertainty, Direction class UnnamedObject(metaclass=ABCMeta): + """Base class for model components not yet assigned a name. + + Rhodium has the concept of a `NamedObject`, which simply means a name is + associated with an object, typically one of Rhodium's classes like `Lever` + or `Uncertainty`. But when using decorators to construct a model, the + name is derived from the keyword arguments to a function, which are not + known until we can inspect the function. Thus, this class represents the + `NamedObject` before it is assigned a name. + + Parameters + ---------- + constructor : Callable + The constructor that converts this unnamed object into a named object + """ def __init__(self, constructor, *args, **kwargs): self.constructor = constructor @@ -34,31 +48,37 @@ def convert(self, name): return self.constructor(name, *self.args, **self.kwargs) class Real(UnnamedObject): + """Construct a `RealLever` using the decorator approach.""" def __init__(self, *args, **kwargs): super().__init__(RealLever, *args, **kwargs) class Integer(UnnamedObject): + """Construct a `IntegerLever` using the decorator approach.""" def __init__(self, *args, **kwargs): super().__init__(IntegerLever, *args, **kwargs) class Categorical(UnnamedObject): + """Construct a `CategoricalLever` using the decorator approach.""" def __init__(self, *args, **kwargs): super().__init__(CategoricalLever, *args, **kwargs) class Permutation(UnnamedObject): + """Construct a `PermutationLever` using the decorator approach.""" def __init__(self, *args, **kwargs): super().__init__(PermutationLever, *args, **kwargs) class Subset(UnnamedObject): + """Construct a `SubsetLever` using the decorator approach.""" def __init__(self, *args, **kwargs): super().__init__(SubsetLever, *args, **kwargs) class Uniform(float, UnnamedObject): + """Construct a `UniformUncertainty` using the decorator approach.""" def __init__(self, *args, **kwargs): super().__init__(UniformUncertainty, *args, **kwargs) @@ -67,6 +87,7 @@ def __new__(cls, *args, **kwargs): return float.__new__(cls, kwargs.get("default_value", float("NaN"))) class Normal(float, UnnamedObject): + """Construct a `NormalUncertainty` using the decorator approach.""" def __init__(self, *args, **kwargs): super().__init__(NormalUncertainty, *args, **kwargs) @@ -75,6 +96,7 @@ def __new__(cls, *args, **kwargs): return float.__new__(cls, kwargs.get("default_value", float("NaN"))) class LogNormal(float, UnnamedObject): + """Construct a `LogNormalUncertainty` using the decorator approach.""" def __init__(self, *args, **kwargs): super().__init__(LogNormalUncertainty, *args, **kwargs)