ML (Preprocessing)
bin_feature()¶
Map an encrypted value to its ordinal bucket index.
This cell verifies the bin_feature 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.
from concrete import fhe
from concrete_fhe_toolkit.ml.preprocessing import bin_feature
def test_bin_feature(value):
return bin_feature(value, [2, 4, 6])
compiler = fhe.Compiler(test_bin_feature, {'value': 'encrypted'})
inputset = [(5,)]
circuit = compiler.compile(inputset)
circuit.encrypt_run_decrypt(*inputset[0])
print("bin_feature tests passed! (1/1)")
FHEBinner¶
Demonstrates the FHEBinner class.
This transformer is evaluated in cleartext here. Its FHE compilation is tested automatically when chained inside an FHEPipeline.
from concrete_fhe_toolkit.ml.preprocessing import FHEBinner
binner = FHEBinner([[18, 30, 45, 65], [10, 50]])
res = binner._transform_logic([55, 70])
assert list(res) == [3, 2]
print('FHEBinner logic tested successfully in cleartext! (1/1)')
FHEBinner logic tested successfully in cleartext! (1/1)
FHEStandardScaler¶
Demonstrates the FHEStandardScaler class.
This transformer is evaluated in cleartext here. Its FHE compilation is tested automatically when chained inside an FHEPipeline.
from concrete_fhe_toolkit.ml.preprocessing import FHEStandardScaler
scaler = FHEStandardScaler(means=[50, 100], stds=[10, 20], scale=10)
res = scaler._transform_logic([65, 60])
assert list(res) == [15, -20]
print('FHEStandardScaler logic tested successfully in cleartext! (1/1)')
FHEStandardScaler logic tested successfully in cleartext! (1/1)
FHEMinMaxScaler¶
Demonstrates the FHEMinMaxScaler class.
This transformer is evaluated in cleartext here. Its FHE compilation is tested automatically when chained inside an FHEPipeline.
from concrete_fhe_toolkit.ml.preprocessing import FHEMinMaxScaler
scaler = FHEMinMaxScaler([0, 10], [200, 20], scale=100)
res = scaler._transform_logic([50, 15])
assert list(res) == [25, 50]
print('FHEMinMaxScaler logic tested successfully in cleartext! (1/1)')
FHEMinMaxScaler logic tested successfully in cleartext! (1/1)