项目开始日期 : 2019/10/01
目前项目总代码 : 709 行
测试代码 : 810 行
测试环境:
MacBook Pro
编译器环境:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix目前实现的:
How to install and run the demo:
git clone git@github.com:AllenZYJ/Edge-Computing-Engine.git
cd to this dir
g++ main.cpp -o main
./main
Matrix API:
Matrix A:
| 第1列 | 第2列 | 第3列 | 第4列 | 第5列 |
|---|---|---|---|---|
| 72.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 |
| 0.0000 | 64.0000 | 0.0000 | 0.0000 | 0.0000 |
| 16.0000 | 8.0000 | 0.0000 | 0.0000 | 0.0000 |
| 0.0000 | 0.0000 | 56.0000 | 16.0000 | 32.0000 |
| 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 |
| 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 |
MAtrix B:
| 第1列 | 第2列 | 第3列 | 第4列 | 第5列 | 第6列 |
|---|---|---|---|---|---|
| 72.0000 | 0.0000 | 16.0000 | 0.0000 | 0.0000 | 0.0000 |
| 0.0000 | 64.0000 | 8.0000 | 0.0000 | 0.0000 | 0.0000 |
| 0.0000 | 0.0000 | 0.0000 | 56.0000 | 0.0000 | 0.0000 |
| 0.0000 | 0.0000 | 0.0000 | 16.0000 | 0.0000 | 0.0000 |
| 0.0000 | 0.0000 | 0.0000 | 32.0000 | 0.0000 | 0.0000 |
To
| 第1列 | 第2列 | 第3列 | 第4列 | 第5列 | 第6列 |
|---|---|---|---|---|---|
| 5184.0000 | 0.0000 | 1152.0000 | 0.0000 | 0.0000 | 0.0000 |
| 0.0000 | 4096.0000 | 512.0000 | 0.0000 | 0.0000 | 0.0000 |
| 1152.0000 | 512.0000 | 320.0000 | 0.0000 | 0.0000 | 0.0000 |
| 0.0000 | 0.0000 | 0.0000 | 4416.0000 | 0.0000 | 0.0000 |
| 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 |
| 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 |
double* flatten(Matrix mid1)
| 1 | 2 | 3 |
|---|---|---|
| 2 | 4 | 6 |
| 7 | 8 | 9 |
To
| 1 | 2 | 3 | 2 | 4 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|
| Like numpy.flatten |
Matrix appply(Matrix mid1,Matrix mid2,int axis = 0)
if axis=0 :
| 0 | 7 | 2 |
|---|---|---|
| 0 | 3 | 1 |
| 0 | 0 | 0 |
| 0 | 0 | 11 |
| 0 | 7 | 2 |
| 0 | 3 | 1 |
| 0 | 0 | 0 |
| 0 | 0 | 11 |
axis = 1:
| 0 | 7 | 2 | 0 | 7 | 2 |
|---|---|---|---|---|---|
| 0 | 3 | 1 | 0 | 3 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 11 | 0 | 0 | 11 |
#include<iostream>
#include<ctime>
#include<string>
#include <time.h>
#include <math.h>
#include <fstream>
#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"
using namespace std;
clock_t start, stop;
double duration;
int main()
{
welcome();
string path = "./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 = 100;
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-----------"<<endl;
Matrix temp_mul = mul(x_1,weight);
Matrix h =e_sigmoid(temp_mul);
Matrix error = subtract(y,h);
Matrix temp_update = mul(x_2,error);
Matrix updata = add(weight,times_mat(alpha,temp_update),0);
cout_mat(weight);
cout<<"epoch: "<<epoch<<" error: "<<matrix_sum(error)<<endl;
cout<<"-----------split-line-----------"<<endl;
}
stop = clock();
printf("%f\n", (double)(stop - start) / CLOCKS_PER_SEC);
return 0;
}
Something :
- Matrix'element is default 1
- Dynamically allocate memory to prevent matrix from being too large
- To save memory and delete later, use pointer to open up array space temporarily
- if free please delete(matrix);
- Api design like numpy or pandas
- Talking is cheap u can get the code
- welcome 🏃watched and star.
个人小站:极度空间
作者邮箱:zk@likedge.top | edge@ibooker.org.cn
QQ:2533524298