Skip to content

Commit

Permalink
Add initial log2(x) bi-orthogonal DWT variant
Browse files Browse the repository at this point in the history
  • Loading branch information
cgouert committed May 20, 2024
1 parent 06a8c39 commit 4278884
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions data/bior_lut_log_16.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"0": 152, "1": 45, "2": 66, "3": 102, "4": 128, "5": 149, "6": 165, "7": 179, "8": 192, "9": 203, "10": 212, "11": 221, "12": 229, "13": 236, "14": 243, "15": 250, "16": 0, "17": 5, "18": 10, "19": 15, "20": 20, "21": 25, "22": 29, "23": 33, "24": 37, "25": 41, "26": 44, "27": 48, "28": 51, "29": 54, "30": 58, "31": 61, "32": 64, "33": 66, "34": 69, "35": 72, "36": 74, "37": 77, "38": 79, "39": 82, "40": 84, "41": 86, "42": 89, "43": 91, "44": 93, "45": 95, "46": 97, "47": 99, "48": 101, "49": 103, "50": 105, "51": 107, "52": 108, "53": 110, "54": 112, "55": 114, "56": 115, "57": 117, "58": 118, "59": 120, "60": 122, "61": 123, "62": 125, "63": 126, "64": 128, "65": 129, "66": 130, "67": 132, "68": 133, "69": 134, "70": 136, "71": 137, "72": 138, "73": 140, "74": 141, "75": 142, "76": 143, "77": 145, "78": 146, "79": 147, "80": 148, "81": 149, "82": 150, "83": 152, "84": 153, "85": 154, "86": 155, "87": 156, "88": 157, "89": 158, "90": 159, "91": 160, "92": 161, "93": 162, "94": 163, "95": 164, "96": 165, "97": 166, "98": 167, "99": 168, "100": 169, "101": 170, "102": 171, "103": 171, "104": 172, "105": 173, "106": 174, "107": 175, "108": 176, "109": 177, "110": 178, "111": 178, "112": 179, "113": 180, "114": 181, "115": 182, "116": 182, "117": 183, "118": 184, "119": 185, "120": 186, "121": 186, "122": 187, "123": 188, "124": 189, "125": 189, "126": 190, "127": 191, "128": 192, "129": 192, "130": 193, "131": 194, "132": 194, "133": 195, "134": 196, "135": 196, "136": 197, "137": 198, "138": 198, "139": 199, "140": 200, "141": 200, "142": 201, "143": 202, "144": 202, "145": 203, "146": 204, "147": 204, "148": 205, "149": 206, "150": 206, "151": 207, "152": 207, "153": 208, "154": 209, "155": 209, "156": 210, "157": 210, "158": 211, "159": 212, "160": 212, "161": 213, "162": 213, "163": 214, "164": 214, "165": 215, "166": 216, "167": 216, "168": 217, "169": 217, "170": 218, "171": 218, "172": 219, "173": 219, "174": 220, "175": 220, "176": 221, "177": 221, "178": 222, "179": 222, "180": 223, "181": 223, "182": 224, "183": 225, "184": 225, "185": 226, "186": 226, "187": 227, "188": 227, "189": 227, "190": 228, "191": 228, "192": 229, "193": 229, "194": 230, "195": 230, "196": 231, "197": 231, "198": 232, "199": 232, "200": 233, "201": 233, "202": 234, "203": 234, "204": 235, "205": 235, "206": 235, "207": 236, "208": 236, "209": 237, "210": 237, "211": 238, "212": 238, "213": 239, "214": 239, "215": 239, "216": 240, "217": 240, "218": 241, "219": 241, "220": 242, "221": 242, "222": 242, "223": 243, "224": 243, "225": 244, "226": 244, "227": 244, "228": 245, "229": 245, "230": 246, "231": 246, "232": 246, "233": 247, "234": 247, "235": 248, "236": 248, "237": 248, "238": 249, "239": 249, "240": 250, "241": 250, "242": 250, "243": 251, "244": 251, "245": 251, "246": 252, "247": 252, "248": 253, "249": 253, "250": 253, "251": 254, "252": 254, "253": 254, "254": 255, "255": 255}
1 change: 1 addition & 0 deletions data/bior_lut_log_16_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"0": 45, "1": 66, "2": 102, "3": 128, "4": 149, "5": 165, "6": 179, "7": 192, "8": 203, "9": 212, "10": 221, "11": 229, "12": 236, "13": 243, "14": 250, "15": 0, "16": 5, "17": 10, "18": 15, "19": 20, "20": 25, "21": 29, "22": 33, "23": 37, "24": 41, "25": 44, "26": 48, "27": 51, "28": 54, "29": 58, "30": 61, "31": 64, "32": 66, "33": 69, "34": 72, "35": 74, "36": 77, "37": 79, "38": 82, "39": 84, "40": 86, "41": 89, "42": 91, "43": 93, "44": 95, "45": 97, "46": 99, "47": 101, "48": 103, "49": 105, "50": 107, "51": 108, "52": 110, "53": 112, "54": 114, "55": 115, "56": 117, "57": 118, "58": 120, "59": 122, "60": 123, "61": 125, "62": 126, "63": 128, "64": 129, "65": 130, "66": 132, "67": 133, "68": 134, "69": 136, "70": 137, "71": 138, "72": 140, "73": 141, "74": 142, "75": 143, "76": 145, "77": 146, "78": 147, "79": 148, "80": 149, "81": 150, "82": 152, "83": 153, "84": 154, "85": 155, "86": 156, "87": 157, "88": 158, "89": 159, "90": 160, "91": 161, "92": 162, "93": 163, "94": 164, "95": 165, "96": 166, "97": 167, "98": 168, "99": 169, "100": 170, "101": 171, "102": 171, "103": 172, "104": 173, "105": 174, "106": 175, "107": 176, "108": 177, "109": 178, "110": 178, "111": 179, "112": 180, "113": 181, "114": 182, "115": 182, "116": 183, "117": 184, "118": 185, "119": 186, "120": 186, "121": 187, "122": 188, "123": 189, "124": 189, "125": 190, "126": 191, "127": 192, "128": 192, "129": 193, "130": 194, "131": 194, "132": 195, "133": 196, "134": 196, "135": 197, "136": 198, "137": 198, "138": 199, "139": 200, "140": 200, "141": 201, "142": 202, "143": 202, "144": 203, "145": 204, "146": 204, "147": 205, "148": 206, "149": 206, "150": 207, "151": 207, "152": 208, "153": 209, "154": 209, "155": 210, "156": 210, "157": 211, "158": 212, "159": 212, "160": 213, "161": 213, "162": 214, "163": 214, "164": 215, "165": 216, "166": 216, "167": 217, "168": 217, "169": 218, "170": 218, "171": 219, "172": 219, "173": 220, "174": 220, "175": 221, "176": 221, "177": 222, "178": 222, "179": 223, "180": 223, "181": 224, "182": 225, "183": 225, "184": 226, "185": 226, "186": 227, "187": 227, "188": 227, "189": 228, "190": 228, "191": 229, "192": 229, "193": 230, "194": 230, "195": 231, "196": 231, "197": 232, "198": 232, "199": 233, "200": 233, "201": 234, "202": 234, "203": 235, "204": 235, "205": 235, "206": 236, "207": 236, "208": 237, "209": 237, "210": 238, "211": 238, "212": 239, "213": 239, "214": 239, "215": 240, "216": 240, "217": 241, "218": 241, "219": 242, "220": 242, "221": 242, "222": 243, "223": 243, "224": 244, "225": 244, "226": 244, "227": 245, "228": 245, "229": 246, "230": 246, "231": 246, "232": 247, "233": 247, "234": 248, "235": 248, "236": 248, "237": 249, "238": 249, "239": 250, "240": 250, "241": 250, "242": 251, "243": 251, "244": 251, "245": 252, "246": 252, "247": 253, "248": 253, "249": 253, "250": 254, "251": 254, "252": 254, "253": 255, "254": 255, "255": 0}
34 changes: 31 additions & 3 deletions src/primitive_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ fn main() {
start.elapsed().as_secs_f64()
);

let x = quantize(4.0, precision, bit_width as u8);
let x = quantize(2.0, precision, bit_width as u8);
let x_ct = client_key.encrypt(x);
let y_ct = client_key.encrypt(2_u64.pow(bit_width as u32) - 5_u64);
// let y_ct = client_key.encrypt(5_u64);
Expand Down Expand Up @@ -531,15 +531,43 @@ fn main() {
let lut_log_quant: u64 = client_key.decrypt(&log_ct_quant);
println!("log2(x) (Quantized LUT) time: {:?}", lut_time_quant);

let (lsb_1, _msb_1) = bior(
"./data/bior_lut_log_16.json",
wave_depth as u8,
bit_width as u8,
);
let (lsb_2, _msb_2) = bior(
"./data/bior_lut_log_16_2.json",
wave_depth as u8,
bit_width as u8,
);
let luts = vec![&lsb_1, &lsb_2];

// 3.4 log2(x) using Biorthogonal
let (log_ct_bior, lut_time_bior) = ct_lut_eval_bior(
x_ct.clone(),
bit_width,
nb_blocks,
&luts,
wave_depth,
&wopbs_key,
0_i32,
&server_key,
);
let lut_log_bior: u64 = client_key.decrypt(&log_ct_bior);
println!("log2(x) (Bior LUT) time: {:?}", lut_time_bior);

println!(
"--- LUT: {:?}, DWT LUT: {:?}, Quant LUT: {:?},\
\n--- unq: LUT: {:?}, DWT LUT: {:?}, Quant LUT {:?}",
"--- LUT: {:?}, DWT LUT: {:?}, Quant LUT: {:?}, Bior LUT: {:?}\
\n--- unq: LUT: {:?}, DWT LUT: {:?}, Quant LUT {:?}, Bior LUT: {:?}",
lut_log,
dwt_lut_log,
lut_log_quant,
lut_log_bior,
unquantize(lut_log, precision, bit_width as u8),
unquantize(dwt_lut_log, precision, bit_width as u8),
unquantize(lut_log_quant, precision, bit_width as u8),
unquantize(lut_log_bior, precision, bit_width as u8),
);

// // 4.1 sigmoid(x) using LUT
Expand Down

0 comments on commit 4278884

Please sign in to comment.