读书笔记 day1:The design of approximation algorithms

Chapter 1


As P not equal to NP, we cannot simultaneously have algorithms that 1. find optimal solutions; 2. in polynomial time; 3. for any instance.

At least one of these requirements need to be relaxed to dealing with NP problem.

The more common approach would be relaxing the requirement of polynomial time solvability. This is the approach taken by those in the field of operations research and mathematical programming or the area of artificial intelligence(like A* search).


But the most common and the book is using, is to relax the requirement of finding an optimal solution and settle for a solution that is "good enough".


Definition 1.1:

An α-approximation algorithm for an optimization problem is a polynomial time algorithm that for all instances of the problem produces a solution whose value is within a factor of α of the value of an optimal solution.


So we call α the performance guarantee of the algorithm, or more often: the approximation ratio or factor of the algorithm.

(α > 1 for minimization problems, and α < 1 for maximization problems)


Note that the worst-case bounds for algorithms are often due to pathological cases that do not arise in practice, so that approximation algorithm often give rise to heuristics that return solutions much closer to optimal than indicated by their performance guarantees.

Here is a possible implementation of a Matlab function that provides the minimax approximation of a given function f on a closed interval or a set of finitely many points: ```matlab function [p, err] = minimax(f, a, b, n) % MINIMAX Computes the minimax approximation of f on [a, b] or on a set of n points. % Define Chebyshev nodes and Chebyshev polynomials x = cos(pi*(0:n-1)/(n-1)).'; T = cos(bsxfun(@times, acos(x), 0:n-1)); % Compute function values at the nodes or at the interval endpoints if isscalar(a) && isscalar(b) % interval case y = f((a+b)/2 + (b-a)/2*x); else % points case y = f(a + (b-a)*x); end % Compute the Chebyshev coefficients of the function c = T\y; % Construct the minimax polynomial using the Chebyshev coefficients p = @(xx) (T*c).*cos(bsxfun(@times, acos(xx), 0:n-1))*[1/2; ones(n-2,1); 1/2]; % Compute the maximum absolute error if isscalar(a) && isscalar(b) % interval case err = norm(f((a+b)/2 + (b-a)/2*x) - p(x), Inf); else % points case err = norm(f(a + (b-a)*x) - p(x), Inf); end end ``` The input arguments of the function are: - `f`: the function to be approximated. It should be a function handle that can be evaluated at a scalar or vector of inputs. - `a`, `b`: the endpoints of the closed interval on which to approximate the function. If `a` and `b` are scalar, the function is approximated on the interval `[a, b]`. If they are vectors of the same size, the function is approximated on the set of `n=numel(a)` points `(a(1), b(1)), ..., (a(n), b(n))`. - `n`: the number of Chebyshev nodes to use in the approximation. If `a` and `b` are scalar, `n` nodes are chosen on the interval `[a, b]`. If they are vectors, `n=numel(a)` nodes are used. The function returns two values: - `p`: a function handle to the minimax polynomial approximation of `f`. - `err`: the maximum absolute error of the approximation. The function works by first computing the Chebyshev nodes `x` and the Chebyshev polynomials `T` up to degree `n-1`. Then, it evaluates the function `f` at the nodes or at the endpoints of the interval, and computes the Chebyshev coefficients `c` of the function using a least-squares fit. Finally, it constructs the minimax polynomial using the Chebyshev coefficients, and computes the maximum absolute error of the approximation. Note that the function uses vectorized operations to improve efficiency and avoid for loops. Also, the function assumes that `f` is continuous and bounded on the interval or set of points, and that the minimax polynomial exists. If these assumptions are not met, the function may produce inaccurate results or fail.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值