/**
  * Helper method to locate the leftmost cube 
  * in a series of neighboured cubes.
  */
unsigned Phonemic::leftmostNeighbor(unsigned id) {
    // Find leftmost cube
	Neighborhood hood = Neighborhood(id);
	CubeID leftmostID = id;
	while(hood.hasCubeAt(LEFT)) {
		leftmostID = hood.cubeAt(LEFT);
		hood = Neighborhood(leftmostID);
	}
    return leftmostID;
}
/**
  * Helper method to determine if any cubes are neighboured
  */
bool Phonemic::noNeighbors() {
    for(CubeID cube: CubeSet::connected())
	{
        Neighborhood hood = Neighborhood(cube);
        if(hood.hasCubeAt(LEFT) || hood.hasCubeAt(RIGHT))
            return false;
    }
    return true;
}
/** 
  * Helper method to decide if a series of cubes
  * spells the current word.
  */
void Phonemic::checkForWord(unsigned id) {

    // Find leftmost cube
	CubeID nextID = leftmostNeighbor(id);
    Neighborhood hood = Neighborhood(nextID);
    	
	// Find the sequence of symbols spelled by
    // the sequence of cubes
    int wordAttempt[MAX_WORD_SIZE];
    wordAttempt[0] = cubes[nextID].symbol;
    int i = 1;
    while(hood.hasCubeAt(RIGHT)) {
    	nextID = hood.cubeAt(RIGHT);
	    hood = Neighborhood(nextID);
    	wordAttempt[i] = cubes[nextID].symbol;
        i++;
	}
    wordAttempt[i] = -1;
        
    // Check for a match
	bool match = true;
    for(int i = 0; i < /*MAX_WORD_SIZE*/ length; i++) {
        if(/*order[i]*/ wordFamilies[level].phonemes[word][i] != wordAttempt[i]) 
        {
            match = false;
            break;
        }
        //if(wordFamilies[level].phonemes[word][i] == -1) break;
    }
    
    // Recognize match
	if(match) {
    	//sounding.play(SfxChime);
		//sounding.play(SfxCat);
		
		sounding.play(/*SfxChime*/ *wordFamilies[level].words[word].sound);
        allSmiles();
        System::paint();
        state = WORD_FOUND;
	}
}
Exemple #4
0
void TrainOutput(NET* Net, REAL* Output)
{
  INT  i,j;
  REAL Out, Weight, Lambda;

  for (i=0; i<Net->OutputLayer->Units; i++) {
    for (j=0; j<Net->KohonenLayer->Units; j++) {
      Out = Output[i];
      Weight = Net->OutputLayer->Weight[i][j];
      Lambda = Neighborhood(Net, j);
      Net->OutputLayer->Weight[i][j] += Net->Alpha_ * Lambda * (Out - Weight);
    }
  }
}
Exemple #5
0
void TrainKohonen(NET* Net, REAL* Input)
{
  INT  i,j;
  REAL Out, Weight, Lambda, StepSize;

  for (i=0; i<Net->KohonenLayer->Units; i++) {
    for (j=0; j<Net->InputLayer->Units; j++) {
      Out = Input[j];
      Weight = Net->KohonenLayer->Weight[i][j];
      Lambda = Neighborhood(Net, i);
      Net->KohonenLayer->Weight[i][j] += Net->Alpha * Lambda * (Out - Weight);
    }
    StepSize = Net->KohonenLayer->StepSize[i];
    Net->KohonenLayer->StepSize[i] += Net->Alpha__ * Lambda * -StepSize;
  }
}
Exemple #6
0
/**
 * Notes:
 * - Comment out the parts you aren't currently using.
 */
int main() {
    // test_buffer();

    // ------------------------------------------------------------------------

    //test_shape();

    // ------------------------------------------------------------------------

    // animate  neighborhood
    unsigned int size_x = TERM_SIZE_X/Shape::size_x;
    unsigned int size_y = TERM_SIZE_Y/Shape::size_y;
    Neighborhood(size_x, size_y).animate(1000);

    // ------------------------------------------------------------------------

    return 0;  // success
}
/**
  * Helper method to sounds out the sequence of cubes.
  */
void Phonemic::soundOut(unsigned id) {
    // Wait for audio channel to be clear
    if(sounding.isPlaying()) return;
    
    // Highlight the current cube
    cubes[id].vid.bg0.image(vec(0,0), *cubes[id].images[1]);
    System::paint();
    System::finish();
        
    // Play the current cube's sound
    sounding.play(*cubes[id].sound);
    while(sounding.isPlaying()) {
        System::yield();
    }
    
    // Return the cube to its normal appearance
    cubes[id].vid.bg0.image(vec(0,0), *cubes[id].images[0]);
    
    // Play any cube connected to the right
    Neighborhood hood = Neighborhood(id);
    if(hood.hasCubeAt(RIGHT)) soundOut(hood.cubeAt(RIGHT));
}
Exemple #8
0
      Instance(const std::vector<Resource>& resources,
               const std::vector<Machine>& machines,
               const std::vector<Service>& services,
               const std::vector<Process>& processes,
               const std::vector<BalanceCost>& balanceCosts,
               std::vector<int> const & initAssignment,
               int processMoveCostWeight,
               int serviceMoveCostWeight,
               int machineMoveCostWeight,
               int numNeighborhoods,
               int numLocations)
         : _resources(resources),
           _machines(machines),
           _services(services),
           _processes(processes),
           _balanceCosts(balanceCosts),
           _initAssignment(initAssignment),
           _processMoveCostWeight(processMoveCostWeight),
           _serviceMoveCostWeight(serviceMoveCostWeight),
           _machineMoveCostWeight(machineMoveCostWeight),
           _numNeighborhoods(numNeighborhoods),
           _numLocations(numLocations),
           _numResources(_resources.size()),
           _resourcesLoadCostWeight(_resources.size(), 0)
      {
         for (int i = 0; i < numResources(); i++)
         {
            _isTransient.push_back(_resources[i].transient());
            _resourcesLoadCostWeight[i] = _resources[i].loadCostWeight();
         }

         for (int i = 0; i < _processes.size(); i++)
         {
            _services[_processes[i].service()].addProcess(i);
         }

         for (int i = 0; i < _numLocations; i++)
         {
            _locations.push_back(Location(i));
         }

         for (int i = 0; i < _numNeighborhoods; i++)
         {
            _neighborhoods.push_back(Neighborhood(i));
         }

         for (int i = 0; i < _machines.size(); i++)
         {
            _locations[machines[i].location()].addMachine(i);
            _neighborhoods[machines[i].neighborhood()].addMachine(i);
         }

         for (int i = 0; i < _services.size(); i++)
         {
            for (int j = 0; j < _services[i].dependencies().size(); j++)
            {
               _dependencies.push_back(
                  std::make_pair(i, _services[i].dependencies()[j]));
            }
         }

      }