Skip to content
Snippets Groups Projects
ConnectionWeight.cpp 1.18 KiB
Newer Older
  • Learn to ignore specific revisions
  • /**
     * DESCRIPTION OF THE FILE
     *
     * @author Michal Kravčenko
     * @date 14.6.18 -
     */
    
    #include "ConnectionWeight.h"
    
    ConnectionWeight::ConnectionWeight() {
    
    
    }
    
    
    ConnectionWeight::ConnectionWeight(int param_count, std::function<double(double **, int)> *f) {
    
        this->param_ptrs = new double*[param_count];
        this->n_params = param_count;
    
        this->weight_function = f;
    }
    
    ConnectionWeight::~ConnectionWeight() {
        if(this->param_ptrs){
            delete [] this->param_ptrs;
            this->param_ptrs = nullptr;
        }
    }
    
    void ConnectionWeight::adjust_weights(double *values) {
        for(int i = 0; i < this->n_params; ++i){
            (*this->param_ptrs[i]) += values[i];
        }
    }
    
    void ConnectionWeight::set_weights(double *values) {
        for(int i = 0; i < this->n_params; ++i){
            (*this->param_ptrs[i]) = values[i];
        }
    }
    
    void ConnectionWeight::SetParamPointer(double **param_ptr) {
        for(int i = 0; i < this->n_params; ++i){
            this->param_ptrs[i] = param_ptr[i];
        }
    }
    
    void ConnectionWeight::SetParamPointer(double *param_ptr, int idx) {
        this->param_ptrs[idx] = param_ptr;
    }
    
    double ConnectionWeight::eval() {
    
        return (*this->weight_function)(this->param_ptrs, this->n_params);