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)
| 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): |
no outgoing calls
no test coverage detected