MCPcopy
hub / github.com/TheAlgorithms/Python / _choose_a2

Method _choose_a2

machine_learning/sequential_minimum_optimization.py:263–299  ·  view source on GitHub ↗

Choose the second alpha using a heuristic algorithm Steps: 1: Choose alpha2 that maximizes the step size (|E1 - E2|). 2: Start in a random point, loop over all non-bound samples till alpha1 and alpha2 are optimized. 3: Start in a ra

(self, i1)

Source from the content-addressed store, hash-verified

261 return False
262
263 def _choose_a2(self, i1):
264 """
265 Choose the second alpha using a heuristic algorithm
266 Steps:
267 1: Choose alpha2 that maximizes the step size (|E1 - E2|).
268 2: Start in a random point, loop over all non-bound samples till alpha1 and
269 alpha2 are optimized.
270 3: Start in a random point, loop over all samples till alpha1 and alpha2 are
271 optimized.
272 """
273 self._unbound = [i for i in self._all_samples if self._is_unbound(i)]
274
275 if len(self.unbound) > 0:
276 tmp_error = self._error.copy().tolist()
277 tmp_error_dict = {
278 index: value
279 for index, value in enumerate(tmp_error)
280 if self._is_unbound(index)
281 }
282 if self._e(i1) >= 0:
283 i2 = min(tmp_error_dict, key=lambda index: tmp_error_dict[index])
284 else:
285 i2 = max(tmp_error_dict, key=lambda index: tmp_error_dict[index])
286 cmd = yield i1, i2
287 if cmd is None:
288 return
289
290 rng = np.random.default_rng()
291 for i2 in np.roll(self.unbound, rng.choice(self.length)):
292 cmd = yield i1, i2
293 if cmd is None:
294 return
295
296 for i2 in np.roll(self._all_samples, rng.choice(self.length)):
297 cmd = yield i1, i2
298 if cmd is None:
299 return
300
301 # Get the new alpha2 and new alpha1
302 def _get_new_alpha(self, i1, i2, a1, a2, e1, e2, y1, y2):

Callers 1

_choose_a1Method · 0.95

Calls 4

_is_unboundMethod · 0.95
_eMethod · 0.95
copyMethod · 0.80
rollMethod · 0.80

Tested by

no test coverage detected