python类logical_and()的实例源码

main.py 文件源码 项目:specularity-removal 作者: gmichaeljaison 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def _resolve_spec(im1, im2):
    im = im1.copy()

    img1 = cv.cvtColor(im1, cv.COLOR_BGR2GRAY)
    img2 = cv.cvtColor(im2, cv.COLOR_BGR2GRAY)

    # Best pixel selection criteria
    #   1. Pixel difference should be more than 20. (just an experimentally value. Free to change!)
    #   2. Best pixel should have less intensity
    #   3. pixel should not be pure black. (just an additional constraint
    #       to remove black background created by warping)
    mask = np.logical_and((img1 - img2) > DIFF_THRESHOLD, img1 > img2)
    mask = np.logical_and(mask, img2 != 0)

    im[mask] = im2[mask]
    return im
build_feature_files.py 文件源码 项目:human-rl 作者: gsastry 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def action_label_counts(directory, data_loader, n_actions=18, n=None):
    episode_paths = frame.episode_paths(directory)
    label_counts = [0, 0]
    action_label_counts = [[0, 0] for i in range(n_actions)]
    if n is not None:
        np.random.shuffle(episode_paths)
        episode_paths = episode_paths[:n]
    for episode_path in tqdm.tqdm(episode_paths):
        try:
            features, labels = data_loader.load_features_and_labels([episode_path])
        except:
            traceback.print_exc()
        else:
            for label in range(len(label_counts)):
                label_counts[label] += np.count_nonzero(labels == label)
                for action in range(n_actions):
                    actions = np.reshape(np.array(features["action"]), [-1])
                    action_label_counts[action][label] += np.count_nonzero(
                        np.logical_and(labels == label, actions == action))
    return label_counts, action_label_counts
numerics.py 文件源码 项目:npstreams 作者: LaurentRDC 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def iall(arrays, axis = -1):
    """ 
    Test whether all array elements along a given axis evaluate to True 

    Parameters
    ----------
    arrays : iterable
        Arrays to be reduced.
    axis : int or None, optional
        Axis along which a logical AND reduction is performed. The default
        is to perform a logical AND along the 'stream axis', as if all arrays in ``array``
        were stacked along a new dimension. If ``axis = None``, arrays in ``arrays`` are flattened
        before reduction.

    Yields
    ------
    all : ndarray, dtype bool 
    """
    yield from ireduce_ufunc(arrays, ufunc = np.logical_and, axis = axis)
multigenome.py 文件源码 项目:cellranger 作者: 10XGenomics 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def _classify_gems(counts0, counts1):
        """ Infer number of distinct transcriptomes present in each GEM (1 or 2) and
            report cr_constants.GEM_CLASS_GENOME0 for a single cell w/ transcriptome 0,
            report cr_constants.GEM_CLASS_GENOME1 for a single cell w/ transcriptome 1,
            report cr_constants.GEM_CLASS_MULTIPLET for multiple transcriptomes """
        # Assumes that most of the GEMs are single-cell; model counts independently
        thresh0, thresh1 = [cr_constants.DEFAULT_MULTIPLET_THRESHOLD] * 2
        if sum(counts0 > counts1) >= 1 and sum(counts1 > counts0) >= 1:
            thresh0 = np.percentile(counts0[counts0 > counts1], cr_constants.MULTIPLET_PROB_THRESHOLD)
            thresh1 = np.percentile(counts1[counts1 > counts0], cr_constants.MULTIPLET_PROB_THRESHOLD)

        doublet = np.logical_and(counts0 >= thresh0, counts1 >= thresh1)
        dtype = np.dtype('|S%d' % max(len(cls) for cls in cr_constants.GEM_CLASSES))
        result = np.where(doublet, cr_constants.GEM_CLASS_MULTIPLET, cr_constants.GEM_CLASS_GENOME0).astype(dtype)
        result[np.logical_and(np.logical_not(result == cr_constants.GEM_CLASS_MULTIPLET), counts1 > counts0)] = cr_constants.GEM_CLASS_GENOME1

        return result
hdf5.py 文件源码 项目:cellranger 作者: 10XGenomics 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def reg2bin_vector(begin, end):
    '''Vectorized tabix reg2bin -- much faster than reg2bin'''
    result = np.zeros(begin.shape)

    # Entries filled
    done = np.zeros(begin.shape, dtype=np.bool)

    for (bits, bins) in rev_bit_bins:
        begin_shift = begin >> bits
        new_done = (begin >> bits) == (end >> bits)
        mask = np.logical_and(new_done, np.logical_not(done))
        offset = ((1 << (29 - bits)) - 1) / 7
        result[mask] = offset + begin_shift[mask]

        done = new_done

    return result.astype(np.int32)
learn_parameters.py 文件源码 项目:OrbWeaver 作者: rajanil 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def compute_test_accuracy(X_test, Y_test, model, prediction_type, cellgroup_map_array):

    prediction = model.predict(X_test)
    auc = []

    if prediction_type=="cellgroup":

        prediction = np.dot(prediction, cellgroup_map_array)
        Y_test = np.dot(Y_test, cellgroup_map_array)

    mask = ~np.logical_or(Y_test.sum(1)==0, Y_test.sum(1)==Y_test.shape[1])

    for y,pred in zip(Y_test.T,prediction.T):
        pos = np.logical_and(mask, y==1)
        neg = np.logical_and(mask, y==0)
        try:
            U = stats.mannwhitneyu(pred[pos], pred[neg])[0]
            auc.append(1.-U/(np.count_nonzero(pos)*np.count_nonzero(neg)))
        except ValueError:
            auc.append(0.5)

    return auc
fit_sbp.py 文件源码 项目:atoolbox 作者: liweitianux 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def ignore_data(self, xmin=None, xmax=None, unit=None):
        """
        Ignore the data points within range [xmin, xmax].
        If xmin is None, then xmin=min(xdata);
        if xmax is None, then xmax=max(xdata).

        if unit is None, then assume the same unit as `self.xunit'.
        """
        if unit is None:
            unit = self.xunit
        if xmin is not None:
            xmin = self.convert_unit(xmin, unit=unit)
        else:
            xmin = np.min(self.xdata)
        if xmax is not None:
            xmax = self.convert_unit(xmax, unit=unit)
        else:
            xmax = np.max(self.xdata)
        ignore_idx = np.logical_and(self.xdata >= xmin, self.xdata <= xmax)
        self.mask[ignore_idx] = False
        # reset `f_residual'
        self.f_residual = None
fit_sbp.py 文件源码 项目:atoolbox 作者: liweitianux 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def notice_data(self, xmin=None, xmax=None, unit=None):
        """
        Notice the data points within range [xmin, xmax].
        If xmin is None, then xmin=min(xdata);
        if xmax is None, then xmax=max(xdata).

        if unit is None, then assume the same unit as `self.xunit'.
        """
        if unit is None:
            unit = self.xunit
        if xmin is not None:
            xmin = self.convert_unit(xmin, unit=unit)
        else:
            xmin = np.min(self.xdata)
        if xmax is not None:
            xmax = self.convert_unit(xmax, unit=unit)
        else:
            xmax = np.max(self.xdata)
        notice_idx = np.logical_and(self.xdata >= xmin, self.xdata <= xmax)
        self.mask[notice_idx] = True
        # reset `f_residual'
        self.f_residual = None
proc.py 文件源码 项目:PyMDNet 作者: HungWei-Andy 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def overlap_ratio(boxes1, boxes2):
  # find intersection bbox
  x_int_bot = np.maximum(boxes1[:, 0], boxes2[0])
  x_int_top = np.minimum(boxes1[:, 0] + boxes1[:, 2], boxes2[0] + boxes2[2])
  y_int_bot = np.maximum(boxes1[:, 1], boxes2[1])
  y_int_top = np.minimum(boxes1[:, 1] + boxes1[:, 3], boxes2[1] + boxes2[3])

  # find intersection area
  dx = x_int_top - x_int_bot
  dy = y_int_top - y_int_bot
  area_int = np.where(np.logical_and(dx>0, dy>0), dx * dy, np.zeros_like(dx))

  # find union
  area_union = boxes1[:,2] * boxes1[:,3] + boxes2[2] * boxes2[3] - area_int

  # find overlap ratio
  ratio = np.where(area_union > 0, area_int/area_union, np.zeros_like(area_int))
  return ratio


###########################################################################
#                          overlap_ratio of two bboxes                    #
###########################################################################
proc.py 文件源码 项目:PyMDNet 作者: HungWei-Andy 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def overlap_ratio_pair(boxes1, boxes2):
  # find intersection bbox
  x_int_bot = np.maximum(boxes1[:, 0], boxes2[:, 0])
  x_int_top = np.minimum(boxes1[:, 0] + boxes1[:, 2], boxes2[:, 0] + boxes2[:, 2])
  y_int_bot = np.maximum(boxes1[:, 1], boxes2[:, 1])
  y_int_top = np.minimum(boxes1[:, 1] + boxes1[:, 3], boxes2[:, 1] + boxes2[:, 3])

  # find intersection area
  dx = x_int_top - x_int_bot
  dy = y_int_top - y_int_bot
  area_int = np.where(np.logical_and(dx>0, dy>0), dx * dy, np.zeros_like(dx))

  # find union
  area_union = boxes1[:,2] * boxes1[:,3] + boxes2[:, 2] * boxes2[:, 3] - area_int

  # find overlap ratio
  ratio = np.where(area_union > 0, area_int/area_union, np.zeros_like(area_int))
  return ratio
layers.py 文件源码 项目:fold 作者: tensorflow 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def _create_drop_path_choices(self):
    if not self._drop_path:  # Drop path was turned off.
      return np.zeros(shape=[len(self._choices)], dtype='int32')
    elif np.random.uniform() < self._p_local_drop_path:
      # Local drop-path (make each choice independantly at random.)
      choices = np.random.uniform(size=[len(self._choices)])
      drop_base = choices < self._p_drop_base_case
      drop_recursive = np.logical_and(
          choices < (self._p_drop_base_case + self._p_drop_recursive_case),
          np.logical_not(drop_base))
      return (np.int32(drop_base)*self._JUST_RECURSE +
              np.int32(drop_recursive)*self._JUST_BASE)
    else:
      # Global (pick a single column.)
      column = np.random.randint(self._fractal_block_depth)
      return np.array(
          [self._JUST_RECURSE if len(binary_seq) < column else self._JUST_BASE
           for _, binary_seq in self._choices],
          dtype='int32')
agent.py 文件源码 项目:IntelAct-Vizdoom 作者: chendagui16 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __act_manual(self, state_meas):
        if len(self.__measure_for_manual):
            # [AMMO2, AMMO3, AMMO4, AMMO5, AMMO6, AMMO7, WEAPON2,
            # WEAPON3 WEAPON4 WEAPON5 WEAPON6 WEAPON7 SELECTED_WEAPON]
            assert len(self.__measure_for_manual) == 13
            # [SELECT_WEAPON2 SELECT_WEAPON3 SELECT_WEAPON4 SELECT_WEAPON5 SELECT_WEAPON6 SELECT_WEAPON7]
            curr_action = np.zeros((state_meas.shape[0], self.__num_manual_controls), dtype=np.int)
            for ns in range(state_meas.shape[0]):
                curr_ammo = state_meas[ns, self.__measure_for_manual[:6]]
                curr_weapons = state_meas[ns, self.__measure_for_manual[6:12]]
                if self.verbose:
                    print 'current ammo:', curr_ammo
                    print 'current weapons:', curr_weapons
                available_weapons = np.logical_and(curr_ammo >= np.array([1, 2, 1, 1, 1, 40]), curr_weapons)
                if any(available_weapons):
                    best_weapon = np.nonzero(available_weapons)[0][-1]
                    if not state_meas[ns, self.__measure_for_manual[12]] == best_weapon + 2:
                        curr_action[ns, best_weapon] = 1
            return curr_action
        else:
            return []
polyCrystal.py 文件源码 项目:Graphene 作者: ashivni 项目源码 文件源码 阅读 52 收藏 0 点赞 0 评论 0
def anamVertexRegionSize(vor, L, typical=6):
    """
    Given a set of centroids (voronoi generators),
    for each vertex in the tessellation, return 1 if the vertex is part of a region that
    is not of the 'typical' size
    """
    # vertices
    v = vor.vertices

    sizeFlag = numpy.zeros(len(v))  # flag for anamolous region size
    # regSize = [[]]*len(v)     # list of region sizes
    for reg in vor.regions:
        if len(reg) > 0 and -1 not in reg:  # Non-empty and non-open region
            size = len(reg)
            if size != typical:
                for vert in reg:  # update size of all vertices that are in the region
                    # regSize[vert].append(size)
                    sizeFlag[vert] = 1

    # Choose all in box
    sizeFlag = sizeFlag[numpy.logical_and(*[numpy.logical_and(v[:, i] >= 0, v[:, i] <= L[i]) for i in range(2)])]

    sizeFlag = sizeFlag.astype('int')
    return sizeFlag
grainBdr.py 文件源码 项目:Graphene 作者: ashivni 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def anamVertexRegionSize(vor, L, typical=6):
    """
    Given a set of centroids (voronoi generators),
    for each vertex in the tessellation, return 1 if the vertex is part of a region that 
    is not of the 'typical' size
    """
    # vertices
    v = vor.vertices

    sizeFlag = numpy.zeros(len(v))      # flag for anamolous region size
    #regSize = [[]]*len(v)      # list of region sizes
    for reg in vor.regions:
        if len(reg) > 0 and -1 not in reg:  # Non-empty and non-open region
            size = len(reg)
            if size != typical:
                for vert in reg:        # update size of all vertices that are in the region
                    #regSize[vert].append(size)
                    sizeFlag[vert] = 1 

    # Choose all in box
    sizeFlag = sizeFlag[ numpy.logical_and(* [ numpy.logical_and(v[:,i]>=0, v[:,i] <= L[i]) for i in range(2) ] )]

    sizeFlag = sizeFlag.astype('int')
    return sizeFlag
test_umath.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def test_truth_table_logical(self):
        # 2, 3 and 4 serves as true values
        input1 = [0, 0, 3, 2]
        input2 = [0, 4, 0, 2]

        typecodes = (np.typecodes['AllFloat']
                     + np.typecodes['AllInteger']
                     + '?')     # boolean
        for dtype in map(np.dtype, typecodes):
            arg1 = np.asarray(input1, dtype=dtype)
            arg2 = np.asarray(input2, dtype=dtype)

            # OR
            out = [False, True, True, True]
            for func in (np.logical_or, np.maximum):
                assert_equal(func(arg1, arg2).astype(bool), out)
            # AND
            out = [False, False, False, True]
            for func in (np.logical_and, np.minimum):
                assert_equal(func(arg1, arg2).astype(bool), out)
            # XOR
            out = [False, True, True, False]
            for func in (np.logical_xor, np.not_equal):
                assert_equal(func(arg1, arg2).astype(bool), out)
test_ufunc.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def test_object_logical(self):
        a = np.array([3, None, True, False, "test", ""], dtype=object)
        assert_equal(np.logical_or(a, None),
                        np.array([x or None for x in a], dtype=object))
        assert_equal(np.logical_or(a, True),
                        np.array([x or True for x in a], dtype=object))
        assert_equal(np.logical_or(a, 12),
                        np.array([x or 12 for x in a], dtype=object))
        assert_equal(np.logical_or(a, "blah"),
                        np.array([x or "blah" for x in a], dtype=object))

        assert_equal(np.logical_and(a, None),
                        np.array([x and None for x in a], dtype=object))
        assert_equal(np.logical_and(a, True),
                        np.array([x and True for x in a], dtype=object))
        assert_equal(np.logical_and(a, 12),
                        np.array([x and 12 for x in a], dtype=object))
        assert_equal(np.logical_and(a, "blah"),
                        np.array([x and "blah" for x in a], dtype=object))

        assert_equal(np.logical_not(a),
                        np.array([not x for x in a], dtype=object))

        assert_equal(np.logical_or.reduce(a), 3)
        assert_equal(np.logical_and.reduce(a), None)
test_ufunc.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_NotImplemented_not_returned(self):
        # See gh-5964 and gh-2091. Some of these functions are not operator
        # related and were fixed for other reasons in the past.
        binary_funcs = [
            np.power, np.add, np.subtract, np.multiply, np.divide,
            np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or,
            np.bitwise_xor, np.left_shift, np.right_shift, np.fmax,
            np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2,
            np.logical_and, np.logical_or, np.logical_xor, np.maximum,
            np.minimum, np.mod
            ]

        # These functions still return NotImplemented. Will be fixed in
        # future.
        # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal]

        a = np.array('1')
        b = 1
        for f in binary_funcs:
            assert_raises(TypeError, f, a, b)
PConsC2.py 文件源码 项目:Master-Thesis 作者: AntoinePassemiers 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def get_metrics(predictions, targets):
    assert(np.logical_or(predictions == 1, predictions == 0).all())
    assert(np.logical_or(targets == 1, targets == 0).all())
    TP  = np.logical_and(predictions == 1, targets == 1).sum()
    FP  = np.logical_and(predictions == 1, targets == 0).sum()
    FN  = np.logical_and(predictions == 0, targets == 1).sum()
    TN  = np.logical_and(predictions == 0, targets == 0).sum()
    N   = TP + FP + FN + TN

    PPV = float(TP) / float(TP + FP) if TP != 0.0 else 0.0
    FPV = float(TN) / float(TN + FN) if TN != 0.0 else 0.0
    ACC = float(TP + TN) / float(N)
    TPR = float(TP) / float(TP + FN) if TP != 0.0 else 0.0
    FPR = float(FP) / float(FP + TN) if FP != 0.0 else 0.0
    tp, tn, fp, fn = float(TP) / N, float(TN) / N, float(FP) / N, float(FN) / N
    MCC = float(tp*tn - fp*fn) / (np.sqrt(tp+fp)*np.sqrt(tp+fn)*np.sqrt(tn+fp)*np.sqrt(tn+fn))
    F1 = 2 * TP / float(2 * TP + FP + FN)
    metrics = {
        "TP": TP, "FP": FP, "FN": FN, "TN": TN, "N": N,
        "PPV": PPV, "FPV": FPV, "MCC": MCC, "ACC": ACC,
        "F1": F1
    }
    return metrics
FashionVictimModel.py 文件源码 项目:HARK 作者: econ-ark 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def simOnePrd(self):
        '''
        Simulate one period of the fashion victom model for this type.  Each
        agent receives an idiosyncratic preference shock and chooses whether to
        change styles (using the optimal decision rule).

        Parameters
        ----------
        none

        Returns
        -------
        none
        '''
        pNow    = self.pNow
        sPrev   = self.sNow
        J2Pprob = self.switchFuncJock(pNow)
        P2Jprob = self.switchFuncPunk(pNow)
        Shks    = self.RNG.rand(self.pop_size)
        J2P     = np.logical_and(sPrev == 0,Shks < J2Pprob)
        P2J     = np.logical_and(sPrev == 1,Shks < P2Jprob)
        sNow    = copy(sPrev)
        sNow[J2P] = 1
        sNow[P2J] = 0
        self.sNow = sNow
rsrm.py 文件源码 项目:brainiak 作者: brainiak 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _shrink(v, gamma):
        """Soft-shrinkage of an array with parameter gamma.

        Parameters
        ----------

        v : array
            Array containing the values to be applied to the shrinkage operator

        gamma : float
            Shrinkage parameter.

        Returns
        -------

        v : array
            The same input array after the shrinkage operator was applied.
        """
        pos = v > gamma
        neg = v < -gamma
        v[pos] -= gamma
        v[neg] += gamma
        v[np.logical_and(~pos, ~neg)] = .0
        return v
likelihoods.py 文件源码 项目:uncover-ml 作者: GeoscienceAustralia 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __split_apply(self, func_y_lt_f, func_y_gt_f, func_f_lt_0, y, f):

        # Make sure all arrays are of a compatible type
        y, f = np.broadcast_arrays(y, f)
        y = y.astype(float, copy=False)
        f = f.astype(float, copy=False)

        if any(y < 0):
            raise ValueError("y has to be > 0!")

        # get indicators of which likelihoods to apply where
        y_lt_f = np.logical_and(y <= f, f > 0)
        y_gt_f = np.logical_and(y > f, f > 0)
        f_lt_0 = f <= 0

        result = np.zeros_like(y)

        result[y_lt_f] = func_y_lt_f(y[y_lt_f], f[y_lt_f])
        result[y_gt_f] = func_y_gt_f(y[y_gt_f], f[y_gt_f])
        result[f_lt_0] = func_f_lt_0(y[f_lt_0], f[f_lt_0])

        return result
image.py 文件源码 项目:uncover-ml 作者: GeoscienceAustralia 项目源码 文件源码 阅读 51 收藏 0 点赞 0 评论 0
def _global_lonlat2pix(self, lonlat):
        x = np.searchsorted(self._coords_x, lonlat[:, 0], side='right') - 1
        x = x.astype(int)
        ycoords = self._coords_y
        y = np.searchsorted(ycoords, lonlat[:, 1], side='right') - 1
        y = y.astype(int)

        # We want the *closed* interval, which means moving
        # points on the end back by 1
        on_end_x = lonlat[:, 0] == self._coords_x[-1]
        on_end_y = lonlat[:, 1] == self._coords_y[-1]
        x[on_end_x] -= 1
        y[on_end_y] -= 1
        if (not all(np.logical_and(x >= 0, x < self._full_res[0]))) or \
                (not all(np.logical_and(y >= 0, y < self._full_res[1]))):
            raise ValueError("Queried location is not "
                             "in the image {}!".format(self.source._filename))

        result = np.concatenate((x[:, np.newaxis], y[:, np.newaxis]), axis=1)
        return result

    # @contract(lonlat='array[Nx2](float64),N>0')
switching.py 文件源码 项目:Auspex 作者: BBN-Q 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def load_switching_data(filename_or_fileobject, start_state=None, group="main", failure=False, threshold=None,
                        voltage_scale_factor=1.0, duration_scale_factor=1.0, data_name='voltage', data_filter=None, display=False):
    data, desc = load_from_HDF5(filename_or_fileobject, reshape=False)
    # Regular axes
    states = desc[group].axis("state").points
    reps   = desc[group].axis("attempt").points
    # Main data array, possibly unstructured
    dat = data[group][:].reshape((-1, reps.size, states.size))
    # Filter data if desired
    # e.g. filter_func = lambda dat: np.logical_and(dat['field'] == 0.04, dat['temperature'] == 4.0)
    if data_filter:
        dat = dat[np.where(data_filter(dat))]

    Vs     = dat[data_name]
    durs   = dat['pulse_duration'][:,0,0]
    amps   = dat['pulse_voltage'][:,0,0]
    points = np.array([durs, amps]).transpose()

    if failure:
        return points, reset_failure(Vs, start_state=start_state)
    else:
        return points, switching_phase(Vs, start_state=start_state, threshold=threshold, display=display)
cfc.py 文件源码 项目:brainpipe 作者: EtienneCmb 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _pfp(pha, amp, phabin, binsize):
    """Sub prefered phase function
    """
    nbin, nt = len(phabin), pha.shape[1]
    ampbin = np.zeros((len(phabin), nt), dtype=float)
    # Binarize amplitude accros all trials :
    for t in range(nt):
        curpha, curamp = pha[:, t], amp[:, t]
        for i, p in enumerate(phabin):
            idx = np.logical_and(curpha >= p, curpha < p+binsize)
            if idx.astype(int).sum() != 0:
                ampbin[i, t] = curamp[idx].mean()
            else:
                ampbin[i, t] = 0
        ampbin[:, t] /= ampbin[:, t].sum()
    # Find prefered phase and p-values :
    pfp = np.array([phabin[k]+binsize/2 for k in ampbin.argmax(axis=0)])
    pvalue = circ_rtest(pfp)[0]
    prf = phabin[ampbin.mean(axis=1).argmax()]+binsize/2

    return pfp, prf, pvalue, ampbin
utils.py 文件源码 项目:motif 作者: rabitt 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_snippet_idx(snippet, full_array):
    """ Find the indices of ``full_array`` where ``snippet`` is present.
    Assumes both ``snippet`` and ``full_array`` are ordered.

    Parameters
    ----------
    snippet : np.array
        Array of ordered time stamps
    full_array : np.array
        Array of ordered time stamps

    Returns
    -------
    idx : np.array
        Array of booleans indicating where in ``full_array`` ``snippet``
        is present.

    """
    idx = np.logical_and(
        full_array >= snippet[0], full_array <= snippet[-1]
    )
    return idx
waveform_dataset.py 文件源码 项目:tu-dortmund-ice-cube 作者: wjam1995 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_signal_mask(df):
    masks = []
    # Select waveforms whose DOMs are close to both interaction
    # vertices and still suficiently separated in time
    masks.append(df['GeometricalSelection'] == 1)
    # Apply a light set of cuts on the remaining waveforms
    masks.append(df['Bins_ToT_Pulse1'] >= 2)
    masks.append(df['Bins_ToT_Pulse2'] >= 3)
    masks.append(df['Bins_TbT'] >= 2)
    masks.append(df['Amplitude_Pulse1'] >= 10)
    masks.append(df['Amplitude_Pulse2'] >= 10)

    # Combine all the masks
    selection_mask = masks[0]
    for i in range(1, len(masks)):
        selection_mask = np.logical_and(selection_mask, masks[i])

    return selection_mask
base.py 文件源码 项目:voropy 作者: nschloe 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def get_edge_mask(self, subdomain=None):
        '''Get faces which are fully in subdomain.
        '''
        if subdomain is None:
            # http://stackoverflow.com/a/42392791/353337
            return numpy.s_[:]

        if subdomain not in self.subdomains:
            self._mark_vertices(subdomain)

        # A face is inside if all its edges are in.
        # An edge is inside if all its nodes are in.
        is_in = self.subdomains[subdomain]['vertices'][self.idx_hierarchy]
        # Take `all()` over the first index
        is_inside = numpy.all(is_in, axis=tuple(range(1)))

        if subdomain.is_boundary_only:
            # Filter for boundary
            is_inside = numpy.logical_and(is_inside, self.is_boundary_edge)

        return is_inside
base.py 文件源码 项目:voropy 作者: nschloe 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def get_face_mask(self, subdomain):
        '''Get faces which are fully in subdomain.
        '''
        if subdomain is None:
            # http://stackoverflow.com/a/42392791/353337
            return numpy.s_[:]

        if subdomain not in self.subdomains:
            self._mark_vertices(subdomain)

        # A face is inside if all its edges are in.
        # An edge is inside if all its nodes are in.
        is_in = self.subdomains[subdomain]['vertices'][self.idx_hierarchy]
        # Take `all()` over all axes except the last two (face_ids, cell_ids).
        n = len(is_in.shape)
        is_inside = numpy.all(is_in, axis=tuple(range(n-2)))

        if subdomain.is_boundary_only:
            # Filter for boundary
            is_inside = numpy.logical_and(is_inside, self.is_boundary_face)

        return is_inside
base.py 文件源码 项目:voropy 作者: nschloe 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def _mark_vertices(self, subdomain):
        '''Mark faces/edges which are fully in subdomain.
        '''
        if subdomain is None:
            is_inside = numpy.ones(len(self.node_coords), dtype=bool)
        else:
            is_inside = subdomain.is_inside(self.node_coords.T).T

            if subdomain.is_boundary_only:
                # Filter boundary
                self.mark_boundary()
                is_inside = numpy.logical_and(is_inside, self.is_boundary_node)

        self.subdomains[subdomain] = {
                'vertices': is_inside,
                }
        return
pascal_voc.py 文件源码 项目:mxnet-ssd 作者: zhreshold 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _filter_image_with_no_gt(self):
        """
        filter images that have no ground-truth labels.
        use case: when you wish to work only on a subset of pascal classes, you have 2 options:
            1. use only the sub-dataset that contains the subset of classes
            2. use all images, and images with no ground-truth will count as true-negative images
        :return:
        self object with filtered information
        """

        # filter images that do not have any of the specified classes
        self.labels = [f[np.logical_and(f[:, 0] >= 0, f[:, 0] <= self.num_classes-1), :] for f in self.labels]
        # find indices of images with ground-truth labels
        gt_indices = [idx for idx, f in enumerate(self.labels) if not f.size == 0]

        self.labels = [self.labels[idx] for idx in gt_indices]
        self.image_set_index = [self.image_set_index[idx] for idx in gt_indices]
        old_num_images = self.num_images
        self.num_images = len(self.labels)

        print ('filtering images with no gt-labels. can abort filtering using *true_negative* flag')
        print ('... remaining {0}/{1} images.  '.format(self.num_images, old_num_images))


问题


面经


文章

微信
公众号

扫码关注公众号