fpc

package
v0.7.7 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2021 License: Apache-2.0, BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrVoteAlreadyOngoing is returned if a vote is already going on for the given ID.
	ErrVoteAlreadyOngoing = errors.New("a vote is already ongoing for the given ID")
	// ErrNoOpinionGiversAvailable is returned if a round cannot be performed as no opinion gives are available.
	ErrNoOpinionGiversAvailable = errors.New("can't perform round as no opinion givers are available")
)

Functions

func ManaBasedSampling added in v0.5.5

func ManaBasedSampling(opinionGivers []opinion.OpinionGiver, maxQuerySampleSize, querySampleSize int, rng *rand.Rand) (map[opinion.OpinionGiver]int, float64)

ManaBasedSampling returns list of OpinionGivers to query, weighted by consensus mana and corresponding total mana value. If mana not available, fallback to uniform sampling weighted random sampling based on https://eli.thegreenplace.net/2010/01/22/weighted-random-generation-in-python/

func New

func New(opinionGiverFunc opinion.OpinionGiverFunc, ownWeightRetrieverFunc opinion.OwnWeightRetriever, paras ...*Parameters) vote.DRNGRoundBasedVoter

New creates a new FPC instance.

func RandUniformThreshold

func RandUniformThreshold(rand float64, thresholdLowerBound float64, thresholdUpperBound float64) float64

RandUniformThreshold returns random threshold between the given lower/upper bound values.

func UniformSampling added in v0.5.5

func UniformSampling(opinionGivers []opinion.OpinionGiver, maxQuerySampleSize, querySampleSize int, rng *rand.Rand) map[opinion.OpinionGiver]int

UniformSampling returns list of OpinionGivers to query, sampled uniformly

Types

type FPC

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

FPC is a DRNGRoundBasedVoter which uses the Opinion of other entities in order to finalize an Opinion.

func (*FPC) Events

func (f *FPC) Events() vote.Events

Events returns the events which happen on a vote.

func (*FPC) IntermediateOpinion

func (f *FPC) IntermediateOpinion(id string) (opinion.Opinion, error)

IntermediateOpinion returns the last formed opinion. If the vote is not found for the specified ID, it returns with error ErrVotingNotFound.

func (*FPC) Round

func (f *FPC) Round(random float64, delayedRoundStart ...time.Duration) error

Round enqueues new items, sets opinions on active vote contexts, finalizes them and then queries for opinions.

func (*FPC) SetOpinionGiverRng added in v0.5.5

func (f *FPC) SetOpinionGiverRng(rng *rand.Rand)

SetOpinionGiverRng sets random number generator in the FPC instance

func (*FPC) Vote

func (f *FPC) Vote(id string, objectType vote.ObjectType, initOpn opinion.Opinion) error

Vote sets an initial opinion on the vote context and enqueues the vote context.

type Parameters

type Parameters struct {
	// The lower bound liked percentage threshold at the first round. Also called 'a'.
	FirstRoundLowerBoundThreshold float64
	// The upper bound liked percentage threshold at the first round. Also called 'b'.
	FirstRoundUpperBoundThreshold float64
	// The lower bound liked percentage threshold used after the first round.
	SubsequentRoundsLowerBoundThreshold float64
	// The upper bound liked percentage threshold used after the first round.
	SubsequentRoundsUpperBoundThreshold float64
	// The fixed liked percentage threshold used in last 'l2' rounds.
	EndingRoundsFixedThreshold float64
	// The amount of opinions to query on each round for a given vote context. Also called 'k'.
	QuerySampleSize int
	// The maximum amount of votes to collect on each round for a given vote context. Naive implementation of 'k_diff' from the paper.
	MaxQuerySampleSize int
	// The amount of rounds a vote context's opinion needs to stay the same to be considered final. Also called 'l'.
	TotalRoundsFinalization int
	// The amount of last rounds for the fixed threshold.
	TotalRoundsFixedThreshold int
	// The amount of rounds for which to ignore any finalization checks for. Also called 'm'.
	TotalRoundsCoolingOffPeriod int
	// The max amount of rounds to execute per vote context before aborting them.
	MaxRoundsPerVoteContext int
	// The max amount of time a query is allowed to take.
	QueryTimeout time.Duration
	// MinOpinionsReceived defines the minimum amount of opinions to receive in order to consider an FPC round valid.
	MinOpinionsReceived int
}

Parameters define the parameters of an FPC instance.

func DefaultParameters

func DefaultParameters() *Parameters

DefaultParameters returns the default parameters used in FPC.

Jump to

Keyboard shortcuts

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