Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve IDW #53

Open
patel-zeel opened this issue Aug 27, 2023 · 0 comments
Open

Improve IDW #53

patel-zeel opened this issue Aug 27, 2023 · 0 comments

Comments

@patel-zeel
Copy link
Member

The following lines in IDW might slow down IDW since it is a for loop over all examples. Can we use a clever math/code trick to get rid of them?

polire/polire/idw/idw.py

Lines 85 to 91 in 4b9360f

# if point is from train data, ground truth must not change
for i in range(X.shape[0]):
mask = np.equal(X[i], self.X).all(axis=1)
if mask.any():
result[i] = (self.y * mask).sum()
return result

A relevant trick is used in causal attention. Consider the following sentence:
I play cricket

A self-attention matrix will be 3x3 for this. Let's populate some values:

. I play cricket
I a11 0 0
play a21 a22 0
cricket a31 a32 a33

To make sure, softmax works correctly, we replace zeros with -inf.

. I play cricket
I a11 -inf -inf
play a21 a22 -inf
cricket a31 a32 a33

Softmax output:

. I play cricket
I 1 0 0
play exp(a21)/row_sum exp(a22)/row_sum 0
cricket exp(a31)/row_sum exp(a32)/row_sum exp(a33)/row_sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant