Merge pull request #697 from quantified-uncertainty/develop
Develop -> Master, 14/06/2022
This commit is contained in:
commit
a8ad464623
|
@ -1,3 +1,4 @@
|
||||||
dist/
|
dist/
|
||||||
storybook-static
|
storybook-static
|
||||||
src/styles/base.css
|
src/styles/base.css
|
||||||
|
src/styles/forms.css
|
||||||
|
|
|
@ -5,14 +5,15 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@headlessui/react": "^1.6.4",
|
"@headlessui/react": "^1.6.4",
|
||||||
"@heroicons/react": "^1.0.6",
|
"@heroicons/react": "^1.0.6",
|
||||||
"@hookform/resolvers": "^2.9.0",
|
"@hookform/resolvers": "^2.9.1",
|
||||||
"@quri/squiggle-lang": "^0.2.8",
|
"@quri/squiggle-lang": "^0.2.8",
|
||||||
"@react-hook/size": "^2.1.2",
|
"@react-hook/size": "^2.1.2",
|
||||||
|
"clsx": "^1.1.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"react": "^18.1.0",
|
"react": "^18.1.0",
|
||||||
"react-ace": "^10.1.0",
|
"react-ace": "^10.1.0",
|
||||||
"react-dom": "^18.1.0",
|
"react-dom": "^18.1.0",
|
||||||
"react-hook-form": "^7.31.3",
|
"react-hook-form": "^7.32.0",
|
||||||
"react-use": "^17.4.0",
|
"react-use": "^17.4.0",
|
||||||
"react-vega": "^7.5.1",
|
"react-vega": "^7.5.1",
|
||||||
"vega": "^5.22.1",
|
"vega": "^5.22.1",
|
||||||
|
@ -22,21 +23,20 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/plugin-proposal-private-property-in-object": "^7.17.12",
|
"@babel/plugin-proposal-private-property-in-object": "^7.17.12",
|
||||||
"@storybook/addon-actions": "^6.5.7",
|
"@storybook/addon-actions": "^6.5.8",
|
||||||
"@storybook/addon-essentials": "^6.5.7",
|
"@storybook/addon-essentials": "^6.5.8",
|
||||||
"@storybook/addon-links": "^6.5.7",
|
"@storybook/addon-links": "^6.5.8",
|
||||||
"@storybook/builder-webpack5": "^6.5.7",
|
"@storybook/builder-webpack5": "^6.5.8",
|
||||||
"@storybook/manager-webpack5": "^6.5.7",
|
"@storybook/manager-webpack5": "^6.5.8",
|
||||||
"@storybook/node-logger": "^6.5.6",
|
"@storybook/node-logger": "^6.5.6",
|
||||||
"@storybook/preset-create-react-app": "^4.1.2",
|
"@storybook/preset-create-react-app": "^4.1.2",
|
||||||
"@storybook/react": "^6.5.7",
|
"@storybook/react": "^6.5.8",
|
||||||
"@tailwindcss/forms": "^0.5.2",
|
|
||||||
"@testing-library/jest-dom": "^5.16.4",
|
"@testing-library/jest-dom": "^5.16.4",
|
||||||
"@testing-library/react": "^13.3.0",
|
"@testing-library/react": "^13.3.0",
|
||||||
"@testing-library/user-event": "^14.2.0",
|
"@testing-library/user-event": "^14.2.0",
|
||||||
"@types/jest": "^27.5.0",
|
"@types/jest": "^27.5.0",
|
||||||
"@types/lodash": "^4.14.182",
|
"@types/lodash": "^4.14.182",
|
||||||
"@types/node": "^17.0.40",
|
"@types/node": "^17.0.42",
|
||||||
"@types/react": "^18.0.9",
|
"@types/react": "^18.0.9",
|
||||||
"@types/react-dom": "^18.0.5",
|
"@types/react-dom": "^18.0.5",
|
||||||
"@types/styled-components": "^5.1.24",
|
"@types/styled-components": "^5.1.24",
|
||||||
|
@ -48,14 +48,14 @@
|
||||||
"postcss-loader": "^7.0.0",
|
"postcss-loader": "^7.0.0",
|
||||||
"react-scripts": "^5.0.1",
|
"react-scripts": "^5.0.1",
|
||||||
"style-loader": "^3.3.1",
|
"style-loader": "^3.3.1",
|
||||||
"tailwindcss": "^3.0.24",
|
"tailwindcss": "^3.1.2",
|
||||||
"ts-loader": "^9.3.0",
|
"ts-loader": "^9.3.0",
|
||||||
"tsconfig-paths-webpack-plugin": "^3.5.2",
|
"tsconfig-paths-webpack-plugin": "^3.5.2",
|
||||||
"typescript": "^4.7.3",
|
"typescript": "^4.7.3",
|
||||||
"web-vitals": "^2.1.4",
|
"web-vitals": "^2.1.4",
|
||||||
"webpack": "^5.73.0",
|
"webpack": "^5.73.0",
|
||||||
"webpack-cli": "^4.9.2",
|
"webpack-cli": "^4.10.0",
|
||||||
"webpack-dev-server": "^4.9.0"
|
"webpack-dev-server": "^4.9.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "cross-env REACT_APP_FAST_REFRESH=false && start-storybook -p 6006 -s public",
|
"start": "cross-env REACT_APP_FAST_REFRESH=false && start-storybook -p 6006 -s public",
|
||||||
|
|
|
@ -129,6 +129,7 @@ export const CheckBox: React.FC<CheckBoxProps> = ({
|
||||||
value={value + ""}
|
value={value + ""}
|
||||||
onChange={() => onChange(!value)}
|
onChange={() => onChange(!value)}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
className="form-checkbox"
|
||||||
/>
|
/>
|
||||||
<label className={clsx(disabled && "text-slate-400")}> {label}</label>
|
<label className={clsx(disabled && "text-slate-400")}> {label}</label>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -162,7 +162,7 @@ function InputItem<T>({
|
||||||
<input
|
<input
|
||||||
type={type}
|
type={type}
|
||||||
{...register(name)}
|
{...register(name)}
|
||||||
className="max-w-lg block w-full shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:max-w-xs sm:text-sm border-gray-300 rounded-md"
|
className="form-input max-w-lg block w-full shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:max-w-xs sm:text-sm border-gray-300 rounded-md"
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
|
@ -182,7 +182,7 @@ function Checkbox<T>({
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
{...register(name)}
|
{...register(name)}
|
||||||
className="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded"
|
className="form-checkbox focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded"
|
||||||
/>
|
/>
|
||||||
{/* Clicking on the div makes the checkbox lose focus while mouse button is pressed, leading to annoying blinking; I couldn't figure out how to fix this. */}
|
{/* Clicking on the div makes the checkbox lose focus while mouse button is pressed, leading to annoying blinking; I couldn't figure out how to fix this. */}
|
||||||
<div className="ml-3 text-sm font-medium text-gray-700">{label}</div>
|
<div className="ml-3 text-sm font-medium text-gray-700">{label}</div>
|
||||||
|
|
|
@ -368,143 +368,4 @@ video {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* these styles were generated by tailwindcss-forms */
|
|
||||||
[type='text'],[type='email'],[type='url'],[type='password'],[type='number'],[type='date'],[type='datetime-local'],[type='month'],[type='search'],[type='tel'],[type='time'],[type='week'],[multiple],textarea,select {
|
|
||||||
appearance: none;
|
|
||||||
background-color: #fff;
|
|
||||||
border-color: #6b7280;
|
|
||||||
border-width: 1px;
|
|
||||||
border-radius: 0px;
|
|
||||||
padding-top: 0.5rem;
|
|
||||||
padding-right: 0.75rem;
|
|
||||||
padding-bottom: 0.5rem;
|
|
||||||
padding-left: 0.75rem;
|
|
||||||
font-size: 1rem;
|
|
||||||
line-height: 1.5rem;
|
|
||||||
--tw-shadow: 0 0 #0000;
|
|
||||||
}
|
|
||||||
[type='text']:focus, [type='email']:focus, [type='url']:focus, [type='password']:focus, [type='number']:focus, [type='date']:focus, [type='datetime-local']:focus, [type='month']:focus, [type='search']:focus, [type='tel']:focus, [type='time']:focus, [type='week']:focus, [multiple]:focus, textarea:focus, select:focus {
|
|
||||||
outline: 2px solid transparent;
|
|
||||||
outline-offset: 2px;
|
|
||||||
--tw-ring-inset: var(--tw-empty,/*!*/ /*!*/);
|
|
||||||
--tw-ring-offset-width: 0px;
|
|
||||||
--tw-ring-offset-color: #fff;
|
|
||||||
--tw-ring-color: #2563eb;
|
|
||||||
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
|
||||||
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);
|
|
||||||
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
|
||||||
border-color: #2563eb;
|
|
||||||
}
|
|
||||||
input::placeholder,textarea::placeholder {
|
|
||||||
color: #6b7280;
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
::-webkit-datetime-edit-fields-wrapper {
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
::-webkit-date-and-time-value {
|
|
||||||
min-height: 1.5em;
|
|
||||||
}
|
|
||||||
::-webkit-datetime-edit,::-webkit-datetime-edit-year-field,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute-field,::-webkit-datetime-edit-second-field,::-webkit-datetime-edit-millisecond-field,::-webkit-datetime-edit-meridiem-field {
|
|
||||||
padding-top: 0;
|
|
||||||
padding-bottom: 0;
|
|
||||||
}
|
|
||||||
select {
|
|
||||||
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
|
|
||||||
background-position: right 0.5rem center;
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
background-size: 1.5em 1.5em;
|
|
||||||
padding-right: 2.5rem;
|
|
||||||
-webkit-print-color-adjust: exact;
|
|
||||||
print-color-adjust: exact;
|
|
||||||
}
|
|
||||||
[multiple] {
|
|
||||||
background-image: initial;
|
|
||||||
background-position: initial;
|
|
||||||
background-repeat: unset;
|
|
||||||
background-size: initial;
|
|
||||||
padding-right: 0.75rem;
|
|
||||||
-webkit-print-color-adjust: unset;
|
|
||||||
print-color-adjust: unset;
|
|
||||||
}
|
|
||||||
[type='checkbox'],[type='radio'] {
|
|
||||||
appearance: none;
|
|
||||||
padding: 0;
|
|
||||||
-webkit-print-color-adjust: exact;
|
|
||||||
print-color-adjust: exact;
|
|
||||||
display: inline-block;
|
|
||||||
vertical-align: middle;
|
|
||||||
background-origin: border-box;
|
|
||||||
-webkit-user-select: none;
|
|
||||||
user-select: none;
|
|
||||||
flex-shrink: 0;
|
|
||||||
height: 1rem;
|
|
||||||
width: 1rem;
|
|
||||||
color: #2563eb;
|
|
||||||
background-color: #fff;
|
|
||||||
border-color: #6b7280;
|
|
||||||
border-width: 1px;
|
|
||||||
--tw-shadow: 0 0 #0000;
|
|
||||||
}
|
|
||||||
[type='checkbox'] {
|
|
||||||
border-radius: 0px;
|
|
||||||
}
|
|
||||||
[type='radio'] {
|
|
||||||
border-radius: 100%;
|
|
||||||
}
|
|
||||||
[type='checkbox']:focus,[type='radio']:focus {
|
|
||||||
outline: 2px solid transparent;
|
|
||||||
outline-offset: 2px;
|
|
||||||
--tw-ring-inset: var(--tw-empty,/*!*/ /*!*/);
|
|
||||||
--tw-ring-offset-width: 2px;
|
|
||||||
--tw-ring-offset-color: #fff;
|
|
||||||
--tw-ring-color: #2563eb;
|
|
||||||
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
|
||||||
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);
|
|
||||||
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
|
||||||
}
|
|
||||||
[type='checkbox']:checked,[type='radio']:checked {
|
|
||||||
border-color: transparent;
|
|
||||||
background-color: currentColor;
|
|
||||||
background-size: 100% 100%;
|
|
||||||
background-position: center;
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
}
|
|
||||||
[type='checkbox']:checked {
|
|
||||||
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e");
|
|
||||||
}
|
|
||||||
[type='radio']:checked {
|
|
||||||
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3ccircle cx='8' cy='8' r='3'/%3e%3c/svg%3e");
|
|
||||||
}
|
|
||||||
[type='checkbox']:checked:hover,[type='checkbox']:checked:focus,[type='radio']:checked:hover,[type='radio']:checked:focus {
|
|
||||||
border-color: transparent;
|
|
||||||
background-color: currentColor;
|
|
||||||
}
|
|
||||||
[type='checkbox']:indeterminate {
|
|
||||||
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 16 16'%3e%3cpath stroke='white' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M4 8h8'/%3e%3c/svg%3e");
|
|
||||||
border-color: transparent;
|
|
||||||
background-color: currentColor;
|
|
||||||
background-size: 100% 100%;
|
|
||||||
background-position: center;
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
}
|
|
||||||
[type='checkbox']:indeterminate:hover,[type='checkbox']:indeterminate:focus {
|
|
||||||
border-color: transparent;
|
|
||||||
background-color: currentColor;
|
|
||||||
}
|
|
||||||
[type='file'] {
|
|
||||||
background: unset;
|
|
||||||
border-color: inherit;
|
|
||||||
border-width: 0;
|
|
||||||
border-radius: 0;
|
|
||||||
padding: 0;
|
|
||||||
font-size: unset;
|
|
||||||
line-height: inherit;
|
|
||||||
}
|
|
||||||
[type='file']:focus {
|
|
||||||
outline: 1px solid ButtonText;
|
|
||||||
outline: 1px auto -webkit-focus-ring-color;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
102
packages/components/src/styles/forms.css
Normal file
102
packages/components/src/styles/forms.css
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
/* Fork of https://github.com/tailwindlabs/tailwindcss-forms styles, see the comment in main.css for details. */
|
||||||
|
.squiggle {
|
||||||
|
.form-input,.form-textarea,.form-select,.form-multiselect {
|
||||||
|
appearance: none;
|
||||||
|
background-color: #fff;
|
||||||
|
border-color: #6b7280;
|
||||||
|
border-width: 1px;
|
||||||
|
border-radius: 0px;
|
||||||
|
padding-top: 0.5rem;
|
||||||
|
padding-right: 0.75rem;
|
||||||
|
padding-bottom: 0.5rem;
|
||||||
|
padding-left: 0.75rem;
|
||||||
|
font-size: 1rem;
|
||||||
|
line-height: 1.5rem;
|
||||||
|
--tw-shadow: 0 0 #0000;
|
||||||
|
}
|
||||||
|
.form-input:focus, .form-textarea:focus, .form-select:focus, .form-multiselect:focus {
|
||||||
|
outline: 2px solid transparent;
|
||||||
|
outline-offset: 2px;
|
||||||
|
--tw-ring-inset: var(--tw-empty,/*!*/ /*!*/);
|
||||||
|
--tw-ring-offset-width: 0px;
|
||||||
|
--tw-ring-offset-color: #fff;
|
||||||
|
--tw-ring-color: #2563eb;
|
||||||
|
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
||||||
|
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);
|
||||||
|
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
||||||
|
border-color: #2563eb;
|
||||||
|
}
|
||||||
|
.form-input::placeholder,.form-textarea::placeholder {
|
||||||
|
color: #6b7280;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
.form-input::-webkit-datetime-edit-fields-wrapper {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
.form-input::-webkit-date-and-time-value {
|
||||||
|
min-height: 1.5em;
|
||||||
|
}
|
||||||
|
.form-input::-webkit-datetime-edit,.form-input::-webkit-datetime-edit-year-field,.form-input::-webkit-datetime-edit-month-field,.form-input::-webkit-datetime-edit-day-field,.form-input::-webkit-datetime-edit-hour-field,.form-input::-webkit-datetime-edit-minute-field,.form-input::-webkit-datetime-edit-second-field,.form-input::-webkit-datetime-edit-millisecond-field,.form-input::-webkit-datetime-edit-meridiem-field {
|
||||||
|
padding-top: 0;
|
||||||
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
|
.form-checkbox,.form-radio {
|
||||||
|
appearance: none;
|
||||||
|
padding: 0;
|
||||||
|
-webkit-print-color-adjust: exact;
|
||||||
|
print-color-adjust: exact;
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
|
background-origin: border-box;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
user-select: none;
|
||||||
|
flex-shrink: 0;
|
||||||
|
height: 1rem;
|
||||||
|
width: 1rem;
|
||||||
|
color: #2563eb;
|
||||||
|
background-color: #fff;
|
||||||
|
border-color: #6b7280;
|
||||||
|
border-width: 1px;
|
||||||
|
--tw-shadow: 0 0 #0000;
|
||||||
|
}
|
||||||
|
.form-checkbox {
|
||||||
|
border-radius: 0px;
|
||||||
|
}
|
||||||
|
.form-checkbox:focus,.form-radio:focus {
|
||||||
|
outline: 2px solid transparent;
|
||||||
|
outline-offset: 2px;
|
||||||
|
--tw-ring-inset: var(--tw-empty,/*!*/ /*!*/);
|
||||||
|
--tw-ring-offset-width: 2px;
|
||||||
|
--tw-ring-offset-color: #fff;
|
||||||
|
--tw-ring-color: #2563eb;
|
||||||
|
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
||||||
|
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);
|
||||||
|
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
||||||
|
}
|
||||||
|
.form-checkbox:checked,.form-radio:checked {
|
||||||
|
border-color: transparent;
|
||||||
|
background-color: currentColor;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
background-position: center;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
}
|
||||||
|
.form-checkbox:checked {
|
||||||
|
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e");
|
||||||
|
}
|
||||||
|
.form-checkbox:checked:hover,.form-checkbox:checked:focus,.form-radio:checked:hover,.form-radio:checked:focus {
|
||||||
|
border-color: transparent;
|
||||||
|
background-color: currentColor;
|
||||||
|
}
|
||||||
|
.form-checkbox:indeterminate {
|
||||||
|
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 16 16'%3e%3cpath stroke='white' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M4 8h8'/%3e%3c/svg%3e");
|
||||||
|
border-color: transparent;
|
||||||
|
background-color: currentColor;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
background-position: center;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
}
|
||||||
|
.form-checkbox:indeterminate:hover,.form-checkbox:indeterminate:focus {
|
||||||
|
border-color: transparent;
|
||||||
|
background-color: currentColor;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,24 @@
|
||||||
|
/*
|
||||||
|
Fork of tailwind's preflight with `.squiggle` scoping.
|
||||||
|
*/
|
||||||
@import "./base.css";
|
@import "./base.css";
|
||||||
|
/*
|
||||||
|
Fork of https://github.com/tailwindlabs/tailwindcss-forms styles (with strategy: "class"), but with `.squiggle` scoping.
|
||||||
|
This is necessary because tailwindcss-forms's css specificity is lower than preflight's specificity (`padding: 0` and so on),
|
||||||
|
so unscoped forms css with scoped preflight css, and there's no setting for scoping.
|
||||||
|
*/
|
||||||
|
@import "./forms.css";
|
||||||
|
|
||||||
|
/*
|
||||||
|
This doesn't include tailwind's original preflight (it's disabled in tailwind.config.js),
|
||||||
|
but this line is still necessary for proper initialization of `--tw-*` variables.
|
||||||
|
*/
|
||||||
|
@tailwind base;
|
||||||
|
|
||||||
@tailwind components;
|
@tailwind components;
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
||||||
/* necessary hack because scoped preflight in ./base.css has higher specificity */
|
/* Necessary hack because scoped preflight in ./base.css has higher specificity. */
|
||||||
.ace_cursor {
|
.ace_cursor {
|
||||||
border-left: 2px solid !important;
|
border-left: 2px solid !important;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
content: ["./src/**/*.{html,tsx,ts,js,jsx}"],
|
content: ["./src/**/*.{html,tsx,ts,js,jsx}"],
|
||||||
|
corePlugins: {
|
||||||
|
preflight: false,
|
||||||
|
},
|
||||||
|
important: ".squiggle",
|
||||||
theme: {
|
theme: {
|
||||||
extend: {},
|
extend: {},
|
||||||
},
|
},
|
||||||
important: ".squiggle",
|
|
||||||
plugins: [require("@tailwindcss/forms")],
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,7 +25,7 @@ let expectToExpressionToBe = (expr, answer, ~v="_", ()) => {
|
||||||
->Result.flatMap(expr =>
|
->Result.flatMap(expr =>
|
||||||
Expression.reduceExpression(
|
Expression.reduceExpression(
|
||||||
expr,
|
expr,
|
||||||
ReducerInterface_DefaultExternalBindings.defaultInternalBindings,
|
ReducerInterface_StdLib.internalStdLib,
|
||||||
ExpressionValue.defaultEnvironment,
|
ExpressionValue.defaultEnvironment,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -29,6 +29,7 @@ let expectEvalError = (expr: string) =>
|
||||||
|
|
||||||
let expectEvalBindingsToBe = (expr: string, bindings: Reducer.externalBindings, answer: string) =>
|
let expectEvalBindingsToBe = (expr: string, bindings: Reducer.externalBindings, answer: string) =>
|
||||||
Reducer.evaluateUsingOptions(expr, ~externalBindings=Some(bindings), ~environment=None)
|
Reducer.evaluateUsingOptions(expr, ~externalBindings=Some(bindings), ~environment=None)
|
||||||
|
->Reducer_Helpers.rRemoveDefaults
|
||||||
->ExpressionValue.toStringResult
|
->ExpressionValue.toStringResult
|
||||||
->expect
|
->expect
|
||||||
->toBe(answer)
|
->toBe(answer)
|
||||||
|
|
|
@ -80,6 +80,7 @@ describe("eval on distribution functions", () => {
|
||||||
testEval("truncateLeft(normal(5,2), 3)", "Ok(Point Set Distribution)")
|
testEval("truncateLeft(normal(5,2), 3)", "Ok(Point Set Distribution)")
|
||||||
testEval("truncateRight(normal(5,2), 3)", "Ok(Point Set Distribution)")
|
testEval("truncateRight(normal(5,2), 3)", "Ok(Point Set Distribution)")
|
||||||
testEval("truncate(normal(5,2), 3, 8)", "Ok(Point Set Distribution)")
|
testEval("truncate(normal(5,2), 3, 8)", "Ok(Point Set Distribution)")
|
||||||
|
testEval("isNormalized(truncate(normal(5,2), 3, 8))", "Ok(true)")
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("exp", () => {
|
describe("exp", () => {
|
||||||
|
|
|
@ -57,14 +57,14 @@
|
||||||
"moduleserve": "^0.9.1",
|
"moduleserve": "^0.9.1",
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"peggy": "^2.0.1",
|
"peggy": "^2.0.1",
|
||||||
"reanalyze": "^2.22.0",
|
"reanalyze": "^2.23.0",
|
||||||
"rescript-fast-check": "^1.1.1",
|
"rescript-fast-check": "^1.1.1",
|
||||||
"ts-jest": "^27.1.4",
|
"ts-jest": "^27.1.4",
|
||||||
"ts-loader": "^9.3.0",
|
"ts-loader": "^9.3.0",
|
||||||
"ts-node": "^10.8.1",
|
"ts-node": "^10.8.1",
|
||||||
"typescript": "^4.7.3",
|
"typescript": "^4.7.3",
|
||||||
"webpack": "^5.73.0",
|
"webpack": "^5.73.0",
|
||||||
"webpack-cli": "^4.9.2"
|
"webpack-cli": "^4.10.0"
|
||||||
},
|
},
|
||||||
"source": "./src/js/index.ts",
|
"source": "./src/js/index.ts",
|
||||||
"main": "./dist/src/js/index.js",
|
"main": "./dist/src/js/index.js",
|
||||||
|
|
|
@ -142,7 +142,7 @@ module DistributionOperation = {
|
||||||
| ToDist(Scale(#LogarithmWithThreshold(eps), r)) =>
|
| ToDist(Scale(#LogarithmWithThreshold(eps), r)) =>
|
||||||
`scaleLogWithThreshold(${E.Float.toFixed(r)}, epsilon=${E.Float.toFixed(eps)})`
|
`scaleLogWithThreshold(${E.Float.toFixed(r)}, epsilon=${E.Float.toFixed(eps)})`
|
||||||
| ToString(ToString) => `toString`
|
| ToString(ToString) => `toString`
|
||||||
| ToString(ToSparkline(n)) => `toSparkline(${E.I.toString(n)})`
|
| ToString(ToSparkline(n)) => `sparkline(${E.I.toString(n)})`
|
||||||
| ToBool(IsNormalized) => `isNormalized`
|
| ToBool(IsNormalized) => `isNormalized`
|
||||||
| ToDistCombination(Algebraic(_), _, _) => `algebraic`
|
| ToDistCombination(Algebraic(_), _, _) => `algebraic`
|
||||||
| ToDistCombination(Pointwise, _, _) => `pointwise`
|
| ToDistCombination(Pointwise, _, _) => `pointwise`
|
||||||
|
|
|
@ -214,7 +214,9 @@ module Truncate = {
|
||||||
| Some(r) => Ok(r)
|
| Some(r) => Ok(r)
|
||||||
| None =>
|
| None =>
|
||||||
toPointSetFn(t)->E.R2.fmap(t => {
|
toPointSetFn(t)->E.R2.fmap(t => {
|
||||||
DistributionTypes.PointSet(PointSetDist.T.truncate(leftCutoff, rightCutoff, t))
|
DistributionTypes.PointSet(
|
||||||
|
PointSetDist.T.truncate(leftCutoff, rightCutoff, t)->PointSetDist.T.normalize,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -295,7 +295,7 @@ module Float = {
|
||||||
let inv = (p, t: t) => p < t ? 0.0 : 1.0
|
let inv = (p, t: t) => p < t ? 0.0 : 1.0
|
||||||
let mean = (t: t) => Ok(t)
|
let mean = (t: t) => Ok(t)
|
||||||
let sample = (t: t) => t
|
let sample = (t: t) => t
|
||||||
let toString = (t: t) => j`Delta($t)`
|
let toString = (t: t) => j`PointMass($t)`
|
||||||
let toPointSetDist = (t: t): PointSetTypes.pointSetDist => Discrete(
|
let toPointSetDist = (t: t): PointSetTypes.pointSetDist => Discrete(
|
||||||
Discrete.make(~integralSumCache=Some(1.0), {xs: [t], ys: [1.0]}),
|
Discrete.make(~integralSumCache=Some(1.0), {xs: [t], ys: [1.0]}),
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,4 +24,4 @@ let foreignFunctionInterface = (
|
||||||
|
|
||||||
let defaultEnvironment = ExpressionValue.defaultEnvironment
|
let defaultEnvironment = ExpressionValue.defaultEnvironment
|
||||||
|
|
||||||
let defaultExternalBindings = ReducerInterface_DefaultExternalBindings.defaultExternalBindings
|
let defaultExternalBindings = ReducerInterface_StdLib.externalStdLib
|
||||||
|
|
|
@ -116,14 +116,20 @@ let evaluateUsingOptions = (
|
||||||
~externalBindings: option<ReducerInterface_ExpressionValue.externalBindings>,
|
~externalBindings: option<ReducerInterface_ExpressionValue.externalBindings>,
|
||||||
code: string,
|
code: string,
|
||||||
): result<expressionValue, errorValue> => {
|
): result<expressionValue, errorValue> => {
|
||||||
let anEnvironment = switch environment {
|
let anEnvironment = Belt.Option.getWithDefault(
|
||||||
| Some(env) => env
|
environment,
|
||||||
| None => ReducerInterface_ExpressionValue.defaultEnvironment
|
ReducerInterface_ExpressionValue.defaultEnvironment,
|
||||||
}
|
)
|
||||||
|
|
||||||
let anExternalBindings = switch externalBindings {
|
let anExternalBindings = switch externalBindings {
|
||||||
| Some(bindings) => bindings
|
| Some(bindings) => {
|
||||||
| None => ReducerInterface_DefaultExternalBindings.defaultExternalBindings
|
let cloneLib = ReducerInterface_StdLib.externalStdLib->Reducer_Category_Bindings.cloneRecord
|
||||||
|
Js.Dict.entries(bindings)->Js.Array2.reduce((acc, (key, value)) => {
|
||||||
|
acc->Js.Dict.set(key, value)
|
||||||
|
acc
|
||||||
|
}, cloneLib)
|
||||||
|
}
|
||||||
|
| None => ReducerInterface_StdLib.externalStdLib
|
||||||
}
|
}
|
||||||
|
|
||||||
let bindings = anExternalBindings->Bindings.fromExternalBindings
|
let bindings = anExternalBindings->Bindings.fromExternalBindings
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
module Bindings = Reducer_Category_Bindings
|
|
||||||
|
|
||||||
let defaultInternalBindings = Bindings.emptyBindings->SquiggleLibrary_Math.makeBindings
|
|
||||||
|
|
||||||
@genType
|
|
||||||
let defaultExternalBindings = defaultInternalBindings->Bindings.toRecord
|
|
|
@ -221,9 +221,9 @@ let dispatchToGenericOutput = (
|
||||||
}
|
}
|
||||||
| ("integralSum", [EvDistribution(dist)]) => Helpers.toFloatFn(#IntegralSum, dist, ~env)
|
| ("integralSum", [EvDistribution(dist)]) => Helpers.toFloatFn(#IntegralSum, dist, ~env)
|
||||||
| ("toString", [EvDistribution(dist)]) => Helpers.toStringFn(ToString, dist, ~env)
|
| ("toString", [EvDistribution(dist)]) => Helpers.toStringFn(ToString, dist, ~env)
|
||||||
| ("toSparkline", [EvDistribution(dist)]) =>
|
| ("sparkline", [EvDistribution(dist)]) =>
|
||||||
Helpers.toStringFn(ToSparkline(MagicNumbers.Environment.sparklineLength), dist, ~env)
|
Helpers.toStringFn(ToSparkline(MagicNumbers.Environment.sparklineLength), dist, ~env)
|
||||||
| ("toSparkline", [EvDistribution(dist), EvNumber(n)]) =>
|
| ("sparkline", [EvDistribution(dist), EvNumber(n)]) =>
|
||||||
Helpers.toStringFn(ToSparkline(Belt.Float.toInt(n)), dist, ~env)
|
Helpers.toStringFn(ToSparkline(Belt.Float.toInt(n)), dist, ~env)
|
||||||
| ("exp", [EvDistribution(a)]) =>
|
| ("exp", [EvDistribution(a)]) =>
|
||||||
// https://mathjs.org/docs/reference/functions/exp.html
|
// https://mathjs.org/docs/reference/functions/exp.html
|
||||||
|
@ -273,6 +273,8 @@ let dispatchToGenericOutput = (
|
||||||
| ("cdf", [EvDistribution(dist), EvNumber(float)]) => Helpers.toFloatFn(#Cdf(float), dist, ~env)
|
| ("cdf", [EvDistribution(dist), EvNumber(float)]) => Helpers.toFloatFn(#Cdf(float), dist, ~env)
|
||||||
| ("pdf", [EvDistribution(dist), EvNumber(float)]) => Helpers.toFloatFn(#Pdf(float), dist, ~env)
|
| ("pdf", [EvDistribution(dist), EvNumber(float)]) => Helpers.toFloatFn(#Pdf(float), dist, ~env)
|
||||||
| ("inv", [EvDistribution(dist), EvNumber(float)]) => Helpers.toFloatFn(#Inv(float), dist, ~env)
|
| ("inv", [EvDistribution(dist), EvNumber(float)]) => Helpers.toFloatFn(#Inv(float), dist, ~env)
|
||||||
|
| ("quantile", [EvDistribution(dist), EvNumber(float)]) =>
|
||||||
|
Helpers.toFloatFn(#Inv(float), dist, ~env)
|
||||||
| ("toSampleSet", [EvDistribution(dist), EvNumber(float)]) =>
|
| ("toSampleSet", [EvDistribution(dist), EvNumber(float)]) =>
|
||||||
Helpers.toDistFn(ToSampleSet(Belt.Int.fromFloat(float)), dist, ~env)
|
Helpers.toDistFn(ToSampleSet(Belt.Int.fromFloat(float)), dist, ~env)
|
||||||
| ("toSampleSet", [EvDistribution(dist)]) =>
|
| ("toSampleSet", [EvDistribution(dist)]) =>
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
module Bindings = Reducer_Category_Bindings
|
||||||
|
|
||||||
|
let internalStdLib = Bindings.emptyBindings->SquiggleLibrary_Math.makeBindings
|
||||||
|
|
||||||
|
@genType
|
||||||
|
let externalStdLib = internalStdLib->Bindings.toRecord
|
|
@ -1,8 +1,23 @@
|
||||||
module Bindings = Reducer_Category_Bindings
|
module Bindings = Reducer_Category_Bindings
|
||||||
module Module = Reducer_Category_Module
|
module Module = Reducer_Category_Module
|
||||||
|
|
||||||
let m =
|
let availableNumbers: array<(string, float)> = [
|
||||||
Module.emptyModule->Module.defineNumber("pi", Js.Math._PI)->Module.defineNumber("e", Js.Math._E)
|
("pi", Js.Math._PI),
|
||||||
|
("e", Js.Math._E),
|
||||||
|
("ln2", Js.Math._LN2),
|
||||||
|
("ln10", Js.Math._LN10),
|
||||||
|
("log2e", Js.Math._LOG2E),
|
||||||
|
("log10e", Js.Math._LOG10E),
|
||||||
|
("sqrt2", Js.Math._SQRT2),
|
||||||
|
("sqrt1_2", Js.Math._SQRT1_2),
|
||||||
|
("phi", 1.618033988749895),
|
||||||
|
("tau", 6.283185307179586),
|
||||||
|
]
|
||||||
|
|
||||||
|
let mathBindings: Bindings.ExpressionT.bindings =
|
||||||
|
availableNumbers
|
||||||
|
->E.A2.fmap(((name, v)) => (name, ReducerInterface_ExpressionValue.EvNumber(v)))
|
||||||
|
->Belt.Map.String.fromArray
|
||||||
|
|
||||||
let makeBindings = (previousBindings: Bindings.t): Bindings.t =>
|
let makeBindings = (previousBindings: Bindings.t): Bindings.t =>
|
||||||
previousBindings->Bindings.defineModule("Math", m)
|
previousBindings->Bindings.defineModule("Math", mathBindings)
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
.docusaurus
|
.docusaurus
|
||||||
build
|
build
|
||||||
|
docs/Api/.*
|
|
@ -3,8 +3,12 @@ sidebar_position: 1
|
||||||
title: Date
|
title: Date
|
||||||
---
|
---
|
||||||
|
|
||||||
|
Squiggle date types are a very simple implementation on [Javascript's Date type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date). It's mainly here for early experimentation. There are more relevant functions for the [Duration](/docs/Api/Duration) type.
|
||||||
|
|
||||||
### makeFromYear
|
### makeFromYear
|
||||||
|
|
||||||
|
(Now `makeDateFromYear`)
|
||||||
|
|
||||||
```
|
```
|
||||||
Date.makeFromYear: (number) => date
|
Date.makeFromYear: (number) => date
|
||||||
```
|
```
|
||||||
|
@ -19,6 +23,16 @@ makeFromYear(2022.32);
|
||||||
toString: (date) => string
|
toString: (date) => string
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### add
|
||||||
|
|
||||||
|
```
|
||||||
|
add: (date, duration) => date
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
makeFromYear(2022.32) + years(5);
|
||||||
|
```
|
||||||
|
|
||||||
### subtract
|
### subtract
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -30,13 +44,3 @@ subtract: (date, duration) => date
|
||||||
makeFromYear(2040) - makeFromYear(2020); // 20 years
|
makeFromYear(2040) - makeFromYear(2020); // 20 years
|
||||||
makeFromYear(2040) - years(20); // 2020
|
makeFromYear(2040) - years(20); // 2020
|
||||||
```
|
```
|
||||||
|
|
||||||
### add
|
|
||||||
|
|
||||||
```
|
|
||||||
add: (date, duration) => date
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
makeFromYear(2022.32) + years(5);
|
|
||||||
```
|
|
||||||
|
|
|
@ -3,6 +3,34 @@ sidebar_position: 2
|
||||||
title: Dictionary
|
title: Dictionary
|
||||||
---
|
---
|
||||||
|
|
||||||
|
Squiggle dictionaries work similar to Python dictionaries. The syntax is similar to objects in Javascript.
|
||||||
|
|
||||||
|
Dictionaries are unordered and duplicates are not allowed. They are meant to be immutable, like most types in Squiggle.
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
valueFromOfficeItems = {
|
||||||
|
keyboard: 1,
|
||||||
|
chair: 0.01 to 0.5,
|
||||||
|
headphones: "ToDo"
|
||||||
|
}
|
||||||
|
|
||||||
|
valueFromHomeItems = {
|
||||||
|
monitor: 1,
|
||||||
|
bed: 0.2 to 0.6,
|
||||||
|
lights: 0.02 to 0.2,
|
||||||
|
coffee: 5 to 20
|
||||||
|
}
|
||||||
|
|
||||||
|
homeToItemsConversion = 0.1 to 0.4
|
||||||
|
|
||||||
|
conversionFn(i) = [i[0], i[1] * homeToItemsConversion]
|
||||||
|
updatedValueFromHomeItems = valueFromHomeItems |> Dict.toList |> map(conversionFn) |> Dict.fromList
|
||||||
|
|
||||||
|
allItems = merge(valueFromOfficeItems, updatedValueFromHomeItems)
|
||||||
|
```
|
||||||
|
|
||||||
### toList
|
### toList
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -3,50 +3,47 @@ sidebar_position: 3
|
||||||
title: Distribution
|
title: Distribution
|
||||||
---
|
---
|
||||||
|
|
||||||
|
import Admonition from "@theme/Admonition";
|
||||||
import TOCInline from "@theme/TOCInline";
|
import TOCInline from "@theme/TOCInline";
|
||||||
|
|
||||||
|
Distributions are the flagship data type in Squiggle. The distribution type is a generic data type that contains one of three different formats of distributions.
|
||||||
|
These subtypes are [point set](/docs/Api/DistPointSet), [sample set](/docs/Api/DistSampleSet), and symbolic. The first two of these have a few custom functions that only work on them. You can read more about the differences between these formats [here](/docs/Discussions/Three-Formats-Of-Distributions).
|
||||||
|
|
||||||
|
Several functions below only can work on particular distribution formats.
|
||||||
|
For example, scoring and pointwise math requires the point set format. When this happens, the types are automatically converted to the correct format. These conversions are lossy.
|
||||||
|
|
||||||
<TOCInline toc={toc} />
|
<TOCInline toc={toc} />
|
||||||
|
|
||||||
## Distribution Creation
|
## Distribution Creation
|
||||||
|
|
||||||
### Normal Distribution
|
These are functions for creating primative distributions. Many of these could optionally take in distributions as inputs. In these cases, Monte Carlo Sampling will be used to generate the greater distribution. This can be used for simple hierarchical models.
|
||||||
|
|
||||||
**Definitions**
|
See a longer tutorial on creating distributions [here](/docs/Guides/DistributionCreation).
|
||||||
|
|
||||||
|
### normal
|
||||||
|
|
||||||
```javascript
|
|
||||||
normal: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
|
|
||||||
```
|
```
|
||||||
|
normal: (distribution|number, distribution|number) => distribution
|
||||||
```javascript
|
normal: (dict<{p5: distribution|number, p95: distribution|number}>) => distribution
|
||||||
normal: (dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>) => distribution
|
normal: (dict<{mean: distribution|number, stdev: distribution|number}>) => distribution
|
||||||
```
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
normal: (dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>) => distribution
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
```js
|
```js
|
||||||
normal(5, 1);
|
normal(5, 1)
|
||||||
normal({ p5: 4, p95: 10 });
|
normal({ p5: 4, p95: 10 })
|
||||||
normal({ mean: 5, stdev: 2 });
|
normal({ mean: 5, stdev: 2 })
|
||||||
|
normal(5 to 10, normal(3, 2))
|
||||||
|
normal({ mean: uniform(5, 9), stdev: 3 })
|
||||||
```
|
```
|
||||||
|
|
||||||
### Lognormal Distribution
|
### lognormal
|
||||||
|
|
||||||
**Definitions**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
lognormal: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
|
|
||||||
```
|
```
|
||||||
|
lognormal: (distribution|number, distribution|number) => distribution
|
||||||
```javascript
|
lognormal: (dict<{p5: distribution|number, p95: distribution|number}>) => distribution
|
||||||
lognormal: (dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>) => distribution
|
lognormal: (dict<{mean: distribution|number, stdev: distribution|number}>) => distribution
|
||||||
```
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
lognormal: (dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>) => distribution
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
@ -57,12 +54,10 @@ lognormal({ p5: 4, p95: 10 });
|
||||||
lognormal({ mean: 5, stdev: 2 });
|
lognormal({ mean: 5, stdev: 2 });
|
||||||
```
|
```
|
||||||
|
|
||||||
### Uniform Distribution
|
### uniform
|
||||||
|
|
||||||
**Definitions**
|
```
|
||||||
|
uniform: (distribution|number, distribution|number) => distribution
|
||||||
```javascript
|
|
||||||
uniform: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
@ -71,12 +66,10 @@ uniform: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
|
||||||
uniform(10, 12);
|
uniform(10, 12);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Beta Distribution
|
### beta
|
||||||
|
|
||||||
**Definitions**
|
```
|
||||||
|
beta: (distribution|number, distribution|number) => distribution
|
||||||
```javascript
|
|
||||||
beta: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
@ -85,12 +78,10 @@ beta: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
|
||||||
beta(20, 25);
|
beta(20, 25);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Cauchy Distribution
|
### cauchy
|
||||||
|
|
||||||
**Definitions**
|
```
|
||||||
|
cauchy: (distribution|number, distribution|number) => distribution
|
||||||
```javascript
|
|
||||||
cauchy: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
@ -99,12 +90,22 @@ cauchy: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
|
||||||
cauchy(5, 1);
|
cauchy(5, 1);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Gamma Distribution
|
### gamma
|
||||||
|
|
||||||
**Definitions**
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
gamma: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
|
gamma: (distribution|number, distribution|number) => distribution
|
||||||
|
```
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
|
```js
|
||||||
|
gamma(5, 1);
|
||||||
|
```
|
||||||
|
|
||||||
|
### logistic
|
||||||
|
|
||||||
|
```
|
||||||
|
logistic: (distribution|number, distribution|number) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
@ -113,30 +114,53 @@ gamma: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
|
||||||
gamma(5, 1);
|
gamma(5, 1);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Logistic Distribution
|
### exponential
|
||||||
|
|
||||||
**Definitions**
|
```
|
||||||
|
exponential: (distribution|number) => distribution
|
||||||
```javascript
|
|
||||||
logistic: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
gamma(5, 1);
|
exponential(2);
|
||||||
```
|
```
|
||||||
|
|
||||||
### To (Distribution)
|
### bernoulli
|
||||||
|
|
||||||
**Definitions**
|
```
|
||||||
|
bernoulli: (distribution|number) => distribution
|
||||||
```javascript
|
|
||||||
to: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
credibleIntervalToDistribution(frValueDistOrNumber, frValueDistOrNumber) => distribution;
|
bernoulli(0.5);
|
||||||
|
```
|
||||||
|
|
||||||
|
### triangular
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
triangular: (number, number, number) => distribution;
|
||||||
|
```
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
triangular(5, 10, 20);
|
||||||
|
```
|
||||||
|
|
||||||
|
### to / credibleIntervalToDistribution
|
||||||
|
|
||||||
|
The `to` function is an easy way to generate simple distributions using predicted _5th_ and _95th_ percentiles.
|
||||||
|
|
||||||
|
If both values are above zero, a `lognormal` distribution is used. If not, a `normal` distribution is used.
|
||||||
|
|
||||||
|
`To` is an alias for `credibleIntervalToDistribution`. However, because of its frequent use, it is recommended to use the shorter name.
|
||||||
|
|
||||||
|
```
|
||||||
|
to: (distribution|number, distribution|number) => distribution
|
||||||
|
credibleIntervalToDistribution(distribution|number, distribution|number) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
@ -147,97 +171,29 @@ to(5,10)
|
||||||
-5 to 5
|
-5 to 5
|
||||||
```
|
```
|
||||||
|
|
||||||
### Exponential
|
### mixture
|
||||||
|
|
||||||
**Definitions**
|
```
|
||||||
|
mixture: (...distributionLike, weights?:list<float>) => distribution
|
||||||
```javascript
|
mixture: (list<distributionLike>, weights?:list<float>) => distribution
|
||||||
exponential: (frValueDistOrNumber) => distribution;
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
exponential(2);
|
mixture(normal(5, 1), normal(10, 1), 8);
|
||||||
```
|
mx(normal(5, 1), normal(10, 1), [0.3, 0.7]);
|
||||||
|
mx([normal(5, 1), normal(10, 1)], [0.3, 0.7]);
|
||||||
### Bernoulli
|
|
||||||
|
|
||||||
**Definitions**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
bernoulli: (frValueDistOrNumber) => distribution;
|
|
||||||
```
|
|
||||||
|
|
||||||
**Examples**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
bernoulli(0.5);
|
|
||||||
```
|
|
||||||
|
|
||||||
### toContinuousPointSet
|
|
||||||
|
|
||||||
Converts a set of points to a continuous distribution
|
|
||||||
|
|
||||||
**Definitions**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
toContinuousPointSet: (array<dict<{x: numeric, y: numeric}>>) => distribution
|
|
||||||
```
|
|
||||||
|
|
||||||
**Examples**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
toContinuousPointSet([
|
|
||||||
{ x: 0, y: 0.1 },
|
|
||||||
{ x: 1, y: 0.2 },
|
|
||||||
{ x: 2, y: 0.15 },
|
|
||||||
{ x: 3, y: 0.1 },
|
|
||||||
]);
|
|
||||||
```
|
|
||||||
|
|
||||||
### toDiscretePointSet
|
|
||||||
|
|
||||||
Converts a set of points to a discrete distribution
|
|
||||||
|
|
||||||
**Definitions**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
toDiscretePointSet: (array<dict<{x: numeric, y: numeric}>>) => distribution
|
|
||||||
```
|
|
||||||
|
|
||||||
**Examples**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
toDiscretePointSet([
|
|
||||||
{ x: 0, y: 0.1 },
|
|
||||||
{ x: 1, y: 0.2 },
|
|
||||||
{ x: 2, y: 0.15 },
|
|
||||||
{ x: 3, y: 0.1 },
|
|
||||||
]);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
### mixture
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
mixture: (...distributionLike, weights:list<float>) => distribution
|
|
||||||
```
|
|
||||||
|
|
||||||
**Examples**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
mixture(normal(5, 1), normal(10, 1));
|
|
||||||
mx(normal(5, 1), normal(10, 1), [0.3, 0.7]);
|
|
||||||
```
|
|
||||||
|
|
||||||
### sample
|
### sample
|
||||||
|
|
||||||
Get one random sample from the distribution
|
One random sample from the distribution
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
sample(distribution) => number
|
sample: (distribution) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
@ -248,66 +204,70 @@ sample(normal(5, 2));
|
||||||
|
|
||||||
### sampleN
|
### sampleN
|
||||||
|
|
||||||
Get n random samples from the distribution
|
N random samples from the distribution
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
sampleN: (distribution, number) => list<number>
|
sampleN: (distribution, number) => list<number>
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sample: normal(5, 2), 100;
|
sampleN(normal(5, 2), 100);
|
||||||
```
|
```
|
||||||
|
|
||||||
### mean
|
### mean
|
||||||
|
|
||||||
Get the distribution mean
|
The distribution mean
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
mean: (distribution) => number;
|
mean: (distribution) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
mean: normal(5, 2);
|
mean(normal(5, 2));
|
||||||
```
|
```
|
||||||
|
|
||||||
### stdev
|
### stdev
|
||||||
|
|
||||||
```javascript
|
Standard deviation. Only works now on sample set distributions (so converts other distributions into sample set in order to calculate.)
|
||||||
stdev: (distribution) => number;
|
|
||||||
|
```
|
||||||
|
stdev: (distribution) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### variance
|
### variance
|
||||||
|
|
||||||
```javascript
|
Variance. Similar to stdev, only works now on sample set distributions.
|
||||||
variance: (distribution) => number;
|
|
||||||
|
```
|
||||||
|
variance: (distribution) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### mode
|
### mode
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
mode: (distribution) => number;
|
mode: (distribution) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### cdf
|
### cdf
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
cdf: (distribution, number) => number;
|
cdf: (distribution, number) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
cdf: normal(5, 2), 3;
|
cdf(normal(5, 2), 3);
|
||||||
```
|
```
|
||||||
|
|
||||||
### pdf
|
### pdf
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
pdf: (distribution, number) => number;
|
pdf: (distribution, number) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
@ -316,24 +276,26 @@ pdf: (distribution, number) => number;
|
||||||
pdf(normal(5, 2), 3);
|
pdf(normal(5, 2), 3);
|
||||||
```
|
```
|
||||||
|
|
||||||
### inv
|
### quantile
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
inv: (distribution, number) => number;
|
quantile: (distribution, number) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
inv(normal(5, 2), 0.5);
|
quantile(normal(5, 2), 0.5);
|
||||||
```
|
```
|
||||||
|
|
||||||
### toPointSet
|
### toPointSet
|
||||||
|
|
||||||
Converts a distribution to the pointSet format
|
**TODO: Will soon be called "PointSet.make"**
|
||||||
|
|
||||||
```javascript
|
Converts a distribution to the pointSet format.
|
||||||
toPointSet: (distribution) => pointSetDistribution;
|
|
||||||
|
```
|
||||||
|
toPointSet: (distribution) => pointSetDistribution
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
@ -344,10 +306,12 @@ toPointSet(normal(5, 2));
|
||||||
|
|
||||||
### toSampleSet
|
### toSampleSet
|
||||||
|
|
||||||
Converts a distribution to the sampleSet format, with n samples
|
**TODO: Will soon be called "SampleSet.make"**
|
||||||
|
|
||||||
```javascript
|
Converts a distribution to the sampleSet format, with n samples.
|
||||||
toSampleSet: (distribution, number) => sampleSetDistribution;
|
|
||||||
|
```
|
||||||
|
toSampleSet: (distribution, number) => sampleSetDistribution
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
@ -360,7 +324,7 @@ toSampleSet(normal(5, 2), 1000);
|
||||||
|
|
||||||
Truncates the left side of a distribution. Returns either a pointSet distribution or a symbolic distribution.
|
Truncates the left side of a distribution. Returns either a pointSet distribution or a symbolic distribution.
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
truncateLeft: (distribution, l => number) => distribution
|
truncateLeft: (distribution, l => number) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -374,7 +338,7 @@ truncateLeft(normal(5, 2), 3);
|
||||||
|
|
||||||
Truncates the right side of a distribution. Returns either a pointSet distribution or a symbolic distribution.
|
Truncates the right side of a distribution. Returns either a pointSet distribution or a symbolic distribution.
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
truncateRight: (distribution, r => number) => distribution
|
truncateRight: (distribution, r => number) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -384,14 +348,12 @@ truncateRight: (distribution, r => number) => distribution
|
||||||
truncateLeft(normal(5, 2), 6);
|
truncateLeft(normal(5, 2), 6);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Scoring
|
|
||||||
|
|
||||||
### klDivergence
|
### klDivergence
|
||||||
|
|
||||||
Kullback–Leibler divergence between two distributions
|
[Kullback–Leibler divergence](https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence) between two distributions.
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
klDivergence: (distribution, distribution) => number;
|
klDivergence: (distribution, distribution) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
@ -404,8 +366,8 @@ klDivergence(normal(5, 2), normal(5, 4)); // returns 0.57
|
||||||
|
|
||||||
### toString
|
### toString
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
toString: (distribution) => string;
|
toString: (distribution) => string
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
@ -414,42 +376,46 @@ toString: (distribution) => string;
|
||||||
toString(normal(5, 2));
|
toString(normal(5, 2));
|
||||||
```
|
```
|
||||||
|
|
||||||
### toSparkline
|
### sparkline
|
||||||
|
|
||||||
Produce a sparkline of length n
|
Produce a sparkline of length n. For example, `▁▁▁▁▁▂▄▆▇██▇▆▄▂▁▁▁▁▁`. These can be useful for testing or quick text visualizations.
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
toSparkline: (distribution, n = 20) => string;
|
sparkline: (distribution, n = 20) => string
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
toSparkline(normal(5, 2), 10);
|
toSparkline(truncateLeft(normal(5, 2), 3), 20); // produces ▁▇█████▇▅▄▃▂▂▁▁▁▁▁▁▁
|
||||||
```
|
```
|
||||||
|
|
||||||
### inspect
|
### inspect
|
||||||
|
|
||||||
Prints the value of the distribution to the Javascript console, then returns the distribution.
|
Prints the value of the distribution to the Javascript console, then returns the distribution. Useful for debugging.
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
inspect: (distribution) => distribution;
|
inspect: (distribution) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
inspect(normal(5, 2));
|
inspect(normal(5, 2)); // logs "normal(5, 2)" to the javascript console and returns the distribution.
|
||||||
```
|
```
|
||||||
|
|
||||||
## Normalization
|
## Normalization
|
||||||
|
|
||||||
|
There are some situations where computation will return unnormalized distributions. This means that their cumulative sums are not equal to 1.0. Unnormalized distributions are not valid for many relevant functions; for example, klDivergence and scoring.
|
||||||
|
|
||||||
|
The only functions that do not return normalized distributions are the pointwise arithmetic operations and the scalewise arithmetic operations. If you use these functions, it is recommended that you consider normalizing the resulting distributions.
|
||||||
|
|
||||||
### normalize
|
### normalize
|
||||||
|
|
||||||
Normalize a distribution. This means scaling it appropriately so that it's cumulative sum is equal to 1.
|
Normalize a distribution. This means scaling it appropriately so that it's cumulative sum is equal to 1.
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
normalize: (distribution) => distribution;
|
normalize: (distribution) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
@ -462,8 +428,8 @@ normalize(normal(5, 2));
|
||||||
|
|
||||||
Check of a distribution is normalized. Most distributions are typically normalized, but there are some commands that could produce non-normalized distributions.
|
Check of a distribution is normalized. Most distributions are typically normalized, but there are some commands that could produce non-normalized distributions.
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
isNormalized: (distribution) => bool;
|
isNormalized: (distribution) => bool
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
@ -474,10 +440,12 @@ isNormalized(normal(5, 2)); // returns true
|
||||||
|
|
||||||
### integralSum
|
### integralSum
|
||||||
|
|
||||||
Get the sum of the integral of a distribution. If the distribution is normalized, this will be 1.
|
**Note: If you have suggestions for better names for this, please let us know.**
|
||||||
|
|
||||||
```javascript
|
Get the sum of the integral of a distribution. If the distribution is normalized, this will be 1.0. This is useful for understanding unnormalized distributions.
|
||||||
integralSum: (distribution) => number;
|
|
||||||
|
```
|
||||||
|
integralSum: (distribution) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
@ -486,151 +454,208 @@ integralSum: (distribution) => number;
|
||||||
integralSum(normal(5, 2));
|
integralSum(normal(5, 2));
|
||||||
```
|
```
|
||||||
|
|
||||||
## Algebraic Operations
|
## Regular Arithmetic Operations
|
||||||
|
|
||||||
|
Regular arithmetic operations cover the basic mathematical operations on distributions. They work much like their equivalent operations on numbers.
|
||||||
|
|
||||||
|
The infixes `+`,`-`, `*`, `/`, `^` are supported for addition, subtraction, multiplication, division, power, and unaryMinus.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
pointMass(5 + 10) == pointMass(5) + pointMass(10);
|
||||||
|
```
|
||||||
|
|
||||||
### add
|
### add
|
||||||
|
|
||||||
|
```
|
||||||
|
add: (distributionLike, distributionLike) => distribution
|
||||||
|
```
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
add: (distributionLike, distributionLike) => distribution;
|
normal(0, 1) + normal(1, 3); // returns normal(1, 3.16...)
|
||||||
|
add(normal(0, 1), normal(1, 3)); // returns normal(1, 3.16...)
|
||||||
```
|
```
|
||||||
|
|
||||||
### sum
|
### sum
|
||||||
|
|
||||||
```javascript
|
**Todo: Not yet implemented**
|
||||||
|
|
||||||
|
```
|
||||||
sum: (list<distributionLike>) => distribution
|
sum: (list<distributionLike>) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
sum([normal(0, 1), normal(1, 3), uniform(10, 1)]);
|
||||||
|
```
|
||||||
|
|
||||||
### multiply
|
### multiply
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
multiply: (distributionLike, distributionLike) => distribution;
|
multiply: (distributionLike, distributionLike) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### product
|
### product
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
product: (list<distributionLike>) => distribution
|
product: (list<distributionLike>) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### subtract
|
### subtract
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
subtract: (distributionLike, distributionLike) => distribution;
|
subtract: (distributionLike, distributionLike) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### divide
|
### divide
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
divide: (distributionLike, distributionLike) => distribution;
|
divide: (distributionLike, distributionLike) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### pow
|
### pow
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
pow: (distributionLike, distributionLike) => distribution;
|
pow: (distributionLike, distributionLike) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### exp
|
### exp
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
exp: (distributionLike, distributionLike) => distribution;
|
exp: (distributionLike, distributionLike) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### log
|
### log
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
log: (distributionLike, distributionLike) => distribution;
|
log: (distributionLike, distributionLike) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### log10
|
### log10
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
log10: (distributionLike, distributionLike) => distribution;
|
log10: (distributionLike, distributionLike) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### unaryMinus
|
### unaryMinus
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
unaryMinus: (distribution) => distribution;
|
unaryMinus: (distribution) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
## Pointwise Operations
|
**Examples**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
-normal(5, 2); // same as normal(-5, 2)
|
||||||
|
unaryMinus(normal(5, 2)); // same as normal(-5, 2)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Pointwise Arithmetic Operations
|
||||||
|
|
||||||
|
<Admonition type="caution" title="Unnormalized Results">
|
||||||
|
<p>
|
||||||
|
Pointwise arithmetic operations typically return unnormalized or completely
|
||||||
|
invalid distributions. For example, the operation{" "}
|
||||||
|
<code>normal(5,2) .- uniform(10,12)</code> results in a distribution-like
|
||||||
|
object with negative probability mass.
|
||||||
|
</p>
|
||||||
|
</Admonition>
|
||||||
|
|
||||||
|
Pointwise arithmetic operations cover the standard arithmetic operations, but work in a different way than the regular operations. These operate on the y-values of the distributions instead of the x-values. A pointwise addition would add the y-values of two distributions.
|
||||||
|
|
||||||
|
The infixes `.+`,`.-`, `.*`, `./`, `.^` are supported for their respective operations.
|
||||||
|
|
||||||
|
The `mixture` methods works with pointwise addition.
|
||||||
|
|
||||||
### dotAdd
|
### dotAdd
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
dotAdd: (distributionLike, distributionLike) => distribution;
|
dotAdd: (distributionLike, distributionLike) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### dotMultiply
|
### dotMultiply
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
dotMultiply: (distributionLike, distributionLike) => distribution;
|
dotMultiply: (distributionLike, distributionLike) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### dotSubtract
|
### dotSubtract
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
dotSubtract: (distributionLike, distributionLike) => distribution;
|
dotSubtract: (distributionLike, distributionLike) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### dotDivide
|
### dotDivide
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
dotDivide: (distributionLike, distributionLike) => distribution;
|
dotDivide: (distributionLike, distributionLike) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### dotPow
|
### dotPow
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
dotPow: (distributionLike, distributionLike) => distribution;
|
dotPow: (distributionLike, distributionLike) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### dotExp
|
### dotExp
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
dotExp: (distributionLike, distributionLike) => distribution;
|
dotExp: (distributionLike, distributionLike) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
## Scale Operations
|
## Scale Arithmetic Operations
|
||||||
|
|
||||||
### scaleMultiply
|
<Admonition type="caution" title="Likely to change">
|
||||||
|
<p>
|
||||||
|
We're planning on removing scale operations in favor of more general
|
||||||
|
functions soon.
|
||||||
|
</p>
|
||||||
|
</Admonition>
|
||||||
|
|
||||||
```javascript
|
Scale operations are similar to pointwise operations, but operate on a constant y-value instead of y-values coming from a distribution. You can think about this as scaling a distribution vertically by a constant.
|
||||||
scaleMultiply: (distributionLike, number) => distribution;
|
|
||||||
|
The following items would be equivalent.
|
||||||
|
|
||||||
|
```js
|
||||||
|
scalePow(normal(5,2), 2)
|
||||||
|
mapY(normal(5,2), {|y| y ^ 2}) // Not yet available
|
||||||
```
|
```
|
||||||
|
|
||||||
### scalePow
|
### scalePow
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
scalePow: (distributionLike, number) => distribution;
|
scalePow: (distributionLike, number) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### scaleExp
|
### scaleExp
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
scaleExp: (distributionLike, number) => distribution;
|
scaleExp: (distributionLike, number) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### scaleLog
|
### scaleLog
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
scaleLog: (distributionLike, number) => distribution;
|
scaleLog: (distributionLike, number) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
### scaleLog10
|
### scaleLog10
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
scaleLog10: (distributionLike, number) => distribution;
|
scaleLog10: (distributionLike, number) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
## Special
|
## Special
|
||||||
|
|
||||||
### Declaration (Continuous Function)
|
### Declaration (Continuous Functions)
|
||||||
|
|
||||||
Adds metadata to a function of the input ranges. Works now for numeric and date inputs. This is useful when making predictions. It allows you to limit the domain that your prediction will be used and scored within.
|
Adds metadata to a function of the input ranges. Works now for numeric and date inputs. This is useful when making formal predictions. It allows you to limit the domain that your prediction will be used and scored within.
|
||||||
|
|
||||||
```javascript
|
Declarations are currently experimental and will likely be removed or changed in the future.
|
||||||
|
|
||||||
|
```
|
||||||
declareFn: (dict<{fn: lambda, inputs: array<dict<{min: number, max: number}>>}>) => declaration
|
declareFn: (dict<{fn: lambda, inputs: array<dict<{min: number, max: number}>>}>) => declaration
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -3,20 +3,56 @@ sidebar_position: 4
|
||||||
title: Point Set Distribution
|
title: Point Set Distribution
|
||||||
---
|
---
|
||||||
|
|
||||||
|
:::danger
|
||||||
|
These functions aren't yet implemented with these specific names. This should be changed soon
|
||||||
|
:::
|
||||||
|
|
||||||
|
Point set distributions are one of the three distribution formats. They are stored as a list of x-y coordinates representing both discrete and continuous distributions.
|
||||||
|
|
||||||
|
One complication is that it's possible to represent invalid probability distributions in the point set format. For example, you can represent shapes with negative values, or shapes that are not normalized.
|
||||||
|
|
||||||
### make
|
### make
|
||||||
|
|
||||||
|
Converts the distribution in question into a point set distribution. If the distribution is symbolic, then it does this by taking the quantiles. If the distribution is a sample set, then it uses a version of kernel density estimation to approximate the point set format. One complication of this latter process is that if there is a high proportion of overlapping samples (samples that are exactly the same as each other), it will convert these samples into discrete point masses. Eventually we'd like to add further methods to help adjust this process.
|
||||||
|
|
||||||
```
|
```
|
||||||
PointSet.make: (distribution) => pointSetDist
|
PointSet.make: (distribution) => pointSetDist
|
||||||
```
|
```
|
||||||
|
|
||||||
### makeContinuous
|
### makeContinuous
|
||||||
|
|
||||||
|
**TODO: Now called "toContinuousPointSet"**
|
||||||
|
|
||||||
|
Converts a set of x-y coordinates directly into a continuous distribution.
|
||||||
|
|
||||||
```
|
```
|
||||||
PointSet.makeContinuous: (list<{x: number, y: number}>) => pointSetDist
|
PointSet.makeContinuous: (list<{x: number, y: number}>) => pointSetDist
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
PointSet.makeContinuous([
|
||||||
|
{ x: 0, y: 0.1 },
|
||||||
|
{ x: 1, y: 0.2 },
|
||||||
|
{ x: 2, y: 0.15 },
|
||||||
|
{ x: 3, y: 0.1 },
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
### makeDiscrete
|
### makeDiscrete
|
||||||
|
|
||||||
|
**TODO: Now called "toDiscretePointSet"**
|
||||||
|
|
||||||
|
Converts a set of x-y coordinates directly into a discrete distribution.
|
||||||
|
|
||||||
```
|
```
|
||||||
PointSet.makeDiscrete: (list<{x: number, y: number}>) => pointSetDist
|
PointSet.makeDiscrete: (list<{x: number, y: number}>) => pointSetDist
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
PointSet.makeDiscrete([
|
||||||
|
{ x: 0, y: 0.1 },
|
||||||
|
{ x: 1, y: 0.2 },
|
||||||
|
{ x: 2, y: 0.15 },
|
||||||
|
{ x: 3, y: 0.1 },
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
|
@ -3,12 +3,22 @@ sidebar_position: 5
|
||||||
title: Sample Set Distribution
|
title: Sample Set Distribution
|
||||||
---
|
---
|
||||||
|
|
||||||
|
:::danger
|
||||||
|
These functions aren't yet implemented with these specific names. This should be added soon.
|
||||||
|
:::
|
||||||
|
|
||||||
|
Sample set distributions are one of the three distribution formats. Internally, they are stored as a list of numbers. It's useful to distinguish point set distributions from arbitrary lists of numbers to make it clear which functions are applicable.
|
||||||
|
|
||||||
|
Monte Carlo calculations typically result in sample set distributions.
|
||||||
|
|
||||||
|
All regular distribution function work on sample set distributions. In addition, there are several functions that only work on sample set distributions.
|
||||||
|
|
||||||
### make
|
### make
|
||||||
|
|
||||||
```
|
```
|
||||||
SampleSet.make: (distribution) => sampleSet
|
SampleSet.make: (distribution) => sampleSet
|
||||||
SampleSet.make: (() => number) => sampleSet
|
|
||||||
SampleSet.make: (list<number>) => sampleSet
|
SampleSet.make: (list<number>) => sampleSet
|
||||||
|
SampleSet.make: (() => number) => sampleSet // not yet implemented
|
||||||
```
|
```
|
||||||
|
|
||||||
### map
|
### map
|
||||||
|
@ -35,7 +45,7 @@ SampleSet.map3: (sampleSet, sampleSet, sampleSet, ((number, number, number) => n
|
||||||
SampleSet.toList: (sampleSet) => list<number>
|
SampleSet.toList: (sampleSet) => list<number>
|
||||||
```
|
```
|
||||||
|
|
||||||
Gets the internal samples of a sampleSet distribution. This is separate from the sampleN() function, which would shuffle the samples. toList() maintains order and length. Gets the internal samples of a sampleSet distribution. This is separate from the sampleN() function, which would shuffle the samples. toList() maintains order and length.
|
Gets the internal samples of a sampleSet distribution. This is separate from the sampleN() function, which would shuffle the samples. toList() maintains order and length.
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,10 @@ sidebar_position: 6
|
||||||
title: Duration
|
title: Duration
|
||||||
---
|
---
|
||||||
|
|
||||||
|
Duration works with the [Date](/docs/Api/Date) type. Similar to the Date implementation, the Duration functions are early and experimental. There is no support yet for date or duration probability distributions.
|
||||||
|
|
||||||
|
Durations are stored in Unix milliseconds.
|
||||||
|
|
||||||
import TOCInline from "@theme/TOCInline";
|
import TOCInline from "@theme/TOCInline";
|
||||||
|
|
||||||
<TOCInline toc={toc} />
|
<TOCInline toc={toc} />
|
||||||
|
|
|
@ -3,13 +3,21 @@ sidebar_position: 7
|
||||||
title: List
|
title: List
|
||||||
---
|
---
|
||||||
|
|
||||||
|
Squiggle lists are a lot like Python lists or Ruby arrays. They accept all types.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
myList = [3, normal(5, 2), "random"];
|
||||||
|
```
|
||||||
|
|
||||||
### make
|
### make
|
||||||
|
|
||||||
|
**Note: currently just called `makeList`, without the preix**
|
||||||
|
|
||||||
```
|
```
|
||||||
List.make: (number, 'a) => list<'a>
|
List.make: (number, 'a) => list<'a>
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns an array of size `n` filled with value `e`.
|
Returns an array of size `n` filled with the value.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
List.make(4, 1); // creates the list [1, 1, 1, 1]
|
List.make(4, 1); // creates the list [1, 1, 1, 1]
|
||||||
|
@ -31,6 +39,8 @@ length: (list<'a>) => number
|
||||||
|
|
||||||
### up to
|
### up to
|
||||||
|
|
||||||
|
**Note: currently just called `upTo`, without the preix**
|
||||||
|
|
||||||
```
|
```
|
||||||
List.upTo: (low:number, high:number) => list<number>
|
List.upTo: (low:number, high:number) => list<number>
|
||||||
```
|
```
|
||||||
|
|
|
@ -6,7 +6,7 @@ title: Math
|
||||||
### E
|
### E
|
||||||
|
|
||||||
```
|
```
|
||||||
Math.E:
|
Math.e:
|
||||||
```
|
```
|
||||||
|
|
||||||
Euler's number; ≈ 2.718281828459045
|
Euler's number; ≈ 2.718281828459045
|
||||||
|
@ -14,7 +14,7 @@ Euler's number; ≈ 2.718281828459045
|
||||||
### LN2
|
### LN2
|
||||||
|
|
||||||
```
|
```
|
||||||
Math.LN2:
|
Math.ln2:
|
||||||
```
|
```
|
||||||
|
|
||||||
Natural logarithm of 2; ≈ 0.6931471805599453
|
Natural logarithm of 2; ≈ 0.6931471805599453
|
||||||
|
@ -22,7 +22,7 @@ Natural logarithm of 2; ≈ 0.6931471805599453
|
||||||
### LN10
|
### LN10
|
||||||
|
|
||||||
```
|
```
|
||||||
Math.LN10:
|
Math.ln10:
|
||||||
```
|
```
|
||||||
|
|
||||||
Natural logarithm of 10; ≈ 2.302585092994046
|
Natural logarithm of 10; ≈ 2.302585092994046
|
||||||
|
@ -30,7 +30,7 @@ Natural logarithm of 10; ≈ 2.302585092994046
|
||||||
### LOG2E
|
### LOG2E
|
||||||
|
|
||||||
```
|
```
|
||||||
Math.LOG2E:
|
Math.log2e:
|
||||||
```
|
```
|
||||||
|
|
||||||
Base 2 logarithm of E; ≈ 1.4426950408889634Base 2 logarithm of E; ≈ 1.4426950408889634
|
Base 2 logarithm of E; ≈ 1.4426950408889634Base 2 logarithm of E; ≈ 1.4426950408889634
|
||||||
|
@ -38,7 +38,7 @@ Base 2 logarithm of E; ≈ 1.4426950408889634Base 2 logarithm of E; ≈ 1.442695
|
||||||
### LOG10E
|
### LOG10E
|
||||||
|
|
||||||
```
|
```
|
||||||
Math.LOG10E:
|
Math.log10e:
|
||||||
```
|
```
|
||||||
|
|
||||||
Base 10 logarithm of E; ≈ 0.4342944819032518
|
Base 10 logarithm of E; ≈ 0.4342944819032518
|
||||||
|
@ -46,7 +46,7 @@ Base 10 logarithm of E; ≈ 0.4342944819032518
|
||||||
### PI
|
### PI
|
||||||
|
|
||||||
```
|
```
|
||||||
Math.PI:
|
Math.pi:
|
||||||
```
|
```
|
||||||
|
|
||||||
Pi - ratio of the circumference to the diameter of a circle; ≈ 3.141592653589793
|
Pi - ratio of the circumference to the diameter of a circle; ≈ 3.141592653589793
|
||||||
|
@ -54,7 +54,7 @@ Pi - ratio of the circumference to the diameter of a circle; ≈ 3.1415926535897
|
||||||
### SQRT1_2
|
### SQRT1_2
|
||||||
|
|
||||||
```
|
```
|
||||||
Math.SQRT1_2:
|
Math.sqrt1_2:
|
||||||
```
|
```
|
||||||
|
|
||||||
Square root of 1/2; ≈ 0.7071067811865476
|
Square root of 1/2; ≈ 0.7071067811865476
|
||||||
|
@ -62,7 +62,7 @@ Square root of 1/2; ≈ 0.7071067811865476
|
||||||
### SQRT2
|
### SQRT2
|
||||||
|
|
||||||
```
|
```
|
||||||
Math.SQRT2:
|
Math.sqrt2:
|
||||||
```
|
```
|
||||||
|
|
||||||
Square root of 2; ≈ 1.4142135623730951
|
Square root of 2; ≈ 1.4142135623730951
|
||||||
|
@ -70,7 +70,7 @@ Square root of 2; ≈ 1.4142135623730951
|
||||||
### PHI
|
### PHI
|
||||||
|
|
||||||
```
|
```
|
||||||
Math.PHI:
|
Math.phi:
|
||||||
```
|
```
|
||||||
|
|
||||||
Phi is the golden ratio. 1.618033988749895
|
Phi is the golden ratio. 1.618033988749895
|
||||||
|
@ -78,7 +78,7 @@ Phi is the golden ratio. 1.618033988749895
|
||||||
### TAU
|
### TAU
|
||||||
|
|
||||||
```
|
```
|
||||||
Math.TAU:
|
Math.tau:
|
||||||
```
|
```
|
||||||
|
|
||||||
Tau is the ratio constant of a circle's circumference to radius, equal to 2 \* pi. 6.283185307179586
|
Tau is the ratio constant of a circle's circumference to radius, equal to 2 \* pi. 6.283185307179586
|
||||||
|
|
|
@ -3,63 +3,67 @@ sidebar_position: 9
|
||||||
title: Number
|
title: Number
|
||||||
---
|
---
|
||||||
|
|
||||||
|
Squiggle `numbers` are Javascript floats.
|
||||||
|
|
||||||
|
Many of the functions below work on lists or pairs of numbers.
|
||||||
|
|
||||||
import TOCInline from "@theme/TOCInline";
|
import TOCInline from "@theme/TOCInline";
|
||||||
|
|
||||||
<TOCInline toc={toc} />
|
<TOCInline toc={toc} />
|
||||||
|
|
||||||
### ceil
|
### ceil
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
ceil: (number) => number;
|
ceil: (number) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### floor
|
### floor
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
floor: (number) => number;
|
floor: (number) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### abs
|
### abs
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
abs: (number) => number;
|
abs: (number) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### round
|
### round
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
round: (number) => number;
|
round: (number) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
## Statistics
|
## Statistics
|
||||||
|
|
||||||
### max
|
### max
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
max: (list<number>) => number
|
max: (list<number>) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### min
|
### min
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
min: (list<number>) => number
|
min: (list<number>) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### mean
|
### mean
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
mean: (list<number>) => number
|
mean: (list<number>) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### stdev
|
### stdev
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
stdev: (list<number>) => number
|
stdev: (list<number>) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### variance
|
### variance
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
variance: (list<number>) => number
|
variance: (list<number>) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -67,25 +71,25 @@ variance: (list<number>) => number
|
||||||
|
|
||||||
### unaryMinus
|
### unaryMinus
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
unaryMinus: (number) => number;
|
unaryMinus: (number) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### equal
|
### equal
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
equal: (number, number) => boolean;
|
equal: (number, number) => boolean
|
||||||
```
|
```
|
||||||
|
|
||||||
### add
|
### add
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
add: (number, number) => number;
|
add: (number, number) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### sum
|
### sum
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
sum: (list<number>) => number
|
sum: (list<number>) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -97,13 +101,13 @@ cumsum: (list<number>) => list<number>
|
||||||
|
|
||||||
### multiply
|
### multiply
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
multiply: (number, number) => number;
|
multiply: (number, number) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### product
|
### product
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
product: (list<number>) => number
|
product: (list<number>) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -115,30 +119,30 @@ cumprod: (list<number>) => list<number>
|
||||||
|
|
||||||
### subtract
|
### subtract
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
subtract: (number, number) => number;
|
subtract: (number, number) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### divide
|
### divide
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
divide: (number, number) => number;
|
divide: (number, number) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### pow
|
### pow
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
pow: (number, number) => number;
|
pow: (number, number) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### exp
|
### exp
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
exp: (number) => number;
|
exp: (number) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
### log
|
### log
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
log: (number) => number;
|
log: (number) => number
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
title: "Distribution Creation"
|
title: "Distribution Creation"
|
||||||
sidebar_position: 20
|
sidebar_position: 2
|
||||||
---
|
---
|
||||||
|
|
||||||
import { SquiggleEditor } from "../../src/components/SquiggleEditor";
|
import { SquiggleEditor } from "../../src/components/SquiggleEditor";
|
||||||
|
@ -91,7 +91,7 @@ The `mixture` mixes combines multiple distributions to create a mixture. You can
|
||||||
|
|
||||||
### Arguments
|
### Arguments
|
||||||
|
|
||||||
- `distributions`: A set of distributions or numbers, each passed as a paramater. Numbers will be converted into Delta distributions.
|
- `distributions`: A set of distributions or numbers, each passed as a paramater. Numbers will be converted into point mass distributions.
|
||||||
- `weights`: An optional array of numbers, each representing the weight of its corresponding distribution. The weights will be re-scaled to add to `1.0`. If a weights array is provided, it must be the same length as the distribution paramaters.
|
- `weights`: An optional array of numbers, each representing the weight of its corresponding distribution. The weights will be re-scaled to add to `1.0`. If a weights array is provided, it must be the same length as the distribution paramaters.
|
||||||
|
|
||||||
### Aliases
|
### Aliases
|
||||||
|
@ -221,22 +221,22 @@ Creates a [uniform distribution](<https://en.wikipedia.org/wiki/Uniform_distribu
|
||||||
</p>
|
</p>
|
||||||
</Admonition>
|
</Admonition>
|
||||||
|
|
||||||
## Delta
|
## Point Mass
|
||||||
|
|
||||||
`delta(value:number)`
|
`pointMass(value:number)`
|
||||||
|
|
||||||
Creates a discrete distribution with all of its probability mass at point `value`.
|
Creates a discrete distribution with all of its probability mass at point `value`.
|
||||||
|
|
||||||
Few Squiggle users call the function `delta()` directly. Numbers are converted into delta distributions automatically, when it is appropriate.
|
Few Squiggle users call the function `pointMass()` directly. Numbers are converted into point mass distributions automatically, when it is appropriate.
|
||||||
|
|
||||||
For example, in the function `mixture(1,2,normal(5,2))`, the first two arguments will get converted into delta distributions
|
For example, in the function `mixture(1,2,normal(5,2))`, the first two arguments will get converted into point mass distributions
|
||||||
with values at 1 and 2. Therefore, this is the same as `mixture(delta(1),delta(2),normal(5,2))`.
|
with values at 1 and 2. Therefore, this is the same as `mixture(pointMass(1),pointMass(2),pointMass(5,2))`.
|
||||||
|
|
||||||
`Delta()` distributions are currently the only discrete distributions accessible in Squiggle.
|
`pointMass()` distributions are currently the only discrete distributions accessible in Squiggle.
|
||||||
|
|
||||||
<Tabs>
|
<Tabs>
|
||||||
<TabItem value="ex1" label="delta(3)" default>
|
<TabItem value="ex1" label="pointMass(3)" default>
|
||||||
<SquiggleEditor initialSquiggleString="delta(3)" />
|
<SquiggleEditor initialSquiggleString="pointMass(3)" />
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value="ex3" label="mixture(1,3,5)">
|
<TabItem value="ex3" label="mixture(1,3,5)">
|
||||||
<SquiggleEditor initialSquiggleString="mixture(1,3,5)" />
|
<SquiggleEditor initialSquiggleString="mixture(1,3,5)" />
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
title: "Functions Reference"
|
title: "Distribution Functions"
|
||||||
sidebar_position: 3
|
sidebar_position: 3
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ given point x.
|
||||||
### Cumulative density function
|
### Cumulative density function
|
||||||
|
|
||||||
The `cdf(dist, x)` gives the cumulative probability of the distribution
|
The `cdf(dist, x)` gives the cumulative probability of the distribution
|
||||||
or all values lower than x. It is the inverse of `inv`.
|
or all values lower than x. It is the inverse of `quantile`.
|
||||||
|
|
||||||
<SquiggleEditor initialSquiggleString="cdf(normal(0,1),0)" />
|
<SquiggleEditor initialSquiggleString="cdf(normal(0,1),0)" />
|
||||||
|
|
||||||
|
@ -179,13 +179,13 @@ or all values lower than x. It is the inverse of `inv`.
|
||||||
- `x` must be a scalar
|
- `x` must be a scalar
|
||||||
- `dist` must be a distribution
|
- `dist` must be a distribution
|
||||||
|
|
||||||
### Inverse CDF
|
### Quantile
|
||||||
|
|
||||||
The `inv(dist, prob)` gives the value x or which the probability for all values
|
The `quantile(dist, prob)` gives the value x or which the probability for all values
|
||||||
lower than x is equal to prob. It is the inverse of `cdf`. In the literature, it
|
lower than x is equal to prob. It is the inverse of `cdf`. In the literature, it
|
||||||
is also known as the quantiles function.
|
is also known as the quantiles function.
|
||||||
|
|
||||||
<SquiggleEditor initialSquiggleString="inv(normal(0,1),0.5)" />
|
<SquiggleEditor initialSquiggleString="quantile(normal(0,1),0.5)" />
|
||||||
|
|
||||||
#### Validity
|
#### Validity
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,6 @@ ozzie_estimate(1) * nuno_estimate(1, 1)`}
|
||||||
|
|
||||||
## See more
|
## See more
|
||||||
|
|
||||||
- [Distribution creation](./Distributions)
|
- [Distribution creation](./DistributionCreation)
|
||||||
- [Functions reference](./Functions)
|
- [Functions reference](./Functions)
|
||||||
- [Gallery](../Discussions/Gallery)
|
- [Gallery](../Discussions/Gallery)
|
||||||
|
|
|
@ -122,14 +122,14 @@ TODO
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
## `pdf`, `cdf`, and `inv`
|
## `pdf`, `cdf`, and `quantile`
|
||||||
|
|
||||||
With $\forall dist, pdf := x \mapsto \texttt{pdf}(dist, x) \land cdf := x \mapsto \texttt{cdf}(dist, x) \land inv := p \mapsto \texttt{inv}(dist, p)$,
|
With $\forall dist, pdf := x \mapsto \texttt{pdf}(dist, x) \land cdf := x \mapsto \texttt{cdf}(dist, x) \land quantile := p \mapsto \texttt{quantile}(dist, p)$,
|
||||||
|
|
||||||
### `cdf` and `inv` are inverses
|
### `cdf` and `quantile` are inverses
|
||||||
|
|
||||||
$$
|
$$
|
||||||
\forall x \in (0,1), cdf(inv(x)) = x \land \forall x \in \texttt{dom}(cdf), x = inv(cdf(x))
|
\forall x \in (0,1), cdf(quantile(x)) = x \land \forall x \in \texttt{dom}(cdf), x = quantile(cdf(x))
|
||||||
$$
|
$$
|
||||||
|
|
||||||
### The codomain of `cdf` equals the open interval `(0,1)` equals the codomain of `pdf`
|
### The codomain of `cdf` equals the open interval `(0,1)` equals the codomain of `pdf`
|
||||||
|
|
|
@ -25,7 +25,7 @@ $$
|
||||||
a \cdot Normal(\mu, \sigma) = Normal(a \cdot \mu, |a| \cdot \sigma)
|
a \cdot Normal(\mu, \sigma) = Normal(a \cdot \mu, |a| \cdot \sigma)
|
||||||
$$
|
$$
|
||||||
|
|
||||||
We can now look at the inverse cdf of a $Normal(0,1)$. We find that the 95% point is reached at $1.6448536269514722$. ([source](https://stackoverflow.com/questions/20626994/how-to-calculate-the-inverse-of-the-normal-cumulative-distribution-function-in-p)) This means that the 90% confidence interval is $[-1.6448536269514722, 1.6448536269514722]$, which has a width of $2 \cdot 1.6448536269514722$.
|
We can now look at the quantile of a $Normal(0,1)$. We find that the 95% point is reached at $1.6448536269514722$. ([source](https://stackoverflow.com/questions/20626994/how-to-calculate-the-inverse-of-the-normal-cumulative-distribution-function-in-p)) This means that the 90% confidence interval is $[-1.6448536269514722, 1.6448536269514722]$, which has a width of $2 \cdot 1.6448536269514722$.
|
||||||
|
|
||||||
So then, if we take a $Normal(0,1)$ and we multiply it by $\frac{(high -. low)}{(2. *. 1.6448536269514722)}$, it's 90% confidence interval will be multiplied by the same amount. Then we just have to shift it by the mean to get our target normal.
|
So then, if we take a $Normal(0,1)$ and we multiply it by $\frac{(high -. low)}{(2. *. 1.6448536269514722)}$, it's 90% confidence interval will be multiplied by the same amount. Then we just have to shift it by the mean to get our target normal.
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ const config = {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "doc",
|
type: "doc",
|
||||||
docId: "Api/Dictionary",
|
docId: "Api/DistGeneric",
|
||||||
position: "left",
|
position: "left",
|
||||||
label: "API",
|
label: "API",
|
||||||
},
|
},
|
||||||
|
|
|
@ -26,6 +26,11 @@ const sidebars = {
|
||||||
id: "Introduction",
|
id: "Introduction",
|
||||||
label: "Introduction",
|
label: "Introduction",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: "doc",
|
||||||
|
id: "Node-Packages",
|
||||||
|
label: "Node Packages",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: "category",
|
type: "category",
|
||||||
label: "Guides",
|
label: "Guides",
|
||||||
|
|
|
@ -3,5 +3,4 @@ module.exports = {
|
||||||
theme: {
|
theme: {
|
||||||
extend: {},
|
extend: {},
|
||||||
},
|
},
|
||||||
plugins: [require("@tailwindcss/forms")],
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user