dfm / dfm/emcee

Blobs function error

Open
#407 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.6k
Forks
440
PR merge metrics
No merged PRs in 30d

Description

General information:

  • emcee version: 3.1.1
  • platform: Centos7
  • installation method (pip/conda/source/other?): Conda-forge

Problem description:

Expected behavior:

Blobs function

Actual behavior:

After running normally for some time, an error is reported:

378012 Traceback (most recent call last):
378013 File "/home/yuebb/.local/lib/python3.9/site-packages/emcee/ensemble.py", line 492, in compute_log_prob
378014 log_prob = np.array([float(l[0]) for l in results])
378015 File "/home/yuebb/.local/lib/python3.9/site-packages/emcee/ensemble.py", line 492, in
378016 log_prob = np.array([float(l[0]) for l in results])
378017 TypeError: 'float' object is not subscriptable
378018
378019 During handling of the above exception, another exception occurred:
378020
378021 Traceback (most recent call last):
378022 File "/public/data/yuebb/Neutrino/SkyWalker/bin/JUNOMCMC/JUNO_C13_Pool.py", line 146, in
378023 sampler.run_mcmc(starting_guesses, nsteps)
378024 File "/home/yuebb/.local/lib/python3.9/site-packages/emcee/ensemble.py", line 443, in run_mcmc
378025 for results in self.sample(initial_state, iterations=nsteps, **kwargs):
378026 File "/home/yuebb/.local/lib/python3.9/site-packages/emcee/ensemble.py", line 402, in sample
378027 state, accepted = move.propose(model, state)
378028 File "/home/yuebb/.local/lib/python3.9/site-packages/emcee/moves/red_blue.py", line 93, in propose
378029 new_log_probs, new_blobs = model.compute_log_prob_fn(q)
378030 File "/home/yuebb/.local/lib/python3.9/site-packages/emcee/ensemble.py", line 495, in compute_log_prob
378031 log_prob = np.array([float(l) for l in results])
378032 File "/home/yuebb/.local/lib/python3.9/site-packages/emcee/ensemble.py", line 495, in
378033 log_prob = np.array([float(l) for l in results])
378034 TypeError: float() argument must be a string or a number, not 'tuple'

What have you tried so far?:
Minimal example:
import emcee

def log_posterior(theta):
    deltaMSq21, sinSqTheta12, B8Flux, B8NuShift, JUNO_B12, JUNO_Li8, JUNO_C10, JUNO_Be11, JUNO_He6, JUNO_U238, JUNO_Th232, JUNO_ReactorES, JUNO_CCBG, C13CCScale, C13NCScale, ESScale, sinSqThetaW, JUNODetectorESNCEff, JUNODetectorESCCEff = theta
    
    model.setParValue("deltaMSq21", deltaMSq21*1e-5)
    model.setParValue("sinSqTheta12", sinSqTheta12)
    model.setParValue("B8Flux", B8Flux)
    model.setParValue("B8NuShift", B8NuShift)
    model.setParValue("JUNO_B12", JUNO_B12)
    model.setParValue("JUNO_Li8", JUNO_Li8)
    model.setParValue("JUNO_C10", JUNO_C10)
    model.setParValue("JUNO_Be11", JUNO_Be11)
    model.setParValue("JUNO_He6", JUNO_He6)
    model.setParValue("JUNO_U238", JUNO_U238)
    model.setParValue("JUNO_Th232", JUNO_Th232)
    model.setParValue("JUNO_ReactorES", JUNO_ReactorES)

    model.setParValue("JUNO_CCBG", JUNO_CCBG)
    model.setParValue("C13CCScale", C13CCScale)
    model.setParValue("C13NCScale", C13NCScale)
    model.setParValue("ESScale", ESScale)
    model.setParValue("sinSqThetaW", sinSqThetaW)
    model.setParValue("JUNODetectorESNCEff", JUNODetectorESNCEff)
    model.setParValue("JUNODetectorESCCEff", JUNODetectorESCCEff)

    if sinSqTheta12 < 0 or sinSqTheta12 > 1 or deltaMSq21 < 0 or B8Flux < 0 or JUNO_B12 < 0 or JUNO_Li8 < 0 or JUNO_C10 < 0 or JUNO_Be11 < 0 or JUNO_He6 < 0 or JUNO_U238 < 0 or JUNO_Th232 < 0 or JUNO_ReactorES < 0:
        return -np.inf  

    return -0.5*model.getChiSquare(), B8Flux*model.getProb(0), B8Flux*model.getProb(1), B8Flux*model.getProb(2), B8Flux*(model.getProb(1)+model.getProb(2))

#### ignoring some useless code

dtype = [("PhiE", float), ("PhiM", float), ("PhiT", float), ("PhiMT", float)]

filename = data+"_Backend.h5"
#np.save(data+"_original_data.npy", sampler.chain)  # emcee_trace)
backend = emcee.backends.HDFBackend(filename)
backend.reset(nwalkers, ndim)

# with Pool() as pool:
sampler = emcee.EnsembleSampler(nwalkers, ndim, log_posterior,  # pool=pool,
                                # sampler = emcee.EnsembleSampler(nwalkers, ndim, log_posterior,
                                #     # )#,
                                #     # moves=[(emcee.moves.WalkMove(), 1),]) # (emcee.moves.DESnookerMove(), 0.2),],)
                                moves=[(emcee.moves.DEMove(), 1), ],
                                blobs_dtype=dtype,
                                backend=backend,
                                )

sampler.run_mcmc(starting_guesses, nsteps)


# sample code goes here...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal Python example and the compute_log_prob entry point in emcee/ensemble.py, especially the handling shown at lines 492-495. Compare the tuple returned by log_posterior with blobs_dtype, then run sampler.run_mcmc to reproduce the failure. Done means the example completes without the reported TypeError while using blobs_dtype.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.