sigmoid.c
Go to the documentation of this file.
1 /*****************************************************************
2 /* sigmoid function for neural network simulator
3 /* 1989Mar Matsui T., ETL
4 /* 1990Apr sigmoidx is added,
5 /* load with :ld-option "-lm" to link tanh
6 /****************************************************************/
7 
8 #include "eus.h"
9 
10 static pointer SIGMOID(ctx,n,argv)
11 context *ctx;
12 int n;
13 pointer argv[];
14 { float x;
15  double exp();
16  x=fltval(argv[0]);
17  return(makeflt(1.0/(1.0+exp(-x))));}
18 
19 pointer SIGMOIDX(ctx,n,argv)
20 context *ctx;
21 int n;
22 pointer argv[];
23 { double x,u,s,th1,th2;
24  double exp(), tanh();
25  x=ckfltval(argv[0]); u=ckfltval(argv[1]);
26  th1=ckfltval(argv[2]); th2=ckfltval(argv[3]);
27  s=0.5*(1.0+tanh(x/u));
28  if (s<th1) return(makeflt(th1));
29  else if (s>th2) return(makeflt(th2));
30  else return(makeflt(s));}
31 
33 context *ctx;
34 register int n;
35 register pointer argv[];
36 { pointer v=argv[0];
37  float x=ckfltval(argv[1]), *f;
38  ckarg(2);
39  if (!isfltvector(v)) error(E_FLOATVECTOR);
40  f=v->c.fvec.fv;
41  n=vecsize(v);
42  while (--n>=0) f[n]+=x;
43  return(v);}
44 
45 pointer sigmoid(ctx,n,argv)
46 context *ctx;
47 int n;
48 pointer argv[];
49 { pointer mod=argv[0];
50  defun(ctx,"SIGMOID",mod,SIGMOID,NULL);
51  defun(ctx,"SIGMOIDX",mod,SIGMOIDX,NULL);
52  defun(ctx,"OFFSET-VECTOR",mod,OFFSET_VECTOR,NULL);}
53 
E_FLOATVECTOR
@ E_FLOATVECTOR
Definition: eus.h:981
defun
defun("ADR_TO_STRING", mod, ADR_TO_STRING)
context
Definition: eus.h:524
s
short s
Definition: structsize.c:2
ckfltval
float ckfltval()
sigmoid
pointer sigmoid(context *ctx, int n, argv)
Definition: sigmoid.c:45
eus.h
NULL
#define NULL
Definition: transargv.c:8
fltval
float fltval()
makeflt
pointer makeflt()
error
pointer error(enum errorcode ec,...) pointer error(va_alist) va_dcl
Definition: eus.c:297
f
f
cell
Definition: eus.h:381
SIGMOID
static pointer SIGMOID(context *ctx, int n, argv)
Definition: sigmoid.c:10
SIGMOIDX
pointer SIGMOIDX(context *ctx, int n, argv)
Definition: sigmoid.c:19
n
GLfloat n[6][3]
Definition: cube.c:15
v
GLfloat v[8][3]
Definition: cube.c:21
ckarg
ckarg(2)
OFFSET_VECTOR
pointer OFFSET_VECTOR(context *ctx, int n, argv)
Definition: sigmoid.c:32


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Jun 15 2023 02:06:43