程序化交易吧 关注:3,287贴子:8,503
  • 0回复贴,共1

期货量化软件:赫兹量化系统神经网轻松学习之关注机制

只看楼主收藏回复

在之前的文章中,我们已经测试了组织规划神经网络的各种选项。 其中包括借鉴来的图像处理算法的卷积网络[ 3 ],以及递归神经网络[ 4 ],这些神经网络不仅处理重要的数值序列,还有它们在源数据集合中的位置。全连接和卷积神经网络具有固定的输入序列大小。 递归神经网络通过转移先前迭代中的隐藏状态,可稍微扩展所分析序列。 但是它们的有效性也随着序列的递增而降低。 在 2014 年,出于机器翻译的目的,第一次提出了关注机制。 该机制的目的在于判定并高亮显示与目标翻译词最相关的源句子(上下文)的区块。 这种直观的方法极大地提高了神经网络翻译文本的质量。
在类方法中实现相应的修改。class CNeuronConvOCL : public CNeuronProofOCL {protected: uint iWindowOut;//--- CBufferDouble *WeightsConv; CBufferDouble *DeltaWeightsConv; CBufferDouble *FirstMomentumConv; CBufferDouble *SecondMomentumConv;//--- virtual bool int window_in, int window_out, uint activation) { int i=get_global_id(0); int w_in=window_in; int w_out=window_out; double sum=0.0; double4 inp, weight; int shift_out=w_out*i; int shift_in=step*i; for(int out=0;out<w_out;out++) { int shift=(w_in+1)*out; int stop=(w_in<=(inputs-shift_in) ? w_in : (inputs-shift_in)); for(int k=0; k<=stop; k=k+4) { switch(stop-k) { case 0: inp=(double4)(1,0,0,0); weight=(double4)(matrix_w[shift+k],0,0,0); break; case 1: inp=(double4)(matrix_i[shift_in+k],1,0,0); weight=(double4)(matrix_w[shift+k],matrix_w[shift+k+1],0,0); break; case 2: inp=(double4)(matrix_i[shift_in+k],matrix_i[shift_in+k+1],1,0); weight=(double4)(matrix_w[shift+k],matrix_w[shift+k+1],matrix_w[shift+k+2],0); break; case 3: inp=(double4)(matrix_i[shift_in+k],matrix_i[shift_in+k+1],matrix_i[shift_in+k+2],1); weight=(double4)(matrix_w[shift+k],matrix_w[shift+k+1],matrix_w[shift+k+2],matrix_w[shift+k+3]); break; default: inp=(double4)(matrix_i[shift_in+k],matrix_i[shift_in+k+1],matrix_i[shift_in+k+2],matrix_i[shift_in+k+3]); weight=(double4)(matrix_w[shift+k],matrix_w[shift+k+1],matrix_w[shift+k+2],matrix_w[shift+k+3]); break; } sum+=dot(inp,weight); } switch(activation) { case 0: sum=tanh(sum); break; case 1: sum=1/(1+exp(-clamp(sum,-50.0,50.0))); break; case 2: if(sum<0) sum*=0.01; break; default: break; } matrix_o[out+shift_out]=sum; } }


IP属地:浙江1楼2023-10-13 15:15回复