def _predict_scores_fixed(self, X, **kwargs):
        """Predict the scores for a given collection of sets of objects of same size.

           Parameters
           ----------
           X : array-like, shape (n_samples, n_objects, n_features)


           Returns
           -------
           Y : array-like, shape (n_samples, n_objects)
               Returns the scores of each of the objects for each of the samples.
        """
        n_instances, n_objects, n_features = X.shape
        assert n_features == self.n_object_features_fit_
        outputs = [list() for _ in range(n_objects)]
        for i, j in combinations(range(n_objects), 2):
            x1 = X[:, i]
            x2 = X[:, j]
            x1x2 = np.concatenate((x1, x2), axis=1)
            x2x1 = np.concatenate((x2, x1), axis=1)
            n_g = np.dot(x1x2, self.weight1_) + self.bias1_
            n_l = np.dot(x2x1, self.weight1_) + self.bias1_
            outputs[i].append(n_g)
            outputs[j].append(n_l)
        outputs = np.array(outputs)
        outputs = np.mean(outputs, axis=1).T
        scores_zero = np.dot(X, self.weight2_) + self.bias2_
        scores = sigmoid(self.W_last_[0] * scores_zero + self.W_last_[1] * outputs)
        return scores
Beispiel #2
0
 def _predict_scores_fixed(self, X, **kwargs):
     n_instances, n_objects, n_features = X.shape
     assert n_features == self.n_object_features_fit_
     rep = np.mean(np.dot(X, self.weight1_), axis=1) + self.bias1_
     rep = np.tile(rep[:, np.newaxis, :], (1, n_objects, 1))
     X_n = np.concatenate((X, rep), axis=2)
     scores = np.dot(X_n, self.weight2_) + self.bias2_
     scores = sigmoid(scores)
     return scores
Beispiel #3
0
 def _predict_scores_fixed(self, X, **kwargs):
     n_instances, n_objects, n_features = X.shape
     assert n_features == self.n_object_features
     outputs = [list() for _ in range(n_objects)]
     for i, j in combinations(range(n_objects), 2):
         x1 = X[:, i]
         x2 = X[:, j]
         x1x2 = np.concatenate((x1, x2), axis=1)
         x2x1 = np.concatenate((x2, x1), axis=1)
         n_g = np.dot(x1x2, self.weight1) + self.bias1
         n_l = np.dot(x2x1, self.weight1) + self.bias1
         outputs[i].append(n_g)
         outputs[j].append(n_l)
     outputs = np.array(outputs)
     outputs = np.mean(outputs, axis=1).T
     scores_zero = np.dot(X, self.weight2) + self.bias2
     scores = sigmoid(self.W_last[0] * scores_zero +
                      self.W_last[1] * outputs)
     return scores
Beispiel #4
0
 def _predict_scores_using_pairs(self, X, **kwd):
     n_instances, n_objects, n_features = X.shape
     n2 = n_objects * (n_objects - 1)
     pairs = np.empty((n2, 2, n_features))
     scores = np.zeros((n_instances, n_objects))
     for n in range(n_instances):
         for k, (i, j) in enumerate(permutations(range(n_objects), 2)):
             pairs[k] = (X[n, i], X[n, j])
         result = self._predict_pair(pairs[:, 0],
                                     pairs[:, 1],
                                     only_pairwise=True,
                                     **kwd)[:, 0]
         scores[n] += result.reshape(n_objects, n_objects - 1).mean(axis=1)
         del result
     del pairs
     if self._use_zeroth_model:
         scores_zero = self.zero_order_model.predict(
             X.reshape(-1, n_features))
         scores_zero = scores_zero.reshape(n_instances, n_objects)
         model = self._create_weighted_model(n_objects)
         scores = model.predict([scores, scores_zero], **kwd)
     else:
         scores = sigmoid(scores)
     return scores
Beispiel #5
0
 def _predict_scores_using_pairs(self, X, **kwd):
     scores = super()._predict_scores_using_pairs(X=X, **kwd)
     scores = sigmoid(scores)
     return scores