galtonwatson

package module
v0.0.0-...-12cceb7 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: MIT Imports: 5 Imported by: 0

README

galtonwatson

[This module is under early development and should not be used by anyone at this time.]

galtonwatson is a Go module containing efficient algorithms for generating (conditioned) Galton-Watson trees and computing some of their properties. By implication, this module can be used to generate uniformly random samples from many classes of rooted trees, including:

  • uniformly random binary trees of a given size,
  • uniformly random d-ary trees of a given size,
  • uniformly random Cayley trees, i.e., unordered labeled trees of a given size,
  • uniformly random ordered trees of a given size,
  • etc.

Import

import "github.com/tommyreddad/galtonwatson"

Usage

import "github.com/tommyreddad/galtonwatson"

func main() {
    // Generates a uniformly random binary tree of size 100.
    T := galtonwatson.NewGaltonWatson(100, []float64{0.25, 0.5, 0.25}, nil)
    T.Rand()
}

References

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GaltonWatson

type GaltonWatson struct {
	// contains filtered or unexported fields
}

GaltonWatson implements a conditioned Galton-Watson tree generator. The conditioned Galton-Watson tree is specified by an offspring distribution and a node count.

func NewGaltonWatson

func NewGaltonWatson(n uint32, offspringProb []float64, src rand.Source) *GaltonWatson

NewGaltonWatson returns a GaltonWatson which represents a conditioned Galton-Watson tree of a given size `n`, whose offspring distribution is a given probability mass function `offspringProb`.

func NewGaltonWatsonFromRander

func NewGaltonWatsonFromRander(n uint32, rander distuv.Rander, src rand.Source) *GaltonWatson

NewGaltonWatsonFromRander returns a GaltonWatson which represents a conditioned Galton-Watson tree of a given size `n`, whose offspring distribution can be generated by the given `rander`.

func (*GaltonWatson) Rand

func (gw *GaltonWatson) Rand() *tree.Node

Rand returns a random sample drawn from the distribution. The generation algorithm is due to Devroye (2011), see: http://luc.devroye.org/gw-simulation.pdf.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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