Пример #1
0
static void create_net_PROC(void)

{
 int create=1;

 BN_ERROR = 0;

 if(krui_getNoOfUnits() != 0) {
   if(! ui_confirmYes("Create will erase current network. Create?")) {
     create = 0;
   }
 }
 
 if(create && (PLANE_length != 0)) {

   krui_deleteNet();

   calculate_first_snns_unit_no_of_plane();
   create_snns_unit(); 
   make_links();
   krui_setLearnFunc("BPTT");
   krui_setUpdateFunc("Hopfield_Synchronous");
   krui_setInitialisationFunc("ClippHebb");
   ui_NumberOfLearnParamsChanged();
   ui_NumberOfUpdateParamsChanged();
   ui_NumberOfInitParamsChanged();
   bn_basics_refresh();
 }/* if */ 
}
Пример #2
0
/**************************************************
 *  snns_setInitialisationFunc
 * 
 *  Sets the network initialization function using
 *  krui_setInitialisationFunc().
 **************************************************/
int snns_setInitialisationFunc(stEval *args, stEval *result, void *instance) {
  char *initFuncName = STSTRING(&args[0]);
  krui_err errCode;
  char *errMsg;

  errCode = krui_setInitialisationFunc( initFuncName );
  if (errCode == KRERR_NO_ERROR) {
    return EC_OK;
  }
  else {
    errMsg = krui_error(errCode);
    slMessage(0, "breveSNNS: setInitialisationFunc failed with message %s (error code %d).", errMsg, errCode);
    return EC_ERROR;
  }
}
Пример #3
0
krui_err SnnsCLib::bn_kohonen_createNet(int X, int Y, int IUnits, int HUnits)
{
  int i,j,unit_no;
  struct PosType    unit_pos;
  krui_err ret;

  unit_pos.z = 0;

  /*  Allocate units */
  
  ret = krui_allocateUnits( HUnits + IUnits );
  CHECK_RETURN ( ret );


  /*  Create standard (input) Units  */

  unit_pos.x = 1;
  for (i = 1; i <= IUnits; i++) {
    unit_no = krui_createDefaultUnit();
    if (unit_no < 0)  CHECK_RETURN( unit_no );
    ret = krui_setUnitTType( unit_no, INPUT );
    CHECK_RETURN( ret );
    
    unit_pos.y = (IUnits<Y)?i+(Y-IUnits)/2:i;
    krui_setUnitPosition( unit_no, &unit_pos );
  }


  /* Create standard hidden Units. The size of the feature map is X*Y */
  
  for (i = 1; i <= Y; i++)
    for (j = 1; j <= X; j++) {
      unit_pos.x = 4+j;
      unit_no = krui_createDefaultUnit();
      if (unit_no < 0)  CHECK_RETURN( unit_no );
      ret = krui_setUnitTType( unit_no, HIDDEN );
      CHECK_RETURN( ret );
      
      unit_pos.y = i;
      krui_setUnitPosition( unit_no, &unit_pos );
    }
  

  /* Make connections between input units and hidden units  */

  /* set all link weights to zero */

  for (i = IUnits + 1; i <= IUnits + HUnits; i++) {

      /*  Make hidden unit to current unit  */
      ret = krui_setCurrentUnit( i );
      CHECK_RETURN( ret );
    
      /* (backward) connect current (hidden) unit with input unit */
      for (j = 1; j <= IUnits; j++) {
	  ret = krui_createLink( j,0.0);
	  CHECK_RETURN( ret );
      }
  } 
         

  /*  set the update function  */

  ret = krui_setUpdateFunc (const_cast<char*>(KOHONEN_UPDATE_FUNC_NAME));
  CHECK_RETURN( ret );


  /* set the learning function */

  ret = krui_setLearnFunc (const_cast<char*>(KOHONEN_LEARN_FUNC_NAME));
  CHECK_RETURN( ret );


  /* set the init function */

  ret = krui_setInitialisationFunc (const_cast<char*>(KOHONEN_INIT_FUNC_NAME));
  //CHECK_RETURN( ret );

  return(ret);

} /* bn_kohonen_createNet */
Пример #4
0
krui_err SnnsCLib::bn_assoz_createNet(int X, int Y)
{
  int i,j,unit_no;
  struct PosType    unit_pos;
  krui_err ret = KRERR_NO_ERROR;

  int HUnits= X*Y;
  int IUnits= X*Y;


  /*  Allocate units */
  
  ret = krui_allocateUnits( IUnits + HUnits );
  CHECK_RETURN (ret);


  /* Create standard input Units. The size of the input layer is X*Y */
  
  for (i = 1; i <= Y; i++)
    for (j = 1; j <= X; j++) {
      unit_pos.x = j;
      unit_no = krui_createDefaultUnit();
      if (unit_no < 0)  CHECK_RETURN (unit_no);
      ret = krui_setUnitTType( unit_no, INPUT );
      CHECK_RETURN (ret);
      ret = krui_setUnitActFunc( unit_no, const_cast<char*>("Act_RM") );
      CHECK_RETURN (ret);
      
      unit_pos.y = i;
      krui_setUnitPosition( unit_no, &unit_pos );
    }

  /* Create standard hidden Units. The size of the output layer is X*Y */
  
  for (i = 1; i <= Y; i++)
    for (j = 1; j <= X; j++) {
      unit_pos.x = X+4+j;
      unit_no = krui_createDefaultUnit();
      if (unit_no < 0)  CHECK_RETURN (unit_no);
      ret = krui_setUnitTType( unit_no, HIDDEN );
      CHECK_RETURN (ret);
      ret = krui_setUnitActFunc( unit_no, const_cast<char*>("Act_RM") );
      CHECK_RETURN (ret);
      
      unit_pos.y = i;
      krui_setUnitPosition( unit_no, &unit_pos );
    }
  

  /* Make connections between input units and hidden units  */

  for (i = IUnits + 1; i <= IUnits + HUnits; i++) {

      /*  Make hidden unit to current unit  */
      ret = krui_setCurrentUnit( i );
      CHECK_RETURN (ret);
    
      /* (backward) connect current (hidden) unit with input unit */
      /* set all link weights from the input units to one */
      ret = krui_createLink( i-IUnits, 1.0);
      CHECK_RETURN (ret);

      /* Make connections from all hidden units  */
      /* set link weights to zero */
      for (j = IUnits + 1; j <= IUnits + HUnits; j++) {
	  if (j != i){
	      ret = krui_createLink( j, 0.0);
	      CHECK_RETURN (ret);
	  }
      }
  } 

  /*  set the update function  */
  ret = krui_setUpdateFunc (const_cast<char*>(ASSOZ_UPDATE_FUNC_NAME));
  CHECK_RETURN (ret);

  /* set the learning function */
  ret = krui_setLearnFunc (const_cast<char*>(ASSOZ_LEARN_FUNC_NAME));
  CHECK_RETURN (ret);

  /* set the init function */
  ret = krui_setInitialisationFunc (const_cast<char*>(ASSOZ_INIT_FUNC_NAME));
  //CHECK_RETURN (ret);

  return(ret);

} /* bn_assoz_createNet */
Пример #5
0
void ui_list_setUnitValue(Widget w, struct SimpleListType *listDescrPtr, 
	XawListReturnStruct *listStructPtr)

{
    char  buf[120];

    ui_list_returnIndex = listStructPtr->list_index;

    /* if no item selected then return */
    if (listStructPtr->list_index == XAW_LIST_NONE)
	return;

    /* an item is selected */
    /* but if no ftypes present when requesting f-types then return */
    if (((listDescrPtr->listType == UI_LIST_FTYPE) OR
	 (listDescrPtr->listType == UI_LIST_FTYPE_NAME)) AND 
	(ui_list_noOfFtypes == 0))
	return;
    
    switch (listDescrPtr->listType) {
      case UI_LIST_IOTYPE:
	listDescrPtr->unitPtr->iotype = (listStructPtr->list_index + 1);
	break;
      case UI_LIST_FTYPE:
	sprintf(listDescrPtr->unitPtr->ftype, "%s", listStructPtr->string);
	break;
      case UI_LIST_ACT_FUNC:
	sprintf(listDescrPtr->unitPtr->actFuncName, "%s", 
		listStructPtr->string);
	break;
      case UI_LIST_OUT_FUNC:
	sprintf(listDescrPtr->unitPtr->outFuncName, "%s", 
		listStructPtr->string);
	break;
      case UI_LIST_FTYPE_ACT_FUNC:
      case UI_LIST_FTYPE_OUT_FUNC:
      case UI_LIST_FTYPE_NAME:
      case UI_LIST_SITE_FUNC:
      case UI_LIST_SITE:
      case UI_LIST_UNIT_SITE:
	/* site functions are requested only during editing sites!
	   Thus this must be handled in a different way. */
	sprintf(ui_list_returnName, "%s", listStructPtr->string);
	break;
      case UI_LIST_LEARN_FUNC:
	ui_checkError(krui_setLearnFunc(listStructPtr->string));
	sprintf(buf,"Learning func:  %s\n",listStructPtr->string);
	ui_tw_printMessage(buf); 
	ui_xSetLabel(ui_controlMessageWidget, buf);
 	ui_NumberOfLearnParamsChanged();
	break;
      case UI_LIST_UPDATE_FUNC:
	ui_checkError(krui_setUpdateFunc(listStructPtr->string)); 
	sprintf(buf,"Update func  :  %s\n",listStructPtr->string);
	ui_tw_printMessage(buf);
	ui_xSetLabel(ui_controlMessageWidget, buf);
 	ui_NumberOfUpdateParamsChanged();
 	break;
      case UI_LIST_INIT_FUNC:
	ui_checkError(krui_setInitialisationFunc(listStructPtr->string));
	sprintf(buf,"Init. func   :  %s\n",listStructPtr->string);
	ui_tw_printMessage(buf);
	ui_xSetLabel(ui_controlMessageWidget, buf);
 	ui_NumberOfInitParamsChanged();
	break;
      case UI_LIST_FF_LEARN_FUNC:
	ui_checkError (krui_setFFLearnFunc (listStructPtr->string));
	sprintf (buf, "Learning function: %s", listStructPtr->string);
	ui_tw_printMessage (buf);
	ui_xSetLabel (pr_learnFuncText, buf);
	break;
      case UI_LIST_PRUN_FUNC:
	ui_checkError (krui_setPrunFunc (listStructPtr->string));
	sprintf (buf, "Pruning function: %s\n", listStructPtr->string);
	ui_tw_printMessage (buf);
	ui_xSetLabel (pr_prunFuncText, buf);
	break;
    } 
    /* unitPtr may be NULL as well ! */
    if (listDescrPtr->unitPtr == &ui_targetUnit)
    {
	ui_info_getDisplayedUnitAttributes(&ui_targetWidgets, &ui_targetUnit);
        ui_info_setUnitItems(ui_targetWidgets, ui_targetUnit);
    }
    else {
	if (listDescrPtr->unitPtr == &ui_sourceUnit)
	{
	    ui_info_getDisplayedUnitAttributes(&ui_sourceWidgets, 
					       &ui_sourceUnit);
	    ui_info_setUnitItems(ui_sourceWidgets, ui_sourceUnit);
	}
    } 

}
Пример #6
0
void create_network(char *weight_file)

{
 FILE *fp;
 float val;

/*  Allocate units (the user may or may not use this function, 
      there is no need to do this)  */

       ret = krui_allocateUnits( OUnits + HUnits + IUnits );
       errChk( ret );
       printf( "\n\nCreate Units now\n" );

/*  Create standard (input) Units  */

       unit_pos.x = 1;
       for (i = 1; i <= IUnits; i++)
	 {
	   unit_no = krui_createDefaultUnit();
	   if (unit_no < 0)  errChk( unit_no );
	   ret = krui_setUnitTType( unit_no, INPUT );
	   errChk( ret );

	   unit_pos.y = (IUnits<Y)?i+(Y-IUnits)/2:i;
	   krui_setUnitPosition( unit_no, &unit_pos );
	 }

/*  Create standard (hidden) Units  */
  
       for (i = 1; i <= Y; i++)
	 for (j = 1; j <= X; j++)
	   {
	     unit_pos.x = 4+j;
	     unit_no = krui_createDefaultUnit();
	     if (unit_no < 0)  errChk( unit_no );
	     ret = krui_setUnitTType( unit_no, HIDDEN );
	     errChk( ret );

	     unit_pos.y = i;
	     krui_setUnitPosition( unit_no, &unit_pos );
	   }

/*  Create standard (output) Units  */

       unit_pos.x = 4+X+3;
       if (OUnits) for (i = 1; i <= OUnits; i++)
	 {
	   unit_no = krui_createDefaultUnit();
	   if (unit_no < 0)  errChk( unit_no );
	   ret = krui_setUnitTType( unit_no, OUTPUT );
	   errChk( ret );

	   unit_pos.y = (OUnits<Y)?i+(Y-OUnits)/2:i;
	   krui_setUnitPosition( unit_no, &unit_pos );
	 }

/* Make Connections now */
/* Make connections between hidden units and output units first !  */

       for (i = IUnits + HUnits + 1; i <= IUnits + HUnits + OUnits; i++)
	 {  /*  Make output unit to current unit  */
	   ret = krui_setCurrentUnit( i );
	   errChk( ret );

	   for (j = IUnits + 1; j <= IUnits + HUnits; j++)
	     {  /*  connect current (output) unit with hidden unit. 
                    REMEMBER: The hidden unit #j is the predecessor of
                        the (output) unit #i (it is a backward connection) */
	       ret = krui_createLink( j, 0 );
	       errChk( ret );
	     }
	 }

/* Make connections between input units and hidden units
   and set link weight with datas from output_file   */

       printf("\nSet link weights now\n");
       if((fp=fopen(weight_file,"r"))!=NULL)
        for (i = IUnits + 1; i <= IUnits + HUnits; i++)
	 {  /*  Make hidden unit to current unit  */
	   ret = krui_setCurrentUnit( i );
	   errChk( ret );

	   for (j = 1; j <= IUnits; j++)
	     { /*  (backward) connect current (hidden) unit with input unit  */
	       fscanf(fp,"%s",string);
               val = atof(string);
               ret = krui_createLink( j,val);
	       errChk( ret );
	     }
	 }
        else{ /* set all link weights to zero */
	  for (i = IUnits + 1; i <= IUnits + HUnits; i++)
	    {  /*  Make hidden unit to current unit  */
	      ret = krui_setCurrentUnit( i );
	      errChk( ret );
	      
	      for (j = 1; j <= IUnits; j++)
		{/* (backward) connect current (hidden) unit with input unit */
		  ret = krui_createLink( j,0);
		  errChk( ret );
		}
	    } 
	  
	  printf("\nWeight file %s could not be opened!\n",weight_file);
	  printf("All weights have been set to zero!\n");
	}
       fclose(fp);

 
        /*  set the update function  */
       ret = krui_setUpdateFunc (KOHONEN_UPDATE_FUNC_NAME);
       errChk( ret );
        /* set the learning function */
       ret = krui_setLearnFunc (KOHONEN_LEARN_FUNC_NAME);
       errChk( ret );
        /* set the init function */
       ret = krui_setInitialisationFunc (KOHONEN_INIT_FUNC_NAME);
       errChk( ret );


       printf("\nEnter Filename of the Network to save: ");
       scanf("%s", name);
       strcat(name,".net");
       printf("Save Network\n");
      
/*  save the network  */

       ret = krui_saveNet( name, NULL );
       errChk( ret );
       printf( "\nCreate Patterns now\n" );

} /* end of create_network */