void Read_Network_Weights()
{
    MATRIX_DOUBLE *MDIH;
    MATRIX_DOUBLE *MDHO;
/*  char *wts_input_file;   */

/*
 *   Clear_Screen;
 *   Move_To(10,5);
 *   wts_input_file=
 *   Get_String("Enter input-hidden weights file to read");
 *   MDIH = (MATRIX_DOUBLE *) Matrix_Read(wts_input_file);
 */

    MDIH = (MATRIX_DOUBLE *) Matrix_Read("ih_wts.dat");

    if(MDIH->element_size != sizeof(double)
            || MDIH->rows != HNODES || MDIH->cols != INODES ) {
        printf("\nWeights read from ih_wts.dat are inconsistant\n");
        exit(1);
    }
    IH_Wts = Matrix_Allocate_Double(HNODES, INODES);
    ASSIGN_MAT(MDIH->ptr,IH_Wts,HNODES,INODES,double,double);
    Matrix_Free((MATRIX_DOUBLE *) MDIH);
   
/*
 *   Clear_Screen;
 *   Move_To(10,5);
 *   wts_input_file=
 *   Get_String("Enter hidden-ouput weights file to read");
 *   MDHO = (MATRIX_DOUBLE *) Matrix_Read(wts_input_file);
 */

    MDHO = (MATRIX_DOUBLE *) Matrix_Read("ho_wts.dat");

    if(MDHO->element_size != sizeof(double)
            || MDHO->rows != ONODES || MDHO->cols != HNODES ) {
        printf("\nWeights read from ho_wts.dat are inconsistant\n");
        exit(1);
    }
    HO_Wts = Matrix_Allocate_Double(ONODES, HNODES);
    ASSIGN_MAT(MDHO->ptr,HO_Wts,ONODES,HNODES,double,double);
    Matrix_Free((MATRIX_DOUBLE *) MDHO);
    return;
}
void Read_Input_Patterns()
{

    char *input_file;
    FILE *input_fp;
    int i, j, k; 
    char data_element[20];
    double r;

    input_fp = fopen(INPUTS,"r");

/*
    printf("\n\n\n\n    ");
    input_file = Get_String("Test input pattern file name (e.g. input.dat)");
    input_fp = fopen(input_file,"r");
*/

/*
 *  input_file = Vector_Allocate_Char(80);
 *  strcpy(input_file, "input.dat");
 *  input_fp = fopen(input_file,"r");
 */

    if(!input_fp) {
        printf("\n  %s not found \n", input_file);
        printf("\n Press any character to exit...");
        getchar();
        exit(1);
    }   

    Input_Pattern = Matrix_Allocate_Double(NPAT,INODES);

    for(i=0; i< CORENPAT; i++) {
        for(j=0; j< INODES; j++) {
            fscanf(input_fp," %s", data_element);
            Input_Pattern[i][j] = (double) atof(data_element);
        }
        fscanf(input_fp,"\n");
    }
    for(i=CORENPAT; i< NPAT; i++) {
        for(j=0; j< INODES; j++) {
            k = (i % CORENPAT);
            if (j == (NF_VAR_ONE-1)){
               Input_Pattern[i][j] = Input_Pattern[k][j];
            } 
            else if (j == (NF_VAR_TWO-1)){
               r = (double) ((double) rand()/(double) RAND_MAX);
               Input_Pattern[i][j] = MinLimit[j] + r*(MaxLimit[j]-MinLimit[j]);
            } 
            else {
               Input_Pattern[i][j] = Input_Pattern[k][j];
            }
        }
    }
    fclose(input_fp);
    return;
}
void Initialize_Network_Activations()
{
    int np,j;

    Onode_Act = Matrix_Allocate_Double(NPAT,ONODES);
    
    for(np=0; np< ONODES; np++)  {
        for(j=0; j< ONODES; j++)  {
            Onode_Act[np][j] = 0.0;
        }
    }

    Hnode_Act = Vector_Allocate_Double(HNODES);
    for(j=0; j< HNODES; j++)  {
        Hnode_Act[j] = 0.0;
    }
    return;
}
void Read_Target_Patterns()
{

    char *target_file;
    FILE *target_fp;
    int i, j; 
    char data_element[20];
 
 
    target_fp = fopen (TARGETS,"r");
 /*
    printf("\n\n\n\n    ");
    target_file=Get_String("Test target pattern file name (e.g. target.dat)");
    target_fp = fopen (target_file,"r");
 */
  
/*
 *  target_file = Vector_Allocate_Char(80);
 *  strcpy(target_file, "target.dat");
 *  target_fp = fopen(target_file,"r");
 */
   
    if(!target_fp) {
        printf("\n  %s not found \n", target_file);
        exit(1);
    }   
    
    Target_Pattern = Matrix_Allocate_Double(NPAT,ONODES);
 
    for(i=0; i< NPAT; i++) {
        for(j=0; j< ONODES; j++) {
            fscanf(target_fp," %s", data_element);
            Target_Pattern[i][j] = (double) atof(data_element);
        }
        fscanf(target_fp,"\n");
    }   
    fclose(target_fp);
    return;
}
Пример #5
0
void Read_Input_Patterns()
{

    char *input_file;
    FILE *input_fp;
    int i, j; 
    char data_element[20];

    input_fp = fopen(INPUTS,"r");

/*
    printf("\n\n\n\n    ");
    input_file = Get_String("Test input pattern file name (e.g. input.dat)");
    input_fp = fopen(input_file,"r");
*/

/*
 *  input_file = Vector_Allocate_Char(80);
 *  strcpy(input_file, "input.dat");
 *  input_fp = fopen(input_file,"r");
 */

    if(!input_fp) {
        printf("\n  %s not found \n", input_file);
        exit(1);
    }   

    Input_Pattern = Matrix_Allocate_Double(NPAT,INODES);

    for(i=0; i< NPAT; i++) {
        for(j=0; j< INODES; j++) {
            fscanf(input_fp," %s", data_element);
            Input_Pattern[i][j] = (double) atof(data_element);
        }
        fscanf(input_fp,"\n");
    }
    fclose(input_fp);
    return;
}
Пример #6
0
// strFile pointe vers l'image à ouvrir
// QMu indique la direction de la transformée de Fourier Utilisée dans cette fonction
void Construct_Vues_Frequentielles(char * strFile, Quaternion QMu, double seuil)
{
    
    double **dblMatAngle,**dblMatLogModule,**dblMatLogModuleScaled,
        **dblMatAngleScaled,**dblMatAngleMod;
    int i,j,dim[2],type,blnReal;
    unsigned char ** blnLogModulusMaskMat;
    double *r,*g,*b, *dblData;
    Quaternion **QMatrix,**QMatFourier,**QMatrixShifted,**QMatAxe,
        **QMatAxeScaled,**QPureAxeMatMasked,**QAngleColourMasked,**QMatAxeScaled2;
    
    double dblMin,dblMax,dblRMin,dblRMax,dblIMin,dblIMax,dblJMin,dblJMax,dblKMin,dblKMax;
    char * result; //pour la chaine de caractere modifiant le nom du fichier
  
    //lecture de l'en-tete
    MgkTypeImage(strFile,dim,&type);
    
    //allocation des tableaux r,g et b
    r = (double *)malloc(dim[0]*dim[1]*sizeof(double));
    g = (double *)malloc(dim[0]*dim[1]*sizeof(double));
    b = (double *)malloc(dim[0]*dim[1]*sizeof(double));
    
    //remplissage des tableaux
    MgkLireImgCouleur(strFile,r,g,b);
    
    //copie dans matrice quaternionique
    QMatrixAllocate(dim[0],dim[1],&QMatrix);
    QSetMatrix(r,g,b,dim[0],dim[1],&QMatrix);
    printf("Moyenne de l'image d'origine :R%lf G%lf B%lf\n",VectMean_Double(r,dim),VectMean_Double(g,dim),VectMean_Double(b,dim));
    free(r);
	free(g);
	free(b);
	
    // traitement dans l'espace de fourier
    QMatrixAllocate(dim[0],dim[1],&QMatFourier);

	printf("quaternionic fourier transform is processing ...\n");
    Quaternion_Matrix_Fourier_Transform_ExpLeft(QMatrix,&QMatFourier,QMu,dim[0],dim[1]);
    printf("done.\n");
    QMatrixFree(dim[0],&QMatrix);
    
    
    QMatrixAllocate(dim[0],dim[1],&QMatrixShifted);
	QMatrixShift(QMatFourier,&QMatrixShifted,dim[0],dim[1]);
	QMatrixFree(dim[0],&QMatFourier);
	
    //maintenant on a la matrice QMatFourier qui comprend les informations fréquentielles de l'image

    
    // soucis avec cette méthode, on utilise des quaternions purs dans le domaine statial
    // faire attention qu'il n'y ait pas de partie réelle nulle dans le domaine fréquentiel
    // car problème après avec S(q)=0 pour calculer le phi=atan(|V(q)|/S(q))
    
    // donc ici on vérifie pas de partie réelle nulle
    // à faire
    blnReal=IsRealPresent(QMatrixShifted,dim,0.00001);
    printf("La partie réelle de la transformée de Fourier Quaternionique est non nulle (1 oui, 0 non):%d\n",blnReal);
    
    
    // on alloue les différentes matrices qui vont nous servir juste après.
    Matrix_Allocate_Double(dim[0],dim[1],&dblMatLogModule);
    Matrix_Allocate_Double(dim[0],dim[1],&dblMatAngle);
    QMatrixAllocate(dim[0],dim[1],&QMatAxe);
    
    //puis on calcule pour chaque point de la matrice, son module, son angle et son axe.
    Calcul_Matrice_LogRo_Mu_Phi((const Quaternion **)QMatrixShifted,&dblMatLogModule,&dblMatAngle,&QMatAxe,dim[0],dim[1]);
    QMatrixFree(dim[0],&QMatrixShifted);


    ///////////////////////////////////////////////////////////////////////////////////////////////
    //  MODULE
    printf("construction de la vue du module...\n");
    //le log du module est calculé suivant cette formule: *LogRo = log(QNorm(q));
    
    Dbl_Matrix_Min_Max((const double **) dblMatLogModule,dim,&dblMin,&dblMax);
    Matrix_Allocate_Double(dim[0],dim[1],&dblMatLogModuleScaled);
    
    Dbl_Mat_ChgScale_IntLvlMax((const double **) dblMatLogModule,dim,255,dblMin,dblMax,&dblMatLogModuleScaled);
    Matrix_Free_Double(dim[0],&dblMatLogModule);
    
    //on construit le masque a partir du log du module pour appliquer sur l'angle et l'axe
    Matrix_Allocate(dim[0],dim[1],&blnLogModulusMaskMat);
    Mask_From_LogModulus(seuil,dim,dblMatLogModuleScaled,&blnLogModulusMaskMat);
    

    
    //allocation sous forme de tableau monodimensionnel pour passe en argument a la fonction MgkEcrireImgGris
    dblData = (double *)malloc(dim[0]*dim[1]*sizeof(double));
    
    
    //GetUsgCharMatrix(Spectre255,&dblData,dim);
    GetDblTabMatrix(dblMatLogModuleScaled,&dblData,dim);
    Matrix_Free_Double(dim[0],&dblMatLogModuleScaled);
    result = (char *)malloc((10+strlen(strFile))*sizeof(char));
    strcpybtw(&result,strFile,"-qft-mod",'.');
    MgkEcrireImgGris(result,dblData,dim);
    printf("\nimage %s creee\n\n",result);
    free(result);
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // PHASE

    printf("construction de la vue de l'angle...\n");
    //la phase est calculée suivant cette formule:  *Phi = atan(QNorm(QImag(q))/QReal(q));
    // -pi/2 < phi < pi/2
    
    Dbl_Matrix_Min_Max((const double **) dblMatAngle,dim,&dblMin,&dblMax);
    printf("Angle min %lf Angle max %lf\n",dblMin,dblMax);
    
    //Matrix_Allocate_Double(dim[0],dim[1],&dblMatAngleScaled);
    
    //Dbl_Mat_ChgScale_LvlMin_LvlMax((const double **) dblMatAngle,dim,0.,2*M_PI,dblMin,dblMax,&dblMatAngleScaled);
    //Matrix_Free_Double(dim[0],&dblMatAngle);
    
    QMatrixAllocate(dim[0],dim[1],&QAngleColourMasked);
    QMat_Angle_Construct_WithLogModMask(dim,blnLogModulusMaskMat,dblMatAngle,&QAngleColourMasked);    
    Matrix_Free_Double(dim[0],&dblMatAngle);
    
    r = (double *)malloc(dim[0]*dim[1]*sizeof(double));
    g = (double *)malloc(dim[0]*dim[1]*sizeof(double));
    b = (double *)malloc(dim[0]*dim[1]*sizeof(double));
    QGetMatrixImagPart(&r,&g,&b,dim[0],dim[1],QAngleColourMasked);
    QMatrixFree(dim[0],&QAngleColourMasked);

    result = (char *)malloc((10+strlen(strFile))*sizeof(char));
    strcpybtw(&result,strFile,"-qft-angle",'.');
    MgkEcrireImgCouleur(result,r,g,b,dim);
    printf("\nimage %s creee\n\n",result);
    free(result);
    printf("Moyenne de l'image de l'angle :R%lf G%lf B%lf\n",VectMean_Double(r,dim),VectMean_Double(g,dim),VectMean_Double(b,dim));
    free(r);
	free(g);
	free(b); 
    
     ///////////////////////////////////////////////////////////////////////////////////////////////
     // AXE

    printf("construction de la vue de l'axe...\n");
    
    //l'axe est calculé suivant cette formule: *qMu = QScalDiv(QImag(q),QNorm(QImag(q)));
    QMat_Min_Max2((const Quaternion **)QMatAxe,dim,&dblMin,&dblMax);


    QMatrixAllocate(dim[0],dim[1],&QPureAxeMatMasked);
    QMat_Axe_Construct_WithLogModMask(dim,blnLogModulusMaskMat,QMatAxe,&QPureAxeMatMasked);
    Matrix_Free(dim[0],&blnLogModulusMaskMat);
    QMatrixFree(dim[0],&QMatAxe);
    
    
    QMat_Min_Max((const Quaternion **)QPureAxeMatMasked,dim,&dblRMin,&dblRMax,&dblIMin,&dblIMax,&dblJMin,&dblJMax,&dblKMin,&dblKMax);
    
    QMatrixAllocate(dim[0],dim[1],&QMatAxeScaled);
    
    QMat_ChgScale_IntLvlMax((const Quaternion **)QPureAxeMatMasked,dim,255,dblRMin,dblRMax,dblIMin,dblIMax,dblJMin,dblJMax,
    dblKMin,dblKMax,&QMatAxeScaled);
    
    QMatrixFree(dim[0],&QPureAxeMatMasked);

    r = (double *)malloc(dim[0]*dim[1]*sizeof(double));
    g = (double *)malloc(dim[0]*dim[1]*sizeof(double));
    b = (double *)malloc(dim[0]*dim[1]*sizeof(double));
    QGetMatrixImagPart(&r,&g,&b,dim[0],dim[1],QMatAxeScaled);
    QMatrixFree(dim[0],&QMatAxeScaled);
    result = malloc((10+strlen(strFile))*sizeof(char));
    strcpybtw(&result,strFile,"-qft-axe",'.');
    MgkEcrireImgCouleur(result,r,g,b,dim);
    printf("\nimage %s creee\n\n",result);
    free(result);
    free(r);
	free(g);
	free(b); 
 	
	
}