sigmoid.c
Go to the documentation of this file.
00001 /*****************************************************************
00002 /* sigmoid function for neural network simulator
00003 /* 1989Mar      Matsui T., ETL
00004 /* 1990Apr      sigmoidx is added,
00005 /*              load with :ld-option "-lm" to link tanh
00006 /****************************************************************/
00007 
00008 #include "eus.h"
00009 
00010 static pointer SIGMOID(ctx,n,argv)
00011 context *ctx;
00012 int n;
00013 pointer argv[];
00014 { float x;
00015   double exp();
00016   x=fltval(argv[0]);
00017   return(makeflt(1.0/(1.0+exp(-x))));}
00018 
00019 pointer SIGMOIDX(ctx,n,argv)
00020 context *ctx;
00021 int n;
00022 pointer argv[];
00023 { double x,u,s,th1,th2;
00024   double exp(), tanh();
00025   x=ckfltval(argv[0]); u=ckfltval(argv[1]);
00026   th1=ckfltval(argv[2]); th2=ckfltval(argv[3]);
00027   s=0.5*(1.0+tanh(x/u));
00028   if (s<th1) return(makeflt(th1));
00029   else if (s>th2) return(makeflt(th2));
00030   else return(makeflt(s));}
00031 
00032 pointer OFFSET_VECTOR(ctx,n,argv)
00033 context *ctx;
00034 register int n;
00035 register pointer argv[];
00036 { pointer v=argv[0];
00037   float x=ckfltval(argv[1]), *f;
00038   ckarg(2);
00039   if (!isfltvector(v)) error(E_FLOATVECTOR);
00040   f=v->c.fvec.fv;
00041   n=vecsize(v);
00042   while (--n>=0) f[n]+=x;
00043   return(v);}
00044 
00045 pointer sigmoid(ctx,n,argv)
00046 context *ctx;
00047 int n;
00048 pointer argv[];
00049 { pointer mod=argv[0];
00050   defun(ctx,"SIGMOID",mod,SIGMOID,NULL);
00051   defun(ctx,"SIGMOIDX",mod,SIGMOIDX,NULL);
00052   defun(ctx,"OFFSET-VECTOR",mod,OFFSET_VECTOR,NULL);}
00053 


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Jun 6 2019 18:05:53