fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Experiments, Outcomes, Sample Spaces, and Events

Install and import#

bash
npm install fintech-algorithms
ts
import { experimentsOutcomesSampleSpacesAndEvents } from "fintech-algorithms/foundations/probability-and-random-variables/experiments-outcomes-sample-spaces-and-events";

Signature#

experimentsOutcomesSampleSpacesAndEvents(input)

Sizes a sample space and a candidate event, and checks that every outcome named in the event actually appears in the sample space.

Parameters#

NameTypeNotes
input{ pA: number; pB: number; pAB: number; outcomes: unknown[]; event: unknown[] }outcomes lists the sample space and event the subset being examined; membership is tested with strict equality, so outcomes are usually strings or numbers. The family-wide probabilities pA, pB, and pAB are validated on every call even though this topic does not use their values.
pA: 0 <= pA <= 1 · pB: 0 <= pB <= 1 · pAB: 0 <= pAB <= min(pA, pB)

Returns#

{ sampleSpaceSize: number; eventSize: number; eventIsSubset: boolean }

sampleSpaceSize and eventSize are the two list lengths, and eventIsSubset is true only when every element of event is present in outcomes.

Errors#

  • When input is null, an array, or not an object — throws TypeError
  • When pA, pB, or pAB falls outside [0, 1], or pAB exceeds min(pA, pB) — throws RangeError

Complexity: time O(events * outcomes), space O(1).

Worked example#

verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

Input#

input
{
  "pA": 0.6,
  "pB": 0.5,
  "pAB": 0.3,
  "outcomes": ["up", "flat", "down"],
  "event": ["up", "flat"],
  "prior": 0.01,
  "sensitivity": 0.9,
  "falsePositiveRate": 0.05,
  "randomValues": [0, 1, 2],
  "probabilities": [0.2, 0.5, 0.3],
  "randomVariableKind": "discrete",
  "joint": [
    {
      "x": 0,
      "y": 0,
      "p": 0.3
    },
    {
      "x": 0,
      "y": 1,
      "p": 0.2
    },
    {
      "x": 1,
      "y": 0,
      "p": 0.1
    }
  ],
  "conditionY": 1
}

Call#

experimentsOutcomesSampleSpacesAndEvents(input)

Returns#

object with 2 fields: sampleSpaceSize, eventSize

{
  "sampleSpaceSize": 3,
  "eventSize": 2
}

Diagrams#

Experiments, Outcomes, Sample Spaces, and Events — article hero
Experiments, Outcomes, Sample Spaces, and Events — calculation ledger
Experiments, Outcomes, Sample Spaces, and Events — concept anatomy
Experiments, Outcomes, Sample Spaces, and Events — failure boundary
Experiments, Outcomes, Sample Spaces, and Events — method map
Experiments, Outcomes, Sample Spaces, and Events — scenario contrast

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

The rest of the Probability and Random Variables family#