Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Linearizes two term posynomials """
def tangent_point_func(k, x, eps): """ the function used to calculate the tangent points :param k: the point of tangency :param x: the old intersection point :param eps: the error :return: the equation of the tangent line """ # warnings.simplefilter("ignore"): # this is making things slower
def intersection_point_func(x, a, b, eps): """ the function used to calculate the intersection points :param x: the break point to be solved for :param a: the slope of the tangent line :param b: the intercept of the tangent line :param eps: the linearization error :return: the break point equation """
def iterate_two_term_posynomial_linearization_coeff(r, eps): """ Finds the appropriate slopes, intercepts, tangency points, and intersection points for a given linearization error and number of piecewise linear sections :param r: the number of piecewise linear sections :param eps: linearization error :return: the slopes, intercepts, tangency points, and intersection points """ raise Exception('The number of piece-wise sections should two or larger')
1 + np.exp(tangent_point)) tangent_point + 1, args=(slope, intercept, eps))
def compute_two_term_posynomial_linearization_coeff(r, tol): """ Calculates the slopes, intercepts, tangency points, intersection points, and linearization error for a given number of piecewise-linear sections
:param r: the number of piecewise-linear sections :param tol: tolerance of the linearization parameters :return: slopes, intercepts, tangency points, intersection points, and linearization error """ a = None b = None x_tangent = None x_intersection = None
eps = None eps_min = 0 eps_max = np.log(2) delta = 100 delta_old = 200
while delta > tol and delta != delta_old: delta_old = delta eps = (eps_max + eps_min) / 2 x_final_theoretical = -np.log(np.exp(eps) - 1) number_of_actual_r, a, b, x_tangent, x_intersection = \ LinearizeTwoTermPosynomials.iterate_two_term_posynomial_linearization_coeff(r, eps)
x_final_actual = x_intersection[-1]
if x_final_actual > x_final_theoretical or number_of_actual_r < r: eps_max = eps else: eps_min = eps delta = np.abs(x_final_actual - x_final_theoretical) return a, b, x_tangent, x_intersection, eps
def two_term_posynomial_linearization_coeff(r): """ Reads the slopes, intercepts, tangency points, intersection points, and linearization error for a given number of piecewise-linear sections from a text file
:param r: the number of piecewise-linear sections :return: slopes, intercepts, tangency points, intersection points, and linearization error """ raise Exception('The number of piece-wise sections should two or larger')
else: return LinearizeTwoTermPosynomials.compute_two_term_posynomial_linearization_coeff(r, 2*np.finfo(float).eps)
""" Approximates a two term posynomial constraint by upper and lower piecewise-linear constraints
:param m: the index of the constraint :param r: the number of piecewise-linear sections :return: the deprived of data upper and lower constraints and the common data containing constraints """ raise Exception('The number of piece-wise sections should be two or larger')
raise Exception('The posynomial is larger than a two term posynomial')
return [], [], [self.p <= 1]
second_monomial ** a[i] * np.exp(b[i]) <= w]
pass |