Skip to content

Commit

Permalink
nightly analysis and readme edits
Browse files Browse the repository at this point in the history
  • Loading branch information
soulsyrup committed Mar 12, 2024
1 parent 5bf1f19 commit cfb6e3d
Show file tree
Hide file tree
Showing 12 changed files with 384 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .ipynb_checkpoints/README-checkpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ This project is licensed under the [Creative Commons Attribution-ShareAlike 4.0
For collaborations, press inquiries, or questions:
- Email: [[email protected]](mailto:[email protected]) or [[email protected]](mailto:[email protected])
- Discord: soul_syrup
- TikTok: [@soul.syrup](https://www.tiktok.com/@soul.syrup)


## 📚 Library Testing Invitation
We invite you to test our PyPI library for human brain cortical organoid/spheroid, EEG, ECoG, and other signal analyses:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ This project is licensed under the [Creative Commons Attribution-ShareAlike 4.0
For collaborations, press inquiries, or questions:
- Email: [[email protected]](mailto:[email protected]) or [[email protected]](mailto:[email protected])
- Discord: soul_syrup
- TikTok: [@soul.syrup](https://www.tiktok.com/@soul.syrup)


## 📚 Library Testing Invitation
We invite you to test our PyPI library for human brain cortical organoid/spheroid, EEG, ECoG, and other signal analyses:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<mxfile host="Electron" modified="2024-02-18T22:58:04.862Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/22.1.16 Chrome/120.0.6099.109 Electron/28.1.0 Safari/537.36" etag="1QcBfkBqKvNv_i8hugP5" version="22.1.16" type="device">
<mxfile host="Electron" modified="2024-02-18T23:11:25.822Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/22.1.16 Chrome/120.0.6099.109 Electron/28.1.0 Safari/537.36" etag="ipb6FutnhZ3A9176Z70f" version="22.1.16" type="device">
<diagram name="Page-1" id="UO3zegzRqnsEIXU49jw1">
<mxGraphModel dx="1905" dy="1146" grid="0" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1654" pageHeight="1169" background="#000000" math="0" shadow="0">
<mxGraphModel dx="2222" dy="1337" grid="0" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1654" pageHeight="1169" background="#000000" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
Expand Down Expand Up @@ -74,10 +74,7 @@
<mxGeometry x="602" y="904" width="60" height="30" as="geometry" />
</mxCell>
<mxCell id="kK_saXuroscAapvJbY5S-26" value="signals_generator.py" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="991.5" y="1105" width="60" height="30" as="geometry" />
</mxCell>
<mxCell id="kK_saXuroscAapvJbY5S-27" value="&lt;b&gt;Publishing Features&lt;/b&gt;: Publish the encoded features string using a ZeroMQ publisher socket." style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="864.5" y="1145" width="340" height="60" as="geometry" />
<mxGeometry x="1416.5" y="1105" width="60" height="30" as="geometry" />
</mxCell>
<mxCell id="kK_saXuroscAapvJbY5S-29" value="&lt;div&gt;&lt;b&gt;Initialization&lt;/b&gt;: Define bit depth, number of signals, sampling rate, duration, and voltage range.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="1276.5" y="1145" width="340" height="60" as="geometry" />
Expand Down Expand Up @@ -211,15 +208,9 @@
<mxPoint x="1316.5" y="875" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="kK_saXuroscAapvJbY5S-60" value="" style="endArrow=classic;html=1;rounded=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="kK_saXuroscAapvJbY5S-24" target="kK_saXuroscAapvJbY5S-27">
<mxCell id="kK_saXuroscAapvJbY5S-61" value="" style="endArrow=classic;html=1;rounded=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="kK_saXuroscAapvJbY5S-24" target="kK_saXuroscAapvJbY5S-29">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="1406.5" y="875" as="sourcePoint" />
<mxPoint x="1326.5" y="885" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="kK_saXuroscAapvJbY5S-61" value="" style="endArrow=classic;html=1;rounded=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="kK_saXuroscAapvJbY5S-27" target="kK_saXuroscAapvJbY5S-29">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="846.5" y="1185" as="sourcePoint" />
<mxPoint x="1204.5" y="1175" as="sourcePoint" />
<mxPoint x="896.5" y="1215" as="targetPoint" />
</mxGeometry>
</mxCell>
Expand Down Expand Up @@ -316,6 +307,9 @@
<mxCell id="kK_saXuroscAapvJbY5S-82" value="send_signals_to_usb_hub.py" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="1004.5" y="1556" width="60" height="30" as="geometry" />
</mxCell>
<mxCell id="kK_saXuroscAapvJbY5S-84" value="game.py" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="601.5" y="666" width="60" height="30" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import numpy as np
import gudhi as gd

# Assuming `reduced_data_umap` is your dimensionality-reduced data from the previous steps

def compute_persistence_diagrams(data):
"""
Compute the persistence diagrams for a given dataset using Vietoris-Rips complex.
:param data: Input dataset, assumed to be the output of a dimensionality reduction method.
:return: Persistence diagrams for the dataset.
"""
rips_complex = gd.RipsComplex(points=data, max_edge_length=2)
simplex_tree = rips_complex.create_simplex_tree(max_dimension=2)
persistence = simplex_tree.persistence()
return persistence

def plot_persistence_diagrams(persistence):
"""
Plot the persistence diagrams.
:param persistence: Persistence diagrams.
"""
gd.plot_persistence_diagram(persistence)
plt.show()

def calculate_betti_numbers(persistence):
"""
Calculate Betti numbers from the persistence diagrams.
:param persistence: Persistence diagrams.
:return: Betti numbers (b0, b1, b2) counting the number of connected components, loops, and voids respectively.
"""
betti_numbers = {i: 0 for i in range(3)} # Assuming we're only interested in dimensions 0, 1, and 2
for interval in persistence:
if interval[0] < 3: # Filter out infinite persistence intervals
betti_numbers[interval[0]] += 1
return betti_numbers['b0'], betti_numbers['b1'], betti_numbers['b2']

# Compute Persistence Diagrams
persistence = compute_persistence_diagrams(reduced_data_umap)

# Plot Persistence Diagrams
plot_persistence_diagrams(persistence)

# Calculate Betti Numbers
betti_numbers = calculate_betti_numbers(persistence)
print("Betti Numbers:", betti_numbers)
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import numpy as np
import matplotlib.pyplot as plt
from sklearn.manifold import TSNE
import umap.umap_ as umap
from geomstats.geometry.special_orthogonal import SpecialOrthogonal
import geomstats.learning.frechet_mean as frechet_mean
import geomstats.geometry.hypersphere as hypersphere
from geomstats.learning.frechet_mean import FrechetMean
from geomstats.geometry.euclidean import Euclidean

# Assuming the file contains continuous data recorded at 500 Hz from 32 channels
file_path = 'ecog_data_last_24h.npy'
ECoG_data = np.load(file_path)

# Preprocessing steps (filtering, detrending, artifact removal) are assumed to be done prior
# This example focuses on the analysis part
# Apply UMAP for dimensionality reduction to 3D for better visualization and further analysis
reduced_data_umap = umap.UMAP(n_components=3).fit_transform(ECoG_data)
# Apply t-SNE for comparison
reduced_data_tsne = TSNE(n_components=3).fit_transform(ECoG_data)

plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
plt.scatter(reduced_data_umap[:, 0], reduced_data_umap[:, 1], s=1)
plt.title('UMAP Reduction')
plt.subplot(1, 2, 2)
plt.scatter(reduced_data_tsne[:, 0], reduced_data_tsne[:, 1], s=1)
plt.title('t-SNE Reduction')
plt.show()

sphere = hypersphere.Hypersphere(dim=2)
point_a, point_b = sphere.random_point(), sphere.random_point()
distance = sphere.metric.dist(point_a, point_b)

# Frechet Mean on Hypersphere
points = sphere.random_point(n_samples=10)
frechet_mean_sphere = FrechetMean(metric=sphere.metric)
frechet_mean_sphere.fit(points)
mean_sphere = frechet_mean_sphere.estimate_

so3 = SpecialOrthogonal(n=3, point_type='vector')
points_so3 = so3.random_point(n_samples=10)
frechet_mean_so3 = FrechetMean(metric=so3.metric)
frechet_mean_so3.fit(points_so3)
mean_so3 = frechet_mean_so3.estimate_

# Partitioning the reduced space into 4 regions as an example
quantiles = np.quantile(reduced_data_umap, [0.25, 0.5, 0.75], axis=0)

def partition_phase_space(data, quantiles):
symbols = np.zeros(data.shape[0], dtype=int)
for i, point in enumerate(data):
if point[0] < quantiles[0][0]:
symbols[i] = 0
elif point[0] < quantiles[1][0]:
symbols[i] = 1
elif point[0] < quantiles[2][0]:
symbols[i] = 2
else:
symbols[i] = 3
return symbols

symbols = partition_phase_space(reduced_data_umap, quantiles)

plt.figure(figsize=(6, 6))
for i in range(4):
plt.scatter(reduced_data_umap[symbols == i, 0], reduced_data_umap[symbols == i, 1], s=1, label=f'Partition {i}')
plt.title('Symbolic Dynamics Partitioning (UMAP)')
plt.legend()
plt.show()
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import numpy as np
import gudhi as gd

# Assuming `reduced_data_umap` is your dimensionality-reduced data from the previous steps

def compute_persistence_diagrams(data):
"""
Compute the persistence diagrams for a given dataset using Vietoris-Rips complex.
:param data: Input dataset, assumed to be the output of a dimensionality reduction method.
:return: Persistence diagrams for the dataset.
"""
rips_complex = gd.RipsComplex(points=data, max_edge_length=2)
simplex_tree = rips_complex.create_simplex_tree(max_dimension=2)
persistence = simplex_tree.persistence()
return persistence

def plot_persistence_diagrams(persistence):
"""
Plot the persistence diagrams.
:param persistence: Persistence diagrams.
"""
gd.plot_persistence_diagram(persistence)
plt.show()

def calculate_betti_numbers(persistence):
"""
Calculate Betti numbers from the persistence diagrams.
:param persistence: Persistence diagrams.
:return: Betti numbers (b0, b1, b2) counting the number of connected components, loops, and voids respectively.
"""
betti_numbers = {i: 0 for i in range(3)} # Assuming we're only interested in dimensions 0, 1, and 2
for interval in persistence:
if interval[0] < 3: # Filter out infinite persistence intervals
betti_numbers[interval[0]] += 1
return betti_numbers['b0'], betti_numbers['b1'], betti_numbers['b2']

# Compute Persistence Diagrams
persistence = compute_persistence_diagrams(reduced_data_umap)

# Plot Persistence Diagrams
plot_persistence_diagrams(persistence)

# Calculate Betti Numbers
betti_numbers = calculate_betti_numbers(persistence)
print("Betti Numbers:", betti_numbers)
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import numpy as np
import matplotlib.pyplot as plt
from sklearn.manifold import TSNE
import umap.umap_ as umap
from geomstats.geometry.special_orthogonal import SpecialOrthogonal
import geomstats.learning.frechet_mean as frechet_mean
import geomstats.geometry.hypersphere as hypersphere
from geomstats.learning.frechet_mean import FrechetMean
from geomstats.geometry.euclidean import Euclidean

# Assuming the file contains continuous data recorded at 500 Hz from 32 channels
file_path = 'ecog_data_last_24h.npy'
ECoG_data = np.load(file_path)

# Preprocessing steps (filtering, detrending, artifact removal) are assumed to be done prior
# This example focuses on the analysis part
# Apply UMAP for dimensionality reduction to 3D for better visualization and further analysis
reduced_data_umap = umap.UMAP(n_components=3).fit_transform(ECoG_data)
# Apply t-SNE for comparison
reduced_data_tsne = TSNE(n_components=3).fit_transform(ECoG_data)

plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
plt.scatter(reduced_data_umap[:, 0], reduced_data_umap[:, 1], s=1)
plt.title('UMAP Reduction')
plt.subplot(1, 2, 2)
plt.scatter(reduced_data_tsne[:, 0], reduced_data_tsne[:, 1], s=1)
plt.title('t-SNE Reduction')
plt.show()

sphere = hypersphere.Hypersphere(dim=2)
point_a, point_b = sphere.random_point(), sphere.random_point()
distance = sphere.metric.dist(point_a, point_b)

# Frechet Mean on Hypersphere
points = sphere.random_point(n_samples=10)
frechet_mean_sphere = FrechetMean(metric=sphere.metric)
frechet_mean_sphere.fit(points)
mean_sphere = frechet_mean_sphere.estimate_

so3 = SpecialOrthogonal(n=3, point_type='vector')
points_so3 = so3.random_point(n_samples=10)
frechet_mean_so3 = FrechetMean(metric=so3.metric)
frechet_mean_so3.fit(points_so3)
mean_so3 = frechet_mean_so3.estimate_

# Partitioning the reduced space into 4 regions as an example
quantiles = np.quantile(reduced_data_umap, [0.25, 0.5, 0.75], axis=0)

def partition_phase_space(data, quantiles):
symbols = np.zeros(data.shape[0], dtype=int)
for i, point in enumerate(data):
if point[0] < quantiles[0][0]:
symbols[i] = 0
elif point[0] < quantiles[1][0]:
symbols[i] = 1
elif point[0] < quantiles[2][0]:
symbols[i] = 2
else:
symbols[i] = 3
return symbols

symbols = partition_phase_space(reduced_data_umap, quantiles)

plt.figure(figsize=(6, 6))
for i in range(4):
plt.scatter(reduced_data_umap[symbols == i, 0], reduced_data_umap[symbols == i, 1], s=1, label=f'Partition {i}')
plt.title('Symbolic Dynamics Partitioning (UMAP)')
plt.legend()
plt.show()
Loading

0 comments on commit cfb6e3d

Please sign in to comment.