Пример #1
0
int
main(int argc, char *argv[]) {
	int i=2, j=3;
	i = MUDDLE(i,j);
	DEBUG_INT(i);
	j = MUDDLE(j,i);
	DEBUG_INT(j);
	return 0;
}
Пример #2
0
/**
eigentrain

computes the eigen space for matrix images.

This function is used in the training procedure of the face recognition pca
algorithm.
INPUT:  the data matrix of images
OUTPUT: mean: the mean value of the images
eigen_values: eigenvalues
eigen_base: eigenvectors

The data matrix is mean centered, and this is a side effect.
*/
void eigentrain(Matrix *mean, Matrix *eigen_vals,
                Matrix *eigen_base, Matrix images) 
{
    double p = 0.0;
    Matrix M, eigenvectors;

    DEBUG(1, "Calculating mean image.");
    *mean = get_mean_image(images);

    DEBUG(1, "Calculating the mean centered images for the training set.");
    mean_subtract_images(images, *mean);

    MESSAGE2ARG("Calculating Covariance Matrix: M = images' * images. M is a %d by %d Matrix.", images->col_dim, images->col_dim);
    M = transposeMultiplyMatrixL(images, images);
    DEBUG_INT(3, "Covariance Matrix Rows", M->row_dim);
    DEBUG_INT(3, "Covariance Matrix Cols", M->col_dim);

    DEBUG(2, "Allocating memory for eigenvectors and eigenvalues.");
    eigenvectors = makeMatrix(M->row_dim, M->col_dim);
    *eigen_vals = makeMatrix(M->row_dim, 1);


    MESSAGE("Computing snap shot eigen vectors using the double precision cv eigensolver.");

    cvJacobiEigens_64d(M->data, eigenvectors->data, (*eigen_vals)->data, images->col_dim, p, 1);

    freeMatrix(M);

    DEBUG(1, "Verifying the eigen vectors");
    /* Reconstruct M because it is destroyed in cvJacobiEigens */
    M = transposeMultiplyMatrixL(images, images);
    if (debuglevel >= 3)
        eigen_verify(M, *eigen_vals, eigenvectors);
    freeMatrix(M);

    *eigen_base = multiplyMatrix(images, eigenvectors);
    MESSAGE2ARG("Recovered the %d by %d high resolution eigen basis.", (*eigen_base)->row_dim, (*eigen_base)->col_dim);

    DEBUG(1, "Normalizing eigen basis");
    basis_normalize(*eigen_base);

    /*Remove last elements because they are unneeded.  Mean centering the image
    guarantees that the data points define a hyperplane that passes through
    the origin. Therefore all points are in a k - 1 dimensional subspace.
    */
    (*eigen_base)->col_dim -= 1;
    (*eigen_vals)->row_dim -= 1;
    eigenvectors->col_dim -= 1;

    DEBUG(1, "Verifying eigenbasis");
    if (debuglevel >= 3)
        basis_verify(images, *eigen_base);

    /* The eigenvectors for the smaller covariance (snap shot) are not needed */
    freeMatrix(eigenvectors);
}
Matrix findWCSMatrix(Matrix imspca, ImageList* srt, int *numberOfClasses, int writeTextInterm) {
    Matrix Sw;
    Matrix classmatrix = duplicateMatrix(imspca);
    ImageList *subject, *replicate;
    int maxClassSize = 0;
    int repCount;

    *numberOfClasses = 0;
    MESSAGE("Finding within-class scatter matrix.");
    for (subject = srt; subject; subject = subject->next_subject) {
        int classStart, classEnd;
        (*numberOfClasses)++;  /* Count the number of classes */

        DEBUG(3, "Finding the class indexes.");
        classStart = classEnd = subject->imageIndex;
        repCount = 0;
        for (replicate = subject; replicate; replicate = replicate->next_replicate) {
            repCount ++;
            classEnd = replicate->imageIndex;
        }

        if (repCount > maxClassSize) { maxClassSize = repCount; }

        if (repCount == 1 && !quiet) {
            printf("WARNING: class %d only contains one image.\n", *numberOfClasses);
        }

        DEBUG_INT(4, "Lower limit on class.", classStart);
        DEBUG_INT(4, "Upper limit on class.", classEnd);
        DEBUG(3, "Mean centering the class.");
        subtractClassMean(classmatrix, classStart, classEnd);

    }

    DEBUG_CHECK(maxClassSize > 1, "ERROR: at least one class must have more than one replicate.  Make sure your image list is not flat.");

    if (debuglevel > 3)
        printMatrix("classmatrix", classmatrix);

    if (writeTextInterm) { SAVE_MATRIX(classmatrix); } /* output textfiles of intermediate matrices */

    DEBUG(3, "Creating the class scatter matrix.");
    Sw = transposeMultiplyMatrixR(classmatrix, classmatrix);

    if (debuglevel > 3)
        printMatrix("Sw", Sw);
    return Sw;
}
Пример #4
0
void atlas_hw0_irqdispatch(struct pt_regs *regs)
{
	struct irqaction *action;
	unsigned long int_status;
	int irq, cpu = smp_processor_id();

	int_status = atlas_hw0_icregs->intstatus; 

	/* if int_status == 0, then the interrupt has already been cleared */
	if (int_status == 0)
		return;

	irq = ls1bit32(int_status);
	action = irq_desc[irq].action;

	DEBUG_INT("atlas_hw0_irqdispatch: irq=%d\n", irq);

	/* if action == NULL, then we don't have a handler for the irq */
	if ( action == NULL ) {
		printk("No handler for hw0 irq: %i\n", irq);
		spurious_count++;
		return;
	}

	irq_enter(cpu, irq);
	kstat.irqs[0][irq]++;
	action->handler(irq, action->dev_id, regs);
	irq_exit(cpu, irq);

	return;		
}
Пример #5
0
int request_irq(unsigned int irq, 
		void (*handler)(int, void *, struct pt_regs *),
		unsigned long irqflags, 
		const char * devname,
		void *dev_id)
{  
        struct irqaction *action;

	DEBUG_INT("request_irq: irq=%d, devname = %s\n", irq, devname);

	if (irq >= ATLASINT_END)
		return -EINVAL;
	if (!handler)
		return -EINVAL;

	action = (struct irqaction *)kmalloc(sizeof(struct irqaction), GFP_KERNEL);
	if(!action)
		return -ENOMEM;

	action->handler = handler;
	action->flags = irqflags;
	action->mask = 0;
	action->name = devname;
	action->dev_id = dev_id;
	action->next = 0;
	irq_desc[irq].action = action;
	enable_atlas_irq(irq);

	return 0;
}
void process_command(int argc, char** argv, Arguments* args)
{
    int i;
    int param_num = 0;

    /******* Set up default values *******/

    args->mode = octaveFormat;

    quiet = 0;
    debuglevel = 0;

    for (i = 1; i < argc; i++) {

        /* Catch common help requests */
        if      (readOption       (argc, argv, &i, "-help" )) {
            usage(argv[0]);
        }
        else if (readOption       (argc, argv, &i, "--help")) {
            usage(argv[0]);
        }

        /* other flags */
        else if (readOption       (argc, argv, &i, "-quiet")) {
            quiet = 1;
        }
        else if (readOptionInt    (argc, argv, &i, "-debuglevel", &debuglevel));
        else if (readOption       (argc, argv, &i, "-matlab")) {
            args->mode = matlabFormat;
        }

        /* check if the current argument is an unparsed option */
        else if (checkBadOption(argc,argv,&i));

        else if (param_num == 0) {
            args->trainingFile = strdup(argv[i]);
            param_num++;
        }
    }

    if (param_num < 1)
        usage (argv[0]);

    /* Print out the program parameters for appropriate debug level */

    DEBUG_INT (1, "Debuging enabled", debuglevel);

    if (debuglevel > 0)
    {
        printf ("***************** Program Parameters *********************\n");
        printf ("trainingFile: %s\n", args->trainingFile);
    }
}
Пример #7
0
/*
This function reads images in to a vector.  That vector is then mean subtracted
and then projected onto an optimal basis (PCA, LDA or LPP). Returned is a matrix
that contains the images after they have been projected onto the subspace.
*/
Matrix
readAndProjectImages (Subspace *s, char *imageNamesFile, char *imageDirectory, int *numImages, ImageList **srt)
{
    int i, j;
    Matrix images, vector, smallVector;
    char name[FILE_LINE_LENGTH];
    ImageList *subject, *replicate;

    DEBUG(1, "Reading training file names from file");

    *srt = getImageNames(imageNamesFile, numImages);

    DEBUG_CHECK(*srt, "Error: header no imagenames found in file image list file");

    /* Automatically determine number of pixels in images    */
    sprintf(name, "%s/%s", imageDirectory, (*srt)->filename);
    DEBUG(1, "Autodetecting number of pixels, i.e. vector length based on the size of image 0.");
    DEBUG_CHECK (autoFileLength(name) == s->numPixels, "Images sizes do not match subspace basis vector size");
    DEBUG_INT(1, "Vector length", s->numPixels);
    DEBUG_CHECK(s->numPixels > 0, "Error positive value required for a Vector Length");

    /*Images stored in the columns of a matrix */
    DEBUG(1, "Allocating image matrix");

    images = makeMatrix(s->basis->col_dim, *numImages);
    vector = makeMatrix(s->numPixels, 1);

    i = 0;
    for (subject = *srt; subject; subject = subject->next_subject) {
        for (replicate = subject; replicate; replicate = replicate->next_replicate) {
            if (debuglevel > 0)
                printf("%s ", replicate->filename);
            sprintf(name, "%s/%s", imageDirectory, replicate->filename);
            replicate->imageIndex = i;
            readFile(name, 0, vector);

            writeProgress("Reading images", i,*numImages);

            smallVector = centerThenProjectImages(s, vector);

            /* Copy the smaller vector into the image matrix*/
            for (j = 0; j < smallVector->row_dim; j++) {
                ME(images, j, i) = ME(smallVector, j, 0);
            }
            freeMatrix(smallVector);
            i++;  /* increament the image index */
        }
        if (debuglevel > 0)
            printf("\n");
    }

    return images;
}
Пример #8
0
static inline void atlas_hw0_irqdispatch(struct pt_regs *regs)
{
	unsigned long int_status;
	int irq;

	int_status = atlas_hw0_icregs->intstatus;

	/* if int_status == 0, then the interrupt has already been cleared */
	if (unlikely(int_status == 0))
		return;

	irq = ATLAS_INT_BASE + ls1bit32(int_status);

	DEBUG_INT("atlas_hw0_irqdispatch: irq=%d\n", irq);

	do_IRQ(irq, regs);
}
Пример #9
0
/**
* This function reads in the image list file.  It then
* takes the image filenames and reads in every file.
*
* @returns A Matrix containing all of the images
*/
Matrix readImages(char *imageNamesFile, char *imageDirectory, int *numPixels, int *numImages, int *numSubjects, ImageList **srt) {
    int i;
    Matrix images;
    ImageList *subject, *replicate;

    DEBUG(1, "Reading training file names from file");

    *srt = getImageNames(imageNamesFile, numImages);

    DEBUG_CHECK(*srt, "Error: header no imagenames found in file image list file");

    /* Automatically determine number of pixels in images    */

    DEBUG(1, "Autodetecting number of pixels, i.e. vector length based on the size of image 0.");
    *numPixels = autoFileLength(makePath(imageDirectory, (*srt)->filename));
    DEBUG_INT(1, "Vector length", * numPixels);
    DEBUG_CHECK(*numPixels > 0, "Error positive value required for a Vector Length");

    /* Images stored in the columns of a matrix */
    DEBUG(1, "Allocating image matrix");
    images = makeMatrix(*numPixels, *numImages);

    i = 0;
    (*numSubjects) = 0;
    for (subject = *srt; subject; subject = subject->next_subject) {
        for (replicate = subject; replicate; replicate = replicate->next_replicate) {
            if (debuglevel > 0)
                printf("%s ", replicate->filename);
            replicate->imageIndex = i;
            readFile(makePath(imageDirectory, replicate->filename), i++, images);
        }
        if (debuglevel > 0)
            printf("\n");
        (*numSubjects)++;
    }

    return images;

}
Пример #10
0
void unix_cb_disconn_succ(bt_dev_t *dev, bt_acl_t *acl, unsigned char reason) {
   DEBUG_STR("Disconnection successful");
   DEBUG_INT(reason);
   io_bd_addr(acl->peer->bd_addr);
}
Пример #11
0
/**
 * Process the command line and initialize the variables
 *
 * @param argc The number of arguments
 * @param argv The arguments
 */
void
process_command (int argc, char **argv, Arguments * args)
{
    int i;
    int param_num = 0;
    int cutOffSet = 0;

    /******* Set up default values *******/

    args->argc = argc;
    args->argv = argv;

    args->nIntrapersonal = 100;
    args->nExtrapersonal = 100;
    args->distanceMatrix = NULL;
    args->maxRank        = -1;

    args->cutOffMode      = CUTOFF_SIMPLE;
    args->cutOff          = DEFAULT_CUTOFF_PERCENT_SIMPLE;
    args->dropNVectors    = 0;

    debuglevel = 0;

    /******* Read command line arguments *******/

    for (i = 1; i < argc; i++) {

        /* Catch common help requests */
        if      (readOption       (argc, argv, &i, "-help" )) {
            usage(argv[0]);
        }
        else if (readOption       (argc, argv, &i, "--help")) {
            usage(argv[0]);
        }

        /* Read in input directories */
        else if (readOptionString (argc, argv, &i, "-imDir",     &(args->imageDirectory)));
        else if (readOptionString (argc, argv, &i, "-distances", &(args->distanceMatrix)));

        /* Read in number of images to generate */
        else if (readOptionInt    (argc, argv, &i, "-ni", &(args->nIntrapersonal)));
        else if (readOptionInt    (argc, argv, &i, "-ne", &(args->nExtrapersonal)));

        /* Read in maxRank */
        else if (readOptionInt    (argc, argv, &i, "-maxRank", &(args->maxRank)));

        /* Read in PCA training options */
        else if (readOptionInt    (argc, argv, &i, "-dropNVectors", &(args->dropNVectors)));

        else if (readOptionMatch(argc, argv, &i, "-cutOffMode", "NONE"))
        {
            args->cutOffMode = CUTOFF_NONE;
        }
        else if (readOptionMatch(argc, argv, &i, "-cutOffMode", "SIMPLE"))
        {
            args->cutOffMode = CUTOFF_SIMPLE;
        }
        else if (readOptionMatch(argc, argv, &i, "-cutOffMode", "ENERGY"))
        {
            args->cutOffMode = CUTOFF_ENERGY;
        }
        else if (readOptionMatch(argc, argv, &i, "-cutOffMode", "STRETCH"))
        {
            args->cutOffMode = CUTOFF_STRETCH;
        }
        else if (readOptionMatch(argc, argv, &i, "-cutOffMode", "CLASSES"))
        {
            args->cutOffMode = CUTOFF_CLASSES;
        }

        else if (readOptionDouble (argc, argv, &i, "-cutOff", &(args->cutOff)))
        {
            if ((args->cutOff <= 1.0) && (args->cutOff >= 0.000001)) {
                printf("WARNING: cutOff value is %f, expects percentage "
                       "between 0.0 and 100.0", args->cutOff);
                printf("         will proceed assuming value is as desired.");
            }
            cutOffSet = 1;
        }

        /* other flags */
        else if (readOption       (argc, argv, &i, "-quiet")) {
            quiet = 1;
        }
        else if (readOptionInt    (argc, argv, &i, "-debuglevel", &debuglevel));

        /* check if the current argument is an unparsed option */
        else if (checkBadOption(argc,argv,&i));

        /* read required arguments */
        else if (param_num == 0) {
            args->imageList = argv[i];
            param_num++;
        }
        else if (param_num == 1) {
            args->trainingFilename = strdup (argv[i]);
            param_num++;
        }
    }

    /* make sure that there are the proper number of required arguments */

    if (param_num != 2) {
        clParseError(argc,argv,i,"Wrong number of required arguments");
    }

    /* Print out the program parameters for appropriate debug level */

    DEBUG_INT (1, "Debuging enabled", debuglevel);
    if(debuglevel > 0) {
        printf("***************** Program Parameters *********************\n");
        printf ("Image directory:  %s\n", args->imageDirectory);
        printf ("Image list:       %s\n", args->imageList);
        printf ("nIntrapersonal:   %d\n", args->nIntrapersonal);
        printf ("nExtrapersonal:   %d\n", args->nExtrapersonal);
        printf ("distanceMatrix:   %s\n ", args->distanceMatrix);
    }
}
Пример #12
0
int avr_main_handle_uart(bt_dev_t *dev) {
   switch (bt_dev_read_hci(dev)) {
      case dev_evt_conn_request: 
         {
            unsigned char bd_addr[6], cod[3], link_type;
            
            DEBUG_STR("Connection request");
            memcpy(bd_addr, dev->ptr, 6);
            dev->ptr += 6;
            memcpy(cod, dev->ptr, 3);
            dev->ptr += 3;
            
            link_type = UINT8_UNPACK(dev->ptr);
            switch (link_type) {
               case 1:
                  /* ACL, accept */
                  if (handle == -1) {
                     DEBUG_STR("Accepting connection request");
                     bt_dev_pack_accept_conn(dev, bd_addr, 1);
                  } else {
                     DEBUG_STR("Rejecting connection request");
                     bt_dev_pack_reject_conn(dev, 
                           bd_addr,
                           HCI_REJECT_PERSONAL);
                  }
                  break;
                  
               default:
                  /* reject */
                  DEBUG_STR("Rejecting connection request");
                  bt_dev_pack_reject_conn(dev, 
                        bd_addr,
                        HCI_REJECT_PERSONAL);
                  break;
            }
            bt_dev_flush_hci(dev);
            break;
         }
         
      case dev_evt_conn_complete_succ:
         {
            unsigned short tmp_handle;
            unsigned char  bd_addr[6], link, encrypt;
            
            DEBUG_STR("Connection completion successful!");
            tmp_handle = UINT16_UNPACK(dev->ptr) & 0xFFF;
            memcpy(bd_addr, dev->ptr, 6); dev->ptr += 6;
            link = UINT8_UNPACK(dev->ptr);
            encrypt = UINT8_UNPACK(dev->ptr);
            
            if ((link == 1) && (handle == -1)) {
               DEBUG_STR("Acception connection");
               handle = tmp_handle;
            } else {
               DEBUG_STR("Already connected or SCO connection");
               DEBUG_INT(handle);
               bt_dev_pack_disconn(dev, 
                     tmp_handle,
                     HCI_DISCONNECT_USER);
               bt_dev_flush_hci(dev);
            }
            
            break;
         }
         
      case dev_evt_conn_complete_unsucc:
         {
            unsigned short tmp_handle;
            
            DEBUG_STR("Connection completion unsuccesful!");
            tmp_handle = UINT8_UNPACK(dev->ptr) & 0xFFF;
            
            if (tmp_handle == handle)
               handle = -1;
            break;
         }
         
      case dev_evt_disconn_complete_unsucc:
         DEBUG_STR("Close connection unsuccessful");
         break;
         
      case dev_evt_disconn_complete_succ:
         {
            unsigned short tmp_handle;
            unsigned char  reason;
            
            DEBUG_STR("Close connection");
            tmp_handle = UINT16_UNPACK(dev->ptr) & 0xfff;
            reason     = UINT8_UNPACK(dev->ptr);
                  
            if (tmp_handle == handle) {
               DEBUG_STR("Closing our connection");
               handle = -1;
            }
            break;
         }
         break;

      case dev_evt_acl:
         avr_handle_l2cap(dev);
         break;
         
      case dev_evt_timeout:
         break;
         
      default:
         break;
   }

   return 1;
}
Пример #13
0
void
readSubspace (Subspace *s, const char* trainingFile, int quiet)
{
    int i, j, headerSize, rowDim, colDim;
    char junk[FILE_LINE_LENGTH], text[FILE_LINE_LENGTH];
    char** header;
    float ftemp;
    FILE* file;

    headerSize = 255;
    header = (char**) malloc (sizeof(char*) * headerSize);
    assert (header);
    for (i = 0; i < headerSize; i++) {
        header[i] = (char*) malloc(sizeof(char) * FILE_LINE_LENGTH);
        assert (header[i]);
    }

    file = fopen (trainingFile, "rb");

    if (!file) {
        printf("Error: could not open file <%s>\n", trainingFile);
        exit(1);
    }

    for (i = 0; i < headerSize; i++)
        fgets(header[i], FILE_LINE_LENGTH, file);

    if (!quiet) {
        printf("\nTraining Header File is:\n");
        for (i = 0; i < TRAINING_HEADER_ENTRIES; i++)
            printf("   Line %d: %s", i, header[i]);
    }

    sscanf(header[7], "%s%s%d", junk, junk, &s->basisDim);
    sscanf(header[4], "%s%*s%s", junk, text);

    if (strcmp(text, "NO") == 0)
        s->useLDA = 0;
    else
        s->useLDA = 1;


    /*START: Changed by Zeeshan: for LPP*/
    sscanf(header[10], "%s%*s%s", junk, text);

    if (strcmp(text, "NO") == 0)
        s->useLPP = 0;
    else
        s->useLPP = 1;

    sscanf(header[11], "%s%s%d", junk, junk, &s->neighbourCount);
    sscanf(header[12], "%s%*s%s", junk, text);
    s->lppDistance = strdup(text);
    sscanf(header[13], "%s%s%d", junk, junk, &s->lppKeepNVectors);
    sscanf(header[14], "%s%s%d", junk, junk, &s->useAdaptiveK);
    /*END: Changed by Zeeshan: for LPP*/

    /*START: 	Changed by Zeeshan: for ICA*/
    sscanf(header[15], "%s%*s%s", junk, text);

    if (strcmp(text, "NO") == 0)
        s->useICA = 0;
    else
        s->useICA = 1;

    sscanf(header[16], "%s%s%d", junk, junk, &s->blockSize);
    sscanf(header[17], "%s%s%e", junk, junk, &ftemp);
    s->learningRate = (double)ftemp;
    sscanf(header[18], "%s%s%d", junk, junk, &s->iterations);
    sscanf(header[19], "%s%s%d", junk, junk, &s->arch);
    /*END: 		Changed by Zeeshan: for ICA*/


    readInt (file,&rowDim);
    s->numPixels = rowDim;
    DEBUG_INT (3, "Vector size", rowDim);
    s->mean = makeMatrix(rowDim, 1);
    for (i = 0; i < (s->mean)->row_dim; i++) {
        readDouble (file, &ME(s->mean,i,0));
    }

    readInt (file,&rowDim);
    s->values = makeMatrix (rowDim, 1);
    for (i = 0; i < (s->values)->row_dim; i++) {
        readDouble (file, &ME(s->values,i,0));
    }

    rowDim = s->numPixels;
    readInt (file,&colDim);
    s->basis = makeMatrix (rowDim, colDim);
    for (i = 0; i < (s->basis)->col_dim; i++) {
        for (j = 0; j < (s->basis)->row_dim; j++) {
            readDouble (file, &ME(s->basis, j, i));
        }
    }

    if(s->useICA)
    {
        /*START: 	Changed by Zeeshan: for ICA*/
        readInt (file,&rowDim);
        readInt (file,&colDim);
        s->ica2Basis = makeMatrix (rowDim, colDim);
        for (i = 0; i < (s->ica2Basis)->col_dim; i++) {
            for (j = 0; j < (s->ica2Basis)->row_dim; j++) {
                readDouble (file, &ME(s->ica2Basis, j, i));
            }
        }
        /*END: 		Changed by Zeeshan: for ICA*/
    }
    fclose(file);
}
Пример #14
0
void
subspaceTrain (Subspace *s, Matrix images, ImageList *srt, int numSubjects, int dropNVectors, CutOffMode cutOffMode, double cutOff, int useLDA, int writeTextInterm
               /*START Changed by Zeeshan: For LPP*/
               ,int useLPP, int neighbourCount, int useAdaptiveK, int lppKeepNVectors, char* lppDistance
               /*END Changed by Zeeshan: For LPP*/
               /*START 	Changed by Zeeshan: For ICA*/
               ,int useICA, int arch, double learningRate, int blockSize, int iterations
               /*END 	Changed by Zeeshan: For ICA*/
               )
{
    int i;
    Matrix m;
    int n = 0;    /* The number of eigen vectors to keep */
    double total_energy, energy;
    Matrix tmp;

    /* Initialize structure */

    s->useLDA         = useLDA;
    s->cutOffMode     = cutOffMode;
    s->cutOff         = cutOff;
    s->dropNVectors   = dropNVectors;

    s->numSubjects    = numSubjects;
    s->numPixels      = images->row_dim;

    /*START Changed by Zeeshan: For LPP*/
    s->useLPP 	    = useLPP;
    s->neighbourCount = neighbourCount;
    s->lppDistance    = strdup(lppDistance);
    s->lppKeepNVectors= lppKeepNVectors;
    s->useAdaptiveK   = useAdaptiveK;
    /*END Changed by Zeeshan: For LPP*/

    /*START Changed by Zeeshan: For ICA*/
    s->useICA 	    = useICA;
    s->arch	    = arch;
    s->ica2Basis 	    = NULL;
    s->learningRate   = learningRate;
    s->blockSize 	    = blockSize;
    s->iterations     = iterations;
    /*END Changed by Zeeshan: For ICA*/

    /*START Changed by Zeeshan: For ICA & LPP*/
    /*********************************************************************
    * STEP ZERO: Make sure LDA and LPP are executed exclusively
    ********************************************************************/
    DEBUG_CHECK (!(s->useLDA && s->useLPP) && !(s->useLDA && s->useICA) && !(s->useICA && s->useLPP), 
        "Either LDA, LPP or ICA should be executed.");
    /*END Changed by Zeeshan: For ICA & LPP*/


    /*********************************************************************
    * STEP ONE: Calculate the eigenbasis
    ********************************************************************/

    /* Compute the Eigenvalues and Eigenvectors for the covariance matrix
    derived from the images data matrix. The image data is "centered", meaning
    the mean image is subtracted from all images before PCA is performed.
    This centering is done in place, so after this call images are centered. */

    MESSAGE("Computing the PCA eigenspace.");

    eigentrain (&s->mean, &s->values, &s->basis, images);

    MESSAGE("Finished computing eigenspace.");

    /* Numerical roundoff errors may lead to small negative values.
    Strip those before saving the matrix. */

    m = s->values;
    for (i = 0; i < m->row_dim; i++)
    {
        if (ME(m,i,0) < 0) {
            if (ME(m,i,0) < -1e-10)
                printf("WARNING: Large negative eigenvalue found %f. Truncating to zero.\n", ME(m,i,0));
            ME(m,i,0) = 0;
        }
    }

    /*********************************************************************
    * STEP TWO: Drop eigenvectors from the front or truncate them from
    * the back
    ********************************************************************/

    /* 
    The following is used to filter the vectors that are retained after PCA
    training.  The function first optionally removes the vectors from the matrix
    based on the argument -dropNVectors. This argument is always intrepreted in
    terms of absolute numbers, i.e. a value of 1 means drop the first vector, a
    value of 3 means drop the first three. The function then drops vectors from the
    tail based on -cutOffMode and -cutOff arguments. Here, the mode controls how the
    cutoff is performed. The possible modes are:

    NONE:    Keep all remaining eigenvectors.
    SIMPLE:  Keep a percentage where the percentage is specified by cutOff.
    ENERGY:  Keep the fewest vectors are such that the sum of energy for them just
    exceeds cutOff times the total energy. 
    STRETCH: Keep all eigenvectors that have eigenvalues greater than a percentage 
    of the largest, where the percentage is specied by cutOff. 
    CLASSES: Keep as many eigenvectors as there are LDA classes.

    For both Energy and Stretch, if eigen values/vectors are dropped from the front, 
    these are not included in the determination of the total energy or the max
    eigen value. 
    */

    /* Drop the first vectors  */

    DEBUG_CHECK (s->dropNVectors < (s->basis)->col_dim, "Number of vectors to drop must be less than the number of the eigen vectors");

    /* transpose eigenValues for use in this function */

    tmp = transposeMatrix (s->values);
    freeMatrix (s->values);
    s->values = tmp;

    if (s->dropNVectors && (s->dropNVectors < (s->values)->col_dim))
    {
        tmp = matrixCols (s->basis, s->dropNVectors, (s->basis)->col_dim-1);
        freeMatrix (s->basis);
        s->basis = tmp;

        tmp = matrixCols (s->values, s->dropNVectors, (s->values)->col_dim-1);
        freeMatrix (s->values);
        s->values = tmp;
    }

    /* transpose the eigenValues back to the original order. */

    tmp = transposeMatrix (s->values);
    freeMatrix (s->values);
    s->values = tmp;

    DEBUG_CHECK((s->values)->row_dim - s->dropNVectors > 0, "Too many eigen vectors droped from front. Can not proceed.");

    switch (s->cutOffMode)
    {
    case CUTOFF_NONE:
        n = (s->basis)->col_dim;
        break;

    case CUTOFF_SIMPLE:
        n = (int)((s->basis)->col_dim * s->cutOff / 100.0);
        break;

    case CUTOFF_ENERGY:
        /* compute total energy - this will not include vectors/values dropped from front. */
        total_energy = 0;
        for (i = 0; i < (s->values)->row_dim; i++) {
            total_energy += ME(s->values, i, 0);
        }

        /* compute cutoff point */
        i = 0;
        energy = 0;
        while ((i < (s->values)->row_dim) && (energy < total_energy * s->cutOff / 100.0)) {
            energy += ME(s->values, i, 0);
            i++;
        }
        n = i;
        break;

    case CUTOFF_STRETCH:
        i = 1;
        while ((i < (s->values)->row_dim) &&
            (100.0*(ME(s->values, i, 0) / ME(s->values, s->dropNVectors, 0)) > cutOff )) {
                i++;
        }
        n = i;
        break;

    case CUTOFF_CLASSES:
        n = s->numSubjects;
        break;

    case CUTOFF_DROPVEC:
        n = (int)((s->basis)->col_dim - s->cutOff);
        break;

    default:
        n = 0;
        DEBUG_CHECK (0, "ERROR: Unkown cutoff type");
        break;
    };

    /* Never set the dimensionality of the PCA subspace below the number of
    LDA classes when LDA is being used. Doing so creates a horrible problem
    for LDA: too fee dimensions */

    if (s->useLDA && (n < s->numSubjects))
        n = s->numSubjects;

    DEBUG_CHECK (n <= (s->basis)->col_dim, "Tried to expand, not contract, PCA space.");

    MESSAGE1ARG ("Retaining %d eigen vectors.",n);

    tmp = matrixCols ( s->basis, 0 , n-1);
    freeMatrix (s->basis);
    s->basis = tmp;

    DEBUG_INT (1, "Number of eigen vectors kept.", n);

    DEBUG_CHECK ((s->basis)->col_dim > 0, "All basis vectors deleted after cutoff "
        "and vector drop was processed.");

    MESSAGE2ARG("Truncating PCA Space. Subspace projection expressed "
        "as %d by %d matrix.", s->basis->row_dim, s->basis->col_dim);

    /*********************************************************************
    * STEP THREE: Do the LDA if specified
    ********************************************************************/

    if (s->useLDA)
    {
        /* Need to project original images into PCA space */

        Matrix fisherBasis, fisherValues, combinedBasis;
        Matrix imspca = transposeMultiplyMatrixL (s->basis, images);

        MESSAGE("Computing Fisher Linear Discriminants for "
            "training images projected into PCA subspace.");

        fisherTrain (imspca, srt, &fisherBasis, &fisherValues, writeTextInterm);

        combinedBasis = multiplyMatrix (s->basis, fisherBasis);
        basis_normalize (combinedBasis);

        MESSAGE2ARG ("PCA and LDA Combined. Combined projection expressed as %d by "
            "%d matrix.", combinedBasis->row_dim, combinedBasis->col_dim);

        s->values = fisherValues;
        s->basis  = combinedBasis;
    }

    /*START Changed by Zeeshan: For LPP*/
    /*********************************************************************
    * STEP FOUR: Do the LPP if specified
    ********************************************************************/
    if (s->useLPP)
    {
        /* Need to project original images into PCA space */

        Matrix laplacianBasis, laplacianValues, combinedBasis;
        Matrix imspca = transposeMultiplyMatrixL (s->basis, images);           

        MESSAGE("Computing Locality Preservation Projections for "
            "training images projected into PCA subspace.");

        laplacianTrain (imspca, srt, &laplacianBasis, &laplacianValues, neighbourCount, 
            useAdaptiveK, lppKeepNVectors, &s->values, lppDistance, writeTextInterm);

        combinedBasis = multiplyMatrix (s->basis, laplacianBasis);
        basis_normalize (combinedBasis);

        MESSAGE2ARG ("PCA and LPP Combined. Combined projection expressed as %d by "
            "%d matrix.", combinedBasis->row_dim, combinedBasis->col_dim);

        s->values = calculateStandardDeviation (laplacianBasis);//OPTION4
        //s->values = laplacianValues;//OPTION2
        s->basis  = combinedBasis;

        for (i = 0; i < s->values->row_dim; i++)
        {
            if (ME(s->values, i, 0) <= 0.001)
            {
                if (ME(s->values, i, 0) < -1e-10)
                    printf("WARNING: Large negative value found %f. Truncating to zero.\n", ME(s->values, i, 0));
                ME(s->values, i, 0) = 0.001;
            }
        }


    }
    /*END Changed by Zeeshan: For LPP*/


    /*START Changed by Zeeshan: For ICA*/
    /*********************************************************************
    * STEP FIVE: Do the ICA if specified
    ********************************************************************/
    if (s->useICA)
    {
        /* Need to project original images into PCA space */
        Matrix independentBasis;
        Matrix imspca = transposeMultiplyMatrixL (s->basis, images);           

        MESSAGE("Computing independent components from the principle components.");

        independentTrain(s->basis, imspca, &independentBasis, s->arch, s->blockSize, s->learningRate, s->iterations);

        if (s->arch == 1)
        {
            Matrix combinedBasis;
            combinedBasis = multiplyMatrix (s->basis, independentBasis);
            s->basis  = combinedBasis;
            s->ica2Basis = NULL;

            MESSAGE2ARG ("PCA and ICA Combined. Combined projection expressed as %d by "
                "%d matrix.", combinedBasis->row_dim, combinedBasis->col_dim);	
        }
        else if (s->arch == 2)
        {
            s->ica2Basis = independentBasis;
            MESSAGE2ARG ("PCA and ICA kept separate. ICA projection expressed as %d by "
                "%d matrix.", independentBasis->row_dim, independentBasis->col_dim);	
        }
    }
    /*END Changed by Zeeshan: For ICA*/
}
Пример #15
0
extern int
sslc_init(char* serverIpAddress, unsigned short serverPort, int portType, int *mySocket, const char *pCn)
{
    sbyte4   connectionInstance = 0;
    sbyte4   s4QueueId = 0;
    ipaddr_t host;
    int      status = SSLC_OK;
    sslConnect *ssl = NULL;
    
    /* Initial TCP Queue */
    s4QueueId = sslc_find_a_queue();

    if (s4QueueId == -1)
    {
       status = -1;
       goto exit;
    }
    DEBUG_PRINT(DEBUG_SSL_MESSAGES, (sbyte *)"Connecting to host ");
    DEBUG_PRINT(DEBUG_SSL_MESSAGES, (sbyte *)serverIpAddress);
    DEBUG_PRINT(DEBUG_SSL_MESSAGES, (sbyte *)":");
    DEBUG_INT(DEBUG_SSL_MESSAGES, serverPort);
    DEBUG_PRINTNL(DEBUG_SSL_MESSAGES, (sbyte *)"");

    if (SSLC_OK > (status = sslc_create_connect(serverIpAddress, serverPort, mySocket, &host, portType))) {
        DEBUG_PRINT(DEBUG_SSL_MESSAGES, (sbyte *)"host addr type ");
        DEBUG_INT(DEBUG_SSL_MESSAGES, host.type);
        DEBUG_PRINTNL(DEBUG_SSL_MESSAGES, (sbyte *)"");

        sslc_release_a_queue(s4QueueId);
        goto exit;
    }

    DEBUG_PRINT(DEBUG_SSL_MESSAGES, (sbyte *)"Passed sslc_create_connect ");
    DEBUG_PRINT(DEBUG_SSL_MESSAGES, (sbyte *)serverIpAddress);
    DEBUG_PRINT(DEBUG_SSL_MESSAGES, (sbyte *)" socket ");
    DEBUG_HEXINT(DEBUG_SSL_MESSAGES, *mySocket);
    DEBUG_PRINTNL(DEBUG_SSL_MESSAGES, (sbyte *)"");
    ssl = (sslConnect *)*mySocket;
    ssl->s4QueueId = s4QueueId;
    
    if (OK > (connectionInstance = SSL_connect((sbyte4)ssl->tcp, 0, NULL, NULL, (sbyte *)pCn)))
    {
        DEBUG_PRINT(DEBUG_SSL_MESSAGES, (sbyte *)"SSL_connect error ");
        DEBUG_INT(DEBUG_SSL_MESSAGES, connectionInstance);
        DEBUG_PRINTNL(DEBUG_SSL_MESSAGES, (sbyte *)"");

        status = connectionInstance;
        sslc_release_a_queue(s4QueueId);
        sslc_glue_tcp_close((struct tcb *)ssl->tcp); 
        GLUE_FREE(ssl);
        *mySocket = NULL; 
        goto exit;
    }

    DEBUG_PRINTNL(DEBUG_SSL_MESSAGES, (sbyte *)"passed SSL_connect");
    if (OK > (status = SSL_assignCertificateStore(connectionInstance, host_cert_store)))
    {
        DEBUG_PRINT(DEBUG_SSL_MESSAGES, (sbyte *)"SSL_assignCertificiateStore error = ");
        DEBUG_INT(DEBUG_SSL_MESSAGES, status);
        DEBUG_PRINTNL(DEBUG_SSL_MESSAGES, (sbyte *)"");
        sslc_release_a_queue(s4QueueId);
        sslc_glue_tcp_close((struct tcb *)ssl->tcp); 
        SSL_closeConnection(connectionInstance);
        GLUE_FREE(ssl);
        *mySocket = NULL; 
        goto exit;
    }

    if (OK > (status = SSL_negotiateConnection(connectionInstance)))
    {
        DEBUG_PRINT(DEBUG_SSL_MESSAGES, (sbyte *)"SSL_negotiateConnection error = ");
        DEBUG_INT(DEBUG_SSL_MESSAGES, status);
        DEBUG_PRINTNL(DEBUG_SSL_MESSAGES, (sbyte *)"");
        sslc_release_a_queue(s4QueueId);
        sslc_glue_tcp_close((struct tcb *)ssl->tcp); 
        SSL_closeConnection(connectionInstance);
        GLUE_FREE(ssl);
        *mySocket = NULL; 
        goto exit;
    }

    (ssl->tcp)->sslConnectionInstance = connectionInstance;
    ssl->instance = connectionInstance;
    
exit:
    return status;
}
Пример #16
0
void dump_ps_data(GX2PixelShader* ps)
{
   DEBUG_INT(ps->size);
   DEBUG_VAR(ps->mode);
   DEBUG_INT(ps->uniformBlockCount);
   for(int i = 0; i < ps->uniformBlockCount; i++)
   {
      DEBUG_STR(ps->uniformBlocks[i].name);
      DEBUG_INT(ps->uniformBlocks[i].offset);
      DEBUG_INT(ps->uniformBlocks[i].size);
   }
   DEBUG_INT(ps->uniformVarCount);
   for(int i = 0; i < ps->uniformVarCount; i++)
   {
      DEBUG_STR(ps->uniformVars[i].name);
      DEBUG_INT(ps->uniformVars[i].offset);
      DEBUG_INT(ps->uniformVars[i].type);
      DEBUG_INT(ps->uniformVars[i].count);
      DEBUG_INT(ps->uniformVars[i].block);
   }
   DEBUG_INT(ps->initialValueCount);
   for(int i = 0; i < ps->initialValueCount; i++)
   {
      DEBUG_INT(ps->initialValues[i].offset);
      DEBUG_FLOAT(ps->initialValues[i].value[0]);
      DEBUG_FLOAT(ps->initialValues[i].value[1]);
      DEBUG_FLOAT(ps->initialValues[i].value[2]);
      DEBUG_FLOAT(ps->initialValues[i].value[3]);
   }
   DEBUG_INT(ps->loopVarCount);
   for(int i = 0; i < ps->loopVarCount; i++)
   {
      DEBUG_INT(ps->loopVars[i].offset);
      DEBUG_VAR(ps->loopVars[i].value);
   }
   DEBUG_INT(ps->samplerVarCount);
   for(int i = 0; i < ps->samplerVarCount; i++)
   {
      DEBUG_STR(ps->samplerVars[i].name);
      DEBUG_INT(ps->samplerVars[i].type);
      DEBUG_INT(ps->samplerVars[i].location);
   }

}