python not in range1002无标题_Python numpy.range方法代碼示例

本文整理匯總了Python中numpy.range方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.range方法的具體用法?Python numpy.range怎麽用?Python numpy.range使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在模塊numpy的用法示例。

在下文中一共展示了numpy.range方法的29個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Python代碼示例。

示例1: get_graph_nbrhd_paths

​點讚 6

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def get_graph_nbrhd_paths(train_graph, ent, exclude_tuple):

"""Helper to get neighbor (rels, ents) excluding a particular tuple."""

es, er, et = exclude_tuple

neighborhood = []

for i in range(train_graph.max_path_length):

if ent == es:

paths = _proc_paths(train_graph.paths[i][ent], er, et,

train_graph.max_path_length,

(train_graph.rel_pad, train_graph.ent_pad))

else:

paths = _proc_paths(train_graph.paths[i][ent],

max_length=train_graph.max_path_length,

pad=(train_graph.rel_pad, train_graph.ent_pad))

neighborhood += paths

if not neighborhood:

neighborhood = [[]]

neighborhood = np.array(neighborhood, dtype=np.int)

return neighborhood

開發者ID:tensorflow,項目名稱:neural-structured-learning,代碼行數:20,

示例2: ot2bio_ote

​點讚 6

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def ot2bio_ote(ote_tag_sequence):

"""

ot2bio function for ote tag sequence

:param ote_tag_sequence:

:return:

"""

new_ote_sequence = []

n_tag = len(ote_tag_sequence)

prev_ote_tag = '$$$'

for i in range(n_tag):

cur_ote_tag = ote_tag_sequence[i]

assert cur_ote_tag == 'O' or cur_ote_tag == 'T'

if cur_ote_tag == 'O':

new_ote_sequence.append(cur_ote_tag)

else:

# cur_ote_tag is T

if prev_ote_tag == 'T':

new_ote_sequence.append('I')

else:

# cur tag is at the beginning of the opinion target

new_ote_sequence.append('B')

prev_ote_tag = cur_ote_tag

return new_ote_sequence

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:25,

示例3: ot2bieos_batch

​點讚 6

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def ot2bieos_batch(ote_tags, ts_tags):

"""

batch version of function ot2bieos

:param ote_tags: a batch of ote tag sequence

:param ts_tags: a batch of ts tag sequence

:return:

:param ote_tags:

:param ts_tags:

:return:

"""

new_ote_tags, new_ts_tags = [], []

assert len(ote_tags) == len(ts_tags)

n_seqs = len(ote_tags)

for i in range(n_seqs):

ote, ts = ot2bieos(ote_tag_sequence=ote_tags[i], ts_tag_sequence=ts_tags[i])

new_ote_tags.append(ote)

new_ts_tags.append(ts)

return new_ote_tags, new_ts_tags

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:20,

示例4: bio2ot_batch

​點讚 6

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def bio2ot_batch(ote_tags, ts_tags):

"""

batch version of function bio2ot

:param ote_tags: a batch of ote tag sequence

:param ts_tags: a batch of ts tag sequence

:return:

"""

new_ote_tags, new_ts_tags = [], []

assert len(ote_tags) == len(ts_tags)

n_seqs = len(ote_tags)

for i in range(n_seqs):

ote, ts = bio2ot(ote_tag_sequence=ote_tags[i], ts_tag_sequence=ts_tags[i])

new_ote_tags.append(ote)

new_ts_tags.append(ts)

return new_ote_tags, new_ts_tags

# TODO

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:20,

示例5: set_cid

​點讚 6

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def set_cid(dataset, char_vocab):

"""

set cid field for the records in the dataset

:param dataset: dataset

:param char_vocab: vocabulary of character

:return:

"""

n_records = len(dataset)

cids = []

for i in range(n_records):

words = dataset[i]['words']

cids = []

for w in words:

cids.append([char_vocab[ch] for ch in list(w)])

dataset[i]['cids'] = list(cids)

return dataset

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:18,

示例6: conv_tower

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def conv_tower(inputs, filters_init, filters_mult=1, repeat=1, **kwargs):

"""Construct a reducing convolution block.

Args:

inputs: [batch_size, seq_length, features] input sequence

filters_init: Initial Conv1D filters

filters_mult: Multiplier for Conv1D filters

repeat: Conv block repetitions

Returns:

[batch_size, seq_length, features] output sequence

"""

# flow through variable current

current = inputs

# initialize filters

rep_filters = filters_init

for ri in range(repeat):

# convolution

current = conv_block(current,

filters=int(np.round(rep_filters)),

**kwargs)

# update filters

rep_filters *= filters_mult

return current

開發者ID:calico,項目名稱:basenji,代碼行數:31,

示例7: xception_tower

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def xception_tower(inputs, filters_init, filters_mult=1, repeat=1, **kwargs):

"""Construct a reducing convolution block.

Args:

inputs: [batch_size, seq_length, features] input sequence

filters_init: Initial Conv1D filters

filters_mult: Multiplier for Conv1D filters

repeat: Conv block repetitions

Returns:

[batch_size, seq_length, features] output sequence

"""

# flow through variable current

current = inputs

# initialize filters

rep_filters = filters_init

for ri in range(repeat):

# convolution

current = xception_block(current,

filters=int(np.round(rep_filters)),

**kwargs)

# update filters

rep_filters *= filters_mult

return current

############################################################

# Attention

############################################################

開發者ID:calico,項目名稱:basenji,代碼行數:36,

示例8: position_encoding

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def position_encoding(current, min_rate=.0001):

"""Add original Transformer positional encodings,

Args:

current: [batch_size, seq_length, features] sequence

min_rate:

Returns:

sequence w/ positional encodings concatenated.

"""

seq_length = current.shape[1].value

features = current.shape[2].value

assert(features % 2 == 0)

# compute angle rates

angle_rate_exponents = np.linspace(0, 1, features//2)

angle_rates = min_rate**angle_rate_exponents

# compute angle radians

positions = np.range(seq_length)

angle_rads = positions[:, np.newaxis] * angle_rates[np.newaxis, :]

# sines and cosines

sines = np.sin(angle_rads)

cosines = np.cos(angle_rads)

pos_encode = np.concatenate([sines, cosines], axis=-1)

return current

開發者ID:calico,項目名稱:basenji,代碼行數:31,

示例9: dense_image_warp

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def dense_image_warp(image, flow):

# batch_size, height, width, channels = (array_ops.shape(image)[0],

# array_ops.shape(image)[1],

# array_ops.shape(image)[2],

# array_ops.shape(image)[3])

batch_size, height, width, channels = (np.shape(image)[0],

np.shape(image)[1],

np.shape(image)[2],

np.shape(image)[3])

# The flow is defined on the image grid. Turn the flow into a list of query

# points in the grid space.

# grid_x, grid_y = array_ops.meshgrid(

# math_ops.range(width), math_ops.range(height))

# stacked_grid = math_ops.cast(

# array_ops.stack([grid_y, grid_x], axis=2), flow.dtype)

# batched_grid = array_ops.expand_dims(stacked_grid, axis=0)

# query_points_on_grid = batched_grid - flow

# query_points_flattened = array_ops.reshape(query_points_on_grid,

# [batch_size, height * width, 2])

grid_x, grid_y = np.meshgrid(

np.range(width), np.range(height))

stacked_grid = np.cast(

np.stack([grid_y, grid_x], axis=2), flow.dtype)

batched_grid = np.expand_dims(stacked_grid, axis=0)

query_points_on_grid = batched_grid - flow

query_points_flattened = np.reshape(query_points_on_grid,

[batch_size, height * width, 2])

# Compute values at the query points, then reshape the result back to the

# image grid.

interpolated = interp2d(image, query_points_flattened)

interpolated = np.reshape(interpolated,

[batch_size, height, width, channels])

return interpolated

開發者ID:DemisEom,項目名稱:SpecAugment,代碼行數:36,

示例10: _sample_next_edges

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def _sample_next_edges(edges, to_sample):

if len(edges) < to_sample:

return edges

sample_ids = np.random.choice(range(len(edges)), size=to_sample,

replace=False)

return [edges[i] for i in sample_ids]

開發者ID:tensorflow,項目名稱:neural-structured-learning,代碼行數:8,

示例11: sample_or_pad

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def sample_or_pad(arr, max_size, pad_value=-1):

"""Helper to pad arr along axis 0 to max_size or subsample to max_size."""

arr_shape = arr.shape

if arr.size == 0:

if isinstance(pad_value, list):

result = np.ones((max_size, len(pad_value)), dtype=arr.dtype) * pad_value

else:

result = np.ones((max_size,), dtype=arr.dtype) * pad_value

elif arr.shape[0] > max_size:

if arr.ndim == 1:

result = np.random.choice(arr, size=max_size, replace=False)

else:

idx = np.arange(arr.shape[0])

np.random.shuffle(idx)

result = arr[idx[:max_size], :]

else:

padding = np.ones((max_size-arr.shape[0],) + arr_shape[1:],

dtype=arr.dtype)

if isinstance(pad_value, list):

for i in range(len(pad_value)):

padding[..., i] *= pad_value[i]

else:

padding *= pad_value

result = np.concatenate((arr, padding), axis=0)

# result = np.pad(arr,

# [[0, max_size-arr.shape[0]]] + ([[0, 0]] * (arr.ndim-1)),

# "constant", constant_values=pad_value)

return result

開發者ID:tensorflow,項目名稱:neural-structured-learning,代碼行數:30,

示例12: ot2bio_ts

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def ot2bio_ts(ts_tag_sequence):

"""

ot2bio function for ts tag sequence

:param ts_tag_sequence:

:return:

"""

new_ts_sequence = []

n_tag = len(ts_tag_sequence)

prev_pos = '$$$'

for i in range(n_tag):

cur_ts_tag = ts_tag_sequence[i]

if cur_ts_tag == 'O':

new_ts_sequence.append('O')

cur_pos = 'O'

else:

# current tag is subjective tag, i.e., cur_pos is T

# print(cur_ts_tag)

cur_pos, cur_sentiment = cur_ts_tag.split('-')

if cur_pos == prev_pos:

# prev_pos is T

new_ts_sequence.append('I-%s' % cur_sentiment)

else:

# prev_pos is O

new_ts_sequence.append('B-%s' % cur_sentiment)

prev_pos = cur_pos

return new_ts_sequence

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:28,

示例13: ot2bio_ote_batch

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def ot2bio_ote_batch(ote_tag_seqs):

"""

batch version of function ot2bio_ote

:param ote_tags:

:return:

"""

new_ote_tag_seqs = []

n_seqs = len(ote_tag_seqs)

for i in range(n_seqs):

new_ote_seq = ot2bio_ote(ote_tag_sequence=ote_tag_seqs[i])

new_ote_tag_seqs.append(new_ote_seq)

return new_ote_tag_seqs

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:14,

示例14: ot2bio_ts_batch

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def ot2bio_ts_batch(ts_tag_seqs):

"""

batch version of function ot2bio_ts

:param ts_tag_seqs:

:return:

"""

new_ts_tag_seqs = []

n_seqs = len(ts_tag_seqs)

for i in range(n_seqs):

new_ts_seq = ot2bio_ts(ts_tag_sequence=ts_tag_seqs[i])

new_ts_tag_seqs.append(new_ts_seq)

return new_ts_tag_seqs

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:14,

示例15: ot2bio_batch

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def ot2bio_batch(ote_tags, ts_tags):

"""

batch version of function ot2bio

:param ote_tags: a batch of ote tag sequence

:param ts_tags: a batch of ts tag sequence

:return:

"""

new_ote_tags, new_ts_tags = [], []

assert len(ote_tags) == len(ts_tags)

n_seqs = len(ote_tags)

for i in range(n_seqs):

ote, ts = ot2bio(ote_tag_sequence=ote_tags[i], ts_tag_sequence=ts_tags[i])

new_ote_tags.append(ote)

new_ts_tags.append(ts)

return new_ote_tags, new_ts_tags

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:17,

示例16: ot2bieos_ts

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def ot2bieos_ts(ts_tag_sequence):

"""

ot2bieos function for ts task

:param ts_tag_sequence: tag sequence for targeted sentiment

:return:

"""

n_tags = len(ts_tag_sequence)

new_ts_sequence = []

prev_pos = '$$$'

for i in range(n_tags):

cur_ts_tag = ts_tag_sequence[i]

if cur_ts_tag == 'O':

new_ts_sequence.append('O')

cur_pos = 'O'

else:

cur_pos, cur_sentiment = cur_ts_tag.split('-')

# cur_pos is T

if cur_pos != prev_pos:

# prev_pos is O and new_cur_pos can only be B or S

if i == n_tags - 1:

new_ts_sequence.append('S-%s' % cur_sentiment)

else:

next_ts_tag = ts_tag_sequence[i + 1]

if next_ts_tag == 'O':

new_ts_sequence.append('S-%s' % cur_sentiment)

else:

new_ts_sequence.append('B-%s' % cur_sentiment)

else:

# prev_pos is T and new_cur_pos can only be I or E

if i == n_tags - 1:

new_ts_sequence.append('E-%s' % cur_sentiment)

else:

next_ts_tag = ts_tag_sequence[i + 1]

if next_ts_tag == 'O':

new_ts_sequence.append('E-%s' % cur_sentiment)

else:

new_ts_sequence.append('I-%s' % cur_sentiment)

prev_pos = cur_pos

return new_ts_sequence

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:41,

示例17: ot2bieos_ote_batch

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def ot2bieos_ote_batch(ote_tag_seqs):

"""

batch version of function ot2bieos_ote

:param ote_tags:

:return:

"""

new_ote_tag_seqs = []

n_seqs = len(ote_tag_seqs)

for i in range(n_seqs):

new_ote_seq = ot2bieos_ote(ote_tag_sequence=ote_tag_seqs[i])

new_ote_tag_seqs.append(new_ote_seq)

return new_ote_tag_seqs

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:14,

示例18: ot2bieos_ts_batch

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def ot2bieos_ts_batch(ts_tag_seqs):

"""

batch version of function ot2bieos_ts

:param ts_tag_seqs:

:return:

"""

new_ts_tag_seqs = []

n_seqs = len(ts_tag_seqs)

for i in range(n_seqs):

new_ts_seq = ot2bieos_ts(ts_tag_sequence=ts_tag_seqs[i])

new_ts_tag_seqs.append(new_ts_seq)

return new_ts_tag_seqs

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:14,

示例19: bio2ot_ote

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def bio2ot_ote(ote_tag_sequence):

"""

perform bio-->ot for ote tag sequence

:param ote_tag_sequence:

:return:

"""

new_ote_sequence = []

n_tags = len(ote_tag_sequence)

for i in range(n_tags):

ote_tag = ote_tag_sequence[i]

if ote_tag == 'B' or ote_tag == 'I':

new_ote_sequence.append('T')

else:

new_ote_sequence.append('I')

return new_ote_sequence

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:17,

示例20: bio2ot_ote_batch

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def bio2ot_ote_batch(ote_tag_seqs):

"""

batch version of function bio2ot_ote

:param ote_tag_seqs: ote tag sequences

:return:

"""

new_ote_tag_seqs = []

n_seqs = len(ote_tag_seqs)

for i in range(n_seqs):

new_ote_seq = bio2ot_ote(ote_tag_sequence=ote_tag_seqs[i])

new_ote_tag_seqs.append(new_ote_seq)

return new_ote_tag_seqs

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:14,

示例21: bio2ot_ts_batch

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def bio2ot_ts_batch(ts_tag_seqs):

"""

batch version of function bio2ot_ts

:param ts_tag_seqs:

:return:

"""

new_ts_tag_seqs = []

n_seqs = len(ts_tag_seqs)

for i in range(n_seqs):

new_ts_seq = bio2ot_ts(ts_tag_sequence=ts_tag_seqs[i])

new_ts_tag_seqs.append(new_ts_seq)

return new_ts_tag_seqs

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:14,

示例22: set_wid

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def set_wid(dataset, vocab, win=1):

"""

set wid field for the dataset

:param dataset: dataset

:param vocab: vocabulary

:param win: context window size, for window-based input, should be an odd number

:return: dataset with field wid

"""

n_records = len(dataset)

for i in range(n_records):

words = dataset[i]['words']

lm_labels = []

# set labels for the auxiliary language modeling task

for w in words:

lm_labels.append(vocab[w])

dataset[i]['lm_labels'] = list(lm_labels)

n_padded_words = win // 2

pad_left = ['PADDING' for _ in range(n_padded_words)]

pad_right = ['PADDING' for _ in range(n_padded_words)]

padded_words = pad_left + words + pad_right

# the window-based input

win_input = list(ngrams(padded_words, win))

assert len(win_input) == len(words)

n_grams = []

for t in win_input:

n_grams.append(t)

wids = [[vocab[w] for w in ngram] for ngram in n_grams]

dataset[i]['wids'] = list(wids)

return dataset

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:31,

示例23: set_padding

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def set_padding(dataset, max_len):

n_records = len(dataset)

for i in range(n_records):

sent_len = len(dataset[i]['words'])

words = dataset[i]['words'] + ['PADDING'] * (max_len-sent_len)

ote_tags = dataset[i]['ote_raw_tags'] + ['O'] * (max_len-sent_len)

ts_tags = dataset[i]['ts_raw_tags'] + ['O'] * (max_len-sent_len)

dataset[i]['words'] = list(words)

dataset[i]['ote_raw_tags'] = list(ote_tags)

dataset[i]['ts_raw_tags'] = list(ts_tags)

dataset[i]['length'] = sent_len

return dataset

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:17,

示例24: to_conll

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def to_conll(train, val, test, embeddings, vocab, ds_name):

"""

:param train: training dataset

:param val: validation / development dataset

:param test: testing dataset

:param embeddings: pre-trained word embeddings

:param vocab: vocabulary

:return:

"""

inv_vocab = {}

for w in vocab:

wid = vocab[w]

inv_vocab[wid] = w

train_lines = semeval2conll(dataset=train)

dev_lines = semeval2conll(dataset=val)

test_lines = semeval2conll(dataset=test)

base_folder = '/projdata9/info_fil/lixin/Research/NCRFpp/sample_data'

with open('%s/%s_train.txt' % (base_folder, ds_name), 'w+') as fp:

fp.writelines(train_lines)

with open('%s/%s_dev.txt' % (base_folder, ds_name), 'w+') as fp:

fp.writelines(dev_lines)

with open('%s/%s_test.txt' % (base_folder, ds_name), 'w+') as fp:

fp.writelines(test_lines)

emb_lines = []

for i in range(len(embeddings)):

word = inv_vocab[i]

emb_vec = embeddings[i]

emb_lines.append('%s %s\n' % (word, ' '.join([str(ele) for ele in emb_vec])))

# write the embeddings back to the NCRFpp foler

with open('%s/%s_emb.txt' % (base_folder, ds_name), 'w+') as fp:

fp.writelines(emb_lines)

開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:35,

示例25: covariances

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def covariances(X, estimator='cov'):

est = _check_est(estimator)

Nt, Ne, Ns = X.shape

covmats = numpy.zeros((Nt, Ne, Ne))

for i in range(Nt):

covmats[i, :, :] = est(X[i, :, :])

return covmats

開發者ID:alexandrebarachant,項目名稱:decoding-brain-challenge-2016,代碼行數:9,

示例26: covariances_EP

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def covariances_EP(X, P, estimator='cov'):

est = _check_est(estimator)

Nt, Ne, Ns = X.shape

Np, Ns = P.shape

covmats = numpy.zeros((Nt, Ne + Np, Ne + Np))

for i in range(Nt):

covmats[i, :, :] = est(numpy.concatenate((P, X[i, :, :]), axis=0))

return covmats

開發者ID:alexandrebarachant,項目名稱:decoding-brain-challenge-2016,代碼行數:10,

示例27: coherence

​點讚 5

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def coherence(X, nfft=256, fs=2, noverlap=0):

"""Compute coherence."""

n_chan = X.shape[0]

ij = []

for i in range(n_chan):

for j in range(i+1, n_chan):

ij.append((i, j))

Cxy, Phase, freqs = mlab.cohere_pairs(X, ij, NFFT=nfft, Fs=fs,

noverlap=noverlap)

coh = numpy.zeros((n_chan, n_chan, len(freqs)))

for i in range(n_chan):

coh[i, i] = 1

for j in range(i+1, n_chan):

coh[i, j] = coh[j, i] = Cxy[(i, j)]

return coh

開發者ID:alexandrebarachant,項目名稱:decoding-brain-challenge-2016,代碼行數:17,

示例28: xception_block

​點讚 4

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def xception_block(inputs, filters=None, kernel_size=1,

dropout=0, pool_size=2, **kwargs):

"""Construct a single convolution block.

Args:

inputs: [batch_size, seq_length, features] input sequence

filters: Conv1D filters

kernel_size: Conv1D kernel_size

dropout: Dropout rate probability

pool_size: Pool/stride width

Returns:

[batch_size, seq_length, features] output sequence

"""

# flow through variable current

current = inputs

if filters is None:

filters = inputs.shape[-1]

# strided convolution

current_stride = conv_block(current,

filters=filters,

kernel_size=pool_size,

strides=pool_size,

dropout=0,

kernel_initializer='ones',

**kwargs)

# pooled convolution

current_pool = current

for ci in range(2):

current_pool = conv_block(current_pool,

filters=filters,

kernel_size=kernel_size,

conv_type='separable',

dropout=dropout,

**kwargs)

# should the last conv_block be set to bn_gamma='zeros'?

# I don't think so since we really need that new information

# max pool

current_pool = tf.keras.layers.MaxPool1D(

pool_size=int(1.5*pool_size),

strides=pool_size,

padding='same')(current_pool)

# residual add

current = tf.keras.layers.Add()([current_stride,current_pool])

return current

############################################################

# Towers

############################################################

開發者ID:calico,項目名稱:basenji,代碼行數:60,

示例29: res_tower

​點讚 4

# 需要導入模塊: import numpy [as 別名]

# 或者: from numpy import range [as 別名]

def res_tower(inputs, filters_init, filters_mult=1, dropout=0,

pool_size=2, repeat=1, num_convs=2, **kwargs):

"""Construct a reducing convolution block.

Args:

inputs: [batch_size, seq_length, features] input sequence

filters_init: Initial Conv1D filters

filters_mult: Multiplier for Conv1D filters

dropout: Dropout on subsequent convolution blocks.

repeat: Residual block repetitions

num_convs: Conv blocks per residual layer

Returns:

[batch_size, seq_length, features] output sequence

"""

# flow through variable current

current = inputs

# initialize filters

rep_filters = filters_init

for ri in range(repeat):

rep_filters_int = int(np.round(rep_filters))

# initial

current = conv_block(current,

filters=rep_filters_int,

dropout=0,

bn_gamma='ones',

**kwargs)

current0 = current

# subsequent

for ci in range(1,num_convs):

bg = 'ones' if ci < num_convs-1 else 'zeros'

current = conv_block(current,

filters=rep_filters_int,

dropout=dropout,

bn_gamma=bg,

**kwargs)

# residual add

current = tf.keras.layers.Add()([current0,current])

# pool

if pool_size > 1:

current = tf.keras.layers.MaxPool1D(

pool_size=pool_size,

padding='same')(current)

# update filters

rep_filters *= filters_mult

return current

開發者ID:calico,項目名稱:basenji,代碼行數:57,

注:本文中的numpy.range方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值