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

Simple form of y-transform #3127

Merged
merged 14 commits into from
Mar 30, 2024
Merged

Simple form of y-transform #3127

merged 14 commits into from
Mar 30, 2024

Conversation

OAGr
Copy link
Contributor

@OAGr OAGr commented Mar 26, 2024

Experimentation:

toPointSet(dist) = {
  dist: dist -> Tag.startOpen,
  transform: PointSet.yTransform(PointSet.make(dist))
    -> PointSet.mapY(
      {|e| (e > 0 ? log(e) : log(-e)) -> max(-0)}
    )
    -> Tag.startOpen,
}

{
  dist1: toPointSet(mx(Sym.normal(5, 2), Sym.triangular(50, 51, 52))),
  dist2: toPointSet(
    mx(Sym.uniform(0, 1), Sym.uniform(3, 6), Sym.uniform(10, 12))
  ),
  dist3: toPointSet(mx(1, 2, 3, 4, 4)),
  dist4: toPointSet(mx(Sym.triangular(1, 2, 3))),
}

Or maybe:

toPointSet(dist) = {
  transform1 = Danger.yTransform(PointSet.make(dist))
  transform2 = Danger.yTransform(transform1)
  transform3 = Danger.yTransform(transform2)

  {
    dist: dist -> Tag.startOpen,
    transform1: transform1 -> Tag.startOpen,
    transform2: transform2 -> Tag.startOpen,
    transform3: transform3 -> Tag.startOpen,
  }
}

{
  dist1: toPointSet(
    mx(
      PointSet(normal(5, 2)),
      PointSet(triangular(50, 51, 52)),
      PointSet(uniform(60, 70))
    )
  ),
  dist5: toPointSet(normal(5, 2)),
  dist2: toPointSet(
    mx(Sym.uniform(0, 1), Sym.uniform(3, 6), Sym.uniform(10, 12))
  ),
  dist3: toPointSet(mx(1, 2, 3, 4, 4)),
  dist4: toPointSet(mx(triangular(1, 2, 3))),
}

My impression is that it's doing okay for continuous, but breaking for discrete.

Copy link

changeset-bot bot commented Mar 26, 2024

🦋 Changeset detected

Latest commit: 03b8164

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 26, 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 30, 2024 8:44pm
squiggle-components ✅ Ready (Inspect) Visit Preview Mar 30, 2024 8:44pm
squiggle-website ✅ Ready (Inspect) Visit Preview Mar 30, 2024 8:44pm
1 Ignored Deployment
Name Status Preview Updated (UTC)
quri-ui ⬜️ Ignored (Inspect) Visit Preview Mar 30, 2024 8:44pm

@OAGr
Copy link
Contributor Author

OAGr commented Mar 27, 2024

Seems like it's kind of working, but messing up with Uniform distributions.

image

@OAGr OAGr marked this pull request as ready for review March 28, 2024 17:04
@OAGr OAGr requested a review from berekuk as a code owner March 28, 2024 17:04
Copy link
Collaborator

@berekuk berekuk left a comment

Choose a reason for hiding this comment

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

I haven't read the tests, but tested this in the playground and output seems mostly fine.

Because of EPSILON and numeric issues, the output will be buggy for multiple transforms applied in a row, but I can't find a quick way to fix that.

packages/squiggle-lang/src/yTransform.ts Outdated Show resolved Hide resolved
const x1 = shape.xs[i];
const x2 = shape.xs[i + 1];
const y1 = shape.ys[i];
const y2 = shape.ys[i + 1];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not that fond of overdoing FP, but in this case maybe having a common E_A.forEachPair(() => { ... }) would make sense.

(E_A.forEachPair : Array.forEach :: E_A.pairwise : Array.map)


rectangles.push({
x1: Math.min(y1, y2),
x2: Math.max(y1, y2),
Copy link
Collaborator

Choose a reason for hiding this comment

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

(minor)

I'd probably swap y1 and y2 early on to avoid these min/max calls. Like,

let y1 = ...;
let y2 = ...;
if (y1 > y2) [y1, y2] = [y2, y1];

for (let i = 0; i < keys.length; i++) {
result.push([keys[i], y]);
y += map.get(keys[i])!;
result.push([keys[i], y]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should add Number.EPSILON; XYShapes with identical xs values are not valid, as we discussed in DMs.
(this is still hacky but we don't have real stepwise XYShapes yet)

This is my code but it works identical as your previous version, and changing this would require test updates, so I'll leave this for you to improve (or keep as is and deal with bugs later; both versions would be buggy, for different reasons).

Co-authored-by: Slava Matyukhin <me@berekuk.ru>
* main:
  changeset
  implement Common.try
  Create khaki-lamps-repair.md
  fix x = {||...} -> ... parser bug; avoid extra block nodes in AST
  minor refactorings
  rename #indexLookup to forbid overrides
  clean up types
  remove FRFunction.output
  Create early-moons-return.md
  support != in lezer grammar (fixes #3071)
  upgrade to turbo 1.13
  ts fixes for latest pothos
  fix DefaultAuthStrategy
  Minor cleanup
  Dist chart can now show negative values
  First pass at handling negative dists
  ⬆️ Bump @pothos/plugin-prisma from 3.63.1 to 3.64.0
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