def trainEvent(observations, event_type, source_tag, target_tag, algo_type): '''Train model by input observations ''' model = getModel(algo_type, source_tag, event_type) model_param = model["modelParam"] status_sets = model["statusSets"] sound_set = status_sets["sound"] motion_set = status_sets["motion"] location_set = status_sets["location"] d = Dataset(event_type=getEventList(), motion_type=motion_set, sound_type=sound_set, location_type=location_set, event_prob_map=getEventProbMap()) numerical_obs = d._convertObs2Dataset(observations) logger.debug('[trainEvent] numerical_obs=%s' % (numerical_obs)) TRAINER = ALGOMAP[algo_type] my_trainer = TRAINER(model_param) my_trainer.fit(numerical_obs) description = '[source_tag=%s]Train model algo_type=%s for eventType=%s' % ( source_tag, algo_type, event_type) return setModel(algo_type, target_tag, event_type, my_trainer.params_, status_sets, datetime.datetime.now(), description, json.dumps(observations))