www.pudn.com > 基于VC的神经网络开发程序包(源码).rar > CenterNeuron.cpp


#include "../include/Exception.h" 
#include "../include/CenterNeuron.h" 
 
#include  
#include  
using namespace std; 
namespace annie 
{ 
 
CenterNeuron::CenterNeuron(int label, int dimension) : Neuron(label) 
{ 
	_dimension = dimension; 
	_activationFunction = gaussian; 
	_dActivationFunction = dgaussian; 
 
	_center = new real[dimension]; 
//	_deltaCenter = new real[dimension]; 
	for (int i=0;igetSource()->getOutput() - _center[j]; 
		_activationCache += (temp*temp); 
	} 
	_activationCache = (real)sqrt(_activationCache); 
	_outputCache = _activationFunction(_activationCache); 
	 
	_outputCacheValid = true; 
} 
 
void 
CenterNeuron::_recacheError() 
{	_errorCacheValid = true;	} 
 
int 
CenterNeuron::getDimension() 
{	return _dimension;	} 
 
void 
CenterNeuron::connect(Neuron *from) 
{ 
	disconnect(from); 
	Link *link = new Link(this,from,1.0); 
	_inputLinks.push_back(link); 
	from->_outputLinks.push_back(link); 
	invalidateOutputCache(); 
} 
 
//void 
//CenterNeuron::calculateNewCenter(real learningRate) 
//{ 
//	LINKS::iterator k1,i; 
//	int k; 
//	real act,dact,factor; 
//	Link *inl,*outl; 
//	if (getInputCount() != getDimension()) 
//	{ 
//		string error(getClassName()); 
//		error = error + "::calculateNewCenter() - Setup not valid, number of inputs not equal to dimension of center."; 
//		throw Exception(error); 
//	} 
//	 
//	for (k1=_inputLinks.begin(), k=0; k1!=_inputLinks.end(); k1++,k++) 
//	{ 
//		inl=(Link*)(*k1); 
//		_deltaCenter[k] = (real)0.0; 
//		act = getActivation(); 
//		dact = (real)(exp(-1*act*act)*2);//_dActivationFunction(act); // 
//		factor = (inl->getSource()->getOutput() - _center[k])*dact;///act; 
//		for (i=_outputLinks.begin(); i!=_outputLinks.end(); i++) 
//		{ 
//			outl=(Link*)(*i); 
//			_deltaCenter[k] += outl->getDestination()->getError() * outl->getWeight(); 
//		} 
//		_deltaCenter[k] = _deltaCenter[k] * factor * learningRate; 
//	} 
//} 
// 
//void 
//CenterNeuron::update() 
//{ 
//	int dim = getDimension(); 
//	int i; 
//	for (i=0; i