#include #include #include #define FROM 0.0 #define TO 100.0 #define STEP 0.01 #define sigmoid_slope -1.0 double INPUT=0.1; double INITIAL_VALUE=10.0; double INIT_SELFWGT=1.0; typedef struct { double output; double thres; double state; double old_state; double inp_wgt; double self_wgt; } neuron; void initialize_neuron(neuron *a) { a->output = INITIAL_VALUE; a->state = INITIAL_VALUE; a->thres = 0.0; a->inp_wgt = 1.0; a->self_wgt = INIT_SELFWGT; } double output_f(double value) { /* return 1.0 / ( 1.0 + exp(sigmoid_slope * value) ); */ return value; } void update_neuron(neuron *a, double input) { a->state += (- a->output + a->inp_wgt * input + a->old_state * a->self_wgt - a->thres) * STEP; a->output = output_f(a->state); a->old_state = a->output; } int main(int argc, char **argv) { neuron a; double t; if ( argc != 4 ) { fprintf(stderr,"Usage: %s input initial self_wgt\n",argv[0]); exit( 0 ); } INPUT=atof(argv[1]); INITIAL_VALUE=atof(argv[2]); INIT_SELFWGT=atof(argv[3]); fprintf(stderr,"INPUT=%f,INITIAL_VALUE=%f,INIT_SELFWGT=%f\n", INPUT,INITIAL_VALUE,INIT_SELFWGT); initialize_neuron(&a); t = FROM; while ( t <= TO ){ update_neuron(&a, INPUT); printf("%f %f\n", t, a.output); t += STEP; } return EXIT_SUCCESS; }