Skip to content

Commit a47e49e

Browse files
committed
upgrade optimtool
1 parent f3aeaf8 commit a47e49e

File tree

11 files changed

+52
-49
lines changed

11 files changed

+52
-49
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ oh.approt.[函数名]([目标函数], [参数表], [初始迭代点], [正则化
235235

236236
| 方法头 | 解释 |
237237
| ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
238-
| grad(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | 基于梯度方法的邻近近似 |
238+
| grad(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | 基于梯度方法的邻近近似 |
239239

240240
#### FISTA算法(fista)
241241

@@ -245,9 +245,9 @@ oh.fista.[函数名]([目标函数], [参数表], [初始迭代点], [正则化
245245

246246
| 方法头 | 解释 |
247247
| ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
248-
| normal(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | 两步计算一个新点 |
249-
| variant(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | normal法的等价变形 |
250-
| decline(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | 基于函数下降趋势的变体 |
248+
| normal(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | 两步计算一个新点 |
249+
| variant(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | normal法的等价变形 |
250+
| decline(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | 基于函数下降趋势的变体 |
251251

252252
#### Nesterov算法(nesterov)
253253

@@ -257,8 +257,8 @@ oh.nesterov.[函数名]([目标函数], [参数表], [初始迭代点], [正则
257257

258258
| 方法头 | 解释 |
259259
| ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
260-
| seckin(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | 第二类Nesterov加速法 |
261-
| accer(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", lk: float=0.01, tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | 复合优化算法的加速框架 |
260+
| seckin(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | 第二类Nesterov加速法 |
261+
| accer(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", lk: float=0.01, tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | 复合优化算法的加速框架 |
262262

263263
## LICENSE
264264

README_en.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ oh.approt.[Function Name]([Target Function], [Parameters], [Initial Point], [Reg
236236

237237
| head method | explain |
238238
| ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
239-
| grad(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | Proximity approximation based on gradient method |
239+
| grad(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | Proximity approximation based on gradient method |
240240

241241
#### FISTA Algorithms(fista)
242242

@@ -246,9 +246,9 @@ oh.fista.[Function Name]([Target Function], [Parameters], [Initial Point], [Regu
246246

247247
| head method | explain |
248248
| ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
249-
| normal(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | Two step calculation of a new point |
250-
| variant(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | Equivalent deformation of normal method |
251-
| decline(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | Variant based on the downward trend of the function |
249+
| normal(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | Two step calculation of a new point |
250+
| variant(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | Equivalent deformation of normal method |
251+
| decline(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | Variant based on the downward trend of the function |
252252

253253
#### Nesterov Algorithms(nesterov)
254254

@@ -258,8 +258,8 @@ oh.nesterov.[Function Name]([Target Function], [Parameters], [Initial Point], [R
258258

259259
| head method | explain |
260260
| ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
261-
| seckin(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | Nesterov acceleration method of the second kind |
262-
| accer(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", lk: float=0.01, tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | An accelerated method for hybrid optimization algorithm |
261+
| seckin(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | Nesterov acceleration method of the second kind |
262+
| accer(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", lk: float=0.01, tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | An accelerated method for hybrid optimization algorithm |
263263

264264
## LICENSE
265265

examples/doc/_hybrid.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ oh.approt.[函数名]([目标函数], [参数表], [初始迭代点], [正则化
3333

3434
| 方法头 | 解释 |
3535
| ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
36-
| grad(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | 基于梯度方法的邻近近似 |
36+
| grad(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | 基于梯度方法的邻近近似 |
3737

3838
```python
39-
oh.approt.grad(f, x, x_0, verbose=True, epsilon=1e-4)
39+
oh.approt.grad(f, x, x_0, verbose=True)
4040
```
4141

4242
```text
@@ -281,12 +281,12 @@ oh.fista.[函数名]([目标函数], [参数表], [初始迭代点], [正则化
281281

282282
| 方法头 | 解释 |
283283
| ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
284-
| normal(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | 两步计算一个新点 |
285-
| variant(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | normal法的等价变形 |
286-
| decline(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | 基于函数下降趋势的变体 |
284+
| normal(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | 两步计算一个新点 |
285+
| variant(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | normal法的等价变形 |
286+
| decline(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | 基于函数下降趋势的变体 |
287287

288288
```python
289-
oh.fista.normal(f, x, x_0, verbose=True, epsilon=1e-4)
289+
oh.fista.normal(f, x, x_0, verbose=True)
290290
```
291291

292292
```text
@@ -438,11 +438,11 @@ oh.nesterov.[函数名]([目标函数], [参数表], [初始迭代点], [正则
438438

439439
| 方法头 | 解释 |
440440
| ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
441-
| seckin(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | 第二类Nesterov加速法 |
442-
| accer(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", lk: float=0.01, tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-6, k: int=0) -> OutputType | 复合优化算法的加速框架 |
441+
| seckin(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | 第二类Nesterov加速法 |
442+
| accer(funcs: FuncArray, args: ArgArray, x_0: PointArray, mu: float=1e-3, proxim: str="L1", lk: float=0.01, tk: float=0.02, verbose: bool=False, draw: bool=True, output_f: bool=False, epsilon: float=1e-4, k: int=0) -> OutputType | 复合优化算法的加速框架 |
443443

444444
```python
445-
oh.nesterov.accer(f, x, x_0, verbose=True, epsilon=1e-4)
445+
oh.nesterov.accer(f, x, x_0, verbose=True)
446446
```
447447

448448
```text

optimtool/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
from ._version import __version__
3333

3434
if sys.version_info < (3, 7, 0):
35-
raise OSError(f'optimtool-2.6.1 requires Python >=3.7, but yours is {sys.version}')
35+
raise OSError(f'optimtool-2.6.2 requires Python >=3.7, but yours is {sys.version}')

optimtool/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
__version__ = '2.6.1'
21+
__version__ = '2.6.2'

optimtool/example/Lasso.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# SOFTWARE.
2020

2121
from ..base import np, sp
22-
from .._convert import a2m
22+
from .._convert import a2m, p2t
2323
from .._utils import get_value, plot_iteration
2424

2525
from .._typing import NDArray, ArgArray, PointArray, OutputType, DataType
@@ -57,7 +57,8 @@ def gradient(A: NDArray,
5757
assert delta > 0
5858
assert alp > 0
5959
from .._drive import get_f_delta_gradient
60-
args = a2m(args)
60+
args, x_0 = a2m(args), p2t(x_0)
61+
assert args.shape[0] == len(x_0)
6162
funcs = sp.Matrix([0.5*((A*args - b).T)*(A*args - b)])
6263
res = funcs.jacobian(args)
6364
L = np.linalg.norm((A.T).dot(A)) + mu / delta
@@ -111,7 +112,8 @@ def subgradient(A: NDArray,
111112
'''
112113
assert alphak > 0
113114
from .._drive import get_subgradient
114-
args = a2m(args)
115+
args, x_0 = a2m(args), p2t(x_0)
116+
assert args.shape[0] == len(x_0)
115117
funcs = sp.Matrix([0.5*((A*args - b).T)*(A*args - b)])
116118
res = funcs.jacobian(args)
117119
point, f = [], []
@@ -160,7 +162,8 @@ def approximate_point(A: NDArray,
160162
161163
:return: final convergenced point and iterative times, (iterative values in a list).
162164
'''
163-
args = a2m(args)
165+
args, x_0 = a2m(args), p2t(x_0)
166+
assert args.shape[0] == len(x_0)
164167
values, _ = np.linalg.eig((A.T).dot(A))
165168
lambda_ma = max(values)
166169
tk = 1 / np.real(lambda_ma) if isinstance(lambda_ma, complex) else 1 / lambda_ma

optimtool/hybrid/approt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def grad(funcs: FuncArray,
3535
verbose: bool=False,
3636
draw: bool=True,
3737
output_f: bool=False,
38-
epsilon: float=1e-6,
38+
epsilon: float=1e-4,
3939
k: int=0) -> OutputType:
4040
'''
4141
:param funcs: FuncArray, current objective equation constructed with values of `symbols` according to rules.
@@ -47,7 +47,7 @@ def grad(funcs: FuncArray,
4747
:param verbose: bool, iteration point, function value, numbers of iteration after the k-th iteration. default: bool=False.
4848
:param draw: bool, use `bool` to control whether to draw visual images. default: bool=True.
4949
:param output_f: bool, use `bool` to control whether to obtain iterative values of `funcs`. default: bool=False.
50-
:param epsilon: float, used to set the precision of stopping the overall algorithm. default: float=1e-6.
50+
:param epsilon: float, used to set the precision of stopping the overall algorithm. default: float=1e-4.
5151
:param k: int, iterative times is used to measure the difficulty of learning the `funcs` in the algorithm. default: int=0.
5252
5353
:return: final convergenced point and iterative times, (iterative values in a list).

optimtool/hybrid/fista.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def normal(funcs: FuncArray,
3535
verbose: bool=False,
3636
draw: bool=True,
3737
output_f: bool=False,
38-
epsilon: float=1e-6,
38+
epsilon: float=1e-4,
3939
k: int=0) -> OutputType:
4040
'''
4141
:param funcs: FuncArray, current objective equation constructed with values of `symbols` according to rules.
@@ -47,7 +47,7 @@ def normal(funcs: FuncArray,
4747
:param verbose: bool, iteration point, function value, numbers of iteration after the k-th iteration. default: bool=False.
4848
:param draw: bool, use `bool` to control whether to draw visual images. default: bool=True.
4949
:param output_f: bool, use `bool` to control whether to obtain iterative values of `funcs`. default: bool=False.
50-
:param epsilon: float, used to set the precision of stopping the overall algorithm. default: float=1e-6.
50+
:param epsilon: float, used to set the precision of stopping the overall algorithm. default: float=1e-4.
5151
:param k: int, iterative times is used to measure the difficulty of learning the `funcs` in the algorithm. default: int=0.
5252
5353
:return: final convergenced point and iterative times, (iterative values in a list).
@@ -85,7 +85,7 @@ def variant(funcs: FuncArray,
8585
verbose: bool=False,
8686
draw: bool=True,
8787
output_f: bool=False,
88-
epsilon: float=1e-6,
88+
epsilon: float=1e-4,
8989
k: int=0) -> OutputType:
9090
'''
9191
:param funcs: FuncArray, current objective equation constructed with values of `symbols` according to rules.
@@ -97,7 +97,7 @@ def variant(funcs: FuncArray,
9797
:param verbose: bool, iteration point, function value, numbers of iteration after the k-th iteration. default: bool=False.
9898
:param draw: bool, use `bool` to control whether to draw visual images. default: bool=True.
9999
:param output_f: bool, use `bool` to control whether to obtain iterative values of `funcs`. default: bool=False.
100-
:param epsilon: float, used to set the precision of stopping the overall algorithm. default: float=1e-6.
100+
:param epsilon: float, used to set the precision of stopping the overall algorithm. default: float=1e-4.
101101
:param k: int, iterative times is used to measure the difficulty of learning the `funcs` in the algorithm. default: int=0.
102102
103103
:return: final convergenced point and iterative times, (iterative values in a list).
@@ -138,7 +138,7 @@ def decline(funcs: FuncArray,
138138
verbose: bool=False,
139139
draw: bool=True,
140140
output_f: bool=False,
141-
epsilon: float=1e-6,
141+
epsilon: float=1e-4,
142142
k: int=0) -> OutputType:
143143
'''
144144
:param funcs: FuncArray, current objective equation constructed with values of `symbols` according to rules.
@@ -150,7 +150,7 @@ def decline(funcs: FuncArray,
150150
:param verbose: bool, iteration point, function value, numbers of iteration after the k-th iteration. default: bool=False.
151151
:param draw: bool, use `bool` to control whether to draw visual images. default: bool=True.
152152
:param output_f: bool, use `bool` to control whether to obtain iterative values of `funcs`. default: bool=False.
153-
:param epsilon: float, used to set the precision of stopping the overall algorithm. default: float=1e-6.
153+
:param epsilon: float, used to set the precision of stopping the overall algorithm. default: float=1e-4.
154154
:param k: int, iterative times is used to measure the difficulty of learning the `funcs` in the algorithm. default: int=0.
155155
156156
:return: final convergenced point and iterative times, (iterative values in a list).

0 commit comments

Comments
 (0)