www.pudn.com > ica_v0.04.rar > util.c


/*
  util.c

  Time-stamp: 

  General purpose utilities used in the program. Was going to
  include matrix operations here too but just ended up doing
  them in-line for now since it was simpler.

  Programmer: Peter Stepien
              pstepien@sedal.usyd.edu.au
              CEL, School of Electrical & Information Engineering
              The University of Sydney
              SYDNEY NSW 2006 Australia

              COPYRIGHT 1997-2001
*/

/* System headers */
#include 
#include 
#include 

/* Local headers */
#include "ica.h"

/* For printing out the file types */
const char *FILE_TYPE_MAP[] = {"None",
			       "EDF",
			       "INT16",
			       "FLOAT64",
			       "FLOAT32",
			       0};

/* For printing out the non-linearity types */
const char *NONLINEAR_TYPE_MAP[] = {"None",
				    "EXP",
				    "TANH",
				    0};

/*
  Prints out all the possible file types.
*/

void
util_print_file_types()
{
  int i;

  i = 1;
  while (FILE_TYPE_MAP[i] != 0)
  {
    printf("%s ", FILE_TYPE_MAP[i]);
    i++;
  }
  printf("\n");

}

/*
  Prints out all the possible non-linearities types.
*/

void
util_print_nonlinear_types()
{
  int i;

  i = 1;
  while (NONLINEAR_TYPE_MAP[i] != 0)
  {
    printf("%s ", NONLINEAR_TYPE_MAP[i]);
    i++;
  }
  printf("\n");

}

/*
  Returns the file type index given the string.
*/

int
util_get_file_type(char *string)
{
  int i;

  i = 1;
  while (FILE_TYPE_MAP[i] != 0)
  {
    if (strcmp(string, FILE_TYPE_MAP[i]) == 0)
    {
      return(i);
    }
    else
    {
      i++;
    }
  }

  return(0);
}

/*
  Returns the nonlinearity type index given the string.
*/

int
util_get_nonlinear_type(char *string)
{
  int i;

  i = 1;
  while (NONLINEAR_TYPE_MAP[i] != 0)
  {
    if (strcmp(string, NONLINEAR_TYPE_MAP[i]) == 0)
    {
      return(i);
    }
    else
    {
      i++;
    }
  }

  return(0);
}

/*
  Calculates the RMS values of the off diagonals of a
  covariance matrix. It then divides it by the RMS values
  of the diagonal. This provides a normalisation type function.
*/

FLOAT_TYPE
util_rms_cov(cov, num_channels)
int num_channels;
FLOAT_TYPE cov[num_channels][num_channels];
{
  int i,j;
  FLOAT_TYPE diagonal;
  FLOAT_TYPE result;

  /* Off diagonal and diagonal squared sum and mean */
  result = 0.0;
  diagonal = 0.0;
  for (i=0;i