I have built a partial human brain model and the following is an example of how I use all the classes. I was wondering if anyone could critique my implementation strategies because I feel like the following setup is very clumsy. You can view all the code at: https://github.com/quinnliu/WalnutiQ

public class HowToUseMARK_I extends junit.framework.TestCase {
    private NervousSystem nervousSystem;
    private MemoryClassifier memoryClassifier_Digits;

    private Gson gson;

    public void setUp() throws IOException {
        this.gson = new Gson();
        this.nervousSystem = this.constructConnectedNervousSystem();
        this.memoryClassifier_Digits = this.trainMemoryClassifierWithNervousSystem();

    private NervousSystem constructConnectedNervousSystem() {
        // construct Neocortex with just V1
        Region rootRegionOfNeocortex = new Region("V1", 4, 4, 4, 50, 3);
        RegionToRegionConnect neocortexConnectType = new RegionToRegionRectangleConnect();
        Neocortex unconnectedNeocortex = new Neocortex(rootRegionOfNeocortex,

        // construct LGN
        Region LGNRegion = new Region("LGN", 8, 8, 1, 50, 3);
        LateralGeniculateNucleus unconnectedLGN = new LateralGeniculateNucleus(

        // construct Retina
        VisionCell[][] visionCells = new VisionCell[65][65];
        for (int x = 0; x < visionCells.length; x++) {
            for (int y = 0; y < visionCells[0].length; y++) {
                visionCells[x][y] = new VisionCell();
        Retina unconnectedRetina = new Retina(visionCells);

        // construct 1 object of NervousSystem to encapsulate all classes in
        // MARK II
        NervousSystem nervousSystem = new NervousSystem(unconnectedNeocortex,
                unconnectedLGN, unconnectedRetina);

        // connect Retina to LGN
        Retina retina = nervousSystem.getPNS().getSNS().getRetina();

        LateralGeniculateNucleus LGN = nervousSystem.getCNS().getBrain()

        SensorCellsToRegionConnect retinaToLGN = new SensorCellsToRegionRectangleConnect();
        retinaToLGN.connect(retina.getVisionCells(), LGN.getRegion(), 0, 0);

        // connect LGN to V1 Region of Neocortex
        Neocortex neocortex = nervousSystem.getCNS().getBrain().getCerebrum()

        RegionToRegionConnect LGNToV1 = new RegionToRegionRectangleConnect();
        LGNToV1.connect(LGN.getRegion(), neocortex.getCurrentRegion(), 0, 0);

        return nervousSystem;

2 Answers 2

  1. I would consider making this code:

    // construct Retina
    VisionCell[][] visionCells = new VisionCell[65][65];
    for (int x = 0; x < visionCells.length; x++) {
        for (int y = 0; y < visionCells[0].length; y++) {
            visionCells[x][y] = new VisionCell();

    a factory method on Retina (passing in the dimensions of the cell array) as it will probably be a common thing to create.

  2. Call chains like these nervousSystem.getPNS().getSNS().getRetina() are a code smell. You could model your nervous system as some kind of repository where you can query the individual components like this:


    or fully generic (additional bonus points ;))


    More complex components like Brain can then be modeled in the same way:


    This alleviates the caller from having to know the internal structure.

  3. I find it quite weird that your ctor for the NervousSystem only takes some very specific components of individual subsystems. From the looks of it the NervousSystem is composed out of PNS and CNS with SNS being part of the PNS and Brain being part of the CNS etc. so I'm wondering why the NervousSystem is not being built like that but gets some very specific subcomponents instead.

    I would have thought the setup should look something like this (I haven't checked the code on github so the class names are purely guesswork):

    Neocortex neocortex = new Neocortex(...);
    CerebralCortex cerebralCortex = new CerebralCortex(neocortex, ...);
    Cerebrum cerebrum = new Cerebrum(cerebralCortex, ...);
    LateralGeniculateNucleus lgn = new LateralGeniculateNucleus(...);
    Thalamus thalamus = new Thalamus(lgn, ...);
    Brain brain = new Brain(cerebrum, thalamus, ...);
    CNS cns = new CNS(brain, ...);
    Retina retina = new Retina(...);
    SNS sns = new SNS(retina, ...);
    PNS pns = new PNS(sns, ...);
    NervousSystem nervousSystem = new NervousSystem(cns, pns);
  4. For wiring individual components up you could pass a WiringStrategy into the NervousSystem which decides how things are wired up (so you can simulate broken wiring for example).

  • \$\begingroup\$ Hi Chris, thank you very much. To answer your 3rd question I have only implemented very small parts of the brain and if I created the setup you suggested I would just have a lot of filler classes right now. But your suggested setup is the goal ;) \$\endgroup\$
    – letter Q
    Commented Dec 25, 2013 at 18:05
  • \$\begingroup\$ I like your idea in #2. Can you explain how I can make the getter method fully generic? Like do I need a class that everything in a Nervous System extends? \$\endgroup\$
    – letter Q
    Commented Dec 28, 2013 at 7:25

Well, nobody said that modelling the brain would be easy.

However, it you find that it takes a lot of code to set up the nervous system model, it's probably a sign that your library is underdeveloped. Maybe the library should include some kind of NervousSystemFactory for convenience. Maybe the library should support a configuration file to describe the connections. YAML, for example, lets you reference other nodes within a document, which might be a useful feature for this application.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.