GithubHelp home page GithubHelp logo

Comments (4)

Samreay avatar Samreay commented on September 16, 2024

Can I confirm you're using the 1.* version of ChainConsumer for this? There's the grid example here. If you can share the wfit file itself I can try to reproduce orioerky,

from chainconsumer.

am610 avatar am610 commented on September 16, 2024

Sorry for the late reply, I missed your previous comment somehow. Here is a URL link where I uploaded the file
https://rb.gy/1u8nz9

I would also like to mention I tried this

the version I have is 1.0.0, I had issues with v. 1.1.2


from chainconsumer import ChainConsumer, Chain
import pandas as pd
import numpy as np

# Define the path and load the data

df = pd.read_csv('DIROPT00000_COVOPT000_FITOPT000_CHI2GRID.DAT', sep=r'\s+', comment='#')

w0 = df.iloc[:, [2]]
wa = df.iloc[:, [3]]

# Calculate weights
weights = np.exp(-0.5 * df['chi2_tot'].values)

# Create a Chain object with the samples and weights
chain = Chain(
    samples= df.iloc[:, [3, 2]],  # w0, wa
    weights=weights,  # Add weights to the chain
    name="Test",  # Add a name
    color="red",  # Add a color
    grid = True
)

# Initialize ChainConsumer and add the chain
c = ChainConsumer()
c.add_chain(chain)


fig = c.plotter.plot(figsize='column')

if you please give your feedback will be useful, thanks.

from chainconsumer.

Samreay avatar Samreay commented on September 16, 2024

I think the main issue here is your computation of weights is incorrect. You need a delta chi2, not the absolute value, and you can see if you inspect the weights you've made they'll be all zero. I should make an issue to support 0 weights better, and also log weights properly, but in the meantime this code should work:

import numpy as np
import pandas as pd

from chainconsumer import Chain, ChainConsumer

# Define the path and load the data
df = pd.read_csv("DIROPT00000_COVOPT000_FITOPT000_CHI2GRID.DAT", sep=r"\s+", comment="#")
# Add a weight column. Theres poor handling of zero weights in ChainConsumer, so I add a small value here
df["weight"] = np.exp(-0.5 * (df["chi2_tot"] - df["chi2_tot"].min())) + 1e-50

# Initialize ChainConsumer and add the chain
c = ChainConsumer()
c.add_chain(Chain(samples=df[["w0", "wa", "weight"]], name="Test", color="red", grid=True))
fig = c.plotter.plot(figsize="column")

tmp

from chainconsumer.

am610 avatar am610 commented on September 16, 2024

Amazing, thank you. this is exactly what I was looking for.

from chainconsumer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.