Independent parameters in nonlin_residmin

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Independent parameters in nonlin_residmin

phofman
Hi,

Please is there a way to tell nonlin_residmin that some parameters are
related to some items in the residua vector only and do not affect the
other residual vector items? In other words I would like to run single
nonlin_residmin call for fitting multiple parameter sets with
independent results.

The reason is my function takes rather long but can provide results for
all the parameter sets at once.

Details: I am measuring harmonic distortion residua from soundcard
loopback (playrec) using FFT. FFT requires/takes 1 second of data (long
iteration), providing all the harmonic values at once. But each harmonic
is independent from the others. At each iteration I would like to
improve values of all harmonic corrections. Value = amplitude and phase
(2 numbers). Once the correction values for one harmonic frequency
result in low-enough recorded/FFTed distortion amplitude (a single item
in the residuals vector), I do not want to change the found/fitted
values in the next iteration run - they have no impact on residual
vector items for other harmonics.

I could run nonlin_residmin iterations for each harmonic frequency
separately but that would take multiple time.

So far I was not able to find an optimisation parameter for this.

Thanks a lot for any help/hints.

Best regards,

Pavel.


Reply | Threaded
Open this post in threaded view
|

Re: Independent parameters in nonlin_residmin

Olaf Till-2
On Wed, Dec 19, 2018 at 02:16:50PM +0100, Pavel Hofman wrote:

> Hi,
>
> Please is there a way to tell nonlin_residmin that some parameters are
> related to some items in the residua vector only and do not affect the other
> residual vector items? In other words I would like to run single
> nonlin_residmin call for fitting multiple parameter sets with independent
> results.
>
> The reason is my function takes rather long but can provide results for all
> the parameter sets at once.
Hi Pavel,

nonlin_residmin can't prevent your function from computing all
residuals, your function itself has to prevent unnecessary
computations. Your function needs some information for this -- this
information is passed to it by nonlin_residmin. The following
explanation assumes that you use the default gradient function of
nonlin_residmin (the feature is not yet implemented for complex step
derivatives).

In your function, check (e.g. with nargin()) if it is called with a
second argument. This will be the case if the function is called for
gradient determination. The second argument will be a structure with a
field "plabels". plabels{1}{1} should be the number of the parameter
(its index in the parameter vector) whose partial derivative is
currently computed. Your function doesn't need to compute residuals
which are unaffected by this parameter, it can return a constant value
for them.

Olaf

--
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net



signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Independent parameters in nonlin_residmin

phofman
Hi Olaf,

Thanks a lot for your expert reply, I very much appreciate your help.
Honestly, I am just a beginner with optimization functions and do not
know exactly the internal procedure, please excuse my ignorance.

This is the problem - I need my function be called/asked/queried as few
times as possible. Each two pairs of parameters (i.e. quadruples) affect
only their corresponding 2 items in the residual array.

You talk about the plabel cell array with index of parameter whose
partial derivative is currently computed - in my case the ideal solution
would query/compute partial derivatives of all the quadruples (e.g. 10
quandruples) at once.

The function calculates FFT which generates values for all the
frequencies at once. If the function is called for each frequency
separately, the other frequency bins are still being determined and
subsequently dropped/forgotten. Actually my problem is not the actual
FFT calculation (light CPU load), but collecting samples for the FFT
which cannot be sped up as the incoming sample rate is constant and limited.

Or if I could postpone returning the function result until all the
params are asked about in the iteration cycle, and then call the actual
determining code. I looked at the user_interaction setting, perhaps some
multithreaded code blocking at the function until all the params are
queried, then running the determination code and returning corresponding
values to their respective threads... probably unfeasible.

Thanks a lot for your patience.

Best regards,

Pavel.

>
> Hi Pavel,
>
> nonlin_residmin can't prevent your function from computing all
> residuals, your function itself has to prevent unnecessary
> computations. Your function needs some information for this -- this
> information is passed to it by nonlin_residmin. The following
> explanation assumes that you use the default gradient function of
> nonlin_residmin (the feature is not yet implemented for complex step
> derivatives).
>
> In your function, check (e.g. with nargin()) if it is called with a
> second argument. This will be the case if the function is called for
> gradient determination. The second argument will be a structure with a
> field "plabels". plabels{1}{1} should be the number of the parameter
> (its index in the parameter vector) whose partial derivative is
> currently computed. Your function doesn't need to compute residuals
> which are unaffected by this parameter, it can return a constant value
> for them.
>
> Olaf
>



Reply | Threaded
Open this post in threaded view
|

Re: Independent parameters in nonlin_residmin

phofman
>
> The function calculates FFT which generates values for all the
> frequencies at once. If the function is called for each frequency
> separately, the other frequency bins are still being determined and
> subsequently dropped/forgotten.

To clarify - the FFT results cannot be cached after the first call in
the iteration and returned when the other frequency params are queried
as the incoming samples must be modified with the supplied params first
and then the FFT is calculated - it is all part of the function.

I may have to write my own specific-case implementation, using the
lower-level optim functions.

Thanks a lot for any hints,

Pavel.