5
5
#* repeating the selection experiment a lot of times:
6
6
times = int (input ("\n Repetitions: " ))
7
7
8
- #? Example list of 10 elements ;
9
- #* The algorithm has to recieve this list and select randomly one element ;
8
+ #? Example list of 10 objects ;
9
+ #* The algorithm has to recieve this list and select randomly one object ;
10
10
#* By repeating the selection a lot of times, the result has to be that the
11
- #* first element "E1 " is the most frecuent selected, and then "E2 ", etc.
11
+ #* first object "Obj1 " is the most frecuent selected, and then "Obj2 ", etc.
12
12
#! IF YOU WANT TO MAKE SOME EXPERIMENTS WITH AN OWN IDEA OF SELECTION LIST
13
- #! YOU JUST HAVE TO PUT INTO THE LIST "elements " WHATEVER YOU WANT!
14
- elements : list = ["E1 " , "E2 " , "E3 " , "E4 " , "E5 " , "E6 " , "E7 " , "E8 " , "E9 " , "E10 " ]
13
+ #! YOU JUST HAVE TO PUT INTO THE LIST "objects " WHATEVER YOU WANT!
14
+ objects : list = ["Obj1 " , "Obj2 " , "Obj3 " , "Obj4 " , "Obj5 " , "Obj6 " , "Obj7 " , "Obj8 " , "Obj9 " , "Obj10 " ]
15
15
counter = []
16
- n = len (elements )
16
+ n = len (objects )
17
17
18
18
#? Fills a counter vector with 0's; it will contains the amount of times that
19
- #? each element of the list was selected:
19
+ #? each object of the list was selected:
20
20
for i in range (0 , n ):
21
21
counter .append (0 )
22
22
23
23
#/ Does all the repetitions of the experiment using the logrps function to select
24
- #/ something on the list; and counts the times that each element was selected.
24
+ #/ something on the list; and counts the times that each object was selected:
25
25
for _ in range (0 , times ):
26
- selected = logrps (elements )
27
- index = elements .index (selected )
26
+ selected = logrps (objects )
27
+ index = objects .index (selected )
28
28
counter [index ] += 1
29
29
30
30
#? Prints the data from the counter:
31
- print (f"Elements on list: { n } " )
31
+ print (f"Objects on list: { n } " )
32
32
print ("\n Selected times:" )
33
33
for i in range (0 , n ):
34
- print (f"Element #{ i + 1 } [{ elements [i ]} ]: { counter [i ]} times selected;" )
34
+ print (f"Object #{ i + 1 } [{ objects [i ]} ]: { counter [i ]} times selected;" )
35
35
36
36
37
37
# Draws the line in a graph:
38
38
plt .rcParams ["figure.figsize" ] = [10 , 5 ]
39
39
plt .rcParams ["figure.autolayout" ] = True
40
40
41
41
# Points with:
42
- # (element , amountOfSelections ):
42
+ # (object , amountOfSelections ):
43
43
# points: list = []
44
44
x_values : list = []
45
45
y_values : list = []
53
53
# Shows the graphic:
54
54
plt .title ("LOGARITHMIC RANDOM PONDERATED SELECTOR" )
55
55
plt .ylabel ("Amount of selected times" )
56
- plt .xlabel ("Number of element " )
57
- info = f"For { n } elements ;\n With { times } choices;"
56
+ plt .xlabel ("Number of object " )
57
+ info = f"For { n } objects ;\n With { times } choices;"
58
58
plt .annotate (info ,
59
59
xy = (0.96 , 0.8 ), xytext = (0 , 12 ),
60
60
xycoords = ("axes fraction" , "figure fraction" ),
61
61
textcoords = "offset points" ,
62
62
size = 10 , ha = "right" , va = "top" ,
63
- bbox = dict (boxstyle = "square,pad=1.0" , fc = "white" , ec = "b " , lw = 2 ))
63
+ bbox = dict (boxstyle = "square,pad=1.0" , fc = "white" , ec = "#8B0880 " , lw = 2 ))
64
64
65
- plt .plot (x_values , y_values , "bo " , linestyle = "-" )
65
+ plt .plot (x_values , y_values , "o" , c = "#8B0880" , mfc = "#8B0880 " , linestyle = "-" )
66
66
plt .savefig ("logselection.png" , dpi = "figure" )
67
67
plt .show ()
68
68
print ()
0 commit comments