NeuronLinear.cpp 1.21 KB
Newer Older
1 2 3 4
//
// Created by fluffymoo on 11.6.18.
//

5
#include <boost/serialization/base_object.hpp>
6
#include "NeuronLinear.h"
7 8 9

NeuronLinear::NeuronLinear(double a, double b) {

10
    this->n_activation_function_parameters = 2;
11 12 13 14 15
    this->activation_function_parameters = new double[2];

    this->activation_function_parameters[0] = a;
    this->activation_function_parameters[1] = b;

16 17 18
    this->edges_in = new std::vector<Connection*>(0);
    this->edges_out = new std::vector<Connection*>(0);

19 20
}

21
void NeuronLinear::activate( ) {
22

23 24 25 26 27
    double x = this->potential;
    double a = this->activation_function_parameters[0];
    double b = this->activation_function_parameters[1];

    this->state = b * x + a;
28 29 30 31 32 33 34 35

}

double NeuronLinear::activation_function_get_partial_derivative(int param_idx) {

    if(param_idx == 0){
        return 1.0;
    }
36 37 38 39 40 41
    else if(param_idx == 1){
        double x = this->potential;
        return x;
    }

    return 0.0;
42 43
}

44 45 46 47
double NeuronLinear::activation_function_get_derivative( ) {
    double b = this->activation_function_parameters[1];

    return b;
48 49 50 51 52 53
}

//template<class Archive>
//void NeuronLinear::serialize(Archive & ar, const unsigned int version) {
//    ar & boost::serialization::base_object<Neuron>(*this);
//}