-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add minimal pymc example #7281
Add minimal pymc example #7281
Conversation
] |
README.rst
Outdated
mu = x @ betas | ||
|
||
# Likelihood | ||
y = pm.Normal("y", mu, sigma, dims=["trial"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ricardoV94 what might the output be? I think at least having a short story like "imagine we ran an experiment where for different levels of hardness, conducitivty and temperature, we measured Y".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I'm asking what we're measuring in this hypothetical experiment. Just to round out the example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pick one from ChatGPT:
- Material Strength: This could include tensile strength, yield strength, or fatigue strength. These measures could be affected by changes in material hardness and temperature.
- Electrical Properties: Besides conductivity, which is already a variable, YY might represent electrical resistance or capacitance, which can change with temperature and material properties.
- Thermal Properties: Such as thermal expansion or specific heat capacity, which could be influenced by the material's hardness and its conductivity.
- Optical Properties: Such as reflectivity or light absorption, which might change with temperature and the physical state of the material.
- Chemical Reactivity: Rate of a chemical reaction that could be influenced by the material's properties and temperature.
- Phase Changes: The point at which a material changes from solid to liquid (melting point) or from liquid to gas (boiling point), which can be influenced by the material's composition and environmental conditions.
- Durability or Wear Resistance: How well a material can withstand wear or degradation over time, potentially influenced by its hardness and operating temperature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a different example from GPT that I think works better:
Objective: Investigate the effects of sunlight exposure, water amount, and soil nitrogen content on plant growth.
Background: Plant growth can be influenced by multiple factors, and understanding these relationships is crucial for optimizing agricultural practices. In this experiment, we aim to predict the growth of a plant based on three different environmental variables.
Experiment Setup:
Variables:
Independent Variables:
Sunlight Hours (X1): Number of hours the plant is exposed to sunlight daily.
Water Amount (X2): Daily water amount given to the plant (in milliliters).
Soil Nitrogen Content (X3): Percentage of nitrogen content in the soil.
Dependent Variable:
Plant Growth (Y): Measured as the increase in plant height (in centimeters) over a certain period.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, just say data is standardized so the normal draws and likelihood make sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HarshvirSandhu Can you make these changes to the example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
README.rst
Outdated
|
||
# Define coordinate values for all dimensions of the data | ||
coords={ | ||
"trial": range(100), | ||
"features": ["hardness", "conductivity", "temperature"], | ||
"features": ["X1", "X2", "X3"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"features": ["X1", "X2", "X3"], | |
"features": ["sunlight hours", "water amount", "soil nitrogen"], |
README.rst
Outdated
@@ -45,11 +52,20 @@ Linear Regression Example | |||
x_dist = pm.Normal.dist(shape=(100, 3)) | |||
x_data = pm.draw(x_dist, random_seed=seed) | |||
|
|||
# Independent Variables: | |||
# Sunlight Hours (X1): Number of hours the plant is exposed to sunlight daily. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Sunlight Hours (X1): Number of hours the plant is exposed to sunlight daily. | |
# Sunlight Hours: Number of hours the plant is exposed to sunlight daily. |
README.rst
Outdated
|
||
Plant growth can be influenced by multiple factors, and understanding these relationships is crucial for optimizing agricultural practices. | ||
|
||
In this experiment, we aim to predict the growth of a plant based on three different environmental variables. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this experiment, we aim to predict the growth of a plant based on three different environmental variables. | |
Imagine we conduct an experiment to predict the growth of a plant based on three different environmental variables. |
README.rst
Outdated
@@ -36,6 +36,13 @@ Features | |||
|
|||
Linear Regression Example | |||
========================== | |||
|
|||
**Background** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**Background** |
README.rst
Outdated
mu = x @ betas | ||
|
||
# Likelihood | ||
y = pm.Normal("y", mu, sigma, dims=["trial"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
y = pm.Normal("y", mu, sigma, dims=["trial"]) | |
plant_growth = pm.Normal("plant growth (z-scored)", mu, sigma, dims="trial") |
README.rst
Outdated
@@ -137,7 +135,7 @@ sigma 0.511 0.037 0.438 0.575 0.001 0 | |||
with pm.do( | |||
inference_model, | |||
{inference_model["betas"]: inference_model["betas"] * [1, 1, 0]}, | |||
) as heat_death_model: | |||
) as new_model: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) as new_model: | |
) as plant_growth_model: |
README.rst
Outdated
@@ -80,7 +79,7 @@ In this experiment, we aim to predict the growth of a plant based on three diffe | |||
mu = x @ betas | |||
|
|||
# Likelihood | |||
y = pm.Normal("y", mu, sigma, dims=["trial"]) | |||
plant_growth = pm.Normal("plant growth (z-scored)", mu, sigma, dims="trial") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plant_growth = pm.Normal("plant growth (z-scored)", mu, sigma, dims="trial") | |
# Assuming we measure deviation of each plant from baseline | |
plant_growth = pm.Normal("plant growth", mu, sigma, dims="trial") |
random_seed=seed, | ||
) | ||
|
||
pm.stats.summary(idata.predictions, kind="stats") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we show all the summaries outputs? Why only the first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for starters it's TMI and can scare people off. Convergence diagnostics is more advanced than what we want to demo here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I thought you meant more columns, but you meant more rows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean't every time the have pm.stats.summary
, we should show the output. I already removed the extra convergence columns with kind="stats"
. Right now it's only showing for the first usage
========================== ====== ===== ======== ========= | ||
Output mean sd hdi_3% hdi_97% | ||
========================== ====== ===== ======== ========= | ||
plant growth (z-scored)[0] 14.21 0.509 13.232 15.144 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is still the old name ("z-scored").
========================== ====== ===== ======== ========= | ||
Output mean sd hdi_3% hdi_97% | ||
========================== ====== ===== ======== ========= | ||
plant growth (z-scored)[0] 14.153 0.509 13.181 15.096 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also needs updated name.
Having a look at this at the PyData London 2024 hackathon 😄 |
Couldn't commit to this branch, so there's a PR here on another fork: #7358. As of today, the example works on my machine and the outputs reflect the names used in the example. |
Closing in favor of #7358. |
Description
Example is taken from this notebook and made to look like the readme example of sunode
Not sure if the example is placed correctly.
Related Issue
Checklist
Type of change
📚 Documentation preview 📚: https://pymc--7281.org.readthedocs.build/en/7281/