source: cpp/frams/neuro/impl/neuroimpl-simple.cpp @ 138

Last change on this file since 138 was 121, checked in by sz, 11 years ago

updated file headers and makefiles

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 2002-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#include "neuroimpl-simple.h"
6
7#define NEURO_MAX 10.0
8#define OVERLOAD 0.1
9#define MUSCLESPEED   0.08
10#define MUSCLEACC   0.01
11
12int NI_StdNeuron::lateinit()
13{
14#ifdef MODEL_V1_COMPATIBLE
15if (inertia<0) inertia=neuro->inertia;
16if (force<0) force=neuro->force;
17if (sigmo>1e9) sigmo=neuro->sigmo;
18#endif
19istate=newstate+neuro->state; // neuro->state -> random initialization
20calcOutput();
21neuro->state=newstate;
22return 1;
23}
24
25void NI_StdNeuron::calcInternalState()
26{
27double sum=getWeightedInputSum();
28velocity=force*(sum-istate)+inertia*velocity;
29istate+=velocity;
30if (istate>NEURO_MAX) istate=NEURO_MAX;
31else if (istate<-NEURO_MAX) istate=-NEURO_MAX;
32}
33
34void NI_StdNeuron::go()
35{
36calcInternalState();
37calcOutput();
38}
39
40void NI_StdNeuron::calcOutput()
41{
42double s=istate * sigmo;
43if (s<-30.0) setState(-1);
44else setState(2.0/(1.0+exp(-s))-1.0); // -1...1
45}
46
47void NI_StdUNeuron::calcOutput()
48{
49double s=istate * sigmo;
50if (s<-30.0) setState(0);
51else setState(1.0/(1.0+exp(-s))); // 0...1
52}
Note: See TracBrowser for help on using the repository browser.