我已经建立了一个部分人脑模型,下面是我如何使用所有类的一个例子。我想知道是否有人可以批评我的实现策略,因为我觉得下面的设置非常笨拙。您可以在: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,
neocortexConnectType);
// construct LGN
Region LGNRegion = new Region("LGN", 8, 8, 1, 50, 3);
LateralGeniculateNucleus unconnectedLGN = new LateralGeniculateNucleus(
LGNRegion);
// 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()
.getThalamus().getLGN();
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()
.getCerebralCortex().getNeocortex();
RegionToRegionConnect LGNToV1 = new RegionToRegionRectangleConnect();
LGNToV1.connect(LGN.getRegion(), neocortex.getCurrentRegion(), 0, 0);
return nervousSystem;
}发布于 2013-12-25 11:37:32
Retina上的工厂方法(传入单元格数组的维度),因为它可能是要创建的常见内容。nervousSystem.getPNS().getSNS().getRetina()这样的呼叫链是一种代码气味。您可以将您的神经系统建模为某种存储库,您可以在其中查询单个组件,如: nervousSystem.getRetina();nervousSystem.getBrain();或完全通用的(额外的加分;) nervousSystem.get();nervousSystem.get();更复杂的组件(如Brain )然后可以以同样的方式建模: nervousSystem.get().get();这可以减轻调用者不需要知道内部结构的问题。NervousSystem只需要各个子系统的一些非常特定的组件。从外观上看,NervousSystem是由PNS和CNS组成的,SNS是PNS的一部分,Brain是CNS的一部分,所以我想知道为什么NervousSystem不是那样构建的,而是得到一些非常具体的子组件。我认为设置应该是这样的(我没有检查github上的代码,因此类名纯属猜测):新大脑皮层=新大脑皮层(.);CerebralCortex cerebralCortex =新cerebralCortex(新皮质,.);大脑皮层=新大脑皮层(cerebralCortex,.);LateralGeniculateNucleus lgn =新LateralGeniculateNucleus(.);丘脑=新丘脑(lgn,.);脑=新脑(大脑、丘脑,.);CNS =新中枢神经系统(脑,.);视网膜=新视网膜(.);SNS sns =新视网膜(.);PNS NervousSystem =新视网膜(sns,.);WiringStrategy传递到NervousSystem中,这将决定事情是如何连接的(例如,您可以模拟断线)。发布于 2013-12-25 09:18:44
没人说做大脑模型很容易。
然而,你会发现建立神经系统模型需要大量的代码,这可能是你的库不完善的一个标志。也许为了方便起见,图书馆应该包括一些NervousSystemFactory。也许库应该支持一个配置文件来描述连接。例如,YAML允许您使用引用文档中的其他节点,这可能是此应用程序的一个有用特性。
https://codereview.stackexchange.com/questions/38060
复制相似问题