提交 8cd1be16 编写于 作者: sahduashufa's avatar sahduashufa

add save_txt

上级 aa7c24ff
<div align=center><img src="./picture/01.svg"/></div> <div align=center><img src="./picture/01.svg"/></div>
# Edge-Engine # Edge-Engine
...@@ -78,6 +76,8 @@ Matrix API: ...@@ -78,6 +76,8 @@ Matrix API:
- [x] Matrix read_csv(string &file_path)读取格式化文件(csv),返回一个自动计算长度的矩阵. - [x] Matrix read_csv(string &file_path)读取格式化文件(csv),返回一个自动计算长度的矩阵.
- [x] int save_txt(Matrix mid1,string path = "./",string delimiter = ",",string header="./") 设计文件流获取文件头部接口 , 写入格式化文件 , 已设计支持矩阵类型数据写入,支持自定义表头,写入文件路径 , 自定义分隔符,默认为" , ".
- [x] Create a matrix : create(row,cols)开辟一个矩阵结构的内存,元素初值为0; - [x] Create a matrix : create(row,cols)开辟一个矩阵结构的内存,元素初值为0;
- [x] Change the element for matrix void move_ele(int &ele1, int &ele2),修改某一个位置的元素的值. - [x] Change the element for matrix void move_ele(int &ele1, int &ele2),修改某一个位置的元素的值.
......
...@@ -95,4 +95,21 @@ Matrix read_csv(string &file_path) ...@@ -95,4 +95,21 @@ Matrix read_csv(string &file_path)
} }
return data_ma; return data_ma;
} }
int save_txt(Matrix mid1,string path = "./",string delimiter = ",",string header="./")
{
int index_x,index_y;
ofstream fout(path,ios::app);
fout<<header<<endl;
for(index_x=0;index_x<mid1.row;index_x++)
{
for(index_y=0;index_y<mid1.col;index_y++)
{
fout<<mid1.matrix[index_x][index_y]<<delimiter;
}
fout<<endl;
}
fout.close();
return 0;
}
//-----------split------------ //-----------split------------
无法预览此类型文件
...@@ -17,6 +17,7 @@ int main() ...@@ -17,6 +17,7 @@ int main()
{ {
welcome(); welcome();
string path = "./data/nerual_data.csv"; string path = "./data/nerual_data.csv";
ofstream fout( "mytest.txt" );
Matrix data = read_csv(path); Matrix data = read_csv(path);
Matrix bais = CreateMatrix(data.row,1); Matrix bais = CreateMatrix(data.row,1);
Matrix x = iloc(data,0,100,0,2); Matrix x = iloc(data,0,100,0,2);
...@@ -27,7 +28,7 @@ int main() ...@@ -27,7 +28,7 @@ int main()
Matrix W2 = CreateRandMat(H_num,out_Dim); Matrix W2 = CreateRandMat(H_num,out_Dim);
cout_mat(W1); cout_mat(W1);
cout_mat(W2); cout_mat(W2);
for(int epoch = 0;epoch<100;epoch++) for(int epoch = 0;epoch<500;epoch++)
{ {
Matrix x_w1 = mul(x,W1); Matrix x_w1 = mul(x,W1);
Matrix re = mat_relu(x_w1); Matrix re = mat_relu(x_w1);
...@@ -47,5 +48,6 @@ int main() ...@@ -47,5 +48,6 @@ int main()
cout_mat(W2); cout_mat(W2);
cout<<"loss"<<": "; cout<<"loss"<<": ";
cout<<matrix_sum(mat_sq)/100<<endl; cout<<matrix_sum(mat_sq)/100<<endl;
save_txt(W1,"result.csv",",","header");
} }
} }
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册