predictor

package
v0.0.0-...-ebe581b Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback interface {
	// SavePredictOut to persist prediction outcomes
	SavePredictOut(*pbCom.PredictTaskResult) error

	// StopTask to stop a prediction task
	// You'd better use it asynchronously to avoid deadlock
	StopTask(*pbCom.StopTaskRequest) error

	// Validate saves the prediction results to the Evaluator or LiveEvaluator,
	// then trigger the subsequent verification process.
	Validate(*pb.ValidateRequest) error
}

Callback contains some methods would be called when finish prediction such as to save the trained models and to stop a prediction task set into Predictor instance in initialization phase

type Model

type Model interface {
	// Advance does calculation with local parts of samples and communicates with other nodes in cluster to predict outcomes
	// payload could be resolved by Model trained out by specific algorithm and samples
	// We'd better call the method asynchronously avoid blocking the main go-routine
	Advance(payload []byte) (*pb.PredictResponse, error)
}

Model was trained out by a Learner, and participates in the multi-parts-calculation during prediction process If input different parts of a sample into Models on different mpc-nodes, you'll get final predicting result after some time of multi-parts-calculation

type PredictResponse

type PredictResponse struct {
	Resp *pb.PredictResponse
	Err  error
}

type Predictor

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

Predictor manages Models, such as to create or to delete a model dispatches requests to different Models by taskId, keeps the number of Models in the proper range in order to avoid high memory usage

func NewPredictor

func NewPredictor(address string, rh RpcHandler, cb Callback, modelLimit int) *Predictor

NewPredictor creates a Predictor instance, address indicates local mpc-node address modelLimit indicates the upper limit of the number of Models rh indicates the handler for rpc request sending cb indicates the callback methods called when finish prediction

func (*Predictor) DeleteModel

func (p *Predictor) DeleteModel(req *pbCom.StopTaskRequest) error

DeleteModel deletes a task from Memory Storage

func (*Predictor) NewModel

func (p *Predictor) NewModel(req *pbCom.StartTaskRequest) error

NewModel creates a Model instance related to TaskId and stores it into Memory Storage keeps the number of Models in the proper range in order to avoid high memory usage

func (*Predictor) Predict

func (p *Predictor) Predict(req *pb.PredictRequest, resC chan *PredictResponse)

Predict dispatches requests to different Models by taskId resC returns the result, and couldn't be set with nil

func (*Predictor) SaveResult

func (p *Predictor) SaveResult(result *pbCom.PredictTaskResult)

SaveResult saves the prediction results (failed status or successful status) of samples for a Model and stops related task. Analyze the TaskID to determine whether the prediction task is a common task from user or a task from Evaluator or LiveEvaluator. If the former, persist the prediction results locally, if the latter, call trainer.validate()

type RpcHandler

type RpcHandler interface {
	StepPredict(req *pb.PredictRequest, peerName string) (*pb.PredictResponse, error)

	// StepPredictWithRetry sends prediction message to remote mpc-node
	// retries 2 times at most
	// inteSec indicates the interval between retry requests, in seconds
	StepPredictWithRetry(req *pb.PredictRequest, peerName string, times int, inteSec int64) (*pb.PredictResponse, error)
}

RpcHandler performs remote procedure calls to remote cluster nodes.

Jump to

Keyboard shortcuts

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