Skip to main content

← HomOps Reference

HomPolyIndicator

Soft one-hot / bin membership on encrypted values.

PiPolynomials
RunsServer
Changes shapeYes - prepends a num_bins batch dim
Changes scaleYes - grows through the evaluation
Levels spentSeveral - grows with the degree
RotatesNo
KeysSquare key

What it does​

HomPolyIndicator builds packed Chebyshev indicator coefficients for num_bins bins and evaluates them through HomPolyEvalBase. The output prepends a num_bins batch dimension: one soft indicator channel per bin.
Reach for it when you need soft one-hot / bin membership on encrypted scalars or vectors, for example similarity or search pipelines that threshold scores into discrete bins.
It is not a separately registered op type: it serializes as PolyEval through the base class. Default domain is [0, 1], unlike the base default of [-1, 1].

Signature​

HomPolyIndicator(
    degree,             # required: Chebyshev degree
    num_bins,           # required: packed indicator channels
    left=0,
    right=1,
    tol=1e-8,
    plot=False,
    rows_budget=None,
)
Coefficients are generated from degree and num_bins, then passed to the base evaluator. No set_data.

Parameters​

ParameterTypeDefaultDescription
degreeintrequiredChebyshev degree of each packed indicator.
num_binsintrequiredNumber of packed indicator functions / output batch size.
left, rightint0, 1The input domain, passed through to HomPolyEvalBase. Default is [0, 1].
tolfloat1e-8Tolerance used when generating coefficients and during evaluation.
plotboolFalseOptional debug plot when generating coefficients.
rows_budgetsequenceNoneRestricts which levels the internal mod-switches may spend, by absolute row index. See rows_budget.
Rules that depend on the value
SettingRuleIf you break it
left, rightInputs must lie inside [left, right] (default [0, 1]). Values outside the domain make the approximation meaningless.Wrong results, not an error.
num_bins, degreeCoefficient shape is typically (num_bins, degree+1); the output prepends num_bins to the input shape.-
degree / keysLevel cost and square-key requirement match HomPolyEvalBase.-
rows_budgetAt least one listed row must be droppable at each internal mod-switch.Compilation fails if none are eligible.

Requirements​

  • Input in domain. Values should lie in [left, right] (default [0, 1]).
  • Square key. Evaluation multiplies ciphertexts; the square key is required (generated during key generation).
  • Level headroom. High for large degree; verify with the compile-time simulation. See Level budget.

Shape effect - yes​

Rule: prepend num_bins to the tensor shape.
StageShape
Input(N,)
After HomPolyIndicator(num_bins, N)

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: optional domain remap, then direct or Paterson–Stockmeyer evaluation. 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​

Four soft bins over the default unit interval:
pipeline.pyPYTHON
from lattica_build.operators import HomPolyIndicator
from lattica_build.base_classes.hom_pipeline import HomomorphicPipeline
from lattica_build.operators.composite.sequential import SequentialHomOp

pipeline = HomomorphicPipeline(
    hom=SequentialHomOp(
        HomPolyIndicator(
            degree=15,
            num_bins=4,
            left=0,
            right=1,
            rows_budget=[3],
        ),
    ),
    input_shape=(128,),
)

See also​