程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> 注釋yusugomori的DA代碼 --- dA.h

注釋yusugomori的DA代碼 --- dA.h

編輯:C++入門知識

DA就是“Denoising Autoencoders”的縮寫。繼續給yusugomori做注釋,邊注釋邊學習。看了一些DA的材料,基本上都在前面“轉載”了。學習中間總有個疑問:DA和RBM到底啥區別?(別笑,我不是“學院派”的看Deep Learning理論,如果“順次”看下來,可能不會有這個問題),現在了解的差不多了,詳情見:【deep learning學習筆記】Autoencoder。之後,又有個疑問,DA具體的權重更新公式是怎麼推導出來的?我知道是BP算法,不過具體公示的推導、偏導數的求解,沒有看到哪個材料有具體的公式,所以姑且認為yusugomori的代碼寫的是正確的。

 


注釋後的頭文件:


 

 // The Class of denoising auto-encoder  
class dA  
{ 
public: 
    int N;          // the number of training samples  
    int n_visible;  // the number of visible nodes  
    int n_hidden;   // the number of hidden nodes  
    double **W;     // the weight connecting visible node and hidden node  
    double *hbias;  // the bias of hidden nodes  
    double *vbias;  // the bias of visible nodes  
 
public: 
    // initialize the parameters  
    dA ( int,       // N  
         int,       // n_visible  
         int ,      // n_hidden  
         double**,  // W  
         double*,   // hbias  
         double*    // vbias  
         ); 
    ~dA(); 
 
    // make the input noised  
    void get_corrupted_input ( 
                int*,       // the original input 0-1 vector            -- input  
                int*,       // the resulted 0-1 vector gotten noised    -- output  
                double      // the p probability of noise, binomial test -- input  
                ); 
    // encode process: calculate the probability output from hidden node  
    // p(hi|v) = sigmod ( sum_j(vj * wij) + bi), it's same with RBM  
    // but different from RBM, it dose not generate 0-1 state from Bernoulli distribution  
    void get_hidden_values ( 
                int*,       // the input from visible nodes  
                double*     // the output of hidden nodes  
                ); 
    // decode process: calculate the probability output from visiable node  
    // p(vi|h) = sigmod ( sum_j(hj * wij) + ci), it's same with RBM  
    // but different from RBM, it dose not generate 0-1 state from Bernoulli distribution   
    void get_reconstructed_input ( 
                double*,    // the input from hidden nodes  
                double*     // the output reconstructed of visible nodes  
                ); 
    // train the model by a single sample  
    void train ( 
                int*,       // the input sample from visiable node  
                double,     // the learning rate  
                double      // corruption_level is the probability of noise  
                ); 
    // reconstruct the input sample  
    void reconstruct ( 
                int*,       // the input sample     -- input  
                double*     // the reconstructed value -- output  
                ); 
}; 

// The Class of denoising auto-encoder
class dA
{
public:
 int N;   // the number of training samples
 int n_visible; // the number of visible nodes
 int n_hidden; // the number of hidden nodes
 double **W;  // the weight connecting visible node and hidden node
 double *hbias; // the bias of hidden nodes
 double *vbias; // the bias of visible nodes

public:
 // initialize the parameters
 dA ( int,  // N
   int,  // n_visible
   int ,  // n_hidden
   double**, // W
   double*, // hbias
   double* // vbias
   );
 ~dA();

 // make the input noised
 void get_corrupted_input (
    int*,  // the original input 0-1 vector   -- input
    int*,  // the resulted 0-1 vector gotten noised -- output
    double  // the p probability of noise, binomial test -- input
    );
 // encode process: calculate the probability output from hidden node
 // p(hi|v) = sigmod ( sum_j(vj * wij) + bi), it's same with RBM
 // but different from RBM, it dose not generate 0-1 state from Bernoulli distribution
 void get_hidden_values (
    int*,  // the input from visible nodes
    double*  // the output of hidden nodes
    );
 // decode process: calculate the probability output from visiable node
 // p(vi|h) = sigmod ( sum_j(hj * wij) + ci), it's same with RBM
 // but different from RBM, it dose not generate 0-1 state from Bernoulli distribution
 void get_reconstructed_input (
    double*, // the input from hidden nodes
    double*  // the output reconstructed of visible nodes
    );
 // train the model by a single sample
 void train (
    int*,  // the input sample from visiable node
    double,  // the learning rate
    double  // corruption_level is the probability of noise
    );
 // reconstruct the input sample
 void reconstruct (
    int*,  // the input sample  -- input
    double*  // the reconstructed value -- output
    );
};

 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved