<commit_before>"""
Example for fitdata function
============================
This example creates fake data with noise
then fits the exponential with the fitdata
function.
"""   
from pyspecdata import *
from pyspecdata import fitdata 
from sympy import symbols
import numpy as np
fl = figlist_var()
# %%
# creating a fake data recovery curve
tau = nddata(r_[0:2:100j], 'tau')
fake_data = 102*(1-2*exp(-tau*6.0))
fake_data.add_noise(5.0)

# %%
# fitting data
f = fitdata(fake_data)
M0,Mi,R1,vd = sympy.symbols("M_0 M_inf R_1 tau",real=True)
f.functional_form = Mi + (M0-Mi)*sympy.exp(-vd*R1)
logger.info(strm("Functional Form", f.functional_form))
logger.info(strm("Functional Form", f.functional_form))
f.set_guess({M0:-500, Mi:500, R1:2})
f.settoguess()
guess = f.eval(100)
f.fit()
print("output:",f.output())
print("latex:",f.latex())
T1 = 1./f.output('R_1')
fl.next('fit with guess')
fl.plot(fake_data,'o',label='fake data')
fl.plot(f.eval(100),label='fit')
fl.plot(guess,label='guess')
<commit_msg>last edit of day for sphinx<commit_after>"""
Example for fitdata function
============================
This example creates fake data with noise
then fits the exponential with the fitdata
function.
"""   
from pyspecdata import *
from pyspecdata import fitdata 
from sympy import symbols
import numpy as np
# %%
# creating a fake data recovery curve
tau = nddata(r_[0:2:100j], 'tau')
fake_data = 102*(1-2*exp(-tau*6.0))
fake_data.add_noise(5.0)

# %%
# fitting data
f = fitdata(fake_data)
M0,Mi,R1,vd = sympy.symbols("M_0 M_inf R_1 tau",real=True)
f.functional_form = Mi + (M0-Mi)*sympy.exp(-vd*R1)
logger.info(strm("Functional Form", f.functional_form))
logger.info(strm("Functional Form", f.functional_form))
f.set_guess({M0:-500, Mi:500, R1:2})
f.settoguess()
guess = f.eval(100)
f.fit()
print("output:",f.output())
print("latex:",f.latex())
T1 = 1./f.output('R_1')
with figlist_var() as fl: 
    fl.next('fit with guess')
    fl.plot(fake_data,'o',label='fake data')
    fl.plot(f.eval(100),label='fit')
    fl.plot(guess,label='guess')

{'fraction_non_alphanumeric': 0.19373776908023482, 'fraction_numerical': 0.03718199608610567, 'mean_word_length': 5.816666666666666, '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': '5875335', 'n_tokens_mistral': 831, 'n_tokens_neox': 780, 'n_words': 177}