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

Last change on this file since 1229 was 907, checked in by Maciej Komosinski, 5 years ago

Code formatting

  • Property svn:eol-style set to native
File size: 1.0 KB
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{
14        istate = newstate + neuro->state; // neuro->state -> random initialization
15        calcOutput();
16        neuro->state = newstate;
17        return 1;
18}
19
20void NI_StdNeuron::calcInternalState()
21{
22        double sum = getWeightedInputSum();
23        velocity = force * (sum - istate) + inertia * velocity;
24        istate += velocity;
25        if (istate > NEURO_MAX) istate = NEURO_MAX;
26        else if (istate < -NEURO_MAX) istate = -NEURO_MAX;
27}
28
29void NI_StdNeuron::go()
30{
31        calcInternalState();
32        calcOutput();
33}
34
35void NI_StdNeuron::calcOutput()
36{
37        double s = istate * sigmo;
38        if (s < -30.0) setState(-1);
39        else setState(2.0 / (1.0 + exp(-s)) - 1.0); // -1...1
40}
41
42void NI_StdUNeuron::calcOutput()
43{
44        double s = istate * sigmo;
45        if (s < -30.0) setState(0);
46        else setState(1.0 / (1.0 + exp(-s))); // 0...1
47}
Note: See TracBrowser for help on using the repository browser.