Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
linebuf = raw_input("Please enter some words to plot, or empty for a canned list: ")
while linebuf:
buf += linebuf + " "
linebuf = raw_input("... ")
labels = buf.split() \
or "doctor nurse politician senator lawyer barrister defend accuse heal treat cure elect vote".split()
vs = [a.w(x) for x in labels if a.w(x) is not None ]
flatplot = TSNE(2)
ps = flatplot.fit_transform(vs)
plt.title("Reduced vector space model")
plt.xlabel("First Principal Component")
plt.ylabel("Second Principal Component")
plt.scatter(ps[:, 0], ps[:, 1])
for (x, y), label in zip(ps, labels):
print "plotting %f, %f, %s" %(x, y, label)
plt.annotate(label, xy = (x, y), xytext = (0, 0), textcoords = 'offset points')
plt.show()
returnax = False
fig = pl.figure()
ax = fig.add_subplot(111)
else:
returnax = True
# actual plotting
for y in np.arange(0, 10000., vert_res):
ax.axhline(y=y, color="grey")
for x in ranges:
ax.axvline(x=x, color="grey")
for i in range(len(elevs)):
ax.plot(ranges, alt[i, :], lw=2, color="black")
pl.ylim(top=maxalt)
ax.tick_params(labelsize="large")
pl.xlabel("Range (m)", size="large")
pl.ylabel("Height over radar (m)", size="large")
for i, elev in enumerate(elevs):
x = ranges[-1] + 1500.
y = alt[i, :][-1]
if y > maxalt:
ix = np.where(alt[i, :] < maxalt)[0][-1]
x = ranges[ix]
y = maxalt + 100.
pl.text(x, y, str(elev), fontsize="large")
if returnax:
return ax
pl.show()
target_vals = flattenList(target_vals)
model_vals = flattenList(model_vals)
target_ses = flattenList(target_ses)
model_ses = flattenList(model_ses)
plt.figure()
plt.title("Fst, target vs. model calcs, " + str(numReps) + " reps")
ind = [x + .6 for x in np.arange(len(popPairs))]
ind2 = [x + 1 for x in np.arange(len(popPairs))]
plt.bar(ind, target_vals, color = targetcolor, width =.4, label="target", yerr=target_ses)
plt.bar(ind2, model_vals, color = modelcolor, width =.4, yerr=model_ses, label="model")
plt.legend(loc='best')
plt.xticks(ind2, popPairLabels, fontsize=10)
plt.xlabel('pop pair')
plt.ylabel('Fst')
plt.show()
plt.close()
return
trainer = gluon.Trainer(net.collect_params(),
trainer_name, trainer_hyperparams)
for _ in range(num_epochs):
start = time.time()
for batch_i, (X, y) in enumerate(data_iter):
with autograd.record():
l = loss(net(X), y)
l.backward()
trainer.step(batch_size)
if (batch_i + 1) * batch_size % 100 == 0:
ls.append(eval_loss())
print('loss: %f, %f sec per epoch' % (ls[-1], time.time() - start))
set_figsize()
plt.plot(np.linspace(0, num_epochs, len(ls)), ls)
plt.xlabel('epoch')
plt.ylabel('loss')
x_display[int(z_centerline_voxel[i] - z_centerline_voxel[0])] = x_centerline[i]
y_display[int(z_centerline_voxel[i] - z_centerline_voxel[0])] = y_centerline[i]
plt.figure(1)
plt.subplot(2, 1, 1)
plt.plot(z_centerline_voxel, x_display, 'ro')
plt.plot(z_centerline_voxel, x_centerline_voxel)
plt.xlabel("Z")
plt.ylabel("X")
plt.title("x and x_fit coordinates")
plt.subplot(2, 1, 2)
plt.plot(z_centerline_voxel, y_display, 'ro')
plt.plot(z_centerline_voxel, y_centerline_voxel)
plt.xlabel("Z")
plt.ylabel("Y")
plt.title("y and y_fit coordinates")
plt.show()
# Create an image with the centerline
min_z_index, max_z_index = int(round(min(z_centerline_voxel))), int(round(max(z_centerline_voxel)))
for iz in range(min_z_index, max_z_index + 1):
data[int(round(x_centerline_voxel[iz - min_z_index])), int(round(y_centerline_voxel[iz - min_z_index])), int(iz)] = 1 # if index is out of bounds here for hanning: either the segmentation has holes or labels have been added to the file
# Write the centerline image in RPI orientation
# hdr.set_data_dtype('uint8') # set imagetype to uint8
sct.printv('\nWrite NIFTI volumes...', verbose)
im_seg.data = data
im_seg.setFileName('centerline_RPI.nii.gz')
im_seg.changeType('uint8')
im_seg.save()
sct.printv('\nSet to original orientation...', verbose)
# Age/Survived
fig, ax = plt.subplots(1, 2, figsize = (18, 8))
sns.violinplot("Pclass", "Age", hue="Survived", data=train_data, split=True, ax=ax[0])
ax[0].set_title('Pclass and Age vs Survived')
ax[0].set_yticks(range(0, 110, 10))
sns.violinplot("Sex", "Age", hue="Survived", data=train_data, split=True, ax=ax[1])
ax[1].set_title('Sex and Age vs Survived')
ax[1].set_yticks(range(0, 110, 10))
# Age
plt.figure(figsize = (12, 5))
plt.subplot(121)
DataSet['Age'].hist(bins=70)
plt.xlabel('Age')
plt.ylabel('Num')
plt.subplot(122)
DataSet.boxplot(column='Age', showfliers=False)
plt.show()
facet = sns.FacetGrid(DataSet, hue = "Survived", aspect = 4)
facet.map(sns.kdeplot, 'Age', shade = True)
facet.set(xlim = (0, DataSet['Age'].max()))
facet.add_legend()
# average survived passsengers by age
fig, axis1 = plt.subplots(1, 1, figsize = (18, 4))
DataSet["Age_int"] = DataSet["Age"].astype(int)
average_age = DataSet[["Age_int", "Survived"]].groupby(['Age_int'], as_index = False).mean()
sns.barplot(x = 'Age_int', y = 'Survived', data = average_age)
def plot_network_history(history, suffix):
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
name = 'model train vs validation loss, ' + suffix
plt.title(name)
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'validation'], loc='upper right')
plt.savefig(f'figures/{name}.png')
plt.show()
def plot_confusion_matrix(cls_pred):
cls_true = data.test.cls
cm = confusion_matrix(cls_true, cls_pred)
print(cm)
plt.matshow(cm)
plt.xlabel("Predicted")
plt.ylabel("True")
plt.show()
'''define a function to predict using batch'''
plt.subplot(2, 2, 1)
plt.plot(ts, data[error_names[plot_axis]])
plt.ylabel(error_names[plot_axis])
plt.subplot(2, 2, 2)
plt.plot(ts, data[cumulative_error_names[plot_axis]])
plt.ylabel(cumulative_error_names[plot_axis])
plt.xlabel('Time (seconds)')
plt.subplot(2, 2, 3)
plt.plot(ts, data[control_names[plot_axis]])
plt.ylabel(control_names[plot_axis])
plt.xlabel('Time (seconds)')
plt.subplot(2, 2, 4)
plt.plot(ts, -data[goal_names[plot_axis]] + data[error_names[plot_axis]])
plt.plot(ts, data[goal_names[plot_axis]])
plt.legend(['position', 'goal'])
plt.ylabel(state_goal_names[plot_axis])
plt.xlabel('Time (seconds)')
plt.show()
R[iMic, jMic, :] = tempR[512:]
else:
R[iMic, jMic, :] = tempR[512:]
'''
import matplotlib.pyplot as plt
plt.figure()
plt.plot(R[0, 1, :])
plt.plot(R[0, 2, :], 'g')
plt.plot(R[0, 3, :], 'r')
plt.plot(R[0, 4, :], 'y')
# plt.cohere(Noise[:,0], Noise[:,1],NFFT=128, Fs=16000)
# plt.cohere(Noise[:, 0], Noise[:, 3],NFFT=128,Fs=16000)
# plt.cohere(Noise[:, 0], Noise[:, 5],NFFT=128, Fs=16000)
# plt.cohere(Noise[:, 0], Noise[:, 7],NFFT=128, Fs=16000)
plt.xlabel('frequency [Hz]')
plt.ylabel('Coherence')
plt.axis([0, 513, -0.5, 1])
plt.show()
return R