<jupyter_start><jupyter_text>Setting up Persistent Homology Creating Persistent Homology<jupyter_code># Generate noisy data on two concentric spheres
D = 4
N = 1000
K = 4
trueLabels = np.append(np.ones([int(N/2), 1]), 2 * np.ones([int(N/2), 1])).reshape(N,1)

var = 0.01

# cluster 1
X1 = np.random.randn(D, int(N/2))
X1 = X1 / np.tile(np.sqrt(sum(X1**2)), (D,1))
X1 = X1 + np.tile(np.sqrt(var) * np.random.randn(1, int(N/2)), (D,1))

# cluster 2
X2 = np.random.randn(D, int(N/2))
X2 = 2*X2 / np.tile(np.sqrt(sum(X2**2)), (D,1))
X2 = X2 + np.tile(np.sqrt(var) * np.random.randn(1, int(N/2)), (D,1))
X = X1

# Data visualization
plt.figure(figsize=(6,6))
ax = plt.axes(projection='3d')
#plt.scatter(X[0], X[1], marker='X')

Z = np.random.normal(1,.0001,len(X[1]))
ax.scatter3D(X[0], X[1], Z,marker='X', c='blue')
#plt.scatter(X[0, int(N/2):N], X[1, int(N/2):N], marker='X')

plt.title("Sythetic Data - True Clusters")
plt.show()
result = ripser(X.T, coeff=2, do_cocycles=True)
diagrams = result['dgms']
cocycles = result['cocycles']
D = result['dperm2all']
dgm1 = diagrams[1]
idx = np.argmax(dgm1[:, 1] - dgm1[:, 0])
plot_diagrams(diagrams, show = False)
plt.scatter(dgm1[idx, 0], dgm1[idx, 1], 20, 'k', 'x')
plt.title("Max 1D birth = %.3g, death = %.3g"%(dgm1[idx, 0], dgm1[idx, 1]))
plt.show()

ax = plt.axes(projection='3d')

# Data for a three-dimensional line
zline = np.linspace(0, 15, 1000)
xline = np.sin(zline)
yline = np.cos(zline)
ax.plot3D(xline, yline, zline, 'gray')

# Data for three-dimensional scattered points
zdata = 15 * np.random.random(100)
xdata = np.sin(zdata) + 0.1 * np.random.randn(100)
ydata = np.cos(zdata) + 0.1 * np.random.randn(100)
ax.scatter3D(xdata, ydata, zdata, c='blue');
plt.show()
R = np.vstack((xdata,ydata))
R = np.vstack((R,zdata))
print(R.shape)
result = ripser(R.T, coeff=2, do_cocycles=True)
diagrams = result['dgms']
cocycles = result['cocycles']
D = result['dperm2all']
dgm1 = diagrams[1]
idx = np.argmax(dgm1[:, 1] - dgm1[:, 0])
plot_diagrams(diagrams, show = False)
plt.scatter(dgm1[idx, 0], dgm1[idx, 1], 20, 'k', 'x')
plt.title("Max 1D birth = %.3g, death = %.3g"%(dgm1[idx, 0], dgm1[idx, 1]))
plt.show()
import plotly.graph_objects as go
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/vortex.csv")

fig = go.Figure(data = go.Cone(
    x=df['x'],
    y=df['y'],
    z=df['z'],
    u=df['u'],
    v=df['v'],
    w=df['w'],
    colorscale='Blues',
    sizemode="absolute",
    sizeref=40))

fig.update_layout(scene=dict(aspectratio=dict(x=1, y=1, z=0.8),
                             camera_eye=dict(x=1.2, y=1.2, z=0.6)))

fig.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2234002271866717, 'fraction_numerical': 0.05301022340022719, 'mean_word_length': 4.645299145299146, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '264543', 'license': 'MIT', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1203, 'n_words': 228, 'path': 'RipCircle.ipynb', 'repo_name': 'mmayers88/TDA_Experiments', 'size': '2641'}