Fast Element-Wise power to non-integer value
古いコメントを表示
I am working on a non-linear optimization problem using fmincon. My current setup delivers the best results so far in simulations.
Now I am working on optimizing my code and I have a bottle-neck in computation time in the expression:
(1-(1-x.^a).^b);
where 'x' is a vector of Nx1 observations, with N "medium-large" (> 30000 rows). Moreover, 'a' and 'b' are non-integer parameters > 0 (to be fitted)
f is the function that I am minimizing, thus, it's called by the optimizer several times (90000 in my current setting) resulting in a significant bottleneck in the overall procedure.
Are there any ways to improve the speed of this calculation? According to the code, profiler, this line is responsible for 25% of the total computation time in seconds. A replicable example is shown below:
%Example
N = 30000;
x = linspace(0,1,N)'; %vector of N x 1
a = 1.2; %positive non-integer power
b = 0.3; %positive non-integer power
f3 = @() (1-(1-x.^a).^b);
timeit(f3)
Although it seems fast, if the function is called by the optimization procedure 90000 times, then the total time is around 0.0029*90000 = 261 seconds
Question:
Is there any way to make this computation faster? So far, I've tried
- bsxfun, however it's included in the .^ command for newer releases
- Increase maxNumCompThreads to 8
- Relax optimization Tolerance levels
- Tried other optimizers (such as lsqnonlin) but deliver worst estimates
- write the expression as logarithm and then take exponential (it seems slower in preliminar trials)
Thank you for your comments
All best!
4 件のコメント
Bruno Luong
2023 年 2 月 23 日
編集済み: Bruno Luong
2023 年 2 月 23 日
If you want to find 2 parameters to fit 30000 data, you could probably some sort of agregate your data and fit with a less overdertermined system, and quicker to evaluate.
You could use such strategy i a hirarchy of problems: to approach the solution, then using the solution to starting point of another lesser agregated modified problem, and make the convergence with less number of iterations than 90000.
John D'Errico
2023 年 2 月 23 日
編集済み: John D'Errico
2023 年 2 月 23 日
Big problems take big time. Why would they have implemented a slower method than possible of raising a number to a power?
Note that for large arrays, MATLAB will already automatically use multiple cores. However, 30000 is not really that large. In a quick test, I tried a test with a 20000x20000 matrix, then raised those elements to a non-integer power. It took that large of a matrix before I started to see multiple cores being seriously used.
Alfonso Silva
2023 年 2 月 23 日
Walter Roberson
2023 年 2 月 23 日
[I was wondering whether it would be effective to taylor f3 to a reasonable number of terms. I experimented with taylor around b = 0.5 (midpoint of the range), tested at 0.1 0.2 0.3 0.4... and the results for order 10 or order 20 were not encouraging.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Get Started with Optimization Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!