Exemplo n.º 1
0
    def test_setdiff1d(self):
        a = np.array([6, 5, 4, 7, 1, 2, 7, 4])
        b = np.array([2, 4, 3, 3, 2, 1, 5])

        ec = np.array([6, 7])
        c = setdiff1d(a, b)
        assert_array_equal(c, ec)

        a = np.arange(21)
        b = np.arange(19)
        ec = np.array([19, 20])
        c = setdiff1d(a, b)
        assert_array_equal(c, ec)

        assert_array_equal([], setdiff1d([], []))
    def test_setdiff1d(self):
        a = np.array([6, 5, 4, 7, 1, 2, 7, 4])
        b = np.array([2, 4, 3, 3, 2, 1, 5])

        ec = np.array([6, 7])
        c = setdiff1d(a, b)
        assert_array_equal(c, ec)

        a = np.arange(21)
        b = np.arange(19)
        ec = np.array([19, 20])
        c = setdiff1d(a, b)
        assert_array_equal(c, ec)

        assert_array_equal([], setdiff1d([], []))
Exemplo n.º 3
0
def setdiff1d(a, b):
    """
    setdiff1d(a, b) returns the elements of a that are not in b.
    """
    from MDSplus import Data
    from numpy.lib.arraysetops import setdiff1d
    return Data(setdiff1d(a.data(),b.data()))
Exemplo n.º 4
0
    def filter(self, u_ind, job_inds, return_appd=False):
        '''
        Removes the jobs the user has already applied to.

        Parameters
        ----------
        u_ind: int
               The index in the User-Job application co-occur matrix
        job_inds: list of ints
                  This is a list of job indices   
        return_appd: boolean
                     if True, return the jobs applied to by u_ind as well
                     
        Returns
        -------
        A filted list of job indices excluding the indices to jobs the user
        has already applied for.
        
        Optionally, returns the jobs the user applied to as well.
        '''
        
        applied_inds = nonzero(self.UserJobOccurs[u_ind,:])[1]
        filtered = setdiff1d(job_inds,applied_inds)
        if return_appd:
            return filtered, applied_inds
        else:
            return filtered 
Exemplo n.º 5
0
    def test_manyways(self):
        a = np.array([5, 7, 1, 2, 8])
        b = np.array([9, 8, 2, 4, 3, 1, 5])

        c1 = setxor1d(a, b)
        aux1 = intersect1d(a, b)
        aux2 = union1d(a, b)
        c2 = setdiff1d(aux2, aux1)
        assert_array_equal(c1, c2)
    def test_manyways(self):
        a = np.array([5, 7, 1, 2, 8])
        b = np.array([9, 8, 2, 4, 3, 1, 5])

        c1 = setxor1d(a, b)
        aux1 = intersect1d(a, b)
        aux2 = union1d(a, b)
        c2 = setdiff1d(aux2, aux1)
        assert_array_equal(c1, c2)
Exemplo n.º 7
0
    def test_naive_aggregation(self):
        for A in self.cases:
            S = symmetric_strength_of_connection(A)

            (expected, expected_Cpts) = reference_naive_aggregation(S)
            (result, Cpts) = naive_aggregation(S)

            assert_equal((result - expected).nnz, 0)
            assert_equal(Cpts.shape[0], expected_Cpts.shape[0])
            assert_equal(setdiff1d(Cpts, expected_Cpts).shape[0], 0)
Exemplo n.º 8
0
    def test_naive_aggregation(self):
        for A in self.cases:
            S = symmetric_strength_of_connection(A)
            
            (expected,expected_Cpts) = reference_naive_aggregation(S)
            (result,Cpts)   = naive_aggregation(S)

            assert_equal( (result - expected).nnz, 0 )
            assert_equal( Cpts.shape[0], expected_Cpts.shape[0])
            assert_equal( setdiff1d(Cpts, expected_Cpts).shape[0], 0)
Exemplo n.º 9
0
    def test_naive_aggregation(self):
        for A in self.cases:
            S = symmetric_strength_of_connection(A)

            (expected, expected_Cpts) = reference_naive_aggregation(S)
            (result, Cpts) = naive_aggregation(S)

            assert_equal((result - expected).nnz, 0)
            assert_equal(Cpts.shape[0], expected_Cpts.shape[0])
            assert_equal(setdiff1d(Cpts, expected_Cpts).shape[0], 0)

        # S is diagonal - no dofs aggregated
        S = spdiags([[1, 1, 1, 1]], [0], 4, 4, format='csr')
        (result, Cpts) = naive_aggregation(S)
        expected = numpy.eye(4)
        assert_equal(result.todense(), expected)
        assert_equal(Cpts.shape[0], 4)
Exemplo n.º 10
0
    def test_naive_aggregation(self):
        for A in self.cases:
            S = symmetric_strength_of_connection(A)
            
            (expected,expected_Cpts) = reference_naive_aggregation(S)
            (result,Cpts)   = naive_aggregation(S)

            assert_equal( (result - expected).nnz, 0 )
            assert_equal( Cpts.shape[0], expected_Cpts.shape[0])
            assert_equal( setdiff1d(Cpts, expected_Cpts).shape[0], 0)
    
        # S is diagonal - no dofs aggregated
        S = spdiags([[1,1,1,1]],[0],4,4,format='csr')
        (result, Cpts)   = naive_aggregation(S)
        expected = numpy.eye(4)
        assert_equal(result.todense(),expected)
        assert_equal(Cpts.shape[0], 4)
Exemplo n.º 11
0
 def test_setdiff1d_char_array(self):
     a = np.array(['a', 'b', 'c'])
     b = np.array(['a', 'b', 's'])
     assert_array_equal(setdiff1d(a, b), np.array(['c']))
Exemplo n.º 12
0
 def test_setdiff1d_unique(self):
     a = np.array([3, 2, 1])
     b = np.array([7, 5, 2])
     expected = np.array([3, 1])
     actual = setdiff1d(a, b, assume_unique=True)
     assert_equal(actual, expected)
Exemplo n.º 13
0
def ghost_layer(submesh, mesh, p, tupper, tlower, parameters = None):

    ncoord = mesh.number_of_nodes
    ntriangles = mesh.number_of_triangles

    if parameters is None:
        layer_width  = 2
    else:
        layer_width = parameters['ghost_layer_width']


    full_ids = num.arange(tlower, tupper)

    n0 = mesh.neighbours[full_ids, :]
    n0 = num.unique(n0.flat)
    n0 = num.extract(n0>=0,n0)
    n0 = num.extract(num.logical_or(n0<tlower, tupper<= n0), n0)

    layer_cells = {}
    layer_cells[0] = n0


    # Find the subsequent layers of ghost triangles
    for i in range(layer_width-1):

        # use previous layer as a start
        n0 = mesh.neighbours[n0, :]
        n0 = num.unique(n0.flat)
        n0 = num.extract(n0>=0,n0)
        n0 = num.extract(num.logical_or(n0<tlower, tupper<= n0), n0)

        for j in xrange(i+1):
            n0 = numset.setdiff1d(n0,layer_cells[j])

        layer_cells[i+1] = n0


    # Build the triangle list and make note of the vertices
    new_trianglemap = layer_cells[0]
    for i in range(layer_width-1):
        new_trianglemap = numset.union1d(new_trianglemap,layer_cells[i+1])

    new_subtriangles = num.concatenate((num.reshape(new_trianglemap, (-1,1)), mesh.triangles[new_trianglemap]), 1)




    fullnodes = submesh["full_nodes"][p]
    full_nodes_ids = num.array(fullnodes[:,0],num.int)

    new_nodes = num.unique(mesh.triangles[new_trianglemap].flat)
    new_nodes = numset.setdiff1d(new_nodes,full_nodes_ids)

    new_subnodes = num.concatenate((num.reshape(new_nodes, (-1,1)), mesh.nodes[new_nodes]), 1)

    # Clean up before exiting

    del (new_nodes)
    del (layer_cells)
    del (n0)
    del (new_trianglemap)

    # Return the triangles and vertices sitting on the boundary layer

    return new_subnodes, new_subtriangles, layer_width
Exemplo n.º 14
0
 def test_setdiff1d_char_array(self):
     a = np.array(["a", "b", "c"])
     b = np.array(["a", "b", "s"])
     assert_array_equal(setdiff1d(a, b), np.array(["c"]))
Exemplo n.º 15
0
def ghost_layer(submesh, mesh, p, tupper, tlower, parameters=None):

    ncoord = mesh.number_of_nodes
    ntriangles = mesh.number_of_triangles

    if parameters is None:
        layer_width = 2
    else:
        layer_width = parameters['ghost_layer_width']

    full_ids = num.arange(tlower, tupper)

    n0 = mesh.neighbours[full_ids, :]
    n0 = num.unique(n0.flat)
    n0 = num.extract(n0 >= 0, n0)
    n0 = num.extract(num.logical_or(n0 < tlower, tupper <= n0), n0)

    layer_cells = {}
    layer_cells[0] = n0

    # Find the subsequent layers of ghost triangles
    for i in range(layer_width - 1):

        # use previous layer as a start
        n0 = mesh.neighbours[n0, :]
        n0 = num.unique(n0.flat)
        n0 = num.extract(n0 >= 0, n0)
        n0 = num.extract(num.logical_or(n0 < tlower, tupper <= n0), n0)

        for j in range(i + 1):
            n0 = numset.setdiff1d(n0, layer_cells[j])

        layer_cells[i + 1] = n0

    # Build the triangle list and make note of the vertices
    new_trianglemap = layer_cells[0]
    for i in range(layer_width - 1):
        new_trianglemap = numset.union1d(new_trianglemap, layer_cells[i + 1])

    new_subtriangles = num.concatenate(
        (num.reshape(new_trianglemap,
                     (-1, 1)), mesh.triangles[new_trianglemap]), 1)

    fullnodes = submesh["full_nodes"][p]
    full_nodes_ids = num.array(fullnodes[:, 0], num.int)

    new_nodes = num.unique(mesh.triangles[new_trianglemap].flat)
    new_nodes = numset.setdiff1d(new_nodes, full_nodes_ids)

    new_subnodes = num.concatenate(
        (num.reshape(new_nodes, (-1, 1)), mesh.nodes[new_nodes]), 1)

    # Clean up before exiting

    del (new_nodes)
    del (layer_cells)
    del (n0)
    del (new_trianglemap)

    # Return the triangles and vertices sitting on the boundary layer

    return new_subnodes, new_subtriangles, layer_width
 def test_setdiff1d_char_array(self):
     a = np.array(['a', 'b', 'c'])
     b = np.array(['a', 'b', 's'])
     assert_array_equal(setdiff1d(a, b), np.array(['c']))
Exemplo n.º 17
0
import matplotlib.pyplot as plt
import numpy.lib.arraysetops as aso

lr = linear_model.LinearRegression()

rcv = linear_model.RidgeCV()

boston = datasets.load_boston()
y = boston.target

# cross_val_predict returns an array of the same size as `y` where each entry
# is a prediction obtained by cross validation:
predicted = cross_val_predict(lr, boston.data, y, cv=10)
predicted2 = cross_val_predict(rcv, boston.data, y, cv=10)

print aso.setdiff1d(predicted, predicted2)

# which one is better?

print type(predicted2)
print rcv

fig, ax = plt.subplots()
ax.scatter(y, predicted)
ax.plot([y.min(), y.max()], [y.min(), y.max()], 'k--', lw=4)
ax.set_xlabel('Measured')
ax.set_ylabel('Predicted')
plt.show()

fig, ax = plt.subplots()
ax.scatter(y, predicted2)
Exemplo n.º 18
0
 def test_setdiff1d_unique(self):
     a = np.array([3, 2, 1])
     b = np.array([7, 5, 2])
     expected = np.array([3, 1])
     actual = setdiff1d(a, b, assume_unique=True)
     assert_equal(actual, expected)
Exemplo n.º 19
0
    sys.exit(1)

file1, file2 = sys.argv[1:]

if os.path.isfile(file1) != True:
    sys.stderr.write('\nERROR: file ' + file1 + ' not found\n')
    sys.exit(1)
elif os.path.isfile(file2) != True:
    sys.stderr.write('\nERROR: file ' + file2 + ' not found\n')
    sys.exit(1)

#open the 2 files
var_file = pd.read_csv(file1, sep='\t', usecols=[0], chunksize=1000000)
annotation = pd.read_csv(file2, sep='\t', usecols=[0])

print 'Chunking the var matrix...'
for c in var_file:
    #check if all the var in the var_file are in the geno_annotation file
    diff = aso.setdiff1d(c.values, annotation.values)
    print 'Check consistency between the var_file colnames chunk and the annotation file colnames'
    #check consistency between var_file and geno_annotation file
    if diff.shape[0] != 0:
        for var in diff:
            sys.stderr.write('\nERROR: variant ' + var +
                             ' not found in the annotation file\n')
        sys.exit(1)
    else:
        print 'OK!'

sys.exit(0)