diff --git a/.main.cpp.swp b/.main.cpp.swp index 403309eaf466a1bd316b9c289f8ddb37570fc952..35d20aee882da03b0fc065a4821c0575992bf8c6 100644 Binary files a/.main.cpp.swp and b/.main.cpp.swp differ diff --git a/matrix/.matrix_def.h.swp b/.nerual_test.cpp.swp similarity index 78% rename from matrix/.matrix_def.h.swp rename to .nerual_test.cpp.swp index d2a7753e107d7ae87036a61e215d2be8085740af..93a2c88b2f7c98a377b73ffdd3b1f4e5526ac898 100644 Binary files a/matrix/.matrix_def.h.swp and b/.nerual_test.cpp.swp differ diff --git a/README.md b/README.md index d0696f594e4b7e1714160a20e92f658dce0191de..607fa5d27c454940359b5e97cadeea6497670757 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,33 @@ make install ## 新的demo程序实现5层全连接层,可自定义神经元和激活函数,损失函数 +全连接层使用方法: + +第一层的权重自定义,而后调用forward函数前向传播一层,自动求出激活以后的值,激活函数可自定义. + +首先定义一个权重矩阵和偏置矩阵,第一个矩阵的维度大小使用数据列去定义: + +```c + Matrix bias1 = CreateRandMat(2,1); + Matrix weight1 = CreateRandMat(2,data.col); +``` + +之后可以输出第一层前向传播的值,同时可以定义下一层的bias的维度, row使用第一层的权重矩阵的行,第二层的权重矩阵的行使用了第一层的输出的行, 而列自行定义即可, 这一点体现了前向传播算法的维度相容. 也就是: + +```c +Matrix output1 = sequaltial.forward(get_T(get_row(data_mine,index)),weight1,bias1); +``` + +```c +Matrix weight2 = CreateRandMat(output1.row,2); +Matrix bias2 = CreateRandMat(weight2.row,1); +Matrix output2 = sequaltial.forward(output1,weight2,bias2); +``` + +同时第二层的输出也可以求出来,以此类推 . + +最终输出代码见nerual_test.cpp ![nerual_test1](/Users/zhangyiji/Documents/code/cpp_demo/my_os/Edge-Computing-Engine/picture/nerual_test1.png) + 代码: ```c diff --git a/file_pro/.data_read.h.swp b/file_pro/.data_read.h.swp deleted file mode 100644 index 9783bf9da1210336b8144958d282d7299b2fad39..0000000000000000000000000000000000000000 Binary files a/file_pro/.data_read.h.swp and /dev/null differ diff --git a/grad_edge/matrix_grad.h b/grad_edge/matrix_grad.h index 524dea9c0575603752874841cf760b669a4b6d82..f78679770498cfc516672ed3ebac9bc80254e704 100644 --- a/grad_edge/matrix_grad.h +++ b/grad_edge/matrix_grad.h @@ -18,9 +18,6 @@ Node sigmoid(Node z){ struct edge_network { edge_network(int input, int num_neuron){ - - - } Matrix forward(Matrix data,Matrix weights,Matrix bais) { diff --git a/ma b/ma index 2bda49bb2841ee486fb1d820956f7a8f49c663cf..55955ce7811b786e46889e267f9368688d8ceb64 100755 Binary files a/ma and b/ma differ diff --git a/main.cpp b/main.cpp index 1eafd8e78bf88869a6b440933c9ca9c843a5968e..555473cbebaee489910b00085ccaa5e0f4c340e9 100644 --- a/main.cpp +++ b/main.cpp @@ -5,7 +5,7 @@ #include #include #include "./autodiff/node.h" -#include"./matrix/matrix_def.h"a +#include"./matrix/matrix_def.h" #include"./matrix/matrix_pro.h" #include"./welcome/score_wel.cpp" #include"./logistic/logistic_def.h" @@ -29,38 +29,7 @@ return sigmoid_act; Node (*loss)(Node,Node) = loss_act; Node (*act)(Node) = sigmoid_act; int main() -{ /* - welcome(); - string path = "./data/new_data2.csv"; - Matrix data = read_csv(path); - Matrix bais = CreateMatrix(data.row,1); - data = appply(data,bais,1); - Matrix y = iloc(data,0,0,3,4); - Matrix x_1 = iloc(data,0,0,0,3); - Matrix x_2 = get_T(x_1); - double alpha = 0.002; - int max_epoch = 1; - Matrix weight = CreateMatrix(3,1); - change_va(weight,0,0,1); - change_va(weight,1,0,1); - change_va(weight,2,0,1); - int epoch = 0; - for(epoch = 0;epoch<=max_epoch;epoch++) - { - cout<<"-----------split-line-----------"<count_word; - string path_word = "mytest.csv"; - str_Matrix data_readed = read_file(path_word); - for(int index_x = 0;index_x +#include +#include +#include +#include +#include"./autodiff/node.h" +#include"./matrix/matrix_def.h" +#include"./matrix/matrix_pro.h" +#include"./welcome/score_wel.cpp" +#include"./logistic/logistic_def.h" +#include"./file_pro/data_read.h" +#include"./grad_edge/matrix_grad.h" +using namespace std; +Node z = 1; +Node t1 = 1,a13 = 1; +Node loss_act(Node t1,Node a13) +{ + Node loss = 0.5*(pow((t1-a13),2)); + return loss; +} +Node sigmoid_act(Node z) +{ + Node sigmoid_act = 1/(1+(1/exp(z))); + return sigmoid_act; +} +Node (*loss)(Node,Node) = loss_act; +Node (*act)(Node) = sigmoid_act; +int main() +{ + cout<<"begin to train"<