Accueil > > > PRÉDICTION ET MODELISATION DE SERIES TEMPORELLES PAR RESEAUX DE NEURONES ARTIFICIELS MULTICOUCHES(PARTIE 1)
PRÉDICTION ET MODELISATION DE SERIES TEMPORELLES PAR RESEAUX DE NEURONES ARTIFICIELS MULTICOUCHES(PARTIE 1)
Information sur la source
Description
Modélisation de la croissance de la population par l'application logistique: Xn+1=AXn(1-Xn)=f(Xn) (A paramètre de non-linéarité, 0<Xn<1 n elem N) Les fonctions utiles 1.Generation des valeurs de Xn 2.Transposer d'une matrice 3.Produit d'une matrice 4.Diagonalisation d'une matrice NXN 5.Fonction cosinus/sinus 6.Valeur propre 7.Calcul du nombre de couche d'entrée en RNA 8.Calcul d'erreur d'approximation moyenne 9.Apprentissage du réseau Prédiction (J'ai divisé en 2 parties: et voici la première... )
Source
- //---------------------------------------------------------------------------
-
- #include <vcl.h>
- #pragma hdrstop
-
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- #include<math.h>
-
- TForm1 *Form1;
-
- int itr=0;
- float paramA,X[500],X1[500][500],transX1[500][500],produitX1transX1[500][500],transP[500][500],mat1[500][500],mat2[500][500],pdsortieW[500],N[500],saveN[500] ;
- float A[500][500],derniereMatrice[500][500],valeurpropre[500],valeurpropre1[500],P[500][500],erreurappr[500],V[500][500],W[500][500],Sortie[500];
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
-
-
- void __fastcall TForm1::Button1Click(TObject *Sender)
- { Memo1->Text="";
- if (Edit1->Text=="")
- ShowMessage("Entrer une valeur pour le paramètre de non-linéarité");
- else {
- paramA=StrToFloat(Edit1->Text);
- X[0]=0.1;
-
- for(int i=0;i<500;i++)
- {
- X[0]=0.1;
- X[i+1]=paramA*X[i]*(1-X[i]);
- Memo1->Lines->Add("X["+IntToStr(i)+"]="+X[i]);
- }
- }
-
- }
- //---------------------------------------------------------------------------
- //--------------------------construction de la matrice X1 à partir de X-------------------------------------------------
-
- void creer_matriceX1(float matX1[500],int dimension)
- {
-
- for(int i=0;i<dimension;i++)
- {
- for(int j=0;j<dimension;j++)
- {
- if(i>=0){X1[i][0]=matX1[i];}
- else X1[i][j]=0;
- }
- }
- }
-
- //---------------------------------------------------------------------------
- //--------------------------transposer de la matrice X1------------------------------------------------
-
-
- void transposer_matriceX1(float t_X1[500][500],int dimension)
- {
- for(int i=0;i<dimension;i++)
- {
- for(int j=0;j<dimension;j++)
- {
- transX1[i][j]=t_X1[j][i];
- }
- }
- }
-
- //---------------------------------------------------------------------------
- //--------------------------produit de la matrice X1 avec la matrice transX1(COVARIANCE)-------------------------------------------------
-
-
-
- void produit_matrice(float pX1[500][500],float ptransX1[500][500],int dimension)
- {
- for(int i=0;i<dimension;i++)
- for(int j=0;j<dimension;j++)
- {
- float somme=0;
- for(int k=0;k<dimension;k++)
- {
- somme+=pX1[i][k]*ptransX1[k][j];
- }
- produitX1transX1[i][j]=somme;
- }
- }
-
-
-
- //-------------------------------------------------------------------------
- //-------------------------------------------------------------------------
-
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- Memo1->Text="";
- creer_matriceX1(X,StrToInt(Edit2->Text));
- transposer_matriceX1(X1,StrToInt(Edit2->Text));
- produit_matrice(X1,transX1,StrToInt(Edit2->Text));
-
- for(int i=0;i<StrToInt(Edit2->Text);i++)
- {
- for(int j=0;j<StrToInt(Edit2->Text);j++)
- Memo1->Lines->Add("covariance["+ IntToStr(i)+"]["+ IntToStr(j)+"]="+produitX1transX1[i][j]);
- }
- }
- //---------------------------------------------------------------------------
- //-------------------------------------------------------------------------
-
-
-
-
- //---------------------ETAPE 2----------------------------------------------
-
-
-
- //-------------------------------------------------------------------------
- //-------------------------------creation de la matrice A--------------------------------------------
-
- void creer_matriceA(float A1[500][500],int dimension)
- {
- for(int i=0;i<dimension;i++)
- for(int j=0;j<dimension;j++)
- A1[i][j]=produitX1transX1[i][j];
-
- }
-
- //------------------------------------------------------------------
- //--------maximum ligne--------------------------------------------
- int maxiligne(float pA[500][500],int dimension)
- {
- float maximum=pA[0][1];
- int maxligne=0;
- for(int i=0;i<dimension;i++)
- {
- for(int j=0;j<dimension;j++)
- {
- if(i!=j)
- {
- if(pA[i][j]>=maximum)
- {
- maximum=pA[i][j];
- maxligne=i;
- }
- }
- }
- }
- return maxligne;
- }
-
- //------------------------------------------------------------------
- //--------maximum colonne--------------------------------------------
- int maxicolonne(float pA[500][500],int dimension)
- {
- float maximum=pA[0][1];
- int maxcolonne=0;
- for(int i=0;i<dimension;i++)
- {
- for(int j=0;j<dimension;j++)
- {
- if(i!=j)
- {
- if(pA[i][j]>=maximum)
- {
- maximum=pA[i][j];
- maxcolonne=j;
- }
- }
- }
- }
- return maxcolonne;
- }
-
- //-------------------------------------------------------------------------
- //---------cosinus-----------------------------------
- double get_cos(double c,double b)
- {
- double cos_teta;
- cos_teta=sqrt(0.5*(1+(b/sqrt(c*c+b*b))));
- return cos_teta;
- }
- //-------------------------------------------------------------------------
- //---------sinus----------
- double get_sin(double c,double b)
- {
- double sin_teta,cos_teta;
- cos_teta=sqrt(0.5*(1+(b/sqrt(c*c+b*b))));
- sin_teta=c/(2*cos_teta*sqrt(c*c+b*b));
- return sin_teta;
- }
-
- //-------------------------------------------------------------------------
- //---------creation de P-----------------------------------
-
- void creer_matriceP(float pP[500][500],float val1,float val2,int lignmax,int colonnmax,int dimension)
- {
-
- for(int i=0;i<dimension;i++)
- {
- for(int j=0;j<dimension;j++)
- {
- if((i==lignmax)&&(j==colonnmax))
- pP[i][j]=-val2;
- if((i==lignmax)&&(j==lignmax))
- pP[i][j]=val1;
- if((i==colonnmax)&&(j==colonnmax))
- pP[i][j]=val1;
- if((i==colonnmax)&&(j==lignmax))
- pP[i][j]=val2;
- }
- }
- for(int i=0;i<dimension;i++)
- {
- for(int j=0;j<dimension;j++)
- {
- if(i==j)
- {
- if(pP[i][j]==0)
- pP[i][i]=1;
- }
- }
- }
- }
-
- //-------------------------------------------------------------------------
- //---------transposer de P-----------------------------------
-
-
- void transposer_matriceP(float ptransP[500][500],float pP[500][500],int dimension)
- {
-
- for(int i=0;i<dimension;i++)
- for(int j=0;j<dimension;j++)
- ptransP[i][j]=pP[j][i];
- }
-
-
- //---------------------------------------------------------------------------------------------------
- //-----------produit de matrices P*Pt-------------------------------------------------------------------
- void produit_mat1(float pA[500][500],float ptransP[500][500],int dimension)
- {
-
- for(int i=0;i<dimension;i++)
- {
- for(int j=0;j<dimension;j++)
- {
- float somme=0;
- for(int k=0;k<dimension;k++)
- somme+=pA[i][k]*ptransP[k][j];
- mat1[i][j]=somme;
- }
- }
- }
-
- void produit_mat2(float pP[500][500],float pmat1[500][500],int dimension)
- {
-
- for(int i=0;i<dimension;i++)
- {
- for(int j=0;j<dimension;j++)
- {
- float somme=0;
- for(int k=0;k<dimension;k++)
- {
- somme+=pP[i][k]*pmat1[k][j];
- }
- mat2[i][j]=somme;
- }
- }
- }
-
- //-------------------------------------------------------------------------
- //-------------------------------Diagonalisation--------------------------------------------
-
-
- double diagonalisation(float pA[500][500],int dimension)
- {
- float lnlnP;
- float cnlnP;
- double a,b;
-
-
-
- int lnmax=maxiligne(pA,dimension);
- int cnmax=maxicolonne(pA,dimension);
-
- a=2*pA[lnmax][lnmax];
- b=pA[lnmax][lnmax]-pA[cnmax][cnmax];
- if(pA[lnmax][lnmax]!=pA[cnmax][cnmax])
- {
- lnlnP=get_cos(a,b);
- lnlnP=get_sin(a,b);
- }
- else
- {
- lnlnP=sqrt(2)/2;
- cnlnP=sqrt(2)/2;
- }
- creer_matriceP(P,lnlnP,cnlnP,lnmax,cnmax,dimension);
- transposer_matriceP(transP,P,dimension);
- produit_mat1(A,transP,dimension);
- produit_mat2(P,mat1,dimension);
-
- return(0);
-
- }
-
- //-------------------------------------------------------------------------
- //-------------------------------Valeur propre-------------------------------------------
-
-
-
- void __fastcall TForm1::Button3Click(TObject *Sender)
- {
- itr++;
- creer_matriceA(A,StrToInt(Edit2->Text));
- diagonalisation(mat2,StrToInt(Edit2->Text));
- Memo1->Lines->Add(" ");
- Memo1->Lines->Add(" ");
- Memo1->Lines->Add("Valeur propre________________________");
- Memo1->Lines->Add(IntToStr(itr)+"itération");
- for(int i=0;i<StrToInt(Edit2->Text);i++)
- {
- valeurpropre[i]=mat2[i][i];
- Memo1->Lines->Add("valeurpropre["+IntToStr(i)+"]="+valeurpropre[i]);
- }
- }
-
- //---------------------------------------------------------------------------
- //-----------------------------Ordre décroissant----------------------------------------------
-
- void __fastcall TForm1::Button4Click(TObject *Sender)
- {
- Memo1->Text="";
- float save;
- for(int i=0;i<StrToInt(Edit2->Text);i++)
- valeurpropre1[i]=valeurpropre[i];
- for(int i=0;i<StrToInt(Edit2->Text);i++)
- {
- for(int j=i+1;j<StrToInt(Edit2->Text);j++)
- {
- if(valeurpropre1[i]<valeurpropre1[j])
- {
- save=valeurpropre1[j];
- valeurpropre1[j]=valeurpropre1[i];
- valeurpropre1[i]=save;
- }
- }
- }
- for(int i=0;i<StrToInt(Edit2->Text);i++)
- Memo1->Lines->Add(valeurpropre1[i]);
-
- }
- //---------------------------------------------------------------------------
-
-
- int Nombredecouchedentree(float perreurappr[500],int dimension)
- {
- for (int i=0;i<dimension;i++)
- perreurappr[i]=sqrt(valeurpropre1[i]+1);
-
- float c1,c2;
- float error;
- int n;
- c1=perreurappr[0];
- c2=perreurappr[1];
- for(int i=2;i<dimension;i++)
- {
- error=c2-c1;
- if(error<0.01){n=i;return (n-1);}
- else
- {
- c1=c2;
- c2=perreurappr[i];
- }
- }
- }
-
-
- void __fastcall TForm1::Button5Click(TObject *Sender)
- {
- Memo1->Text="";
- Memo1->Lines->Add("Nombre de couche d'entrée : "+IntToStr(Nombredecouchedentree(erreurappr,StrToInt(Edit2->Text))));
- for(int i=0;i<StrToInt(Edit2->Text);i++)
- Memo1->Lines->Add("Erreur d'aproximation moyenne : "+FloatToStr(erreurappr[i]));
- }
- //---------------------------------------------------------------------------
-
- //---------------------------------------------------------------------------
- //--------------------------------Motif d'entrée-------------------------------------------
-
- void motifdentree(int valeur)
- {
-
- for(int i=1;i<=2;i++)
- {
- V[1][i]=X[valeur+i-1];
- Form1->Memo1->Lines->Add("Motif d'entrée V[1]["+IntToStr(i)+"]="+V[1][i]);
- }
- }
- //---------------------------------------------------------------------------
- //--------------------------------Poidsd'entrée-------------------------------------------
-
- void poiddentree(int nbdunitecache)
- {
-
- for(int i=1;i<=nbdunitecache;i++)
- for(int j=1;j<=2;j++)
- {
- W[i][j]=0.5*j/1.5;
- Form1->Memo1->Lines->Add("poids d'entrée W["+IntToStr(i)+"]["+IntToStr(j)+"]="+W[i][j]);
- }
- }
-
- //---------------------------------------------------------------------------
- //--------------------------------Poidsdesortie-------------------------------------------
-
-
- void poiddesortie(int nbdunitecache)
- {
-
- for(int i=1;i<=nbdunitecache;i++)
- {
- pdsortieW[i]=0.2*i/0.7;
- Form1->Memo1->Lines->Add("poids de sortie["+IntToStr(i)+"]="+pdsortieW[i]);
- }
- }
- //---------------------------------------------------------------------------
- //--------------------------------fonction d'activation-------------------------------------------
- float fonctionG(float x)
- {
- float y;
- y=1/(1+exp(-x));
- return y;
- }
- //---------------------------------------------------------------------------
- //--------------------------------fonction d'activation (Primitive)-------------------------------------------
-
- float primitiveG(float x)
- {
- float y;
- y=exp(-x)/(1+exp(-x));
- return y;
- }
-
- //---------------------------------------------------------------------------
- //---------------addition entree--------------
- float additionentree(float V[500][500],float W[500][500],int valeur)
- {
- float sum=0;
- for(int i=1;i<=2;i++)
- sum+=W[valeur][i]*V[1][i];
- return sum;
- }
-
- //---------------------------------------------------------------------------
- //---------------addition sortie--------------
-
- float additionsortie(float V[500][500],float pdsortieW[500],int valeur)
- {
- float sum=0;
- for(int i=1;i<=valeur;i++)
- sum+=pdsortieW[i]*V[2][i];
- return sum;
- }
-
-
- //---------------------------------------------------------------------------
- //--------------------------------propagation vers l'avant-------------------------------------------
-
-
- void propagationverslavant(float V[500][500],float W[500][500],int nbdunitecache)
- {
- float h[500];
- for(int i=1;i<=nbdunitecache;i++)
- {
- h[i]=additionentree(V,W,i);
- V[2][i]=fonctionG(h[i]*h[i]);
- Form1->Memo1->Lines->Add("pro vers lavant V[2]["+IntToStr(i)+"]="+FloatToStr(V[2][i]));
- }
- }
-
- //---------------------------------------------------------------------------
- //--------------------------------Sortie prédite-------------------------------------------
-
-
-
- void sortiepredite(float V[500][500],float W[500][500],int nbunitecache,int valeur)
- {
- V[3][1]=additionsortie(V,pdsortieW,nbunitecache);
- Sortie[valeur+2]=V[3][1];
- Form1->Memo1->Lines->Add("V[3][1]="+FloatToStr(V[3][1]));
- }
-
- //---------------------------------------------------------------------------
- //--------------------------------Variance-------------------------------------------
-
-
- float Xvariance(float X[500],float W[500][500],int dimension)
- {
- float moyenne,variance,sum=0;
- float sum1=0;
- for(int i=1;i<=dimension;i++)
- sum1+=X[i-1]*W[1][i];
- moyenne=sum1/10;
- for(int k=1;k<dimension;k++)
- sum+=W[1][k]*(X[k-1]-moyenne)*(X[k-1]-moyenne);
- variance=sum/10;
- return(variance);
- }
-
- //---------------------------------------------------------------------------
- //--------------------------------Calcul du nombre d'unité caché-------------------------------------------
-
-
- int calculnbrdUcache(float Sortie[50],float X[500],float W[500][500],int dimension,int nbunitecache1)
- {
- double sum=0,resultat;
- float save;
- int nombredunite;
- for(int i=3;i<=dimension;i++)
- sum+=(X[i]-Sortie[i])*(X[i]-Sortie[i]);
- resultat=sum/(8*Xvariance(X,W,dimension)*Xvariance(X,W,dimension));
- N[nbunitecache1]=resultat;
- for(int i=1;i<=dimension-2;i++)
- saveN[i]=N[i];
- for(int i=1;i<=dimension-2;i++)
- {
- for(int j=i+1;j<dimension-2;j++)
- {
- if(saveN[i]<saveN[j])
- {
- save=saveN[j];
- saveN[j]=saveN[i];
- saveN[i]=save;
- nombredunite=i+1;
- }
- }
- }
- return nombredunite;
- }
-
- void __fastcall TForm1::Button6Click(TObject *Sender)
- {
- Memo1->Clear();
- for(int nombredunitecache=1;nombredunitecache<=StrToInt(Edit2->Text);nombredunitecache++)
- {
- Form1->Memo1->Lines->Add("------------------nombre couche="+IntToStr(nombredunitecache));
- for(int j=0;j<10;j++){
- motifdentree(j);
- poiddentree(nombredunitecache);
- poiddesortie(nombredunitecache);
- propagationverslavant(V,W,nombredunitecache);
- sortiepredite(V,W,nombredunitecache,j);
- }
- Memo1->Lines->Add("Nombre d'unité caché="+IntToStr(calculnbrdUcache(Sortie,X,W,StrToInt(Edit2->Text),nombredunitecache)));
- }
-
- }
-
- //---------------------------------------------------------------------------
-
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#include<math.h>
TForm1 *Form1;
int itr=0;
float paramA,X[500],X1[500][500],transX1[500][500],produitX1transX1[500][500],transP[500][500],mat1[500][500],mat2[500][500],pdsortieW[500],N[500],saveN[500] ;
float A[500][500],derniereMatrice[500][500],valeurpropre[500],valeurpropre1[500],P[500][500],erreurappr[500],V[500][500],W[500][500],Sortie[500];
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{ Memo1->Text="";
if (Edit1->Text=="")
ShowMessage("Entrer une valeur pour le paramètre de non-linéarité");
else {
paramA=StrToFloat(Edit1->Text);
X[0]=0.1;
for(int i=0;i<500;i++)
{
X[0]=0.1;
X[i+1]=paramA*X[i]*(1-X[i]);
Memo1->Lines->Add("X["+IntToStr(i)+"]="+X[i]);
}
}
}
//---------------------------------------------------------------------------
//--------------------------construction de la matrice X1 à partir de X-------------------------------------------------
void creer_matriceX1(float matX1[500],int dimension)
{
for(int i=0;i<dimension;i++)
{
for(int j=0;j<dimension;j++)
{
if(i>=0){X1[i][0]=matX1[i];}
else X1[i][j]=0;
}
}
}
//---------------------------------------------------------------------------
//--------------------------transposer de la matrice X1------------------------------------------------
void transposer_matriceX1(float t_X1[500][500],int dimension)
{
for(int i=0;i<dimension;i++)
{
for(int j=0;j<dimension;j++)
{
transX1[i][j]=t_X1[j][i];
}
}
}
//---------------------------------------------------------------------------
//--------------------------produit de la matrice X1 avec la matrice transX1(COVARIANCE)-------------------------------------------------
void produit_matrice(float pX1[500][500],float ptransX1[500][500],int dimension)
{
for(int i=0;i<dimension;i++)
for(int j=0;j<dimension;j++)
{
float somme=0;
for(int k=0;k<dimension;k++)
{
somme+=pX1[i][k]*ptransX1[k][j];
}
produitX1transX1[i][j]=somme;
}
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Memo1->Text="";
creer_matriceX1(X,StrToInt(Edit2->Text));
transposer_matriceX1(X1,StrToInt(Edit2->Text));
produit_matrice(X1,transX1,StrToInt(Edit2->Text));
for(int i=0;i<StrToInt(Edit2->Text);i++)
{
for(int j=0;j<StrToInt(Edit2->Text);j++)
Memo1->Lines->Add("covariance["+ IntToStr(i)+"]["+ IntToStr(j)+"]="+produitX1transX1[i][j]);
}
}
//---------------------------------------------------------------------------
//-------------------------------------------------------------------------
//---------------------ETAPE 2----------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------creation de la matrice A--------------------------------------------
void creer_matriceA(float A1[500][500],int dimension)
{
for(int i=0;i<dimension;i++)
for(int j=0;j<dimension;j++)
A1[i][j]=produitX1transX1[i][j];
}
//------------------------------------------------------------------
//--------maximum ligne--------------------------------------------
int maxiligne(float pA[500][500],int dimension)
{
float maximum=pA[0][1];
int maxligne=0;
for(int i=0;i<dimension;i++)
{
for(int j=0;j<dimension;j++)
{
if(i!=j)
{
if(pA[i][j]>=maximum)
{
maximum=pA[i][j];
maxligne=i;
}
}
}
}
return maxligne;
}
//------------------------------------------------------------------
//--------maximum colonne--------------------------------------------
int maxicolonne(float pA[500][500],int dimension)
{
float maximum=pA[0][1];
int maxcolonne=0;
for(int i=0;i<dimension;i++)
{
for(int j=0;j<dimension;j++)
{
if(i!=j)
{
if(pA[i][j]>=maximum)
{
maximum=pA[i][j];
maxcolonne=j;
}
}
}
}
return maxcolonne;
}
//-------------------------------------------------------------------------
//---------cosinus-----------------------------------
double get_cos(double c,double b)
{
double cos_teta;
cos_teta=sqrt(0.5*(1+(b/sqrt(c*c+b*b))));
return cos_teta;
}
//-------------------------------------------------------------------------
//---------sinus----------
double get_sin(double c,double b)
{
double sin_teta,cos_teta;
cos_teta=sqrt(0.5*(1+(b/sqrt(c*c+b*b))));
sin_teta=c/(2*cos_teta*sqrt(c*c+b*b));
return sin_teta;
}
//-------------------------------------------------------------------------
//---------creation de P-----------------------------------
void creer_matriceP(float pP[500][500],float val1,float val2,int lignmax,int colonnmax,int dimension)
{
for(int i=0;i<dimension;i++)
{
for(int j=0;j<dimension;j++)
{
if((i==lignmax)&&(j==colonnmax))
pP[i][j]=-val2;
if((i==lignmax)&&(j==lignmax))
pP[i][j]=val1;
if((i==colonnmax)&&(j==colonnmax))
pP[i][j]=val1;
if((i==colonnmax)&&(j==lignmax))
pP[i][j]=val2;
}
}
for(int i=0;i<dimension;i++)
{
for(int j=0;j<dimension;j++)
{
if(i==j)
{
if(pP[i][j]==0)
pP[i][i]=1;
}
}
}
}
//-------------------------------------------------------------------------
//---------transposer de P-----------------------------------
void transposer_matriceP(float ptransP[500][500],float pP[500][500],int dimension)
{
for(int i=0;i<dimension;i++)
for(int j=0;j<dimension;j++)
ptransP[i][j]=pP[j][i];
}
//---------------------------------------------------------------------------------------------------
//-----------produit de matrices P*Pt-------------------------------------------------------------------
void produit_mat1(float pA[500][500],float ptransP[500][500],int dimension)
{
for(int i=0;i<dimension;i++)
{
for(int j=0;j<dimension;j++)
{
float somme=0;
for(int k=0;k<dimension;k++)
somme+=pA[i][k]*ptransP[k][j];
mat1[i][j]=somme;
}
}
}
void produit_mat2(float pP[500][500],float pmat1[500][500],int dimension)
{
for(int i=0;i<dimension;i++)
{
for(int j=0;j<dimension;j++)
{
float somme=0;
for(int k=0;k<dimension;k++)
{
somme+=pP[i][k]*pmat1[k][j];
}
mat2[i][j]=somme;
}
}
}
//-------------------------------------------------------------------------
//-------------------------------Diagonalisation--------------------------------------------
double diagonalisation(float pA[500][500],int dimension)
{
float lnlnP;
float cnlnP;
double a,b;
int lnmax=maxiligne(pA,dimension);
int cnmax=maxicolonne(pA,dimension);
a=2*pA[lnmax][lnmax];
b=pA[lnmax][lnmax]-pA[cnmax][cnmax];
if(pA[lnmax][lnmax]!=pA[cnmax][cnmax])
{
lnlnP=get_cos(a,b);
lnlnP=get_sin(a,b);
}
else
{
lnlnP=sqrt(2)/2;
cnlnP=sqrt(2)/2;
}
creer_matriceP(P,lnlnP,cnlnP,lnmax,cnmax,dimension);
transposer_matriceP(transP,P,dimension);
produit_mat1(A,transP,dimension);
produit_mat2(P,mat1,dimension);
return(0);
}
//-------------------------------------------------------------------------
//-------------------------------Valeur propre-------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
itr++;
creer_matriceA(A,StrToInt(Edit2->Text));
diagonalisation(mat2,StrToInt(Edit2->Text));
Memo1->Lines->Add(" ");
Memo1->Lines->Add(" ");
Memo1->Lines->Add("Valeur propre________________________");
Memo1->Lines->Add(IntToStr(itr)+"itération");
for(int i=0;i<StrToInt(Edit2->Text);i++)
{
valeurpropre[i]=mat2[i][i];
Memo1->Lines->Add("valeurpropre["+IntToStr(i)+"]="+valeurpropre[i]);
}
}
//---------------------------------------------------------------------------
//-----------------------------Ordre décroissant----------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
Memo1->Text="";
float save;
for(int i=0;i<StrToInt(Edit2->Text);i++)
valeurpropre1[i]=valeurpropre[i];
for(int i=0;i<StrToInt(Edit2->Text);i++)
{
for(int j=i+1;j<StrToInt(Edit2->Text);j++)
{
if(valeurpropre1[i]<valeurpropre1[j])
{
save=valeurpropre1[j];
valeurpropre1[j]=valeurpropre1[i];
valeurpropre1[i]=save;
}
}
}
for(int i=0;i<StrToInt(Edit2->Text);i++)
Memo1->Lines->Add(valeurpropre1[i]);
}
//---------------------------------------------------------------------------
int Nombredecouchedentree(float perreurappr[500],int dimension)
{
for (int i=0;i<dimension;i++)
perreurappr[i]=sqrt(valeurpropre1[i]+1);
float c1,c2;
float error;
int n;
c1=perreurappr[0];
c2=perreurappr[1];
for(int i=2;i<dimension;i++)
{
error=c2-c1;
if(error<0.01){n=i;return (n-1);}
else
{
c1=c2;
c2=perreurappr[i];
}
}
}
void __fastcall TForm1::Button5Click(TObject *Sender)
{
Memo1->Text="";
Memo1->Lines->Add("Nombre de couche d'entrée : "+IntToStr(Nombredecouchedentree(erreurappr,StrToInt(Edit2->Text))));
for(int i=0;i<StrToInt(Edit2->Text);i++)
Memo1->Lines->Add("Erreur d'aproximation moyenne : "+FloatToStr(erreurappr[i]));
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//--------------------------------Motif d'entrée-------------------------------------------
void motifdentree(int valeur)
{
for(int i=1;i<=2;i++)
{
V[1][i]=X[valeur+i-1];
Form1->Memo1->Lines->Add("Motif d'entrée V[1]["+IntToStr(i)+"]="+V[1][i]);
}
}
//---------------------------------------------------------------------------
//--------------------------------Poidsd'entrée-------------------------------------------
void poiddentree(int nbdunitecache)
{
for(int i=1;i<=nbdunitecache;i++)
for(int j=1;j<=2;j++)
{
W[i][j]=0.5*j/1.5;
Form1->Memo1->Lines->Add("poids d'entrée W["+IntToStr(i)+"]["+IntToStr(j)+"]="+W[i][j]);
}
}
//---------------------------------------------------------------------------
//--------------------------------Poidsdesortie-------------------------------------------
void poiddesortie(int nbdunitecache)
{
for(int i=1;i<=nbdunitecache;i++)
{
pdsortieW[i]=0.2*i/0.7;
Form1->Memo1->Lines->Add("poids de sortie["+IntToStr(i)+"]="+pdsortieW[i]);
}
}
//---------------------------------------------------------------------------
//--------------------------------fonction d'activation-------------------------------------------
float fonctionG(float x)
{
float y;
y=1/(1+exp(-x));
return y;
}
//---------------------------------------------------------------------------
//--------------------------------fonction d'activation (Primitive)-------------------------------------------
float primitiveG(float x)
{
float y;
y=exp(-x)/(1+exp(-x));
return y;
}
//---------------------------------------------------------------------------
//---------------addition entree--------------
float additionentree(float V[500][500],float W[500][500],int valeur)
{
float sum=0;
for(int i=1;i<=2;i++)
sum+=W[valeur][i]*V[1][i];
return sum;
}
//---------------------------------------------------------------------------
//---------------addition sortie--------------
float additionsortie(float V[500][500],float pdsortieW[500],int valeur)
{
float sum=0;
for(int i=1;i<=valeur;i++)
sum+=pdsortieW[i]*V[2][i];
return sum;
}
//---------------------------------------------------------------------------
//--------------------------------propagation vers l'avant-------------------------------------------
void propagationverslavant(float V[500][500],float W[500][500],int nbdunitecache)
{
float h[500];
for(int i=1;i<=nbdunitecache;i++)
{
h[i]=additionentree(V,W,i);
V[2][i]=fonctionG(h[i]*h[i]);
Form1->Memo1->Lines->Add("pro vers lavant V[2]["+IntToStr(i)+"]="+FloatToStr(V[2][i]));
}
}
//---------------------------------------------------------------------------
//--------------------------------Sortie prédite-------------------------------------------
void sortiepredite(float V[500][500],float W[500][500],int nbunitecache,int valeur)
{
V[3][1]=additionsortie(V,pdsortieW,nbunitecache);
Sortie[valeur+2]=V[3][1];
Form1->Memo1->Lines->Add("V[3][1]="+FloatToStr(V[3][1]));
}
//---------------------------------------------------------------------------
//--------------------------------Variance-------------------------------------------
float Xvariance(float X[500],float W[500][500],int dimension)
{
float moyenne,variance,sum=0;
float sum1=0;
for(int i=1;i<=dimension;i++)
sum1+=X[i-1]*W[1][i];
moyenne=sum1/10;
for(int k=1;k<dimension;k++)
sum+=W[1][k]*(X[k-1]-moyenne)*(X[k-1]-moyenne);
variance=sum/10;
return(variance);
}
//---------------------------------------------------------------------------
//--------------------------------Calcul du nombre d'unité caché-------------------------------------------
int calculnbrdUcache(float Sortie[50],float X[500],float W[500][500],int dimension,int nbunitecache1)
{
double sum=0,resultat;
float save;
int nombredunite;
for(int i=3;i<=dimension;i++)
sum+=(X[i]-Sortie[i])*(X[i]-Sortie[i]);
resultat=sum/(8*Xvariance(X,W,dimension)*Xvariance(X,W,dimension));
N[nbunitecache1]=resultat;
for(int i=1;i<=dimension-2;i++)
saveN[i]=N[i];
for(int i=1;i<=dimension-2;i++)
{
for(int j=i+1;j<dimension-2;j++)
{
if(saveN[i]<saveN[j])
{
save=saveN[j];
saveN[j]=saveN[i];
saveN[i]=save;
nombredunite=i+1;
}
}
}
return nombredunite;
}
void __fastcall TForm1::Button6Click(TObject *Sender)
{
Memo1->Clear();
for(int nombredunitecache=1;nombredunitecache<=StrToInt(Edit2->Text);nombredunitecache++)
{
Form1->Memo1->Lines->Add("------------------nombre couche="+IntToStr(nombredunitecache));
for(int j=0;j<10;j++){
motifdentree(j);
poiddentree(nombredunitecache);
poiddesortie(nombredunitecache);
propagationverslavant(V,W,nombredunitecache);
sortiepredite(V,W,nombredunitecache,j);
}
Memo1->Lines->Add("Nombre d'unité caché="+IntToStr(calculnbrdUcache(Sortie,X,W,StrToInt(Edit2->Text),nombredunitecache)));
}
}
//---------------------------------------------------------------------------
Conclusion
J'ai posté ce code car je trouve que peu de gens sache comment programmer les réseaux de neurones artificiels et l'intelligence artificielle
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
logique mathématique [ par khaleddjeddi ]
[color=green]SVP aider moi pour faire cet algorithme....[/color] Algorithme de mise sous forme normale Toute fbf de LP admet une fnc et une fnd (minim
convertir un algorithme en pascal [ par telwithe ]
svp,je voudrai realiser un logiciel qui qui convertie un algorithme en un code ecrit en pascal ou en c.pour cela j'aimerai que vous m'aidiez a limiter
C++ Transformée de Fourier Rapide Algorithme du Papillon [ par mamadoucasa ]
Bonjour, Je cherche à trouver le moyen de calculer une transformée de fourier rapide, j'ai déjà une idée grace aux précédents posts mais ne sais pas
définir un graphe dynamique en c++ [ par manelisg ]
salem, je suis débutante en c++ et je dois implémenter un algorithme pour max flow dans un graphe dynamique. donc j'ai besoin de définir ce graphe. J'
algorithme ordonnecement... [ par hano88 ]
Bonjour, Je veux implémenter l'algorithme EDF (Earliast Dealine First) en C++ qui fait l'ordre des taches périodiques, mais j'ai aucune idée. Par P
algorithme bruch and bound pour flowshop [ par ounissi ]
slt tt le monde.mon pfe conserne la génération automatique de code pour résoudre le probleme de flowshop par l'algorithme brunch and bound. si vous po
réseaux de neurones artificiels [ par rajaaESA ]
s'il vous plais qlq peut m'aider [i]on veut réaliser un apprentissage par rétro-propagation d'erreu sur une base de données,on vas considere un perc
algorithme parallèle [ par aapprendre ]
Bonjour, Est ce ke quelqu'un peut me donner un exemple d'algorithme parallèle très simple... merci
|
Derniers Blogs
[WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|