Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

PRÉDICTION ET MODELISATION DE SERIES TEMPORELLES PAR RESEAUX DE NEURONES ARTIFICIELS MULTICOUCHES(PARTIE 1)


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
 

Commentaires et avis

signaler à un administrateur
Commentaire de patou1979 le 21/07/2008 05:18:04

Tsara ka. Tena tsara. Izaho koa efa nanao an'io exo io t@ 4 eme année tao @ ISPM. Bon courage.
Patrick

signaler à un administrateur
Commentaire de Lossy311082 le 26/07/2008 16:44:58

kaiza ry ry bandy e!
alefao ndray ny partie 2

signaler à un administrateur
Commentaire de patou1979 le 26/07/2008 17:07:53

tsara ampiarahina ny interface graphique satria tsy voatry hahay borland C++ builder daholo ny olona. Manjary tsy mi-interresser olona raha toa ka tsy hainy ny mi-compiler an'ilay code

Ajouter un commentaire

Discussions en rapport avec ce code source dans le forum

Algorithme de compression STAR amélioré [ par hi_vivie2 ] Bonjour à tous,Je dois réaliser de manière urgente l'implémentation en java de l'algorithme de compression STAR amélioré appliqué aux images en mouvem Algorithme de compression STAR amélioré [ par hi_vivie2 ] Bonjour à tous,Je dois réaliser de manière urgente l'implémentation en java de l'algorithme de compression STAR amélioré appliqué aux images en mouvem un programme à creer [ par yoyo ] je dois creer un programme permettant d trouver les nombres premiers.l'algorithme est donné, et il utilise des tableaux dont les cases sont remplies p Récupérer une adresse IP. ( à partir de 2 cartes réseaux. ) [ par pcayrol ] Ma config : un PC avec deux cartes réseaux. Chaque carte a son adresse IP.Avec la fonction gethostbyname je recupere un pointeur HOSTENT qui pointe su Qui sait l'algorithme pour calculer les racines? [ par TMT ] Aidez-moi! Obtenir l'IP d'une connexion réseaux sur XP [ par jbrek ] Obtenir l'IP d'une connexion réseaux sur XP sous VC++ ?Est-ce possible ? Y a plusieurs manières ? Obtenir l'IP d'une connexion réseaux sur XP [ par jbrek ] Obtenir l'IP d'une connexion réseaux sur XP sous VC++ ?Est-ce possible ? Y a plusieurs manières ? conversion de la partie fractionnaire en base n [ par Alucard ] J'ai vu qu'il y avait beaucoup d'algorithme de la partie entière (int) d'un nombre en n'importe quel base mais je voulais savoir si quelqu'un avait un Algorithme de mélange [ par C2S ] bonjour, j'aimerais connaitre un algorithme de mélange d'un tableau... (aléatoire) ... c'est pour simuler une fonction "mélanger" relative a un paquet aide sur l'algorithme AMR [ par semecurbep ] Votre texte iciVotre texte ICIVotre texte ICI


Nos sponsors

Sondage...

CalendriCode

Juillet 2009
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Téléchargements

Logiciels à télécharger sur le même thème :

Comparez les prix Nouvelle version

Photothèque Nouveau !



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,686 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.