neuralpp/src/synapsis.cpp

79 lines
2.2 KiB
C++
Raw Normal View History

2009-02-18 00:10:57 +01:00
/**************************************************************************************************
* LibNeural++ v.0.4 - All-purpose library for managing neural networks *
2009-02-18 00:10:57 +01:00
* 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/>. *
**************************************************************************************************/
#include <cstdlib>
#include "neural++.hpp"
2009-02-18 00:10:57 +01:00
2009-08-09 11:17:39 +02:00
namespace neuralpp {
2009-08-15 02:59:09 +02:00
Synapsis::Synapsis(Neuron * i, Neuron * o, double (*a) (double)) {
2009-08-09 11:17:39 +02:00
srand((unsigned) time(NULL));
delta = 0;
prev_delta = 0;
weight = RAND;
in = i;
out = o;
actv_f = a;
}
Synapsis::Synapsis(Neuron * i, Neuron * o,
2009-08-15 02:59:09 +02:00
double w, double (*a) (double)) {
2009-08-09 11:17:39 +02:00
delta = 0;
prev_delta = 0;
weight = w;
in = i;
out = o;
actv_f = a;
}
Neuron *Synapsis::getIn() const {
2009-08-09 11:17:39 +02:00
return in;
}
Neuron *Synapsis::getOut() const {
2009-08-09 11:17:39 +02:00
return out;
}
double Synapsis::getWeight() const {
2009-08-09 11:17:39 +02:00
return weight;
}
double Synapsis::getDelta() const {
2009-08-09 11:17:39 +02:00
return delta;
}
double Synapsis::getPrevDelta() const {
2009-08-09 11:17:39 +02:00
return prev_delta;
}
2009-08-10 18:06:52 +02:00
void Synapsis::setWeight(double w) throw(InvalidSynapticalWeightException) {
2009-08-09 19:53:21 +02:00
if (weight > 1.0)
2009-08-10 18:06:52 +02:00
throw InvalidSynapticalWeightException();
weight = w;
2009-08-09 11:17:39 +02:00
}
2009-08-10 18:06:52 +02:00
void Synapsis::setDelta(double d) throw(InvalidSynapticalWeightException) {
2009-08-09 11:17:39 +02:00
prev_delta = delta;
delta = d;
}
double Synapsis::momentum(int N, int x) const {
2009-08-09 11:17:39 +02:00
return (BETA0 * N) / (20 * x + N);
}
2009-08-09 10:24:52 +02:00
}
2009-02-18 00:10:57 +01:00