⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alphaneuron.cpp

📁 amygdata的神经网络算法源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            converged = 0;            iterate = 0;            // set the scheduled spike time to zero to keep            // the neuron from spiking when an inhibitory input            // spike has canceled a previously scheduled spike.            schedSpikeTime = 0;        }        else if (currState > 1.0) {            converged = 1;            iterate = 0;        }        else {            stateDelta = fabs(1.0 - currState);            threshCrs = (stateDelta / currDeriv) + lstThreshCrs;            LOGGER(6, "stateDelta: " << stateDelta << "\nthreshCrs: " << threshCrs << "\nlstThreshCrs: " << lstThreshCrs)            if ((threshCrs - lstThreshCrs) < convergeRes) {                if (stateDelta < 1.0) {                    converged = 1;                    iterate = 0;                    LOGGER(6, "threshCrs - lstThreshCrs < convergeRes -- Converged")                }                else {                    converged = 0;                    calcTime = int(threshCrs);                    lstThreshCrs = threshCrs;                    // set the scheduled spike time to zero to keep                    // the neuron from spiking when an inhibitory input                    // spike has canceled a previously scheduled spike.                    schedSpikeTime = 0;                }            }            else {                converged = 0;                if ((threshCrs-lstThreshCrs) > maxThreshCrs) {                //if (threshCrs > maxThreshCrs) {                    iterate = 0;                }                calcTime = int(threshCrs);                lstThreshCrs = threshCrs;                // set the scheduled spike time to zero to keep                // the neuron from spiking when an inhibitory input                // spike has canceled a previously scheduled spike.                schedSpikeTime = 0;            }        }    }    if (converged) {        // Make sure we wait at least one cycle before spiking        if (calcTime == inTime) {            calcTime += simStepSize;        }        schedSpikeTime = calcTime;        LOGGER(5, "Neuron " << nId << " Scheduling spike at " << schedSpikeTime)        		Network::GetNetworkRef()->ScheduleSpike( schedSpikeTime, this );    }}float AlphaNeuron::GetMembranePtnl() const{    float currState=0.0, currDeriv=0.0;    unsigned int histSize = inputHist.size();    unsigned int hbi = histBeginIdx;    //AmTimeInt calcTime = Node::SimTime();    AmTimeInt calcTime = Network::GetNetworkRef()->SimTime();    Utilities::RoundTime(calcTime, pspStepSize);    for (unsigned int i=hbi; i<histSize; i++) {        InputHist tmpInput = inputHist[i];        AmTimeInt funcTime = calcTime - tmpInput.time;        float funcWeight = tmpInput.weight;        unsigned int tblIndex = (funcTime / pspStepSize);        if (tblIndex < pspLSize) {            if ( funcWeight > 0.0 ) {                currState = currState + (funcWeight * (epspLookup[tblIndex]));                currDeriv = currDeriv + (funcWeight * (edPspLookup[tblIndex]));            }            else {                currState = currState + (funcWeight * (ipspLookup[tblIndex]));                currDeriv = currDeriv + (funcWeight * (idPspLookup[tblIndex]));            }        }        else {            ++hbi;        }    }    return currState;}void AlphaNeuron::ScaleFunctionLookups(){    unsigned int i;    float lastPtnl=0.0;    float maxPtnl=0.0;    for (i=0; i<pspLSize; ++i) {        maxPtnl = epspLookup[i];        //maxDPtnl = edPspLookup[i];        if (maxPtnl < lastPtnl) {            maxPtnl = lastPtnl;            break;        }        else {            lastPtnl = maxPtnl;        }        /*if (maxDPtnl < lastDPtnl) {            maxDPtnl = lastDPtnl;            break;        }        else {            lastDPtnl = maxDPtnl;        } */    }    if (maxPtnl == 0.0)        return;    // Normalize the function -- a small number is added to the    // peak to make sure that a weight of 1 will cross the threshold    float scaleFactor = 1.0/maxPtnl + 0.000001;    //float dscaleFactor = 1.0/maxDPtnl;    for (i=0; i<pspLSize; i++) {        epspLookup[i] = scaleFactor*epspLookup[i];        edPspLookup[i] = scaleFactor*edPspLookup[i];    }    // maxScaledWeight is increased a little bit beyond its    // true value to make sure that a weight of 1.0 will always    // exceed the threshold at the peak of the psp curve.//    maxScaledWeight = ( thresholdPtnl / maxPtnl ) + 0.000001;    // Scale the inhibitory psp to match the amplitude of the epsp.    // This will ensure consistent behavior for all time constants    // (the maximum of the ipsp gets lower with increasing synaptic    // time constants).    float imaxPtnl = 0.0;    lastPtnl = 0.0;    for (i=0; i<pspLSize; i++) {        imaxPtnl = ipspLookup[i];        //imaxDPtnl = idPspLookup[i];        if (imaxPtnl < lastPtnl) {            imaxPtnl = lastPtnl;            break;        }        else {            lastPtnl = imaxPtnl;        }        /*if (imaxDPtnl < lastDPtnl) {            imaxDPtnl = lastDPtnl;            break;        }        else {            lastDPtnl = imaxDPtnl;        }*/    }    //scaleFactor = 1.0*maxPtnl/imaxPtnl;    scaleFactor = 1.0/imaxPtnl;    //dscaleFactor = 0.9*maxDPtnl/imaxDPtnl;    for (i=0; i<pspLSize; i++) {        ipspLookup[i] = scaleFactor*ipspLookup[i];        idPspLookup[i] = scaleFactor*idPspLookup[i];    }}void AlphaNeuron::PrintLookupTables(){    cout << "\n\nPrinting excitatory tables:\nepspLookup:\n\n";    for (unsigned int i=0; i<pspLSize; ++i) {        cout << i << "\t" << epspLookup[i] << endl;    }    /*cout << "\n\nedPspLookup:\n\n";    for (unsigned int i=0; i<pspLSize; ++i) {        cout << i << "\t" << edPspLookup[i] << endl;    }*/    cout << "\n\nPrinting inhibitory tables:\nipspLookup:\n\n";    for (unsigned int i=0; i<pspLSize; ++i) {        cout << i << "\t" << ipspLookup[i] << endl;    }    /*cout << "\n\nidPspLookup:\n\n";    for (unsigned int i=0; i<pspLSize; ++i) {        cout << i << "\t" << idPspLookup[i] << endl;    }*/}void AlphaNeuron::InitLookup(){	FunctionLookup* fl = Network::GetNetworkRef()->GetFunctionLookup();	try {		TableProperties t0 = GetTableProps(0);		TableProperties t1 = GetTableProps(1);		TableProperties t2 = GetTableProps(2);		TableProperties t3 = GetTableProps(3);		epspLookup = fl->GetTableData(t0);		edPspLookup = fl->GetTableData(t1);		ipspLookup = fl->GetTableData(t2);		idPspLookup = fl->GetTableData(t3);	}	catch (TableNotFoundException& e) {		//pspLookup = fl->MakeLookupTable(props);		MakeLookupTables();		//PrintLookupTables();	}}TableProperties AlphaNeuron::GetTableProps(unsigned int index){	TableProperties props;	props.SetClassName("AlphaNeuron");	props.SetTableSize(pspLSize);	AlphaNeuronProperties* anProps = dynamic_cast<AlphaNeuronProperties*>(neuronProps);	float membraneConst = anProps->GetMembraneConst();	float eSynConst = anProps->GetExcitatorySynapseConst();	float iSynConst = anProps->GetInhibitorySynapseConst();	props.AddParam((AmTimeInt)index);	props.AddParam(membraneConst);	props.AddParam(eSynConst);	props.AddParam(iSynConst);	return props;}void AlphaNeuron::MakeLookupTables(){	FunctionLookup* fl = Network::GetNetworkRef()->GetFunctionLookup();		TableProperties t0 = GetTableProps(0);	TableProperties t1 = GetTableProps(1);	TableProperties t2 = GetTableProps(2);	TableProperties t3 = GetTableProps(3);	LOGGER(6, "Making lookup tables")    epspLookup = fl->MakeLookupTable(t0);    edPspLookup = fl->MakeLookupTable(t1);    ipspLookup = fl->MakeLookupTable(t2);    idPspLookup = fl->MakeLookupTable(t3);    LOGGER(6, "Lookups made")    	AlphaNeuronProperties* anProps = dynamic_cast<AlphaNeuronProperties*>(neuronProps);	float membraneConst = anProps->GetMembraneConst();	float eSynConst = anProps->GetExcitatorySynapseConst();	float iSynConst = anProps->GetInhibitorySynapseConst();	// TODO: Need to add in code for iSynConst here and in Euler	Euler* eul = new Euler(1, 0, 100000, eSynConst, iSynConst, membraneConst);	LOGGER(6, "Filling lookup tables")    eul->GenExcitatoryTable(pspStepSize, epspLookup, edPspLookup);    eul->GenInhibitoryTable(pspStepSize, ipspLookup, idPspLookup);        delete eul;    ScaleFunctionLookups();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -