python内部函数参数错误_python - 处理python中参数化Sigmoid函数中的错误 - 堆栈内存溢出...

我正在尝试将一组数字转换成S形:

actualarray = {

'open_cost_1':{

'cost_matrix': [

{'a': 24,'b': 56,'c': 78},

{'a': 3,'b': 98,'c':1711},

{'a': 121,'b': 12121,'c': 12989121},

]

},

'open_cost_2':{

'cost_matrix': [

{'a': 123,'b': 1312,'c': 1231},

{'a': 1011,'b': 1911,'c':911},

{'a': 1433,'b': 19829,'c': 1132},

]

}

}

每个cost_matrix中的每个字典列表中的每个数字都通过不同的Sigmoid函数进行归一化:

def apply_normalizations(costs):

def sigmoid(b,m,v):

return ((np.exp(b+m*v) / (1 + np.exp(b+m*v)))*2)-1 #Taken from http://web.stanford.edu/class/psych252/tutorials/Tutorial_LogisticRegression.html

def normalize_dicts_local_sigmoid(bias, slope,lst):

return [{key: sigmoid(bias, slope,val) for key,val in dic.iteritems()} for dic in lst]

for name, value in costs.items():

if int((name.split("_")[-1]))>1:

value['normalised_matrix_sigmoid'] = normalize_dicts_local_sigmoid(0,1,value['cost_matrix'])

apply_normalizations(actualarray)

但是,运行此命令时,我得到:

RuntimeWarning: overflow encountered in exp

return ((np.exp(b+m*v) / (1 + np.exp(b+m*v)))*2)-1

RuntimeWarning: invalid value encountered in double_scalars

return ((np.exp(b+m*v) / (1 + np.exp(b+m*v)))*2)-1

数组变成:

{

'open_cost_2': {

'cost_matrix': [

{

'a': 123,

'c': 1231,

'b': 1312

},

{

'a': 1011,

'c': 911,

'b': 1911

},

{

'a': 1433,

'c': 1132,

'b': 19829

}

],

'normalised_matrix_sigmoid': [

{

'a': 1.0,

'c': nan,

'b': nan

},

{

'a': nan,

'c': nan,

'b': nan

},

{

'a': nan,

'c': nan,

'b': nan

}

]

},

'open_cost_1': {

'cost_matrix': [

{

'a': 24,

'c': 78,

'b': 56

},

{

'a': 3,

'c': 1711,

'b': 98

},

{

'a': 121,

'c': 12989121,

'b': 12121

}

]

}

}

请注意,每个成本总是大于0,因此我在S型函数中乘以2并减去1。

我该如何适应这个错误?

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值