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

Last change on this file since 869 was 791, checked in by Maciej Komosinski, 7 years ago

Code formatting

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