-2

I have the expression Sum from 1 to K of log(sigmoid(-u_k^Tv_c)) . Sorry I don't have enough reputation on StackOverflow to post an image.

Here u and v are both matrices. I'm trying to implement this using numpy and getting totally stuck.

What I have:

np.sum(log(sigmoid(-np.dot(u.T,v))))

Which I know isn't even close to what I want because I haven't been able to restrict the sum to the range 1 through k at all yet. Sigmoid is a function implemented elsewhere. The dimensions of u and v should work out just fine.

user2813092
  • 11
  • 1
  • 5

1 Answers1

0

Without formal math notation this is a little unclear

Sum from 1 to K of log(sigmoid(-u_k^Tv_c))

But let's try to clear up some details.

u and v are 'matrices'. That's little vague. What, specifically are their shapes. 1d, 2d? Keep in mind that Transpose of 1d does nothing.

Is this what you mean by sigmoid: How to calculate a logistic sigmoid function in Python?

sum from 1 to K - sum what? Sum the k dimension of u?

Is u_k^T v_c supposed to be an outer product, producing a 2d result (rows of same size as u, columns as from c)? Or a scalar dot/matrix product, multiplying two 1d arrays and summing the products?

And what shape do you expect from the result?

The key point when working with numpy arrays, what are the shapes of the inputs, and what is desired shape of the result?

Community
  • 1
  • 1
hpaulj
  • 221,503
  • 14
  • 230
  • 353