Deep Learning Neural Network pure C language basic Edition

Source: Internet
Author: User

Deep Learning Neural Network pure C language basic Edition

Today, Deep Learning has become a field of fire, and the performance of Deep Learning Neural Networks (DNN) in the field of computer vision is remarkable. Of course, convolutional neural networks are used in engineering to reduce computational workload rather than fully-Linked Neural Networks-so the computational workload is too large. However, the computational workload of a neural network is really not a problem because its structure ensures that it can be computed in parallel. Once each unit of the network can be calculated independently, multiple links at each layer are calculated at the same time. We look forward to the development of hardware neural networks.

The C language function built by a neural network with any hidden layers is hand-written below, which can be easily transplanted to embedded devices. This program is only a basic deep learning network in the form of matrix-based full link. The learning algorithm used is the random gradient descent method, and the sigmoid function is used as the activation function. It performs well in a small number of samples.

 

/* Deep Learning Neural Network V1.0made by xyt2015/7/23 language: This program is used to construct a multi-layer matrix neural network multi-input single output learning strategy: random gradient descent activation function: before using sigmoid, you must use srand (unsigned) time (NULL) to obtain the random ing Initial Value */# ifndef _ DNN_H # define _ DNN_H # include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Define DNN_VEC 8 // enter the number of training groups # define DNN_INUM 5 // input dimension double dnn_sig (double in) {// sigmoid function, return 1.0/(1.0 + exp (-1.0 * in);} struct dnn_cell {// neuron structure double w [DNN_INUM]; double wb; double in [DNN_INUM]; double out; double error; double v; void SetCell_Default () {// default initialization. the initialization of the weight is very small int I; for (I = 0; I
     
      
0; j --) {l = 0; for (I = (J-1) * DNN_INUM; I
      
        The call example is as follows:
       

 

 

# Include
        
         
# Includednn. husing namespace std; int main () {srand (unsigned) time (NULL); double Round CT [8] = {0.23, 0.23, 0.23, 0.23, 0.83, 0.83, 0.83, 0.83}; double in [8] [5] = {1.1, 2.1, 5, 3.9, 0.8, 3, 2.2, 5, 4.2, 3, 5, 0.9, 2.1, 4.9, 4.1, 5, 2.9, 3.1, 2.9, 2.1, 1 }; dnn_cell a [16]; int I; for (I = 0; I <16; I ++) a [I]. setCell_InitAll (rand () * 2.0/RAND_MAX-1, 0.001); DNN_Train (a, 4, in, round CT, 100000); double pp [5]; while (1) {for (I = 0; I <5; I ++) cin> pp [I]; cout <
         
          
Note that the expected value must be 0 ~ Between 1
          

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.