我已用本徵的一小艾本下面的代碼完成,但它有執行C++徵拋出錯誤但計算
#include <stdio.h>
#include <iostream>
#include <time.h>
#include <math.h>
#include <Eigen/Dense>
using namespace std;
using namespace Eigen;
MatrixXd sigmoid(MatrixXd);
MatrixXd sigmoid_d(MatrixXd);
class Layer{
public:
MatrixXd layerweights;
Layer(int x,int y){
layerweights.resize(x,y);
for(int i=0;i<layerweights.rows();i++){
for(int j=0;j<layerweights.cols();j++){
double r =(rand()/(double)(RAND_MAX)) * 2 - 1;
layerweights(i,j) = r;
}
}
}
Layer(){
this->layerweights.setZero();
}
};
class Network{
public:
Layer l1;
Layer l2;
MatrixXd inp;
MatrixXd outp;
int id;
Network(){
id = 0;
inp.resize(1,5);
inp << 0,1,2,3,4;
outp.resize(1,5);
outp << 0,1,4,9,16;
}
MatrixXd think(){
MatrixXd ol1 = sigmoid(inp * l1.layerweights);//1x5*5x5 1x5
MatrixXd ol2 = sigmoid(ol1 * l2.layerweights); //1x5*5x5 1x5
return ol2;
}
int main() {
Network generation [10];
srand(time(NULL));
for(int i=0;i<6;i++){ //initialize 1st generation
generation[i].l1 = Layer(5,5);
generation[i].l2 = Layer(5,5);
generation[i].id = i;
}
for(int i=0;i<=6;i++){
cout<<generation[i].think()<<'\n';
}
return 0;
}
MatrixXd sigmoid(MatrixXd x){
return 1./(1+(x.array() * -1).exp());
}
當在控制檯輸出是一些奇怪的行爲:
斷言失敗: lhs.cols()== rhs.rows()& &「無效矩陣產品」& &「如果你想要coeff-wise或dot產品使用各自的顯式函數」,文件c:\ mingw \ include \ eigen \ src/Core/Product.h,第97行
此應用程序已請求運行時以非常規方式終止它。 有關更多信息,請聯繫應用程序的支持團隊。
15.7222 7.48441 15.4497 8.88806 15.2964 8.90715 7.4913 4.46665 11.0792 9.32262 4.38281 5.5597 6.06866 7.33861 3.5983 5.69089 2.82105 8.79453 2.2928 7.4683 14.2536 5.6492 11.3739 11.9831 5.04955 9.85721 16.4741 4.57733 3.87002 2.37858
也將打開運行不正常的gena_exe窗口(我在Windows筆記本電腦上工作)。
關於它的奇怪的是,prūogram被excuted結束和犯規阻止 也許這是因爲我的代碼是更快,則錯誤處理 發生錯誤時
請幫助 - 謝謝
感謝您的回答,現在我使用eclipse調試工具 –