ML (Clustering)
inertia()¶
Sum of squared distances from each sample to its nearest centroid.
This cell verifies the inertia function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
In [ ]:
Copied!
from concrete import fhe
from concrete_fhe_toolkit.ml.clustering import inertia
def test_inertia(features):
return inertia(features, [[0, 0], [1, 1]], max_distance=100)
compiler = fhe.Compiler(test_inertia, {'features': 'encrypted'})
inputset = [([[1, 1], [0, 0]],)]
circuit = compiler.compile(inputset)
circuit.encrypt_run_decrypt(*inputset[0])
print("inertia tests passed! (1/1)")
from concrete import fhe
from concrete_fhe_toolkit.ml.clustering import inertia
def test_inertia(features):
return inertia(features, [[0, 0], [1, 1]], max_distance=100)
compiler = fhe.Compiler(test_inertia, {'features': 'encrypted'})
inputset = [([[1, 1], [0, 0]],)]
circuit = compiler.compile(inputset)
circuit.encrypt_run_decrypt(*inputset[0])
print("inertia tests passed! (1/1)")