Пример #1
0
    def __call__(self, model, X, Y = None):

        if self.X_callback is not None:
            orig_X = X
            X = CallbackOp(self.X_callback)(X)
            assert len(X.owner.inputs) == 1
            assert orig_X is X.owner.inputs[0]

        if self.y_callback is not None:
            Y = CallbackOp(self.y_callback)(Y)

        cost = X.sum()
        if self.supervised and Y is not None:
            cost = cost + Y.sum()

        model_terms = sum([param.sum() for param in model.get_params()])

        cost = cost * model_terms

        return cost
Пример #2
0
    def expr(self, model, data):
        self.get_data_specs(model)[0].validate(data)
        callbacks = self.data_callbacks

        cb_tuple = self._mapping.flatten(callbacks, return_tuple=True)
        data_tuple = self._mapping.flatten(data, return_tuple=True)

        costs = []
        for (callback, data_var) in safe_zip(cb_tuple, data_tuple):
            orig_var = data_var
            data_var = CallbackOp(callback)(data_var)
            assert len(data_var.owner.inputs) == 1
            assert orig_var is data_var.owner.inputs[0]

            costs.append(data_var.sum())

        # sum() will call theano.add on the symbolic variables
        cost = sum(costs)
        model_terms = sum([param.sum() for param in model.get_params()])
        cost = cost * model_terms
        return cost
Пример #3
0
    def expr(self, model, data):
        self.get_data_specs(model)[0].validate(data)
        callbacks = self.data_callbacks

        cb_tuple = self._mapping.flatten(callbacks, return_tuple=True)
        data_tuple = self._mapping.flatten(data, return_tuple=True)

        costs = []
        for (callback, data_var) in safe_zip(cb_tuple, data_tuple):
            orig_var = data_var
            data_var = CallbackOp(callback)(data_var)
            assert len(data_var.owner.inputs) == 1
            assert orig_var is data_var.owner.inputs[0]

            costs.append(data_var.sum())

        # sum() will call theano.add on the symbolic variables
        cost = sum(costs)
        model_terms = sum([param.sum() for param in model.get_params()])
        cost = cost * model_terms
        return cost
Пример #4
0
    def __call__(self, model, X, Y=None):

        if self.X_callback is not None:
            orig_X = X
            X = CallbackOp(self.X_callback)(X)
            assert len(X.owner.inputs) == 1
            assert orig_X is X.owner.inputs[0]

        if self.y_callback is not None:
            Y = CallbackOp(self.y_callback)(Y)

        cost = X.sum()
        if self.supervised and Y is not None:
            cost = cost + Y.sum()

        model_terms = sum([param.sum() for param in model.get_params()])

        cost = cost * model_terms

        return cost