- Introduction to Python
- Getting started with Python and the IPython notebook
- Functions are first class objects
- Data science is OSEMN
- Working with text
- Preprocessing text data
- Working with structured data
- Using SQLite3
- Using HDF5
- Using numpy
- Using Pandas
- Computational problems in statistics
- Computer numbers and mathematics
- Algorithmic complexity
- Linear Algebra and Linear Systems
- Linear Algebra and Matrix Decompositions
- Change of Basis
- Optimization and Non-linear Methods
- Practical Optimizatio Routines
- Finding roots
- Optimization Primer
- Using scipy.optimize
- Gradient deescent
- Newton’s method and variants
- Constrained optimization
- Curve fitting
- Finding paraemeters for ODE models
- Optimization of graph node placement
- Optimization of standard statistical models
- Fitting ODEs with the Levenberg–Marquardt algorithm
- 1D example
- 2D example
- Algorithms for Optimization and Root Finding for Multivariate Problems
- Expectation Maximizatio (EM) Algorithm
- Monte Carlo Methods
- Resampling methods
- Resampling
- Simulations
- Setting the random seed
- Sampling with and without replacement
- Calculation of Cook’s distance
- Permutation resampling
- Design of simulation experiments
- Example: Simulations to estimate power
- Check with R
- Estimating the CDF
- Estimating the PDF
- Kernel density estimation
- Multivariate kerndel density estimation
- Markov Chain Monte Carlo (MCMC)
- Using PyMC2
- Using PyMC3
- Using PyStan
- C Crash Course
- Code Optimization
- Using C code in Python
- Using functions from various compiled languages in Python
- Julia and Python
- Converting Python Code to C for speed
- Optimization bake-off
- Writing Parallel Code
- Massively parallel programming with GPUs
- Writing CUDA in C
- Distributed computing for Big Data
- Hadoop MapReduce on AWS EMR with mrjob
- Spark on a local mahcine using 4 nodes
- Modules and Packaging
- Tour of the Jupyter (IPython3) notebook
- Polyglot programming
- What you should know and learn more about
- Wrapping R libraries with Rpy
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
Finding roots
For root finding, we generally need to proivde a starting point in the vicinitiy of the root. For iD root finding, this is often provided as a bracket (a, b) where a and b have opposite signs.
Univariate roots and fixed points
def f(x): return x**3-3*x+1
x = np.linspace(-3,3,100) plt.axhline(0) plt.plot(x, f(x));
from scipy.optimize import brentq, newton
brentq(f, -3, 0), brentq(f, 0, 1), brentq(f, 1,3)
(-1.8794, 0.3473, 1.5321)
newton(f, -3), newton(f, 0), newton(f, 3)
(-1.8794, 0.3473, 1.5321)
Finding fixed points
Finding the fixed points of a function \(g(x) = x\) is the same as finding the roots of \(g(x) - x\). However, specialized algorihtms also exist - e.g. using scipy.optimize.fixedpoint
.
from scipy.optimize import fixed_point
def f(x, r): """Discrete logistic equation.""" return r*x*(1-x)
n = 100 fps = np.zeros(n) for i, r in enumerate(np.linspace(0, 4, n)): fps[i] = fixed_point(f, 0.5, args=(r, ))
plt.plot(np.linspace(0, 4, n), fps);
Mutlivariate roots and fixed points
from scipy.optimize import root, fsolve
def f(x): return [x[1] - 3*x[0]*(x[0]+1)*(x[0]-1), .25*x[0]**2 + x[1]**2 - 1]
sol = root(f, (0.5, 0.5)) sol
status: 1 success: True qtf: array([ -1.4947e-08, 1.2702e-08]) nfev: 21 r: array([ 8.2295, -0.8826, -1.7265]) fun: array([ -1.6360e-12, 1.6187e-12]) x: array([ 1.1169, 0.8295]) message: 'The solution converged.' fjac: array([[-0.9978, 0.0659], [-0.0659, -0.9978]])
f(sol.x)
[-0.0000, 0.0000]
sol = root(f, (12,12)) sol
status: 1 success: True qtf: array([ -1.5296e-08, 3.5475e-09]) nfev: 33 r: array([-10.9489, 6.1687, -0.3835]) fun: array([ 4.7062e-13, 1.4342e-10]) x: array([ 0.778 , -0.9212]) message: 'The solution converged.' fjac: array([[ 0.2205, -0.9754], [ 0.9754, 0.2205]])
f(sol.x)
[0.0000, 0.0000]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论