bayesian_ab_testing.models
Thompson sampling with bernoulli reward
TS_Bernoulli.ThompsonAlgo
Bases: ISQL_Etiquette
The sampling algorithm used for live A/B testing
Source code in bayesian_ab_testing\models\TS_Bernoulli\bernoulli_algorithm.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
__init__(cnxn, customer_id)
Constructor that initializes the thompson algorithm
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cnxn |
Connection
|
Connection to db |
required |
customer_id |
int
|
customer_id |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
The customer has no active arms |
Source code in bayesian_ab_testing\models\TS_Bernoulli\bernoulli_algorithm.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
get_best_arm(information=None)
Samples the best arm
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
information |
str
|
Information provided by the customer to be stored without structure. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
serve |
Source code in bayesian_ab_testing\models\TS_Bernoulli\bernoulli_algorithm.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
TS_Bernoulli.ThompsonArm
Bases: ISQL_Etiquette
An implementation of the Thompson Sampling algorithm arm.
Source code in bayesian_ab_testing\models\TS_Bernoulli\bernoulli_algorithm.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
__init__(id, cnxn, **kwargs)
Constructor for the arm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id |
int
|
arm_id |
required |
cnxn |
Connection
|
sqlite3.connection |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
provide |
ValueError
|
provide |
Source code in bayesian_ab_testing\models\TS_Bernoulli\bernoulli_algorithm.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
__repr__()
String representation of the arm.
Source code in bayesian_ab_testing\models\TS_Bernoulli\bernoulli_algorithm.py
85 86 87 88 89 | |
change_type(type=None)
Change the type of the arm
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type |
str
|
Arm type. Defaults to None. |
None
|
Source code in bayesian_ab_testing\models\TS_Bernoulli\bernoulli_algorithm.py
151 152 153 154 155 156 157 158 159 160 161 | |
log_sampled(information=None)
Acknowledge the fact that this arm has been chosen by the algorithm
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
information |
str
|
Information provided by the customer to store without structure. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
serve |
Source code in bayesian_ab_testing\models\TS_Bernoulli\bernoulli_algorithm.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
log_trigger(serve_id)
Acknowledge the fact that this arm triggered a reward
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serve_id |
int
|
serve_id |
required |
Source code in bayesian_ab_testing\models\TS_Bernoulli\bernoulli_algorithm.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
pull()
Pulls a random number from the beta distribution (used to determine winner while allowing for exploration)
Source code in bayesian_ab_testing\models\TS_Bernoulli\bernoulli_algorithm.py
92 93 94 95 96 97 | |