(self, n_entries)
| 199 | |
| 200 | #多批次训练 |
| 201 | def train(self, n_entries): |
| 202 | global force_train, random_train, n_improved, n_not_improved |
| 203 | n_improved = 0 |
| 204 | n_not_improved = 0 |
| 205 | |
| 206 | n_batches = math.ceil(n_entries/BATCH_SIZE) |
| 207 | for i in range(n_batches): |
| 208 | batch = cp.creat_data(BATCH_SIZE) |
| 209 | self.one_batch_train(batch) |
| 210 | improvement_rate = n_improved/(n_improved + n_not_improved) |
| 211 | print("Improvement rate") |
| 212 | print(format(improvement_rate, ".0%")) |
| 213 | if improvement_rate <= FORCE_TRAIN_THRESHOLD: |
| 214 | force_train = True |
| 215 | else: |
| 216 | force_train = False |
| 217 | if n_improved == 0: |
| 218 | random_train = True |
| 219 | else: |
| 220 | random_train = False |
| 221 | |
| 222 | data = cp.creat_data(800) |
| 223 | inputs = data[:, (0, 1)] |
| 224 | outputs = self.network_forward(inputs) |
| 225 | classification = classify(outputs[-1]) |
| 226 | data[:, 2] = classification |
| 227 | cp.plot_data(data, "After training") |
| 228 | |
| 229 | #随机更新 |
| 230 | def random_update(self): |
no test coverage detected