CoolFace
Apppublic

arao02/Desktop

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
MLP.cpp30 linesDownload Raw Back to root
1#include "MLP.h"2 3double frand(){4    return(2.0*(double)rand()/RAND_MAX) -1.0;5}6 7 8//Return a new Perceptron object with the specified number of inputs(+1 for the bias)9Perceptron::Perceptron(int inputs, double bias){10    this-> bias = bias;11    weights.resize(inputs+1);12    generate(weights.begin(),weights.end(),frand);13 14}15 16//Run the perceptron. x is a vector with the input values.17double Perceptron::run(vector<double>x){18    x.push_back(bias);19    double_sum = inner_product(x.begin(),x.end(),weights.begin(),(double)0.0);20    return sigmoid(sum);21 22}23 24void Perceptron::set_weights(vector<double>w_init){25    weights = w_init;26}27 28double Perceptron::sigmoid(double x){29    return (1.0/(1.0 + exp(-x)));30}