MCPcopy Create free account
hub / github.com/Morgansy/Genetic-Alpha / execute

Method execute

_program.py:417–463  ·  view source on GitHub ↗

Execute the program according to X. Parameters ---------- X : {array-like}, shape = [n_samples, n_features] Training vectors, where n_samples is the number of samples and n_features is the number of features. Returns ------- y

(self, X)

Source from the content-addressed store, hash-verified

415 return len(self.program)
416
417 def execute(self, X):
418 """Execute the program according to X.
419
420 Parameters
421 ----------
422 X : {array-like}, shape = [n_samples, n_features]
423 Training vectors, where n_samples is the number of samples and
424 n_features is the number of features.
425
426 Returns
427 -------
428 y_hats : array-like, shape = [n_samples]
429 The result of executing the program on X.
430
431 # Check for single-node programs
432 node = self.program[0]
433 if isinstance(node, float):
434 return np.tile(node, (X.shape[0], X.shape[1]))
435 if isinstance(node, int):
436 return X[:, :, node]
437
438 apply_stack = []
439
440 for node in self.program:
441
442 if isinstance(node, _Function):
443 apply_stack.append([node])
444 else:
445 # Lazily evaluate later
446 apply_stack[-1].append(node)
447
448 while len(apply_stack[-1]) == apply_stack[-1][0].arity + 1:
449 # Apply functions that have sufficient arguments
450 function = apply_stack[-1][0]
451 terminals = [t if isinstance(t, float)
452 else X[:, :, t] if isinstance(t, int)
453 else t for t in apply_stack[-1][1:]]
454 intermediate_result = function(*terminals)
455 if len(apply_stack) != 1:
456 apply_stack.pop()
457 apply_stack[-1].append(intermediate_result)
458 else:
459 return intermediate_result
460 """
461 # We call the calculator function defined in utilities.py,
462 # which is the same as the function defination above
463 return calculator(self.program, X)
464
465 def get_all_indices(self, n_samples=None, max_samples=None,
466 random_state=None):

Callers 5

raw_fitnessMethod · 0.95
fitMethod · 0.80
predictMethod · 0.80
predict_probaMethod · 0.80
transformMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected