def construct_model(self, X, Y): self.logger.info('Creating model_args config {}'.format( print_dictionary(self.default_configuration))) with pm.Model() as self.model: self.Xt = theano.shared(X) self.Yt = theano.shared(Y) shapes = {'weights': self.n_object_features} # shapes = {'weights': (self.n_object_features, 3)} weights_dict = create_weight_dictionary(self.model_args, shapes) intercept = pm.Normal('intercept', mu=0, sd=10) utility = tt.dot(self.Xt, weights_dict['weights']) + intercept self.p = ttu.sigmoid(utility) yl = BinaryCrossEntropyLikelihood('yl', p=self.p, observed=self.Yt) self.logger.info("Model construction completed")
def construct_model(self, X, Y): """ Constructs the linear logit model which evaluated the utility score as :math:`U(x) = w \\cdot x`, where :math:`w` is the weight vector. The probability of choosing the object :math:`x_i` from the query set :math:`Q = \\{x_1, \\ldots ,x_n\\}` is: .. math:: P_i = P(x_i \\lvert Q) = \\frac{1}{1+exp(-U(x_i))} Parameters ---------- X : numpy array (n_instances, n_objects, n_features) Feature vectors of the objects Y : numpy array (n_instances, n_objects) Preferences in form of Choices for given objects Returns ------- model : pymc3 Model :class:`pm.Model` """ logger.info( "Creating model_args config {}".format( print_dictionary(self.model_configuration) ) ) self.trace_ = None self.trace_vi_ = None with pm.Model() as self.model: self.Xt_ = theano.shared(X) self.Yt_ = theano.shared(Y) shapes = {"weights": self.n_object_features_fit_} # shapes = {'weights': (self.n_object_features_fit_, 3)} weights_dict = create_weight_dictionary(self.model_configuration, shapes) intercept = pm.Normal("intercept", mu=0, sd=10) utility = tt.dot(self.Xt_, weights_dict["weights"]) + intercept self.p_ = ttu.sigmoid(utility) BinaryCrossEntropyLikelihood("yl", p=self.p_, observed=self.Yt_) logger.info("Model construction completed")