Example #1
0
    def __init__(
        self,
        optimizer_names: Optional[List[str]] = None,
        log_scale: bool = False,
        quantile_width: float = 0.5,
        show_extrama: bool = True,
        **kwargs,
    ):
        self._optimizer_names = params.optional_(
            optimizer_names, lambda arg: params.sequence(arg, type_=str)
        )
        self._show_extrema = params.boolean(show_extrama)
        log_scale = params.boolean(log_scale)
        scale = "log" if log_scale else "linear"

        self._quantile_width = params.real(quantile_width, from_=0, to=1)

        kwargs["axes_scales"] = kwargs.get("axes_scales", (scale, "linear"))
        kwargs["axes_labels"] = kwargs.get(
            "axes_labels", ("function evaluations", "best score", None, None)
        )
        kwargs["rectify"] = False
        kwargs["visualization_type"] = "shaded-line"

        super().__init__(**kwargs)
Example #2
0
    def __init__(self,
                 labels_to_load: Optional[Union[str, List[str]]] = None,
                 ignore_dubious: bool = False):
        """Initialize Ni-superalloy dataset with specified labels.

        Parameters:
            labels_to_load (str or List[str]): which labels to load. Options are
                'Yield Strength', 'Ultimate Tensile Strength', 'Stress Rupture Time',
                'Stress Rupture Stress', and 'Elongation'.
                If None, then all labels are loaded.
            ignore_dubious: whether or not to ignore samples that have something
                questionable about them

        """

        labels_to_load = params.optional_(
            labels_to_load,
            lambda arg: params.any_(
                arg,
                params.string,
                lambda arg: params.sequence(arg, type_=str),
            ),
        )
        ignore_dubious = params.boolean(ignore_dubious)

        filepath = self.DEFAULT_PATH
        data, labels = self._load_data_and_labels(filepath, labels_to_load,
                                                  ignore_dubious)
        super().__init__(data=data, labels=labels)
Example #3
0
 def __init__(
     self,
     input_: TabularData,
     output: PredictiveDistribution,
     scores: Sequence[float],
     **kwargs
 ):
     super().__init__(**kwargs)
     self._input: TabularData = params.instance(input_, TabularData)
     self._output: PredictiveDistribution = params.instance(output, PredictiveDistribution)
     # total number of function evaluations during this step
     self._num_evaluations: int = params.integer(self._input.num_samples, from_=1)
     self._scores: Sequence[float] = params.any_(
         scores,
         lambda arg: params.sequence(arg, length=1, type_=float),
         lambda arg: params.sequence(arg, length=self._num_evaluations, type_=float),
     )
Example #4
0
    def __init__(
        self,
        data: Data,
        training: Sequence[Sampler],
        validation: Sampler,
        learners: Sequence[SupervisedLearner],
        features: DataValuedTransformation = IdentityFeatures(),
        metric: ScalarEvaluationMetric = RootMeanSquaredError(),
        evaluations: Sequence[Evaluation] = (LearningCurvePlot(),),  # todo: add table
        progressf: Optional[Callable[[int, int], None]] = None,
    ):
        """Initialize workflow.

        Parameters:
            data: labeled data
            training: sequence of Samplers, one for each training set size
            validation: Sampler for validation set
            learners: sequence of supervised regression algorithms
            features: any data-valued transformation
            metric: evaluation metric to use; root mean squared error by default
            evaluations: one or more evaluations; default are learning curve and table
            progressf: callable with two parameters, done iterations and total number of iterations
        """

        self._data = params.instance(data, Data)  # todo: params.data(..., is_labeled=True)
        if not self._data.is_labeled:
            raise InvalidParameterError("labeled data", "unlabeled data")
        self._training = params.sequence(training, type_=Sampler)
        self._validation = params.instance(validation, Sampler)
        self._learners = params.sequence(learners, type_=SupervisedLearner)
        self._features = params.instance(features, Features)
        self._metric = params.instance(metric, ScalarEvaluationMetric)
        self._evaluations = params.tuple_(
            evaluations, lambda arg: params.instance(arg, Evaluation)
        )
        self._progressf = params.optional_(
            progressf, lambda arg: params.callable(arg, num_pos_or_kw=2)
        )
        if self._progressf is None:
            self._progressf = lambda *args: None
Example #5
0
    def _render(self, target, **kwargs):
        """Render optimization trajectory plot.

        Parameters:
            target: rendering target which evaluation outcome is rendered to; see Evaluation._render method
        """
        if self._optimizer_names is None:
            self._line_labels = [None] * len(self._plotdata)
        else:
            self._line_labels = params.sequence(self._optimizer_names, length=len(self._plotdata))

        for i, (pd, label) in enumerate(zip(self._plotdata, self._line_labels)):
            self.shaded_line(
                pd[0],
                pd[1],
                color_idx=i,
                label=label,
                quantile_width=self._quantile_width,
                show_extrema=self._show_extrema,
            )
Example #6
0
 def __init__(
     self,
     data: VectorSpaceData,
     model: Learner,
     scorer: Scorer,
     optimizers: Sequence[Optimizer],
     evaluations: Sequence[Evaluation] = (OptimizationTrajectoryPlot(),),
     num_trials: int = 1,
     training_data: Optional[Data] = None,
 ):
     self._data = params.instance(data, VectorSpaceData)
     self._scorer = params.instance(scorer, Scorer)
     self._model = params.instance(model, Learner)
     self._optimizers = params.sequence(optimizers, type_=Optimizer)
     self._evaluations = params.tuple_(
         evaluations, lambda arg: params.instance(arg, Evaluation)
     )
     self._num_trials = params.integer(num_trials, from_=1)
     self._training_data = params.optional_(
         training_data, lambda arg: params.instance(arg, Data)
     )
Example #7
0
 def __init__(self, steps: Sequence[OptimizerStep]):
     self._steps = params.sequence(steps, type_=OptimizerStep)
     self._num_evaluations = np.sum([r.num_evaluations for r in self.steps])