美文网首页
LSTM Custom

LSTM Custom

作者: Easize | 来源:发表于2017-10-21 22:45 被阅读0次

    def InitLSTM(self,LSTM,Name,InputSize)

          LSTM.Forget_Wights_X=tf.Variable(tf.truncated_normal(

                                                      shape=  [InputSize,LSTM.Size],stddev=0.1))

          LSTM.Forget_Wights_Z=tf.Variable(tf.truncated_normal(

                                                      shape=[LSTM.Size,LSTM.Size],stddev=0.1),)

          LSTM.Forget_Biases=tf.Variable(tf.zeros(shape=[LSTM.Size]))

          LSTM.Output_Wights_X=tf.Variable(tf.truncated_normal(

                                                     shape=[InputSize,LSTM.Size],stddev=0.1),)

         LSTM.Output_Wights_Z=tf.Variable(tf.truncated_normal(

                                                     shape=[LSTM.Size,LSTM.Size]),)

         LSTM.Output_Biases=tf.zeros(shape=[LSTM.Size],)

         LSTM.Generate_Wights_Xi=tf.Variable(tf.truncated_normal(

                                          shape=[InputSize,LSTM.Size],stddev=0.1),)

         LSTM.Generate_Wights_XC=tf.Variable(tf.truncated_normal(

                                          shape=[InputSize,LSTM.Size],stddev=0.1),)

         LSTM.Generate_Wights_Zi=tf.Variable(tf.truncated_normal(

                                         shape=[LSTM.Size.Size],stddev=0.1))

         LSTM.Generate_Wights_ZC=tf.Variable(tf.truncated_normal(

             shape=[LSTM.Size,LSTM.Size],stddev=0.1))

              LSTM.Generate_Biases=tf.zeros(shape=[LSTM.Size])

              LSTM.HState=tf.zeros(shape=[LSTM.Size],name="HState"+Name)

             LSTM.CState=tf.zeros(shape=[LSTM.Size],name="CState"+Name)


    def      CalculateLSTM(self,LSTM,Input):

              Out=None

               for i in    range(LSTM.Step):

               Forget=tf.matmul(Input,LSTM.Forget_Wights_X)\

                                 +tf.matmul(LSTM.HState,LSTM.Forget_Wights_Z)\

                                       +LSTM.Forget_Biases

              Generate_i=tf.matmul(Input,LSTM.Generate_Wights_Xi)\

                                        +tf.matmul(LSTM.HState,LSTM.Generate_Wights_Zi)\

                                            +LSTM.Generate_Biases_i

               Generate_C=tf.matmul(Input,LSTM.Generate_Wights_XC)\

                                           +tf.matmul(LSTM.HState,LSTM.Generate_Wights_ZC)\

                                                +LSTM.Generate_Biases_C

               Out=tf.matmul(Input,LSTM.Output_Wights_X)\

                                          +tf.matmul(LSTM.HState,LSTM.Output_Wights_Z)\

                                              +LSTM.Output_Biases

               #Updata State

                  LSTM.CState=Forget*LSTM.HState+Generate_C*Generate_i

                  LSTM.HState=Out*tf.tanh(LSTM.CState)

                 returnOut

    相关文章

      网友评论

          本文标题:LSTM Custom

          本文链接:https://www.haomeiwen.com/subject/guvwuxtx.html