def get_tagging_channels_from_state(self, state, target):

        missingValuesFilter = T.neq(target, -1)

        rval = OrderedDict()
        y_hat = state > 0.5
        y = target > 0.5
        wrong_bit = T.cast(T.neq(y, y_hat), state.dtype) * missingValuesFilter
        rval['mistagging'] = T.cast(wrong_bit.sum() / missingValuesFilter.sum(),
                                 state.dtype)

        y = T.cast(y, state.dtype)
        y_hat = T.cast(y_hat, state.dtype)
        tp = (y * y_hat * missingValuesFilter).sum()
        fp = ((1-y) * y_hat * missingValuesFilter).sum()
        precision = tp / T.maximum(1., tp + fp)
        recall = tp / T.maximum(1., (y * missingValuesFilter).sum())
        rval['precision'] = precision
        rval['recall'] = recall
        rval['f1'] = 2. * precision * recall / T.maximum(1, precision + recall)

        tp = (y * y_hat * missingValuesFilter).sum(axis=0)
        fp = ((1-y) * y_hat * missingValuesFilter).sum(axis=0)
        precision = tp / T.maximum(1., tp + fp)

        rval['per_output_precision.max'] = precision.max()
        rval['per_output_precision.mean'] = precision.mean()
        rval['per_output_precision.min'] = precision.min()

        recall = tp / T.maximum(1., (y * missingValuesFilter).sum(axis=0))

        rval['per_output_recall.max'] = recall.max()
        rval['per_output_recall.mean'] = recall.mean()
        rval['per_output_recall.min'] = recall.min()

        f1 = 2. * precision * recall / T.maximum(1, precision + recall)

        rval['per_output_f1.max'] = f1.max()
        rval['per_output_f1.mean'] = f1.mean()
        rval['per_output_f1.min'] = f1.min()
        
        # Add computation of the mean average recision
        from pylearn2_ECCV2014 import meanAvgPrec
        (rval['min_avg_prec'],
         rval['mean_avg_prec'],
         rval['max_avg_prec'],
         rval['mean_avg_prec_AnswerPhone'],
         rval['mean_avg_prec_DriveCar'],
         rval['mean_avg_prec_Eat'],
         rval['mean_avg_prec_FightPerson'],
         rval['mean_avg_prec_GetOutCar'],
         rval['mean_avg_prec_HandShake'],
         rval['mean_avg_prec_HugPerson'],
         rval['mean_avg_prec_Kiss'],
         rval['mean_avg_prec_Run'],
         rval['mean_avg_prec_SitDown'],
         rval['mean_avg_prec_SitUp'],
         rval['mean_avg_prec_StandUp']) = meanAvgPrec.meanAveragePrecisionTheano(target, state)

        return rval
    def get_tagging_channels_from_state(self, state, target):

        missingValuesFilter = T.neq(target, -1)

        rval = OrderedDict()
        y_hat = state > 0.5
        y = target > 0.5
        wrong_bit = T.cast(T.neq(y, y_hat), state.dtype) * missingValuesFilter
        rval['mistagging'] = T.cast(
            wrong_bit.sum() / missingValuesFilter.sum(), state.dtype)

        y = T.cast(y, state.dtype)
        y_hat = T.cast(y_hat, state.dtype)
        tp = (y * y_hat * missingValuesFilter).sum()
        fp = ((1 - y) * y_hat * missingValuesFilter).sum()
        precision = tp / T.maximum(1., tp + fp)
        recall = tp / T.maximum(1., (y * missingValuesFilter).sum())
        rval['precision'] = precision
        rval['recall'] = recall
        rval['f1'] = 2. * precision * recall / T.maximum(1, precision + recall)

        tp = (y * y_hat * missingValuesFilter).sum(axis=0)
        fp = ((1 - y) * y_hat * missingValuesFilter).sum(axis=0)
        precision = tp / T.maximum(1., tp + fp)

        rval['per_output_precision.max'] = precision.max()
        rval['per_output_precision.mean'] = precision.mean()
        rval['per_output_precision.min'] = precision.min()

        recall = tp / T.maximum(1., (y * missingValuesFilter).sum(axis=0))

        rval['per_output_recall.max'] = recall.max()
        rval['per_output_recall.mean'] = recall.mean()
        rval['per_output_recall.min'] = recall.min()

        f1 = 2. * precision * recall / T.maximum(1, precision + recall)

        rval['per_output_f1.max'] = f1.max()
        rval['per_output_f1.mean'] = f1.mean()
        rval['per_output_f1.min'] = f1.min()

        # Add computation of the mean average recision
        from pylearn2_ECCV2014 import meanAvgPrec
        (rval['min_avg_prec'], rval['mean_avg_prec'], rval['max_avg_prec'],
         rval['mean_avg_prec_AnswerPhone'], rval['mean_avg_prec_DriveCar'],
         rval['mean_avg_prec_Eat'], rval['mean_avg_prec_FightPerson'],
         rval['mean_avg_prec_GetOutCar'], rval['mean_avg_prec_HandShake'],
         rval['mean_avg_prec_HugPerson'], rval['mean_avg_prec_Kiss'],
         rval['mean_avg_prec_Run'], rval['mean_avg_prec_SitDown'],
         rval['mean_avg_prec_SitUp'], rval['mean_avg_prec_StandUp']
         ) = meanAvgPrec.meanAveragePrecisionTheano(target, state)

        return rval
idx[which["test"]] = numpy.cast["int"](numpy.loadtxt(path + "test/Newtest.txt"))
num_feats = numpy.cast["int"](numpy.loadtxt("NumFeatures.txt"))

x = theano.tensor.tensor4()
y_hat = theano.tensor.fmatrix()
y = theano.tensor.fmatrix()

predict_fn = [0] * len(f2i)

for i in range(len(model)):
    model[i] = pickle.load(file(path + "latest2class3_" + str(i2f[i]) + ".pkl"))
    dset[which["train"]][i] = adn.AtousaDataset("train", num_feats=i2f[i])
    dset[which["test"]][i] = adn.AtousaDataset("test", num_feats=i2f[i])
    predict_fn[i] = theano.function([x], model[i].fprop(x))

theano_map = theano.function([y_hat, y], meanAveragePrecisionTheano(y_hat, y))


def predict(data, i):
    transform = lambda x: x
    if voting_mode:
        transform = lambda x: onehot(x)

    return transform(numpy.array(predict_fn[i](data)))


def mean_ap(target, pred):
    return numpy.array(theano_map(target, pred))


def onehot(pred):
num_feats = numpy.cast['int'](numpy.loadtxt('NumFeatures.txt'))

x = theano.tensor.tensor4()
y_hat = theano.tensor.fmatrix()
y = theano.tensor.fmatrix()

predict_fn = [0] * len(f2i)

for i in range(len(model)):
    model[i] = pickle.load(file(path + 'latest2class3_' + str(i2f[i]) +
                                '.pkl'))
    dset[which['train']][i] = adn.AtousaDataset('train', num_feats=i2f[i])
    dset[which['test']][i] = adn.AtousaDataset('test', num_feats=i2f[i])
    predict_fn[i] = theano.function([x], model[i].fprop(x))

theano_map = theano.function([y_hat, y], meanAveragePrecisionTheano(y_hat, y))


def predict(data, i):
    transform = lambda x: x
    if voting_mode:
        transform = lambda x: onehot(x)

    return transform(numpy.array(predict_fn[i](data)))


def mean_ap(target, pred):
    return numpy.array(theano_map(target, pred))


def onehot(pred):