hi...I am trying to do something similar. I need to find out the value of 
the cost function ( the loss) for each sample. My example code has 
something written like this.

test_model_error = theano.function([index], layer4.errors(y),
             givens={
                x: test_set_x[index * batch_size: (index + 1) * batch_size],
                y: test_set_y[index * batch_size: (index + 1) * 
batch_size]})

here layer4.errors(y) is giving the rate of prediction mistakes the model 
makes for a minibatch. But I need the value of the cost function which uis 
defined in the code as 

cost = layer4.negative_log_likelihood(y)

How can a write a function which will give me the value of the cost 
function for a single sample ?
I have written something like this but it is not working.

test_model_cost = theano.function([sample_index], cost,
             givens={
                x: test_set_x[sample_index],
                y: test_set_y[sample_index]})

Also since y is not a shared variable its giving some error in "y: 
test_set_y[sample_index]".
Also can you tell me how to make y a shared variable....since y is a 
categorical array (containing the labels) its not allowing me to convert it 
into a shared variable.

PLEASE HELP ME....I NEED TO DO THIS...I HAVE A DEADLINE....

THANKS IN ADVANCE...

On Wednesday, August 20, 2014 at 2:20:30 AM UTC-4, amyvnee wrote:
>
> Very sweet, Pascal. 
>
> Thank you a lot. 
> My training dataset is extremely unbalanced. I am thinking of making more 
> augmented data for class 0. 
> Thank you for your help.
>
> Sincerely,
>
> On Wednesday, August 20, 2014 4:04:27 AM UTC+9, Pascal Lamblin wrote:
>>
>> On Tue, Aug 19, 2014, amyvnee wrote: 
>> > Hi Pascal. 
>> > 
>> > I did make a new function and compile the new function as following 
>> > 
>> > >         predict_model = theano.function( 
>> > > inputs=[index], outputs=[layer5.y_pred], 
>> > > givens={ 
>> > > x: test_set_x[index * batch_size: (index + 1) * batch_size]}) 
>> > > result = [predict_model(i) for i in xrange(n_test_batches)] 
>> > > 
>> > > result = numpy.asarray(result); 
>> > 
>> >         print result 
>> > 
>> > Since the predict_model is running with the test_set_x and it's pretty 
>> > large, I think it's better to run on many batches too. 
>>
>> Yes, it makes sense to use minibatches for prediction as well. 
>>
>> > But it gave me an array of all elements which have value 1. 
>> > Could you please tell me what I am doing wrong here? 
>>
>> Maybe your dataset is really unbalanced, and has a large majority 
>> of examples in class 1? In that case, the network may have learned 
>> to always predict the most frequent class, which still gives low 
>> classification error. 
>> For instance, if 96% of the examples are of class 1, then always 
>> predicting 1 will give 4% error. 
>>
>> To check if it is the case, you can compile a function that only 
>> computes the classification error given the prediction (not the input!) 
>> and the actual target. Then, call that function on your "result" array, 
>> and check if you have the same error rate. 
>>
>> Let us know how it goes, 
>> -- 
>> Pascal 
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to