Skip to content

Question: No 'name' attribute for network items #407

Open
@krooq

Description

@krooq

BindsNET has a really nice API, its super easy to understand and has a low barrier for entry, massive props to the team.
I found one rough edge that I'd like to understand a little better and maybe propose a change,
i.e. network items have no 'name' attribute.

This example code is a really good starting point and this is what I have been using to learn bindsnet.
I copied the code into my editor and messed around a bit and found after a while that it was getting a bit ugly slinging all these strings around.

I ended up doing something like this to make the code much cleaner and reduce the string duplication

class Net(Network):
    def add_layer(self, nodes: Nodes, name: str) -> str:
        super().add_layer(nodes, name)
        setattr(nodes, 'name', name)
        return nodes

    def add_connection(self, connection: Connection) -> Connection:
        super().add_connection(connection, source=connection.source.name, target=connection.target.name)
        return connection

    def add_monitor(self, monitor: Monitor, name: str) -> Monitor:
        super().add_monitor(monitor, name)
        return monitor

This made the network creation just a few lines and meant I didn't have to sling around all those strings.

time = 500
net = Net()
layer_0 = net.add_layer(Input(n=100), 'layer_0')
layer_1 = net.add_layer(LIFNodes(n=1000), 'layer_1')
cxn_0_1 = net.add_connection(Connection(layer_0, layer_1, w=0.05 + 0.1 * torch.randn(layer_0.n, layer_1.n)))
cxn_1_1 = net.add_connection(Connection(layer_1, layer_1, w=0.025 * (torch.eye(layer_1.n) - 1)))
mon_0   = net.add_monitor(Monitor(layer_0, ("s",), time), 'mon_0')
mon_1   = net.add_monitor(Monitor(layer_1, ("s","v"), time), 'mon_1')

Admittedly there are less intense ways to do this like just creating a separate string for layer names but it didn't feel that appealing.

So a few questions
Is it worth adding a name attribute to items that can be attached to a network to clean up the API?
Is my example just a contrived case that doesn't reflect the real world?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions