How to use the nni.metis_tuner.Regression_GP.Prediction.predict function in nni

To help you get started, we’ve selected a few nni examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / nni / src / sdk / pynni / nni / metis_tuner / metis_tuner.py View on Github external
if next_improvement > temp_improvement:
                            next_improvement = temp_improvement
                            next_candidate = threads_result['candidate']
            else:
                # ===== STEP 6: If we have no candidates, randomly pick one ===
                logger.info(
                    "DEBUG: No candidates from exploration, exploitation,\
                                 and resampling. We will random a candidate for next_candidate\n"
                )

                next_candidate = _rand_with_constraints(
                    x_bounds,
                    x_types) if minimize_starting_points is None else minimize_starting_points[0]
                next_candidate = lib_data.match_val_type(
                    next_candidate, x_bounds, x_types)
                expected_mu, expected_sigma = gp_prediction.predict(
                    next_candidate, gp_model['model'])
                next_candidate = {
                    'hyperparameter': next_candidate,
                    'reason': "random",
                    'expected_mu': expected_mu,
                    'expected_sigma': expected_sigma}

        # STEP 7: If current optimal hyperparameter occurs in the history
        # or exploration probability is less than the threshold, take next
        # config as exploration step
        outputs = self._pack_output(lm_current['hyperparameter'])
        ap = random.uniform(0, 1)
        if outputs in self.total_data or ap <= self.exploration_probability:
            if next_candidate is not None:
                outputs = self._pack_output(next_candidate['hyperparameter'])
            else:
github microsoft / nni / src / sdk / pynni / nni / metis_tuner / Regression_GP / OutlierDetection.py View on Github external
def _outlierDetection_threaded(inputs):
    """
    Detect the outlier
    """
    [samples_idx, samples_x, samples_y_aggregation] = inputs
    sys.stderr.write("[%s] DEBUG: Evaluating %dth of %d samples\n"
                     % (os.path.basename(__file__), samples_idx + 1, len(samples_x)))
    outlier = None

    # Create a diagnostic regression model which removes the sample that we
    # want to evaluate
    diagnostic_regressor_gp = gp_create_model.create_model(
        samples_x[0:samples_idx] + samples_x[samples_idx + 1:],
        samples_y_aggregation[0:samples_idx] + samples_y_aggregation[samples_idx + 1:])
    mu, sigma = gp_prediction.predict(
        samples_x[samples_idx], diagnostic_regressor_gp['model'])

    # 2.33 is the z-score for 98% confidence level
    if abs(samples_y_aggregation[samples_idx] - mu) > (2.33 * sigma):
        outlier = {"samples_idx": samples_idx,
                   "expected_mu": mu,
                   "expected_sigma": sigma,
                   "difference": abs(samples_y_aggregation[samples_idx] - mu) - (2.33 * sigma)}
    return outlier
github microsoft / nni / src / sdk / pynni / nni / metis_tuner / Regression_GP / Selection.py View on Github external
sys.stderr.write("[%s] Exercise \"%s\" acquisition function\n" \
                        % (os.path.basename(__file__), acquisition_function))

    if acquisition_function == "ei":
        outputs = lib_acquisition_function.next_hyperparameter_expected_improvement(\
                        gp_prediction.predict, [regressor_gp], x_bounds, x_types, \
                        samples_y_aggregation, minimize_starting_points, \
                        minimize_constraints_fun=minimize_constraints_fun)
    elif acquisition_function == "lc":
        outputs = lib_acquisition_function.next_hyperparameter_lowest_confidence(\
                        gp_prediction.predict, [regressor_gp], x_bounds, x_types,\
                        minimize_starting_points, minimize_constraints_fun=minimize_constraints_fun)
    elif acquisition_function == "lm":
        outputs = lib_acquisition_function.next_hyperparameter_lowest_mu(\
                        gp_prediction.predict, [regressor_gp], x_bounds, x_types,\
                        minimize_starting_points, minimize_constraints_fun=minimize_constraints_fun)
    return outputs
github microsoft / nni / src / sdk / pynni / nni / metis_tuner / metis_tuner.py View on Github external
minimize_constraints_fun=minimize_constraints_fun)
                    else:
                        # If all parameters are of "range_continuous",
                        # let's use GMM to generate random starting points
                        results_exploitation = gmm_selection.selection_r(
                            x_bounds,
                            x_types,
                            gmm['clusteringmodel_good'],
                            gmm['clusteringmodel_bad'],
                            num_starting_points=self.selection_num_starting_points,
                            minimize_constraints_fun=minimize_constraints_fun)

                    if results_exploitation is not None:
                        if _num_past_samples(results_exploitation['hyperparameter'], samples_x, samples_y) == 0:
                            temp_expected_mu, temp_expected_sigma = \
                                    gp_prediction.predict(results_exploitation['hyperparameter'], gp_model['model'])
                            temp_candidate = {
                                'hyperparameter': results_exploitation['hyperparameter'],
                                'expected_mu': temp_expected_mu,
                                'expected_sigma': temp_expected_sigma,
                                'reason': "exploitation_gmm"
                            }
                            candidates.append(temp_candidate)

                            logger.info(
                                "DEBUG: 1 exploitation_gmm candidate selected\n")
                            logger.info(temp_candidate)
                    else:
                        logger.info(
                            "DEBUG: No suitable exploitation_gmm candidates were found\n")

                except ValueError as exception:
github microsoft / nni / src / sdk / pynni / nni / metis_tuner / Regression_GP / OutlierDetection.py View on Github external
def outlierDetection(samples_x, samples_y_aggregation):
    outliers = []
    for samples_idx, _ in enumerate(samples_x):
        #sys.stderr.write("[%s] DEBUG: Evaluating %d of %d samples\n"
        #  \ % (os.path.basename(__file__), samples_idx + 1, len(samples_x)))
        diagnostic_regressor_gp = gp_create_model.create_model(\
                                        samples_x[0:samples_idx] + samples_x[samples_idx + 1:],\
                                        samples_y_aggregation[0:samples_idx] + samples_y_aggregation[samples_idx + 1:])
        mu, sigma = gp_prediction.predict(samples_x[samples_idx],
                                          diagnostic_regressor_gp['model'])
        # 2.33 is the z-score for 98% confidence level
        if abs(samples_y_aggregation[samples_idx] - mu) > (2.33 * sigma):
            outliers.append({"samples_idx": samples_idx,
                             "expected_mu": mu,
                             "expected_sigma": sigma,
                             "difference": \
                                abs(samples_y_aggregation[samples_idx] - mu) - (2.33 * sigma)})

    outliers = outliers if outliers else None
    return outliers
github microsoft / nni / src / sdk / pynni / nni / metis_tuner / Regression_GP / Selection.py View on Github external
samples_y_aggregation,
              x_bounds, x_types,
              regressor_gp,
              minimize_starting_points,
              minimize_constraints_fun=None):
    '''
    selection
    '''
    outputs = None

    sys.stderr.write("[%s] Exercise \"%s\" acquisition function\n" \
                        % (os.path.basename(__file__), acquisition_function))

    if acquisition_function == "ei":
        outputs = lib_acquisition_function.next_hyperparameter_expected_improvement(\
                        gp_prediction.predict, [regressor_gp], x_bounds, x_types, \
                        samples_y_aggregation, minimize_starting_points, \
                        minimize_constraints_fun=minimize_constraints_fun)
    elif acquisition_function == "lc":
        outputs = lib_acquisition_function.next_hyperparameter_lowest_confidence(\
                        gp_prediction.predict, [regressor_gp], x_bounds, x_types,\
                        minimize_starting_points, minimize_constraints_fun=minimize_constraints_fun)
    elif acquisition_function == "lm":
        outputs = lib_acquisition_function.next_hyperparameter_lowest_mu(\
                        gp_prediction.predict, [regressor_gp], x_bounds, x_types,\
                        minimize_starting_points, minimize_constraints_fun=minimize_constraints_fun)
    return outputs