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.

347 lines
11 KiB

  1. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation. All rights reserved.
  4. //
  5. // Module:
  6. // volcano/inc/vtune.h
  7. //
  8. // Description:
  9. // Volcano tuning parameters
  10. //
  11. // Author:
  12. // hrowley
  13. //
  14. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  15. #pragma once
  16. #include <wtypes.h>
  17. #include "common.h"
  18. // These constants are used to configure which recognizer is used at
  19. // which stroke counts. They are also used as indices into a lookup
  20. // table for the weight to give to the score from each recognizer.
  21. // Configuration for the recognizer
  22. #define VOLCANO_CONFIG_NONE -1
  23. #define VOLCANO_CONFIG_OTTER 0
  24. #define VOLCANO_CONFIG_ZILLA 1
  25. #define VOLCANO_CONFIG_HOUND 2
  26. // How many recognizers are defined above.
  27. #define VOLCANO_CONFIG_NUM_CORE_RECOGNIZERS 3
  28. // The maximum stroke count which needs to be configured
  29. #define VOLCANO_CONFIG_MAX_STROKE_COUNT 29
  30. // Recognizer configuration
  31. typedef struct tagVOLCANO_CONFIG
  32. {
  33. // Which recognizer to use fo reach number of strokes
  34. int iRecognizers[VOLCANO_CONFIG_MAX_STROKE_COUNT + 1];
  35. } VOLCANO_CONFIG;
  36. // These values are used as indices into the array of
  37. // weights for scores from different recognizer components.
  38. // The first three are global weights for all recognizer modes
  39. // The following two don't actually get tuned because there isn't enough data.
  40. #define VTUNE_ADHOC_CIRCLE (0)
  41. #define VTUNE_ADHOC_IJ (VTUNE_ADHOC_CIRCLE + 1)
  42. #define VTUNE_UNIGRAM (VTUNE_ADHOC_IJ + 1)
  43. // These parameters are used only in character mode
  44. #define VTUNE_CHAR_SHAPE_BOX_UNIGRAM (VTUNE_UNIGRAM + 1)
  45. #define VTUNE_CHAR_CRANE (VTUNE_CHAR_SHAPE_BOX_UNIGRAM + 1)
  46. #define VTUNE_CHAR_CORE (VTUNE_CHAR_CRANE + 1)
  47. // These are used in string mode
  48. #define VTUNE_STRING_SHAPE_BOX_UNIGRAM (VTUNE_CHAR_CORE + VOLCANO_CONFIG_NUM_CORE_RECOGNIZERS)
  49. #define VTUNE_STRING_CRANE (VTUNE_STRING_SHAPE_BOX_UNIGRAM + 1)
  50. #define VTUNE_STRING_CORE (VTUNE_STRING_CRANE + 1)
  51. #define VTUNE_STRING_SHAPE_BOX_BIGRAM (VTUNE_STRING_CORE + VOLCANO_CONFIG_NUM_CORE_RECOGNIZERS)
  52. #define VTUNE_STRING_SMOOTHING_UNIGRAM (VTUNE_STRING_SHAPE_BOX_BIGRAM + 1)
  53. #define VTUNE_STRING_BIGRAM (VTUNE_STRING_SMOOTHING_UNIGRAM + 1)
  54. #define VTUNE_STRING_CLASS_BIGRAM (VTUNE_STRING_BIGRAM + 1)
  55. // These are used in free input mode
  56. #define VTUNE_FREE_PROB (VTUNE_STRING_CLASS_BIGRAM + 1)
  57. #define VTUNE_FREE_SMOOTHING_UNIGRAM (VTUNE_FREE_PROB + 1)
  58. #define VTUNE_FREE_BIGRAM (VTUNE_FREE_SMOOTHING_UNIGRAM + 1)
  59. #define VTUNE_FREE_CLASS_BIGRAM (VTUNE_FREE_BIGRAM + 1)
  60. #define VTUNE_FREE_SHAPE_UNIGRAM (VTUNE_FREE_CLASS_BIGRAM + 1)
  61. #define VTUNE_FREE_SHAPE_BIGRAM (VTUNE_FREE_SHAPE_UNIGRAM + 1)
  62. #define VTUNE_FREE_SEG_UNIGRAM (VTUNE_FREE_SHAPE_BIGRAM + 1)
  63. #define VTUNE_FREE_SEG_BIGRAM (VTUNE_FREE_SEG_UNIGRAM + 1)
  64. // Total number of weights
  65. #define VTUNE_NUM_WEIGHTS (VTUNE_FREE_SEG_BIGRAM + 1)
  66. // Hold the weights for various recognizer components.
  67. // It is also used to hold the individual scores from each component when doing
  68. // the tuning, so as to keep the weights and scores in one-to-one correpsondence.
  69. typedef struct VOLCANO_WEIGHTS
  70. {
  71. FLOAT afl[VTUNE_NUM_WEIGHTS];
  72. } VOLCANO_WEIGHTS;
  73. // An array of names of the weights, for the tuning program
  74. extern wchar_t *g_wszVTuneWeightNames[VTUNE_NUM_WEIGHTS];
  75. // Magic key the identifies the tuning database files
  76. #define VTUNE_FILE_TYPE 0x19980808
  77. // Version information for file.
  78. #define VTUNE_MIN_FILE_VERSION 0 // First version of code that can read this file
  79. #define VTUNE_OLD_FILE_VERSION 0 // Oldest file version this code can read.
  80. #define VTUNE_CUR_FILE_VERSION 0 // Current version of code.
  81. // In addition to holding the weights, this holds other parameters which are
  82. // not tuned by the normal linear tuning algorithm, because they have a
  83. // non-linear relationship with the scores.
  84. typedef struct VOLCANO_PARAMS
  85. {
  86. DWORD dwFileType; // This should always be set to VTUNE_FILE_TYPE.
  87. INT iFileVer; // Version of code that wrote the file.
  88. INT iMinCodeVer; // Earliest version of code that can read this file
  89. VOLCANO_WEIGHTS weights; // Weights for components
  90. FLOAT flZillaGeo; // Zilla geometrics weight (untuned for now)
  91. FLOAT flStringHwxWeight; // Weight of hwx scores for IFELang3 in string mode
  92. FLOAT flStringHwxThreshold; // Threshold for hwx scores for IFELang3 in string mode
  93. FLOAT flFreeHwxWeight; // Weight of hwx scores for IFELang3 in free mode
  94. FLOAT flFreeHwxThreshold; // Threshold for hwx scores for IFELang3 in free mode
  95. } VOLCANO_PARAMS;
  96. // This structure holds the pointer to the loaded tuning database
  97. // as well as information for unloading the database later.
  98. typedef struct VOLCANO_PARAMS_INFO
  99. {
  100. VOLCANO_PARAMS *pTune;
  101. LOAD_INFO info;
  102. } VOLCANO_PARAMS_INFO;
  103. // Functions for loading and unloading the database
  104. ///////////////////////////////////////
  105. //
  106. // VTuneLoadFile
  107. //
  108. // Given a parameter information structure and a path,
  109. // map the database from a file called vtune.bin in that
  110. // directory and fill in the info structure.
  111. //
  112. // Parameters:
  113. // pInfo: [out] Pointer to the parameter information structure to fill in.
  114. // wszPath: [in] Name of directory to map vtune.bin from
  115. //
  116. // Return values:
  117. // TRUE on success, FALSE on failure.
  118. //
  119. //////////////////////////////////////
  120. BOOL VTuneLoadFile(VOLCANO_PARAMS_INFO *pInfo, wchar_t *wszPath);
  121. ///////////////////////////////////////
  122. //
  123. // VTuneUnloadFile
  124. //
  125. // Given a parameter information structure, close the mapping
  126. // from the file that holds the parameters.
  127. //
  128. // Parameters:
  129. // pInfo: [in] Pointer to the parameter information structure to fill in.
  130. //
  131. // Return values:
  132. // TRUE on success, FALSE on failure.
  133. //
  134. //////////////////////////////////////
  135. BOOL VTuneUnloadFile(VOLCANO_PARAMS_INFO *pInfo);
  136. ///////////////////////////////////////
  137. //
  138. // VTuneLoadRes
  139. //
  140. // Map a resource as the tuning parameter database
  141. //
  142. // Parameters:
  143. // pInfo: [out] Pointer to the database structure to fill in
  144. // hInst: [in] DLL to locate the resource in
  145. // nResID: [in] Resource ID
  146. // nType: [in] Resource type
  147. //
  148. // Return values:
  149. // TRUE if the mapping succeeds, FALSE if the mapping fails.
  150. //
  151. //////////////////////////////////////
  152. BOOL VTuneLoadRes(VOLCANO_PARAMS_INFO *pInfo, HINSTANCE hInst, int nResID, int nType);
  153. // Functions used at runtime
  154. ///////////////////////////////////////
  155. //
  156. // VTuneInit
  157. //
  158. // Initialize the parameter database to a reasonable set of defaults
  159. // based on the previous volcano parameters.
  160. //
  161. // Parameters:
  162. // pTune: [out] Pointer to a parameter database to be initialized
  163. //
  164. // Return values:
  165. // None.
  166. //
  167. //////////////////////////////////////
  168. void VTuneInit(VOLCANO_PARAMS *pTune);
  169. ///////////////////////////////////////
  170. //
  171. // VTuneWriteFile
  172. //
  173. // Given a set of parameters and a file name, write out the database.
  174. //
  175. // Parameters:
  176. // pTune: [in] The parameters to write out
  177. // wszFileName: [in] The file name to write to
  178. //
  179. // Return values:
  180. // TRUE on success, FALSE on failure.
  181. //
  182. //////////////////////////////////////
  183. BOOL VTuneWriteFile(VOLCANO_PARAMS *pTune, wchar_t *wszFileName);
  184. ///////////////////////////////////////
  185. //
  186. // VTuneZeroWeights
  187. //
  188. // Zero out an array of weights on scores
  189. //
  190. // Parameters:
  191. // pWeights: [out] Pointer to a weights array
  192. //
  193. // Return values:
  194. // None.
  195. //
  196. //////////////////////////////////////
  197. void VTuneZeroWeights(VOLCANO_WEIGHTS *pWeights);
  198. ///////////////////////////////////////
  199. //
  200. // VTuneComputeScore
  201. //
  202. // Compute the weighted sum of the scores and return the result
  203. //
  204. // Parameters:
  205. // pWeights: [in] Pointer to a weights array
  206. // pScores: [in] Pointer to a scores array
  207. //
  208. // Return values:
  209. // Weighted sum of the scores.
  210. //
  211. //////////////////////////////////////
  212. float VTuneComputeScore(VOLCANO_WEIGHTS *pWeights, VOLCANO_WEIGHTS *pScores);
  213. ///////////////////////////////////////
  214. //
  215. // VTuneComputeScoreNoLM
  216. //
  217. // Compute the weighted sum of the scores and return the result.
  218. // Unlike VTuneComputeScore, this version does not add in the
  219. // components of the score related to the language model.
  220. //
  221. // Parameters:
  222. // pWeights: [in] Pointer to a weights array
  223. // pScores: [in] Pointer to a scores array
  224. //
  225. // Return values:
  226. // Weighted sum of the scores.
  227. //
  228. //////////////////////////////////////
  229. float VTuneComputeScoreNoLM(VOLCANO_WEIGHTS *pWeights, VOLCANO_WEIGHTS *pScores);
  230. ///////////////////////////////////////
  231. //
  232. // VTuneAddScores
  233. //
  234. // Add an array of scores to another array of scores
  235. //
  236. // Parameters:
  237. // pDest: [in/out] Array of scores where the result is stored.
  238. // pSrc: [in] Array of scores to add to pDest.
  239. //
  240. // Return values:
  241. // None.
  242. //
  243. //////////////////////////////////////
  244. void VTuneAddScores(VOLCANO_WEIGHTS *pDest, VOLCANO_WEIGHTS *pSrc);
  245. // Functions used at train time
  246. ///////////////////////////////////////
  247. //
  248. // VTuneLoadFileFromName
  249. //
  250. // Given a pointer to a parameter structure and a file name, read
  251. // the parameter database in.
  252. //
  253. // Parameters:
  254. // pTune: [out] Pointer to parameter structure to fill in
  255. // wszFileName: [in] File to read from
  256. //
  257. // Return values:
  258. // TRUE on success, FALSE on failure.
  259. //
  260. //////////////////////////////////////
  261. BOOL VTuneLoadFileFromName(VOLCANO_PARAMS *pTune, wchar_t *wszFileName);
  262. ///////////////////////////////////////
  263. //
  264. // VTuneCheckFileVersion
  265. //
  266. // Check the file header and version information in a tuning database
  267. //
  268. // Parameters:
  269. // pTune: [in] Tuning database to check
  270. //
  271. // Return values:
  272. // TRUE if file version is okay, FALSE otherwise
  273. //
  274. //////////////////////////////////////
  275. BOOL VTuneCheckFileVersion(VOLCANO_PARAMS *pTune);
  276. ///////////////////////////////////////
  277. //
  278. // VTuneCompressTuningRecord
  279. //
  280. // Given an array of scores from the various recognizer components,
  281. // write it out to a file in a compact form. The compaction process
  282. // makes two assumptions, first that there are less than 32 components,
  283. // and second that many of the component scores will be zero. The compact
  284. // form consists of a DWORD which is a bitmask of which components
  285. // have non-zero stores, followed by FLOATs giving those scores.
  286. //
  287. // Parameters:
  288. // f: [in] File to write tuning information to
  289. // pTune: [in] Array of component scores to write out
  290. //
  291. // Return values:
  292. // TRUE on success, FALSE on write failure.
  293. //
  294. //////////////////////////////////////
  295. BOOL VTuneCompressTuningRecord(FILE *f, VOLCANO_WEIGHTS *pTune);
  296. ///////////////////////////////////////
  297. //
  298. // VTuneDecompressTuningRecord
  299. //
  300. // Given a compacted array of scores as produced by the VTuneCompressTuningRecord,
  301. // unpack it into a flat array for use by the tuning programs.
  302. //
  303. // Parameters:
  304. // pTune: [out] Pointer to score array to fill in
  305. // pBuffer: [in] Pointer to the compacted record
  306. //
  307. // Return values:
  308. // Pointer to the next tuning record.
  309. //
  310. //////////////////////////////////////
  311. DWORD *VTuneDecompressTuningRecord(VOLCANO_WEIGHTS *pTune, DWORD *pBuffer);