View Single Post
Old 05-05-2012, 10:13 PM
kurts kurts is offline
Invited Guest
Join Date: Apr 2012
Location: Portland, OR
Posts: 70
Default Re: Evaluating a gradient function with vectors

Holland, I think you are right. I thought the same thing, and I ended up trying it with the whole dot product in the denominator, and I am getting a much better final set of w values.

Instead of just plugging in individual w_nx_n values in the exponential, I go ahead and calculate the whole {\mathbf{w_n^Tx_n}} dot product and use the same denominator for each element of the gradient.

double altgradient(double yn, double xn, double wtx) {
  double num = -1.0*yn*xn;
  double denom = 1 + exp(yn*wtx);
  return num / denom;

double calcWTX(double x1, double x2, double w0, double w1, double w2) {
  double sum = w0 + w1*x1 + w2*x2;
  return sum;

double wtx = calcWTX(x1n, x2n, w0, w1, w2);
double g0 = altgradient(yn, 1.0, wtx);
double g1 = altgradient(yn, x1n, wtx);
double g2 = altgradient(yn, x2n, wtx);
This is giving me a much better approximation of f. However, it does increase the number of steps by quite a bit.

Reply With Quote