import matplotlib.pyplot as pp
import numpy as np
def g( x ):
return np.exp( x )
def f( x ):
return np.sin( x )
x = np.linspace( -4.0, 4.0 )
pp.plot( x, f( x ) )
pp.plot( x, g( f( x ) ) )
pp.show()
Seja $\def\vect{\boldsymbol}$$\vect x^* \in \mathbb R^n$ um minimizador local de $f$, então, existe $\epsilon > 0$ tal que: $$ \|\vect y - \vect x^* \| \leq \epsilon \Rightarrow f( \vect y ) \ge f( \vect x^* ). $$
Mas, como $g$ é crescente, temos $$ f( \vect y ) \ge f( \vect x^* ) \Rightarrow g\bigl( f( \vect y ) \bigr) \ge g\bigl( f( \vect x^* ) \bigr) $$ além disso como $g$ é estritamente crescente, $$ f( \vect y ) > f( \vect x^* ) \Rightarrow g\bigl( f( \vect y ) \bigr) > g\bigl( f( \vect x^* ) \bigr). $$
Portanto: $$ \|\vect y - \vect x^* \| \leq \epsilon \Rightarrow f( \vect y ) \ge f( \vect x^* ) \Leftrightarrow g\bigl( f( \vect y ) \bigr) \ge g\bigl( f( \vect x^* ) \bigr). $$
$$ f( \vect x ) = \| A\vect x- \vect b \| = \sqrt{ \sum_{i = 1}^m\bigl( (A\vect x)_i - b_i \bigr)^2 } $$ $$ F( \vect x ) = \frac12f^2( \vect x ) =\frac12\sum_{i = 1}^m\bigl( (A\vect x)_i - b_i \bigr)^2 $$
$$ \nabla F( \vect x ) = A^T( A\vect x - \vect b ). $$
$$ A^T( A\vect x^* - \vect b ) = \vect 0 \Leftrightarrow A^TA\vect x^* = A^T\vect b. $$
$$ A \in \mathbb R^{m \times n} $$ $$ A^T \in \mathbb R^{n \times m} $$ portanto, $$ A^TA \in \mathbb R^{n \times n} $$
import sympy as sym
def f( x_1, x_2 ):
return ( x_1 ** 3 + x_2 ) ** 2 + 2 * ( x_2 - x_1 - 4 ) ** 4
( x_1, x_2 ) = sym.symbols( 'x_1, x_2' )
print( x_1, x_2 )
print( f( x_1, x_2 ).subs( x_1, x_1 + x_2 ).expand().factor( x_2 ) )
( l, d_1, d_2 ) = sym.symbols( r'\lambda, d_1, d_2' )
print( f( x_1 + l * d_1, x_2 + l * d_2 ) )
import IPython
def show_expr( expr ):
IPython.display.display( IPython.display.Math( sym.latex( expr ) ) )
show_expr( f( x_1 + l * d_1, x_2 + l * d_2 ) )
g = f( x_1 + l * d_1, x_2 + l * d_2 ).subs( x_1, 0 )\
.subs( x_2, 0 )\
.subs( d_1, 1 )\
.subs( d_2, 1 )
show_expr( g.simplify().diff( l, 2 ).subs( l, 0 ) )
$$ \min_{\vect x \in \mathbb R^n} \quad \frac12\| A \vect x - \vect b \|^2 $$ $$ A^TA\vect x = A^T\vect b $$
Seja $A \in \mathbb R^{m \times n}$, então $$ A = U\Sigma V^T, $$ onde $U\in \mathbb R^{m \times m}$ e $V \in \mathbb R^{n \times n}$ são ortonormais e $\sigma \in \mathbb R_+^{m \times n}$ é diagonal.
A = np.array( [ [ 10, 10, 32, 5.47 ], [ 10, 10, 32, 5.47 ], [ 10, 10, 32, 5.47 ] ] )
print( A )
( U, S, V ) = np.linalg.svd( A, full_matrices = True )
print( U )
print( S )
print( V )
print( V @ V.T )
$$ A^TA = ( U\Sigma V^T )^TU\Sigma V^T = V\Sigma^TU^T U\Sigma V^T = V \overline\Sigma V^T $$
$$ A^TA\vect x = A^T\vect b $$ $$ V \overline\Sigma V^T\vect x = V\Sigma^TU^T\vect b $$ $$ V^T V\overline\Sigma V^T\vect x = V^TV\Sigma^TU^T\vect b $$ $$ \overline\Sigma V^T\vect x = \Sigma^TU^T\vect b $$
s1 = np.array( [ [ 1, 0 ], [0, 0], [ 0, 0 ] ] )
print( s1 )
print( s1.T )