LogisticRegression.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. 
  2. using OpenCVForUnity.CoreModule;
  3. using OpenCVForUnity.UtilsModule;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Runtime.InteropServices;
  7. namespace OpenCVForUnity.MlModule
  8. {
  9. // C++: class LogisticRegression
  10. //javadoc: LogisticRegression
  11. public class LogisticRegression : StatModel
  12. {
  13. protected override void Dispose (bool disposing)
  14. {
  15. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  16. try {
  17. if (disposing) {
  18. }
  19. if (IsEnabledDispose) {
  20. if (nativeObj != IntPtr.Zero)
  21. ml_LogisticRegression_delete (nativeObj);
  22. nativeObj = IntPtr.Zero;
  23. }
  24. } finally {
  25. base.Dispose (disposing);
  26. }
  27. #else
  28. return;
  29. #endif
  30. }
  31. protected internal LogisticRegression (IntPtr addr)
  32. : base (addr)
  33. {
  34. }
  35. // internal usage only
  36. public static new LogisticRegression __fromPtr__ (IntPtr addr)
  37. {
  38. return new LogisticRegression (addr);
  39. }
  40. // C++: enum RegKinds
  41. public const int REG_DISABLE = -1;
  42. public const int REG_L1 = 0;
  43. public const int REG_L2 = 1;
  44. // C++: enum Methods
  45. public const int BATCH = 0;
  46. public const int MINI_BATCH = 1;
  47. //
  48. // C++: Mat cv::ml::LogisticRegression::get_learnt_thetas()
  49. //
  50. //javadoc: LogisticRegression::get_learnt_thetas()
  51. public Mat get_learnt_thetas ()
  52. {
  53. ThrowIfDisposed ();
  54. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  55. Mat retVal = new Mat (ml_LogisticRegression_get_1learnt_1thetas_10 (nativeObj));
  56. return retVal;
  57. #else
  58. return null;
  59. #endif
  60. }
  61. //
  62. // C++: static Ptr_LogisticRegression cv::ml::LogisticRegression::create()
  63. //
  64. //javadoc: LogisticRegression::create()
  65. public static LogisticRegression create ()
  66. {
  67. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  68. LogisticRegression retVal = LogisticRegression.__fromPtr__ (ml_LogisticRegression_create_10 ());
  69. return retVal;
  70. #else
  71. return null;
  72. #endif
  73. }
  74. //
  75. // C++: static Ptr_LogisticRegression cv::ml::LogisticRegression::load(String filepath, String nodeName = String())
  76. //
  77. //javadoc: LogisticRegression::load(filepath, nodeName)
  78. public static LogisticRegression load (string filepath, string nodeName)
  79. {
  80. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  81. LogisticRegression retVal = LogisticRegression.__fromPtr__ (ml_LogisticRegression_load_10 (filepath, nodeName));
  82. return retVal;
  83. #else
  84. return null;
  85. #endif
  86. }
  87. //javadoc: LogisticRegression::load(filepath)
  88. public static LogisticRegression load (string filepath)
  89. {
  90. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  91. LogisticRegression retVal = LogisticRegression.__fromPtr__ (ml_LogisticRegression_load_11 (filepath));
  92. return retVal;
  93. #else
  94. return null;
  95. #endif
  96. }
  97. //
  98. // C++: TermCriteria cv::ml::LogisticRegression::getTermCriteria()
  99. //
  100. //javadoc: LogisticRegression::getTermCriteria()
  101. public TermCriteria getTermCriteria ()
  102. {
  103. ThrowIfDisposed ();
  104. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  105. double[] tmpArray = new double[3];
  106. ml_LogisticRegression_getTermCriteria_10 (nativeObj, tmpArray);
  107. TermCriteria retVal = new TermCriteria (tmpArray);
  108. return retVal;
  109. #else
  110. return null;
  111. #endif
  112. }
  113. //
  114. // C++: double cv::ml::LogisticRegression::getLearningRate()
  115. //
  116. //javadoc: LogisticRegression::getLearningRate()
  117. public double getLearningRate ()
  118. {
  119. ThrowIfDisposed ();
  120. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  121. double retVal = ml_LogisticRegression_getLearningRate_10 (nativeObj);
  122. return retVal;
  123. #else
  124. return -1;
  125. #endif
  126. }
  127. //
  128. // C++: float cv::ml::LogisticRegression::predict(Mat samples, Mat& results = Mat(), int flags = 0)
  129. //
  130. //javadoc: LogisticRegression::predict(samples, results, flags)
  131. public override float predict (Mat samples, Mat results, int flags)
  132. {
  133. ThrowIfDisposed ();
  134. if (samples != null)
  135. samples.ThrowIfDisposed ();
  136. if (results != null)
  137. results.ThrowIfDisposed ();
  138. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  139. float retVal = ml_LogisticRegression_predict_10 (nativeObj, samples.nativeObj, results.nativeObj, flags);
  140. return retVal;
  141. #else
  142. return -1;
  143. #endif
  144. }
  145. //javadoc: LogisticRegression::predict(samples, results)
  146. public override float predict (Mat samples, Mat results)
  147. {
  148. ThrowIfDisposed ();
  149. if (samples != null)
  150. samples.ThrowIfDisposed ();
  151. if (results != null)
  152. results.ThrowIfDisposed ();
  153. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  154. float retVal = ml_LogisticRegression_predict_11 (nativeObj, samples.nativeObj, results.nativeObj);
  155. return retVal;
  156. #else
  157. return -1;
  158. #endif
  159. }
  160. //javadoc: LogisticRegression::predict(samples)
  161. public override float predict (Mat samples)
  162. {
  163. ThrowIfDisposed ();
  164. if (samples != null)
  165. samples.ThrowIfDisposed ();
  166. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  167. float retVal = ml_LogisticRegression_predict_12 (nativeObj, samples.nativeObj);
  168. return retVal;
  169. #else
  170. return -1;
  171. #endif
  172. }
  173. //
  174. // C++: int cv::ml::LogisticRegression::getIterations()
  175. //
  176. //javadoc: LogisticRegression::getIterations()
  177. public int getIterations ()
  178. {
  179. ThrowIfDisposed ();
  180. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  181. int retVal = ml_LogisticRegression_getIterations_10 (nativeObj);
  182. return retVal;
  183. #else
  184. return -1;
  185. #endif
  186. }
  187. //
  188. // C++: int cv::ml::LogisticRegression::getMiniBatchSize()
  189. //
  190. //javadoc: LogisticRegression::getMiniBatchSize()
  191. public int getMiniBatchSize ()
  192. {
  193. ThrowIfDisposed ();
  194. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  195. int retVal = ml_LogisticRegression_getMiniBatchSize_10 (nativeObj);
  196. return retVal;
  197. #else
  198. return -1;
  199. #endif
  200. }
  201. //
  202. // C++: int cv::ml::LogisticRegression::getRegularization()
  203. //
  204. //javadoc: LogisticRegression::getRegularization()
  205. public int getRegularization ()
  206. {
  207. ThrowIfDisposed ();
  208. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  209. int retVal = ml_LogisticRegression_getRegularization_10 (nativeObj);
  210. return retVal;
  211. #else
  212. return -1;
  213. #endif
  214. }
  215. //
  216. // C++: int cv::ml::LogisticRegression::getTrainMethod()
  217. //
  218. //javadoc: LogisticRegression::getTrainMethod()
  219. public int getTrainMethod ()
  220. {
  221. ThrowIfDisposed ();
  222. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  223. int retVal = ml_LogisticRegression_getTrainMethod_10 (nativeObj);
  224. return retVal;
  225. #else
  226. return -1;
  227. #endif
  228. }
  229. //
  230. // C++: void cv::ml::LogisticRegression::setIterations(int val)
  231. //
  232. //javadoc: LogisticRegression::setIterations(val)
  233. public void setIterations (int val)
  234. {
  235. ThrowIfDisposed ();
  236. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  237. ml_LogisticRegression_setIterations_10 (nativeObj, val);
  238. return;
  239. #else
  240. return;
  241. #endif
  242. }
  243. //
  244. // C++: void cv::ml::LogisticRegression::setLearningRate(double val)
  245. //
  246. //javadoc: LogisticRegression::setLearningRate(val)
  247. public void setLearningRate (double val)
  248. {
  249. ThrowIfDisposed ();
  250. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  251. ml_LogisticRegression_setLearningRate_10 (nativeObj, val);
  252. return;
  253. #else
  254. return;
  255. #endif
  256. }
  257. //
  258. // C++: void cv::ml::LogisticRegression::setMiniBatchSize(int val)
  259. //
  260. //javadoc: LogisticRegression::setMiniBatchSize(val)
  261. public void setMiniBatchSize (int val)
  262. {
  263. ThrowIfDisposed ();
  264. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  265. ml_LogisticRegression_setMiniBatchSize_10 (nativeObj, val);
  266. return;
  267. #else
  268. return;
  269. #endif
  270. }
  271. //
  272. // C++: void cv::ml::LogisticRegression::setRegularization(int val)
  273. //
  274. //javadoc: LogisticRegression::setRegularization(val)
  275. public void setRegularization (int val)
  276. {
  277. ThrowIfDisposed ();
  278. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  279. ml_LogisticRegression_setRegularization_10 (nativeObj, val);
  280. return;
  281. #else
  282. return;
  283. #endif
  284. }
  285. //
  286. // C++: void cv::ml::LogisticRegression::setTermCriteria(TermCriteria val)
  287. //
  288. //javadoc: LogisticRegression::setTermCriteria(val)
  289. public void setTermCriteria (TermCriteria val)
  290. {
  291. ThrowIfDisposed ();
  292. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  293. ml_LogisticRegression_setTermCriteria_10 (nativeObj, val.type, val.maxCount, val.epsilon);
  294. return;
  295. #else
  296. return;
  297. #endif
  298. }
  299. //
  300. // C++: void cv::ml::LogisticRegression::setTrainMethod(int val)
  301. //
  302. //javadoc: LogisticRegression::setTrainMethod(val)
  303. public void setTrainMethod (int val)
  304. {
  305. ThrowIfDisposed ();
  306. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  307. ml_LogisticRegression_setTrainMethod_10 (nativeObj, val);
  308. return;
  309. #else
  310. return;
  311. #endif
  312. }
  313. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  314. const string LIBNAME = "__Internal";
  315. #else
  316. const string LIBNAME = "opencvforunity";
  317. #endif
  318. // C++: Mat cv::ml::LogisticRegression::get_learnt_thetas()
  319. [DllImport (LIBNAME)]
  320. private static extern IntPtr ml_LogisticRegression_get_1learnt_1thetas_10 (IntPtr nativeObj);
  321. // C++: static Ptr_LogisticRegression cv::ml::LogisticRegression::create()
  322. [DllImport (LIBNAME)]
  323. private static extern IntPtr ml_LogisticRegression_create_10 ();
  324. // C++: static Ptr_LogisticRegression cv::ml::LogisticRegression::load(String filepath, String nodeName = String())
  325. [DllImport (LIBNAME)]
  326. private static extern IntPtr ml_LogisticRegression_load_10 (string filepath, string nodeName);
  327. [DllImport (LIBNAME)]
  328. private static extern IntPtr ml_LogisticRegression_load_11 (string filepath);
  329. // C++: TermCriteria cv::ml::LogisticRegression::getTermCriteria()
  330. [DllImport (LIBNAME)]
  331. private static extern void ml_LogisticRegression_getTermCriteria_10 (IntPtr nativeObj, double[] retVal);
  332. // C++: double cv::ml::LogisticRegression::getLearningRate()
  333. [DllImport (LIBNAME)]
  334. private static extern double ml_LogisticRegression_getLearningRate_10 (IntPtr nativeObj);
  335. // C++: float cv::ml::LogisticRegression::predict(Mat samples, Mat& results = Mat(), int flags = 0)
  336. [DllImport (LIBNAME)]
  337. private static extern float ml_LogisticRegression_predict_10 (IntPtr nativeObj, IntPtr samples_nativeObj, IntPtr results_nativeObj, int flags);
  338. [DllImport (LIBNAME)]
  339. private static extern float ml_LogisticRegression_predict_11 (IntPtr nativeObj, IntPtr samples_nativeObj, IntPtr results_nativeObj);
  340. [DllImport (LIBNAME)]
  341. private static extern float ml_LogisticRegression_predict_12 (IntPtr nativeObj, IntPtr samples_nativeObj);
  342. // C++: int cv::ml::LogisticRegression::getIterations()
  343. [DllImport (LIBNAME)]
  344. private static extern int ml_LogisticRegression_getIterations_10 (IntPtr nativeObj);
  345. // C++: int cv::ml::LogisticRegression::getMiniBatchSize()
  346. [DllImport (LIBNAME)]
  347. private static extern int ml_LogisticRegression_getMiniBatchSize_10 (IntPtr nativeObj);
  348. // C++: int cv::ml::LogisticRegression::getRegularization()
  349. [DllImport (LIBNAME)]
  350. private static extern int ml_LogisticRegression_getRegularization_10 (IntPtr nativeObj);
  351. // C++: int cv::ml::LogisticRegression::getTrainMethod()
  352. [DllImport (LIBNAME)]
  353. private static extern int ml_LogisticRegression_getTrainMethod_10 (IntPtr nativeObj);
  354. // C++: void cv::ml::LogisticRegression::setIterations(int val)
  355. [DllImport (LIBNAME)]
  356. private static extern void ml_LogisticRegression_setIterations_10 (IntPtr nativeObj, int val);
  357. // C++: void cv::ml::LogisticRegression::setLearningRate(double val)
  358. [DllImport (LIBNAME)]
  359. private static extern void ml_LogisticRegression_setLearningRate_10 (IntPtr nativeObj, double val);
  360. // C++: void cv::ml::LogisticRegression::setMiniBatchSize(int val)
  361. [DllImport (LIBNAME)]
  362. private static extern void ml_LogisticRegression_setMiniBatchSize_10 (IntPtr nativeObj, int val);
  363. // C++: void cv::ml::LogisticRegression::setRegularization(int val)
  364. [DllImport (LIBNAME)]
  365. private static extern void ml_LogisticRegression_setRegularization_10 (IntPtr nativeObj, int val);
  366. // C++: void cv::ml::LogisticRegression::setTermCriteria(TermCriteria val)
  367. [DllImport (LIBNAME)]
  368. private static extern void ml_LogisticRegression_setTermCriteria_10 (IntPtr nativeObj, int val_type, int val_maxCount, double val_epsilon);
  369. // C++: void cv::ml::LogisticRegression::setTrainMethod(int val)
  370. [DllImport (LIBNAME)]
  371. private static extern void ml_LogisticRegression_setTrainMethod_10 (IntPtr nativeObj, int val);
  372. // native support for java finalize()
  373. [DllImport (LIBNAME)]
  374. private static extern void ml_LogisticRegression_delete (IntPtr nativeObj);
  375. }
  376. }