optimus

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2018 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDegenerateVector = errors.New("all elements in the vector the same")
)

Functions

func SortOrders

func SortOrders(orders []WeightedOrder)

Types

type Blacklist added in v0.4.4

type Blacklist interface {
	Update(ctx context.Context) error
	IsAllowed(addr common.Address) bool
}

type BruteForceModel added in v0.4.4

type BruteForceModel struct{}

type Clock

type Clock func() time.Time

Clock describes whatever that can return current time. Used primarily while testing.

type Config

type Config struct {
	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"`
	Optimization optimizationConfig
}

func LoadConfig

func LoadConfig(path string) (*Config, error)

func (*Config) Validate

func (m *Config) Validate() error

type Consumer

type Consumer interface {
	LowerBound() []float64
	DeviceType() sonm.DeviceType
	DeviceBenchmark(id int) (*sonm.Benchmark, bool)
	SplittingAlgorithm() sonm.SplittingAlgorithm
	Result(criteria float64) interface{}
}

type DeviceManager

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

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

type FittingFunc added in v0.4.4

type FittingFunc struct {
	Filters []func(order *sonm.Order) bool
}

func (*FittingFunc) Filter added in v0.4.4

func (m *FittingFunc) Filter(order *sonm.Order) bool

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(knapsack *Knapsack, orders []*MarketOrder) error

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

func (*Knapsack) Plans added in v0.4.4

func (m *Knapsack) Plans() []*sonm.AskPlan

func (*Knapsack) Price added in v0.4.4

func (m *Knapsack) Price() *sonm.Price

func (*Knapsack) Put added in v0.4.4

func (m *Knapsack) Put(order *sonm.Order) error

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)

type MarketOrder

type MarketOrder = sonm.DWHOrder

type MarketScanner added in v0.4.4

type MarketScanner interface {
	ActiveOrders(ctx context.Context) ([]*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 Normalizer

type Normalizer interface {
	Normalize(x float64) float64
	NormalizeBatch(x []float64)
	Denormalize(x float64) float64
	IsDegenerated() bool
}

type OptimizationMethod added in v0.4.4

type OptimizationMethod interface {
	Optimize(knapsack *Knapsack, orders []*MarketOrder) error
}

type Optimus

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

func NewOptimus

func NewOptimus(cfg Config, options ...Option) (*Optimus, error)

func (*Optimus) Run

func (m *Optimus) Run(ctx context.Context) error

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

func WithVersion(version string) Option

type OrderClassification

type OrderClassification struct {
	WeightedOrders []WeightedOrder
	Predictor      *OrderPredictor
	Sigmoid        sigmoid
	Clock          Clock
}

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 OrderPolicy

type OrderPolicy int
const (
	PolicySpotOnly OrderPolicy = iota
)

func (*OrderPolicy) UnmarshalYAML

func (m *OrderPolicy) UnmarshalYAML(unmarshal func(interface{}) error) error

type OrderPredictor

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

func (*OrderPredictor) PredictPrice

func (m *OrderPredictor) PredictPrice(order *MarketOrder) (float64, error)

type Registry

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

Registry keeps all used components in itself.

func (*Registry) Close

func (m *Registry) Close()

func (*Registry) NewDWH

func (m *Registry) NewDWH(ctx context.Context, addr auth.Addr, privateKey *ecdsa.PrivateKey) (sonm.DWHClient, error)

func (*Registry) NewWorkerManagement

func (m *Registry) NewWorkerManagement(ctx context.Context, addr auth.Addr, privateKey *ecdsa.PrivateKey) (sonm.WorkerManagementClient, error)

type Tagger added in v0.4.5

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

func (*Tagger) Tag added in v0.4.5

func (m *Tagger) Tag() []byte

type TrainedModel

type TrainedModel interface {
	Predict(vec []float64) (float64, error)
}

type Watcher

type Watcher interface {
	OnRun()
	OnShutdown()
	Execute(ctx context.Context)
}

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 WorkerManagementClientExt added in v0.4.4

type WorkerManagementClientExt interface {
	sonm.WorkerManagementClient
	RemoveAskPlans(ctx context.Context, ids []string) error
}

WorkerManagementClientExt extends default "WorkerManagementClient" with an ability to remove multiple ask-plans.

Jump to

Keyboard shortcuts

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