MRFTerm

Contents

MRFTerm#

class liesel_gam.MRFTerm(basis, penalty, scale, name='', inference=None, coef_name=None, _update_on_init=True, validate_scalar_scale=True)[source]#

Bases: StrctTerm

Term object for Markov random fields.

Derived from StrctTerm, with a few additional attributes that give access to information about the Markov random field setup.

Examples

MRFTerm objects are usually created by TermBuilder, which also attaches label and neighborhood metadata.

>>> import pandas as pd
>>> import liesel_gam as gam
>>> df = pd.DataFrame({"region": ["a", "b", "a"]})
>>> term = gam.TermBuilder.from_df(df).mrf(
...     "region",
...     nb={"a": ["b"], "b": ["a"]},
...     absorb_cons=False,
...     diagonal_penalty=False,
...     scale_penalty=False,
...     scale=1.0,
... )
>>> term.neighbors
{'a': ['b'], 'b': ['a']}
>>> term.labels
['a', 'b']

Attributes

labels

Region labels.

mapping

A label-integer mapping for the regions in this term.

neighbors

Dictionary of neighborhood structure (if available).

ordered_labels

Ordered labels, if they are available.

polygons

Dictionary of arrays.