Skip to content
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

Added property layer viz to sugarscape #2653

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sanika-n
Copy link
Contributor

This PR addresses Issue #2580, I have replaced the normal matplotlib visualization in sugarscape to the property layer visualization with matplotlib as backend.

Before

Screenshot 2025-01-16 141514

After

image

Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔴 +6.5% [+4.8%, +8.2%] 🔵 +0.3% [+0.2%, +0.4%]
BoltzmannWealth large 🔵 +0.5% [-0.3%, +1.6%] 🔵 +0.5% [-2.2%, +2.5%]
Schelling small 🔵 +0.7% [+0.4%, +1.0%] 🔵 -1.1% [-1.2%, -1.0%]
Schelling large 🔵 -0.3% [-0.6%, +0.0%] 🔵 +2.8% [+1.6%, +4.0%]
WolfSheep small 🔵 +2.0% [+1.7%, +2.2%] 🔵 -0.5% [-0.7%, -0.3%]
WolfSheep large 🔵 +1.6% [+0.9%, +2.3%] 🔴 +9.9% [+8.3%, +11.3%]
BoidFlockers small 🔵 +1.3% [+0.2%, +2.4%] 🔵 -0.5% [-0.7%, -0.3%]
BoidFlockers large 🔵 +0.2% [-0.5%, +1.0%] 🔵 -0.8% [-1.1%, -0.4%]

"vmin": 0,
"vmax": 10,
},
"spice": {"color": "red", "alpha": 0.8, "colorbar": True, "vmin": 0, "vmax": 10},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanika-n The formatting here seems off --- are you using the ruff linter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I actually wrote spice in the same way as sugar but when I ran ruff it was changing the formatting of spice and it didn't allow me to keep it like sugar, so now I have made sugar formatted like spice...

Copy link
Member

@tpike3 tpike3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sanika-n -- this code shows the power of property layer.

Just one question as the formatting does not seem to be uniform.

@tpike3 tpike3 added the example Changes the examples or adds to them. label Jan 31, 2025
@quaquel
Copy link
Member

quaquel commented Feb 2, 2025

I had a look at sugarscape a few weeks back as well. It made me realize that the property layer portrayal needs some more work at the API level (see also #2640). However, in the meantime, this looks fine to me. However, could you experiment a bit with colormaps that are more distinct that the current red and blue? Likewise, what happens if you lower the alpha to say 0.5?

@sanika-n
Copy link
Contributor Author

sanika-n commented Feb 3, 2025

So here are some plots with different values of alpha, the reason why there is not much opacity even alpha=1 is that I set vmax to 10, and the sugar and spice levels in this example only go up to 4.
image

Given that the first property layer is sugar and the second is spice, in areas where both spice and sugar equal 10 we will only see a bright red because both colors are completely opaque (alpha=1 and value=vmax) and therefore spice will cover up sugar. I set vmax to 10 to avoid this. However, this case is rare, and I noticed it doesn't come up much in this example, and setting vmax to 4 made the plot more vibrant.
image

Coming to colormaps, I tried a few configurations, but for most of them, I wasn't too happy with how it turned out. The colors were mixing quite a lot with each other.

Example 1:

propertylayer_portrayal = {
    "sugar": {"colormap": "winter", "alpha": 1, "colorbar": True, "vmin": 0, "vmax": 4},
    "spice": {"colormap": "afmhot", "alpha": 0.5, "colorbar": True, "vmin": 0, "vmax": 10},
}

image

Example 2

propertylayer_portrayal = {
    "sugar": {"colormap": "winter", "alpha": 1, "colorbar": True, "vmin": 0, "vmax": 4},
    "spice": {"colormap": "Reds", "alpha": 0.4, "colorbar": True, "vmin": 0, "vmax": 10},
}

image

Example 3:

propertylayer_portrayal = {
    "sugar": {"colormap": "viridis", "alpha": 0.5, "colorbar": True, "vmin": 0, "vmax": 4},
    "spice": {"colormap": "plasma", "alpha": 0.5, "colorbar": True, "vmin": 0, "vmax": 4},
}

image

@quaquel
Copy link
Member

quaquel commented Feb 3, 2025

Thanks for this. I'll think about this a bit more (also in light of the various other visualization and API issues that are popping up). I am inclined to accept this PR while we hash out a better overall API level solution.

@tpike3
Copy link
Member

tpike3 commented Feb 4, 2025

Thanks for this. I'll think about this a bit more (also in light of the various other visualization and API issues that are popping up). I am inclined to accept this PR while we hash out a better overall API level solution.

I concur @quaquel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
example Changes the examples or adds to them.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants