<commit_before>#!/usr/bin/env python
"""
Collection of fit procedures for VAMPy project
Provides:
classes:
 fitcurve(func, x, y, init, Dfun=None, **lsq_kwargs)
"""
from numpy import diag, exp, linspace, sqrt, pi, log
from scipy.optimize import leastsq
from scipy.special import sici
from scipy.stats import linregress
from scipy.odr import models, RealData, ODR

class fitcurve():
    """
    Simple wrapper for scipy.optimize.leastsq
    """
    def __init__(self, func, x, y, pinit, Dfun=None, **lsq_kwargs):
        """
        Constructor method
        @param func: function to fit in the form of f(params,x)
        @param x:
        @param y:
        @param pinit: initial guess for parameters
        @param Dfun: Jacobian function, see help for scipy.optimize.leastsq
        lsq_kwargs: dictionary of other options to pass to scipy.optimize.leastsq, see its help
        """
        self.func = func
        self.x = x
        self.y = y
        self.pinit = pinit
        self.Dfun = Dfun
        self.lsq_kwargs = lsq_kwargs
    
    def fit(self):
        """
        Fitting method
        Correction of raw covariance matrix with standard error of the estimate is implemented.
        returns fit results with respective standard errors, and message and success flag from leastsq
        """
        errfunc = lambda p, x, y: y - self.func(p, x)
        fit, cov, info, mesg, success = leastsq(
            errfunc, self.pinit, (self.x, self.y), Dfun = self.Dfun, full_output=1, **self.lsq_kwargs)
        df = len(self.x)-len(fit)
        ### this correction is according to http://thread.gmane.org/gmane.comp.python.scientific.user/19482
        see = sqrt((errfunc(fit, self.x, self.y)**2).sum()/df)
        if cov == None:
            stderr = None
        else:
            stderr = sqrt(diag(cov))*see
        return fit, stderr, mesg, success<commit_msg>+added setters to fitcurve object<commit_after>#!/usr/bin/env python
"""
Collection of fit procedures for VAMPy project
Provides:
classes:
 fitcurve(func, x, y, init, Dfun=None, **lsq_kwargs)
"""
from numpy import diag, exp, linspace, sqrt, pi, log
from scipy.optimize import leastsq
from scipy.special import sici
from scipy.stats import linregress
from scipy.odr import models, RealData, ODR

class fitcurve():
    """
    Simple wrapper for scipy.optimize.leastsq
    """
    def __init__(self, func, x, y, pinit, Dfun=None, **lsq_kwargs):
        """
        Constructor method
        @param func: function to fit in the form of f(params,x)
        @param x:
        @param y:
        @param pinit: initial guess for parameters
        @param Dfun: Jacobian function, see help for scipy.optimize.leastsq
        lsq_kwargs: dictionary of other options to pass to scipy.optimize.leastsq, see its help
        """
        self.func = func
        self.x = x
        self.y = y
        self.pinit = pinit
        self.Dfun = Dfun
        self.lsq_kwargs = lsq_kwargs
    
    def set_data(self, x,y):
        self.x = x
        self.y = y
    
    def set_func(self, func, Dfun = None):
        self.func = func
        self.Dfun = Dfun
    
    def set_init(self, pinit):
        self.pinit = pinit
    
    def fit(self):
        """
        Fitting method
        Correction of raw covariance matrix with standard error of the estimate is implemented.
        returns fit results with respective standard errors, and message and success flag from leastsq
        """
        errfunc = lambda p, x, y: y - self.func(p, x)
        fit, cov, info, mesg, success = leastsq(
            errfunc, self.pinit, (self.x, self.y), Dfun = self.Dfun, full_output=1, **self.lsq_kwargs)
        df = len(self.x)-len(fit)
        ### this correction is according to http://thread.gmane.org/gmane.comp.python.scientific.user/19482
        see = sqrt((errfunc(fit, self.x, self.y)**2).sum()/df)
        if cov == None:
            stderr = None
        else:
            stderr = sqrt(diag(cov))*see
        return fit, stderr, mesg, success
{'fraction_non_alphanumeric': 0.10337078651685393, 'fraction_numerical': 0.003495630461922597, 'mean_word_length': 2.3663865546218488, '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': '868706', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1255, 'n_words': 404}