Skip to content

Commit d85a2d8

Browse files
committed
update
1 parent e138cc3 commit d85a2d8

24 files changed

+7717
-660
lines changed

1.Integration.ipynb

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,28 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Integration [source](https://docs.scipy.org/doc/scipy/reference/tutorial/integrate.html)"
7+
"# Integration "
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"|Function|Description|\n",
15+
"|---------|:---------:|\n",
16+
"|```quad```|single integration|\n",
17+
"|```dblquad``` |double integration|\n",
18+
"|```tplquad```|\ttriple integration|\n",
19+
"|```nquad```\t|n-fold multiple integration|\n",
20+
"|```fixed_quad```|\tGaussian quadrature, order n|\n",
21+
"|```quadrature```|\tGaussian quadrature to tolerance|\n",
22+
"|```romberg```|\tRomberg integration|\n",
23+
"|```trapz```|\ttrapezoidal rule|\n",
24+
"|```cumtrapz```|\ttrapezoidal rule to cumulatively compute integral|\n",
25+
"|```simps```|\tSimpson’s rule|\n",
26+
"|```romb```|\tRomberg integration|\n",
27+
"|```polyint```|\tAnalytical polynomial integration (NumPy)|\n",
28+
"|```poly1d```\t|Helper function for polyint (NumPy)|"
829
]
930
},
1031
{

2a.DifferentialEQ-Ordinary.ipynb

+123-489
Large diffs are not rendered by default.

2b.DifferentialEQ-Chaos.ipynb

+293
Large diffs are not rendered by default.

2b.DifferentialEQ-Partial.ipynb 2c.DifferentialEQ-Partial.ipynb

+11-123
Large diffs are not rendered by default.

3.Interpolation.ipynb

-32
This file was deleted.

3a.Algebra-Introduction.ipynb

+662
Large diffs are not rendered by default.

5.LinearAlgebra.ipynb 3b.Algebra-Advanced.ipynb

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"## Linear Algebra \n",
7+
"## Linear Algebra Advanced\n",
88
"\n",
99
"**Resources: [Linear algebra (scipy.linalg)](https://docs.scipy.org/doc/scipy/reference/linalg.html#module-scipy.linalg)**\n",
1010
"\n",
@@ -327,13 +327,6 @@
327327
"### References:\n",
328328
"1. [Scipy Tutorials](https://docs.scipy.org/doc/scipy/reference/tutorial/index.html)"
329329
]
330-
},
331-
{
332-
"cell_type": "code",
333-
"execution_count": null,
334-
"metadata": {},
335-
"outputs": [],
336-
"source": []
337330
}
338331
],
339332
"metadata": {
File renamed without changes.

4b.FourierSeries.ipynb

+612
Large diffs are not rendered by default.

7.SpecialFunctions.ipynb 5a.SpecialFunctions-Bessels.ipynb

-7
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,6 @@
299299
"4. https://www.acs.psu.edu/drussell/Demos/MembraneCircle/Circle.html\n",
300300
"5. http://balbuceosastropy.blogspot.com/2015/06/spherical-harmonics-in-python.html"
301301
]
302-
},
303-
{
304-
"cell_type": "code",
305-
"execution_count": null,
306-
"metadata": {},
307-
"outputs": [],
308-
"source": []
309302
}
310303
],
311304
"metadata": {

5b.SpecialFunctions-SHrmonics.ipynb

+289
Large diffs are not rendered by default.

6a.Optimization-Intro.ipynb

+269
Large diffs are not rendered by default.

6b. Optimization-Scipy-Brute.ipynb

+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Scipy Optimization [Source](https://docs.scipy.org/doc/scipy/reference/optimize.html#module-scipy.optimize)"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"SciPy optimize provides functions for minimizing (or maximizing) objective functions, possibly subject to constraints. It includes solvers for nonlinear problems (with support for both local and global optimization algorithms), linear programing, constrained and nonlinear least-squares, root finding and curve fitting."
15+
]
16+
},
17+
{
18+
"cell_type": "markdown",
19+
"metadata": {},
20+
"source": [
21+
"1. Scalar Functions Optimization\n",
22+
"2. Local (Multivariate) Optimization\n",
23+
"3. Global Optimization\n",
24+
" - **basinhopping** : Find the global minimum of a function using the basin-hopping algorithm\n",
25+
" - **brute** : Minimize a function over a given range by brute force.\n",
26+
" - **differential_evolution** : Finds the global minimum of a multivariate function.\n",
27+
" - **shgo** : Finds the global minimum of a function using SHG optimization.\n",
28+
" - **dual_annealing**: Find the global minimum of a function using Dual Annealing.\n",
29+
"\n",
30+
"\n",
31+
"4. Least-squares and Curve Fitting\n",
32+
"5. Root finding"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"metadata": {},
38+
"source": [
39+
"### Brute Method (Global Optimization)\n",
40+
"\n",
41+
"Minimize a function over a given range by brute force.\n",
42+
"\n",
43+
"Uses the “brute force” method, i.e., computes the function’s value at each point of a multidimensional grid of points, to find the global minimum of the function.\n",
44+
"\n",
45+
"The function is evaluated everywhere in the range with the datatype of the first call to the function, as enforced by the vectorize NumPy function. The value and type of the function evaluation returned when ```full_output=True``` are affected in addition by the finish argument (see Notes).\n",
46+
"\n",
47+
"The brute force approach is inefficient because the number of grid points increases exponentially - the number of grid points to evaluate is ```Ns ** len(x)```. Consequently, even with coarse grid spacing, even moderately sized problems can take a long time to run, and/or run into memory limitations."
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": 6,
53+
"metadata": {},
54+
"outputs": [],
55+
"source": [
56+
"import numpy as np\n",
57+
"import numpy.linalg as la\n",
58+
"import scipy.optimize as sopt\n",
59+
"from scipy.optimize import minimize\n",
60+
"\n",
61+
"import matplotlib.pyplot as pt\n",
62+
"from mpl_toolkits.mplot3d import axes3d\n",
63+
"%matplotlib inline\n",
64+
"import seaborn as sns\n",
65+
"sns.set()"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": 7,
71+
"metadata": {},
72+
"outputs": [],
73+
"source": [
74+
"params = (2, 3, 7, 8, 9, 10, 44, -1, 2, 26, 1, -2, 0.5)\n",
75+
"\n",
76+
"def f1(z, *params):\n",
77+
" x, y = z\n",
78+
" a, b, c, d, e, f, g, h, i, j, k, l, scale = params\n",
79+
" return (a * x**2 + b * x * y + c * y**2 + d*x + e*y + f)\n",
80+
"\n",
81+
"def f2(z, *params):\n",
82+
" x, y = z\n",
83+
" a, b, c, d, e, f, g, h, i, j, k, l, scale = params\n",
84+
" return (-g*np.exp(-((x-h)**2 + (y-i)**2) / scale))\n",
85+
"\n",
86+
"def f3(z, *params):\n",
87+
" x, y = z\n",
88+
" a, b, c, d, e, f, g, h, i, j, k, l, scale = params\n",
89+
" return (-j*np.exp(-((x-k)**2 + (y-l)**2) / scale))\n",
90+
"\n",
91+
"def f(z, *params):\n",
92+
" return f1(z, *params) + f2(z, *params) + f3(z, *params)"
93+
]
94+
},
95+
{
96+
"cell_type": "code",
97+
"execution_count": 8,
98+
"metadata": {},
99+
"outputs": [],
100+
"source": [
101+
"rranges = (slice(-4, 4, 0.25), slice(-4, 4, 0.25))"
102+
]
103+
},
104+
{
105+
"cell_type": "code",
106+
"execution_count": 9,
107+
"metadata": {},
108+
"outputs": [],
109+
"source": [
110+
"from scipy import optimize\n",
111+
"resbrute = optimize.brute(f, rranges, args=params, full_output=True,\n",
112+
" finish=optimize.fmin)"
113+
]
114+
},
115+
{
116+
"cell_type": "code",
117+
"execution_count": 10,
118+
"metadata": {},
119+
"outputs": [
120+
{
121+
"data": {
122+
"text/plain": [
123+
"-3.4085818767996527"
124+
]
125+
},
126+
"execution_count": 10,
127+
"metadata": {},
128+
"output_type": "execute_result"
129+
}
130+
],
131+
"source": [
132+
"resbrute[0] # global minimum\n",
133+
"resbrute[1] # function value at global minimum"
134+
]
135+
},
136+
{
137+
"cell_type": "markdown",
138+
"metadata": {},
139+
"source": [
140+
"------"
141+
]
142+
},
143+
{
144+
"cell_type": "markdown",
145+
"metadata": {},
146+
"source": [
147+
"### References"
148+
]
149+
},
150+
{
151+
"cell_type": "markdown",
152+
"metadata": {},
153+
"source": [
154+
"1. https://andreask.cs.illinois.edu/cs357-s15/public/demos/12-optimization/Steepest%20Descent.html\n",
155+
"2. https://scipy-lectures.org/advanced/mathematical_optimization/auto_examples/plot_gradient_descent.html\n",
156+
"3. https://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html\n",
157+
"4. https://scipy-cookbook.readthedocs.io/index.html\n",
158+
"5. http://folk.ntnu.no/leifh/teaching/tkt4140/._main000.html"
159+
]
160+
}
161+
],
162+
"metadata": {
163+
"kernelspec": {
164+
"display_name": "Python 3",
165+
"language": "python",
166+
"name": "python3"
167+
},
168+
"language_info": {
169+
"codemirror_mode": {
170+
"name": "ipython",
171+
"version": 3
172+
},
173+
"file_extension": ".py",
174+
"mimetype": "text/x-python",
175+
"name": "python",
176+
"nbconvert_exporter": "python",
177+
"pygments_lexer": "ipython3",
178+
"version": "3.7.3"
179+
}
180+
},
181+
"nbformat": 4,
182+
"nbformat_minor": 2
183+
}

6c. Optimization-Manual.ipynb

+485
Large diffs are not rendered by default.

6d. Optimization-Scipy-Nelder-mead.ipynb

+668
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)