Пример #1
0
def residuals(data, layout):
    """Return the residuals for the given data and layout.

    >>> residuals(np.array([1, 2, 3, 6], float), [[0, 1], [2, 3]])
    array([-0.5,  0.5, -1.5,  1.5])

    :param data: 
      An ndarray. Any number of dimensions is allowed.

    :param layout:
      A :term:`layout` describing the data.

    :return: 
      The residuals obtained by subtracting the means of the groups
      defined by the layout from the values in data.

    """
    means = group_means(data, layout)
    diffs = []
    groups = apply_layout(data, layout)

    for i, group in enumerate(groups):
        these_means = means[..., i].reshape(np.shape(group)[:-1] + (1, ))
        diffs.append(group - these_means)
    return np.concatenate(diffs, axis=-1)
Пример #2
0
Файл: stat.py Проект: itmat/pade
def residuals(data, layout):
    """Return the residuals for the given data and layout.

    >>> residuals(np.array([1, 2, 3, 6], float), [[0, 1], [2, 3]])
    array([-0.5,  0.5, -1.5,  1.5])

    :param data: 
      An ndarray. Any number of dimensions is allowed.

    :param layout:
      A :term:`layout` describing the data.

    :return: 
      The residuals obtained by subtracting the means of the groups
      defined by the layout from the values in data.

    """
    means = group_means(data, layout)
    diffs = []
    groups = apply_layout(data, layout)
    
    for i, group in enumerate(groups):
        these_means = means[..., i].reshape(np.shape(group)[:-1] + (1,))
        diffs.append(group - these_means)
    return np.concatenate(diffs, axis=-1)
Пример #3
0
    def __call__(self, data):
        groups = apply_layout(data, self.condition_layout)
        res = []
        for i, grp in enumerate(groups):
            syms = []
            for index in grp:
                sym = self.index_to_symbol[index]
                syms.append(sym)

            res.append(''.join(sorted(syms)))

        return ' '.join(res)
Пример #4
0
Файл: stat.py Проект: itmat/pade
    def __call__(self, data):
        groups = apply_layout(data, self.condition_layout)
        res = []
        for i, grp in enumerate(groups):
            syms = []
            for index in grp:
                sym = self.index_to_symbol[index]
                syms.append(sym)

            res.append(''.join(sorted(syms)))


        return ' '.join(res)
Пример #5
0
def group_means(data, layout):
    """Get the means for each group defined by layout.

    Groups data according to the given layout and returns a new
    ndarray with the same number of dimensions as data, but with the
    last dimension replaced by the means according to the specified
    grouping.
    
    One dimensional input:

    >>> group_means(np.array([-1, -3, 4, 6]), [[0, 1], [2, 3]])
    array([-2.,  5.])

    Two dimensional input:

    >>> data = np.array([[-1, -3, 4, 6], [10, 12, 30, 40]])
    >>> layout = [[0, 1], [2, 3]]
    >>> group_means(data, layout) # doctest: +NORMALIZE_WHITESPACE
    array([[ -2.,  5.],
           [ 11., 35.]])

    :param data: An ndarray. Any number of dimensions is allowed.

    :param layout: A :term:`layout` describing the data.

    :return: An ndarray giving the means for each group obtained by
      applying the given layout to the given data.

    """
    # We'll take the mean of the last axis of each group, so change
    # the shape of the array to collapse the last axis down to one
    # item per group.
    shape = np.shape(data)[:-1] + (len(layout), )
    res = np.zeros(shape)

    for i, group in enumerate(apply_layout(data, layout)):
        res[..., i] = np.mean(group, axis=-1)

    return res
Пример #6
0
Файл: stat.py Проект: itmat/pade
def group_means(data, layout):
    """Get the means for each group defined by layout.

    Groups data according to the given layout and returns a new
    ndarray with the same number of dimensions as data, but with the
    last dimension replaced by the means according to the specified
    grouping.
    
    One dimensional input:

    >>> group_means(np.array([-1, -3, 4, 6]), [[0, 1], [2, 3]])
    array([-2.,  5.])

    Two dimensional input:

    >>> data = np.array([[-1, -3, 4, 6], [10, 12, 30, 40]])
    >>> layout = [[0, 1], [2, 3]]
    >>> group_means(data, layout) # doctest: +NORMALIZE_WHITESPACE
    array([[ -2.,  5.],
           [ 11., 35.]])

    :param data: An ndarray. Any number of dimensions is allowed.

    :param layout: A :term:`layout` describing the data.

    :return: An ndarray giving the means for each group obtained by
      applying the given layout to the given data.

    """
    # We'll take the mean of the last axis of each group, so change
    # the shape of the array to collapse the last axis down to one
    # item per group.
    shape = np.shape(data)[:-1] + (len(layout),)
    res = np.zeros(shape)

    for i, group in enumerate(apply_layout(data, layout)):
        res[..., i] = np.mean(group, axis=-1)

    return res
Пример #7
0
 def sep(self, data):
     data = np.asarray(data)
     groups = apply_layout(data, self.condition_layout)
     return np.abs(
         np.mean(groups[0], axis=-1) - np.mean(groups[1], axis=-1))
Пример #8
0
Файл: stat.py Проект: itmat/pade
 def sep(self, data):
     data = np.asarray(data)
     groups = apply_layout(data, self.condition_layout)
     return np.abs(np.mean(groups[0], axis=-1) - np.mean(groups[1], axis=-1))