diff --git a/ai/framework.go b/ai/framework.go index dae1f34..91fe029 100644 --- a/ai/framework.go +++ b/ai/framework.go @@ -8,18 +8,27 @@ package ai SHOULD PROVIDE ABSTRACTION FOR ELASTICFEED ENGINE AND SERVER-PLUGIN LOGIC. - Support for ANN: new, train, predict, grow, optimise - - Support for GA: new, simulate - - - Recognition: Photo, Songs, Video - - Transformations: FFT, ... - - - Filtering - - Sorting - - Aggregation - - - Compressing - - Export/Import - - Transcoding + - unidirectional + - bidirectional / RNN (recurrent) + - ******************************** + - Continuous-time Recurrent Neural Network CTRNN + - Multiple Timescales Recurrent Neural Network MTRNN + - ******************************** + - steps: network architecture, learning rule, activation updating function + + - Support for Genethic Algorithms: new, simulate + + - Requirements: + - Recognition: Photo, Songs, Video + - Transformations: FFT, ... + - ******************************** + - Filtering + - Sorting + - Aggregation + - ******************************** + - Compressing + - Export/Import + - Transcoding */ func init() {} diff --git a/population/hvs.go b/population/hvs.go new file mode 100644 index 0000000..3fd88ec --- /dev/null +++ b/population/hvs.go @@ -0,0 +1,46 @@ +package population + +import ( + "github.com/feedlabs/elasticfeed/population/vhs" +) + +/* + + ******************************* + * Virtual Human Surrogate * + ******************************* + + + - SHOULD DEFINE PRIVATE VIRTUAL PERSONALITY + - SHOULD DEFINE INPUT LANGUAGE AND CHANNEL + - SHOULD DEFINE OUTPUT LANGUAGE AND CHANNEL + - SHOULD DEFINE MOBILITY FEATURES + - ... + +*/ + +type VHSController struct { + pvp *PVPController + + communicator vhs.Communicator +} + +func (this *VHSController) Query(query interface {}) interface {} { + return this.communicator.Query(this.pvp, query) +} + +func (this *VHSController) Train(train interface {}) interface {} { + return this.communicator.Query(this.pvp, train) +} + +func (this *VHSController) GetPVP() *PVPController { + return this.pvp +} + +func (this *VHSController) GetCommunicator() vhs.Communicator { + return this.communicator +} + +func NewVirtualHumanSurrogate(communicator vhs.Communicator) *VHSController { + return &VHSController{nil, communicator} +} diff --git a/population/pvp.go b/population/pvp.go index d4ba3ae..203a8d2 100644 --- a/population/pvp.go +++ b/population/pvp.go @@ -1,17 +1,11 @@ package population /* + *********************************** * Private Virtual Personality * *********************************** - https://en.wikipedia.org/wiki/Talk%3APrivate_virtual_personality - - VI vs AI - - A VI is restricted to certain responses and actions, and can't become self-aware, - while an AI is free to think how it likes and is self-aware. - */ type PVPController struct { @@ -34,27 +28,56 @@ type PVPController struct { } -func (this *PVPController) Train() { +func (this *PVPController) Train(train interface{}) interface{} { /* PVP LEARNS VIA HUMAN TEACHING - CARROT/STICK METHOD - - MOOD DETECTION - ... + + TRAIN PACKAGE: + - HUMAN ENVIRONMENT SENSORS STATUS + - SUBJECT KNOWLEDGE + - HUMAN DECISION + - LIFETIME ACTIVITY&KNOWLEDGE */ + + return map[string]interface{}{ + "train": "success", + } } -func (this *PVPController) Query() { +func (this *PVPController) Query(query interface{}) interface{} { /* QUESTION WITH LOGIC ANSWER: YES/NO - QUESTION WITH PROBABILITY ANSWER: MAYBE YES, MAYBE NOT + QUESTION WITH PROBABILITY ANSWER: MOST LIKELY, MAYBE, PROBABLY YES/NO QUESTION ABOUT LIKENESS OF SUBJECT: LIKE/DISLIKE - QUESTION ABOUT LIKENESS OF PRICE: LIKE/DISLIKE + QUESTION ABOUT LIKENESS OF PRICE: CHEAP/LUXURY QUESTION ABOUT MOOD: GOOD, BAD, SAD + + QUESTION ABOUT BEHAVIOUR TODAY/TOMORROW: IDLE, SHOPPING, READING... + + QUESTION ABOUT ABILITY TO LEARN: LOW/MEDIUM/HIGH */ + + return map[string]interface{}{ + "query": "response", + } +} + +func (this *PVPController) AskMood(query interface{}) interface{} { + return this.Query(query) +} + +func (this *PVPController) AskLike(query interface{}) interface{} { + return this.Query(query) +} + +func (this *PVPController) AskPriceAcceptance(query interface{}) interface{} { + return this.Query(query) } // SUPER GOAL: Artificial Intelligence @@ -75,10 +98,10 @@ func (this *PVPController) GetAI() { THE COMBINATION OF: - TRAINING USING CURRENT SENSORS + - TRAINING USING CURRENT DECISIONS - CURRENT BRAIN STATE - - CURRENT INDICES - - CURRENT METRICS OF ACTIONS, BEHAVIOURS - - CURRENT HABITS + - CURRENT KNOWLEDGE/INDICES + - CURRENT METRICS OF BEHAVIOURS, HABITS, ABILITIES, MOODS - ... ******************************************** */ diff --git a/population/pvp/decision.go b/population/pvp/decision.go new file mode 100644 index 0000000..1f62be2 --- /dev/null +++ b/population/pvp/decision.go @@ -0,0 +1,10 @@ +package pvp + +type DecisionController struct { + + /* + - ACTIONS: click, skip, like, scroll-back, returned + - TIME AXIS BASED + */ + +} diff --git a/population/pvp/environment.go b/population/pvp/environment.go new file mode 100644 index 0000000..54a191e --- /dev/null +++ b/population/pvp/environment.go @@ -0,0 +1,9 @@ +package pvp + +type EnvironmentController struct { + /* + - NETWORK: 3G, Wifi + - PLACE: HOME, OFFICE + - ... + */ +} diff --git a/population/pvp/fact.go b/population/pvp/fact.go new file mode 100644 index 0000000..cbb7120 --- /dev/null +++ b/population/pvp/fact.go @@ -0,0 +1,11 @@ +package pvp + +type FactController struct { + /* + - AGE + - SEX + - HEIGHT + - WEIGHT + - ... + */ +} diff --git a/population/pvp/knowledge.go b/population/pvp/knowledge.go new file mode 100644 index 0000000..6ffaa14 --- /dev/null +++ b/population/pvp/knowledge.go @@ -0,0 +1,3 @@ +package pvp + +type KnowledgeController struct {} diff --git a/population/pvp/system_big3/approach.go b/population/pvp/system_big3/approach.go new file mode 100644 index 0000000..0ff6ea0 --- /dev/null +++ b/population/pvp/system_big3/approach.go @@ -0,0 +1,10 @@ +package big3 + +type ApproachController struct { + /* + - help + - intimacy + - success + - dominance + */ +} diff --git a/population/pvp/system_big3/avoidance.go b/population/pvp/system_big3/avoidance.go new file mode 100644 index 0000000..496e676 --- /dev/null +++ b/population/pvp/system_big3/avoidance.go @@ -0,0 +1,10 @@ +package big3 + +type AvoidanecController struct { + /* + - avoid harm + - avoid disappointment + - avoid failure + - avoid financial loss + */ +} diff --git a/population/pvp/system_big3/behavior.go b/population/pvp/system_big3/behavior.go new file mode 100644 index 0000000..816aeab --- /dev/null +++ b/population/pvp/system_big3/behavior.go @@ -0,0 +1,14 @@ +package big3 + +type BehaviorController struct { + /* + - help + - intimacy + - success + - dominance + - avoid harm + - avoid disappointment + - avoid failure + - avoid financial loss + */ +} diff --git a/population/pvp/system_big3/situation_goal.go b/population/pvp/system_big3/situation_goal.go new file mode 100644 index 0000000..bae1314 --- /dev/null +++ b/population/pvp/system_big3/situation_goal.go @@ -0,0 +1,9 @@ +package big3 + +type SituationGoalController struct { + /* + - S1 + - ... + - S8 + */ +} diff --git a/population/pvp/system_big3/situation_resource.go b/population/pvp/system_big3/situation_resource.go new file mode 100644 index 0000000..34adcc2 --- /dev/null +++ b/population/pvp/system_big3/situation_resource.go @@ -0,0 +1,9 @@ +package big3 + +type SituationResourceController struct { + /* + - R1 + - ... + - R8 + */ +} diff --git a/population/pvp/trait/ability.go b/population/pvp/trait/ability.go new file mode 100644 index 0000000..d0b173b --- /dev/null +++ b/population/pvp/trait/ability.go @@ -0,0 +1,11 @@ +package trait + +type AbilityController struct { + /* + - FAST LEARN + - IGNORANT + - OPTIMISTIC + - PESIMISTIC + - ... + */ +} diff --git a/population/pvp/trait/behaviour.go b/population/pvp/trait/behaviour.go new file mode 100644 index 0000000..1470bef --- /dev/null +++ b/population/pvp/trait/behaviour.go @@ -0,0 +1,10 @@ +package trait + +type BehaviourController struct { + /* + - CLICKING FROM LEFT ONLY + - CLICKING FROM RIGHT ONLY + - CLICKING TOP ONLY + - CLICKING BOTTOM ONLY + */ +} diff --git a/population/pvp/trait/habit.go b/population/pvp/trait/habit.go new file mode 100644 index 0000000..8193c80 --- /dev/null +++ b/population/pvp/trait/habit.go @@ -0,0 +1,9 @@ +package trait + +type HabitController struct { + /* + - CLICKING ORDER + - TIME TO VISIT + - ... + */ +} diff --git a/population/pvp/trait/mood.go b/population/pvp/trait/mood.go new file mode 100644 index 0000000..dfc51cb --- /dev/null +++ b/population/pvp/trait/mood.go @@ -0,0 +1,12 @@ +package trait + +type MoodController struct { + /* + - EROTIC + - NATURE + - CAR + - FASHION + - MOTO + - ... + */ +} diff --git a/population/trait/behaviour.go b/population/trait/behaviour.go deleted file mode 100644 index d8a3c89..0000000 --- a/population/trait/behaviour.go +++ /dev/null @@ -1,3 +0,0 @@ -package trait - -type BehaviourController struct {} diff --git a/population/trait/decision.go b/population/trait/decision.go deleted file mode 100644 index a4aebc0..0000000 --- a/population/trait/decision.go +++ /dev/null @@ -1,3 +0,0 @@ -package trait - -type DecisionController struct {} diff --git a/population/trait/fact.go b/population/trait/fact.go deleted file mode 100644 index 5b5e940..0000000 --- a/population/trait/fact.go +++ /dev/null @@ -1,3 +0,0 @@ -package trait - -type FactController struct {} diff --git a/population/trait/habit.go b/population/trait/habit.go deleted file mode 100644 index 1c741a5..0000000 --- a/population/trait/habit.go +++ /dev/null @@ -1,3 +0,0 @@ -package trait - -type HabitController struct {} diff --git a/population/trait/location.go b/population/trait/location.go deleted file mode 100644 index 2af8c28..0000000 --- a/population/trait/location.go +++ /dev/null @@ -1,3 +0,0 @@ -package trait - -type LocationController struct {} diff --git a/population/trait/mood.go b/population/trait/mood.go deleted file mode 100644 index 2334cfa..0000000 --- a/population/trait/mood.go +++ /dev/null @@ -1,3 +0,0 @@ -package trait - -type MoodController struct {} diff --git a/population/vhs/communicator.go b/population/vhs/communicator.go new file mode 100644 index 0000000..3b232c0 --- /dev/null +++ b/population/vhs/communicator.go @@ -0,0 +1,7 @@ +package vhs + +type Communicator interface { + + Query(interface {}, interface {}) interface {} + Train(interface {}, interface {}) interface {} +} diff --git a/population/vhs/communicator/audio.go b/population/vhs/communicator/audio.go new file mode 100644 index 0000000..211f475 --- /dev/null +++ b/population/vhs/communicator/audio.go @@ -0,0 +1 @@ +package communicator diff --git a/population/vhs/communicator/elasticfeed_protocol.go b/population/vhs/communicator/elasticfeed_protocol.go new file mode 100644 index 0000000..211f475 --- /dev/null +++ b/population/vhs/communicator/elasticfeed_protocol.go @@ -0,0 +1 @@ +package communicator diff --git a/population/vhs/communicator/video_audio.go b/population/vhs/communicator/video_audio.go new file mode 100644 index 0000000..211f475 --- /dev/null +++ b/population/vhs/communicator/video_audio.go @@ -0,0 +1 @@ +package communicator diff --git a/service/service.go b/service/service.go index 830dfd1..ba47a25 100644 --- a/service/service.go +++ b/service/service.go @@ -5,6 +5,7 @@ import ( "github.com/feedlabs/elasticfeed/service/stream" "github.com/feedlabs/elasticfeed/service/system" "github.com/feedlabs/elasticfeed/service/predict" + "github.com/feedlabs/elasticfeed/service/surrogate" "github.com/feedlabs/elasticfeed/elasticfeed/model" ) @@ -18,6 +19,7 @@ type ServiceManager struct { stream *stream.StreamService system *system.SystemService predict *predict.PredictService + surrogate *surrogate.SurrogateService } func (this *ServiceManager) Init() { @@ -25,6 +27,7 @@ func (this *ServiceManager) Init() { this.stream.Init() this.store.Init() this.predict.Init() + this.surrogate.Init() } func (this *ServiceManager) GetDbService() *store.DbService { @@ -43,12 +46,17 @@ func (this *ServiceManager) GetPredictService() *predict.PredictService { return this.predict } +func (this *ServiceManager) GetSurrogateService() *surrogate.SurrogateService { + return this.surrogate +} + func NewServiceManager(engine model.Elasticfeed) *ServiceManager { store := store.NewDbService() stream := stream.NewStreamService() system := system.NewSystemService() predict := predict.NewPredictService() + surrogate := surrogate.NewSurrogateService() - return &ServiceManager{engine, store, stream, system, predict} + return &ServiceManager{engine, store, stream, system, predict, surrogate} } diff --git a/service/surrogate/surrogate.go b/service/surrogate/surrogate.go new file mode 100644 index 0000000..2647719 --- /dev/null +++ b/service/surrogate/surrogate.go @@ -0,0 +1,24 @@ +package surrogate + +import ( + "github.com/feedlabs/elasticfeed/service/surrogate/v1/router" +) + +/* + TODO: + - SHOULD BE A BRIDGE TO PVP + - SHOULD BE A BRIDGE VIA VHS + - .. + */ + +type SurrogateService struct {} + +func (this *SurrogateService) Init() { + router.InitStatusRouters() + router.InitQueryRouters() + router.InitTrainRouters() +} + +func NewSurrogateService() *SurrogateService { + return &SurrogateService{} +} diff --git a/service/surrogate/v1/controller/default.go b/service/surrogate/v1/controller/default.go new file mode 100644 index 0000000..fe583aa --- /dev/null +++ b/service/surrogate/v1/controller/default.go @@ -0,0 +1,24 @@ +package controller + +import ( + "github.com/feedlabs/feedify" +) + +type DefaultController struct { + feedify.Controller +} + +func (this *DefaultController) Get() { + this.Data["json"] = map[string]string{"succes": "ok"} + this.Controller.ServeJson() +} + +func (this *DefaultController) ServeJson(data interface{}, status int) { + this.Data["json"] = data + this.SetResponseStatusCode(status) + this.Controller.ServeJson() +} + +func (this *DefaultController) SetResponseStatusCode(code int) { + this.Controller.Ctx.Output.SetStatus(code) +} diff --git a/service/surrogate/v1/controller/status.go b/service/surrogate/v1/controller/status.go new file mode 100644 index 0000000..ce3a067 --- /dev/null +++ b/service/surrogate/v1/controller/status.go @@ -0,0 +1,17 @@ +package controller + +import ( + "github.com/feedlabs/feedify" +) + +type StatusController struct { + feedify.Controller +} + +func (this *StatusController) Get() { + this.Data["json"] = map[string]interface{}{ + "enabled": true, + } + + this.Controller.ServeJson() +} diff --git a/service/surrogate/v1/router/query.go b/service/surrogate/v1/router/query.go new file mode 100644 index 0000000..019c0c9 --- /dev/null +++ b/service/surrogate/v1/router/query.go @@ -0,0 +1,10 @@ +package router + +import ( + "github.com/feedlabs/feedify" + "github.com/feedlabs/elasticfeed/service/surrogate/v1/controller" +) + +func InitQueryRouters() { + feedify.Router("/v1/surrogate/query", &controller.DefaultController{}, "get:Get") +} diff --git a/service/surrogate/v1/router/status.go b/service/surrogate/v1/router/status.go new file mode 100644 index 0000000..a86be83 --- /dev/null +++ b/service/surrogate/v1/router/status.go @@ -0,0 +1,10 @@ +package router + +import ( + "github.com/feedlabs/feedify" + "github.com/feedlabs/elasticfeed/service/surrogate/v1/controller" +) + +func InitStatusRouters() { + feedify.Router("/v1/surrogate/status", &controller.StatusController{}, "get:Get") +} diff --git a/service/surrogate/v1/router/train.go b/service/surrogate/v1/router/train.go new file mode 100644 index 0000000..daec3e8 --- /dev/null +++ b/service/surrogate/v1/router/train.go @@ -0,0 +1,10 @@ +package router + +import ( + "github.com/feedlabs/feedify" + "github.com/feedlabs/elasticfeed/service/surrogate/v1/controller" +) + +func InitTrainRouters() { + feedify.Router("/v1/surrogate/train", &controller.DefaultController{}, "get:Get") +} diff --git a/service/surrogate/v1/template/const.go b/service/surrogate/v1/template/const.go new file mode 100644 index 0000000..8e811ae --- /dev/null +++ b/service/surrogate/v1/template/const.go @@ -0,0 +1,12 @@ +package template + +const HTTP_CODE_VALID_REQUEST = 200 +const HTTP_CODE_ENTITY_CREATED = 201 +const HTTP_CODE_ENTITY_NOEXIST = 404 +const HTTP_CODE_ENTITY_CONFLICT = 409 +const HTTP_CODE_INVALID_REQUEST = 400 +const HTTP_CODE_ACCESS_UNAUTHORIZED = 401 +const HTTP_CODE_ACCESS_FORBIDDEN = 403 +const HTTP_CODE_NOALLOWED_REQUEST = 405 +const HTTP_CODE_TOOMANY_REQUEST = 429 +const HTTP_CODE_SERVER_ERROR = 500 diff --git a/service/surrogate/v1/template/default.go b/service/surrogate/v1/template/default.go new file mode 100644 index 0000000..eeac146 --- /dev/null +++ b/service/surrogate/v1/template/default.go @@ -0,0 +1,29 @@ +package template + +func Error(err error) (entry map[string]interface{}, code int) { + entry = make(map[string]interface{}) + entry["result"] = err.Error() + entry["status"] = "error" + + return entry, HTTP_CODE_ENTITY_NOEXIST +} + +func Success(msg string) (entry map[string]string, code int) { + return map[string]string{"result": msg, "status": "ok"}, HTTP_CODE_VALID_REQUEST +} + +func GetOK() int { + return HTTP_CODE_VALID_REQUEST +} + +func PostOK() int { + return HTTP_CODE_ENTITY_CREATED +} + +func PutOK() int { + return HTTP_CODE_ENTITY_CREATED +} + +func DeleteOK() int { + return HTTP_CODE_VALID_REQUEST +} diff --git a/service/surrogate/v1/template/request.go b/service/surrogate/v1/template/request.go new file mode 100644 index 0000000..52a8849 --- /dev/null +++ b/service/surrogate/v1/template/request.go @@ -0,0 +1,9 @@ +package template + +import ( + net "net/url" +) + +func QueryParamsCount(url *net.URL) int { + return len(url.Query()) +} diff --git a/service/surrogate/v1/template/response.go b/service/surrogate/v1/template/response.go new file mode 100644 index 0000000..4e3fe81 --- /dev/null +++ b/service/surrogate/v1/template/response.go @@ -0,0 +1,56 @@ +package template + +import ( + "strconv" + "github.com/feedlabs/feedify/context" +) + +type ResponseDefinition struct { + orderby string + orderdir string + page int + limit int +} + +func (this *ResponseDefinition) GetOrderBy() string { + return this.orderby +} + +func (this *ResponseDefinition) GetOrderDir() string { + return this.orderdir +} + +func (this *ResponseDefinition) GetPage() int { + return this.page +} + +func (this *ResponseDefinition) GetLimit() int { + return this.limit +} + +func NewResponseDefinition(input *context.Input) *ResponseDefinition { + orderby := input.Request.URL.Query().Get("orderby") + if orderby == "" { + orderby = "id" + } + + orderdir := input.Request.URL.Query().Get("orderdir") + if orderdir == "" { + orderdir = "asc" + } + + page := input.Request.URL.Query().Get("page") + if page == "" { + page = "0" + } + + limit := input.Request.URL.Query().Get("limit") + if limit == "" { + limit = "100" + } + + pageInt, _ := strconv.Atoi(page) + limitInt, _ := strconv.Atoi(limit) + + return &ResponseDefinition{orderby, orderdir, pageInt, limitInt} +}