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)
| 340 | return len(self.program) |
| 341 | |
| 342 | def execute(self, X): |
| 343 | """Execute the program according to X. |
| 344 | |
| 345 | Parameters |
| 346 | ---------- |
| 347 | X : {array-like}, shape = [n_samples, n_features] |
| 348 | Training vectors, where n_samples is the number of samples and |
| 349 | n_features is the number of features. |
| 350 | |
| 351 | Returns |
| 352 | ------- |
| 353 | y_hats : array-like, shape = [n_samples] |
| 354 | The result of executing the program on X. |
| 355 | |
| 356 | """ |
| 357 | # Check for single-node programs |
| 358 | node = self.program[0] |
| 359 | if isinstance(node, float): |
| 360 | return np.repeat(node, X.shape[0]) |
| 361 | if isinstance(node, int): |
| 362 | return X[:, node] |
| 363 | |
| 364 | apply_stack = [] |
| 365 | |
| 366 | for node in self.program: |
| 367 | |
| 368 | if isinstance(node, _Function): |
| 369 | apply_stack.append([node]) |
| 370 | else: |
| 371 | # Lazily evaluate later |
| 372 | apply_stack[-1].append(node) |
| 373 | |
| 374 | while len(apply_stack[-1]) == apply_stack[-1][0].arity + 1: |
| 375 | # Apply functions that have sufficient arguments |
| 376 | function = apply_stack[-1][0] |
| 377 | terminals = [np.repeat(t, X.shape[0]) if isinstance(t, float) |
| 378 | else X[:, t] if isinstance(t, int) |
| 379 | else t for t in apply_stack[-1][1:]] |
| 380 | intermediate_result = function(*terminals) |
| 381 | if len(apply_stack) != 1: |
| 382 | apply_stack.pop() |
| 383 | apply_stack[-1].append(intermediate_result) |
| 384 | else: |
| 385 | return intermediate_result |
| 386 | |
| 387 | # We should never get here |
| 388 | return None |
| 389 | |
| 390 | def get_all_indices(self, n_samples=None, max_samples=None, |
| 391 | random_state=None): |
no outgoing calls