def fit(self, X, y): """Run the search algorithm to synthesize a push program. Parameters ---------- X : pandas dataframe of shape = [n_samples, n_features] The training input samples. y : list, array-like, or pandas dataframe. The target values (class labels in classification, real numbers in regression). Shape = [n_samples] or [n_samples, n_outputs] """ # arity is the number of inputs that the program takes. X, y, arity, y_types = check_X_y(X, y) output_types = [ self.interpreter.type_library.push_type_for_type(t).name for t in y_types ] if self.last_str_from_stdout: ndx = list_rindex(output_types, "str") if ndx is not None: output_types[ndx] = "stdout" self.signature = ProgramSignature(arity=arity, output_stacks=output_types, push_config=self.push_config) self.evaluator = DatasetEvaluator(X, y, interpreter=self.interpreter) self._build_search_algo() self.solution = self.search.run() self.search.config.tear_down()
def evaluate(self, program: CodeBlock) -> np.ndarray: """Evaluate the program and return the error vector. Parameters ---------- program Program (CodeBlock of Push code) to evaluate. Returns ------- np.ndarray The error vector of the program. """ errors_on_cases = [] for ndx, case in enumerate(self.X): expected = self.y[ndx] if not isinstance(expected, (list, np.ndarray)): expected = [expected] output_types = [self.interpreter.type_library.push_type_of(_).name for _ in expected] if self.last_str_from_stdout: ndx = list_rindex(output_types, "str") if ndx is not None: output_types[ndx] = "stdout" actual = self.interpreter.run(program, case, output_types) errors_on_cases.append(self.default_error_function(actual, expected)) return np.array(errors_on_cases).flatten()
def fit(self, X, y): """Run the search algorithm to synthesize a push program. Parameters ---------- X : pandas dataframe of shape = [n_samples, n_features] The training input samples. y : list, array-like, or pandas dataframe. The target values (class labels in classification, real numbers in regression). Shape = [n_samples] or [n_samples, n_outputs] """ X, y, arity, y_types = check_X_y(X, y) self.interpreter.instruction_set.register_n_inputs(arity) output_types = [push_type_for_type(t).name for t in y_types] if self.last_str_from_stdout: ndx = list_rindex(output_types, "str") if ndx is not None: output_types[ndx] = "stdout" self.evaluator = DatasetEvaluator( X, y, interpreter=self.interpreter, last_str_from_stdout=self.last_str_from_stdout, verbosity_config=DEFAULT_VERBOSITY_LEVELS[self.verbose]) self._build_search_algo() best_seen = self.search.run() self._result = SearchResult(best_seen.program, output_types)
def fit(self, X, y): """Run the search algorithm to synthesize a push program. Parameters ---------- X : pandas dataframe of shape = [n_samples, n_features] The training input samples. y : list, array-like, or pandas dataframe. The target values (class labels in classification, real numbers in regression). Shape = [n_samples] or [n_samples, n_outputs] """ X, y, arity, y_types = check_X_y(X, y) self.interpreter.instruction_set.register_n_inputs(arity) output_types = [self.interpreter.type_library.push_type_for_type(t).name for t in y_types] if self.last_str_from_stdout: ndx = list_rindex(output_types, "str") if ndx is not None: output_types[ndx] = "stdout" self.evaluator = DatasetEvaluator( X, y, interpreter=self.interpreter, last_str_from_stdout=self.last_str_from_stdout ) self._build_search_algo() best_seen = self.search.run() self._result = SearchResult(best_seen.program, output_types)
def evaluate(self, program: CodeBlock) -> np.ndarray: """Evaluate the program and return the error vector. Parameters ---------- program Program (CodeBlock of Push code) to evaluate. Returns ------- np.ndarray The error vector of the program. """ errors_on_cases = [] for ndx, case in enumerate(self.X): expected = self.y[ndx] if not isinstance(expected, (list, np.ndarray)): expected = [expected] output_types = [push_type_of(_).name for _ in expected] if self.last_str_from_stdout: ndx = list_rindex(output_types, "str") if ndx is not None: output_types[ndx] = "stdout" actual = self.interpreter.run(program, case, output_types, self.verbosity_config) errors_on_cases.append( self.default_error_function(actual, expected)) return np.array(errors_on_cases).flatten()