university-of-newcastle-research / pmwg

Repository for code for the Samplers Team at UoN
3 stars 3 forks source link

[BUG] If all samples accepted, check_adapted fails #43

Closed gjcooper closed 3 years ago

gjcooper commented 3 years ago

Describe the bug When the check_adapted call is run it tests for the number of accepted particles for each subject, however if every particle has been accepted it fails (returns a matrix full of 1's instead of a vector full of counts)

To Reproduce Run adaptation on a not successfully burnt in object and this may happen. Gavin has a post_adapt.RData file that seems to exhibit this behaviour to work with.

Expected behavior If > 20 new particles accepted (ie each particle is unique with > 20 iterations) then adaptation should succeed.

Additional context original email from Andrew Heathcote:

Then the sapply(…,length) gives you the number of unique values, which works when the apply returns a list because the unique returns vectors of different lengths. However, in my case every sample is always unique so I get a matrix (i.e., all 100 iterations for every one of the 80 subjects, so I get 100 x 80 matrix back every time for each of my 19 parameters).

for (i in 1:19) {
  one_par <- hsA$samples$alpha[i,,hsA$samples$stage == "adapt"]
  u_one_par <- apply(one_par, 1, unique)
  if (is.list(u_one_par)) print(sapply(u_one_par,length)) else 
    print(dim(u_one_par))
}
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80
[1] 100  80

Hence, I dont understand the test as run_adapt terminated with a message saying I need to run more, whereas this test seems to indicate that I have many more than 20.

gjcooper commented 3 years ago

Closed by commit 2e25f81