필터 지우기
필터 지우기

Fast Element-Wise power to non-integer value

조회 수: 2 (최근 30일)
Alfonso Silva
Alfonso Silva 2023년 2월 23일
댓글: Walter Roberson 2023년 3월 2일
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)
ans = 0.0029
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
  1. bsxfun, however it's included in the .^ command for newer releases
  2. Increase maxNumCompThreads to 8
  3. Relax optimization Tolerance levels
  4. Tried other optimizers (such as lsqnonlin) but deliver worst estimates
  5. write the expression as logarithm and then take exponential (it seems slower in preliminar trials)
Thank you for your comments
All best!
  댓글 수: 4
Alfonso Silva
Alfonso Silva 2023년 2월 23일
Thank you for your replies and for your time. Indeed big problems require some time. I've managed to reduce the time by avoiding unncessary calculations when possible, but ultimately it's about waiting.
Thank you again!
Walter Roberson
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Torsten
Torsten 2023년 2월 23일
편집: Torsten 2023년 2월 23일
I don't know your optimization problem, but this helps saving function evaluations if objective function and constraints share the same function:
  댓글 수: 5
Alfonso Silva
Alfonso Silva 2023년 3월 2일
I'll accept this answer since, the idea of avoiding unnecessary evaluations did work
Thanks!
Walter Roberson
Walter Roberson 2023년 3월 2일
Hmmm I am surprised that guide document does not refer to memoize()

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by