File: decay.py

package info (click to toggle)
python-bumps 1.0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,200 kB
  • sloc: python: 24,517; xml: 493; ansic: 373; makefile: 211; javascript: 99; sh: 94
file content (102 lines) | stat: -rw-r--r-- 1,966 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python

"""
Bevington & Robinson's model of dual exponential decay

References::
    [5] Bevington & Robinson (1992).
    Data Reduction and Error Analysis for the Physical Sciences,
    Second Edition, McGraw-Hill, Inc., New York.
"""

import numpy as np
from numpy import exp, inf, sqrt


def dual_exponential(t, a):
    """
    Computes dual exponential decay.

        y = a1 + a2 exp(-t/a3) + a4 exp(-t/a5)
    """
    a1, a2, a3, a4, a5 = a
    t = np.asarray(t)
    return a1 + a2 * exp(-t / a4) + a3 * exp(-t / a5)


# data from Chapter 8 of [5].
data = np.array(
    [
        [15, 775],
        [30, 479],
        [45, 380],
        [60, 302],
        [75, 185],
        [90, 157],
        [105, 137],
        [120, 119],
        [135, 110],
        [150, 89],
        [165, 74],
        [180, 61],
        [195, 66],
        [210, 68],
        [225, 48],
        [240, 54],
        [255, 51],
        [270, 46],
        [285, 55],
        [300, 29],
        [315, 28],
        [330, 37],
        [345, 49],
        [360, 26],
        [375, 35],
        [390, 29],
        [405, 31],
        [420, 24],
        [435, 25],
        [450, 35],
        [465, 24],
        [480, 30],
        [495, 26],
        [510, 28],
        [525, 21],
        [540, 18],
        [555, 20],
        [570, 27],
        [585, 17],
        [600, 17],
        [615, 14],
        [630, 17],
        [645, 24],
        [660, 11],
        [675, 22],
        [690, 17],
        [705, 12],
        [720, 10],
        [735, 13],
        [750, 16],
        [765, 9],
        [780, 9],
        [795, 14],
        [810, 21],
        [825, 17],
        [840, 13],
        [855, 12],
        [870, 18],
        [885, 10],
    ]
)


x = data[:, 0]
y = data[:, 1]
dy = sqrt(data[:, 1])
Po = [1, 1, 1, 1, 1]
Plo = [-inf, 0, 0, 0, 0]
Phi = [inf, inf, inf, inf, inf]

from .model import Fitness

decay = Fitness(f=dual_exponential, data=(x, y, dy), limits=(Plo, Phi), start=Po)