main(int    argc,
     char **argv)
{
l_int32      patno, red;
L_REGPARAMS  *rp;

    if (regTestSetup(argc, argv, &rp))
        return 1;

    for (patno = 0; patno < 2; patno++) {
        for (red = 4; red <= 16; red *= 2) {
            if (patno == 1 && red == 16) continue;
            GeneratePattern(patno, red, rp);
        }
    }

    regTestCleanup(rp);
    return 0;
}
예제 #2
0
char TNeuralNetBase::Init() 
{
#ifdef DEBUG
  cout << "TNeuralNetBase::Init........." << endl;
#endif
  // See how fast we are in sec.
  start_time= time(NULL);
  // Read first part of par file already here to know NbTrials.
  if(TNeuralNetBase::LoadPar()) { 
    cerr<<"Error in NeuralNetBase::Init : LoadPar."<<endl; return 1; }
  // Init random generator
  if(RandomSeed==0) { time_t t; RandomSeed = (long) time(&t); }
//  srand48(RandomSeed);
  // Init EpoLogBuf
#ifdef BUFFER_EPO_LOG
  TrainMSEEpoLogBuf.Init(MaxEpochs+EpochsAfterLearned, AverageTrainBuf,
			 "TrainMSEEpoLogBuf"); 
    if(!NoClassesOnlyPredict)
      TrainErrEpoLogBuf.Init(MaxEpochs+EpochsAfterLearned, AverageTrainBuf,
			     "TrainErrEpoLogBuf");
  unsigned int TME; // Test buffer one longer for the final test.
  if(TestEach_Epo) TME=TestEach_Epo; else TME=TestMaxEach_Epo;
  if(!NoClassesOnlyPredict)
    TestErrEpoLogBuf.
      Init((int) 
	   ceil((double)(MaxEpochs+EpochsAfterLearned)/TME)+1,1,
	   "TestErrEpoLogBuf");
  TestMSEEpoLogBuf.
    Init((int) ceil((double)(MaxEpochs+EpochsAfterLearned)/TME)+1,1,
	 "TestMSEEpoLogBuf");
#endif
  // Init Pattern.
  TrainData.Generalize=0;
  TestData.Generalize=Test_Generalize;
  FreezeSeqLoop=false;
#if !defined(DO_ONLINE_PAT_PRODUCTION)
  FreezeSeqLoop=false;
  if(Generate_Pat) {
    // Test.
    Set_RefData(&TestDataOrg,false,false,true);
    Set_LoopAllSeqs(Generate_Pat_NbLoopAllSeqs_Test);
    GeneratePattern(TestData, Pat_FuncName);
    // Train.
    Set_RefData(&TrainDataOrg,true,true,true);
    Set_LoopAllSeqs(Generate_Pat_NbLoopAllSeqs_Train); // Stays set.
    GeneratePattern(TrainData, Pat_FuncName);
  } else {
    if(LoadTrainPattern()) return 1; // from PatternFile
    if(LoadTestPattern()) return 1; // from PatternFile
    if(PredictionOffset>0) 
      //For prediction task:f*dy(t-1),y(t),f*dy(t),y(t+T)
      // start with y(t).
      //->y(t),y(t+T)
      TransPat2StepByStepPredict(
				 NbIn,NbOut,
				 1, //NbPredictInputs, task dependent.
				 PredictionOffset,
				 PredictAllUntilOffset);
    if(PredictDiff) {
      //->y(t),y(t+T),dy(t-1)
      Add_IODiff(1);
      //->y(t),y(t+T),f*dy(t-1)
      PredictDiffFactor = Scale_IODIff(PredictDiff,2);
      //->f*dy(t-1),y(t),y(t+T),f*dy(t-1)
      //Add_IODiff2Input();// Then: FlipO1O2(2,3); 
      //->f*dy(t-1),y(t),f*dy(t),y(t+T)
      FlipO1O2(1,2); 
      //if(PredictOnlyDiff) 
      //Trans2IODiff(PredictDiff);
      //else Add_IODiff(PredictDiff);
    }
    // Split the series into PredictionOffset sequences dep. on offset.
    if((PredictionOffset>1) && !TimeWindowSize) { 
      SplitPredictionOffset(PredictionOffset); 
    }
    if(TimeWindowSize) {
      //      Add_IODiff(1);
      //PredictDiffFactor = Scale_IODIff(PredictDiff,2);
      Add_TimeWindow(NbIn/TimeWindowSize,
		     TimeWindowSize,TimeWindowStepSize); 
//    //ddd
//      for(unsigned int seq=0;seq<TrainData.NbSeq;seq++) { 
//        for(unsigned int pat=0;pat<TrainData.NbPat[seq];pat++) {
//          cout<<pat<<" ";
//          for(unsigned int val=0;val<TrainData.NbVal;val++) {
//    	cout<<((TrainData.SeqList[seq])[pat])[val]<<" "; }
//          cout<<"\n"; }
//        cout<<"\n"; }
//      exit(0);//ddd
      //->y(t),...,dy(t-1),y(t+T)
      //FlipO1O2(NbIn,NbIn+1); 
    }
    // Modify the NbIn not to include the Diff outputs.
    unsigned int NbOutMSE=NbOut; 
    // Detemine which units contribute to the MSE:
    if(PredictDiff && !PredictOnlyDiff) NbOutMSE/=2;
#ifndef STAT_OUT
    CalcPatStatisticsAll(NbIn,NbOutMSE);
#else
    // Considder only the stat outs.
    CalcPatStatisticsAll(NbIn+NbOut,NbOutMSE);
#endif
  }
  //  exit(0);//ddd
#else
  if(!SetStepTarget) FreezeSeqLoop=true;
#ifdef SETSTEPTARGET_BUT_COUNT_SEQUENCEWISE
  FreezeSeqLoop=true;
#endif
#endif
  //SaveTrainPattern(); exit(0); // For debug.
  // Init general network stuff.
  ClampOut=false;
#ifdef UPDATE_WEIGHTS_AFTER_SEQ
  update_weights_after_seq=UPDATE_WEIGHTS_AFTER_SEQ;
#endif
  // Init Done.
#ifdef DEBUG
  cout << "TNeuralNetBase::Init done." << endl;
#endif
  return 0;
}
예제 #3
0
// Main - Set things up, call the pattern generator.
int main (void) {

  int i;

  // Reserve the pixel data memory.
  galaxyData_t galaxy;                // Contains an array of pointers to pixels.
  color_t actualPixels[PIXEL_COUNT];  // Sets aside memory for the actual pixels.

  galaxy.size = PIXEL_COUNT;

  // Map the array of pointers to the actual pixel memory.
  for (i = 0; i < PIXEL_COUNT; i++) {
    galaxy.pixels[i] = &actualPixels[i];
  }

  // Seed the pseudorandom number generator.
  srand(25);

  // Initialize the PIC hardware
  HardwareInit();

  // Initialize the emulator hardware.
#ifdef EMULATE
  // Init the display window.
  // SDL, Simple DirectMedia Layer, is a library for access to the keyboard,
  // and graphics hardware.  See www.libsdl.org  
  if (SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0) {
    fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
    exit(EXIT_FAILURE);
  } else {
    // Register an exit callback to cleanup SDL.
    atexit(SDL_Quit);
  }

   // Initialize the SDL surfaces.
  SDL_CreateWindowAndRenderer(INITIAL_WINDOW_WIDTH, INITIAL_WINDOW_HEIGHT,
                              SDL_WINDOW_RESIZABLE, &sdlWindow, &sdlRenderer);
  if ((sdlWindow == NULL) || (sdlRenderer == NULL)) {
    fprintf(stderr, "Unable to create SDL window or renderer! %s\n", SDL_GetError());
    exit(EXIT_FAILURE);
  }

  // Set the window title
  WindowTitle(delayMultiplier);

  // Clear the window to black.
  SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 0, 255);
  SDL_RenderClear(sdlRenderer);
  SDL_RenderPresent(sdlRenderer);

  // Generate the output pixel map
  GeneratePixelMap(INITIAL_WINDOW_WIDTH, INITIAL_WINDOW_HEIGHT);

  // Print version information.
  if (strlen(PRERELEASE_VERSION) == 0) {
    printf("Galaxy Emulator v%s.%s.%s\n", MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION);
  } else {
    printf("Galaxy Emulator v%s.%s.%s-%s\n", MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, PRERELEASE_VERSION);
  }
  printf("Keys: ESC, <ctrl> c, q - Quit\n");
  printf("      +                - Increase emulation speed\n");
  printf("      -                - Decrease emulation speed\n");
  printf("      0                - Set emulation speed to 100%%\n");
  printf("      p                - Pause / unpause the simulation\n");
  printf("      SPACE            - Go to another pattern\n");
  printf("The emulator window must have focus for the key presses to work.\n");
#endif

  // Hand off control to the pattern generator.
  GeneratePattern(&galaxy);

  // We can only get this far on the emulator.
  exit(EXIT_SUCCESS);  // Required on the emu target for SDL cleanup.
  return(0);  // Never happens.
}
예제 #4
0
// Simple test to run "artifical" NumSimultaneous threads 
int ArtificalSimultaneousThreads (int NumSimultaneousThreads)
{
	ContextStructure* cs[TCM_MAX_SIMULTANEOUS_THREADS];
	//if(NumSimultaneousThreads<MAX_SIMULTANEOUS_THREADS)
	int i,ret=0;

	//Get context 
	for (i=0;i<NumSimultaneousThreads;i++)
	{
		ret=cm.GetFreeContext(cs[i]);
		if(ret)
		{
			printf("Error creating new context\n");
			return -1;
		}
	}

	// Generate the pattern
	char *pattern;
	GeneratePattern(pattern);
	/*int max=64;
	for(int k=0,j=0;k<max/(int)(sizeof(int));k++,j+=sizeof(int))
	{
		printf("%d",*(int *)(pattern+j));
	}*/

	//Copy pattern to context
	for (i=0;i<NumSimultaneousThreads;i++)
	{
		memcpy(cs[i]->cachedb_key,pattern,CM_DEFAULT_CACHEDB_KEY_SIZE);
		memcpy(cs[i]->md_lookup_key,pattern,CM_DEFAULT_CACHEDB_KEY_SIZE);
		memcpy(cs[i]->md_lookup_value,pattern,CM_DEFAULT_MD_LOOKUP_VALUE_SIZE);
		memcpy(cs[i]->qdb_key,pattern,CM_DEFAULT_QDB_KEY_SIZE);
		memcpy(cs[i]->qdb_value,pattern,CM_DEFAULT_QDB_VALUE_SIZE);

	}

	//Compare if the context is correct 
	for (i=0;i<NumSimultaneousThreads;i++)
	{
		if(memcmp(cs[i]->cachedb_key,pattern,CM_DEFAULT_CACHEDB_KEY_SIZE)!=0)
		{
			printf("Pattern does not match created value\n");
			return -2;
		}
		if(memcmp(cs[i]->md_lookup_key,pattern,CM_DEFAULT_CACHEDB_KEY_SIZE)!=0)
		{
			printf("Pattern does not match created value\n");
			return -2;
		}
		if(memcmp(cs[i]->md_lookup_value,pattern,CM_DEFAULT_MD_LOOKUP_VALUE_SIZE)!=0)
		{
			printf("Pattern does not match created value\n");
			return -2;
		}
		if(memcmp(cs[i]->qdb_key,pattern,CM_DEFAULT_QDB_KEY_SIZE)!=0)
		{
			printf("Pattern does not match created value\n");
			return -2;
		}
		if(memcmp(cs[i]->qdb_value,pattern,CM_DEFAULT_QDB_VALUE_SIZE)!=0)
		{
			printf("Pattern does not match created value\n");
			return -2;
		}
	}

	// Release Context
	for(i=0;i<NumSimultaneousThreads;i++)
	{
		ret=cm.ReleaseContext(cs[i]);
		if(ret)
		{
			printf("Error releasing context\n");
			return -2;
		}
	}
	delete [] pattern;
	return 0;
}
예제 #5
0
DWORD WINAPI ContextWorkerThread( LPVOID lpParam ) 
{	
	// Thread ID
	int id = *((int*)lpParam); 
	int NumSimultaneousThreads=TCM_NUM_ELEMENTS_TO_ACCESS;
	ContextStructure* cs[TCM_MAX_SIMULTANEOUS_THREADS];
	//if(NumSimultaneousThreads<MAX_SIMULTANEOUS_THREADS)
	int i,ret=0;

	
	//Get context 
	for (i=0;i<NumSimultaneousThreads;i++)
	{
		
		ret=cm.GetFreeContext(cs[i]);
		if(ret)
		{
			printf("Error creating new context\n");
			return -1;
		}
	}

	Sleep( rand() % TCM_MAX_SLEEP_TIME );

	// Generate the pattern
	char *pattern;
	GeneratePattern(pattern);
	/*int max=64;
	for(int k=0,j=0;k<max/(int)(sizeof(int));k++,j+=sizeof(int))
	{
		printf("%d",*(int *)(pattern+j));
	}*/

	//Copy pattern to context
	for (i=0;i<NumSimultaneousThreads;i++)
	{
		memcpy(cs[i]->cachedb_key,pattern,CM_DEFAULT_CACHEDB_KEY_SIZE);
	//	memcpy(cs[i]->md_lookup_key,pattern,CM_DEFAULT_CACHEDB_KEY_SIZE);
		memcpy(cs[i]->md_lookup_value,pattern,CM_DEFAULT_MD_LOOKUP_VALUE_SIZE);
		memcpy(cs[i]->qdb_key,pattern,CM_DEFAULT_QDB_KEY_SIZE);
		memcpy(cs[i]->qdb_value,pattern,CM_DEFAULT_QDB_VALUE_SIZE);

	}

	//Compare if the context is correct 
	for (i=0;i<NumSimultaneousThreads;i++)
	{
		if(memcmp(cs[i]->cachedb_key,pattern,CM_DEFAULT_CACHEDB_KEY_SIZE)!=0)
		{
			printf("Pattern does not match created value\n");
			return -2;
		}
		//if(memcmp(cs[i]->md_lookup_key,pattern,CM_DEFAULT_CACHEDB_KEY_SIZE)!=0)
		//{
		//	printf("Pattern does not match created value\n");
		//	return -2;
		//}
		if(memcmp(cs[i]->md_lookup_value,pattern,CM_DEFAULT_MD_LOOKUP_VALUE_SIZE)!=0)
		{
			printf("Pattern does not match created value\n");
			return -2;
		}
		if(memcmp(cs[i]->qdb_key,pattern,CM_DEFAULT_QDB_KEY_SIZE)!=0)
		{
			printf("Pattern does not match created value\n");
			return -2;
		}
		if(memcmp(cs[i]->qdb_value,pattern,CM_DEFAULT_QDB_VALUE_SIZE)!=0)
		{
			printf("Pattern does not match created value\n");
			return -2;
		}
	}

	
	// Release Context
	for(i=0;i<NumSimultaneousThreads;i++)
	{
		ret=cm.ReleaseContext(cs[i]);
		if(ret)
		{
			printf("Error releasing context\n");
			return -2;
		}
	}
	printf("Thread %d passed test\n",id);
	delete [] pattern;
	return 0;
	
}