Picklable representation of search space and evaluation function.
| 757 | |
| 758 | |
| 759 | class Domain: |
| 760 | """Picklable representation of search space and evaluation function.""" |
| 761 | |
| 762 | rec_eval_print_node_on_error = False |
| 763 | |
| 764 | # -- the Ctrl object is not used directly, but rather |
| 765 | # a live Ctrl instance is inserted for the pyll_ctrl |
| 766 | # in self.evaluate so that it can be accessed from within |
| 767 | # the pyll graph describing the search space. |
| 768 | pyll_ctrl = pyll.as_apply(Ctrl) |
| 769 | |
| 770 | def __init__( |
| 771 | self, |
| 772 | fn, |
| 773 | expr, |
| 774 | workdir=None, |
| 775 | pass_expr_memo_ctrl=None, |
| 776 | name=None, |
| 777 | loss_target=None, |
| 778 | ): |
| 779 | """ |
| 780 | Parameters |
| 781 | ---------- |
| 782 | |
| 783 | fn : callable |
| 784 | This stores the `fn` argument to `fmin`. (See `hyperopt.fmin.fmin`) |
| 785 | |
| 786 | expr : hyperopt.pyll.Apply |
| 787 | This is the `space` argument to `fmin`. (See `hyperopt.fmin.fmin`) |
| 788 | |
| 789 | workdir : string (or None) |
| 790 | If non-None, the current working directory will be `workdir`while |
| 791 | `expr` and `fn` are evaluated. (XXX Currently only respected by |
| 792 | jobs run via MongoWorker) |
| 793 | |
| 794 | pass_expr_memo_ctrl : bool |
| 795 | If True, `fn` will be called like this: |
| 796 | `fn(self.expr, memo, ctrl)`, |
| 797 | where `memo` is a dictionary mapping `Apply` nodes to their |
| 798 | computed values, and `ctrl` is a `Ctrl` instance for communicating |
| 799 | with a Trials database. This lower-level calling convention is |
| 800 | useful if you want to call e.g. `hyperopt.pyll.rec_eval` yourself |
| 801 | in some customized way. |
| 802 | |
| 803 | name : string (or None) |
| 804 | Label, used for pretty-printing. |
| 805 | |
| 806 | loss_target : float (or None) |
| 807 | The actual or estimated minimum of `fn`. |
| 808 | Some optimization algorithms may behave differently if their first |
| 809 | objective is to find an input that achieves a certain value, |
| 810 | rather than the more open-ended objective of pure minimization. |
| 811 | XXX: Move this from Domain to be an fmin arg. |
| 812 | |
| 813 | """ |
| 814 | self.fn = fn |
| 815 | if pass_expr_memo_ctrl is None: |
| 816 | self.pass_expr_memo_ctrl = getattr(fn, "fmin_pass_expr_memo_ctrl", False) |