def obtain_solution(self, init_mean, init_var):
    'Optimizes the cost function using the provided initial candidate distribution\n        Arguments:\n            init_mean (np.ndarray): The mean of the initial candidate distribution.\n            init_var (np.ndarray): The variance of the initial candidate distribution.\n        '
    (mean, var, t) = (init_mean, init_var, 0)
    X = stats.truncnorm((- 2), 2, loc=np.zeros_like(mean), scale=np.ones_like(var))
    costs_hist = []
    mean_hist = []
    var_hist = []
    while ((t < self.max_iters) and (np.max(var) > self.epsilon)):
        (lb_dist, ub_dist) = ((mean - self.lb), (self.ub - mean))
        constrained_var = np.minimum(np.minimum(np.square((lb_dist / 2)), np.square((ub_dist / 2))), var)
        samples = ((X.rvs(size=[self.popsize, self.sol_dim]) * np.sqrt(constrained_var)) + mean)
        samples = samples.astype(np.float32)
        costs = self.cost_function(samples, t)
        elites = samples[np.argsort(costs)][:self.num_elites]
        new_mean = np.mean(elites, axis=0)
        new_var = np.var(elites, axis=0)
        mean = ((self.alpha * mean) + ((1 - self.alpha) * new_mean))
        var = ((self.alpha * var) + ((1 - self.alpha) * new_var))
        for (i, m) in enumerate(mean):
            self.writer.add_scalar(f'mean/{i}', m, t)
        for (i, m) in enumerate(var):
            self.writer.add_scalar(f'var/{i}', m, t)
        self.writer.add_scalar('costs', np.min(costs), t)
        t += 1
        costs_hist.append(costs)
        mean_hist.append(mean)
        var_hist.append(var)
    self.writer.close()
    return dict(mean_hist=mean_hist, costs_hist=costs_hist, var_hist=var_hist)
Optimizes the cost function using the provided initial candidate distribution
Arguments:
    init_mean (np.ndarray): The mean of the initial candidate distribution.
    init_var (np.ndarray): The variance of the initial candidate distribution.
def obtain_solution(self, init_mean, init_var):
    'Optimizes the cost function using the provided initial candidate distribution\n        Arguments:\n            init_mean (np.ndarray): The mean of the initial candidate distribution.\n            init_var (np.ndarray): The variance of the initial candidate distribution.\n        '
    (mean, var, t) = (init_mean, init_var, 0)
    X = stats.truncnorm((- 2), 2, loc=np.zeros_like(mean), scale=np.ones_like(var))
    costs_hist = []
    mean_hist = []
    var_hist = []
    while ((t < self.max_iters) and (np.max(var) > self.epsilon)):
        (lb_dist, ub_dist) = ((mean - self.lb), (self.ub - mean))
        constrained_var = np.minimum(np.minimum(np.square((lb_dist / 2)), np.square((ub_dist / 2))), var)
        samples = ((X.rvs(size=[self.popsize, self.sol_dim]) * np.sqrt(constrained_var)) + mean)
        samples = samples.astype(np.float32)
        costs = self.cost_function(samples, t)
        elites = samples[np.argsort(costs)][:self.num_elites]
        new_mean = np.mean(elites, axis=0)
        new_var = np.var(elites, axis=0)
        mean = ((self.alpha * mean) + ((1 - self.alpha) * new_mean))
        var = ((self.alpha * var) + ((1 - self.alpha) * new_var))
        for (i, m) in enumerate(mean):
            self.writer.add_scalar(f'mean/{i}', m, t)
        for (i, m) in enumerate(var):
            self.writer.add_scalar(f'var/{i}', m, t)
        self.writer.add_scalar('costs', np.min(costs), t)
        t += 1
        costs_hist.append(costs)
        mean_hist.append(mean)
        var_hist.append(var)
    self.writer.close()
    return dict(mean_hist=mean_hist, costs_hist=costs_hist, var_hist=var_hist)