aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-10 20:37:17 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-10 20:37:17 +0100
commit8ce7df1eb4174dcca246c6800e26144cb86056c5 (patch)
treed18302ba2d000ec0ed9a272a29db34e842267e6f
parentef9839e676596c71b40c3c0dcf77a63111d8ea49 (diff)
downloadrspamd-8ce7df1eb4174dcca246c6800e26144cb86056c5.tar.gz
rspamd-8ce7df1eb4174dcca246c6800e26144cb86056c5.zip
[Minor] Add method to get MSE for ANN
-rw-r--r--src/lua/lua_fann.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/lua/lua_fann.c b/src/lua/lua_fann.c
index d1f187510..d6dd921e7 100644
--- a/src/lua/lua_fann.c
+++ b/src/lua/lua_fann.c
@@ -45,6 +45,7 @@ LUA_FUNCTION_DEF (fann, save);
LUA_FUNCTION_DEF (fann, data);
LUA_FUNCTION_DEF (fann, get_inputs);
LUA_FUNCTION_DEF (fann, get_outputs);
+LUA_FUNCTION_DEF (fann, get_mse);
LUA_FUNCTION_DEF (fann, dtor);
static const struct luaL_reg fannlib_f[] = {
@@ -63,6 +64,7 @@ static const struct luaL_reg fannlib_m[] = {
LUA_INTERFACE_DEF (fann, data),
LUA_INTERFACE_DEF (fann, get_inputs),
LUA_INTERFACE_DEF (fann, get_outputs),
+ LUA_INTERFACE_DEF (fann, get_mse),
{"__gc", lua_fann_dtor},
{"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
@@ -493,6 +495,30 @@ lua_fann_get_outputs (lua_State *L)
}
/***
+ * @method rspamd_fann:get_mse()
+ * Returns mean square error for ANN
+ * @return {number} MSE value
+ */
+static gint
+lua_fann_get_mse (lua_State *L)
+{
+#ifndef WITH_FANN
+ return 0;
+#else
+ struct fann *f = rspamd_lua_check_fann (L, 1);
+
+ if (f != NULL) {
+ lua_pushnumber (L, fann_get_MSE (f));
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ return 1;
+#endif
+}
+
+/***
* @method rspamd_fann:save(fname)
* Save fann to file named 'fname'
* @param {string} fname filename to save fann into