cdflib

package module
v0.0.0-...-f6b646f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2022 License: LGPL-3.0 Imports: 7 Imported by: 1

README

Library for manipulating cumulative distribution functions.

NOTE: This code is undergoing a simultaneous re-write and re-think.

Some of the work going on at the moment:

  • Porting existing code from Go to Rust.
  • Eliminating custom stats code and replacing it with statrs.
  • Trying to decide whether it makes more sense to focus the project more on the "interpreted modeling language" aspect of the project, and less on coding primitives.

For now, the Jupyter integration will be broken until the Rust port is complete. Stay tuned!

Overview

This library was created to aid in statistical modeling. The goal was to create a set of tools that makes it possible to express iterative programs that manipulate random variables as easily as regular numbers.

Jupyter Notebooks

The library comes with an interpreter and a kernel that can be used with Jupyter notebooks.

Building the Kernel

To build the kernel, use the following commands:

go generate github.com/TonyRippy/cdflib/lang
go build -o cdflib-kernel github.com/TonyRippy/cdflib/kernel 

This will create a binary named kernel that you can copy to wherever you'd like to store it. If you're okay with storing the kernel in $GOPATH/bin, then you can use go install instead of go build.

Install the Kernel Specification

You need to use jupyter kernelspec install. There is an example kernelspec in the kernel directory. (I need to write up better directions for this.)

Run the Kernel

To run web-based notebooks, I use:

jupyter notebook --ip=${IP_ADDRESS} --no-browser

It is also possible to use a console-based interpreter:

jupyter console --kernel cdflib

If you're making changes to the kernel you may also want to add the --debug flag.

Example Notebooks

There are several example Jupyter notebooks in the notebooks directory.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrawCDF

func DrawCDF(cdf CDF, p float64, lineColor color.Color, fillColor color.Color, w int, h int) image.Image

Plots a CDF and returns it as an image.

The Y axis of the image will always be [0, 1] inclusive.

The X axis is specified by the p parameter. It specifies the probability range that should be plotted. For example, using p=0.05 the X axis of the image will include the values in the range [V(.05), V(.95)] inclusive.

The background is set to the transparent value.

func DrawCDFs

func DrawCDFs(cdfs []CDF, p float64, lineColors []color.Color, fillColors []color.Color, w int, h int) image.Image

Plots one or more CDFs on the same graph. See DrawCDF for details.

func DrawPDF

func DrawPDF(cdf CDF, p float64, lineColor color.Color, fillColor color.Color, w int, h int) image.Image

Plots a PDF and returns it as an image.

The X axis is specified by the p parameter. It specifies the probability range that should be plotted. For example, using p=0.05 the X axis of the image will include the values in the range [V(.05), V(.95)] inclusive.

The Y axis if the image will always be in the range (0, max), where max is the largest Y value of the PDF.

The background is set to the transparent value.

func DrawPDFs

func DrawPDFs(cdfs []CDF, p float64, lineColors []color.Color, fillColors []color.Color, w int, h int) image.Image

Plots one or more PDFs in the same image. See DrawPDF fr details.

func KSTest

func KSTest(cdf CDF, sample []float64) float64

Shorthand for KolmogorovSmirnovTest().

func KolmogorovSmirnovTest

func KolmogorovSmirnovTest(cdf CDF, sample []float64) float64

Runs a Kolmogorov-Smirnov test for a given sample and reference distribution.

The returned value is the calculated confidence level, an estimate of the likelihood that the given sample comes from the reference distribution.

See: https://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Smirnov_test

Types

type Condition

type Condition interface {
	/*
	  Returns the probability that the condition will be true.
	*/
	P() float64
}

An interface that represents a boolean-typed random variable. Think of it as something that can either happen or not happen with some probability.

func And

func And(conds ...Condition) Condition

Logical AND operation on independent events.

func Apply1b

func Apply1b(A CDF, f func(float64) bool, n int) (Condition, error)

Like Apply1, but the function f returns a boolean value.

func Apply2b

func Apply2b(A CDF, B CDF, f func(float64, float64) bool, n int) (Condition, error)

Like Apply2, but the function f returns a boolean value.

func Apply3b

func Apply3b(A CDF, B CDF, C CDF, f func(float64, float64, float64) bool, n int) (Condition, error)

Like Apply3, but the function f returns a boolean.

func False

func False() Condition

Returns a condition that never happens.

func Not

func Not(cond Condition) Condition

Logical negation of a condition.

func Or

func Or(conds ...Condition) Condition

Logical OR operation on independent events.

func P

func P(p float64) Condition

Creates a condition that happens with a known, fixed probability.

func True

func True() Condition

Returns a condition that always happens.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL