-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
variance in nada-numpy #75
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -948,6 +948,31 @@ def test_shuffle_randomness(vector_size, num_shuffles): | |
|
||
return arr | ||
|
||
def var(self) -> "NadaArray": | ||
""" | ||
Compute the variable of array elements. | ||
|
||
Returns: | ||
nadaarray: the variance of array elements | ||
""" | ||
|
||
# Compute the mean | ||
m = self.mean() | ||
|
||
# Initialise the sum to 0 | ||
sum = Integer(0) | ||
|
||
# compute (x_i - mean)^2 | ||
|
||
for v in self.inner: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should profit from broadcasting here. The function as it is, may not be working as you expect. |
||
diff = v - m | ||
sum += (diff * diff) | ||
|
||
# compute variance | ||
var = sum / Integer(self.size) | ||
|
||
return NadaArray(np.array([var])) | ||
|
||
def __len__(self): | ||
""" | ||
Overrides the default behavior of returning the length of the object. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from nada_dsl import * | ||
import nada_numpy as na | ||
|
||
def nada_main(): | ||
parties = na.parties(4) | ||
|
||
a = na.array([4], parties[0], "A", SecretInteger) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nada arrays do not require re-initialization of each of the entries. |
||
|
||
a[0] = SecretInteger(Input("A_0", parties[0])) | ||
a[1] = SecretInteger(Input("A_1", parties[1])) | ||
a[2] = SecretInteger(Input("A_2", parties[2])) | ||
a[3] = SecretInteger(Input("A_3", parties[3])) | ||
|
||
var = a.var() | ||
|
||
return na.output(var, parties[1], "my_output") |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is correct but doesn't check for other behaviors of the function and other datatypes. You should add the check for other variance values ( |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
program: variance | ||
inputs: | ||
A_0: 3 | ||
A_1: 3 | ||
A_2: 3 | ||
A_3: 3 | ||
expected_outputs: | ||
my_output_0: 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ | |
"shuffle", | ||
"array_comparison", | ||
"private_inverse", | ||
"var", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should match the name of the Python executable, thus |
||
] | ||
|
||
EXAMPLES = [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nada Numpy also supports SecretRational types. The function should also work for Rational types. You can probably look into the implementation of other functions to check for this.