def fit_single_parameter(modelid, fullparms, parmid, parmval, noise=False): """ Use the full parameter set `fullparms` and leave a single parameter `parmid` variable during the fit. Returns the fitted value of the parameter with index `parmid` """ corr = Correlation(fit_model=modelid, fit_algorithm=FITALG, verbose=0) tau = np.exp(np.linspace(np.log(TAUMIN),np.log(TAUMAX), TAULEN)) # Create artificial data by using the current fit_model data = corr.fit_model(fullparms, tau) if noise: if noise is True: deltanoise = (np.max(data)-np.min(data))/20 else: deltanoise = (np.max(data)-np.min(data))*noise anoise = (np.random.random(data.shape[0])-.5)*deltanoise data += anoise # Add artificial data to data set corr.correlation = np.dstack((tau, data))[0] # Set variable parameters fit_bool = np.zeros(fullparms.shape[0]) fit_bool[parmid] = True corr.fit_parameters_variable = fit_bool fullparms_edit = fullparms.copy() fullparms_edit[parmid] = parmval corr.fit_parameters = fullparms_edit Fit(corr) return corr.fit_parameters[parmid]
def create_corr(): corr = Correlation() tau = np.exp(np.linspace(np.log(1e-3),np.log(1e6), 10)) data = corr.fit_model(corr.fit_parameters, tau) noise = (np.random.random(data.shape[0])-.5)*.0005 data += noise corr.correlation = np.dstack((tau, data))[0] return corr