inference_synthesis

package
v0.2.1-dev Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

Inference Synthesis

This package contains the logic from the Inference Synthesis Section of the 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 CalcForecastImpliedInferences

func CalcForecastImpliedInferences(
	inferenceByWorker map[Worker]*emissions.Inference,
	sortedWorkers []Worker,
	forecasts *emissions.Forecasts,
	networkCombinedLoss Loss,
	allInferersAreNew bool,
	epsilon alloraMath.Dec,
	pNorm alloraMath.Dec,
	cNorm alloraMath.Dec,
) (map[Worker]*emissions.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

func CalcNetworkInferences

func CalcNetworkInferences(
	ctx sdk.Context,
	k keeper.Keeper,
	topicId TopicId,
	inferences *emissions.Inferences,
	forecasts *emissions.Forecasts,
	networkCombinedLoss Loss,
	epsilon alloraMath.Dec,
	pNorm alloraMath.Dec,
	cNorm alloraMath.Dec,
) (*emissions.ValueBundle, error)

Calculates all network inferences in I_i given inferences, forecast implied inferences, and network combined inference. I_ij are the inferences of worker j and already given as an argument.

func CalcNetworkLosses

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

Assumes stakes are all positive

func CalcOneInInferences

func CalcOneInInferences(
	ctx sdk.Context,
	k keeper.Keeper,
	topicId TopicId,
	inferencesByWorker map[Worker]*emissions.Inference,
	sortedInferers []Worker,
	forecastImpliedInferences map[Worker]*emissions.Inference,
	sortedForecasters []Worker,
	allWorkersAreNew AllWorkersAreNew,
	maxRegretsByOneInForecaster map[Worker]Regret,
	epsilon alloraMath.Dec,
	pNorm alloraMath.Dec,
	cNorm alloraMath.Dec,
) ([]*emissions.WorkerAttributedValue, error)

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

func CalcOneOutInferences

func CalcOneOutInferences(
	ctx sdk.Context,
	k keeper.Keeper,
	topicId TopicId,
	inferenceByWorker map[Worker]*emissions.Inference,
	sortedInferers []Worker,
	forecastImpliedInferenceByWorker map[Worker]*emissions.Inference,
	sortedForecasters []Worker,
	forecasts *emissions.Forecasts,
	allWorkersAreNew AllWorkersAreNew,
	maxRegret Regret,
	networkCombinedLoss Loss,
	epsilon alloraMath.Dec,
	pNorm alloraMath.Dec,
	cNorm alloraMath.Dec,
) ([]*emissions.WithheldWorkerAttributedValue, []*emissions.WithheldWorkerAttributedValue, error)

Returns all one-out inferences that are possible given the provided input Assumed that there is at most 1 inference per worker. Also that there is at most 1 forecast-implied inference per worker. Loop over all inferences and forecast-implied inferences and withold one inference. Then calculate the network inference less that witheld inference If an inference is held out => recalculate the forecast-implied inferences before calculating the network inference

func ComputeAndBuildEMRegret

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

func ConvertValueBundleToNetworkLossesByWorker

func ConvertValueBundleToNetworkLossesByWorker(
	valueBundle emissions.ValueBundle,
) networkLossesByWorker

Convert a ValueBundle to a networkLossesByWorker

func CosmosIntOneE18

func CosmosIntOneE18() cosmosMath.Int

func FilterNoncesWithinEpochLength added in v0.2.6

func FilterNoncesWithinEpochLength(n emissions.Nonces, blockHeight, epochLength int64) emissions.Nonces

Filter nonces that are within the epoch length of the current block height

func GetCalcSetNetworkRegrets

func GetCalcSetNetworkRegrets(
	ctx sdk.Context,
	k keeper.Keeper,
	topicId TopicId,
	networkLosses emissions.ValueBundle,
	nonce emissions.Nonce,
	alpha 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 GetNetworkInferencesAtBlock added in v0.2.6

func GetNetworkInferencesAtBlock(
	ctx sdk.Context,
	k keeper.Keeper,
	topicId TopicId,
	inferencesNonce BlockHeight,
	previousLossNonce BlockHeight,
) (*emissions.ValueBundle, error)

func MakeMapFromWorkerToTheirWork

func MakeMapFromWorkerToTheirWork(inferences []*emissions.Inference) map[Worker]*emissions.Inference

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

func SelectTopNReputerNonces added in v0.2.6

func SelectTopNReputerNonces(reputerRequestNonces *emissions.ReputerRequestNonces, N int, currentBlockHeight int64, groundTruthLag int64) []*emissions.ReputerRequestNonce

Select the top N latest reputer nonces

func SelectTopNWorkerNonces added in v0.2.6

func SelectTopNWorkerNonces(workerNonces emissions.Nonces, N int) []*emissions.Nonce

Select the top N latest worker nonces

func SortByBlockHeight added in v0.2.6

func SortByBlockHeight(r []*emissions.ReputerRequestNonce)

Types

type AllWorkersAreNew

type AllWorkersAreNew struct {
	AllInferersAreNew    bool
	AllForecastersAreNew bool
}

func AreAllWorkersNew

func AreAllWorkersNew(
	ctx sdk.Context,
	k keeper.Keeper,
	topicId TopicId,
	sortedInferers []Worker,
	forecasts *emissions.Forecasts,
) (AllWorkersAreNew, error)

type BlockHeight

type BlockHeight = int64

type InferenceValue

type InferenceValue = alloraMath.Dec

func CalcWeightedInference

func CalcWeightedInference(
	ctx sdk.Context,
	k keeper.Keeper,
	topicId TopicId,
	inferenceByWorker map[Worker]*emissions.Inference,
	sortedInferers []Worker,
	forecastImpliedInferenceByWorker map[Worker]*emissions.Inference,
	sortedForecasters []Worker,
	allWorkersAreNew AllWorkersAreNew,
	maxRegret Regret,
	epsilon alloraMath.Dec,
	pNorm alloraMath.Dec,
	cNorm alloraMath.Dec,
) (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

type Loss

type Loss = alloraMath.Dec

func CalcCombinedNetworkLoss added in v0.2.6

func CalcCombinedNetworkLoss(
	stakesByReputer map[Worker]Stake,
	reputerReportedLosses *emissions.ReputerValueBundles,
	epsilon alloraMath.Dec,
) (Loss, error)

Same as CalcNetworkLosses() but just returns the combined loss

type Regret

type Regret = alloraMath.Dec

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 StdDevRegrets added in v0.2.6

type StdDevRegrets struct {
	StdDevInferenceRegret     Regret
	StdDevForecastRegret      Regret
	StdDevOneInForecastRegret map[Worker]Regret // max regret for each one-in forecaster
}

func CalcTheStdDevOfRegretsAmongWorkersWithLosses

func CalcTheStdDevOfRegretsAmongWorkersWithLosses(
	ctx sdk.Context,
	k keeper.Keeper,
	topicId TopicId,
	inferenceByWorker map[Worker]*emissions.Inference,
	sortedInferers []Worker,
	forecastImpliedInferenceByWorker map[Worker]*emissions.Inference,
	sortedForecasters []Worker,
	epsilon alloraMath.Dec,
) (StdDevRegrets, error)

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