python的类参数不够_python – 类参数太多:更好的设计策略?

我正在与神经元模型工作。我设计的一个类是细胞类,它是神经元(连接在一起的几个隔室)的拓扑描述。它有很多参数,但它们都是相关的,例如:

轴突节数,顶端双基因,体长,体细胞直径,顶端长度,分支随机性,分支长度等等…总共有约15个参数!

我可以设置所有这些为一些默认值,但我的类看起来疯狂与几行参数。这种事情必须偶尔发生给别人,是否有一些明显的更好的方式来设计这个或我做正确的事情?

更新:

由于你有一些人问我已经附加我的代码为类,你可以看到这个类有大量的参数(> 15),但它们都被使用,是定义单元格的拓扑结构所必需的。问题本质上是他们创建的物理对象是非常复杂的。我附加了一个由这个类产生的对象的图像表示。有经验的程序员如何做不同的,以避免这么多参数的定义?

class LayerV(__Cell):

def __init__(self,somatic_dendrites=10,oblique_dendrites=10,

somatic_bifibs=3,apical_bifibs=10,oblique_bifibs=3,

L_sigma=0.0,apical_branch_prob=1.0,

somatic_branch_prob=1.0,oblique_branch_prob=1.0,

soma_L=30,soma_d=25,axon_segs=5,myelin_L=100,

apical_sec1_L=200,oblique_sec1_L=40,somadend_sec1_L=60,

ldecf=0.98):

import random

import math

#make main the regions:

axon=Axon(n_axon_seg=axon_segs)

soma=Soma(diam=soma_d,length=soma_L)

main_apical_dendrite=DendriticTree(bifibs=

apical_bifibs,first_sec_L=apical_sec1_L,

L_sigma=L_sigma,L_decrease_factor=ldecf,

first_sec_d=9,branch_prob=apical_branch_prob)

#make the somatic denrites

somatic_dends=self.dendrite_list(num_dends=somatic_dendrites,

bifibs=somatic_bifibs,first_sec_L=somadend_sec1_L,

first_sec_d=1.5,L_sigma=L_sigma,

branch_prob=somatic_branch_prob,L_decrease_factor=ldecf)

#make oblique dendrites:

oblique_dends=self.dendrite_list(num_dends=oblique_dendrites,

bifibs=oblique_bifibs,first_sec_L=oblique_sec1_L,

first_sec_d=1.5,L_sigma=L_sigma,

branch_prob=oblique_branch_prob,L_decrease_factor=ldecf)

#connect axon to soma:

axon_section=axon.get_connecting_section()

self.soma_body=soma.body

soma.connect(axon_section,region_end=1)

#connect apical dendrite to soma:

apical_dendrite_firstsec=main_apical_dendrite.get_connecting_section()

soma.connect(apical_dendrite_firstsec,region_end=0)

#connect oblique dendrites to apical first section:

for dendrite in oblique_dends:

apical_location=math.exp(-5*random.random()) #for now connecting randomly but need to do this on some linspace

apsec=dendrite.get_connecting_section()

apsec.connect(apical_dendrite_firstsec,apical_location,0)

#connect dendrites to soma:

for dend in somatic_dends:

dendsec=dend.get_connecting_section()

soma.connect(dendsec,region_end=random.random()) #for now connecting randomly but need to do this on some linspace

#assign public sections

self.axon_iseg=axon.iseg

self.axon_hill=axon.hill

self.axon_nodes=axon.nodes

self.axon_myelin=axon.myelin

self.axon_sections=[axon.hill]+[axon.iseg]+axon.nodes+axon.myelin

self.soma_sections=[soma.body]

self.apical_dendrites=main_apical_dendrite.all_sections+self.seclist(oblique_dends)

self.somatic_dendrites=self.seclist(somatic_dends)

self.dendrites=self.apical_dendrites+self.somatic_dendrites

self.all_sections=self.axon_sections+[self.soma_sections]+self.dendrites

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值