'------------------------------------------------ ' API: these function calls link to the MS VC NXL2.DLL '------------------------------------------------ Public Const MAXERR = 1000000# ' Required to pass strings to the library Public Type String12: char As String * 12: End Type ' Enable Library Public Declare Sub SCN Lib "NXL2.dll" Alias "_SCN@4" (cn As String12) Public Declare Function EnableLibrary Lib "NXL2.dll" Alias "_EnableLibrary@4" (cn As String12) As Integer ' Set or Retrieve Inputs/Outputs Public Declare Function Load_TestPatternOutput Lib "NXL2.dll" _ Alias "_Load_TestPatternOutput@12" (ByRef outno As Integer, ByRef patno As Long, ByRef out As Double) As Double Public Declare Function Load_TrainPatternOutput Lib "NXL2.dll" _ Alias "_Load_TrainPatternOutput@12" (ByRef outno As Integer, ByRef patno As Long, ByRef out As Double) As Double Public Declare Function Load_TestPatternInput Lib "NXL2.dll" _ Alias "_Load_TestPatternInput@12" (ByRef inpno As Integer, ByRef patno As Long, ByRef inp As Double) As Double Public Declare Function Load_TrainPatternInput Lib "NXL2.dll" _ Alias "_Load_TrainPatternInput@12" (ByRef inpno As Integer, ByRef patno As Long, ByRef inp As Double) As Double Public Declare Function Save_TrainPatternInput Lib "NXL2.dll" _ Alias "_Save_TrainPatternInput@8" (ByRef inpno As Integer, ByRef patno As Long) As Double Public Declare Function Save_TestPatternOutput Lib "NXL2.dll" _ Alias "_Save_TestPatternOutput@8" (ByRef outno As Integer, ByRef patno As Long) As Double Public Declare Function Save_TrainPatternOutput Lib "NXL2.dll" _ Alias "_Save_TrainPatternOutput@8" (ByRef outno As Integer, ByRef patno As Long) As Double Public Declare Function Save_TestPatternInput Lib "NXL2.dll" _ Alias "_Save_TestPatternInput@8" (ByRef inpno As Integer, ByRef patno As Long) As Double ' Set Sizes Public Declare Sub Set_TrainingSize Lib "NXL2.dll" Alias "_Set_TrainingSize@4" (ByVal numpat As Integer) Public Declare Sub Set_TestSize Lib "NXL2.dll" Alias "_Set_TestSize@4" (ByVal numpat As Integer) Public Declare Sub Set_MaxNumNodes Lib "NXL2.dll" Alias "_Set_MaxNumNodes@4" (ByVal numnodes As Integer) Public Declare Sub Set_NumInputs Lib "NXL2.dll" Alias "_Set_NumInputs@4" (ByVal NumInputs As Integer) Public Declare Sub Set_NumOutputs Lib "NXL2.dll" Alias "_Set_NumOutputs@4" (ByVal NumOutputs As Integer) ' Retrieve params set by InitNet Public Declare Function Get_NumInputs Lib "NXL2.dll" Alias "_Get_NumInputs@0" () As Integer Public Declare Function Get_NumOutputs Lib "NXL2.dll" Alias "_Get_NumOutputs@0" () As Integer Public Declare Function Get_NumHiddens Lib "NXL2.dll" Alias "_Get_NumHiddens@0" () As Integer Public Declare Function Get_MaxNumNodes Lib "NXL2.dll" Alias "_Get_MaxNumNodes@0" () As Integer ' Set Training Parameters (default values defined in InitNet Public Declare Sub Set_Epsilon Lib "NXL2.dll" Alias "_Set_Epsilon@8" (ByVal e As Double) Public Declare Sub Set_WeightRange Lib "NXL2.dll" Alias "_Set_WeightRange@8" (ByVal wr As Double) Public Declare Sub Set_SigOffset Lib "NXL2.dll" Alias "_Set_SigOffset@8" (ByVal o As Double) Public Declare Sub Set_HyperErr Lib "NXL2.dll" Alias "_Set_HyperErr@4" (ByVal h As Integer) Public Declare Sub Set_Decay Lib "NXL2.dll" Alias "_Set_Decay@8" (ByVal d As Double) Public Declare Sub Set_Seed Lib "NXL2.dll" Alias "_Set_Seed@4" (ByVal s As Integer) Public Declare Sub Set_SplitEpsilon Lib "NXL2.dll" Alias "_Set_SplitEpsilon@4" (ByVal se As Integer) Public Declare Sub Set_Tolerance Lib "NXL2.dll" Alias "_Set_Tolerance@8" (ByVal tol As Double) Public Declare Sub Set_MaxFactor Lib "NXL2.dll" Alias "_Set_MaxFactor@8" (ByVal mf As Double) Public Declare Sub Set_Pruning Lib "NXL2.dll" Alias "_Set_Pruning@4" (ByVal p As Integer) Public Declare Sub Set_PruningCutOff Lib "NXL2.dll" Alias "_Set_PruningCutOff@8" (ByVal pco As Double) Public Declare Sub Set_JumpLinks Lib "NXL2.dll" Alias "_Set_JumpLinks@4" (ByVal j As Integer) ' Retrieve Training Parameters Public Declare Function Get_Epsilon Lib "NXL2.dll" Alias "_Get_Epsilon@0" () As Double Public Declare Function Get_WeightRange Lib "NXL2.dll" Alias "_Get_WeightRange@0" () As Double Public Declare Function Get_SigOffset Lib "NXL2.dll" Alias "_Get_SigOffset@0" () As Double Public Declare Function Get_HyperErr Lib "NXL2.dll" Alias "_Get_HyperErr@0" () As Integer Public Declare Function Get_Decay Lib "NXL2.dll" Alias "_Get_Decay@0" () As Double Public Declare Function Get_Seed Lib "NXL2.dll" Alias "_Get_Seed@0" () As Integer Public Declare Function Get_MaxFactor Lib "NXL2.dll" Alias "_Get_MaxFactor@0" () As Double Public Declare Function Get_Pruning Lib "NXL2.dll" Alias "_Get_Pruning@0" () As Integer Public Declare Function Get_PruningCutOff Lib "NXL2.dll" Alias "_Get_PruningCutOff@0" () As Double Public Declare Function Get_JumpLinks Lib "NXL2.dll" Alias "_Get_JumpLinks@0" () As Integer Public Declare Function Get_SplitEpsilon Lib "NXL2.dll" Alias "_Get_SplitEpsilon@0" () As Integer Public Declare Function Get_Tolerance Lib "NXL2.dll" Alias "_Get_Tolerance@0" () As Double Public Declare Function Get_MemAllocated Lib "NXL2.dll" Alias "_Get_MemAllocated@0" () As Integer ' Get/Set Weight function used to retrieve/save neural structure (weight arrays are 0-based) Public Declare Function Get_Weight Lib "NXL2.dll" _ Alias "_Get_Weight@8" (ByVal i As Integer, ByVal j As Integer) As Double Public Declare Sub Set_Weight Lib "NXL2.dll" _ Alias "_Set_Weight@16" (ByVal i As Integer, ByVal j As Integer, ByVal val As Double) ' Calculates contribution of particular input to output Public Declare Function Contribution Lib "NXL2.dll" _ Alias "_Contribution@8" (ByVal inputno As Integer, ByVal outputno As Integer) As Double ' Init Net. Returns 0 if OK, -1 otherwise Public Declare Function BuildNet Lib "NXL2.dll" Alias "_BuildNet@16" _ (NumInputs As Integer, NumHidden As Integer, NumOutputs As Integer, _ jumplink As Integer) As Integer ' Other BuildNet function, where Jumplinks are set/reset separately (no jumplinks by default) Public Declare Function BuildNetL Lib "NXL2.dll" Alias "_BuildNetL@12" _ (NumInputs As Integer, NumHidden As Integer, NumOutputs As Integer) As Integer ' Release all memory Public Declare Sub ReleaseNet Lib "NXL2.dll" Alias "_ReleaseNet@0" () ' Training procedures. Train1Epoch returns the TotalTrainError Public Declare Function Train_Epochs Lib "NXL2.dll" Alias "_Train_Epochs@4" (ByVal NumEpochs As Integer) As Double Public Declare Function Train_1Epoch Lib "NXL2.dll" Alias "_Train_1Epoch@0" () As Double Public Declare Function RunTrainingPatternThroughNet Lib "NXL2.dll" Alias "_RunTrainingPatternThroughNet@8" _ (ByVal patno As Long, ByVal outno As Integer) As Double Public Declare Function RunTestPatternThroughNet Lib "NXL2.dll" Alias "_RunTestPatternThroughNet@8" _ (ByVal patno As Long, ByVal outno As Integer) As Double ' Training Error (automatically reset after each Epoch) Public Declare Function TotalNetError Lib "NXL2.dll" Alias "_TotalNetError@0" () As Double Public Declare Function AvgTrainNetError Lib "NXL2.dll" Alias "_AvgTrainNetError@0" () As Double Public Declare Function AvgTestNetError Lib "NXL2.dll" Alias "_AvgTestNetError@0" () As Double ' Testing Procedure. TestNet returns TotalTestError Public Declare Function TestNet Lib "NXL2.dll" Alias "_TestNet@4" (ByVal outno As Single) As Double ' Get/Reset Test Error Public Declare Function GetTestError Lib "NXL2.dll" Alias "_GetTestError@0" () As Double Public Declare Sub ResetTestError Lib "NXL2.dll" Alias "_ResetTestError@0" () ' NXL Version Number Public Declare Function NXL_VersionNo Lib "NXL2.dll" Alias "_NXL_VersionNo@0" () As Double ' The following functions are used to verify the existence of the DLL Const OF_EXIST = &H4000 Const OFS_MAXPATHNAME = 128 Type OFSTRUCT cBytes As Byte fFixedDisk As Byte nErrCode As Integer Reserved1 As Integer Reserved2 As Integer szPathName(OFS_MAXPATHNAME) As Byte End Type Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long Public Declare Function GetWindowsDirectory Lib "kernel32" _ Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long Public Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long Function WindowsDirectory() As String Dim strBuffer As String Dim lngLen As Long strBuffer = Space(dhcMaxPath) lngLen = dhcMaxPath lngLen = GetWindowsDirectory(strBuffer, lngLen) If lngLen > dhcMaxPath Then strBuffer = Space(lngLen) lngLen = GetWindowsDirectory(strBuffer, lngLen) End If WindowsDirectory = Left$(strBuffer, lngLen) End Function Function WindowsSystemDirectory() As String Dim strBuffer As String Dim lngLen As Long strBuffer = Space(dhcMaxPath) lngLen = dhcMaxPath lngLen = GetSystemDirectory(strBuffer, lngLen) If lngLen > dhcMaxPath Then strBuffer = Space(lngLen) lngLen = GetSystemDirectory(strBuffer, lngLen) End If WindowsSystemDirectory = Left$(strBuffer, lngLen) End Function