2009-02-18 00:10:57 +01:00
|
|
|
/**************************************************************************************************
|
|
|
|
* LibNeural++ v.0.2 - All-purpose library for managing neural networks *
|
|
|
|
* Copyright (C) 2009, BlackLight *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify it under the terms of the *
|
|
|
|
* GNU General Public License as published by the Free Software Foundation, either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. This program is distributed in the hope *
|
|
|
|
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
|
|
|
|
* more details. You should have received a copy of the GNU General Public License along with *
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
**************************************************************************************************/
|
|
|
|
|
2009-08-07 15:55:59 +02:00
|
|
|
#include "neural++.hpp"
|
2009-02-18 00:10:57 +01:00
|
|
|
|
2009-08-09 10:24:52 +02:00
|
|
|
namespace neuralpp {
|
|
|
|
|
2009-08-08 18:05:02 +02:00
|
|
|
Neuron::Neuron (double (*a)(double), double (*d)(double)) {
|
2009-02-18 00:10:57 +01:00
|
|
|
actv_f=a;
|
|
|
|
deriv=d;
|
|
|
|
}
|
|
|
|
|
2009-08-08 18:05:02 +02:00
|
|
|
Neuron::Neuron (vector< Synapsis > i, vector< Synapsis > o, double (*a)(double), double(*d)(double)) {
|
2009-02-18 00:10:57 +01:00
|
|
|
in=i;
|
|
|
|
out=o;
|
|
|
|
|
|
|
|
actv_f=a;
|
|
|
|
deriv=d;
|
|
|
|
}
|
|
|
|
|
|
|
|
Synapsis& Neuron::synIn (size_t i) { return in[i]; }
|
|
|
|
|
|
|
|
Synapsis& Neuron::synOut (size_t i) { return out[i]; }
|
|
|
|
|
|
|
|
void Neuron::push_in (Synapsis& s) { in.push_back(s); }
|
|
|
|
|
|
|
|
void Neuron::push_out (Synapsis& s) { out.push_back(s); }
|
|
|
|
|
2009-08-08 18:05:02 +02:00
|
|
|
void Neuron::setProp (double val) { prop_val=val; }
|
2009-02-18 00:10:57 +01:00
|
|
|
|
2009-08-08 18:05:02 +02:00
|
|
|
void Neuron::setActv (double val) { actv_val=actv_f(val); }
|
2009-02-18 00:10:57 +01:00
|
|
|
|
|
|
|
size_t Neuron::nIn() { return in.size(); }
|
|
|
|
|
|
|
|
size_t Neuron::nOut() { return out.size(); }
|
|
|
|
|
2009-08-08 18:05:02 +02:00
|
|
|
double Neuron::getProp() { return prop_val; }
|
2009-02-18 00:10:57 +01:00
|
|
|
|
2009-08-08 18:05:02 +02:00
|
|
|
double Neuron::getActv() { return actv_val; }
|
2009-02-18 00:10:57 +01:00
|
|
|
|
2009-08-08 18:05:02 +02:00
|
|
|
double Neuron::propagate() {
|
|
|
|
double aux=0;
|
2009-02-18 00:10:57 +01:00
|
|
|
|
|
|
|
for (size_t i=0; i<nIn(); i++)
|
|
|
|
aux += (in[i].getWeight() * in[i].getIn()->actv_val);
|
|
|
|
return aux;
|
|
|
|
}
|
2009-08-09 10:24:52 +02:00
|
|
|
}
|
2009-02-18 00:10:57 +01:00
|
|
|
|