Skip to main content

HomOps Reference

HomPolyThreshold

Approximate a step / Heaviside on encrypted values.

PtPolynomials
RunsServer
Changes shapeNo
Changes scaleYes - grows through the evaluation
Levels spentSeveral - grows with the degree
RotatesNo
KeysSquare key

What it does

HomPolyThreshold approximates a step / Heaviside / threshold with Chebyshev coefficients, then evaluates them through HomPolyEvalBase. Use it for soft decisions on encrypted scores, roughly "is this above the cut?" under CKKS.
Three variants tune the curve: smooth sigmoid, piecewise_linear, or minimax. Like the indicator helper, it is not a separately registered op type; it serializes as PolyEval through the base class.

Signature

HomPolyThreshold(
    degree,             # required: Chebyshev degree
    margin,             # required: transition band, e.g. (0.4, 0.6)
    variant='sigmoid',  # 'sigmoid' | 'piecewise_linear' | 'minimax'
    sharpness=None,     # required when variant is 'sigmoid'
    tol=1e-5,
    out_val=1,
    domain_start=-1,
    plot=False,
    rows_budget=None,
)
Coefficients are generated from degree, margin, variant, and — for sigmoid — required sharpness, then passed to the base evaluator. This constructor does not expose left/right, so the base defaults apply: domain [-1, 1]. No set_data.

Parameters

ParameterTypeDefaultDescription
degreeintrequiredChebyshev degree of the approximation.
marginsequencerequiredTransition band for the step (especially for minimax); e.g. (0.4, 0.6). Always required in the signature, even for non-minimax variants.
variantstr'sigmoid'Curve family: 'sigmoid', 'piecewise_linear', or 'minimax'.
sharpnessint | NoneNoneSigmoid steepness. Required when variant='sigmoid' (the default); omit for the other variants.
tolfloat1e-5Tolerance for coefficient generation and evaluation.
out_valfloat1High value outside the transition for minimax.
domain_startfloat-1Domain start used when building minimax coefficients.
plotboolFalseOptional debug plot when generating coefficients.
rows_budgetsequenceNoneRestricts which levels the internal mod-switches may spend, by absolute row index. See rows_budget.
Variant → coefficient family
variantCurve
'sigmoid'Smooth Heaviside via a sharp sigmoid Chebyshev fit
'piecewise_linear'Piecewise-linear ramp through a short transition interval
'minimax'Minimax threshold shaped by margin, out_val, and domain_start
Rules that depend on the value
SettingRuleIf you break it
domainEvaluation uses the base domain [-1, 1]. Inputs should lie there for a meaningful approximation.Wrong results, not an error.
marginAlways required in the constructor, even when variant is not minimax.Construction fails if omitted.
sharpnessRequired when variant='sigmoid'. Ignored for piecewise_linear and minimax.Construction raises: sharpness must be provided for sigmoid variant.
variantMust be one of 'sigmoid', 'piecewise_linear', or 'minimax'.Unknown variant raises at construction.
rows_budgetAt least one listed row must be droppable at each internal mod-switch.Compilation fails if none are eligible.

Requirements

  • Input in domain. Base domain is [-1, 1] unless you change remap on the underlying leaf (not exposed on this constructor).
  • Square key. Evaluation multiplies ciphertexts; the square key is required (generated during key generation).
  • Level headroom. Grows with degree; verify with the compile-time simulation. See Level budget.

Shape effect - no

The output shape equals the input shape; scalar coefficients are applied element by element.

Scale effect - yes

Same mechanics as HomPolyEvalBase: scale grows through the evaluation and is paid down by internal mod-switches. Check the compiled output scale before planning the next operator.
How scale moves through a pipeline is on Ciphertext state - Scale.

Level budget

Same depth as HomPolyEvalBase for the chosen degree. Optionally pin drops with rows_budget.
How primes are organized in the chain is explained on Level budget - The chain.

Keys

Square key (relinearization key). Required for the ciphertext multiplies inside the Chebyshev evaluation. Generated for you during key generation. No rotation key.

Example

Sigmoid-style threshold after a similarity score:
pipeline.pyPYTHON
from lattica_build.operators import HomPolyThreshold
from lattica_build.base_classes.hom_pipeline import HomomorphicPipeline
from lattica_build.operators.composite.sequential import SequentialHomOp

pipeline = HomomorphicPipeline(
    hom=SequentialHomOp(
        HomPolyThreshold(
            degree=15,
            margin=(0.4, 0.6),
            variant='sigmoid',
            sharpness=8,
            tol=1e-5,
            rows_budget=[3],
        ),
    ),
    input_shape=(128,),
)

See also