inferencesynthesis

package
v0.4.0-release-RC Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

README

Inference Synthesis

This package contains the logic from the Inference Synthesis Section of the Allora litepaper, which combine current inferences, forecasts, previous losses and current regrets into current network losses and new latest regrets per worker or combination of workers (and topic).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccumulateWeights

func AccumulateWeights(
	inference *emissionstypes.Inference,
	weight alloraMath.Dec,
	allPeersAreNew bool,
	runningUnnormalizedI_i alloraMath.Dec,
	sumWeights alloraMath.Dec,
) (alloraMath.Dec, alloraMath.Dec, error)

func CalcNetworkLosses

func CalcNetworkLosses(
	stakesByReputer map[Worker]Stake,
	reputerReportedLosses emissions.ReputerValueBundles,
) (emissions.ValueBundle, error)

Assumes stakes are all positive

func CalcTopicInitialRegret added in v0.2.13

func CalcTopicInitialRegret(regrets []alloraMath.Dec, epsilon alloraMath.Dec, pNorm alloraMath.Dec, cNorm alloraMath.Dec) (alloraMath.Dec, error)

func CalcWeightFromNormalizedRegret

func CalcWeightFromNormalizedRegret(
	normalizedRegret alloraMath.Dec,
	maxNormalizedRegret alloraMath.Dec,
	pNorm alloraMath.Dec,
	cNorm alloraMath.Dec,
) (alloraMath.Dec, error)

func ComputeAndBuildEMRegret

func ComputeAndBuildEMRegret(
	lossA Loss,
	lossB Loss,
	previousRegret Regret,
	alpha alloraMath.Dec,
	blockHeight BlockHeight,
) (emissions.TimestampedValue, error)

func ConvertForecastImpliedInferencesToArrays added in v0.2.7

func ConvertForecastImpliedInferencesToArrays(
	workers []Worker,
	forecastImpliedInferenceByWorker map[string]*emissionstypes.Inference,
) []*emissionstypes.WorkerAttributedValue

It is assumed every key of `forecastImpliedInferenceByWorker` is contained within the `workers` slice

func ConvertValueBundleToNetworkLossesByWorker

func ConvertValueBundleToNetworkLossesByWorker(
	valueBundle emissions.ValueBundle,
) networkLossesByWorker

Convert a ValueBundle to a networkLossesByWorker

func ConvertWeightsToArrays added in v0.2.7

func ConvertWeightsToArrays(workers []Worker, weights map[Worker]Weight) []*emissionstypes.RegretInformedWeight

It is assumed every key of `weights` is contained within the `workers` slice

func CosmosIntOneE18

func CosmosIntOneE18() cosmosMath.Int

func GetCalcSetNetworkRegrets

func GetCalcSetNetworkRegrets(
	ctx sdk.Context,
	k keeper.Keeper,
	topicId TopicId,
	networkLosses emissions.ValueBundle,
	nonce emissions.Nonce,
	alpha alloraMath.Dec,
	cNorm alloraMath.Dec,
	pNorm alloraMath.Dec,
	epsilon alloraMath.Dec,
) error

Calculate the new network regrets by taking EMAs between the previous network regrets and the new regrets admitted by the inputted network losses It is assumed the workers are uniquely represented in the network losses

func GetNetworkInferences added in v0.4.0

func GetNetworkInferences(
	ctx sdk.Context,
	k keeper.Keeper,
	topicId TopicId,
	inferencesNonce *BlockHeight,
) (
	*emissions.ValueBundle,
	map[string]*emissions.Inference,
	map[string]alloraMath.Dec,
	map[string]alloraMath.Dec,
	int64,
	int64,
	error,
)

func Logger

func Logger(ctx sdk.Context) log.Logger

func MakeMapFromForecasterToTheirForecast

func MakeMapFromForecasterToTheirForecast(forecasts []*emissionstypes.Forecast) map[Worker]*emissionstypes.Forecast

Create a map from worker address to their inference or forecast-implied inference

func MakeMapFromInfererToTheirInference

func MakeMapFromInfererToTheirInference(inferences []*emissionstypes.Inference) map[Worker]*emissionstypes.Inference

Create a map from worker address to their inference or forecast-implied inference

Types

type BlockHeight

type BlockHeight = int64

type InferenceValue

type InferenceValue = alloraMath.Dec

type Loss

type Loss = alloraMath.Dec

type NetworkInferenceBuilder

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

func NewNetworkInferenceBuilderFromSynthRequest

func NewNetworkInferenceBuilderFromSynthRequest(
	req SynthRequest,
) (*NetworkInferenceBuilder, error)

func (*NetworkInferenceBuilder) Build

Calculates all network inferences in the set I_i given historical state (e.g. regrets) and data from workers (e.g. inferences, forecast-implied inferences). Could improve this with Builder pattern, as for other instances of generated ValueBundles.

func (*NetworkInferenceBuilder) CalcAndSetNetworkInferences

func (b *NetworkInferenceBuilder) CalcAndSetNetworkInferences() *NetworkInferenceBuilder

func (*NetworkInferenceBuilder) SetCombinedValue

func (b *NetworkInferenceBuilder) SetCombinedValue() *NetworkInferenceBuilder

Calculates the network combined inference I_i, Equation 9

func (*NetworkInferenceBuilder) SetForecasterValues

func (b *NetworkInferenceBuilder) SetForecasterValues() *NetworkInferenceBuilder

Map forecast-implied inferences to a WorkerAttributedValue array and set

func (*NetworkInferenceBuilder) SetInfererValues

func (b *NetworkInferenceBuilder) SetInfererValues() *NetworkInferenceBuilder

Map inferences to a WorkerAttributedValue array and set

func (*NetworkInferenceBuilder) SetNaiveValue

Calculates the network naive inference I^-_i

func (*NetworkInferenceBuilder) SetOneInValues

func (b *NetworkInferenceBuilder) SetOneInValues() *NetworkInferenceBuilder

Set all one-in inferences that are possible given the provided input Assumed that there is at most 1 inference per worker. Also assume that there is at most 1 forecast-implied inference per worker.

func (*NetworkInferenceBuilder) SetOneOutForecasterValues

func (b *NetworkInferenceBuilder) SetOneOutForecasterValues() *NetworkInferenceBuilder

Set all one-out-forecaster inferences that are possible given the provided input Assume that there is at most 1 forecast-implied inference per forecaster Loop over all forecast-implied inferences and withhold one, then calculate the network inference less that withheld value

func (*NetworkInferenceBuilder) SetOneOutInfererValues

func (b *NetworkInferenceBuilder) SetOneOutInfererValues() *NetworkInferenceBuilder

Set all one-out-inferer inferences that are possible given the provided input Assumed that there is at most 1 inference per inferer Loop over all inferences and withhold one, then calculate the network inference less that withheld inference This involves recalculating the forecast-implied inferences for each withheld inferer

type Regret

type Regret = alloraMath.Dec

type RegretInformedWeights

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

Need to differentiate between the two types of regrets because workers may complete tasks for both roles and may have different regrets for those different roles

type RunningWeightedLoss

type RunningWeightedLoss struct {
	UnnormalizedWeightedLoss Loss
	SumWeight                Weight
}

func RunningWeightedAvgUpdate

func RunningWeightedAvgUpdate(
	runningWeightedAvg *RunningWeightedLoss,
	nextWeight Weight,
	nextValue Weight,
) (RunningWeightedLoss, error)

Update the running information needed to calculate weighted loss per worker

type Stake

type Stake = cosmosMath.Int

type SynthPalette

type SynthPalette struct {
	Ctx               sdk.Context
	K                 keeper.Keeper
	Logger            log.Logger
	TopicId           TopicId
	AllInferersAreNew bool
	// Should use this as a source of truth regarding for which inferers to have data calculated
	// i.e. if an inferer is not present here, calculate a network inference without their data
	// Must be unique values
	Inferers          []Worker
	InferenceByWorker map[Worker]*emissions.Inference
	// Must respect the order of sister `inferers` property
	InfererRegrets map[Worker]*alloraMath.Dec
	// Should use this as a source of truth regarding for which forecasters to have data calculated
	// i.e. if an forecaster is not present here, calculate a network inference without their data
	// Must be unique values
	Forecasters                      []Worker
	ForecastByWorker                 map[Worker]*emissions.Forecast
	ForecastImpliedInferenceByWorker map[Worker]*emissions.Inference
	// Must respect the order of sister `forecasters` property
	ForecasterRegrets   map[Worker]*alloraMath.Dec
	NetworkCombinedLoss Loss
	EpsilonTopic        alloraMath.Dec
	EpsilonSafeDiv      alloraMath.Dec
	PNorm               alloraMath.Dec
	CNorm               alloraMath.Dec
}

func (*SynthPalette) BootstrapRegretData

func (p *SynthPalette) BootstrapRegretData() error

Bootstraps xRegrets, allxsAreNew (x="inferer"|"forecasters") for the inferers and forecasters in the palette Just requires these props:: ctx, k, topicId, inferers, forecasts

func (*SynthPalette) CalcForecastImpliedInferences

func (p *SynthPalette) CalcForecastImpliedInferences() (map[Worker]*emissionstypes.Inference, error)

Calculate the forecast-implied inferences I_ik given inferences, forecasts and network losses. Calculates R_ijk, w_ijk, and I_ik for each forecast k and forecast element (forcast of worker loss) j

Forecast without inference => weight in calculation of I_ik and I_i set to 0. Use latest available regret R_i-1,l Inference without forecast => only weight in calculation of I_ik set to 0 A value of 0 => no inference corresponded to any of the forecasts from a forecaster

Requires: forecasts, inferenceByWorker, allInferersAreNew, networkCombinedLoss, epsilon, pNorm, cNorm Updates: forecastImpliedInferenceByWorker

func (*SynthPalette) CalcWeightedInference

func (p *SynthPalette) CalcWeightedInference(weights RegretInformedWeights) (InferenceValue, error)

Calculates network combined inference I_i, network per worker regret R_i-1,l, and weights w_il from the litepaper: I_i = Σ_l w_il I_il / Σ_l w_il w_il = φ'_p(\hatR_i-1,l) \hatR_i-1,l = R_i-1,l / |max_{l'}(R_i-1,l')| given inferences, forecast-implied inferences, and network regrets

func (*SynthPalette) CalcWeightsGivenWorkers

func (p *SynthPalette) CalcWeightsGivenWorkers() (RegretInformedWeights, error)

Given the current set of inferers and forecasters in the palette, calculate their weights using the current regrets

func (SynthPalette) Clone

func (p SynthPalette) Clone() SynthPalette

Clone creates a deep copy of the SynthPalette.

func (*SynthPalette) GetForecasterRegretsSlice

func (p *SynthPalette) GetForecasterRegretsSlice() []alloraMath.Dec

func (*SynthPalette) GetInfererRegretsSlice

func (p *SynthPalette) GetInfererRegretsSlice() []alloraMath.Dec

func (*SynthPalette) UpdateForecastImpliedInferences

func (p *SynthPalette) UpdateForecastImpliedInferences() error

Calculate the forecast-implied inferences I_ik given inferences, forecasts and network losses. See docs of CalcForecastImpliedInferences for more details on calculation. This calculates and then sets the forecastImpliedInferenceByWorker property of the palette. Requires: forecasts, inferenceByWorker, allInferersAreNew, networkCombinedLoss, epsilon, pNorm, cNorm Updates: forecastImpliedInferenceByWorker

func (*SynthPalette) UpdateForecastersInfo added in v0.2.12

func (p *SynthPalette) UpdateForecastersInfo(newForecasters []Worker) error

UpdateForecasters updates the forecasters and their related fields in the SynthPalette.

func (*SynthPalette) UpdateInferersInfo added in v0.2.12

func (p *SynthPalette) UpdateInferersInfo(newInferers []Worker) error

type SynthPaletteFactory

type SynthPaletteFactory struct{}

func (*SynthPaletteFactory) BuildPaletteFromRequest

func (f *SynthPaletteFactory) BuildPaletteFromRequest(req SynthRequest) (SynthPalette, error)

Could use Builder pattern in the future to make this cleaner

type SynthRequest

type SynthRequest struct {
	Ctx                 sdk.Context
	K                   keeper.Keeper
	TopicId             TopicId
	Inferences          *emissions.Inferences
	Forecasts           *emissions.Forecasts
	NetworkCombinedLoss Loss
	EpsilonTopic        alloraMath.Dec
	EpsilonSafeDiv      alloraMath.Dec
	PNorm               alloraMath.Dec
	CNorm               alloraMath.Dec
}

type TopicId

type TopicId = uint64

type Weight

type Weight = alloraMath.Dec

type Worker

type Worker = string

Jump to

Keyboard shortcuts

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