10 gaussian membership function
11 @tparam number x input value for which to compute membership value.
12 @tparam number sigma is the standard deviation.
13 @tparam number c is the mean.
14 @treturn number membership value.
17 static int liba_mf_gauss_(lua_State
*L
, int arg
)
19 a_float
const x
= (a_float
)luaL_checknumber(L
, arg
+ 1);
20 a_float
const sigma
= (a_float
)luaL_checknumber(L
, arg
+ 2);
21 a_float
const c
= (a_float
)luaL_checknumber(L
, arg
+ 3);
22 lua_pushnumber(L
, (lua_Number
)a_mf_gauss(x
, sigma
, c
));
25 static int liba_mf_gauss(lua_State
*L
)
27 return liba_mf_gauss_(L
, 0);
31 product of two sigmoidal membership functions
32 @tparam number x input value for which to compute membership value.
33 @tparam number sigma1 is the standard deviation of the left gaussian function.
34 @tparam number c1 is the mean of the left gaussian function.
35 @tparam number sigma2 is the standard deviation of the right gaussian function.
36 @tparam number c2 is the mean of the right gaussian function.
37 @treturn number membership value.
40 static int liba_mf_gauss2_(lua_State
*L
, int arg
)
42 a_float
const x
= (a_float
)luaL_checknumber(L
, arg
+ 1);
43 a_float
const sigma1
= (a_float
)luaL_checknumber(L
, arg
+ 2);
44 a_float
const c1
= (a_float
)luaL_checknumber(L
, arg
+ 3);
45 a_float
const sigma2
= (a_float
)luaL_checknumber(L
, arg
+ 4);
46 a_float
const c2
= (a_float
)luaL_checknumber(L
, arg
+ 4);
47 lua_pushnumber(L
, (lua_Number
)a_mf_gauss2(x
, sigma1
, c1
, sigma2
, c2
));
50 static int liba_mf_gauss2(lua_State
*L
)
52 return liba_mf_gauss2_(L
, 0);
56 generalized bell-shaped membership function
57 @tparam number x input value for which to compute membership value.
58 @tparam number a defines the width of the membership function, where a larger value creates a wider membership function.
59 @tparam number b defines the shape of the curve on either side of the central plateau, where a larger value creates a more steep transition.
60 @tparam number c defines the center of the membership function.
61 @treturn number membership value.
64 static int liba_mf_gbell_(lua_State
*L
, int arg
)
66 a_float
const x
= (a_float
)luaL_checknumber(L
, arg
+ 1);
67 a_float
const a
= (a_float
)luaL_checknumber(L
, arg
+ 2);
68 a_float
const b
= (a_float
)luaL_checknumber(L
, arg
+ 3);
69 a_float
const c
= (a_float
)luaL_checknumber(L
, arg
+ 4);
70 lua_pushnumber(L
, (lua_Number
)a_mf_gbell(x
, a
, b
, c
));
73 static int liba_mf_gbell(lua_State
*L
)
75 return liba_mf_gbell_(L
, 0);
79 sigmoidal membership function
80 @tparam number x input value for which to compute membership value.
81 @tparam number a defines the width of the transition area.
82 @tparam number c defines the center of the transition area.
83 @treturn number membership value.
86 static int liba_mf_sig_(lua_State
*L
, int arg
)
88 a_float
const x
= (a_float
)luaL_checknumber(L
, arg
+ 1);
89 a_float
const a
= (a_float
)luaL_checknumber(L
, arg
+ 2);
90 a_float
const c
= (a_float
)luaL_checknumber(L
, arg
+ 3);
91 lua_pushnumber(L
, (lua_Number
)a_mf_sig(x
, a
, c
));
94 static int liba_mf_sig(lua_State
*L
)
96 return liba_mf_sig_(L
, 0);
100 difference between two sigmoidal membership functions
101 @tparam number x input value for which to compute membership value.
102 @tparam number a1 defines the width of the first transition area.
103 @tparam number c1 defines the center of the first transition area.
104 @tparam number a2 defines the width of the second transition area.
105 @tparam number c2 defines the center of the second transition area.
106 @treturn number membership value.
109 static int liba_mf_dsig_(lua_State
*L
, int arg
)
111 a_float
const x
= (a_float
)luaL_checknumber(L
, arg
+ 1);
112 a_float
const a1
= (a_float
)luaL_checknumber(L
, arg
+ 2);
113 a_float
const c1
= (a_float
)luaL_checknumber(L
, arg
+ 3);
114 a_float
const a2
= (a_float
)luaL_checknumber(L
, arg
+ 4);
115 a_float
const c2
= (a_float
)luaL_checknumber(L
, arg
+ 4);
116 lua_pushnumber(L
, (lua_Number
)a_mf_dsig(x
, a1
, c1
, a2
, c2
));
119 static int liba_mf_dsig(lua_State
*L
)
121 return liba_mf_dsig_(L
, 0);
125 product of two sigmoidal membership functions
126 @tparam number x input value for which to compute membership value.
127 @tparam number a1 defines the width of the first transition area.
128 @tparam number c1 defines the center of the first transition area.
129 @tparam number a2 defines the width of the second transition area.
130 @tparam number c2 defines the center of the second transition area.
131 @treturn number membership value.
134 static int liba_mf_psig_(lua_State
*L
, int arg
)
136 a_float
const x
= (a_float
)luaL_checknumber(L
, arg
+ 1);
137 a_float
const a1
= (a_float
)luaL_checknumber(L
, arg
+ 2);
138 a_float
const c1
= (a_float
)luaL_checknumber(L
, arg
+ 3);
139 a_float
const a2
= (a_float
)luaL_checknumber(L
, arg
+ 4);
140 a_float
const c2
= (a_float
)luaL_checknumber(L
, arg
+ 4);
141 lua_pushnumber(L
, (lua_Number
)a_mf_psig(x
, a1
, c1
, a2
, c2
));
144 static int liba_mf_psig(lua_State
*L
)
146 return liba_mf_psig_(L
, 0);
150 trapezoidal membership function
151 @tparam number x input value for which to compute membership value.
152 @tparam number a defines its left foot.
153 @tparam number b defines its left shoulder.
154 @tparam number c defines its right shoulder.
155 @tparam number d defines its right foot.
156 @treturn number membership value.
159 static int liba_mf_trap_(lua_State
*L
, int arg
)
161 a_float
const x
= (a_float
)luaL_checknumber(L
, arg
+ 1);
162 a_float
const a
= (a_float
)luaL_checknumber(L
, arg
+ 2);
163 a_float
const b
= (a_float
)luaL_checknumber(L
, arg
+ 3);
164 a_float
const c
= (a_float
)luaL_checknumber(L
, arg
+ 4);
165 a_float
const d
= (a_float
)luaL_checknumber(L
, arg
+ 4);
166 lua_pushnumber(L
, (lua_Number
)a_mf_trap(x
, a
, b
, c
, d
));
169 static int liba_mf_trap(lua_State
*L
)
171 return liba_mf_trap_(L
, 0);
175 triangular membership function
176 @tparam number x input value for which to compute membership value.
177 @tparam number a defines its left foot.
178 @tparam number b defines its peak.
179 @tparam number c defines its right foot.
180 @treturn number membership value.
183 static int liba_mf_tri_(lua_State
*L
, int arg
)
185 a_float
const x
= (a_float
)luaL_checknumber(L
, arg
+ 1);
186 a_float
const a
= (a_float
)luaL_checknumber(L
, arg
+ 2);
187 a_float
const b
= (a_float
)luaL_checknumber(L
, arg
+ 3);
188 a_float
const c
= (a_float
)luaL_checknumber(L
, arg
+ 4);
189 lua_pushnumber(L
, (lua_Number
)a_mf_tri(x
, a
, b
, c
));
192 static int liba_mf_tri(lua_State
*L
)
194 return liba_mf_tri_(L
, 0);
198 linear s-shaped saturation membership function
199 @tparam number x input value for which to compute membership value.
200 @tparam number a defines its foot.
201 @tparam number b defines its shoulder.
202 @treturn number membership value.
205 static int liba_mf_lins_(lua_State
*L
, int arg
)
207 a_float
const x
= (a_float
)luaL_checknumber(L
, arg
+ 1);
208 a_float
const a
= (a_float
)luaL_checknumber(L
, arg
+ 2);
209 a_float
const b
= (a_float
)luaL_checknumber(L
, arg
+ 3);
210 lua_pushnumber(L
, (lua_Number
)a_mf_lins(x
, a
, b
));
213 static int liba_mf_lins(lua_State
*L
)
215 return liba_mf_lins_(L
, 0);
219 linear z-shaped saturation membership function
220 @tparam number x input value for which to compute membership value.
221 @tparam number a defines its shoulder.
222 @tparam number b defines its foot.
223 @treturn number membership value.
226 static int liba_mf_linz_(lua_State
*L
, int arg
)
228 a_float
const x
= (a_float
)luaL_checknumber(L
, arg
+ 1);
229 a_float
const a
= (a_float
)luaL_checknumber(L
, arg
+ 2);
230 a_float
const b
= (a_float
)luaL_checknumber(L
, arg
+ 3);
231 lua_pushnumber(L
, (lua_Number
)a_mf_linz(x
, a
, b
));
234 static int liba_mf_linz(lua_State
*L
)
236 return liba_mf_linz_(L
, 0);
240 s-shaped membership function
241 @tparam number x input value for which to compute membership value.
242 @tparam number a defines its foot.
243 @tparam number b defines its shoulder.
244 @treturn number membership value.
247 static int liba_mf_s_(lua_State
*L
, int arg
)
249 a_float
const x
= (a_float
)luaL_checknumber(L
, arg
+ 1);
250 a_float
const a
= (a_float
)luaL_checknumber(L
, arg
+ 2);
251 a_float
const b
= (a_float
)luaL_checknumber(L
, arg
+ 3);
252 lua_pushnumber(L
, (lua_Number
)a_mf_s(x
, a
, b
));
255 static int liba_mf_s(lua_State
*L
)
257 return liba_mf_s_(L
, 0);
261 z-shaped membership function
262 @tparam number x input value for which to compute membership value.
263 @tparam number a defines its shoulder.
264 @tparam number b defines its foot.
265 @treturn number membership value.
268 static int liba_mf_z_(lua_State
*L
, int arg
)
270 a_float
const x
= (a_float
)luaL_checknumber(L
, arg
+ 1);
271 a_float
const a
= (a_float
)luaL_checknumber(L
, arg
+ 2);
272 a_float
const b
= (a_float
)luaL_checknumber(L
, arg
+ 3);
273 lua_pushnumber(L
, (lua_Number
)a_mf_z(x
, a
, b
));
276 static int liba_mf_z(lua_State
*L
)
278 return liba_mf_z_(L
, 0);
282 z-shaped membership function
283 @tparam number x input value for which to compute membership value.
284 @tparam number a defines its left foot.
285 @tparam number b defines its left shoulder.
286 @tparam number c defines its right shoulder.
287 @tparam number d defines its right foot.
288 @treturn number membership value.
291 static int liba_mf_pi_(lua_State
*L
, int arg
)
293 a_float
const x
= (a_float
)luaL_checknumber(L
, arg
+ 1);
294 a_float
const a
= (a_float
)luaL_checknumber(L
, arg
+ 2);
295 a_float
const b
= (a_float
)luaL_checknumber(L
, arg
+ 3);
296 a_float
const c
= (a_float
)luaL_checknumber(L
, arg
+ 4);
297 a_float
const d
= (a_float
)luaL_checknumber(L
, arg
+ 4);
298 lua_pushnumber(L
, (lua_Number
)a_mf_pi(x
, a
, b
, c
, d
));
301 static int liba_mf_pi(lua_State
*L
)
303 return liba_mf_pi_(L
, 0);
308 @tparam int e type for membership function
309 @tparam number x input value for which to compute membership value.
310 @tparam number ... is an array that stores parameters.
311 @treturn number membership value.
314 static int liba_mf_mf(lua_State
*L
)
316 lua_Integer
const e
= luaL_checkinteger(L
, 1);
320 return liba_mf_pi_(L
, 1);
322 return liba_mf_z_(L
, 1);
324 return liba_mf_s_(L
, 1);
326 return liba_mf_linz_(L
, 1);
328 return liba_mf_lins_(L
, 1);
330 return liba_mf_tri_(L
, 1);
332 return liba_mf_trap_(L
, 1);
334 return liba_mf_psig_(L
, 1);
336 return liba_mf_dsig_(L
, 1);
338 return liba_mf_sig_(L
, 1);
340 return liba_mf_gbell_(L
, 1);
342 return liba_mf_gauss2_(L
, 1);
344 return liba_mf_gauss_(L
, 1);
351 static int liba_mf_(lua_State
*L
)
353 lua_pushcfunction(L
, liba_mf_mf
);
355 lua_call(L
, lua_gettop(L
) - 1, 1);
359 int luaopen_liba_mf(lua_State
*L
)
362 enumeration for membership function
364 @field GAUSS gaussian membership function
365 @field GAUSS2 gaussian combination membership function
366 @field GBELL generalized bell-shaped membership function
367 @field SIG sigmoidal membership function
368 @field DSIG difference between two sigmoidal membership functions
369 @field PSIG product of two sigmoidal membership functions
370 @field TRAP trapezoidal membership function
371 @field TRI triangular membership function
372 @field LINS linear s-shaped saturation membership function
373 @field LINZ linear z-shaped saturation membership function
374 @field S s-shaped membership function
375 @field Z z-shaped membership function
376 @field PI pi-shaped membership function
379 static lua_int
const enums
[] = {
381 {"GAUSS", A_MF_GAUSS
},
382 {"GAUSS2", A_MF_GAUSS2
},
383 {"GBELL", A_MF_GBELL
},
395 static lua_fun
const funcs
[] = {
396 {"gauss", liba_mf_gauss
},
397 {"gauss2", liba_mf_gauss2
},
398 {"gbell", liba_mf_gbell
},
399 {"sig", liba_mf_sig
},
400 {"dsig", liba_mf_dsig
},
401 {"psig", liba_mf_psig
},
402 {"trap", liba_mf_trap
},
403 {"tri", liba_mf_tri
},
404 {"lins", liba_mf_lins
},
405 {"linz", liba_mf_linz
},
411 lua_createtable(L
, 0, A_LEN(enums
) + A_LEN(funcs
));
412 lua_int_reg(L
, -1, enums
, A_LEN(enums
));
413 lua_fun_reg(L
, -1, funcs
, A_LEN(funcs
));
414 lua_createtable(L
, 0, 1);
415 lua_fun_set(L
, -1, "__call", liba_mf_
);
416 lua_setmetatable(L
, -2);