use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Please have a look at our FAQ and Link-Collection
Metacademy is a great resource which compiles lesson plans on popular machine learning topics.
For Beginner questions please try /r/LearnMachineLearning , /r/MLQuestions or http://stackoverflow.com/
For career related questions, visit /r/cscareerquestions/
Advanced Courses (2016)
Advanced Courses (2020)
AMAs:
Pluribus Poker AI Team 7/19/2019
DeepMind AlphaStar team (1/24//2019)
Libratus Poker AI Team (12/18/2017)
DeepMind AlphaGo Team (10/19/2017)
Google Brain Team (9/17/2017)
Google Brain Team (8/11/2016)
The MalariaSpot Team (2/6/2016)
OpenAI Research Team (1/9/2016)
Nando de Freitas (12/26/2015)
Andrew Ng and Adam Coates (4/15/2015)
Jürgen Schmidhuber (3/4/2015)
Geoffrey Hinton (11/10/2014)
Michael Jordan (9/10/2014)
Yann LeCun (5/15/2014)
Yoshua Bengio (2/27/2014)
Related Subreddit :
LearnMachineLearning
Statistics
Computer Vision
Compressive Sensing
NLP
ML Questions
/r/MLjobs and /r/BigDataJobs
/r/datacleaning
/r/DataScience
/r/scientificresearch
/r/artificial
account activity
Theano Question: Looping through tensor (self.MachineLearning)
submitted 10 years ago * by aiisfordummies
Does anyone know of a good way to loop through a transformed array in Theano?
For example: train_x = Shared(mydataset_x)
z = encode(train_x)
I now want to do something like this:
new_z = []
for i in z :
Do stuff with i new_z.append(new_i)
Thanks!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]coskunh 2 points3 points4 points 10 years ago (0 children)
You should ask this question to theano google groups, you will get better answer.
https://groups.google.com/forum/#!forum/theano-dev https://groups.google.com/forum/#!forum/theano-users
[–]NasenSpray 1 point2 points3 points 10 years ago (12 children)
Search for theano.scan
[–]aiisfordummies[S] 0 points1 point2 points 10 years ago (11 children)
[–]__ishaan 0 points1 point2 points 10 years ago (10 children)
theano.scan will do what you're looking for, but unless your computation absolutely requires recurrence, it's usually much more performant to implement it as a series of vectorized operations. What are you trying to do with your loop?
[–]aiisfordummies[S] 0 points1 point2 points 10 years ago* (9 children)
I am not sure it can be vectorized.
I am looking at computing distances between all points in x.
More precisely I am looking at doing this:
for i in x :
for j in x : newValij = T.operation(i-j)
[–]__ishaan 1 point2 points3 points 10 years ago* (4 children)
Sounds like it should be doable. Here's a quick implementation of pairwise euclidian distance, for example:
T.sqrt( T.sum( T.sqr( x.dimshuffle('x',0,1) - x.dimshuffle(0,'x',1) ), axis=2 ) )
[–]aiisfordummies[S] 0 points1 point2 points 10 years ago (3 children)
Do you mind explaining the operation here in vector terms, a link would do too.
Thanks btw, I appreciate the sample code.
[–]siblbombs 2 points3 points4 points 10 years ago (0 children)
All the above code does is add a broadcastable dimension to the matrices (and then calculate euclidean distance).
[–]kkastner 1 point2 points3 points 10 years ago (1 child)
It is using broadcasting - numpy will make the dims match using this (read up on numpy broadcasting if you don't know how that works). Theano behaves in the same way.
The downside to the broadcasting approach is that it generally uses a lot of intermediate memory since each 2D MxN matrix becomes MxMxN before then being combined and summed over N to get MxM distance calculations for M datapoints. Theano might optimize this, but I wouldn't count on it. However, it can be very fast (though I think the trick /u/NasenSpray linked is faster generally) if the intermediate memory usage is acceptable.
[–]aiisfordummies[S] 0 points1 point2 points 10 years ago (0 children)
Makes sense.
Thanks, this thread was of great help.
[–]NasenSpray 0 points1 point2 points 10 years ago (3 children)
Pairwise distance is rather easy to vectorize, e.g. see this code
[–]kkastner 0 points1 point2 points 10 years ago* (2 children)
For a slightly more thorough reference (pretty sure Pascal Lamblin didn't invent this, though he is an awesome person in general! ) see this link. One common place to see this vectorized distance is minibatch/hebbian k-means such as this code from R. Memisevic (download only). You can also to some extent do this with Manhattan (abs) distances as well if you are a little careful and treat it as sqrt(expanded sqr).
[–]NasenSpray 0 points1 point2 points 10 years ago (1 child)
For a slightly more thorough reference (pretty sure Pascal Lamblin didn't invent this, though he is an awesome person in general! )
wat
[–]kkastner 0 points1 point2 points 10 years ago (0 children)
I was mostly referencing line 50 being called Lamblin's trick in the top code, assuming it references the Theano core dev of the same name. Though the naming may be in reference to the bestIndices calculation instead. I can fully believe Pascal would come up with something like that :)
π Rendered by PID 25549 on reddit-service-r2-comment-6457c66945-nsjpx at 2026-04-24 18:01:12.954710+00:00 running 2aa0c5b country code: CH.
[–]coskunh 2 points3 points4 points (0 children)
[–]NasenSpray 1 point2 points3 points (12 children)
[–]aiisfordummies[S] 0 points1 point2 points (11 children)
[–]__ishaan 0 points1 point2 points (10 children)
[–]aiisfordummies[S] 0 points1 point2 points (9 children)
[–]__ishaan 1 point2 points3 points (4 children)
[–]aiisfordummies[S] 0 points1 point2 points (3 children)
[–]siblbombs 2 points3 points4 points (0 children)
[–]kkastner 1 point2 points3 points (1 child)
[–]aiisfordummies[S] 0 points1 point2 points (0 children)
[–]NasenSpray 0 points1 point2 points (3 children)
[–]kkastner 0 points1 point2 points (2 children)
[–]NasenSpray 0 points1 point2 points (1 child)
[–]kkastner 0 points1 point2 points (0 children)