pop

package
v0.0.0-...-705d94e Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcT2

func CalcT2(p *Pop, sampleSize int) []float64

func CalcT3

func CalcT3(p *Pop, sampleSize int) []float64

func CalcT4

func CalcT4(p *Pop, sampleSize int) []float64

func Evolve

func Evolve(eventChan chan *Event)

Evolve a population by the channel of events.

func FitnessMutateExponential

func FitnessMutateExponential(f *FitnessMutator) (delta float64)

FitnessMutateExponential return a exp value of delta.

func FitnessMutateStep

func FitnessMutateStep(f *FitnessMutator) (delta float64)

FitnessMutateStep return the delta fitness.

Types

type BeneficialMutator

type BeneficialMutator struct {
	S float64
	// contains filtered or unexported fields
}

BeneficialMutator is a selective mutator.

func NewBeneficialMutator

func NewBeneficialMutator(s float64, src rand.Source) *BeneficialMutator

NewBeneficialMutator returns a new BeneficialMutator.

func (*BeneficialMutator) Operate

func (m *BeneficialMutator) Operate(p *Pop)

Operate increase the fitness score by S.

type ByBirthTimeReverse

type ByBirthTimeReverse struct{ Lineages }

func (ByBirthTimeReverse) Less

func (s ByBirthTimeReverse) Less(i, j int) bool

type ByRate

type ByRate []*Event

func (ByRate) Len

func (b ByRate) Len() int

func (ByRate) Less

func (b ByRate) Less(i, j int) bool

func (ByRate) Swap

func (b ByRate) Swap(i, j int)

type ByteSequence

type ByteSequence []byte

type Config

type Config struct {
	// population parameters
	Size     int // population size
	Length   int // length of genome
	NumGen   int // number of generations.
	Alphabet string

	Mutation struct {
		Beneficial struct {
			Rate float64
			S    float64
		}
		Rate float64
	}

	Transfer struct {
		In struct {
			Rate     float64
			Fragment int
		}
		Out struct {
			Rate     float64
			Fragment int
		}
	}

	SampleMethod  string
	FragGenerator string
}

Population config

func (*Config) String

func (c *Config) String() string

type ConstantFrag

type ConstantFrag struct {
	Length int
}

func NewConstantFrag

func NewConstantFrag(length int) *ConstantFrag

func (*ConstantFrag) Size

func (c *ConstantFrag) Size() int

type DeltaMutateFunc

type DeltaMutateFunc func(f *FitnessMutator) (delta float64)

DeltaMutateFunc is a type of function that increase or decrease the fitness score by delta.

type Dilution

type Dilution struct {
	Factor float64
}

Dilution reduces the population by certain poportion.

func (Dilution) Reduce

func (d Dilution) Reduce(p *Pop) *Pop

Reduce reduces the population to certain poportion.

type Event

type Event struct {
	Ops  Operator
	Rate float64
	Pop  *Pop
}

func Emit

func Emit(events []*Event, rw *RouletteWheel) *Event

Emit randomly emits an event accourding to the event rate.

type ExpFrag

type ExpFrag struct {
	Lambda float64
	// contains filtered or unexported fields
}

func NewExpFrag

func NewExpFrag(lambda float64, src rand.Source) *ExpFrag

NewExpFrag return a new ExpFrag.

func (*ExpFrag) Size

func (e *ExpFrag) Size() int

type FitnessMutator

type FitnessMutator struct {
	Scale float64
	Shape float64
	// contains filtered or unexported fields
}

FitnessMutator is a mutator on fitness score.

func NewFitnessMutator

func NewFitnessMutator(scale, shape float64, src rand.Source, deltaFunc DeltaMutateFunc) *FitnessMutator

NewFitnessMutator returns a new fitness mutator.

func (*FitnessMutator) Operate

func (f *FitnessMutator) Operate(p *Pop)

Operate mutate the fitness score.

type FragSizeGenerator

type FragSizeGenerator interface {
	Size() int
}

FragSizeGenerator is a interface with a function return the size of fragment.

type Genome

type Genome interface {
	Seq() []byte
	Fitness() float64
	Length() int
	Copy() Genome
}

type Lineage

type Lineage struct {
	BirthTime int // when it was produced.
	Parent    *Lineage
}

type Lineages

type Lineages []*Lineage

func (Lineages) Len

func (s Lineages) Len() int

func (Lineages) Swap

func (s Lineages) Swap(i, j int)

type LinearSelectionSampler

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

func NewLinearSelectionSampler

func NewLinearSelectionSampler(src rand.Source) *LinearSelectionSampler

func (*LinearSelectionSampler) Operate

func (w *LinearSelectionSampler) Operate(p *Pop)

func (*LinearSelectionSampler) Start

func (l *LinearSelectionSampler) Start()

func (*LinearSelectionSampler) Time

func (l *LinearSelectionSampler) Time(p *Pop) float64

func (*LinearSelectionSampler) Wait

func (l *LinearSelectionSampler) Wait()

type MoranSampler

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

MoranSampler implements Moran reproduction model.

In each step of Moran process, two individuals are randomly chose: one to reproduce and the other to be replaced.

func NewMoranSampler

func NewMoranSampler(src rand.Source) *MoranSampler

func (*MoranSampler) Operate

func (m *MoranSampler) Operate(p *Pop)

func (*MoranSampler) Time

func (m *MoranSampler) Time(p *Pop) float64

type NeutralGenome

type NeutralGenome struct {
	Sequence ByteSequence
	// contains filtered or unexported fields
}

func (*NeutralGenome) Copy

func (g *NeutralGenome) Copy() Genome

func (*NeutralGenome) Fitness

func (g *NeutralGenome) Fitness() float64

func (*NeutralGenome) Length

func (g *NeutralGenome) Length() int

func (*NeutralGenome) Seq

func (g *NeutralGenome) Seq() []byte

type Operator

type Operator interface {
	Operate(*Pop)
}

Objects implementing the Operator interface can be used to do operations to a population.

type OutTransfer

type OutTransfer struct {
	SimpleTransfer
	DonorPop *Pop
}

OutTransfer implements transfers from a donor population to a receiver one.

We randomly choose a sequence from the donor population, and one from the reciever population.

func NewOutTransfer

func NewOutTransfer(frag FragSizeGenerator, donorPop *Pop, src rand.Source) *OutTransfer

NewOutTransfer return a new OutTransfer.

func (*OutTransfer) Operate

func (o *OutTransfer) Operate(p *Pop)

Operate perform a out population transfer.

type Pop

type Pop struct {
	// Genomes stores a array of sequences
	Genomes []Genome
	// Circled indicates whether the genome is circled or not.
	Circled       bool
	Lineages      []*Lineage
	NumGeneration int
	TargetSize    int
}

Pop is a population with a list of genomes.

func New

func New() *Pop

New returns a new Pop.

func Recover

func Recover(p *Pop, finalSize int) *Pop

Recover recovers the population exponentially.

func (*Pop) Length

func (p *Pop) Length() int

Length returns the length of a genome.

func (*Pop) MaxFit

func (p *Pop) MaxFit() float64

MaxFit returns the maximum of fitness.

func (*Pop) MeanFit

func (p *Pop) MeanFit() float64

MeanFit returns the mean of fitness.

func (*Pop) NewLineages

func (p *Pop) NewLineages()

NewLineages create new lineages.

func (*Pop) Size

func (p *Pop) Size() int

Size returns the number of genomes.

type Rand

type Rand interface {
	Intn(n int) int
	Float64() float64
}

type RandomPopGenerator

type RandomPopGenerator struct {
	// Rand is a source of random numbers
	Rand     Rand
	Alphabet []byte
	Size     int // size of population
	Length   int // length of genome
}

RandomPopGenerator randomly generates a population with a random neutral ancestral genome, given the size of the population and the length of the genome.

func NewRandomPopGenerator

func NewRandomPopGenerator(r Rand,
	size, length int,
	alphabet []byte) *RandomPopGenerator

NewRandomPopGenerator return a Pop.

func (*RandomPopGenerator) Operate

func (r *RandomPopGenerator) Operate(p *Pop)

Operate create genomes for a population.

type RouletteWheel

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

RouletteWheel is a random generator.

func NewRouletteWheel

func NewRouletteWheel(src rand.Source) *RouletteWheel

NewRouletteWheel return a new RouletteWheel.

func (*RouletteWheel) Select

func (r *RouletteWheel) Select(weights []float64) (index int)

Select return a select index.

type Sampler

type Sampler interface {
	Time(p *Pop) float64
	Operate(p *Pop)
	Wait()
	Start()
}

type Shock

type Shock interface {
	Reduce(p *Pop) *Pop
}

Shock is an interface for challenging population with shocks.

type SimpleMutator

type SimpleMutator struct {
	// Rand is a source of random numbers
	Alphabet []byte
	// contains filtered or unexported fields
}

SimpleMutator implements a simple mutation model, which assumes the same mutation rate on each site, and equal transition rates between bases.

func NewSimpleMutator

func NewSimpleMutator(alphabet []byte, src rand.Source) *SimpleMutator

NewSimpleMutator returns a new SimpleMutator.

func (*SimpleMutator) Operate

func (s *SimpleMutator) Operate(p *Pop)

Operate mutate a single position at a genome from the *Pop.

type SimplePopGenerator

type SimplePopGenerator struct {
	Ancestor Genome
	Size     int // size of population
}

SimplePopGenerator generate a population with the same ancestral sequence.

func NewSimplePopGenerator

func NewSimplePopGenerator(ancestor Genome, size int) *SimplePopGenerator

NewSimplePopGenerator return a new SimplePopGenerator.

func (*SimplePopGenerator) Operate

func (s *SimplePopGenerator) Operate(p *Pop)

Operate copy the ancestor to all genomes.

type SimpleTransfer

type SimpleTransfer struct {
	Frag FragSizeGenerator
	// contains filtered or unexported fields
}

SimpleTransfer implements a very simple transfer model. We randomly choose two sequences: one to be the donor, and the other to be the receiver. And a piece of the receiver's genome will be replaced by a sequence at corresponding genomic positions.

func NewSimpleTransfer

func NewSimpleTransfer(frag FragSizeGenerator, src rand.Source) *SimpleTransfer

func (*SimpleTransfer) Operate

func (s *SimpleTransfer) Operate(p *Pop)

type WrightFisherSampler

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

WrightFisherSampler for Wright-Fisher reproduction model.

func NewWrightFisherSampler

func NewWrightFisherSampler(src rand.Source) *WrightFisherSampler

NewWrightFisherSampler create a new WrightFisherSampler.

func (*WrightFisherSampler) Operate

func (w *WrightFisherSampler) Operate(p *Pop)

func (*WrightFisherSampler) Start

func (w *WrightFisherSampler) Start()

func (*WrightFisherSampler) Time

func (w *WrightFisherSampler) Time(p *Pop) float64

func (*WrightFisherSampler) Wait

func (w *WrightFisherSampler) Wait()

Jump to

Keyboard shortcuts

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