@@ -85,12 +85,18 @@ function grid_and_sample(lnPs::Vector{<:BatchedReal}, xs::AbstractVector; kwargs
8585 ((batch (getindex .(batches,i)) for i= 1 : 3 ). .. ,)
8686end
8787
88- function grid_and_sample (lnPs:: Vector , xs:: AbstractVector ; progress= false , nsamples= 1 , span= 0.25 )
88+ function grid_and_sample (lnPs:: Vector , xs:: AbstractVector ; progress= false , nsamples= 1 , span= 0.25 , require_convex = false )
8989
9090 # trim leading/trailing zero-probability regions
9191 support = findnext (isfinite,lnPs,1 ): findprev (isfinite,lnPs,length (lnPs))
9292 xs = xs[support]
9393 lnPs = lnPs[support]
94+
95+ if require_convex
96+ support = longest_run_of_trues (finite_second_derivative (lnPs) .< 0 )
97+ xs = xs[support]
98+ lnPs = lnPs[support]
99+ end
94100
95101 # interpolate PDF
96102 xmin, xmax = first (xs), last (xs)
@@ -222,8 +228,10 @@ function sample_joint(
222228
223229 θstarts = if θstart == :prior
224230 [map (range-> batch ((first (range) .+ rand (D) .* (last (range) - first (range))). .. ), θrange) for i= 1 : nchains]
225- elseif ( θstart isa NamedTuple)
231+ elseif θstart isa NamedTuple
226232 fill (θstart, nchains)
233+ elseif θstart isa Vector{<: NamedTuple }
234+ θstart
227235 else
228236 error (" `θstart` should be either `nothing` to randomly sample the starting value or a NamedTuple giving the starting point." )
229237 end
@@ -236,6 +244,8 @@ function sample_joint(
236244 fill (batch (zero (diag (ds (). Cϕ)), D), nchains)
237245 elseif ϕstart isa Field
238246 fill (ϕstart, nchains)
247+ elseif ϕstart isa Vector{<: Field }
248+ ϕstart
239249 elseif ϕstart in [:quasi_sample , :best_fit ]
240250 pmap (θstarts) do θstart
241251 MAP_joint (adapt (storage,ds (;θstart... )), progress= (progress== :verbose ? :summary : false ), Nϕ= adapt (storage,Nϕ), quasi_sample= (ϕstart== :quasi_sample ); MAP_kwargs... ). ϕ
@@ -277,9 +287,11 @@ function sample_joint(
277287
278288 for chunks_index = (chunks_index+ 1 ): (nsamps_per_chain÷ nchunk+ 1 )
279289
290+ println (" starting" )
280291 last_chunks = pmap (last .(last_chunks)) do state
281292
282293 @unpack i,ϕ°,f,θ = state
294+ @show i
283295 f,ϕ°,ds,Nϕ = (adapt (storage, x) for x in (f,ϕ°,dsₐ,Nϕₐ))
284296 dsθ = ds (θ)
285297 ϕ = dsθ. G\ ϕ°
0 commit comments