Coverage for tadkit/catalog/learners/_confiance_components/_cnndrad_wrapper.py: 19%

16 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-04 15:09 +0000

1import numpy as np 

2 

3 

4def get_wrapped_datareconstructionad(): 

5 """Return the TADlearner wrapped from cnndrad's DataReconstructionAD method. 

6 

7 The function is intended for use if the dependency is available. 

8 """ 

9 

10 from cnndrad import DataReconstructionAD 

11 

12 DataReconstructionAD.required_properties = [ 

13 "fixed_time_step", 

14 "univariate_time_series", 

15 ] 

16 DataReconstructionAD.params_description = { 

17 "window_size": { 

18 "description": "Size of the sliding window applied on data samples.", 

19 "value_type": "range", 

20 "start": 10, 

21 "step": 10, 

22 "stop": 1000, 

23 "default": 10, 

24 }, 

25 "window_stride": { 

26 "description": "Stride of the sliding window applied on data samples.", 

27 "value_type": "range", 

28 "start": 10, 

29 "stop": 100, 

30 "step": 10, 

31 "default": 10, 

32 }, 

33 } 

34 

35 DataReconstructionAD.__oldinit__ = DataReconstructionAD.__init__ 

36 

37 def __init__( 

38 self, 

39 window_size=100, 

40 window_stride=1, 

41 reconstruct=[True] * 3, 

42 model_name="CNN_1D_3x3Conv", 

43 metric="mae", 

44 batch_size=32, 

45 epochs=100, 

46 validation_split=0.2, 

47 work_dir="./", 

48 device="/gpu:0", 

49 **kwargs, 

50 ) -> None: 

51 DataReconstructionAD.__oldinit__( 

52 self, 

53 window_size=window_size, 

54 window_stride=window_stride, 

55 reconstruct=reconstruct, 

56 model_name=model_name, 

57 metric=metric, 

58 batch_size=batch_size, 

59 epochs=epochs, 

60 validation_split=validation_split, 

61 work_dir=work_dir, 

62 device=device, 

63 **kwargs, 

64 ) 

65 

66 DataReconstructionAD.__init__ = __init__ 

67 

68 def predict(self, X): 

69 decision_func = self.score_samples(X) 

70 is_inlier = np.ones_like(decision_func, dtype=int) 

71 is_inlier[decision_func < -1] = -1 

72 return is_inlier 

73 

74 DataReconstructionAD.predict = predict 

75 

76 return DataReconstructionAD