Je le code suivant pour un peu ai en utilisant Eigen, mais il a un comportement bizarre lorsqu'il est exécutéC++ Eigen jette l'erreur, mais se termine le calcul
#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());
}
la sortie de la console est:
Assertion a échoué: lhs.cols() == rhs.rows() & & "produit matriciel invalide" & & "si vous vouliez un effet coeff-sage ou un produit scalaire, utilisez les fonctions explicites respectives", fichier c: \ mingw \ include \ eigen \ src/Core/Product.h, ligne 97
Cette application a demandé au Runtime de le terminer de façon inhabituelle. Veuillez contacter l'équipe d'assistance de l'application pour plus d'informations.
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
aussi ouvre la gena_exe ne fonctionne pas fenêtre (je travaille sur un ordinateur portable Windows).
la chose étrange à ce sujet est que la prūogram est excuted à la fin et ne marche pas arrêter peut-être est-ce juste parce que mon code est plus rapide que l'erreur de manipulation lorsque l'erreur se produit
S'il vous plaît aider - Merci
merci pour votre réponse, maintenant j'utilise l'outil de débogage eclipse –