Skip to content

Commit

Permalink
Added named_arrays.PolynomialFunctionArray
Browse files Browse the repository at this point in the history
  • Loading branch information
byrdie committed Nov 1, 2024
1 parent d02d1a6 commit 0ecbfe9
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions named_arrays/_functions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,66 @@ def __setitem__(
if value_inputs is not None:
self.inputs[item_inputs] = value_inputs
self.outputs[item_outputs] = value_outputs


@dataclasses.dataclass(eq=False, repr=False)
class AbstractPolynomialFunctionArray(
AbstractFunctionArray,
):
@property
@abc.abstractmethod
def coefficients(self) -> na.AbstractVectorArray | na.AbstractMatrixArray:
"""
A vector or matrix representing the coefficients of the polynomial.
If this function is scalar-valued, :attr:`coefficients` should be a vector,
and if this function is vector-valued, :attr`coefficients` should be a matrix.
"""

@property
@abc.abstractmethod
def degree(self) -> int:
"""degree of the polynomial"""

@property
@abc.abstractmethod
def components_polynomial(self):
"""the components of the input that this polynomial depends on"""

@property
@abc.abstractmethod
def axis_polynomial(self):
"""the logical axes along which this polynomial is distributed"""

@abc.abstractmethod
def design_matrix(
self,
inputs: float | u.Quantity | na.AbstractScalar | na.AbstractVectorArray,
) -> na.AbstractVectorArray:
"""
The `design matrix <https://en.wikipedia.org/wiki/Design_matrix>`_
corresponding to the given inputs.
Note that while this is `called` a matrix, this function returns a vector
since the rows are independent observations, and this is concept is
already captured by the logical axes in the array.
Parameters
----------
inputs
the set of independent variables to convert into the design matrix
"""

def __call__(self, inputs: na.ScalarArray | na.AbstractVectorArray):

inputs_self = self.inputs
if not isinstance(inputs_self, na.AbstractVectorArray):
pass

Check warning on line 763 in named_arrays/_functions/functions.py

View check run for this annotation

Codecov / codecov/patch

named_arrays/_functions/functions.py#L761-L763

Added lines #L761 - L763 were not covered by tests

components_inputs = inputs.components
for c in components_inputs:
if components_inputs[c] is None:
pass

Check warning on line 768 in named_arrays/_functions/functions.py

View check run for this annotation

Codecov / codecov/patch

named_arrays/_functions/functions.py#L765-L768

Added lines #L765 - L768 were not covered by tests

index = self.inputs.index(inputs)

Check warning on line 770 in named_arrays/_functions/functions.py

View check run for this annotation

Codecov / codecov/patch

named_arrays/_functions/functions.py#L770

Added line #L770 was not covered by tests

0 comments on commit 0ecbfe9

Please sign in to comment.