Closed cutukmirza closed 2 years ago
Hello @cutukmirza,
You are not doing something wrong. The Average
method can only be evaluator on a power of two array. This is why it is parameterized as Average(ctIn *Ciphertext, <logBatchSize> int, ctOut *Ciphertext)
and not with <batchSize>
.
The reason is how it works internally (it uses the trace function, which allows to pre-scale the values by the modular inverse of 2^logBatchSize = n
which removes the need afterward to scale the values by 1/n
).
If you want to do an average on a non-power of two array you can use InnerSumLog
with batchSize = 1
and n
the size of your array, but you will have to divide your values by 1/n
or to multiply ciphertext.Scale
by 1/n
.
I hope this help.
Hello @Pro7ech,
Thank you very much for your quick reply and for your help. I managed to do it using InnerSumLog and divide.
Cheers, Mirza
Hello,
A side question to this, is there a (relatively) simple way to edit innerSumLog to have the inner sum value fill the array (like for the average), instead of filling just left-most value, which wouldn't compromise the performance significantly?
Thank you!
Internally, Average calls InnerSumLog, so you shouldn't have to modify anything, just call InnerSumLog with the same input parameters.
If you want to fill an array that is empty except for a small vector, you can call ReplicateLog.
thanks to this issue, I found the solution to calculating average of a vector sized power of 2.
If you want to do an average on a non-power of two array you can use
InnerSumLog
withbatchSize = 1
andn
the size of your array, but you will have to divide your values by1/n
or to multiplyciphertext.Scale
by1/n
.
If you want to do an average on a non-power of two array you can use InnerSumLog with batchSize = 1 and n the size of your array, but you will have to divide your values by 1/n or to multiply ciphertext.Scale by n
, not 1/n
. right?
BR
Hello,
I have been trying to do an average of a 1000 number array with CKKS (evaluator.Average). I am using ckks.NewParametersFromLiteral(ckks.PN14QP438) as my parameters, and have logBatch=0, batch=1, and n=1000. I generate the rotation keys with the given arguments and then try to evaluate Average, but I get a "specific rotation has not been generated: 1024". On the other hand if I take n=params.Slots(), which is 8192, then I don't get an error, but my average is calculated as sum(values)/8192, instead of sum(values)/1000.
Here is the code snippet if necessary:
I am obviously doing something wrong, but I'm not quite sure what it is. Could you point me in the right direction?
Thank you!