Group Abstract Group Abstract

Message Boards Message Boards

1
|
5.2K Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Create a custom FeatureExtractor that learns and remember?

Posted 6 years ago
POSTED BY: Ettore Mariotti
2 Replies
Posted 6 years ago

Hi Ettore,

For this question

2) How can I initialize the random matrix w so that I don't have to define it as a global variable?

one way to do it in WL is to define a symbol that returns a function with the value of w locally bound. e.g.

randomProject = With[{w = RandomReal[{-1, 1}, {100, numFeats}]}, Function[data, Tanh[w.data]]];

Each time the above definition is evaluated, it will return a function with a different random matrix. Multiple evaluations of the function returned will use the same random matrix.

randomProject[train[[1, 1]]] == randomProject[train[[1, 1]]]
(* True *)
POSTED BY: Rohit Namjoshi

Thank you very much Rohit!

It works wonderfully.

Anyway I have to admit that I prefer the #& convention for declaring function

randomProject = 
  With[{w = RandomReal[{-1, 1}, {100, numFeats}]}, Tanh[w.#] &];

It feels more clean and nautral.

Thank you again, I never used the With statment before, looks very useful!

POSTED BY: Ettore Mariotti
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard