Infer probable output from input x, y
422598
def infer_dm(self, m, s, ds):
        
        OptimizedInverseModel.infer_dm(self, ds)
        if len(self.fmodel.dataset) == 0:
            return [[0.0]*self.dim_out]
        else:
            _, index = self.fmodel.dataset.nn_dims(m, np.hstack((s, ds)), range(len(m)), range(self.dim_x, self.dim_x + self.dim_y), k=1)
            guesses = [self.fmodel.dataset.get_dims(index[0], dims=range(len(m), self.dim_x))]
            result = []
                    
            for g in guesses:
                res = scipy.optimize.minimize(lambda dm:self._error_dm(m, dm, s), g,
                                              args        = (),
                                              method      = self.algo,
                                              options     = self.conf
                                             )
    
    
    
                d = self._error_dm(m, res.x, s)
                result.append((d, res.x))
            return [xi for fi, xi in sorted(result)][0]
492323
def fit_predict(self, X, y=None, **kwargs):
        
        return self.fit(X, **kwargs).predict(X, **kwargs)
687596
def forward_prediction(self, m):
        
        return self.infer(self.conf.m_dims, self.conf.s_dims, m)
481142
def predict(self, X):
        
        logger.info('predicting ...')
        ps = self.predict_raw(X)

        return sigm(ps[:, 0])
115856
private Map<Integer, Double> predict(final double[] x) {
        Map<Integer, Double> result = new HashMap<>();
        for (int i = 0; i < model.weights.length; i++) {
            double y = VectorUtils.dotProduct(x, model.weights[i]);
            y += model.bias[i];
            result.put(i, y);
        }

        return result;
    }
591859
def _infer_shape(self, dimensions):
    
    # Size of input
    n = np.prod(dimensions)
    # Size of output where defined
    m = np.prod(abs(np.array(self._shape)))
    # Replace wildcard
    v = np.array(self._shape)
    v[v == -1] = n // m
    return tuple(v)
1351645
def infer(self, input_data, input_label):
        
        sum_losses = 0
        len_losses = 0
        for data, label in zip(input_data, input_label):
            pred = self.net(data)
            sum_losses += mx.nd.array(self.loss_fn(pred, label)).sum().asscalar()
            len_losses += len(data)
            pred_convert = char_beam_search(pred)
            label_convert = char_conv(label.asnumpy())
            for target, pred in zip(label_convert, pred_convert):
                print("target:{t}  pred:{p}".format(t=target, p=pred))
        return sum_losses, len_losses
891655
def feasible_set(self):
        """"""
        for y in itertools.product(*[range(1, k + 1) for k in self.K]):
            yield np.array(y)
810253
def accuracy(y, z):
    
    tp, tn, fp, fn = contingency_table(y, z)
    return (tp + tn) / (tp + tn + fp + fn)
475319
def initial_guesses(self):
        
        return np.array([param.value for param in self.model.params])
328890
def infer_dims(self, x, y, dims_x, dims_y, dims_out):
        
        OptimizedInverseModel.infer_x(self, y)
        assert len(x) == len(dims_x)
        assert len(y) == len(dims_y)
        if len(self.fmodel.dataset) == 0:
            return [[0.0]*self.dim_out]
        else:
            _, index = self.fmodel.dataset.nn_dims(x, y, dims_x, dims_y, k=1)
            guesses = [self.fmodel.dataset.get_dims(index[0], dims_out)]

            result = []
            for g in guesses:
                res = cma.fmin(lambda q:self._error_dims(q, dims_x, dims_y, dims_out), g, self.cmaes_sigma,
                               options={'bounds':[self.lower, self.upper],
                               'verb_log':0,
                               'verb_disp':False,
                               'maxfevals':self.maxfevals,
                               'seed': self.seed})
                result.append((res[1], res[0]))

            return sorted(result)[0][1]
850843
def infer_x(self, y_desired):
        
        InverseModel.infer_x(y_desired)
        if self.fmodel.size() == 0:
            return self._random_x()
        else:
            idx = random.randint(0, self.fmodel.size()-1)
            return self.dataset.get_x(idx)
432145
def _compute_prediction(self,X):
        
        A_pred = np.dot(X,self._Bhat)
        Y_pred = self._basis_object.inverse_transform(A_pred)
        return Y_pred
1284626
def compute(self, x, y):
        '''
        
        '''
        return np.sqrt(np.sum((x-y)**2))
383666
def inference(self, kern, X, likelihood, Y, mean_function=None, Y_metadata=None):
        
        assert mean_function is None, "inference with a mean function not implemented"

        # Compute K
        K = kern.K(X)

        #Find mode
        if self.bad_fhat or self.first_run:
            Ki_f_init = np.zeros_like(Y)
            self.first_run = False
        else:
            Ki_f_init = self._previous_Ki_fhat

        Ki_f_init = np.zeros_like(Y)# FIXME: take this out

        f_hat, Ki_fhat = self.rasm_mode(K, Y, likelihood, Ki_f_init, Y_metadata=Y_metadata)

        #Compute hessian and other variables at mode
        log_marginal, woodbury_inv, dL_dK, dL_dthetaL = self.mode_computations(f_hat, Ki_fhat, K, Y, likelihood, kern, Y_metadata)

        self._previous_Ki_fhat = Ki_fhat.copy()
        return Posterior(woodbury_vector=Ki_fhat, woodbury_inv=woodbury_inv, K=K), log_marginal, {'dL_dK':dL_dK, 'dL_dthetaL':dL_dthetaL}
96177
def _infer_x_for_line(y):
    
    array_shape = shape(y)

    if len(array_shape) == 0:
        return []
    if len(array_shape) == 1:
        return arange(array_shape[0])
    if len(array_shape) > 1:
        return arange(array_shape[1])
843724
def predict(self, X):
        
        X = np.atleast_2d(X)
        m = np.empty(shape=(0,1))
        s = np.empty(shape=(0,1))

        for k in range(X.shape[0]):
            preds = []
            for pred in self.model.estimators_:
                preds.append(pred.predict(X[k,:])[0])
            m = np.vstack((m ,np.array(preds).mean()))
            s = np.vstack((s ,np.array(preds).std()))
        return m, s