<commit_before>from fitfunctionbase import FitFunctionBase
from fitparameters import *
from fithandles import *



__all__ = [
  'FitFuncGaussian', 'FitFuncPseudoVoigt', 'FitFuncBoltzmann2',
  'FitFuncConstant', 'FitFuncLine', 'FitFuncHeaviside',
  'FitFuncRectangularWindow'
]



class FitFuncGaussian(FitFunctionBase):
  name = 'gaussian'
  label = 'Gaussian'
  expr = 'a*exp(-(x-b)**2/(2*c**2))'
  expr_excel = '%(a)s*exp(-((%(x)s-%(b)s)^2)/(2*(%(c)s^2)))'
  expr_latex = r'y=a\exp\left[-\frac{(x-b)^2}{2c^2}\right]'
  parameters = [
    ('a', 'Max height (at x=b)'),
    ('b', 'Center'),
    ('c', 'Standard deviation')
  ]

  def __init__(self, view):
    super().__init__(view)

    r = view.viewRect()
    x1, x2, y1, y2 = r.left(), r.right(), r.top(), r.bottom()
    self.addParam(FitParam('a', y2*0.6))
    self.addParam(FitParam('b', (x1 + x2)/2))
    self.addParam(FitParam('c', (x2 - x1)*0.1))
    self.addParam(self.eval('Area', 'sqrt(2*pi)*a*c', None))

    half = self.eval('half', 'a/2', None)
    x1 = self.eval('x1', 'b+c*sqrt(2*log(2))', self.c)
    self.addHandle(FitHandlePosition(view, self.b, self.a))
    self.addHandle(FitHandleLine(view, self.b, half, x1, half))



class FitFuncPseudoVoigt(FitFunctionBase):
  name = 'pseudovoigt'
  label = 'PseudoVoigt'
  expr = 'a*(m*2/pi*w/(4*(x-x0)**2+w**2) + (1-m)*2*sqrt(ln(2))/(sqrt(pi)*w)*exp(-4*ln(2)/(w**2)*(x-x0)**2))'
  expr_excel = '%(a)s*(%(m)s*2/PI()*%(w)s/(4*((%(x)s-%(x0)s)^2)+w^2) + (1-%(m)s)*2*sqrt(ln(2))/(sqrt(PI())*%(w)s)*exp(-4*ln(2)/(%(w)s^2)*((%(x)s-%(x0)s)^2)))'
  expr_latex = r'y=a\left\{ m\frac{2}{\pi}\frac{w}{4(x-x_0)^2 + w^2} + (1-m)\frac{2\sqrt{\ln2}}{\sqrt{\pi}w}\exp\left[-\frac{4\ln2}{w^2}(x-x_0)^2\right] \right\}'
  parameters = [
    ('a', 'Area'),
    ('x0', 'Center'),<commit_msg>[Fit] Fix Excel formula of Pseudo-Voigt function<commit_after>from fitfunctionbase import FitFunctionBase
from fitparameters import *
from fithandles import *



__all__ = [
  'FitFuncGaussian', 'FitFuncPseudoVoigt', 'FitFuncBoltzmann2',
  'FitFuncConstant', 'FitFuncLine', 'FitFuncHeaviside',
  'FitFuncRectangularWindow'
]



class FitFuncGaussian(FitFunctionBase):
  name = 'gaussian'
  label = 'Gaussian'
  expr = 'a*exp(-(x-b)**2/(2*c**2))'
  expr_excel = '%(a)s*exp(-((%(x)s-%(b)s)^2)/(2*(%(c)s^2)))'
  expr_latex = r'y=a\exp\left[-\frac{(x-b)^2}{2c^2}\right]'
  parameters = [
    ('a', 'Max height (at x=b)'),
    ('b', 'Center'),
    ('c', 'Standard deviation')
  ]

  def __init__(self, view):
    super().__init__(view)

    r = view.viewRect()
    x1, x2, y1, y2 = r.left(), r.right(), r.top(), r.bottom()
    self.addParam(FitParam('a', y2*0.6))
    self.addParam(FitParam('b', (x1 + x2)/2))
    self.addParam(FitParam('c', (x2 - x1)*0.1))
    self.addParam(self.eval('Area', 'sqrt(2*pi)*a*c', None))

    half = self.eval('half', 'a/2', None)
    x1 = self.eval('x1', 'b+c*sqrt(2*log(2))', self.c)
    self.addHandle(FitHandlePosition(view, self.b, self.a))
    self.addHandle(FitHandleLine(view, self.b, half, x1, half))



class FitFuncPseudoVoigt(FitFunctionBase):
  name = 'pseudovoigt'
  label = 'PseudoVoigt'
  expr = 'a*(m*2/pi*w/(4*(x-x0)**2+w**2) + (1-m)*2*sqrt(ln(2))/(sqrt(pi)*w)*exp(-4*ln(2)/(w**2)*(x-x0)**2))'
  expr_excel = '%(a)s*(%(m)s*2/PI()*%(w)s/(4*((%(x)s-%(x0)s)^2)+%(w)s^2) + (1-%(m)s)*2*sqrt(ln(2))/(sqrt(PI())*%(w)s)*exp(-4*ln(2)/(%(w)s^2)*((%(x)s-%(x0)s)^2)))'
  expr_latex = r'y=a\left\{ m\frac{2}{\pi}\frac{w}{4(x-x_0)^2 + w^2} + (1-m)\frac{2\sqrt{\ln2}}{\sqrt{\pi}w}\exp\left[-\frac{4\ln2}{w^2}(x-x_0)^2\right] \right\}'
  parameters = [
    ('a', 'Area'),
    ('x0', 'Center'),
{'fraction_non_alphanumeric': 0.27921176797113517, 'fraction_numerical': 0.039411601443241746, 'mean_word_length': 4.613707165109035, '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': '7617468', 'n_tokens_mistral': 1730, 'n_tokens_neox': 1628, 'n_words': 215}