begin process at 2012 02 12 22:08:24
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Maths & Algorithmes

 > 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)


 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

Source avec Zip UN EXAMPLE D'APPLICATION EN CUDA DE L'ALGORITHME DE SCAN POU... par oguzaras
Source avec Zip Source avec une capture CHIFFREMENT DE VIGENERE par lajouad
Source avec Zip Source avec une capture ANALYSE SYNTAXIQUE par lajouad
Source avec Zip Source avec une capture STRUCTURE D'UNE MATRICE PAR LES LISTE LINÉAIRE (NON CONTUGUS... par benzarabel
Source avec Zip Source avec une capture DESSINER UNE ARBRE BINAIRE( MODE CONSOLE): par benzarabel

 Sources en rapport avec celle ci

Source avec Zip UN EXAMPLE D'APPLICATION EN CUDA DE L'ALGORITHME DE SCAN POU... par oguzaras
Source avec Zip Source avec une capture RÉSOLUTION SUDOKU (9X9) PAR BACKTRACKING RÉCURSIF INTELLIGEN... par Gallien69
Source avec Zip Source avec une capture EVALUATEUR_EXPRESSION_ARITHMETIQUE par Donald180v
Source avec Zip BELLMAN:LA VALEUR DU PLUS COURT CHEMIN ET LE PLUS COURT CHEM... par Perace
METHODE D'INTEGRATION par jad_raad

Commentaires et avis

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

Commentaire de Lossy311082 le 26/07/2008 16:44:58

kaiza ry ry bandy e!
alefao ndray ny partie 2

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

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


Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
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

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,295 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales