<commit_before>"""The module provides an estimation process given the simulated data set and the initialization
file."""
import os

from scipy.optimize import minimize
import pandas as pd

from development.estimation_auxiliary import minimizing_interface
from development.estimation_auxiliary import optimizing_target
from development.estimation_auxiliary import start_values
from grmpy.read.read import read


def estimate(init_file, type):
    """The function estimates the coefficients of the simulated data set."""
    assert os.path.isfile(init_file)
    # Import init file as dictionary
    dict_ = read(init_file)

    data_file = dict_['SIMULATION']['source'] + '.grmpy.txt'

    assert os.path.isfile(data_file)

    # Read data frame
    data = pd.read_table(data_file, delim_whitespace=True, header=0)

    # define starting values
    x0 = start_values(dict_, data, type)
    opts = {'maxiter': 100}

    opt_rslt = minimize(minimizing_interface, x0, args=(data, dict_), method='BFGS', options=opts)
    x_rslt, fun = opt_rslt['x'], opt_rslt['fun']
    success = opt_rslt['success']

    rslt = optimizing_target(x_rslt, dict_)

    rslt['fval'], rslt['success'] = fun, success

    # Finishing
    return rslt
<commit_msg>Update estimation.py<commit_after>"""The module provides an estimation process given the simulated data set and the initialization
file."""
import os

from scipy.optimize import minimize
import pandas as pd

from development.estimation_auxiliary import minimizing_interface
from development.estimation_auxiliary import optimizing_target
from development.estimation_auxiliary import start_values
from grmpy.read.read import read


def estimate(init_file, type):
    """The function estimates the coefficients of the simulated data set."""
    # Import init file as dictionary
    assert os.path.isfile(init_file)
    dict_ = read(init_file)

    data_file = dict_['SIMULATION']['source'] + '.grmpy.txt'
    assert os.path.isfile(data_file)

    # Read data frame
    data = pd.read_table(data_file, delim_whitespace=True, header=0)

    # define starting values
    x0 = start_values(dict_, data, type)
    opts = {'maxiter': 100}

    opt_rslt = minimize(minimizing_interface, x0, args=(data, dict_), method='BFGS', options=opts)
    x_rslt, fun = opt_rslt['x'], opt_rslt['fun']
    success = opt_rslt['success']

    rslt = optimizing_target(x_rslt, dict_)

    rslt['fval'], rslt['success'] = fun, success

    # Finishing
    return rslt

{'fraction_non_alphanumeric': 0.0981421647819063, 'fraction_numerical': 0.004846526655896607, 'mean_word_length': 4.553811659192825, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1748053', 'n_tokens_mistral': 793, 'n_tokens_neox': 739, 'n_words': 217}