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

Last change on this file since 741 was 726, checked in by Maciej Komosinski, 7 years ago
  • Changed Model::singleStepBuild() to Model::addFromString() to create model elements; the latter requires explicit indication of element type (P/J/N/C)
  • Removed old compatibility source (#ifdef MODEL_V1_COMPATIBLE) from f1->f0 converter and neuron definitions
  • Property svn:eol-style set to native
File size: 1012 bytes
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
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{
14istate=newstate+neuro->state; // neuro->state -> random initialization
15calcOutput();
16neuro->state=newstate;
17return 1;
18}
19
20void NI_StdNeuron::calcInternalState()
21{
22double sum=getWeightedInputSum();
23velocity=force*(sum-istate)+inertia*velocity;
24istate+=velocity;
25if (istate>NEURO_MAX) istate=NEURO_MAX;
26else if (istate<-NEURO_MAX) istate=-NEURO_MAX;
27}
28
29void NI_StdNeuron::go()
30{
31calcInternalState();
32calcOutput();
33}
34
35void NI_StdNeuron::calcOutput()
36{
37double s=istate * sigmo;
38if (s<-30.0) setState(-1);
39else setState(2.0/(1.0+exp(-s))-1.0); // -1...1
40}
41
42void NI_StdUNeuron::calcOutput()
43{
44double s=istate * sigmo;
45if (s<-30.0) setState(0);
46else setState(1.0/(1.0+exp(-s))); // 0...1
47}
Note: See TracBrowser for help on using the repository browser.