Problems when implementing different probability distributions
Closed this issue · 2 comments
Hello M.Keller and other MP-SPDZ users.
I have been recently been implementing some probability distributions on MP-SPDZ, such as Laplace distribution or Gaussian distribution, and I have questions regarding data types but also about the correctness of some of the math functions of MP-SPDZ.
On a code block to calculate a sigma value on for applying later to a Gaussian distribution like:
sensitivity = sfloat(1.00)
epsilon = sfloat(1.00)
delta = sfloat(0.00001) # 10e-5
## Calculate sigma
sigma = sfloat(sensitivity * Compiler.mpc_math.sqrt(sfix(2.000) * Compiler.mpc_math.log_fx(sfloat(1.250)/delta, 2.71828))) / epsilon
I am experiencing, first of all, a difference on the output I receive from the same calculation on MP-SPDZ (using secret values and the mpc_math library) than what I do in Python. Being the correct result for this case: Sigma: 4.34361 and I am getting values such as 4.84442 or 4.84549, but not the same value consistently and not the one that the computation is supposed to ouput. Sometimes getting also big numbers such as: 2.86887e+23 while playing with the data types. My guess is that both, the difference on the correct result and the big outputs come from my error not understanding the sfix type or doing an incorrect use of some of the mpc_math functions.
So, I wanted to ask about 2 things:
- When to use one data type or another as well as the difference between them (sfix and sfloat). As for now I am just using what the functions have to get when I can check the documentation and choosing just by intuition for any other value.
- Is this difference on my results on sigma something expectable or am I doing something wrong?
Thanks in advance!
- I would recommend sticking to sfix because it's better supported and more efficient. If you have issues with accuracy (or overflows), try increasing the precision: https://mp-spdz.readthedocs.io/en/latest/Compiler.html#Compiler.types.sfix.set_precision. If you must use floating-point, stick to it throughout as the conversion is costly and loses accuracy.
- I get roughly 4.34 for delta=10e-5 and 4.84 for delta=1e-5, maybe that explains it?
Thanks a lot for your response. You are right, my computation was not correct. Also this other issue #501 helped me solve the precision problems. And for the data types I will try to stick always to sfix just increasing the precision when needed.
Thank you!