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

Distribution Support & Mixed Sets #3115

Merged
merged 12 commits into from
Mar 27, 2024
Merged

Distribution Support & Mixed Sets #3115

merged 12 commits into from
Mar 27, 2024

Conversation

OAGr
Copy link
Contributor

@OAGr OAGr commented Mar 20, 2024

  • Introduces a new fundamental type, the MixedSet, which is basically a Set of continuous ranges and discrete values. You can think about this like "The domain that a Mixed distribution can take".
  • Introduces support functions to PointSet distributions, to get their support. This is a Mixed Set.
  • Adds new extractSubsetThatSatisfiesThreshold function to XYShape. This is kind of complicated. We only use part of it for support(), but the rest was easy, and could be useful for later.

Most of this is done in squiggle-lang and isn't exposed to the function registry. However, two functions are - PointSet.support and subtracting MixedSet values. MixedSet values are just stored and provided as Dicts.

first = PointSet.support(mx(Sym.uniform(1, 5), Sym.uniform(10, 30)))
a = first - PointSet.support(mx(Sym.uniform(3, 8), Sym.uniform(20, 22)))

image

Copy link

changeset-bot bot commented Mar 20, 2024

🦋 Changeset detected

Latest commit: 6b9e653

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@quri/squiggle-lang Patch
@quri/squiggle-components Patch
@quri/prettier-plugin-squiggle Patch
@quri/versioned-squiggle-components Patch
vscode-squiggle Patch
@quri/squiggle-textmate-grammar Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Mar 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
quri-hub ✅ Ready (Inspect) Visit Preview Mar 27, 2024 8:39pm
squiggle-components ✅ Ready (Inspect) Visit Preview Mar 27, 2024 8:39pm
squiggle-website ✅ Ready (Inspect) Visit Preview Mar 27, 2024 8:39pm
1 Ignored Deployment
Name Status Preview Updated (UTC)
quri-ui ⬜️ Ignored (Inspect) Visit Preview Mar 27, 2024 8:39pm

@@ -232,6 +233,10 @@ export class DiscreteShape implements PointSet<DiscreteShape> {
(t) => t.shapeMap(XYShape.T.square).mean()
);
}

domain() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

todo: Change to "support"

packages/squiggle-lang/src/value/VMixedSet.ts Outdated Show resolved Hide resolved
packages/squiggle-lang/src/fr/mixedSet.ts Show resolved Hide resolved
packages/squiggle-lang/src/utility/MixedSet.ts Outdated Show resolved Hide resolved
packages/squiggle-lang/src/XYShape.ts Outdated Show resolved Hide resolved
packages/squiggle-lang/src/XYShape.ts Outdated Show resolved Hide resolved
packages/squiggle-lang/src/XYShape.ts Outdated Show resolved Hide resolved
case "lesserThan":
return y < _threshold;
case "equals":
return Math.abs(y - _threshold) < Number.EPSILON;
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are probably subtle bugs here, or, at least, this boundary is arbitrary; Number.EPSILON is not the smallest representable number.

Not sure if this is important.

return {
points: sortBy(points, ([x]) => x),
segments,
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

General thoughts on this function, without going into details too much:

  • there are a few things here that could be optimized (e.g. multiple calls to comparisonIsSatisfied), but it's not very important
  • I'm kinda sad about it, because by now I did ~3 attempts to rewrite and clean up XYShape; it's hard to do incrementally and hard to do in a single day; so the more code this file has, the harder it'll be to do
  • but I guess it's worth it and not a blocker for the PR

Copy link
Contributor Author

@OAGr OAGr Mar 27, 2024

Choose a reason for hiding this comment

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

so the more code this file has, the harder it'll be to do

I agree, but at the same time, I don't expect it to be too bad to convert this to any other XYShape format, especially with tests + LLMs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, I wasn't very focused on optimization. I don't expect we'll call this too often, and we can optimize if it ever seems like we'll want to, later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants