예제 #1
0
    def __init__(self, condition_layout, block_layout, alphas=None):

        super(FStat, self).__init__(condition_layout, block_layout)

        self.validate_layouts(condition_layout, block_layout)
        self.layout_full = intersect_layouts(block_layout, condition_layout)
        self.alphas = alphas
예제 #2
0
파일: stat.py 프로젝트: itmat/pade
    def __init__(self, condition_layout, block_layout, alphas=None):

        super(FStat, self).__init__(condition_layout, block_layout)

        self.validate_layouts(condition_layout, block_layout)
        self.layout_full = intersect_layouts(block_layout, condition_layout)
        self.alphas = alphas
예제 #3
0
 def validate_layouts(cls, condition_layout, block_layout):
     full_layout = intersect_layouts(block_layout, condition_layout)
     if min(map(len, full_layout)) < 2:
         raise UnsupportedLayoutException(
             "I can't use an FTest with the specified layouts, because " +
             "the intersection between those layouts results in some " +
             "groups that contain fewer than two samples.")
예제 #4
0
파일: stat.py 프로젝트: itmat/pade
 def validate_layouts(cls, condition_layout, block_layout):
     full_layout = intersect_layouts(block_layout, condition_layout)
     if min(map(len, full_layout)) < 2:
         raise UnsupportedLayoutException(
             "I can't use an FTest with the specified layouts, because " +
             "the intersection between those layouts results in some " +
             "groups that contain fewer than two samples.")
예제 #5
0
파일: stat.py 프로젝트: itmat/pade
    def __call__(self, data):

        conds  = self.condition_layout
        blocks = self.block_layout


        # Build two new layouts. c0 is a list of lists of indexes into
        # the data that represent condition 0 for each block. c1 is
        # the same for data that represent condition 1 for each block.
        c0_blocks = intersect_layouts(blocks, [ conds[0] ])
        c1_blocks = intersect_layouts(blocks, [ conds[1] ])

        # Get the mean for each block for both conditions.
        means0 = group_means(data, c0_blocks)
        means1 = group_means(data, c1_blocks)

        # If we have tuning params, add another dimension to the front
        # of each ndarray to vary the tuning param.
        if self.alphas is not None:
            shape = (len(self.alphas),) + np.shape(means0)
            old0 = means0
            old1 = means1
            means0 = np.zeros(shape)
            means1 = np.zeros(shape)
            for i, a in enumerate(self.alphas):
                means0[i] = old0 + a
                means1[i] = old1 + a

        means0 /= means1
        ratio = means0

        # If we have more than one block, we combine their ratios
        # using the geometric mean.
        ratio = gmean(ratio, axis=-1)

        # 'Symmetric' means that the order of the conditions does not
        # matter, so we should always return a ratio >= 1. So for any
        # ratios that are < 1, use the inverse.
        if self.symmetric:
            # Add another dimension to the front where and 1 is its
            # inverse, then select the max across that dimension
            ratio_and_inverse = np.array([ratio, 1.0 / ratio])
            ratio = np.max(ratio_and_inverse, axis=0)

        return ratio
예제 #6
0
파일: stat.py 프로젝트: itmat/pade
 def __init__(self, condition_layout, block_layout, alphas=None, family='gaussian', shrink=False):
     
     super(GLMFStat, self).__init__(condition_layout, block_layout)       
                                                                          
     self.layout_full = intersect_layouts(block_layout, condition_layout) 
     self.alphas = alphas
     ctor = GLM_FAMILIES[family]
     self.family = ctor()
     self.shrink = shrink
예제 #7
0
    def __call__(self, data):

        conds = self.condition_layout
        blocks = self.block_layout

        # Build two new layouts. c0 is a list of lists of indexes into
        # the data that represent condition 0 for each block. c1 is
        # the same for data that represent condition 1 for each block.
        c0_blocks = intersect_layouts(blocks, [conds[0]])
        c1_blocks = intersect_layouts(blocks, [conds[1]])

        # Get the mean for each block for both conditions.
        means0 = group_means(data, c0_blocks)
        means1 = group_means(data, c1_blocks)

        # If we have tuning params, add another dimension to the front
        # of each ndarray to vary the tuning param.
        if self.alphas is not None:
            shape = (len(self.alphas), ) + np.shape(means0)
            old0 = means0
            old1 = means1
            means0 = np.zeros(shape)
            means1 = np.zeros(shape)
            for i, a in enumerate(self.alphas):
                means0[i] = old0 + a
                means1[i] = old1 + a

        means0 /= means1
        ratio = means0

        # If we have more than one block, we combine their ratios
        # using the geometric mean.
        ratio = gmean(ratio, axis=-1)

        # 'Symmetric' means that the order of the conditions does not
        # matter, so we should always return a ratio >= 1. So for any
        # ratios that are < 1, use the inverse.
        if self.symmetric:
            # Add another dimension to the front where and 1 is its
            # inverse, then select the max across that dimension
            ratio_and_inverse = np.array([ratio, 1.0 / ratio])
            ratio = np.max(ratio_and_inverse, axis=0)

        return ratio
예제 #8
0
    def __init__(self,
                 condition_layout,
                 block_layout,
                 alphas=None,
                 family='gaussian',
                 shrink=False):

        super(GLMFStat, self).__init__(condition_layout, block_layout)

        self.layout_full = intersect_layouts(block_layout, condition_layout)
        self.alphas = alphas
        ctor = GLM_FAMILIES[family]
        self.family = ctor()
        self.shrink = shrink
예제 #9
0
    def __call__(self, data):

        pairs = self.block_layout
        conds = self.condition_layout
        values = []

        for i in [0, 1]:
            # Make a new layout that is just the item for each pair
            # from condition i. layout will be a list of sets, each
            # with just one index, since there is only one item from
            # each pair with condition i. So flatten it into a list of
            # indexes, and grab the corresponding values from the
            # data.
            layout = intersect_layouts(self.block_layout, [conds[i]])
            idxs = list(itertools.chain(*layout))
            values.append(data[..., idxs])

        # Now just get the differences between the two sets of values
        # and call the child statistic on those values.
        return self.child(values[0] - values[1])
예제 #10
0
파일: stat.py 프로젝트: itmat/pade
    def __call__(self, data):
        
        pairs = self.block_layout
        conds = self.condition_layout
        values = []

        for i in [ 0, 1 ]:
            # Make a new layout that is just the item for each pair
            # from condition i. layout will be a list of sets, each
            # with just one index, since there is only one item from
            # each pair with condition i. So flatten it into a list of
            # indexes, and grab the corresponding values from the
            # data.
            layout = intersect_layouts(self.block_layout, [ conds[i] ])
            idxs = list(itertools.chain(*layout))
            values.append(data[..., idxs])

        # Now just get the differences between the two sets of values
        # and call the child statistic on those values.
        return self.child(values[0] - values[1])