mirror of
https://github.com/MPCStats/zk-stats-lib.git
synced 2026-01-10 05:57:55 -05:00
fill nn.parameter, data
This commit is contained in:
@@ -54,8 +54,8 @@ class Median(Operation):
|
||||
super().__init__(torch.tensor(np.median(x_1d)), error)
|
||||
sorted_x = np.sort(x_1d)
|
||||
len_x = len(x_1d)
|
||||
self.lower = torch.nn.Parameter(torch.tensor(sorted_x[int(len_x/2)-1], dtype = torch.float32), requires_grad=False)
|
||||
self.upper = torch.nn.Parameter(torch.tensor(sorted_x[int(len_x/2)], dtype = torch.float32), requires_grad=False)
|
||||
self.lower = torch.nn.Parameter(data = torch.tensor(sorted_x[int(len_x/2)-1], dtype = torch.float32), requires_grad=False)
|
||||
self.upper = torch.nn.Parameter(data = torch.tensor(sorted_x[int(len_x/2)], dtype = torch.float32), requires_grad=False)
|
||||
|
||||
@classmethod
|
||||
def create(cls, x: list[torch.Tensor], error: float) -> 'Median':
|
||||
@@ -158,7 +158,7 @@ class Mode(Operation):
|
||||
class PStdev(Operation):
|
||||
def __init__(self, x: torch.Tensor, error: float):
|
||||
x_1d = to_1d(x)
|
||||
self.data_mean = torch.nn.Parameter(torch.mean(x_1d), requires_grad=False)
|
||||
self.data_mean = torch.nn.Parameter(data=torch.mean(x_1d), requires_grad=False)
|
||||
result = torch.sqrt(torch.var(x_1d, correction = 0))
|
||||
super().__init__(result, error)
|
||||
|
||||
@@ -178,7 +178,7 @@ class PStdev(Operation):
|
||||
class PVariance(Operation):
|
||||
def __init__(self, x: torch.Tensor, error: float):
|
||||
x_1d = to_1d(x)
|
||||
self.data_mean = torch.nn.Parameter(torch.mean(x_1d), requires_grad=False)
|
||||
self.data_mean = torch.nn.Parameter(data=torch.mean(x_1d), requires_grad=False)
|
||||
result = torch.var(x_1d, correction = 0)
|
||||
super().__init__(result, error)
|
||||
|
||||
@@ -198,7 +198,7 @@ class PVariance(Operation):
|
||||
class Stdev(Operation):
|
||||
def __init__(self, x: torch.Tensor, error: float):
|
||||
x_1d = to_1d(x)
|
||||
self.data_mean = torch.nn.Parameter(torch.mean(x_1d), requires_grad=False)
|
||||
self.data_mean = torch.nn.Parameter(data=torch.mean(x_1d), requires_grad=False)
|
||||
result = torch.sqrt(torch.var(x_1d, correction = 1))
|
||||
super().__init__(result, error)
|
||||
|
||||
@@ -218,7 +218,7 @@ class Stdev(Operation):
|
||||
class Variance(Operation):
|
||||
def __init__(self, x: torch.Tensor, error: float):
|
||||
x_1d = to_1d(x)
|
||||
self.data_mean = torch.nn.Parameter(torch.mean(x_1d), requires_grad=False)
|
||||
self.data_mean = torch.nn.Parameter(data=torch.mean(x_1d), requires_grad=False)
|
||||
result = torch.var(x_1d, correction = 1)
|
||||
super().__init__(result, error)
|
||||
|
||||
@@ -241,8 +241,8 @@ class Covariance(Operation):
|
||||
y_1d = to_1d(y)
|
||||
x_1d_list = x_1d.tolist()
|
||||
y_1d_list = y_1d.tolist()
|
||||
self.x_mean = torch.nn.Parameter(torch.tensor(statistics.mean(x_1d_list), dtype = torch.float32), requires_grad=False)
|
||||
self.y_mean = torch.nn.Parameter(torch.tensor(statistics.mean(y_1d_list), dtype = torch.float32), requires_grad=False)
|
||||
self.x_mean = torch.nn.Parameter(data=torch.tensor(statistics.mean(x_1d_list), dtype = torch.float32), requires_grad=False)
|
||||
self.y_mean = torch.nn.Parameter(data=torch.tensor(statistics.mean(y_1d_list), dtype = torch.float32), requires_grad=False)
|
||||
result = torch.tensor(statistics.covariance(x_1d_list, y_1d_list), dtype = torch.float32)
|
||||
super().__init__(result, error)
|
||||
|
||||
@@ -282,11 +282,11 @@ class Correlation(Operation):
|
||||
y_1d = to_1d(y)
|
||||
x_1d_list = x_1d.tolist()
|
||||
y_1d_list = y_1d.tolist()
|
||||
self.x_mean = torch.nn.Parameter(torch.mean(x_1d), requires_grad=False)
|
||||
self.y_mean = torch.nn.Parameter(torch.mean(y_1d), requires_grad = False)
|
||||
self.x_std = torch.nn.Parameter(torch.sqrt(torch.var(x_1d, correction = 1)), requires_grad = False)
|
||||
self.y_std = torch.nn.Parameter(torch.sqrt(torch.var(y_1d, correction = 1)), requires_grad=False)
|
||||
self.cov = torch.nn.Parameter(torch.tensor(statistics.covariance(x_1d_list, y_1d_list), dtype = torch.float32), requires_grad=False)
|
||||
self.x_mean = torch.nn.Parameter(data=torch.mean(x_1d), requires_grad=False)
|
||||
self.y_mean = torch.nn.Parameter(data=torch.mean(y_1d), requires_grad = False)
|
||||
self.x_std = torch.nn.Parameter(data=torch.sqrt(torch.var(x_1d, correction = 1)), requires_grad = False)
|
||||
self.y_std = torch.nn.Parameter(data=torch.sqrt(torch.var(y_1d, correction = 1)), requires_grad=False)
|
||||
self.cov = torch.nn.Parameter(data=torch.tensor(statistics.covariance(x_1d_list, y_1d_list), dtype = torch.float32), requires_grad=False)
|
||||
result = torch.tensor(statistics.correlation(x_1d_list, y_1d_list), dtype = torch.float32)
|
||||
super().__init__(result, error)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user