00001 /************************************************************************ 00002 * Verve * 00003 * Copyright (C) 2004-2006 * 00004 * Tyler Streeter tylerstreeter@gmail.com * 00005 * All rights reserved. * 00006 * Web: http://verve-agents.sourceforge.net * 00007 * * 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of EITHER: * 00010 * (1) The GNU Lesser General Public License as published by the Free * 00011 * Software Foundation; either version 2.1 of the License, or (at * 00012 * your option) any later version. The text of the GNU Lesser * 00013 * General Public License is included with this library in the * 00014 * file license-LGPL.txt. * 00015 * (2) The BSD-style license that is included with this library in * 00016 * the file license-BSD.txt. * 00017 * * 00018 * This library is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * 00021 * license-LGPL.txt and license-BSD.txt for more details. * 00022 ************************************************************************/ 00023 00024 #include "UltraSparseCodePopulation.h" 00025 #include "Neuron.h" 00026 00027 namespace verve 00028 { 00029 UltraSparseCodePopulation::UltraSparseCodePopulation() 00030 : Population() 00031 { 00032 mActiveIndex = -1; 00033 } 00034 00035 UltraSparseCodePopulation::~UltraSparseCodePopulation() 00036 { 00037 } 00038 00039 void UltraSparseCodePopulation::init(unsigned int numNeurons) 00040 { 00041 Population::init(numNeurons); 00042 mActiveIndex = -1; 00043 } 00044 00045 void UltraSparseCodePopulation::resetShortTermMemory() 00046 { 00047 // This should zero all firing rates. 00048 Population::resetShortTermMemory(); 00049 mActiveIndex = -1; 00050 // Be sure not to activate any Neurons here. 00051 } 00052 00053 void UltraSparseCodePopulation::setActiveOutput(unsigned int i) 00054 { 00055 if (mNeurons.empty() || i == mActiveIndex) 00056 { 00057 return; 00058 } 00059 00060 // If another Neuron is currently active, zero its firing rate. 00061 if (-1 != mActiveIndex) 00062 { 00063 mNeurons[mActiveIndex]->setFiringRate(0); 00064 } 00065 00066 mActiveIndex = i; 00067 mNeurons[mActiveIndex]->setFiringRate(1); 00068 } 00069 00070 int UltraSparseCodePopulation::getActiveOutput()const 00071 { 00072 return mActiveIndex; 00073 } 00074 }