Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
5.1 KiB

  1. /************************************************************
  2. *
  3. * runNet.h
  4. *
  5. * Bare bones net.
  6. * Use this implementation to build and run a net
  7. * (Not for training)
  8. *
  9. * mrevow
  10. *
  11. ***********************************************************/
  12. #ifndef H_RUN_NET_H
  13. #define H_RUN_NET_H
  14. // Versioning infrmation
  15. // December 2001 Introduced versioning information. Prior to this the version
  16. // number did not exist. The first element was eNetType which had value < 10
  17. //
  18. // Changes introduce lossType, txfer and unitType into runNet description
  19. //
  20. // March 2002
  21. // Incompatible changes:
  22. // Add upfront scaling of features (Added the range vector for input vars)
  23. // Also add data-type sizes for all weight, bias and range vectors
  24. //
  25. #define RUN_NET_VER_START (10) // First version number introduced December 2001
  26. #define RUN_NET_VER_10 (10) // December 2001 - March 2002
  27. #define RUN_NET_VER_11 (11) // March 2002 Current Version Number
  28. //#define NET_FLOAT
  29. typedef int RREAL; // Used for intermediate calculation and unit activations
  30. typedef short RREAL_WEIGHT; // Used for Net weights (excluding bias)
  31. typedef int RREAL_BIAS; // Used for bias weights
  32. typedef __int64 RREAL_INPUT; // Used for scaling inputs which are of type RREAL
  33. // This types is shared between the train and run time nets
  34. // It is defined here and in netTypes.h - kkep them in sync
  35. #ifndef CAMEL_NET_TYPE_DEFINED
  36. typedef enum tagNET_TYPE {NO_NET_TYPE, FULLY_CONNECTED, LOCALLY_CONNECTED} NET_TYPE;
  37. typedef enum tagLOSS_TYPE {SUMSQUARE, SUMSQUARE_CLASS, CROSSENTROPY, CROSSENTROPY_FULL, C_LOSS_TYPE} LOSS_TYPE;
  38. typedef enum tagTXF_TYPE {TXF_LINEAR, TXF_INT_SIGMOID, TXF_SIGMOID, TXF_TANH, TXF_SOFTMAX, CTXF_TYPE} TXF_TYPE;
  39. typedef enum tagLAYER_TYPE {INPUT_LAYER, HIDDEN_LAYER, OUTPUT_LAYER, BIAS_LAYER, CLAYER_TYPE} LAYER_TYPE;
  40. #define CAMEL_NET_TYPE_DEFINED
  41. #endif
  42. #define MIN_PREC_VAL 0
  43. #define SOFT_MAX_UNITY 10000 // Value of 1.0 in the softMax
  44. // Describes a net. In a running net the description
  45. // up to and including the weight vector will be loaded
  46. // from a resource
  47. typedef struct tagRUN_NET
  48. {
  49. WORD iVer; // Added December 2001 - Versioning information -> 0 implies none present
  50. WORD cLayer; // Number of layers in net
  51. LOSS_TYPE lossType; // Added December 2001 - Type of output loss - only present for net versions > 10
  52. TXF_TYPE *txfType; // Added December 2001 - Txfer type for each layer - only present for net versions > 10
  53. LAYER_TYPE *layerType; // Added December 2001 - Unit type of eachlayer - only present for net versions > 10
  54. WORD cWeight; // Total # of weights in network
  55. WORD cTotUnit; // Total number of units in network
  56. WORD *cUnitsPerLayer; // # of units per layer
  57. WORD *bUseBias; // Use bias units? per layer
  58. WORD *pWeightScale; // Amount by which each layers incoming weights are scaled
  59. WORD iInputScaledMeanDataSize; // Data type size for pInputMean (Introduced March 2002)
  60. WORD iInputRangeDataSize;// Data type size for Input Range Vector (Introduced March 2002)
  61. WORD iWeightDataSize; // Data Type size for weight vector (Introduced March 2002)
  62. RREAL *pInputRange; // Ranges for each input variable > 0 (Introduced March 2002)
  63. RREAL_INPUT *pInputScaledMean; // Scaled Means for input data (Introduced March 2002 to replace pInputMean)
  64. RREAL *pInputMean; // Means for input data
  65. UINT cWeightByte; // Count of bytes used for weights
  66. RREAL_WEIGHT *pWeight; // All network weights.
  67. } RUN_NET;
  68. // describes the outgoing connections of a unit
  69. // as the start and end unit offsets to which it connects
  70. typedef struct tagOUT_CONNECTIONS
  71. {
  72. WORD iUnit; // The unit in question
  73. WORD iStartUnitOffset;
  74. WORD iEndUnitOffset;
  75. } OUT_CONNECTIONS;
  76. // Describes a locally connected network
  77. typedef struct tagLOCAL_NET
  78. {
  79. WORD iVer; // Version Number (Started December 2001, Before all nets had eNetType as the first element set to LOCALLY_CONNECT (
  80. WORD eNetType; // Must be of type LOCALLY_CONNECTED
  81. RUN_NET runNet; // How to run the Net
  82. int cConnect; // Number of connections
  83. OUT_CONNECTIONS *pOutConnect;
  84. } LOCAL_NET;
  85. #ifdef __cplusplus
  86. extern "C"
  87. {
  88. #endif
  89. // API functions
  90. extern BYTE *restoreRunNet( BYTE *pBuf, BYTE *pBCurr, RUN_NET *pNet, WORD iVer) ;
  91. extern LOCAL_NET * restoreLocalConnectNet( void *pBuf, wchar_t wNetId, LOCAL_NET *pNet ) ;
  92. extern RREAL *runFullConnectNet( RUN_NET *pNet, RREAL *pfUnits, UINT *piWinner ) ;
  93. extern RREAL *runLocalConnectNet( LOCAL_NET *pNet, RREAL *pfUnits, UINT *piWinner, UINT *pcOut ) ;
  94. extern int getRunTimeNetMemoryRequirements(void *pBuf);
  95. extern LOCAL_NET *loadNet(HINSTANCE hInst, int iKey, int *iNetSize, LOCAL_NET *pNet);
  96. extern void *loadNetFromResource(HINSTANCE hInst, int iKey, int *iSize);
  97. #ifdef NET_FLOAT
  98. #define SIGMOID fsigmoid
  99. #define EXP(x) exp((x)/65536.0F) * 65536.0F
  100. RREAL * fsigmoid(RREAL *pVec, int cVec, WORD scale);
  101. #else
  102. #define SIGMOID isigmoid
  103. #define EXP(x) iexp(x)
  104. RREAL * isigmoid(RREAL *pVec, int cVec, WORD scale);
  105. RREAL iexp(RREAL val);
  106. #endif
  107. #ifdef HWX_INTERNAL
  108. LOCAL_NET * LoadRunNetFromFp(LOCAL_NET *pNet, int *iNetSize, char * fname);
  109. #endif
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113. #endif