Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added made/.DS_Store
Binary file not shown.
78 changes: 49 additions & 29 deletions made/manifolds.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
parameter space, and metric for computing distances.
"""

from dataclasses import dataclass
from dataclasses import dataclass, field
import matplotlib.pyplot as plt
import numpy as np

Expand Down Expand Up @@ -274,10 +274,12 @@ class Line(AbstractManifold):
"""

dim: int = 1
parameter_space: ParameterSpace = ParameterSpace(
[Range(0, 10, periodic=False)]
parameter_space: ParameterSpace = field(
default_factory=lambda: ParameterSpace(
[Range(0, 10, periodic=False)]
)
)
metric: Metric = Euclidean(dim)
metric: Metric = field(default_factory=lambda: Euclidean(1))


# ----------------------------------- ring ---------------------------------- #
Expand All @@ -289,10 +291,14 @@ class Ring(AbstractManifold):
"""

dim: int = 1
parameter_space: ParameterSpace = ParameterSpace(
[Range(0, 2 * np.pi, periodic=True)]
parameter_space: ParameterSpace = field(
default_factory=lambda: ParameterSpace(
[Range(0, 2 * np.pi, periodic=True)]
)
)
metric: Metric = field(
default_factory=lambda: PeriodicEuclidean(1, periodic=[True])
)
metric: Metric = PeriodicEuclidean(dim, periodic=[True])


# ----------------------------------- plane ---------------------------------- #
Expand All @@ -304,10 +310,12 @@ class Plane(AbstractManifold):
"""

dim: int = 2
parameter_space: ParameterSpace = ParameterSpace(
[Range(0, 2.5, periodic=False), Range(0, 2.5, periodic=False)]
parameter_space: ParameterSpace = field(
default_factory=lambda: ParameterSpace(
[Range(0, 2.5, periodic=False), Range(0, 2.5, periodic=False)]
)
)
metric: Metric = Euclidean(dim)
metric: Metric = field(default_factory=lambda: Euclidean(2))


# --------------------------------- cylinder --------------------------------- #
Expand All @@ -319,10 +327,14 @@ class Cylinder(AbstractManifold):
"""

dim: int = 2
parameter_space: ParameterSpace = ParameterSpace(
[Range(0, 3, periodic=False), Range(0, 2 * np.pi, periodic=True)]
parameter_space: ParameterSpace = field(
default_factory=lambda: ParameterSpace(
[Range(0, 3, periodic=False), Range(0, 2 * np.pi, periodic=True)]
)
)
metric: Metric = field(
default_factory=lambda: PeriodicEuclidean(2, periodic=[False, True])
)
metric: Metric = PeriodicEuclidean(dim, periodic=[False, True])


# ----------------------------------- torus ---------------------------------- #
Expand All @@ -334,13 +346,17 @@ class Torus(AbstractManifold):
"""

dim: int = 2
parameter_space: ParameterSpace = ParameterSpace(
[
Range(0, 2 * np.pi, periodic=True),
Range(0, 2 * np.pi, periodic=True),
]
parameter_space: ParameterSpace = field(
default_factory=lambda: ParameterSpace(
[
Range(0, 2 * np.pi, periodic=True),
Range(0, 2 * np.pi, periodic=True),
]
)
)
metric: Metric = field(
default_factory=lambda: PeriodicEuclidean(2, periodic=[True, True])
)
metric: Metric = PeriodicEuclidean(dim, periodic=[True, True])


# --------------------------------- mobius band --------------------------------- #
Expand All @@ -353,10 +369,12 @@ class MobiusBand(AbstractManifold):
"""

dim: int = 2
parameter_space: ParameterSpace = ParameterSpace(
[Range(-2, 2, periodic=False), Range(0, 2 * np.pi, periodic=True)]
parameter_space: ParameterSpace = field(
default_factory=lambda: ParameterSpace(
[Range(-2, 2, periodic=False), Range(0, 2 * np.pi, periodic=True)]
)
)
metric: Metric = MobiusEuclidean(T=2.0)
metric: Metric = field(default_factory=lambda: MobiusEuclidean(T=2.0))


# ---------------------------------- sphere ---------------------------------- #
Expand All @@ -368,14 +386,16 @@ class Sphere(AbstractManifold):
"""

dim: int = 3
parameter_space: ParameterSpace = SphereParameterSpace(
[
Range(-1, 1, periodic=False),
Range(-1, 1, periodic=False),
Range(-1, 1, periodic=False),
]
parameter_space: ParameterSpace = field(
default_factory=lambda: SphereParameterSpace(
[
Range(-1, 1, periodic=False),
Range(-1, 1, periodic=False),
Range(-1, 1, periodic=False),
]
)
)
metric: Metric = SphericalDistance(dim)
metric: Metric = field(default_factory=lambda: SphericalDistance(3))


# Dictionary of padding values for different manifold types
Expand Down
Binary file added made/notebooks/.DS_Store
Binary file not shown.
85 changes: 46 additions & 39 deletions made/notebooks/1_visualize_connectivity.ipynb

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions made/qan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from dataclasses import dataclass
from dataclasses import dataclass, field

from made.manifolds import AbstractManifold
from made import manifolds
Expand Down Expand Up @@ -121,7 +121,7 @@ class LineQAN(QAN):
The network uses two offset CANs to track movement along the line.
"""

manifold: AbstractManifold = manifolds.Line()
manifold: AbstractManifold = field(default_factory=manifolds.Line)
spacing: float = 0.075 # Spacing between neurons
alpha: float = 3 # Sharpness of neural tuning curves
sigma: float = 1 # Width of neural tuning curves
Expand Down Expand Up @@ -218,7 +218,7 @@ class RingQAN(QAN):
Handles periodic boundary conditions at 0 and 2π.
"""

manifold: AbstractManifold = manifolds.Ring()
manifold: AbstractManifold = field(default_factory=manifolds.Ring)
spacing: float = 0.075
alpha: float = 3
sigma: float = 1
Expand Down Expand Up @@ -330,7 +330,7 @@ class PlaneQAN(QAN):
x and y directions independently.
"""

manifold: AbstractManifold = manifolds.Plane()
manifold: AbstractManifold = field(default_factory=manifolds.Plane)
spacing: float = 0.065
alpha: float = 3
sigma: float = 1
Expand Down Expand Up @@ -425,7 +425,7 @@ def compute_can_input(
# ----------------------------------- Torus ---------------------------------- #
@dataclass
class TorusQAN(QAN):
manifold: AbstractManifold = manifolds.Torus()
manifold: AbstractManifold = field(default_factory=manifolds.Torus)
spacing: float = 0.2
alpha: float = 2.5
sigma: float = 2
Expand Down Expand Up @@ -500,7 +500,7 @@ class CylinderQAN(QAN):
and around the circumference. Handles periodic boundary conditions in the angular dimension.
"""

manifold: AbstractManifold = manifolds.Cylinder()
manifold: AbstractManifold = field(default_factory=manifolds.Cylinder)
spacing: float = 0.2
alpha: float = 2
sigma: float = 1
Expand Down Expand Up @@ -617,7 +617,7 @@ class MobiusBandQAN(QAN):
height flip when completing a full rotation.
"""

manifold: AbstractManifold = manifolds.MobiusBand()
manifold: AbstractManifold = field(default_factory=manifolds.MobiusBand)
spacing: float = 0.15
alpha: float = 2
sigma: float = 2
Expand Down Expand Up @@ -737,7 +737,7 @@ class SphereQAN(QAN):
in the tangent space of the sphere.
"""

manifold: AbstractManifold = manifolds.Sphere()
manifold: AbstractManifold = field(default_factory=manifolds.Sphere)
spacing: float = 0.075
alpha: float = 2.5
sigma: float = 2.5
Expand Down
1 change: 1 addition & 0 deletions made/visuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def visualize_manifold(
Returns:
fig, ax: The matplotlib figure and axes with the plot
"""

if mfld.dim == 1:
f, ax = plt.subplots()
mfld.visualize(ax)
Expand Down