Formatted

This commit is contained in:
Ozzie Gooen 2022-07-28 17:00:06 -07:00
parent f7834b0f46
commit b37e372815
6 changed files with 71 additions and 47 deletions

View File

@ -9,7 +9,7 @@ Much of the Squiggle math is imprecise. This can cause significant errors, so wa
Below are a few specific examples to watch for. We'll work on improving these over time and adding much better warnings and error management.
## Operations on very small or large numbers, silently round to 0 and 1
## Operations on very small or large numbers, silently round to 0 and 1
Squiggle is poor at dealing with very small or large numbers, given fundamental limitations of floating point precision.
See [this Github Issue](https://github.com/quantified-uncertainty/squiggle/issues/834).
@ -38,4 +38,4 @@ The means of sample set distributions can vary dramatically, especially as the n
defaultCode={`symbolicDist = 5 to 50333333
sampleSetDist = SampleSet.fromDist(symbolicDist)
[mean(symbolicDist), mean(sampleSetDist), symbolicDist, sampleSetDist]`}
/>
/>

View File

@ -51,4 +51,4 @@ It might be useful to allow people to annotate functions and variables with long
Right now, Monte Carlo simulations are totally random. It would be nicer to be able to enter a seed somehow in order to control the randomness. Or, with the same seed, the function should always return the same values. This would make debugging and similar easier.
**Caching/Memoization**
There are many performance improvements that Squiggle could have. We'll get to some of them eventually.
There are many performance improvements that Squiggle could have. We'll get to some of them eventually.

View File

@ -35,7 +35,9 @@ If both values are above zero, a `lognormal` distribution is used. If not, a `no
<SquiggleEditor defaultCode="-5 to -3" />
</TabItem>
<TabItem value="ex4" label="1 to 10000">
It's very easy to generate distributions with very long tails. These can be impossible to see without changing view settings. (These settings are available in the Playground, but not this smaller editor component)
It's very easy to generate distributions with very long tails. These can be
impossible to see without changing view settings. (These settings are
available in the Playground, but not this smaller editor component)
<SquiggleEditor defaultCode="1 to 10000" />
</TabItem>
</Tabs>
@ -69,7 +71,7 @@ If both values are above zero, a `lognormal` distribution is used. If not, a `no
`mixture(...distributions: Distribution[], weights?: number[])`
`mx(...distributions: Distribution[], weights?: number[])`
`mixture(distributions: Distributions[], weights?: number[])`
`mx(distributions: Distributions[], weights?: number[])`
`mx(distributions: Distributions[], weights?: number[])`
The `mixture` mixes combines multiple distributions to create a mixture. You can optionally pass in a list of proportional weights.
@ -283,10 +285,7 @@ Creates a [beta distribution](https://en.wikipedia.org/wiki/Beta_distribution) w
<TabItem value="ex5" label="beta(0.8, 0.8)">
<SquiggleEditor defaultCode="beta(0.8, 0.8)" />
</TabItem>
<TabItem
value="ex6"
label="beta({mean: 0.39, stdev: 0.1})"
>
<TabItem value="ex6" label="beta({mean: 0.39, stdev: 0.1})">
<SquiggleEditor defaultCode="beta({mean: 0.39, stdev: 0.1})" />
</TabItem>
</Tabs>
@ -378,12 +377,14 @@ Creates a sample set distribution using an array of samples.
Creates a continuous point set distribution using a list of points.
<SquiggleEditor defaultCode={`PointSet.makeContinuous([
<SquiggleEditor
defaultCode={`PointSet.makeContinuous([
{ x: 0, y: 0.1 },
{ x: 1, y: 0.2 },
{ x: 2, y: 0.15 },
{ x: 3, y: 0.1 }
])`} />
])`}
/>
### Arguments
@ -395,13 +396,15 @@ Creates a continuous point set distribution using a list of points.
Creates a discrete point set distribution using a list of points.
<SquiggleEditor defaultCode={`PointSet.makeDiscrete([
<SquiggleEditor
defaultCode={`PointSet.makeDiscrete([
{ x: 0, y: 0.1 },
{ x: 1, y: 0.2 },
{ x: 2, y: 0.15 },
{ x: 3, y: 0.1 }
])`} />
])`}
/>
### Arguments
- `points`: An array of at least 1 coordinate.
- `points`: An array of at least 1 coordinate.

View File

@ -12,6 +12,7 @@ Squiggle supports some simple types and language features.
<SquiggleEditor defaultCode="4.32" />
## Distributions
There are several ways of easily entering distributions. See the [documentation](/docs/Api/Dist/) on distributions for a complete API.
<SquiggleEditor
@ -23,6 +24,7 @@ d`}
/>
## Lists
Squiggle lists can accept items of any type, similar to those in Python. [API](/docs/Api/List).
<SquiggleEditor
@ -30,6 +32,7 @@ Squiggle lists can accept items of any type, similar to those in Python. [API](/
/>
## Dictionaries
Squiggle dictionaries work similarly to Python dictionaries. [API](/docs/Api/Dictionary).
<SquiggleEditor
@ -50,18 +53,23 @@ f`}
## Comments
<SquiggleEditor defaultCode={`// This is a single-line comment\n
<SquiggleEditor
defaultCode={`// This is a single-line comment\n
/*
This is a multiple
-line comment.
*/
""
`} />
`}
/>
## Pipes
Squiggle features [data-first](https://www.javierchavarri.com/data-first-and-data-last-a-comparison/) pipes. Functions in the standard library are organized to make this convenient.
<SquiggleEditor defaultCode={`normal(5,2) |> truncateLeft(3) |> SampleSet.fromDist |> SampleSet.map({|r| r + 10})`} />
<SquiggleEditor
defaultCode={`normal(5,2) |> truncateLeft(3) |> SampleSet.fromDist |> SampleSet.map({|r| r + 10})`}
/>
## Standard Library
@ -70,24 +78,30 @@ Squiggle features a simple [standard libary](/docs/Api/Dist).
Most functions are namespaced under their respective types to keep functionality distinct. Certain popular functions are usable without their namespaces.
For example,
<SquiggleEditor defaultCode={`a = List.upTo(0, 5000) |> SampleSet.fromList // namespaces required
<SquiggleEditor
defaultCode={`a = List.upTo(0, 5000) |> SampleSet.fromList // namespaces required
b = normal(5,2) // namespace not required
c = 5 to 10 // namespace not required
""`} />
""`}
/>
## Number Prefixes
Numbers support a few scientific notation prefixes.
| prefix | multiplier |
|-----|-------|
| n | 10^-9 |
| m | 10^-3 |
| k | 10^3 |
| M | 10^6 |
| B,G | 10^9 |
| T | 10^12 |
| P | 10^15 |
| prefix | multiplier |
| ------ | ---------- |
| n | 10^-9 |
| m | 10^-3 |
| k | 10^3 |
| M | 10^6 |
| B,G | 10^9 |
| T | 10^12 |
| P | 10^15 |
<SquiggleEditor defaultCode={`simpleNumber = 4.32k
<SquiggleEditor
defaultCode={`simpleNumber = 4.32k
distribution = 40M to 50M
distribution`} />
distribution`}
/>

View File

@ -10,10 +10,12 @@ Squiggle is a minimalist programming language for probabilistic estimation. It's
The basics of Squiggle are fairly straightforward. This can be enough for many models. The more advanced functionality can take some time to learn.
## Simple example
Say you're trying to estimate the number of piano tuners in New York City. You can build a simple model of this, like so.
(Tip: This is interactive! Feel free to modify the code directly.)
<SquiggleEditor defaultCode={`
<SquiggleEditor
defaultCode={`
// Piano tuners in NYC over the next 5 years
populationOfNewYork2022 = 8.1M to 8.4M // This means that you're 90% confident the value is between 8.1 and 8.4 Million.\n
proportionOfPopulationWithPianos = {
@ -26,13 +28,15 @@ pianoTunersPerPiano = {
} \n
totalTunersIn2022 = populationOfNewYork2022 * proportionOfPopulationWithPianos * pianoTunersPerPiano
totalTunersIn2022
`} />
`}
/>
---
---
Now let's take this a bit further. Let's imagine that you think that NYC will grow over time, and you'd like to estimate the number of piano tuners for every point in time for the next few years.
<SquiggleEditor defaultCode={`// Piano tuners in NYC over the next 5 years
<SquiggleEditor
defaultCode={`// Piano tuners in NYC over the next 5 years
populationOfNewYork2022 = 8.1M to 8.4M\n
proportionOfPopulationWithPianos = {
percentage = (.2 to 1)
@ -52,13 +56,13 @@ totalTunersAtTime(t) = populationAtTime(t) * proportionOfPopulationWithPianos *
{
populationAtTime: populationAtTime,
totalTunersAtTimeMedian: {|t| median(totalTunersAtTime(t))}
}`} />
}`}
/>
If you haven't noticed yet, you can hover over the `populationAtTime` graph to see the distribution of population at different points in time.
## Using Squiggle
You can currently interact with Squiggle in a few ways:
**[Playground](/playground)**
@ -68,7 +72,7 @@ The [Squiggle Playground](/playground) is a nice tool for working with small mod
There's a simple [VS Code extension](https://marketplace.visualstudio.com/items?itemName=QURI.vscode-squiggle) for running and visualizing Squiggle code. We find that VS Code is a useful editor for managing larger Squiggle setups.
**[Typescript Library](https://www.npmjs.com/package/@quri/squiggle-lang)**
Squiggle is built using [Rescript](https://rescript-lang.org/), and is accessible via a simple Typescript library. You can use this library to either run Squiggle code in full, or to call select specific functions within Squiggle (though this latter functionality is very minimal).
Squiggle is built using [Rescript](https://rescript-lang.org/), and is accessible via a simple Typescript library. You can use this library to either run Squiggle code in full, or to call select specific functions within Squiggle (though this latter functionality is very minimal).
**[React Components Library](https://www.npmjs.com/package/@quri/squiggle-components)**
All of the components used in the playground and documentation are available in a separate component NPM repo. You can see the full Storybook of components [here](https://squiggle-components.netlify.app).
@ -93,13 +97,15 @@ You can use Squiggle Components in Observable notebooks. Sam Nolan put together
- A visually-driven tool. (See [Guesstimate](https://www.getguesstimate.com/) and [Causal](https://causal.app/))
### Strengths
- Simple and readable syntax, especially for dealing with probabilistic math.
- Fast for relatively small models. Strong for rapid prototyping.
- Optimized for using some numeric and symbolic approaches, not just Monte Carlo.
- Optimized for using some numeric and symbolic approaches, not just Monte Carlo.
- Embeddable in Javascript.
- Free and open-source.
### Weaknesses
### Weaknesses
- Limited scientific capabilities.
- Much slower than serious probabilistic programming languages on sizeable models.
- Can't do Bayesian backwards inference.
@ -109,4 +115,5 @@ You can use Squiggle Components in Observable notebooks. Sam Nolan put together
- Generally not as easy to use as Guesstimate or Causal, especially for non programmers.
## Organization
Squiggle is one of the main projects of [The Quantified Uncertainty Research Institute](https://quantifieduncertainty.org/). QURI is a nonprofit funded primarily by [Effective Altruist](https://www.effectivealtruism.org/) donors.
Squiggle is one of the main projects of [The Quantified Uncertainty Research Institute](https://quantifieduncertainty.org/). QURI is a nonprofit funded primarily by [Effective Altruist](https://www.effectivealtruism.org/) donors.

View File

@ -10,12 +10,12 @@ function HomepageHeader() {
return (
<header className={clsx("hero hero--primary", styles.heroBanner)}>
<div className="container">
<img
alt={'Docusaurus with Keytar'}
className={styles.heroLogo}
src={'/img/squiggle-logo.png'}
width="70"
/>
<img
alt={"Docusaurus with Keytar"}
className={styles.heroLogo}
src={"/img/squiggle-logo.png"}
width="70"
/>
<h1 className="hero__title">{siteConfig.title}</h1>
<p className="hero__subtitle">Early Access</p>
<p className="hero__subtitle2">{siteConfig.tagline}</p>