wucy / gptk

Automatically exported from code.google.com/p/gptk
0 stars 0 forks source link

Bug in ModelTrainer::checkGradient #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
==What steps will reproduce the problem?==
Repeated calls of ModelTrainer::checkGradient()

==What is the expected output? What do you see instead?==
Output should be the same for each call, i.e. all calls should output the
same gradient/finite differences. However, there is a slight change in
gradient after each call.

==What is the cause of the problem==
The error function and its gradient, as required by checkGradient(), rely
on stored values (i.e. the covariance function parameters stored in the
covariance function object) rather than parameters. To compute the
error/gradient at a given set of parameters X, we need to:
# set the parameters in the model to X (overriding current parameters)
# call the error/gradient function (which takes no parameter)

This means computing the error/gradient actually changes the state of the
model. This is very likely to break SCG, which needs to compute gradients
without changing the parameters (the parameters only get changed if a step
is taken, which depends on the scale and gradient value). In the current
setting, the model's parameters get changed even if the step is discarded.

==Directions for fix==
I think we should rethink the design slightly here. The error/gradient
methods should take a vector of parameter values as argument and base their
computations on these values, not on the current state of the model. We
want to replace:

 model.setParameters(x);
 g = model.gradient();

with

 g = model.gradient(x);

leaving the parameters of the model unchanged (same for the error function).

Because this requires some thought (it is not straightforward to implement,
as parameters need to be passed to the model, which passes them on to the
covariance function, etc. - this could get messy), I suggest the following
temporary fix. Replace:

 model.setParameters(x);
 g = model.gradient();

with

 xOld = model.getParameters();
 model.setParameters(x);
 g = model.gradient();
 model.setParameters(xOld);

I will implement this for now - and will suggest further changes (for an
improved design) at a later stage.

 g = model.gradient(x);

Original issue reported on code.google.com by remi.bar...@gmail.com on 29 Jun 2009 at 11:38

GoogleCodeExporter commented 9 years ago
Ignore the last line - its a typo. There doesn't seem to be a way to edit the 
issue
once submitted...

Original comment by remi.bar...@gmail.com on 29 Jun 2009 at 11:44

GoogleCodeExporter commented 9 years ago
Above fix applied.

Original comment by remi.bar...@gmail.com on 29 Jun 2009 at 5:03