Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v0 source pure

Package dokimi holds the rules for a pre-registered experiment.

Overview

Package dokimi holds the rules for a pre-registered experiment.

A Plan states, before any data exists, what is being tested, which metric decides it, how big a change counts as a win and how many people each arm must reach. Judge then compares the recorded numbers with that plan and nothing else, so the bar cannot move after the results are in.

The package is pure: it keeps no state and moves no coins. Any realm can import it to judge its own experiments, or call the Dokimi registry realm to have them stored in public.

All rates and lifts are integers in basis points (1% = 100 bps), so every node computes exactly the same verdict.

Constants 3

const BpsScale, MaxCount, MaxTargetBps, MaxNameLen, MaxTextLen

 1const (
 2	// BpsScale is the number of basis points in 100%.
 3	BpsScale int64 = 10000
 4
 5	// MaxCount is the largest exposure count a Tally may hold. It keeps the
 6	// lift calculation inside int64: MaxCount * MaxCount * BpsScale < 2^63.
 7	MaxCount int64 = 10000000
 8
 9	// MaxTargetBps caps a target at a 1,000% relative change.
10	MaxTargetBps int64 = 100000
11
12	// Text limits keep stored plans small and readable.
13	MaxNameLen = 60
14	MaxTextLen = 400
15)
source

const Inconclusive, Met, Missed

1const (
2	// Inconclusive means the numbers cannot answer the question, usually
3	// because an arm stopped before the pre-registered minimum sample.
4	Inconclusive Outcome = "inconclusive"
5	// Met means the change reached the target in the expected direction.
6	Met Outcome = "met"
7	// Missed means the sample was large enough and the target was not reached.
8	Missed Outcome = "missed"
9)
source

Functions 6

func Commas

1func Commas(n int64) string
source

Commas renders a count with thousands separators: 1530 -> "1,530".

func FormatBps

1func FormatBps(bps int64) string
source

FormatBps renders basis points as a signed percentage with two decimals, for example 1220 -> "+12.20%" and -350 -> "-3.50%".

func FormatRate

1func FormatRate(bps int64) string
source

FormatRate renders a rate in basis points as an unsigned percentage, for example 1750 -> "17.50%".

func LiftBps

1func LiftBps(control, variant Tally) (lift int64, ok bool)
source

LiftBps returns the relative change of the variant's rate over the control's, in basis points, rounded toward zero. ok is false when the lift is undefined: an arm has no exposures or the control has no conversions.

It is computed from the raw counts, not from the rounded rates:

Example
1(vc/ve - cc/ce) / (cc/ce) = (vc*ce - cc*ve) / (cc*ve)

func ParsePercent

1func ParsePercent(s string) (int64, error)
source

ParsePercent turns a percentage typed by a person into basis points. It accepts "15", "15%", "12.5" and "0.25%", with at most two decimals. Negative values are refused: the plan's Direction carries the sign.

func Judge

1func Judge(p Plan, control, variant Tally) Verdict
source

Judge compares the recorded totals with the plan.

The order of the checks is the point of pre-registration: the sample size promised in advance is checked first, so a test stopped early can never be reported as a win, however good its numbers look.

Types 5

type Direction

ident
1type Direction string
source

Direction says which way the metric is expected to move.

type Outcome

ident
1type Outcome string
source

Outcome is the result of judging recorded numbers against a Plan.

type Plan

struct
 1type Plan struct {
 2	Title      string    // short name of the experiment
 3	Hypothesis string    // the claim being tested, in plain words
 4	Metric     string    // the single event or number that decides it
 5	Control    string    // name of the existing version
 6	Variant    string    // name of the new version
 7	Direction  Direction // which way the metric should move
 8	TargetBps  int64     // smallest relative change that counts, in bps
 9	MinSample  int64     // exposures each arm needs before a verdict counts
10}
source

Plan is what gets locked before a test starts.

Methods on Plan

func Digest

method on Plan
1func (p Plan) Digest() string
source

Digest returns the SHA-256 fingerprint of the plan as hex.

Every field is written with its length in front, so two different plans can never produce the same input. Anyone holding the plan text can recompute the digest and compare it with the one a registry stored.

func Validate

method on Plan
1func (p Plan) Validate() error
source

Validate reports the first problem with a plan, or nil.

type Tally

struct
1type Tally struct {
2	Exposures   int64 // people who saw this arm
3	Conversions int64 // of those, how many did the thing the metric counts
4}
source

Tally is the running total for one arm of an experiment.

Methods on Tally

func Covers

method on Tally
1func (t Tally) Covers(earlier Tally) bool
source

Covers reports whether t has at least as many exposures and conversions as earlier. A registry uses it to refuse a report that lowers a total.

func RateBps

method on Tally
1func (t Tally) RateBps() int64
source

RateBps returns conversions per exposure in basis points, rounded down. An arm with no exposures has a rate of 0.

func RateText

method on Tally
1func (t Tally) RateText() string
source

RateText renders the rate as a percentage for people to read: two decimals from 1% upwards and four below, so rare events stay visible. For example 268 of 1,530 is "17.51%" and 33 of 200,745 is "0.0164%".

func Validate

method on Tally
1func (t Tally) Validate() error
source

Validate reports the first problem with a tally, or nil.

type Verdict

struct
1type Verdict struct {
2	Outcome        Outcome
3	ControlRateBps int64
4	VariantRateBps int64
5	LiftBps        int64 // meaningful only when LiftDefined is true
6	LiftDefined    bool
7	Reason         string // one plain sentence explaining the outcome
8}
source

Verdict is the outcome of Judge with the numbers behind it.

Dependencies

Source Files 3