Source Code for Project IAC


The following source file, led by a gray banner, contains all the class functions needed for Project IAC.  The sections highlighted by a yellow background Color are manually entered.  Code sections with white background color are generated by the SansGUI Source Code Framework.  The source file is compiled into a dynamic linked library to be invoked by SansGUI during simulation runs.

For more details about this example, please read A Tour of SansGUI Examples in the SansGUI Getting Started Guide.

Implementation in C/C++ (MSVC)

Functions in Class Base.Neuron    [Go To Top]

/* Base_Neuron.c
 * - DLL routines for class <Component>Base.Neuron
 * DATE: Tuesday, April 2, 2002 TIME: 5:48:50 PM
 * The skeleton of this file is generated by SansGUI(tm)
 */

#include <stdio.h>
#include "SGdll.h"

#ifdef __cplusplus
extern "C"
{
#endif

SG_EXPORT SG_SIM_FUNC SG_xInit_Base_Neuron;
SG_EXPORT SG_SIM_FUNC SG_xBgnCase_Base_Neuron;
SG_EXPORT SG_SIM_FUNC SG_xPreEval_Base_Neuron;
SG_EXPORT SG_SIM_FUNC SG_xEval_Base_Neuron;

#ifdef __cplusplus
}
#endif

/* Macros for attribute indices in class version [1.0.beta.1] */
#define SG_NDX_IHIDDEN 0 /* iHidden - Hidden Unit */

#define SG_NDX_FEXTINPUT 1 /* fExtInput - External Input */
#define SG_NDX_FACTIVATION 2 /* fActivation - Activation Level */
#define SG_NDX_FNETINPUT 3 /* fNetInput - Net Input */
#define SG_NDX_FEXCITATION 4 /* fExcitation - Excitation */
#define SG_NDX_FINHIBITION 5 /* fInhibition - Inhibition */
#define SG_NDX_FMAXACTIV 6 /* fMaxActiv - Maximum Activation */
#define SG_NDX_FMINACTIV 7 /* fMinActiv - Minimum Activation */
#define SG_NDX_FREST 8 /* fRest - Resting Activation Level */
#define SG_NDX_FDECAY 9 /* fDecay - Decay Rate */
#define SG_NDX_FESTR 10 /* fEstr - Scale Factor for External Input */
#define SG_NDX_FALPHA 11 /* fAlpha - Scale Factor for Excitatory Input */
#define SG_NDX_FGAMMA 12 /* fGamma - Scale Factor for Inhibitory Input */
#define SG_NDX_FDTR 13 /* fDTR - Decay Times Rest */
#define SG_NDX_FOMD 14 /* fOMD - 1 minus Decay */

/* Macros added to access link attributes */
#define LINK_NDX_INFO 0
#define LINK_NDX_FWOUTH 1
#define LINK_NDX_FWINH 2

/* ============================================================
 * SG_xInit - Initialization
 * ------------------------------------------------------------
 */
SG_RET_CODE SG_xInit_Base_Neuron(SG_OBJ *const self,
          SG_OBJ *const simCtrl, SG_OBJ *const chgChild,
          SG_OBJ *const refObjs[], const INT *const piRefObjs,
          SG_OBJ *const adjObjs[], const INT *const piAdjObjs,
          SG_OBJ *const lnkObjs[], const INT *const piLnkObjs,
          TCHAR *const cMessage, const INT iMsgLen,
          TCHAR *const cCommand, const INT iCmdLen,
          SG_FILE *const pOutFile )
{
    /* TODO: declare your local variables here */

    if (!SG_IsSchemaOK(self->nSGobjSchema))
        return SG_R_SCHM;

    /* TODO: put your simulator code here */

    /* Version update is required because we've made the following changes

     * since 1.0.alpha:
     * 1. The scope of External Input attribute is changed from In/Out to

     * Input only.
     * 2. The External Input attribute is moved to the second position.
     * These changes demonstrate version control/evoluation features in SansGUI.
     */
    if (self->iVerMajor < 1 || self->iVerMinor < 0 ||
        self->iVerPatch < -1 || self->iVerBuild < 0 )
    {   // version earlier than 1.0.alpha.5
        strcpy(cMessage,
        "Use File>Update Version to upgrade your Project Model to IAC 1.0.beta or later.");
        return SG_R_STOP;
    }

    /* calculate decay times rest for efficiency */
    self->zValues[SG_NDX_FDTR].fData[0] =

          self->zValues[SG_NDX_FDECAY].fData[0] *
          self->zValues[SG_NDX_FREST].fData[0];
    /* calculate 1 minus decay for efficiency */
    self->zValues[SG_NDX_FOMD].fData[0] = 1.0f -

          self->zValues[SG_NDX_FDECAY].fData[0];

    return SG_R_OK;
}

/* ============================================================
* SG_xPreEval - Pre-Evaluation
* ------------------------------------------------------------
*/
SG_RET_CODE SG_xPreEval_Base_Neuron(SG_OBJ *const self,
          SG_OBJ *const simCtrl, SG_OBJ *const chgChild,
          SG_OBJ *const refObjs[], const INT *const piRefObjs,
          SG_OBJ *const adjObjs[], const INT *const piAdjObjs,
          SG_OBJ *const lnkObjs[], const INT *const piLnkObjs,
          TCHAR *const cMessage, const INT iMsgLen,
          TCHAR *const cCommand, const INT iCmdLen,
          SG_FILE *const pOutFile )
{
    /* TODO: declare your local variables here */

    INT i;
    FLOAT fAct;
    FLOAT fWeight;
    INT iHidden = self->zValues[SG_NDX_IHIDDEN].iData[0];
    FLOAT* pfExcitation = &self->zValues[SG_NDX_FEXCITATION].fData[0];
    FLOAT* pfInhibition = &self->zValues[SG_NDX_FINHIBITION].fData[0];

    if (!SG_IsSchemaOK(self->nSGobjSchema))
        return SG_R_SCHM;

    /* TODO: put your simulator code here */

    /* This routine implements get net input from each of the adjacent unit */

    /* zero out local excitation and inhibition level for accumulation */
    *pfExcitation = *pfInhibition = 0.0f;

    /* calculate excitation and inhibition level from adjacent units */
    for (i = 0; i < *piAdjObjs; i++)
    {
        fAct = adjObjs[i]->zValues[SG_NDX_FACTIVATION].fData[0];
        if (fAct > 0.0f)
        {
            fWeight = (iHidden != 0) ?

                      lnkObjs[i]->zValues[LINK_NDX_FWINH].fData[0] :
                      lnkObjs[i]->zValues[LINK_NDX_FWOUTH].fData[0];
            if (fWeight > 0.0f)
                *pfExcitation += fAct * fWeight;
            else if (fWeight < 0.0f)
                *pfInhibition += fAct * fWeight;
        }
    }

    /* scale excitation and inhibition */
    *pfExcitation *= self->zValues[SG_NDX_FALPHA].fData[0];
    *pfInhibition *= self->zValues[SG_NDX_FGAMMA].fData[0];

 

    /* calculate net input from total excitation and inhibition from

     * adjacent units and external inputs
     */
    self->zValues[SG_NDX_FNETINPUT].fData[0] = *pfExcitation +

          *pfInhibition + self->zValues[SG_NDX_FESTR].fData[0] *

                          self->zValues[SG_NDX_FEXTINPUT].fData[0];

    return SG_R_OK;
}

/* ============================================================
 * SG_xEval - Evaluation
 * ------------------------------------------------------------
 */
SG_RET_CODE SG_xEval_Base_Neuron(SG_OBJ *const self,
          SG_OBJ *const simCtrl, SG_OBJ *const chgChild,
          SG_OBJ *const refObjs[], const INT *const piRefObjs,
          SG_OBJ *const adjObjs[], const INT *const piAdjObjs,
          SG_OBJ *const lnkObjs[], const INT *const piLnkObjs,
          TCHAR *const cMessage, const INT iMsgLen,
          TCHAR *const cCommand, const INT iCmdLen,
          SG_FILE *const pOutFile )
{
    /* TODO: declare your local variables here */

    FLOAT* pfAct = &self->zValues[SG_NDX_FACTIVATION].fData[0];
    FLOAT fNetInput = self->zValues[SG_NDX_FNETINPUT].fData[0];
    FLOAT fMaxActiv = self->zValues[SG_NDX_FMAXACTIV].fData[0];
    FLOAT fMinActiv = self->zValues[SG_NDX_FMINACTIV].fData[0];

    if (!SG_IsSchemaOK(self->nSGobjSchema))
        return SG_R_SCHM;

    /* TODO: put your simulator code here */

    if (fNetInput > 0.0f)
    {
        *pfAct = fNetInput * (fMaxActiv - (*pfAct)) +
                 self->zValues[SG_NDX_FOMD].fData[0] * (*pfAct) +
                 self->zValues[SG_NDX_FDTR].fData[0];
        if (*pfAct > fMaxActiv)
            *pfAct = fMaxActiv;
    }
    else
    {
        *pfAct = fNetInput * ((*pfAct) - fMinActiv) +
                 self->zValues[SG_NDX_FOMD].fData[0] * (*pfAct) +
                 self->zValues[SG_NDX_FDTR].fData[0];
        if (*pfAct < fMinActiv)
            *pfAct = fMinActiv;
    }

    return SG_R_OK;
}

 


SansGUI Modeling and Simulation Environment version 1.2

Copyright © 2000-2003 ProtoDesign, Inc. All rights reserved.

http://protodesign-inc.com