Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2@file 

3@brief Actions definition. 

4""" 

5from .api_extension import AutoAction 

6from .gactions import MLAction, MLActionFunction 

7 

8 

9class MLModel(MLActionFunction): 

10 """ 

11 Base class for every machine learned model 

12 """ 

13 

14 def __init__(self, input, output_names=None, name=None): 

15 """ 

16 @param name a name which identifies the action 

17 @param input an action which produces the output result 

18 @param output_names names for the outputs 

19 """ 

20 MLActionFunction.__init__(self, input, name=name) 

21 self.output_names = output_names 

22 

23 @property 

24 def InputNames(self): 

25 """ 

26 Returns the input names 

27 """ 

28 vars = self.enumerate_variables() 

29 res = list(sorted(set(v.name_var for v in vars))) 

30 if len(res) == 0: 

31 raise ValueError( # pragma: no cover 

32 "At least one variable must be defined.") 

33 return res 

34 

35 @property 

36 def OutputNames(self): 

37 """ 

38 Returns the output names 

39 """ 

40 return self.output_names 

41 

42 @AutoAction.cache 

43 def _export_json(self, hook=None, result_name=None): 

44 js = MLAction._export_json(self, hook=hook) 

45 js.update({"input_names": self.InputNames, 

46 "output_names": self.OutputNames}) 

47 return js 

48 

49 @AutoAction.cache 

50 def _export_c(self, hook=None, result_name=None): 

51 if result_name is None: 

52 result_name = "pred" 

53 return MLActionFunction._export_c(self, hook=hook, result_name=result_name)