コード例 #1
0
def get_best_parameterization(config_fn,data_fn,metric_name='d_metric',o_config=None,o_data=None):
    _analyzer = PyposmatDataAnalyzer()
    _analyzer.read_configuration_file(filename=config_fn)
    _analyzer.read_data_file(filename=data_fn)

    # calculate the scoring metric
    if metric_name is 'd_metric':
        _df = _analyzer.calculate_d_metric(df=_analyzer.datafile.df)
    else:
        s = "The metric name {} is unsupported"
        s = s.format(metric_name)
        raise PyposmatUnsupportedPotentialScoringMetric(s)

    _data = PyposmatDataFile()
    _data.read(filename=data_fn)
    _data.df = _df
    _data.subselect_by_score(score_name='d_metric',n=1)

    _free_parameter_names = _analyzer.configuration.free_parameter_names
    
    _parameter_best_dict = OrderedDict()
    for pn in _free_parameter_names:
        _parameter_best_dict[pn] = _data.sub_parameter_df.iloc[0][pn]

    return _parameter_best_dict
コード例 #2
0
def get_parameter_variance(
        config_fn,data_fn,
        metric_name='d_metric',
        n=100,
        o_config=None,
        o_data=None):
    """
    Args:
        config_fn (str):
        data_fn (str):
        metric_name (str):  (default:d_metric)
        n (int): the number of best metric values
        o_config (pypospack.config.data.PyposmatConfigurationFile)
        o_data (pypospack.config.data.PyposmatDataFile)
    Returns:
        collections.OrderedDict
    Raises:
        PyposmatUnknownPotentialScoringMetric
    """

    _analyzer = PyposmatDataAnalyzer()
    _analyzer.read_configuration_file(filename=config_fn)
    _analyzer.read_data_file(filename=data_fn)
   
    # calculate the scoring metric
    if metric_name is 'd_metric':
        _df = _analyzer.calculate_d_metric(df=_analyzer.datafile.df)
    else:
        s = "The metric name {} is unsupported"
        s = s.format(metric_name)
        raise PyposmatUnsupportedPotentialScoringMetric(s)

    _data = PyposmatDataFile()
    _data.read(filename=data_fn)
    _data.df = _df
    _data.subselect_by_score(score_name='d_metric',n=n)

    _param_std_df = _data.sub_parameter_df.std(axis=0)
   
    _parameter_std_dict = OrderedDict()
    for pn in _analyzer.parameter_names:
        _parameter_std_dict[pn] =_param_std_df.to_dict()[pn]
    
    return _parameter_std_dict
コード例 #3
0
if __name__ == "__main__":
    import os
    import pypospack.utils
    _pypospack_root = pypospack.utils.get_pypospack_root_directory()
    _data_in_directory = os.path.join(
        _pypospack_root, 'examples',
        'Ni__eam__born_exp_fs__sensitivityanalysis',
        'data__from_pareto_optimization')
    _pyposmat_data_fn = os.path.join(_data_in_directory, 'pyposmat.kde.6.out')
    _pyposmat_config_fn = os.path.join(_data_in_directory,
                                       'pyposmat.config.in')

    analyzer = PyposmatDataAnalyzer()
    analyzer.read_configuration_file(filename=_pyposmat_config_fn)
    analyzer.read_data_file(filename=_pyposmat_data_fn)
    df = analyzer.calculate_d_metric(df=analyzer.datafile.df)

    data = PyposmatDataFile()
    data.read(filename=_pyposmat_data_fn)
    data.df = df
    data.subselect_by_score(score_name="d_metric", n=100)
    # print(data.sub_df)

    param_stdev_df = data.sub_parameter_df.std(axis=0)
    param_mean_df = data.sub_parameter_df.mean(axis=0)
    print("parameter standard deviations:\n{}".format(param_stdev_df))
    print("parameter means:\n{}".format(param_mean_df))

    data.subselect_by_score(score_name="d_metric", n=1)
    print("best parameterization by d_metric:\n{}".format(
        data.sub_parameter_df))