From 8ce7df1eb4174dcca246c6800e26144cb86056c5 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 10 Oct 2016 20:37:17 +0100 Subject: [Minor] Add method to get MSE for ANN --- src/lua/lua_fann.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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} @@ -492,6 +494,30 @@ lua_fann_get_outputs (lua_State *L) #endif } +/*** + * @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' -- cgit v1.2.3