Ejemplo n.º 1
0
 def fit(self, x: np.ndarray, groups: np.ndarray = None):
     if groups is not None:
         group_index = group_mapping(groups)
         self.mean = aggregate(group_index, x, 'mean')
         self.std = aggregate(group_index, x, 'std', self.ddof)
         self.labels = np.unique(groups)
     else:
         self.mean = simple_mean(x, axis=0)
         self.std = simple_std(x, axis=0, ddof=self.ddof)
Ejemplo n.º 2
0
def simple_settle(weights: np.ndarray,
                  ret_series: np.ndarray,
                  groups: np.ndarray = None) -> np.ndarray:

    if ret_series.ndim == 1:
        ret_series = ret_series.reshape((-1, 1))

    ret_mat = weights * ret_series
    if groups is not None:
        groups = group_mapping(groups)
        return aggregate(groups, ret_mat, 'sum')
    else:
        if ret_mat.ndim == 1:
            ret_mat = ret_mat.reshape((-1, 1))
        return simple_sum(ret_mat, axis=0)
Ejemplo n.º 3
0
 def fit(self, x: np.ndarray):
     raw_groups = x[:, 0].astype(int)
     groups = group_mapping(raw_groups)
     self.mean_ = aggregate(groups, x[:, 1:], 'mean')
     self.std_ = aggregate(groups, x[:, 1:], 'std', self.ddof_)
     self.labels_ = np.unique(raw_groups)