CNTK学习笔记(二)

一、NDL语言基本概念

       The Network Description Language (NDL)的计算网络工具包(CNTK)提供了一种简单的方式来定义一个网络代码的方式。它包含变量和宏,和其他容易理解的概念。它类似于一种脚本语言在语法,但是它不是一个编程“语言”,而是简单的方法来定义一个网络。

SDim=784  
HDim=256  
LDim=10  

B0=Parameter(HDim)  
W0=Parameter(HDim, SDim)  

features=Input(SDim)  
labels=Input(LDim)  

Times1=Times(W0, features)    
Plus1=Plus(Times1, B0)    
RL1=RectifiedLinear(Plus1)  
B1=Parameter(LDim, 1)  
W1=Parameter(LDim, HDim)  
Times2=Times(W1, RL1)  
Plus2=Plus(Times2, B1) 

CrossEntropy=CrossEntropyWithSoftmax(labels, Plus2)  
ErrPredict=ErrorPrediction(labels, Plus2)  

FeatureNodes=(features)  
LabelNodes=(labels)  
CriteriaNodes=(CrossEntropy)  
EvalNodes=(ErrPredict)  
OutputNodes=(Plus2)

SDim=784  
HDim=256  
LDim=10  
这些是变量字符串变量名并给与赋值。


Times1=Times(W0, features)    
Plus1=Plus(Times1, B0)    
RL1=RectifiedLinear(Plus1)  
B1=Parameter(LDim, 1)  
这些事NDL Function,NDL全部函数包括:

  • Input, InputValue
  • ImageInput
  • Parameter, LearnableParameter
  • Sum
  • Scale
  • Times
  • Plus
  • Minus
  • Negate
  • RectifiedLinear
  • Sigmoid
  • Tanh
  • Log
  • Softmax
  • SquareError
  • CrossEntropyWithSoftmax, CEWithSM
  • MatrixL1Reg, L1Reg
  • MatrixL2Reg, L2Reg
  • PerDimMeanVarNormalization, PerDimMVNorm
  • ErrorPrediction
  • Dropout
  • Mean
  • Convolution, Convolve
  • MaxPooling
  • AveragePooling
  • Delay

NDL Macros

         NDL的宏有两种定义方法,第一种是嵌套方法:

    RFF(x1, w1, b1)=RectifiedLinear(Plus(Times(w1,x1),b1))

          函数调用和评估是从最里层到最外层的,Times(w1,x1)先被计算然后作为Plus()的第一个参数传入,Plus()的结果作为RectifiedLinear()的参数,解决了结果储存在用户指定变量中的问题如:

    RFFResult=RFF(x1, w1, b1)

           第二种方法是块定义

     FF(X1, W1, B1)
    {
       T=Times(W1,X1);
       FF=Plus(T, B1);
    }
         这种情况下中间变量可以通过点方法访问。

      

    L1 = FF(features, HDim, SDim)
    L1.T

         宏有一下几点注意:

  • Parameters used in Macros are local to each Macro
  • Return Value of a Macro is returned via the local Macro variable that has the same name as the Macro. If no such variable found, the last variable in the Macro will be returned
  • Parameters can be declared within Macros
  • A Macro can call another Macro, but recursion is not supported
  • # declares a comment line

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值