Coverage for /opt/conda/lib/python3.12/site-packages/medil/examples.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-25 05:42 +0000

1"""Example graphs and data, for use in testing and tutorials.""" 

2 

3import numpy as np 

4 

5 

6class ExampleUDGAndMCM(object): 

7 r"""Example consisting of a description, UDG, and MCM""" 

8 

9 def __init__(self, description): 

10 self.description = description 

11 self.UDG = None 

12 self.MCM = None 

13 

14 def add_udg(self, udg): 

15 self.UDG = np.array(udg) 

16 

17 def add_mcm(self, mcm): 

18 self.MCM = np.array(mcm) 

19 

20 

21simple_M = ExampleUDGAndMCM("M-shaped mcm, with 2 latent- and 3 measurement-variables") 

22simple_M.add_udg([[1, 1, 0], [1, 1, 1], [0, 1, 1]]) 

23simple_M.add_mcm([[0, 1, 1], [1, 1, 0]]) 

24 

25triangle = ExampleUDGAndMCM( 

26 "triangle example, where minECC differs from set of all maximal cliques" 

27) 

28triangle.add_udg( 

29 [ 

30 [1, 1, 1, 0, 0, 0], 

31 [1, 1, 1, 1, 1, 0], 

32 [1, 1, 1, 0, 1, 1], 

33 [0, 1, 0, 1, 1, 0], 

34 [0, 1, 1, 1, 1, 1], 

35 [0, 0, 1, 0, 1, 1], 

36 ] 

37) 

38triangle.add_mcm([[0, 0, 1, 0, 1, 1], [0, 1, 0, 1, 1, 0], [1, 1, 1, 0, 0, 0]]) 

39 

40more_latents = ExampleUDGAndMCM( 

41 "example where number of latent variables is larger than number of measurement variables" 

42) 

43more_latents.add_udg( 

44 [ 

45 [1, 1, 0, 1, 0, 1], 

46 [1, 1, 1, 0, 1, 0], 

47 [0, 1, 1, 1, 0, 0], 

48 [1, 0, 1, 1, 1, 0], 

49 [0, 1, 0, 1, 1, 1], 

50 [1, 0, 0, 0, 1, 1], 

51 ] 

52) 

53more_latents.add_mcm( 

54 [ 

55 [1, 1, 0, 0, 0, 0], 

56 [0, 1, 1, 0, 0, 0], 

57 [0, 0, 1, 1, 0, 0], 

58 [0, 0, 0, 1, 1, 0], 

59 [0, 0, 0, 0, 1, 1], 

60 [1, 0, 0, 0, 0, 1], 

61 [1, 0, 0, 1, 0, 0], 

62 [0, 1, 0, 0, 1, 0], 

63 ] 

64) 

65 

66am_cm_diff = ExampleUDGAndMCM( 

67 "example where multiple ECCs are possible depending on edge minimal vs vertex minimal" 

68) 

69am_cm_diff.add_udg( 

70 [ 

71 [1, 1, 1, 1, 1, 0, 1, 0], 

72 [1, 1, 1, 0, 1, 1, 1, 1], 

73 [1, 1, 1, 0, 1, 1, 1, 1], 

74 [1, 0, 0, 1, 0, 1, 1, 1], 

75 [1, 1, 1, 0, 1, 1, 0, 1], 

76 [0, 1, 1, 1, 1, 1, 0, 1], 

77 [1, 1, 1, 1, 0, 0, 1, 1], 

78 [0, 1, 1, 1, 1, 1, 1, 1], 

79 ] 

80) 

81am_cm_diff.add_mcm( 

82 [ 

83 [1, 1, 1, 0, 1, 0, 0, 0], 

84 [1, 0, 0, 1, 0, 0, 1, 0], 

85 [0, 1, 1, 0, 1, 1, 0, 1], 

86 [0, 0, 0, 1, 0, 1, 0, 1], 

87 [0, 1, 1, 0, 0, 0, 1, 1], 

88 ] 

89) 

90 

91max_assignment_num = ExampleUDGAndMCM( 

92 "example where an edge has maximum assignment number, n - 2" 

93) 

94max_assignment_num.add_udg( 

95 [ 

96 [1, 1, 1, 1, 1, 1, 1, 1], 

97 [1, 1, 1, 1, 1, 1, 1, 1], 

98 [1, 1, 1, 0, 0, 0, 0, 0], 

99 [1, 1, 0, 1, 0, 0, 0, 0], 

100 [1, 1, 0, 0, 1, 0, 0, 0], 

101 [1, 1, 0, 0, 0, 1, 0, 0], 

102 [1, 1, 0, 0, 0, 0, 1, 0], 

103 [1, 1, 0, 0, 0, 0, 0, 1], 

104 ] 

105) 

106max_assignment_num.add_mcm( 

107 [ 

108 [1, 1, 1, 0, 0, 0, 0, 0], 

109 [1, 1, 0, 1, 0, 0, 0, 0], 

110 [1, 1, 0, 0, 1, 0, 0, 0], 

111 [1, 1, 0, 0, 0, 1, 0, 0], 

112 [1, 1, 0, 0, 0, 0, 1, 0], 

113 [1, 1, 0, 0, 0, 0, 0, 1], 

114 ] 

115) 

116 

117examples = (simple_M, triangle, more_latents, am_cm_diff, max_assignment_num) 

118 

119 

120## Data 

121# TODO: add linear and nonlinear data example