def ObjectiveFunctionMaxTwin(t_w): error = 0. for i in range(n_samples): final_time = 2 * math.pi * (i + 1) / n_samples final_time_minus_tw = final_time - t_w approximate_tail_contribution = 0. if m_index + 1: ais = points_set.AsTs[m_index][0][:] tis = [t_w * ti for ti in points_set.AsTs[m_index][1]] approximate_tail_contribution = float( quad.ExactIntegrationOfTail( final_time=final_time, final_time_minus_tw=final_time_minus_tw, initial_time='MinusInfinity', ais=ais, tis=tis)) exact_tail = quad.ExactIntegrationOfSinus( final_time, a='MinusInfinity', b=final_time) - quad.ExactIntegrationOfSinus( final_time, a=final_time_minus_tw, b=final_time) error += abs(exact_tail - approximate_tail_contribution) # print('a', final_time_minus_tw) # print('EXACT', exact_tail) # print('APROX',approximate_tail_contribution) return error / n_samples / ref_error - 1
def CalculateError(t_w): ExactIntegral = quad.ExactIntegrationOfSinus(pp.final_time) F_w = quad.ExactIntegrationOfSinus(pp.final_time, pp.final_time_minus_tw) tis = [t_w * ti for ti in points_set.AsTs[m][1]] F_tail = quad.ExactIntegrationOfTail(pp.final_time, pp.final_time_minus_tw, 0, points_set.AsTs[m][0], tis) ApproxIntegral = float(F_w) + float(F_tail) error_bound = ObjectiveFunction(points_set, m, pp) Error = abs((ExactIntegral - ApproxIntegral)) return error, error_bound
def CalculateErrors(points_set, pp): ExactIntegral = quad.ExactIntegrationOfSinus(pp.final_time, pp.initial_time) pp.lower_limits_for_tail = [0.0] * len(points_set.AsTs) for m in points_set.exponential_indices: tis = [ points_set.AsTs[m][1][i] for i in range(len(points_set.AsTs[m][0])) ] t_min = tis[0] t_max = tis[-1] def K_prime(t): ais = [ points_set.AsTs[m][0][i] for i in range(len(points_set.AsTs[m][0])) ] alphas = [math.sqrt(math.exp(1) / ti) for ti in tis] betas = [-0.5 / ti for ti in tis] return sum([ ais[i] * alphas[i] * betas[i] * math.exp(betas[i] * t) for i in range(len(points_set.AsTs[m][0])) ]) rho = 2. t = t_max while rho > 1: t += t value_at_last_tg_point_K_prime = K_prime(t) value_at_last_tg_point_KB_prime = -1.0 / 2 / t**1.5 rho = abs(value_at_last_tg_point_K_prime / value_at_last_tg_point_KB_prime) security_coeff = 2.0 pp.lower_limits_for_tail[m] = security_coeff * t #print('rho_calc', math.exp(beta_last_exp*(pp.lower_limits_for_tail[m] - t_max))) #print('pp.lower_limits_for_tail[m]', pp.lower_limits_for_tail[m]) #print('lets see', 'm = ', m + 1, 'K / K_B (t) = ', abs(K_prime(pp.lower_limits_for_tail[m]) * 2 * pp.lower_limits_for_tail[m] ** 1.5)) for m in points_set.exponential_indices: F_w = quad.ExactIntegrationOfSinus(pp.final_time, pp.final_time_minus_tw) tis = [pp.t_w * ti for ti in points_set.AsTs[m][1]] F_tail = quad.ExactIntegrationOfTail(pp.final_time, pp.final_time_minus_tw, pp.initial_time, points_set.AsTs[m][0], tis) ApproxIntegral = float(F_w) + float(F_tail) error_bound = ObjectiveFunction(points_set, m, pp) Error = abs(ExactIntegral - ApproxIntegral) points_set.Errors.append(Error) points_set.ErrorBounds.append(error_bound)
def CalculateErrors(points_set, pp, samples=10): Error = 0 error_bound = ObjectiveFunction(points_set, m, pp) tis = [pp.t_w * ti for ti in points_set.AsTs[m][1]] for m in points_set.exponential_indices: for i in range(n_samples): end_time = pp.end_time - 2 * math.pi * i / n_samples end_time_minus_tw = end_time - pp.t_w ExactIntegral = quad.ExactIntegrationOfSinus(end_time) F_w = quad.ExactIntegrationOfSinus(end_time, end_time_minus_tw) tis = [pp.t_w * ti for ti in points_set.AsTs[m][1]] F_tail = quad.ExactIntegrationOfTail(end_time, end_time_minus_tw, 0, points_set.AsTs[m][0], tis) ApproxIntegral = float(F_w) + float(F_tail) error_bound = ObjectiveFunction(points_set, m, pp) Error += abs((ExactIntegral - ApproxIntegral)) points_set.Errors.append(Error / samples) points_set.ErrorBounds.append(error_bound)