code: def compute_constrained_ei(self, comp, pend, cand, vals, labels):
      # First we make predictions for the durations as that
      # doesn't depend on pending experiments
      # First pull out violating points
      compfull = comp.copy()
      comp = comp[labels > 0, :]
      vals = vals[labels > 0]
  
      # Use standard EI if there aren't enough observations of either
      # positive or negative constraint violations
      if np.all(labels > 0) or np.all(labels <= 0):
          func_constraint_m = 1
      else:
          # Compute covariances
          comp_constraint_cov = self.cov(
              self.constraint_amp2, self.constraint_ls, compfull
          )
          cand_constraint_cross = self.cov(
              self.constraint_amp2, self.constraint_ls, compfull, cand
          )
  
          # Cholesky decompositions
          obsv_constraint_cov = (
              comp_constraint_cov
              + self.constraint_noise * np.eye(compfull.shape[0])
          )
          obsv_constraint_chol = spla.cholesky(
              obsv_constraint_cov, lower=True
          )
  
          # Linear systems
          t_alpha = spla.cho_solve(
              (obsv_constraint_chol, True), self.ff
          )
          t_beta = spla.solve_triangular(
              obsv_constraint_chol, cand_constraint_cross, lower=True
          )
  
          # Predict marginal mean times and (possibly) variances
          func_constraint_m = np.dot(cand_constraint_cross.T, t_alpha)
  
      # Squash through a probit
      func_constraint_m = sps.norm.cdf(
          self.constraint_gain * func_constraint_m
      )
      if pend.shape[0] == 0:
          # If there are no pending, don't do anything fancy.
          # Current best.
          best = np.min(vals)
  
          # The primary covariances for prediction.
          comp_cov = self.cov(self.amp2, self.ls, comp)
          comp_cov_full = self.cov(self.amp2, self.ls, compfull)
          cand_cross = self.cov(self.amp2, self.ls, comp, cand)
          cand_cross_full = self.cov(self.amp2, self.ls, compfull, cand)
  
          # Compute the required Cholesky.
          obsv_cov = comp_cov + self.noise * np.eye(comp.shape[0])
          obsv_cov_full = comp_cov_full + self.noise * np.eye(
              compfull.shape[0]
          )
          obsv_chol = spla.cholesky(obsv_cov, lower=True)
          obsv_chol_full = spla.cholesky(obsv_cov_full, lower=True)
  
          # Solve the linear systems.
          alpha = spla.cho_solve((obsv_chol, True), vals - self.mean)
          beta = spla.solve_triangular(
              obsv_chol, cand_cross, lower=True
          )
          # beta   = spla.solve_triangular(obsv_chol_full, cand_cross_full,
          #                               lower=True)
  
          # Predict the marginal means and variances at candidates.
          func_m = np.dot(cand_cross.T, alpha) + self.mean
          func_v = self.amp2 * (1 + 1e-6) - np.sum(beta**2, axis=0)
  
          # Expected improvement
          func_s = np.sqrt(func_v)
          u = (best - func_m) / func_s
          ncdf = sps.norm.cdf(u)
          npdf = sps.norm.pdf(u)
          ei = func_s * (u * ncdf + npdf)
  
          constrained_ei = ei * func_constraint_m
          return constrained_ei
      else:
          # If there are pending experiments, fantasize their outcomes.
  
          # Create a composite vector of complete and pending.
          comp_pend = np.concatenate((comp, pend))
  
          # Compute the covariance and Cholesky decomposition.
          comp_pend_cov = self.cov(
              self.amp2, self.ls, comp_pend
          ) + self.noise * np.eye(comp_pend.shape[0])
          comp_pend_chol = spla.cholesky(comp_pend_cov, lower=True)
  
          # Compute submatrices.
          pend_cross = self.cov(self.amp2, self.ls, comp, pend)
          pend_kappa = self.cov(self.amp2, self.ls, pend)
  
          # Use the sub-Cholesky.
          obsv_chol = comp_pend_chol[: comp.shape[0], : comp.shape[0]]
  
          # Solve the linear systems.
          alpha = spla.cho_solve((obsv_chol, True), vals - self.mean)
          beta = spla.cho_solve((obsv_chol, True), pend_cross)
  
          # Finding predictive means and variances.
          pend_m = np.dot(pend_cross.T, alpha) + self.mean
          pend_K = pend_kappa - np.dot(pend_cross.T, beta)
  
          # Take the Cholesky of the predictive covariance.
          pend_chol = spla.cholesky(pend_K, lower=True)
  
          # Make predictions.
          pend_fant = (
              np.dot(
                  pend_chol,
                  npr.randn(pend.shape[0], self.pending_samples),
              )
              + pend_m[:, None]
          )
  
          # Include the fantasies.
          fant_vals = np.concatenate(
              (
                  np.tile(
                      vals[:, np.newaxis], (1, self.pending_samples)
                  ),
                  pend_fant,
              )
          )
  
          # Compute bests over the fantasies.
          bests = np.min(fant_vals, axis=0)
  
          # Now generalize from these fantasies.
          cand_cross = self.cov(self.amp2, self.ls, comp_pend, cand)
  
          # Solve the linear systems.
          alpha = spla.cho_solve(
              (comp_pend_chol, True), fant_vals - self.mean
          )
          beta = spla.solve_triangular(
              comp_pend_chol, cand_cross, lower=True
          )
  
          # Predict the marginal means and variances at candidates.
          func_m = np.dot(cand_cross.T, alpha) + self.mean
          func_v = self.amp2 * (1 + 1e-6) - np.sum(beta**2, axis=0)
  
          # Expected improvement
          func_s = np.sqrt(func_v[:, np.newaxis])
          u = (bests[np.newaxis, :] - func_m) / func_s
          ncdf = sps.norm.cdf(u)
          npdf = sps.norm.pdf(u)
          ei = func_s * (u * ncdf + npdf)
  
          return np.mean(ei, axis=1) * func_constraint_m
  
imports: import os
  from ..None import gp
  import sys
  from ..None import util
  import tempfile
  import numpy
  import math
  import numpy.random
  import scipy.linalg
  import scipy.stats
  import scipy.optimize
  import pickle
  import matplotlib.pyplot
  import multiprocessing
  import copy
  from ..helpers import *
  from ..Locker import *
  import logging
label_desc: Use image node_id 13 for calling the GPConstrainedEIChooser obj's underlying member method code with example usage: obj.compute_constrained_ei(comp, pend, cand, vals, labels) and returns: constrained_ei, unknown