#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Date : 2026-01-01
# Author : Lancelot PINCET
# GitHub : https://github.com/LancelotPincet
# Library : funcLP
# %% Libraries
import math
import numpy as np
from funclp import Function, Parameter, ufunc
from corelp import rfrom
get_tau, get_amp, get_offset = rfrom("._exponentials", "get_tau", "get_amp", "get_offset")
# %% Parameters
def tau(res, *args) :
return get_tau(res, args[0])
def amp(res, *args) :
return get_amp(res)
def offset(res, *args) :
return get_offset(res)
# %% Function
[docs]
class Exponential1(Function):
@ufunc(
variables=["t"],
parameters=[
Parameter("tau", 1., estimate=tau),
Parameter("amp", 1., estimate=amp),
Parameter("offset", 0., estimate=offset),
],
)
def function(t, /, tau=1., amp=1., offset=0.) :
return amp * math.exp(-t / tau) + offset
# Parameters derivatives
@ufunc()
def d_tau(t, /, tau, amp, offset) :
return amp * math.exp(-t / tau) * t / tau**2
@ufunc()
def d_amp(t, /, tau, amp, offset) :
return math.exp(-t / tau)
@ufunc()
def d_offset(t, /, tau, amp, offset) :
return 1
# Other attributes
@property
def k(self) :
return 1 / self.tau
@k.setter
def k(self,value) :
self.tau = 1 / value
@property
def tau_half(self) :
return self.tau * np.log(2)
@tau_half.setter
def tau_half(self,value) :
self.tau = value / np.log(2)
# %% Test function run
if __name__ == "__main__":
from corelp import debug
from funclp import plot
import numpy as np
debug_folder = debug(__file__)
# Inputs
variables = (
np.linspace(0, 10, 1000),
)
parameters = dict()
# Plot function
instance = Exponential1()
plot(instance, debug_folder, variables, parameters)