Skip to content

penalized_bernoulli

Regularized Bernoulli marginal model.

PenalizedBernoulli(formula, *, penalties=(), device=None)

A Bernoulli marginal with coefficient penalties added to its training loss.

Parameters:

Name Type Description Default
formula dict of str to str, or str

Formula for the logit of the success probability.

required
penalties sequence of CoefficientPenalty

See :mod:scdesigner.distributions.penalties.

()
device device or str
None

Examples:

>>> from scdesigner.distributions.penalties import CoefficientPenalty, QuadraticPenalty
>>> penalty = CoefficientPenalty("mean", ["x"], [1.0], QuadraticPenalty(lam=0.1))
>>> model = PenalizedBernoulli("~ x", penalties=[penalty])
Source code in scdesigner/src/scdesigner/distributions/penalized_bernoulli.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def PenalizedBernoulli(
    formula: Union[Dict[str, str], str],
    *,
    penalties: Sequence[CoefficientPenalty] = (),
    device=None,
) -> Bernoulli:
    """A Bernoulli marginal with coefficient penalties added to its training loss.

    Parameters
    ----------
    formula : dict of str to str, or str
        Formula for the logit of the success probability.
    penalties : sequence of CoefficientPenalty
        See :mod:`scdesigner.distributions.penalties`.
    device : torch.device or str, optional

    Examples
    --------
    >>> from scdesigner.distributions.penalties import CoefficientPenalty, QuadraticPenalty
    >>> penalty = CoefficientPenalty("mean", ["x"], [1.0], QuadraticPenalty(lam=0.1))
    >>> model = PenalizedBernoulli("~ x", penalties=[penalty])
    """
    return Bernoulli(formula, penalties=penalties, device=device)