MemSys5 in C specification The MemSys5 application is described by a MEMSYS structure that specifies the location of inputs, outputs, programs, arrays and diagnostics. struct sMEMPTR; // Structure for array pointers struct sMEMIN; // Structure for input variables struct sMEMOUT; // Structure for output variables struct sMEMPROCS; // Structure defining user procedures typedef struct { struct sMEMPTR* psVpoint; struct sMEMIN* psInput; struct sMEMOUT* psOutput; struct sMEMPROCS* psProcs; FILE* fpLog; } MEMSYS; // Global structure with all MemSys structures The pointer structure psVpoint contains pointers to all the MemSys5 arrays that are accessible to the user (and must be allocated by the user). Not all are used in every MemSys5 application --- this depends on the MemSys5 options. Arrays are divided into two types – hidden space and data space quantities, with respective lengths iNcell and iNdata. The arrays afResult, afData, afLagrange are always required. The afAcc array is needed if the accuracies of the data are not constant and specified by the fAcc parameter. Similarly, if the default model for hidden space is not constant and specified by the parameter fDef, the array afDefault will be needed. The afMock and afResidual arrays and are needed if MemSys5 is called with memrun=4, and these will then contain the mock data and normalised residuals. MemSys5 has a very limited ability to deal with non-linear transforms (MemSys4 and RAMem are more appropriate programs for this case), but simple non-linearities can be dealt with by providing the pfnUmemx function and the additional data-space array afNonlinear. The structure also contains a pointer to the user struct psUser, where transform parameters and other useful information can be stored. typedef struct sMEMPTR { int iNcell; // I # result cells float* afResult; // O MaxEnt result [iNcell] float* afDefault; //(I) Model (if psInput->fDef = 0) [iNcell] float* afMask; //(I) Quantify mask (for MemMask5) [iNcell] int iNdata; // I # data float* afData; // I Data [iNdata] float* afAcc; //(I) Accuracies (if psInput->fAcc = 0)[iNdata] float* afLagrange; // O Lagrange multipliers for result [iNdata] float* afMock; // O Mock data (for memrun=4) [iNdata] float* afResiduals; // O Acc * (Data - Mock) [iNdata] float* afNonlinear; // (O) (required if psProcs->Umemx) [iNdata] void* psUser; // I Transform information } MEMPTR; // MemSys vector pointers The input structure psInput contains the MemSys5 input parameters as described in the manual. The contents of the MemSys5 output structure psOutput are also as described in the manual. The MemSys5 procedure structure contains the user-defined transform and diagnostic routines. typedef struct sMEMIN { int iBayes; // I Stopping switch int iEntropy; // I Entropy switch int iGauss; // I Likelihood switch int iNrand; // I # random vectors int iIseed; // I Regulariser seed float fAim; // I Constraint target float fRate; // I Distance & beta control float fDef; // I Default (if >0) float fAcc; // I Accuracies (if >0) float fUtol; // I Tolerance, O(0.1) } MEMIN; // MemSys input parameters typedef struct sMEMOUT { float fS; // O Entropy float fTest; // O Gradient misfit float fChisq; // O Chi-squared float fScale; // O Scaling sigma(D) float fPlow; // O < evidence float fPhigh; // O > evidence float fPdev; // O Std dev evidence float fGlow; // O < good float fGhigh; // O > good float fGdev; // O Std dev good float fOmega; // O Termination float fAlpha; // I O Regularising parameter int iNtrans; // I O # of transforms float fHhigh; // I O Internal MemSys bubble mismatch float fXtable[8]; // I O Internal MemSys log(alpha) float fYtable[8]; // I O Internal MemSys log(omega) float fVtable[8]; // I O Internal MemSys variance(omega) int iNtable; // I O Internal MemSys length of table int iIstat; // I O Internal MemSys return code unsigned iRand[112]; // I O Internal MemSys randomiser state float* afSt[41]; // (O) Internal MemSys addresses int aiLen[41]; // (O) Internal Memsys lengths } MEMOUT; // MemSys output parameters typedef struct sMEMPROCS { int (*pfnOpus) // Object-to-Data transform (void* psUser, // I Transform structure const float* afObject, // I Input MaxEnt area float* afData ); // O Output data area int (*pfnTropus) // Transpose opus (void* psUser, // I Transform structure const float* afData, // I Input data area float* afObject ); // O Output MaxEnt area int (*pfnUmemx) // Data nonlinearity (float fX, // I Linear transform (x) float* fPhi, // O Nonlinear mock F(x) float* fDphi ); // O Differential dF/dx int (*pfnUinfo) // Manage diagnostics (FILE* fpLog, // I File for diagnostics const char* cString); // I Diagnostic string } MEMPROCS; // MemSys procedure calls The following code initialises the struct MemSys and provides a pointer to the diagnostic file maxent.log. The user-defined struct User contains useful information about the hidden->data transform. In this example the user must provide the transform functions opus and tropus and the diagnostic function uinfo. Unused pointers (such as MemProcs.pfnUmemx should be set explicitly to NULL. #include "memsys5.h" USER User; // User structure for transform MEMIN MemIn; // MemSys Input parameters MEMOUT MemOut; // MemSys Output structure MEMPTR MemPtr; // MemSys Pointer structure MEMPROCS MemProcs; // MemSys Procedure structure MEMSYS MemSys; // Overall MemSys structure //**************** Initialise the MemSys structure *********************** MemSys.psInput = &MemIn; MemSys.psOutput = &MemOut; MemSys.psVpoint = &MemPtr; MemSys.psProcs = &MemProcs; (MemSys.psVpoint)->psUser = &User; MemSys.fpLog = fopen("maxent.log", "w"); // NULL is allowed //**************** Procedures go into MemProcs ************************** MemProcs.pfnOpus = opus; MemProcs.pfnTropus = tropus; MemProcs.pfnUinfo = uinfo; MemProcs.pfnUmemx = NULL; // NULL ensures linear transform