/** @brief oscistep * * @todo: calculate 2nn output */ void SDController::oscistep() { // calculate output values double activityO1=w11_*o1_+w12_*o2_+theta1_+input1_; double activityO2=w21_*o1_+theta2_+input2_; o1_= sigmoid_(activityO1); o2_= sigmoid_(activityO2); // if targetinput is called, inputs must be reseted to zero input1_ = input2_ = 0; }
double Alignment::sumSigmoid_(DBL_MATRIX& x0, DBL_MATRIX& rt_vec, double alpha) { if(x0.columnCount() != 1){ MSPP_LOG(logERROR) << "Alignment::sumSigmoid_(): Wrong dimensionality of input - x0 must be a column vector!" << std::endl; } mspp_precondition(x0.columnCount() == 1 , "Alignment::sumSigmoid_(): Wrong dimensionality of input - x0 must be a column vector!"); int rt_size = rt_vec.rowCount(); DBL_MATRIX x0mat (rt_size,x0.rowCount(),0.) ; //fill each line in x0mat with x0 for(int k = 0; k < rt_size; k++){ for(int l = 0; l < x0.rowCount(); l++){ x0mat(k,l) = x0(l,0); } } DBL_MATRIX delta = rt_vec - x0mat; //return value. increases in loop (sum) double value = 0; //go through all vectors in rt_vec for(int i = 0; i < rt_size; i++){ double prod = -1; double mprod = -1; int count = 0; /*WEIGHTS*/ //build products over the dimensions for(int j = 0; j < rt_vec.columnCount(); j++){ if(rt_vec(i,j) != -1.){ count++; /*WEIGHTS*/ double dij = delta(i,j); prod *= sigmoid_(dij,alpha); mprod *= sigmoid_(-dij,alpha); } } value += prod + mprod; //value += double(count)/double(rt_vec.columnCount()) * (prod + mprod); /*WEIGHTS*/ } return value; }
DBL_MATRIX Alignment::sigmoid_(DBL_MATRIX& delta, double alpha) { if(delta.columnCount() != 1 ){ MSPP_LOG(logERROR) << "Alignment::sigmoid_(): Wrong dimensionality of input - delta must be a column vector!" << std::endl; } mspp_precondition(delta.columnCount() == 1 , "Alignment::sigmoid_(): Wrong dimensionality of input - delta must be a column vector!"); unsigned int size = delta.rowCount(); //create result vector of correct length DBL_MATRIX sig (size,1); //fill result vector for(unsigned int i = 0; i < size; i++){ //calculate each entry with 1-dimensional sigmoid_ sig(i,0) = sigmoid_(delta(i,0), alpha); } return sig; }
void Logit::batch_grad_descent_(Mat &_theta_, Mat &_X_, Mat &_y_, Mat &_Ones_, Mat &_grad_, const double &_alpha_, const double &_lambda_) { Mat _z_ = _X_ * _theta_; Mat temp; sigmoid_(_z_); _grad_.row(0).col(0) = ((double) (1 / (double)(_y_.rows))) * ((double)(sum( _z_ - _y_ ).val[0])); transpose(_X_.colRange(1, _X_.cols) , temp); _grad_.rowRange(1, _grad_.rows) = ( (1 / (double)(_y_.rows)) * (temp * (_z_ - _y_) ) ) + ( (_lambda_ / (double)(_y_.rows)) * _theta_.rowRange(1, _theta_.rows)); /*if (j == 1) { cout<< _theta_.row(0).col(0) << endl; for (int i = 1; i < _theta_.rows; i++) { cout<< _theta_.row(i).col(0) << endl; } }*/ }
void Logit::Predict_(Mat &_X_, Mat &_theta_, Mat &_pred_) { for (int i = 0; i < _X_.rows; i++) { //Mat t = _X_.row(i); Mat _check_ = _X_.row(i) * _theta_; sigmoid_(_check_); float k = _check_.at<float>(0 , 0); //cout<< k << endl; if (k >= 0.5) { _pred_.row(i).col(0) = 1.0; } else { _pred_.row(i).col(0) = 0.0; } } }