def R_cb(x): def sf_func(params): return self.dist.sf(x - self.gamma, *params) jac = np.atleast_2d(jacobian(sf_func)(np.array(self.params))) # Second-Order Taylor Series Expansion of Variance var_R = [] for i, j in enumerate(jac): j = np.atleast_2d(j).T * j j = j[np.triu_indices(j.shape[0])] var_R.append(np.sum(j * pvars)) # First-Order Taylor Series Expansion of Variance # var_R = (jac**2 * np.diag(hess_inv)).sum(axis=1).T R_hat = self.sf(x) if bound == 'two-sided': diff = (z(alpha_ci / 2) * np.sqrt(np.array(var_R)) * np.array([1., -1.]).reshape(2, 1)) elif bound == 'upper': diff = z(alpha_ci) * np.sqrt(np.array(var_R)) else: diff = -z(alpha_ci) * np.sqrt(np.array(var_R)) exponent = diff / (R_hat * (1 - R_hat)) R_cb = R_hat / (R_hat + (1 - R_hat) * np.exp(exponent)) return R_cb.T
def u_cb(self, x, alpha, beta, cv_matrix, alpha_ci, bound='two-sided'): u = self.u(x, alpha, beta) var_u = self.var_u(x, alpha, beta, cv_matrix) if bound == 'two-sided': diff = z(alpha_ci/2) * np.array([1., -1.]).reshape(2, 1) elif bound == 'upper': diff = z(alpha_ci) else: diff = -z(alpha_ci) u_cb = u + (diff * np.sqrt(var_u)) return u_cb
def R_cb_(self, x, alpha, beta, cv_matrix, alpha_ci=0.05): R_hat = self.sf(x, alpha, beta) def dR_f(t): return self.sf(*t) jac = jacobian(dR_f) x_ = np.array(x) if x_.size == 1: dR = jac(np.array((x_, alpha, beta))[1::]) dR = dR.reshape(1, 2) else: out = [] for xx in x_: out.append(jac(np.array((xx, alpha, beta)))[1::]) dR = np.array(out) K = z(alpha_ci / 2) exponent = (K * np.array([-1, 1]).reshape(2, 1) * np.sqrt(self.var_R(dR, cv_matrix))) exponent = exponent / (R_hat * (1 - R_hat)) R_cb = R_hat / (R_hat + (1 - R_hat) * np.exp(exponent)) return R_cb.T
def R_cb(self, t, cb=0.05): def ssf(params): params = np.reshape(params, (self.m, self.dist.k + 1)) F = np.zeros_like(t) for i in range(self.m): F = F + params[i, 0] * self.dist.ff(t, *params[i, 1::]) return 1 - F pvars = self.hess_inv[np.triu_indices(self.hess_inv.shape[0])] with np.errstate(all='ignore'): jac = jacobian(ssf)(self.res.x) var_u = [] for i, j in enumerate(jac): j = np.atleast_2d(j).T * j j = j[np.triu_indices(j.shape[0])] var_u.append(np.sum(j * pvars)) diff = (z(cb / 2) * np.sqrt(np.array(var_u)) * np.array([1., -1.]).reshape(2, 1)) R_hat = self.sf(t) exponent = diff / (R_hat * (1 - R_hat)) R_cb = R_hat / (R_hat + (1 - R_hat) * np.exp(exponent)) return R_cb.T
def lambda_cb(self, x, failure_rate, cv_matrix, alpha_ci=0.05): return failure_rate * np.exp( np.array([-1, 1]).reshape(2, 1) * (z(alpha_ci / 2) * np.sqrt(cv_matrix.item()) / failure_rate))
def z_cb(self, x, mu, sigma, cv_matrix, alpha_ci=0.05): z_hat = (x - mu) / sigma var_z = self.var_z(x, mu, sigma, cv_matrix) bounds = z_hat + np.array([1., -1.]).reshape(2, 1) * z( alpha_ci / 2) * np.sqrt(var_z) return bounds