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.

175 lines
4.8 KiB

  1. /* **************************************************************************** */
  2. /* **************************************************************************** */
  3. /* * AVP 1996 * */
  4. /* **************************************************************************** */
  5. #ifndef MLP_HEADER_INCLUDED
  6. #define MLP_HEADER_INCLUDED
  7. #include "snn.h"
  8. #if !MLP_PRELOAD_MODE
  9. #include "stdio.h"
  10. #endif
  11. // -------------------- Defines ------------------------------------------------
  12. #define MLP_EXPTABL_MAX 8
  13. #define MLP_EXPTABL_SIZE 512
  14. // -------------------- Defines ------------------------------------------------
  15. #define MLP_UNROLL_CYCLES 1
  16. #define MLP_ROLLING_LEARN 0
  17. #define MLP_F_CELL_CMASK 0x0001
  18. #define MLP_F_CELL_PMASK 0x0002
  19. // -----------------------------------------------------------------------------
  20. #define MLP_ABS(x) (((x) > 0) ? (x):(-(x)))
  21. #define MLP_ERR(e) ((e)*(e)*(e))
  22. //#define MLP_ERR(e) (((e) > 0) ? (e)*(e) : -((e)*(e)))
  23. #if MLP_UPSCALE
  24. #if MLP_BYTE_NET
  25. #define MLP_MAX_INT_C 127
  26. #define MLP_MAX_INT_S 255
  27. #if MLP_INT_MODE
  28. #define x_UPCO_C << 3
  29. #define x_DNCO_C >> 3
  30. #define x_UPCO_S << 8
  31. #define x_DNCO_S >> 8
  32. #define x_DNDNCO_S >> 16
  33. #else
  34. #define x_UPCO_C *(8)
  35. #define x_DNCO_C *(0.125)
  36. #define x_UPCO_S *(256)
  37. #define x_DNCO_S *(0.00390625)
  38. #define x_DNDNCO_S *(1.52587890625E-05)
  39. #endif
  40. #else // SHORT mode
  41. #define MLP_MAX_INT_C 32767
  42. #define MLP_MAX_INT_S 4095
  43. #if MLP_INT_MODE
  44. #define x_UPCO_C << 9
  45. #define x_DNCO_C >> 9
  46. #define x_UPCO_S << 12
  47. #define x_DNCO_S >> 12
  48. #define x_DNDNCO_S >> 24
  49. #else
  50. #define x_UPCO_C *(512)
  51. #define x_DNCO_C *(0.001953125)
  52. #define x_UPCO_S *(4096)
  53. #define x_DNCO_S *(0.000244140625)
  54. #define x_DNDNCO_S *(5.96046447753906E-08)
  55. #endif
  56. #endif // MLP_BYTE_NET
  57. #else
  58. // #define MLP_MAX_INT_C 63.9
  59. // #define MLP_MAX_INT_C 15.875
  60. #define MLP_MAX_INT_C 127
  61. #define MLP_MAX_INT_S 1.0
  62. #define x_UPCO_C
  63. #define x_DNCO_C
  64. #define x_UPCO_S
  65. #define x_DNCO_S
  66. #define x_DNDNCO_S
  67. #endif
  68. #if MLP_EMULATE_INT && !(MLP_INT_MODE)
  69. #define FINT_C_OF(x) ((fint_c)(x))
  70. #define FINT_S_OF(x) ((fint_s)(x))
  71. #else
  72. #define FINT_C_OF(x) ((flong)(x))
  73. #define FINT_S_OF(x) ((flong)(x))
  74. #endif
  75. #if MLP_INT_MODE
  76. #define FINT_C_LD(x) (((x) > -MLP_MAX_INT_C && (x) < MLP_MAX_INT_C) ? (fint_c)(x) : (((x) > 0) ? MLP_MAX_INT_C : -MLP_MAX_INT_C))
  77. #else
  78. #define FINT_C_LD(x) (x)
  79. #endif
  80. // -------------------- Structures and classes ---------------------------------
  81. typedef struct
  82. {
  83. _USHORT inp_ind;
  84. fint_c bias;
  85. fint_c weights[MLP_CELL_MAXINPUTS];
  86. #if MLP_LEARN_MODE // Debug + learning
  87. float err;
  88. float sbias;
  89. float psbias;
  90. float sws[MLP_CELL_MAXINPUTS];
  91. float psws[MLP_CELL_MAXINPUTS];
  92. _INT num_sws;
  93. _INT num_psws;
  94. _UCHAR flags;
  95. // _USHORT out_ind;
  96. _INT num_changes;
  97. float prev_val;
  98. #endif
  99. } mlp_cell_type, * p_mlp_cell_type;
  100. typedef struct
  101. {
  102. flong sum_delt;
  103. _INT num_sum;
  104. } mlp_layer_type, * p_mlp_layer_type;
  105. typedef struct
  106. {
  107. _UCHAR id_str[32];
  108. _INT num_layers;
  109. _INT num_inputs;
  110. _INT num_outputs;
  111. fint_s exp_tabl[MLP_EXPTABL_SIZE];
  112. mlp_cell_type cells[MLP_NET_NUMCELLS];
  113. mlp_layer_type layers[MLP_NET_NUMLAYERS];
  114. } mlp_net_type, * p_mlp_net_type;
  115. // ---------------- Functions --------------------------------------------------
  116. _INT CountNetResult(p_UCHAR inps, p_UCHAR outs, p_mlp_data_type mlpd);
  117. fint_s CountCellSignal(_INT nc, p_mlp_data_type mlpd);
  118. #if !MLP_PRELOAD_MODE
  119. _INT LoadNet(FILE * file, p_mlp_data_type mlpd);
  120. _INT InitNet(_INT type, p_mlp_data_type mlpd);
  121. _INT FillExpTable(flong ic, p_mlp_data_type mlpd);
  122. #endif
  123. #if MLP_LEARN_MODE
  124. _INT InitNetWeights(_INT type, flong ic, p_mlp_data_type mlpd);
  125. _INT CountNetError(float * desired_outputs, flong zc, p_mlp_data_type mlpd);
  126. _INT ModifyNetDeltas(_INT flags, p_mlp_data_type mlpd);
  127. _INT AdjustNetWeights(_INT flags, float * lcs, float ic, p_mlp_data_type mlpd);
  128. _INT ShakeNetWeights(_INT flags, float lc, p_mlp_data_type mlpd);
  129. _INT CountNetStats(_INT mode, p_mlp_data_type mlpd);
  130. _INT SaveNet(FILE *file, p_mlp_data_type mlpd);
  131. _INT DumpNet(FILE *file, p_mlp_data_type mlpd);
  132. _INT CalcHiddenLayerError(_INT layer_st, _INT layer_len, p_mlp_data_type mlpd);
  133. _INT CountLayerStats(_INT mode, _INT layer_num, _INT layer_st, _INT layer_len, p_mlp_data_type mlpd);
  134. _INT InitCellWeights(_INT type, float ic, _INT ncell, p_mlp_data_type mlpd);
  135. #endif
  136. #endif // MLP_HEADER_INCLUDED
  137. /* **************************************************************************** */
  138. /* * End OF all * */
  139. /* **************************************************************************** */
  140. //