@@ -124,8 +124,8 @@ class Minibatch(tt.TensorVariable):
124
124
125
125
if we want 1d slice of size 10 we do
126
126
>>> x = Minibatch(data, batch_size=10)
127
-
128
- Note, that your data is casted to `floatX` if it is not integer type
127
+
128
+ Note, that your data is cast to `floatX` if it is not integer type
129
129
But you still can add dtype kwarg for :class:`Minibatch`
130
130
131
131
in case we want 10 sampled rows and columns
@@ -158,15 +158,15 @@ class Minibatch(tt.TensorVariable):
158
158
it directly affects `x.shared`.
159
159
the same thing would be but less convenient
160
160
>>> x.shared.set_value(pm.floatX(np.random.laplace(size=(100, 100))))
161
-
162
- programmatic way to change storage is as following
161
+
162
+ programmatic way to change storage is as follows
163
163
I import `partial` for simplicity
164
164
>>> from functools import partial
165
165
>>> datagen = partial(np.random.laplace, size=(100, 100))
166
166
>>> x = Minibatch(datagen(), batch_size=100, update_shared_f=datagen)
167
167
>>> x.update_shared()
168
168
169
- To be more precise of how we get minibatch, here is a demo
169
+ To be more concrete about how we get minibatch, here is a demo
170
170
1) create shared variable
171
171
>>> shared = theano.shared(data)
172
172
@@ -179,11 +179,16 @@ class Minibatch(tt.TensorVariable):
179
179
That's done. So if you'll need some replacements in the graph
180
180
>>> testdata = pm.floatX(np.random.laplace(size=(1000, 10)))
181
181
182
- you are free to use a kind of this one as `x` is regular Theano Tensor
182
+ To change minibatch with static data you can create a dict with replacements
183
183
>>> replacements = {x: testdata}
184
184
>>> node = x ** 2 # arbitrary expressions
185
185
>>> rnode = theano.clone(node, replacements)
186
186
>>> assert (testdata ** 2 == rnode.eval()).all()
187
+
188
+ To replace minibatch with it's shared variable
189
+ instead of static `np.array` you should do
190
+ >>> replacements = {x.minibatch: x.shared}
191
+ >>> rnode = theano.clone(node, replacements)
187
192
188
193
For more complex slices some more code is needed that can seem not so clear
189
194
They are
@@ -205,7 +210,6 @@ class Minibatch(tt.TensorVariable):
205
210
3) mixing that all, total_size = (10, None, 30, Ellipsis, 50)
206
211
>>> x = Minibatch(moredata, [2, None, 20, Ellipsis, 10])
207
212
>>> assert x.eval().shape == (2, 20, 20, 40, 10)
208
-
209
213
"""
210
214
@theano .configparser .change_flags (compute_test_value = 'raise' )
211
215
def __init__ (self , data , batch_size = 128 , in_memory_size = None ,
0 commit comments