cleverly.bases.Tensor#

class cleverly.bases.Tensor(left: Any, right: Any)[source]#

The tensor product of two bases: every product of a column of each.

With both intercepts kept, the product carries the intercept, each basis’s own terms, and their interactions. Tensor(basis, Linear(["A"])) is the basis, the column A and A times every term of the basis.

Parameters:
leftBasis

The first factor.

rightBasis

The second factor.

Methods#

Tensor.evaluate(frame: Any, modifiers: Modifiers | None = None) → ndarray[source]#

The (n, p_left * p_right) design of products.

Parameters:
framedataframe or mapping

Rows holding the modifier columns.

modifiersModifiers, optional

The declared schema.

Returns:
ndarray

The design.

Tensor.named(modifiers: Modifiers | None) → Tensor[source]#

This basis with every level set resolved from modifiers.

Parameters:
modifiersModifiers or None

The declared schema.

Returns:
Tensor

A basis whose terms carry the level names.

Tensor.truncate(k: int) → Tensor[source]#

Both factors cut to min(k, their size).

Parameters:
kint

A size of at least one.

Returns:
Tensor

The truncated basis.

Attributes#

Tensor.basis_kind#

"known" when both factors are.

Tensor.columns#

The modifier columns either factor reads.

Tensor.max_size#

The larger of the factors’ sizes.

Tensor.n_terms#

The number of design columns.

Tensor.terms#

a:b for every pair of terms, the intercept absorbed.

Tensor.left: Any#
Tensor.right: Any#