Documentation ¶
Index ¶
- Variables
- func NewDecisionOrdersNewGenome(knapsack *Knapsack, orders []*MarketOrder) gago.NewGenome
- func NewPackedOrdersNewGenome(knapsack *Knapsack, orders []*MarketOrder) gago.NewGenome
- func SCAKKT(A [][]float64, b []float64, eps float64, maxIterations int) ([]float64, int, error)
- func SortOrders(orders []WeightedOrder)
- type AbsolutePriceThreshold
- type AxeModel
- type AxeModelConfig
- type AxeModelFactory
- type BatchModel
- type BatchModelConfig
- type BatchModelFactory
- type Blacklist
- type BranchBoundModel
- type BranchBoundModelConfig
- type BranchBoundModelFactory
- type Config
- type Consumer
- type DealRequestFactory
- type DecisionVec
- type Deleter
- type DeviceManager
- type FittingFunc
- type GeneticModel
- type GeneticModelConfig
- type GeneticModelFactory
- type GenomeConfig
- type GreedyLinearRegressionModel
- type GreedyLinearRegressionModelConfig
- type GreedyLinearRegressionModelFactory
- type Knapsack
- type MarketCache
- type MarketOrder
- type MarketScanner
- type Model
- type NewGenomeLab
- type Normalizer
- type OptimizationConfig
- type OptimizationMethod
- type OptimizationMethodFactory
- type Optimus
- type Option
- type OrderClassification
- type OrderClassifier
- type OrderPredictor
- type OrderRequestFactory
- type Orders
- type PredefinedMarketCache
- type PredictorConfig
- type PredictorService
- func (m *PredictorService) Classification() *OrderClassification
- func (m *PredictorService) Predict(ctx context.Context, request *sonm.BidResources) (*sonm.Price, error)
- func (m *PredictorService) PredictSupplier(ctx context.Context, request *sonm.PredictSupplierRequest) (*sonm.PredictSupplierReply, error)
- func (m *PredictorService) Serve(ctx context.Context) error
- type PriceThreshold
- type ReadOnlyWorker
- func (m *ReadOnlyWorker) AskPlans(ctx context.Context, in *sonm.Empty, opts ...grpc.CallOption) (*sonm.AskPlansReply, error)
- func (m *ReadOnlyWorker) CreateAskPlan(ctx context.Context, in *sonm.AskPlan, opts ...grpc.CallOption) (*sonm.ID, error)
- func (m *ReadOnlyWorker) PurgeAskPlans(ctx context.Context, in *sonm.Empty, opts ...grpc.CallOption) (*sonm.Empty, error)
- func (m *ReadOnlyWorker) PurgeBenchmarks(ctx context.Context, in *sonm.Empty, opts ...grpc.CallOption) (*sonm.Empty, error)
- func (m *ReadOnlyWorker) RemoveAskPlan(ctx context.Context, in *sonm.ID, opts ...grpc.CallOption) (*sonm.Empty, error)
- func (m *ReadOnlyWorker) RemoveBenchmark(ctx context.Context, in *sonm.NumericID, opts ...grpc.CallOption) (*sonm.Empty, error)
- func (m *ReadOnlyWorker) ScheduleMaintenance(ctx context.Context, in *sonm.Timestamp, opts ...grpc.CallOption) (*sonm.Empty, error)
- type Registry
- type RegressionModelFactory
- type RelativePriceThreshold
- type RestrictionsConfig
- type SCAKKTModel
- type Tagger
- type TrainedModel
- type TrainedSCAKKTModel
- type Watcher
- type WeightedOrder
- type WorkerManagementClientAPI
- type WorkerManagementClientExt
Constants ¶
This section is empty.
Variables ¶
var (
ErrDegenerateVector = errors.New("all elements in the vector the same")
)
Functions ¶
func NewDecisionOrdersNewGenome ¶ added in v0.4.6
func NewDecisionOrdersNewGenome(knapsack *Knapsack, orders []*MarketOrder) gago.NewGenome
func NewPackedOrdersNewGenome ¶ added in v0.4.6
func NewPackedOrdersNewGenome(knapsack *Knapsack, orders []*MarketOrder) gago.NewGenome
func SCAKKT ¶ added in v0.4.6
SCAKKT solves the non-negative least squares problem.
Argument "A" represents input matrix. Each element of "A" must have the same length. Vector "b" represents a measurement or output vector. "Eps" is a tolerance for stopping iteration.
The result tuple consists of three parameters. The first one returns coefficients of the fitted linear function. It will have the same length as elements of "A". The second value is the number of iterations performed. An error is returned if "A" and "b" are not the same length.
func SortOrders ¶
func SortOrders(orders []WeightedOrder)
Types ¶
type AbsolutePriceThreshold ¶ added in v0.4.10
type AbsolutePriceThreshold struct {
*sonm.Price
}
func NewAbsolutePriceThreshold ¶ added in v0.4.10
func NewAbsolutePriceThreshold(threshold *sonm.Price) (*AbsolutePriceThreshold, error)
func ParseAbsolutePriceThreshold ¶ added in v0.4.10
func ParseAbsolutePriceThreshold(threshold string) (*AbsolutePriceThreshold, error)
type AxeModel ¶ added in v0.4.13
type AxeModel struct { Log *zap.SugaredLogger // contains filtered or unexported fields }
type AxeModelConfig ¶ added in v0.4.13
type AxeModelConfig struct{}
type AxeModelFactory ¶ added in v0.4.13
type AxeModelFactory struct {
AxeModelConfig
}
func (*AxeModelFactory) Config ¶ added in v0.4.13
func (a *AxeModelFactory) Config() interface{}
func (*AxeModelFactory) Create ¶ added in v0.4.13
func (a *AxeModelFactory) Create(orders, matchedOrders []*MarketOrder, log *zap.SugaredLogger) OptimizationMethod
type BatchModel ¶ added in v0.4.6
type BatchModel struct { Methods []OptimizationMethod Log *zap.SugaredLogger }
func (*BatchModel) Optimize ¶ added in v0.4.6
func (m *BatchModel) Optimize(ctx context.Context, knapsack *Knapsack, orders []*MarketOrder) error
type BatchModelConfig ¶ added in v0.4.6
type BatchModelConfig struct { Brute bruteConfig `yaml:"brute"` Methods []optimizationMethodFactory `yaml:"models"` }
type BatchModelFactory ¶ added in v0.4.6
type BatchModelFactory struct {
BatchModelConfig
}
func (*BatchModelFactory) Config ¶ added in v0.4.6
func (m *BatchModelFactory) Config() interface{}
func (*BatchModelFactory) Create ¶ added in v0.4.6
func (m *BatchModelFactory) Create(orders, matchedOrders []*MarketOrder, log *zap.SugaredLogger) OptimizationMethod
type BranchBoundModel ¶ added in v0.4.6
type BranchBoundModel struct {
Log *zap.SugaredLogger
}
func (*BranchBoundModel) Optimize ¶ added in v0.4.6
func (m *BranchBoundModel) Optimize(ctx context.Context, knapsack *Knapsack, orders []*MarketOrder) error
type BranchBoundModelConfig ¶ added in v0.4.6
type BranchBoundModelConfig struct {
HeightLimit int `yaml:"height_limit" default:"6"`
}
type BranchBoundModelFactory ¶ added in v0.4.6
type BranchBoundModelFactory struct {
BranchBoundModelConfig
}
func (*BranchBoundModelFactory) Config ¶ added in v0.4.6
func (m *BranchBoundModelFactory) Config() interface{}
func (*BranchBoundModelFactory) Create ¶ added in v0.4.6
func (*BranchBoundModelFactory) Create(orders, matchedOrders []*MarketOrder, log *zap.SugaredLogger) OptimizationMethod
type Config ¶
type Config struct { Restrictions *RestrictionsConfig `yaml:"restrictions"` Blockchain *blockchain.Config `yaml:"blockchain"` PrivateKey privateKey `yaml:"ethereum" json:"-"` Logging logging.Config `yaml:"logging"` Node nodeConfig `yaml:"node"` Workers map[auth.Addr]*workerConfig `yaml:"workers"` Benchmarks benchmarks.Config `yaml:"benchmarks"` Marketplace marketplaceConfig `yaml:"marketplace"` Debug *debug.Config `yaml:"debug"` }
func LoadConfig ¶
type DealRequestFactory ¶ added in v0.4.13
type DealRequestFactory func() *sonm.DealsRequest
func DefaultDealRequestFactory ¶ added in v0.4.13
func DefaultDealRequestFactory(cfg marketplaceConfig) DealRequestFactory
type DecisionVec ¶ added in v0.4.6
type DecisionVec []float64
func (DecisionVec) Clone ¶ added in v0.4.6
func (m DecisionVec) Clone() DecisionVec
type Deleter ¶ added in v0.4.11
type Deleter interface {
Delete() error
}
func RestrictUsage ¶ added in v0.4.11
func RestrictUsage(cfg *RestrictionsConfig) (Deleter, error)
type DeviceManager ¶
type DeviceManager struct {
// contains filtered or unexported fields
}
func (*DeviceManager) Clone ¶ added in v0.4.6
func (m *DeviceManager) Clone() *DeviceManager
func (*DeviceManager) Consume ¶
func (m *DeviceManager) Consume(benchmarks sonm.Benchmarks, netflags sonm.NetFlags) (*sonm.AskPlanResources, error)
func (*DeviceManager) Contains ¶ added in v0.4.4
func (m *DeviceManager) Contains(benchmarks sonm.Benchmarks, netflags sonm.NetFlags) bool
func (*DeviceManager) GPUCount ¶ added in v0.4.26
func (m *DeviceManager) GPUCount() int
type FittingFunc ¶ added in v0.4.4
type FittingFunc struct {
Filters []func(order *sonm.Order) error
}
func (*FittingFunc) Filter ¶ added in v0.4.4
func (m *FittingFunc) Filter(order *sonm.Order) error
type GeneticModel ¶ added in v0.4.6
type GeneticModel struct { NewGenomeLab NewGenomeLab // PopulationSize specifies the number of individuals per Population. PopulationSize int // MaxGenerations specifies the number of population generations. MaxGenerations int // MaxAge specifies the maximum age of the entire evolution process. MaxAge time.Duration // Log is used for internal logging. Log *zap.SugaredLogger }
func (*GeneticModel) Optimize ¶ added in v0.4.6
func (m *GeneticModel) Optimize(ctx context.Context, knapsack *Knapsack, orders []*MarketOrder) error
func (*GeneticModel) ShouldEvolve ¶ added in v0.4.6
func (m *GeneticModel) ShouldEvolve(ga gago.GA) bool
type GeneticModelConfig ¶ added in v0.4.6
type GeneticModelConfig struct { Genome GenomeConfig `yaml:"genome"` PopulationSize int `yaml:"population_size" default:"256"` MaxGenerations int `yaml:"max_generations" default:"128"` MaxAge time.Duration `yaml:"max_age" default:"5m"` }
type GeneticModelFactory ¶ added in v0.4.6
type GeneticModelFactory struct {
GeneticModelConfig
}
func (*GeneticModelFactory) Config ¶ added in v0.4.6
func (m *GeneticModelFactory) Config() interface{}
func (*GeneticModelFactory) Create ¶ added in v0.4.6
func (m *GeneticModelFactory) Create(orders, matchedOrders []*MarketOrder, log *zap.SugaredLogger) OptimizationMethod
type GenomeConfig ¶ added in v0.4.6
type GenomeConfig struct { NewGenomeLab `json:"-"` Type string }
func (*GenomeConfig) MarshalText ¶ added in v0.4.6
func (m *GenomeConfig) MarshalText() (text []byte, err error)
func (*GenomeConfig) UnmarshalYAML ¶ added in v0.4.6
func (m *GenomeConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
type GreedyLinearRegressionModel ¶ added in v0.4.4
type GreedyLinearRegressionModel struct {
// contains filtered or unexported fields
}
GreedyLinearRegressionModel implements greedy knapsack optimization algorithm. The basic idea is to train the model using BID orders from the marketplace by optimizing multidimensional linear regression over order benchmarks to reduce the number of parameters to a single one - predicted price. This price can be used to assign weights to orders to be able to determine which orders are better to buy than others.
func (*GreedyLinearRegressionModel) Optimize ¶ added in v0.4.4
func (m *GreedyLinearRegressionModel) Optimize(ctx context.Context, knapsack *Knapsack, orders []*MarketOrder) error
type GreedyLinearRegressionModelConfig ¶ added in v0.4.6
type GreedyLinearRegressionModelFactory ¶ added in v0.4.6
type GreedyLinearRegressionModelFactory struct {
GreedyLinearRegressionModelConfig
}
func (*GreedyLinearRegressionModelFactory) Config ¶ added in v0.4.6
func (m *GreedyLinearRegressionModelFactory) Config() interface{}
func (*GreedyLinearRegressionModelFactory) Create ¶ added in v0.4.6
func (m *GreedyLinearRegressionModelFactory) Create(orders, matchedOrders []*MarketOrder, log *zap.SugaredLogger) OptimizationMethod
type Knapsack ¶ added in v0.4.4
type Knapsack struct {
// contains filtered or unexported fields
}
func NewKnapsack ¶ added in v0.4.4
func NewKnapsack(deviceManager *DeviceManager) *Knapsack
type MarketCache ¶ added in v0.4.4
type MarketCache struct {
// contains filtered or unexported fields
}
MarketCache is a communication bus between fetching market orders and its consumers. Required, because there are multiple workers can be targeted by Optimus.
func (*MarketCache) ActiveOrders ¶ added in v0.4.4
func (m *MarketCache) ActiveOrders(ctx context.Context) ([]*MarketOrder, error)
func (*MarketCache) ExecutedOrders ¶ added in v0.4.12
func (m *MarketCache) ExecutedOrders(ctx context.Context, orderType sonm.OrderType) ([]*MarketOrder, error)
type MarketOrder ¶
type MarketOrder = sonm.DWHOrder
type MarketScanner ¶ added in v0.4.4
type MarketScanner interface { ActiveOrders(ctx context.Context) ([]*MarketOrder, error) ExecutedOrders(ctx context.Context, orderType sonm.OrderType) ([]*MarketOrder, error) }
type Model ¶
type Model interface { // Train runs the training process, returning the trained model on success. // The "trainingSet" argument is a MxN matrix, while "expectation" must be // a M-length vector. Train(trainingSet [][]float64, expectation []float64) (TrainedModel, error) }
Model represents a ML model that can be trained using provided training set with some expectation.
type NewGenomeLab ¶ added in v0.4.6
type NewGenomeLab func(knapsack *Knapsack, orders []*MarketOrder) gago.NewGenome
type Normalizer ¶
type OptimizationConfig ¶ added in v0.4.6
type OptimizationConfig struct {
Model optimizationMethodFactory `yaml:"model"`
}
type OptimizationMethod ¶ added in v0.4.4
type OptimizationMethod interface {
Optimize(ctx context.Context, knapsack *Knapsack, orders []*MarketOrder) error
}
type OptimizationMethodFactory ¶ added in v0.4.6
type OptimizationMethodFactory interface { Config() interface{} Create(orders, matchedOrders []*MarketOrder, log *zap.SugaredLogger) OptimizationMethod }
type Option ¶ added in v0.4.5
type Option func(o *options)
func WithLog ¶ added in v0.4.5
func WithLog(log *zap.SugaredLogger) Option
func WithVersion ¶ added in v0.4.5
type OrderClassification ¶
type OrderClassification struct { WeightedOrders []WeightedOrder Predictor *OrderPredictor }
OrderClassification is a struct that is returned after market orders classification. Contains weighted orders for some epoch and is able to predict some order's market price.
func (*OrderClassification) RecalculateWeightsAndSort ¶
func (m *OrderClassification) RecalculateWeightsAndSort(orders []WeightedOrder)
type OrderClassifier ¶
type OrderClassifier interface {
Classify(orders []*MarketOrder) ([]WeightedOrder, error)
}
TODO: Docs.
type OrderPredictor ¶
type OrderPredictor struct {
// contains filtered or unexported fields
}
func (*OrderPredictor) PredictPrice ¶
func (m *OrderPredictor) PredictPrice(order *MarketOrder) (float64, error)
type OrderRequestFactory ¶ added in v0.4.12
type OrderRequestFactory func() *sonm.OrdersRequest
func DefaultOrderRequestFactory ¶ added in v0.4.12
func DefaultOrderRequestFactory(cfg marketplaceConfig) OrderRequestFactory
type Orders ¶ added in v0.4.6
type Orders []*MarketOrder
Orders is a slice of market orders.
Introduced to simplify cloning operation.
type PredefinedMarketCache ¶ added in v0.4.9
type PredefinedMarketCache struct {
Orders []*MarketOrder
}
func NewPredefinedMarketCache ¶ added in v0.4.9
func NewPredefinedMarketCache(orders []*sonm.BigInt, market blockchain.MarketAPI) (*PredefinedMarketCache, error)
func (*PredefinedMarketCache) ActiveOrders ¶ added in v0.4.9
func (m *PredefinedMarketCache) ActiveOrders(ctx context.Context) ([]*MarketOrder, error)
func (*PredefinedMarketCache) ExecutedOrders ¶ added in v0.4.12
func (m *PredefinedMarketCache) ExecutedOrders(ctx context.Context, orderType sonm.OrderType) ([]*MarketOrder, error)
type PredictorConfig ¶ added in v0.4.10
type PredictorConfig struct { Blockchain *blockchain.Config DWH *dwh.DWHConfig Marketplace marketplaceConfig BruteThreshold uint `yaml:"brute_threshold" default:"6"` }
type PredictorService ¶ added in v0.4.10
type PredictorService struct {
// contains filtered or unexported fields
}
func NewPredictorService ¶ added in v0.4.10
func NewPredictorService(cfg *PredictorConfig, eth blockchain.API, benchmarkList benchmarks.BenchList, dwh sonm.DWHClient, log *zap.SugaredLogger) *PredictorService
NewPredictorService constructs a new order price predictor service. Returns nil when nil "cfg" is passed.
func (*PredictorService) Classification ¶ added in v0.4.10
func (m *PredictorService) Classification() *OrderClassification
func (*PredictorService) Predict ¶ added in v0.4.10
func (m *PredictorService) Predict(ctx context.Context, request *sonm.BidResources) (*sonm.Price, error)
func (*PredictorService) PredictSupplier ¶ added in v0.4.13
func (m *PredictorService) PredictSupplier(ctx context.Context, request *sonm.PredictSupplierRequest) (*sonm.PredictSupplierReply, error)
type PriceThreshold ¶ added in v0.4.10
type ReadOnlyWorker ¶ added in v0.4.9
type ReadOnlyWorker struct { WorkerManagementClientAPI // contains filtered or unexported fields }
ReadOnlyWorker is a worker management client wrapper that allows only immutable operations. It returns some default response for operations that mutates something.
func NewReadOnlyWorker ¶ added in v0.4.9
func NewReadOnlyWorker(worker WorkerManagementClientAPI) *ReadOnlyWorker
func (*ReadOnlyWorker) AskPlans ¶ added in v0.4.9
func (m *ReadOnlyWorker) AskPlans(ctx context.Context, in *sonm.Empty, opts ...grpc.CallOption) (*sonm.AskPlansReply, error)
func (*ReadOnlyWorker) CreateAskPlan ¶ added in v0.4.9
func (m *ReadOnlyWorker) CreateAskPlan(ctx context.Context, in *sonm.AskPlan, opts ...grpc.CallOption) (*sonm.ID, error)
func (*ReadOnlyWorker) PurgeAskPlans ¶ added in v0.4.9
func (m *ReadOnlyWorker) PurgeAskPlans(ctx context.Context, in *sonm.Empty, opts ...grpc.CallOption) (*sonm.Empty, error)
func (*ReadOnlyWorker) PurgeBenchmarks ¶ added in v0.4.9
func (m *ReadOnlyWorker) PurgeBenchmarks(ctx context.Context, in *sonm.Empty, opts ...grpc.CallOption) (*sonm.Empty, error)
func (*ReadOnlyWorker) RemoveAskPlan ¶ added in v0.4.9
func (m *ReadOnlyWorker) RemoveAskPlan(ctx context.Context, in *sonm.ID, opts ...grpc.CallOption) (*sonm.Empty, error)
func (*ReadOnlyWorker) RemoveBenchmark ¶ added in v0.4.9
func (m *ReadOnlyWorker) RemoveBenchmark(ctx context.Context, in *sonm.NumericID, opts ...grpc.CallOption) (*sonm.Empty, error)
func (*ReadOnlyWorker) ScheduleMaintenance ¶ added in v0.4.9
func (m *ReadOnlyWorker) ScheduleMaintenance(ctx context.Context, in *sonm.Timestamp, opts ...grpc.CallOption) (*sonm.Empty, error)
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry keeps all used components in itself.
func (*Registry) NewWorkerManagement ¶
type RegressionModelFactory ¶ added in v0.4.6
type RegressionModelFactory interface { Config() interface{} Create(log *zap.SugaredLogger) Model }
type RelativePriceThreshold ¶ added in v0.4.10
func NewRelativePriceThreshold ¶ added in v0.4.10
func NewRelativePriceThreshold(threshold float64) (*RelativePriceThreshold, error)
func ParseRelativePriceThreshold ¶ added in v0.4.10
func ParseRelativePriceThreshold(threshold string) (*RelativePriceThreshold, error)
type RestrictionsConfig ¶ added in v0.4.11
type SCAKKTModel ¶ added in v0.4.6
type SCAKKTModel struct { MaxIterations int Log *zap.SugaredLogger }
func (*SCAKKTModel) Config ¶ added in v0.4.6
func (m *SCAKKTModel) Config() interface{}
func (*SCAKKTModel) Create ¶ added in v0.4.6
func (m *SCAKKTModel) Create(log *zap.SugaredLogger) Model
func (*SCAKKTModel) Train ¶ added in v0.4.6
func (m *SCAKKTModel) Train(trainingSet [][]float64, expectation []float64) (TrainedModel, error)
type TrainedModel ¶
type TrainedSCAKKTModel ¶ added in v0.4.6
type TrainedSCAKKTModel struct {
// contains filtered or unexported fields
}
func (*TrainedSCAKKTModel) Predict ¶ added in v0.4.6
func (m *TrainedSCAKKTModel) Predict(x []float64) (float64, error)
func (*TrainedSCAKKTModel) String ¶ added in v0.4.6
func (m *TrainedSCAKKTModel) String() string
type WeightedOrder ¶
type WeightedOrder struct { // Order is an initial market order. Order *MarketOrder // Price is an order price in USD/s. Price float64 // PredictedPrice is a order price in USD/s, that is calculated during // scanning and analysing the market. PredictedPrice float64 // Weight represents some specific order weight. // // It fits in [0; +Inf] range and is used to reduce an order attractiveness // if it has been laying on the market for a long time without being sold. Weight float64 }
func (*WeightedOrder) ID ¶
func (m *WeightedOrder) ID() *big.Int
type WorkerManagementClientAPI ¶ added in v0.4.13
type WorkerManagementClientAPI interface { Devices(ctx context.Context, request *sonm.Empty, opts ...grpc.CallOption) (*sonm.DevicesReply, error) AskPlans(ctx context.Context, request *sonm.Empty, opts ...grpc.CallOption) (*sonm.AskPlansReply, error) CreateAskPlan(ctx context.Context, request *sonm.AskPlan, opts ...grpc.CallOption) (*sonm.ID, error) RemoveAskPlan(ctx context.Context, request *sonm.ID, opts ...grpc.CallOption) (*sonm.Empty, error) NextMaintenance(ctx context.Context, request *sonm.Empty, opts ...grpc.CallOption) (*sonm.Timestamp, error) }
type WorkerManagementClientExt ¶ added in v0.4.4
type WorkerManagementClientExt interface { WorkerManagementClientAPI RemoveAskPlans(ctx context.Context, ids []string) error }
WorkerManagementClientExt extends default "WorkerManagementClient" with an ability to remove multiple ask-plans.
Source Files ¶
- blacklist.go
- cgroup.go
- cgroup_linux.go
- config.go
- context.go
- devices.go
- engine.go
- engine_axe.go
- engine_branch.go
- engine_genetic.go
- engine_greedy.go
- engine_multi.go
- knapsack.go
- learning.go
- market.go
- market_cache.go
- matrix.go
- model.go
- model_lls.go
- model_nnls.go
- normalize.go
- optimus.go
- options.go
- plan_policy.go
- predictor.go
- predictor_service.go
- price.go
- registry.go
- tagging.go
- watcher.go
- worker.go