<commit_before>from threeML.models.spectralmodel import SpectralModel
from threeML.models.Parameter import Parameter
import math
import scipy.integrate
import operator
import numexpr
import numpy


import collections



class PowerLaw(SpectralModel):

    def setup(self):
        self.functionName        = "Powerlaw"
        self.formula             = r'\begin{equation}f(E) = A (E / E_{piv})^{\gamma}\end{equation}'
        self.parameters          = collections.OrderedDict()
        self.parameters['gamma'] = Parameter('gamma',-2.0,-10,10,0.1,fixed=False,nuisance=False,dataset=None)
        self.parameters['logA']     = Parameter('logA',-4,-40,30,0.1,fixed=False,nuisance=False,dataset=None,normalization=True)
        self.parameters['Epiv']  = Parameter('Epiv',1.0,1e-10,1e10,1,fixed=True,unit='keV')
    
        self.ncalls              = 0
    
        def integral(e1,e2):
            a                      = self.parameters['gamma'].value
            piv                    = self.parameters['Epiv'].value
            norm                   = pow(10, self.parameters['logA'].value)
      
            if(a!=-1):
                def f(energy):
                    return norm * energy * math.pow(energy/piv,a)/(a+1)
            else:
                def f(energy):
                    return norm * piv * math.log(energy)
                    
            return f(e2)-f(e1)
        self.integral            = integral
 
  
    def __call__(self,energy):
        self.ncalls             += 1<commit_msg>Changed the normalization to its logarithm which speeds up and makes much easier the work for the minimizer when the normalization can span many order of magnitudes<commit_after>from threeML.models.spectralmodel import SpectralModel
from threeML.models.Parameter import Parameter
import math
import scipy.integrate
import operator
import numexpr
import numpy


import collections



class PowerLaw(SpectralModel):

    def setup(self):
        self.functionName        = "Powerlaw"
        self.formula             = r'\begin{equation}f(E) = A (E / E_{piv})^{\gamma}\end{equation}'
        self.parameters          = collections.OrderedDict()
        self.parameters['gamma'] = Parameter('gamma',-2.0,-10,10,0.1,fixed=False,nuisance=False,dataset=None)
        self.parameters['logA']     = Parameter('logA',-4,-40,30,0.1,fixed=False,nuisance=False,dataset=None,normalization=False)
        self.parameters['Epiv']  = Parameter('Epiv',1.0,1e-10,1e10,1,fixed=True,unit='keV')
    
        self.ncalls              = 0
    
        def integral(e1,e2):
            a                      = self.parameters['gamma'].value
            piv                    = self.parameters['Epiv'].value
            norm                   = pow(10, self.parameters['logA'].value)
      
            if(a!=-1):
                def f(energy):
                    return norm * energy * math.pow(energy/piv,a)/(a+1)
            else:
                def f(energy):
                    return norm * piv * math.log(energy)
                    
            return f(e2)-f(e1)
        self.integral            = integral
 
  
    def __call__(self,energy):
        self.ncalls             += 1
{'fraction_non_alphanumeric': 0.11864406779661017, 'fraction_numerical': 0.021343377275580666, 'mean_word_length': 1.8946412352406903, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4610632', 'n_tokens_mistral': 965, 'n_tokens_neox': 891, 'n_words': 169}