Documentation ¶
Index ¶
- Variables
- func ManaBasedSampling(opinionGivers []opinion.OpinionGiver, maxQuerySampleSize, querySampleSize int, ...) (map[opinion.OpinionGiver]int, float64)
- func RandUniformThreshold(rand float64, thresholdLowerBound float64, thresholdUpperBound float64) float64
- func UniformSampling(opinionGivers []opinion.OpinionGiver, maxQuerySampleSize, querySampleSize int, ...) map[opinion.OpinionGiver]int
- type FPC
- func (f *FPC) Events() vote.Events
- func (f *FPC) IntermediateOpinion(id string) (opinion.Opinion, error)
- func (f *FPC) Round(random float64, delayedRoundStart ...time.Duration) error
- func (f *FPC) SetOpinionGiverRng(rng *rand.Rand)
- func (f *FPC) Vote(id string, objectType vote.ObjectType, initOpn opinion.Opinion) error
- type Parameters
Constants ¶
This section is empty.
Variables ¶
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 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 New ¶
func New(opinionGiverFunc opinion.OpinionGiverFunc, ownWeightRetrieverFunc opinion.OwnWeightRetriever, paras ...*Parameters) *FPC
New creates a new FPC instance.
func (*FPC) IntermediateOpinion ¶
IntermediateOpinion returns the last formed opinion. If the vote is not found for the specified ID, it returns with error ErrVotingNotFound.
func (*FPC) Round ¶
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
SetOpinionGiverRng sets random number generator in the FPC instance
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.