python - How to prevent division by zero or replace infinite values in Theano? -



python - How to prevent division by zero or replace infinite values in Theano? -

i'm using cost function in theano involves regularizer term requires me compute term:

t.sum(c / self.squared_euclidean_distances)

as values of self.squared_euclidean_distances might 0 produces nan values. how can work around problem? tried utilize t.isinf not successful. 1 solution remove zeros in self.squared_euclidean_distances little number or replace infinite numbers in t.sum(c / self.squared_euclidean_distances) zero. don't know how replace values in theano.

take @ t.switch. example

t.switch(self.squared_euclidean_distances == 0, 0, c / self.squared_euclidean_distances)

(or, upstream, create sure never compare vector using squared euclidean distance.)

python numpy nan divide-by-zero theano

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

ubuntu - Bash Script to Check That Files Are Being Created -

Php operator `break` doesn't stop while -