python类alltrue()的实例源码

test_sgld.py 文件源码 项目:chemblnet 作者: jaak-s 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_sgld_sparse(self):
        tf.reset_default_graph()

        z     = tf.Variable(tf.zeros((5, 2)), dtype=tf.float32)
        idx   = tf.placeholder(tf.int32)
        zi    = tf.gather(z, idx)
        zloss = tf.square(zi - [10.0, 5.0])

        sgld = SGLD(learning_rate=0.4)
        train_op_sgld = sgld.minimize(zloss)

        sess = tf.InteractiveSession()
        sess.run(tf.global_variables_initializer())

        self.assertTrue(np.alltrue(sess.run(z) == 0.0))

        sess.run(train_op_sgld, feed_dict={idx: 3})
        zh = sess.run(z)
        self.assertTrue(np.alltrue(zh[[0, 1, 2, 4], :] == 0.0))
        self.assertTrue(zh[3, 0] > 0)
test_sgld.py 文件源码 项目:chemblnet 作者: jaak-s 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_psgld_sparse(self):
        tf.reset_default_graph()

        z     = tf.Variable(tf.zeros((5, 2)), dtype=tf.float32)
        idx   = tf.placeholder(tf.int32)
        zi    = tf.gather(z, idx)
        zloss = tf.square(zi - [10.0, 5.0])

        psgld = pSGLD(learning_rate=0.4)
        train_op_psgld = psgld.minimize(zloss)

        sess = tf.InteractiveSession()
        sess.run(tf.global_variables_initializer())

        self.assertTrue(np.alltrue(sess.run(z) == 0.0))

        sess.run(train_op_psgld, feed_dict={idx: 3})
        zh = sess.run(z)
        self.assertTrue(np.alltrue(zh[[0, 1, 2, 4], :] == 0.0))
        self.assertTrue(zh[3, 0] > 0)
pohmm.py 文件源码 项目:pohmm 作者: vmonaco 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _set_startprob(self, startprob):
        if startprob is None:
            startprob = np.ones(shape=(self.n_partial_states, self.n_hidden_states)) / self.n_hidden_states
        else:
            startprob = np.asarray(startprob, dtype=np.float)

        # check if there exists a component whose value is exactly zero
        # if so, add a small number and re-normalize
        if not np.alltrue(startprob):
            startprob = normalize(startprob, axis=1)

        if len(startprob) != self.n_partial_states:
            raise ValueError('startprob must have length n_partial_states')
        if not np.allclose(np.sum(startprob, axis=1), 1.0):
            raise ValueError('startprob must sum to 1.0')

        self._log_startprob = np.log(np.asarray(startprob).copy())
pohmm.py 文件源码 项目:pohmm 作者: vmonaco 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _set_steadyprob(self, steadyprob):
        if steadyprob is None:
            steadyprob = np.ones(shape=(self.n_partial_states, self.n_hidden_states)) / self.n_hidden_states
        else:
            steadyprob = np.asarray(steadyprob, dtype=np.float)

        # check if there exists a component whose value is exactly zero
        # if so, add a small number and re-normalize
        if not np.alltrue(steadyprob):
            steadyprob = normalize(steadyprob, axis=1)

        if len(steadyprob) != self.n_partial_states:
            raise ValueError('steadyprob must have length n_partial_states')
        if not np.allclose(np.sum(steadyprob, axis=1), 1.0):
            raise ValueError('steadyprob must sum to 1.0')

        self._log_steadyprob = np.log(np.asarray(steadyprob).copy())
pohmm.py 文件源码 项目:pohmm 作者: vmonaco 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _set_transmat(self, transmat):
        if transmat is None:
            transmat = np.ones(shape=(self.n_partial_states, self.n_partial_states, self.n_hidden_states,
                                      self.n_hidden_states)) / self.n_hidden_states

        # check if there exists a component whose value is exactly zero
        # if so, add a small number and re-normalize
        if not np.alltrue(transmat):
            transmat = normalize(transmat, axis=3)

        if (np.asarray(transmat).shape
                != (self.n_partial_states, self.n_partial_states, self.n_hidden_states, self.n_hidden_states)):
            raise ValueError('transmat must have shape '
                             '(n_partial_states,n_partial_states,n_hidden_states,n_hidden_states)')
        if not np.all(np.allclose(np.sum(transmat, axis=3), 1.0)):
            raise ValueError('Rows of transmat must sum to 1.0')

        self._log_transmat = np.log(np.asarray(transmat).copy())
        underflow_idx = np.isnan(self._log_transmat)
        self._log_transmat[underflow_idx] = NEGINF
test_featurizer.py 文件源码 项目:coordinates 作者: markovmodel 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_backbone_dihedrals(self):
        self.feat = MDFeaturizer(topfile=self.asn_leu_pdbfile)
        self.feat.add_backbone_torsions()

        traj = mdtraj.load(self.asn_leu_pdbfile)
        Y = self.feat.transform(traj)
        assert(np.alltrue(Y >= -np.pi))
        assert(np.alltrue(Y <= np.pi))

        desc = self.feat.describe()
        self.assertEqual(len(desc), self.feat.dimension())

        # test ordering of indices
        backbone_feature = self.feat.active_features[0]
        angle_indices = backbone_feature.angle_indexes
        np.testing.assert_equal(angle_indices[0], backbone_feature._phi_inds[0])
        np.testing.assert_equal(angle_indices[1], backbone_feature._psi_inds[0])
        np.testing.assert_equal(angle_indices[2], backbone_feature._phi_inds[1])
        np.testing.assert_equal(angle_indices[3], backbone_feature._psi_inds[1])
test_penalties.py 文件源码 项目:pyGAM 作者: dswah 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_single_spline_penalty():
    """
    check that feature functions with only 1 basis are penalized correctly

    derivative penalty should be 0.
    l2 should penalty be 1.
    monotonic_ and convexity_ should be 0.
    """
    coef = np.array(1.)
    assert(np.alltrue(derivative(1, coef).A == 0.))
    assert(np.alltrue(l2(1, coef).A == 1.))
    assert(np.alltrue(monotonic_inc(1, coef).A == 0.))
    assert(np.alltrue(monotonic_dec(1, coef).A == 0.))
    assert(np.alltrue(convex(1, coef).A == 0.))
    assert(np.alltrue(concave(1, coef).A == 0.))
    assert(np.alltrue(circular(1, coef).A == 0.))
    assert(np.alltrue(none(1, coef).A == 0.))
basecase.py 文件源码 项目:pysynphot 作者: spacetelescope 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def arraysigtest(self,test,ref):
        #Raise an error if the arrays are not the same size
        if test.shape != ref.shape:
            raise ValueError("Array size mismatch")
        tt=test[2:-2]
        rr=ref[2:-2]
        #Identify the significant elements
        tidx=N.where(tt>(self.sigthresh*tt.max()))[0]
        ridx=N.where(rr>(self.sigthresh*rr.max()))[0]
        #Set a flag if they're not the same set
        if not (N.alltrue(tidx == ridx)):
            self.tra['SigElemDiscrep']=True
            tidx=ridx

        #Now compare only the significant elements.
        #We no longer need to exclude points with zero value, because
        #those points were already excluded as insignificant.
        self.arraytest(tt[ridx],rr[ridx])
basecase.py 文件源码 项目:pysynphot 作者: spacetelescope 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def arraytest(self,test,ref):
        #Exclude the endpoints where the gradient is very steep
        self.adiscrep=self.arraydiff(test,ref)#[2:-2]
        count=N.where(abs(self.adiscrep)>self.thresh)[0].size
        try:
            self.tra['Discrepfrac']=float(count)/self.adiscrep.size
            self.tra['Discrepmin']=self.adiscrep.min()
            self.tra['Discrepmax']=self.adiscrep.max()
            self.tra['Discrepmean']=self.adiscrep.mean()
            self.tra['Discrepstd']=self.adiscrep.std()
            self.tra['Outliers']=self.count_outliers(5)
            if (self.tra['Discrepfrac'] > self.superthresh):
                self.tra['Extreme']=True
            self.failUnless(N.alltrue(abs(self.adiscrep)<self.thresh),
                            msg="Worst case %f"%abs(self.adiscrep).max())
        except ZeroDivisionError:
            self.tra['Discrepfrac']=0.0
            self.tra['Discrepmin']=0.0
            self.tra['Discrepmax']=0.0
conv_base.py 文件源码 项目:pysynphot 作者: spacetelescope 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def arraysigtest(self,ref,test):
        #Raise an error if the arrays are not the same size
        if test.shape != ref.shape:
            raise ValueError("Array size mismatch")
        tt=test[2:-2]
        rr=ref[2:-2]
        #Identify the significant elements
        tidx=N.where(tt>(self.sigthresh*tt.max()))[0]
        ridx=N.where(rr>(self.sigthresh*rr.max()))[0]
        #Set a flag if they're not the same set
        if not (N.alltrue(tidx == ridx)):
            self.tra['SigElemDiscrep']=True
            tidx=ridx

        #Now compare only the significant elements.
        #We no longer need to exclude points with zero value, because
        #those points were already excluded as insignificant.
        self.arraytest(tt[ridx],rr[ridx])
conv_base.py 文件源码 项目:pysynphot 作者: spacetelescope 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def arraytest(self,ref,test):
        self.adiscrep=self.arraydiff(test,ref)
        count=N.where(abs(self.adiscrep)>self.thresh)[0].size
        try:
            self.tra['Discrepfrac']=float(count)/self.adiscrep.size
            self.tra['Discrepmin']=self.adiscrep.min()
            self.tra['Discrepmax']=self.adiscrep.max()
            self.tra['Discrepmean']=self.adiscrep.mean()
            self.tra['Discrepstd']=self.adiscrep.std()
            self.tra['Outliers']=self.count_outliers(5)
            self.failUnless(N.alltrue(abs(self.adiscrep)<self.thresh),
                            msg="Worst case %f"%abs(self.adiscrep).max())
        except ZeroDivisionError:
            self.tra['Discrepfrac']=0.0
            self.tra['Discrepmin']=0.0
            self.tra['Discrepmax']=0.0

#Helper method for scalar comparison
utils.py 文件源码 项目:tslearn 作者: rtavenar 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _arraylike_copy(arr):
    """Duplicate content of arr into a numpy array.

     Examples
     --------
     >>> X_npy = numpy.array([1, 2, 3])
     >>> numpy.alltrue(_arraylike_copy(X_npy) == X_npy)
     True
     >>> _arraylike_copy(X_npy) is X_npy
     False
     >>> numpy.alltrue(_arraylike_copy([1, 2, 3]) == X_npy)
     True
     """
    if type(arr) != numpy.ndarray:
        return numpy.array(arr)
    else:
        return arr.copy()
test.py 文件源码 项目:collision 作者: EelcoHoogendoorn 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_point_correctness():
    import itertools
    stencil = [-1, 0, 1]
    ndim = 3
    n = 2000
    stencil = itertools.product(*[stencil]*ndim)
    stencil = np.array(list(stencil)).astype(np.int32)

    points = (np.random.rand(n, ndim) * [1, 2, 3]).astype(np.float32)
    scale = 0.1

    spec = GridSpec(points, float(scale))
    offsets = spec.stencil(stencil).astype(np.int32)
    grid = PointGrid(spec, points, offsets)

    pairs = grid.pairs()

    from scipy.spatial import cKDTree
    tree = cKDTree(points)
    tree_pairs = tree.query_pairs(scale, output_type='ndarray')
    print(tree_pairs)
    print(pairs)

    assert np.alltrue(npi.unique(tree_pairs) == npi.unique(np.sort(pairs, axis=1)))
test.py 文件源码 项目:collision 作者: EelcoHoogendoorn 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_point_correctness():
    import itertools
    stencil = [-1, 0, 1]
    ndim = 3
    n = 2000
    stencil = itertools.product(*[stencil]*ndim)
    stencil = np.array(list(stencil)).astype(np.int32)

    points = (np.random.rand(n, ndim) * [1, 2, 3]).astype(np.float32)
    scale = 0.1

    spec = GridSpec(points, float(scale))
    offsets = spec.stencil(stencil).astype(np.int32)
    grid = PointGrid(spec, points, offsets)

    pairs = grid.pairs()

    from scipy.spatial import cKDTree
    tree = cKDTree(points)
    tree_pairs = tree.query_pairs(scale, output_type='ndarray')
    print(tree_pairs)
    print(pairs)

    assert np.alltrue(npi.unique(tree_pairs) == npi.unique(np.sort(pairs, axis=1)))
test_grad_zmat.py 文件源码 项目:chemcoord 作者: mcocdawc 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_grad_zmat():
    path = os.path.join(STRUCTURE_PATH, 'MIL53_beta.xyz')
    molecule = cc.Cartesian.read_xyz(path, start_index=1)
    fragment = molecule.get_fragment([(12, 17), (55, 60)])
    connection = np.array([[3, 99, 1, 12], [17, 3, 99, 12], [60, 3, 17, 12]])
    connection = pd.DataFrame(connection[:, 1:], index=connection[:, 0],
                              columns=['b', 'a', 'd'])
    c_table = molecule.get_construction_table([(fragment, connection)])
    molecule = molecule.loc[c_table.index]

    x = sympy.symbols('x', real=True)

    dist_mol = molecule.copy()
    dist_mol.loc[:, ['x', 'y', 'z']] = 0.
    dist_mol.loc[13, 'x'] = x

    zmat_dist = molecule.get_grad_zmat(c_table)(dist_mol)

    moved_atoms = zmat_dist.index[
        (zmat_dist.loc[:, ['bond', 'angle', 'dihedral']] != 0.).any(axis=1)]

    assert moved_atoms[0] == 13
    assert np.alltrue(
        moved_atoms[1:] == c_table.index[(c_table == 13).any(axis=1)])
xyz_functions.py 文件源码 项目:chemcoord 作者: mcocdawc 项目源码 文件源码 阅读 43 收藏 0 点赞 0 评论 0
def allclose(a, b, align=False, rtol=1.e-5, atol=1.e-8):
    """Compare two molecules for numerical equality.

    Args:
        a (Cartesian):
        b (Cartesian):
        align (bool): a and b are
            prealigned along their principal axes of inertia and moved to their
            barycenters before comparing.
        rtol (float): Relative tolerance for the numerical equality comparison
            look into :func:`numpy.allclose` for further explanation.
        atol (float): Relative tolerance for the numerical equality comparison
            look into :func:`numpy.allclose` for further explanation.

    Returns:
        bool:
    """
    return np.alltrue(isclose(a, b, align=align, rtol=rtol, atol=atol))
tip_tilt_2_axes_test.py 文件源码 项目:pi_gcs 作者: lbusoni 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def testVoltageLimitsAreSetAtStartUp(self):
        wanted= self._cfg.lowerVoltageLimit
        actual= self._ctrl.getLowerVoltageLimit(self._tt.ALL_CHANNELS)
        self.assertTrue(
            np.alltrue(wanted == actual),
            "%s %s" % (wanted, actual))

        wanted= self._cfg.upperVoltageLimit
        actual= self._ctrl.getUpperVoltageLimit(self._tt.ALL_CHANNELS)
        self.assertTrue(
            np.alltrue(wanted == actual),
            "%s %s" % (wanted, actual))
tip_tilt_2_axes_test.py 文件源码 项目:pi_gcs 作者: lbusoni 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test3rdAxisIsSetAsPivotAtStartUp(self):
        pivot= self._ctrl.getAxesIdentifiers()[2]
        wanted= self._cfg.pivotValue
        actual= self._ctrl.getOpenLoopAxisValue(pivot)
        self.assertTrue(
            np.alltrue(wanted == actual),
            "%s %s" % (wanted, actual))
evolution_strategy.py 文件源码 项目:pycma 作者: CMA-ES 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def _prepare_injection_directions(self):
        """provide genotypic directions for TPA and selective mirroring,
        with no specific length normalization, to be used in the
        coming iteration.

        Details:
        This method is called in the end of `tell`. The result is
        assigned to ``self.pop_injection_directions`` and used in
        `ask_geno`.

        """
        # self.pop_injection_directions is supposed to be empty here
        if self.pop_injection_directions or self.pop_injection_solutions:
            raise ValueError("""Found unused injected direction/solutions.
                This could be a bug in the calling order/logics or due to
                a too small popsize used in `ask()` or when only using
                `ask(1)` repeatedly. """)
        ary = []
        if self.mean_shift_samples:
            ary = [self.mean - self.mean_old]
            ary.append(self.mean_old - self.mean)  # another copy!
            if np.alltrue(ary[-1] == 0.0):
                utils.print_warning('zero mean shift encountered',
                               '_prepare_injection_directions',
                               'CMAEvolutionStrategy', self.countiter)
        if self.opts['pc_line_samples']: # caveat: before, two samples were used
            ary.append(self.pc.copy())
        if self.sp.lam_mirr and (
                self.opts['CMA_mirrormethod'] == 2 or (
                    self.opts['CMA_mirrormethod'] == 1 and ( # replacement for direct selective mirrors
                        not hasattr(self, '_mirrormethod1_done') or
                        self._mirrormethod1_done < self.countiter - 1))):
            i0 = len(ary)
            ary += self.get_selective_mirrors()
            self._indices_of_selective_mirrors = range(i0, len(ary))
        self.pop_injection_directions = ary
        return ary
test_regression.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_method_args(self, level=rlevel):
        # Make sure methods and functions have same default axis
        # keyword and arguments
        funcs1 = ['argmax', 'argmin', 'sum', ('product', 'prod'),
                 ('sometrue', 'any'),
                 ('alltrue', 'all'), 'cumsum', ('cumproduct', 'cumprod'),
                 'ptp', 'cumprod', 'prod', 'std', 'var', 'mean',
                 'round', 'min', 'max', 'argsort', 'sort']
        funcs2 = ['compress', 'take', 'repeat']

        for func in funcs1:
            arr = np.random.rand(8, 7)
            arr2 = arr.copy()
            if isinstance(func, tuple):
                func_meth = func[1]
                func = func[0]
            else:
                func_meth = func
            res1 = getattr(arr, func_meth)()
            res2 = getattr(np, func)(arr2)
            if res1 is None:
                res1 = arr

            if res1.dtype.kind in 'uib':
                assert_((res1 == res2).all(), func)
            else:
                assert_(abs(res1-res2).max() < 1e-8, func)

        for func in funcs2:
            arr1 = np.random.rand(8, 7)
            arr2 = np.random.rand(8, 7)
            res1 = None
            if func == 'compress':
                arr1 = arr1.ravel()
                res1 = getattr(arr2, func)(arr1)
            else:
                arr2 = (15*arr2).astype(int).ravel()
            if res1 is None:
                res1 = getattr(arr1, func)(arr2)
            res2 = getattr(np, func)(arr1, arr2)
            assert_(abs(res1-res2).max() < 1e-8, func)
test_regression.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_fromiter_bytes(self):
        # Ticket #1058
        a = np.fromiter(list(range(10)), dtype='b')
        b = np.fromiter(list(range(10)), dtype='B')
        assert_(np.alltrue(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
        assert_(np.alltrue(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
test_regression.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_fromiter_comparison(self, level=rlevel):
        a = np.fromiter(list(range(10)), dtype='b')
        b = np.fromiter(list(range(10)), dtype='B')
        assert_(np.alltrue(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
        assert_(np.alltrue(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
test_numeric.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_values(self):
        expected = np.array(list(self.makegen()))
        a = np.fromiter(self.makegen(), int)
        a20 = np.fromiter(self.makegen(), int, 20)
        self.assertTrue(np.alltrue(a == expected, axis=0))
        self.assertTrue(np.alltrue(a20 == expected[:20], axis=0))
test_function_base.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_nd(self):
        y1 = [[0, 0, 1], [0, 1, 1], [1, 1, 1]]
        assert_(not np.all(y1))
        assert_array_equal(np.alltrue(y1, axis=0), [0, 0, 1])
        assert_array_equal(np.alltrue(y1, axis=1), [0, 0, 1])
insert.py 文件源码 项目:cupy 作者: cupy 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def fill_diagonal(a, val, wrap=False):
    """Fills the main diagonal of the given array of any dimensionality.

    For an array `a` with ``a.ndim > 2``, the diagonal is the list of
    locations with indices ``a[i, i, ..., i]`` all identical. This function
    modifies the input array in-place, it does not return a value.

    Args:
        a (cupy.ndarray): The array, at least 2-D.
        val (scalar): The value to be written on the diagonal.
            Its type must be compatible with that of the array a.
        wrap (bool): If specified, the diagonal is "wrapped" after N columns.
            This affects only tall matrices.

    Examples
    --------
    >>> a = cupy.zeros((3, 3), int)
    >>> cupy.fill_diagonal(a, 5)
    >>> a
    array([[5, 0, 0],
           [0, 5, 0],
           [0, 0, 5]])

     .. seealso:: :func:`numpy.fill_diagonal`
    """
    # The followings are imported from the original numpy
    if a.ndim < 2:
        raise ValueError('array must be at least 2-d')
    end = None
    if a.ndim == 2:
        step = a.shape[1] + 1
        if not wrap:
            end = a.shape[1] * a.shape[1]
    else:
        if not numpy.alltrue(numpy.diff(a.shape) == 0):
            raise ValueError('All dimensions of input must be of equal length')
        step = 1 + numpy.cumprod(a.shape[:-1]).sum()

    # Since the current cupy does not support a.flat,
    # we use a.ravel() instead of a.flat
    a.ravel()[:end:step] = val
electrostatics.py 文件源码 项目:electrostatics 作者: tomduck 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def fluxpoints(self, field, n, uniform=False):
        """Returns points where field lines should enter/exit the surface.

        The flux points are usually chosen so that they are equally separated
        in electric field flux.  However, if 'uniform' is True then the points
        are equispaced.

        This method requires that the flux be in xor out everywhere on the
        circle (unless 'uniform' is True)."""

        # Create a dense array of points around the circle
        a = radians(linspace(0, 360, 1001)) + self.a0
        assert len(a)%4 == 1
        x = self.r*array([cos(a), sin(a)]).T + self.x

        if uniform:
            flux = ones_like(a)

        else:
            # Get the flux through each point.  Ensure the fluxes are either
            # all in or all out.
            flux = field.projection(x, a)

            if numpy.sum(flux) < 0:
                flux *= -1
            assert alltrue(flux > 0)

        # Create an integrated flux curve
        intflux = insert(cumsum((flux[:-1]+flux[1:])/2), 0, 0)
        assert isclose(intflux[-1], numpy.sum(flux[:-1]))

        # Divide the integrated flux curve into n+1 portions, and calculate
        # the corresponding angles.
        v = linspace(0, intflux[-1], n+1)
        a = lininterp2(intflux, a, v)[:-1]

        return self.r*array([cos(a), sin(a)]).T + self.x
transforms.py 文件源码 项目:kaggle-seizure-prediction 作者: sics-lm 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def apply(self, data):
        # so that correlation matrix calculation doesn't crash
        for ch in data:
            if np.alltrue(ch == 0.0):
                ch[-1] += 0.00001

        data1 = data

        # if data1.shape[1] > self.max_hz:
        #     data1 = Resample(self.max_hz).apply(data1)

        if self.scale_option == 'usf':
            data1 = UnitScaleFeat().apply(data1)
        elif self.scale_option == 'us':
            data1 = UnitScale().apply(data1)

        data1 = CorrelationMatrix().apply(data1)

        if self.with_eigen:
            w = Eigenvalues().apply(data1)

        out = []
        if self.with_corr:
            data1 = upper_right_triangle(data1)
            out.append(data1)
        if self.with_eigen:
            out.append(w)

        for d in out:
            assert d.ndim == 1

        res = np.concatenate(out, axis=0)

        return res
test_regression.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_method_args(self, level=rlevel):
        # Make sure methods and functions have same default axis
        # keyword and arguments
        funcs1 = ['argmax', 'argmin', 'sum', ('product', 'prod'),
                 ('sometrue', 'any'),
                 ('alltrue', 'all'), 'cumsum', ('cumproduct', 'cumprod'),
                 'ptp', 'cumprod', 'prod', 'std', 'var', 'mean',
                 'round', 'min', 'max', 'argsort', 'sort']
        funcs2 = ['compress', 'take', 'repeat']

        for func in funcs1:
            arr = np.random.rand(8, 7)
            arr2 = arr.copy()
            if isinstance(func, tuple):
                func_meth = func[1]
                func = func[0]
            else:
                func_meth = func
            res1 = getattr(arr, func_meth)()
            res2 = getattr(np, func)(arr2)
            if res1 is None:
                res1 = arr

            if res1.dtype.kind in 'uib':
                assert_((res1 == res2).all(), func)
            else:
                assert_(abs(res1-res2).max() < 1e-8, func)

        for func in funcs2:
            arr1 = np.random.rand(8, 7)
            arr2 = np.random.rand(8, 7)
            res1 = None
            if func == 'compress':
                arr1 = arr1.ravel()
                res1 = getattr(arr2, func)(arr1)
            else:
                arr2 = (15*arr2).astype(int).ravel()
            if res1 is None:
                res1 = getattr(arr1, func)(arr2)
            res2 = getattr(np, func)(arr1, arr2)
            assert_(abs(res1-res2).max() < 1e-8, func)
test_regression.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_fromiter_bytes(self):
        # Ticket #1058
        a = np.fromiter(list(range(10)), dtype='b')
        b = np.fromiter(list(range(10)), dtype='B')
        assert_(np.alltrue(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
        assert_(np.alltrue(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
test_regression.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_fromiter_comparison(self, level=rlevel):
        a = np.fromiter(list(range(10)), dtype='b')
        b = np.fromiter(list(range(10)), dtype='B')
        assert_(np.alltrue(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
        assert_(np.alltrue(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))


问题


面经


文章

微信
公众号

扫码关注公众号