• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tonegas / nnodely / 12281387031

11 Dec 2024 05:10PM UTC coverage: 93.934%. Remained the same
12281387031

push

github

web-flow
Merge pull request #34 from tonegas/features/1-setup-the-documentation

Features/1 setup the documentation

1 of 1 new or added line in 1 file covered. (100.0%)

2 existing lines in 2 files now uncovered.

8625 of 9182 relevant lines covered (93.93%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

17.39
/nnodely/initializer.py
1

2
def init_constant(indexes, params_size, dict_param = {'value':1}):
1✔
3
    """
4
    Initializes parameters to a constant value.
5

6
    Parameters
7
    ----------
8
    dict_param : dict, optional
9
        Dictionary containing the initialization parameters. Default is {'value': 1}.
10
        - value : int or float
11
            The constant value to initialize the parameters with.
12
    """
UNCOV
13
    return dict_param['value']
×
14

15
def init_negexp(indexes, params_size, dict_param = {'size_index':0, 'first_value':1, 'lambda':3}):
1✔
16
    """
17
    Initializes parameters using a negative decay exponential function.
18

19
    Parameters
20
    ----------
21
    indexes : list
22
        List of indexes for the parameters.
23
    params_size : list
24
        List of sizes for each dimension of the parameters.
25
    dict_param : dict, optional
26
        Dictionary containing the initialization parameters. Default is {'size_index': 0, 'first_value': 1, 'lambda': 3}.
27
        - size_index : int
28
            The index of the dimension to apply the exponential function.
29
        - first_value : int or float
30
            The value at the start of the range.
31
        - lambda : int or float
32
            The decay rate parameter of the exponential function.
33
    """
34
    import numpy as np
×
35
    size_index = dict_param['size_index']
×
36
    # check if the size of the list of parameters is 1, to avoid a division by zero
37
    x = 1 if params_size[size_index]-1 == 0 else indexes[size_index]/(params_size[size_index]-1)
×
38
    return dict_param['first_value']*np.exp(-dict_param['lambda']*(1-x))
×
39

40
def init_exp(indexes, params_size, dict_param = {'size_index':0, 'max_value':1, 'lambda':3, 'monotonicity':'decreasing'}):
1✔
41
    """
42
    Initializes parameters using an increasing or decreasing exponential function.
43

44
    Parameters
45
    ----------
46
    indexes : list
47
        List of indexes for the parameters.
48
    params_size : list
49
        List of sizes for each dimension of the parameters.
50
    dict_param : dict, optional
51
        Dictionary containing the initialization parameters. Default is {'size_index': 0, 'max_value': 1, 'lambda': 3, 'monotonicity': 'decreasing'}.
52
        - size_index : int
53
            The index of the dimension to apply the exponential function.
54
        - max_value : int or float
55
            The maximum value of the exponential function.
56
        - lambda : int or float
57
            The rate parameter of the exponential function.
58
        - monotonicity : str
59
            The monotonicity of the exponential function. Can be 'increasing' or 'decreasing'.
60

61
    Raises
62
    ------
63
    ValueError
64
        If the monotonicity is not 'increasing' or 'decreasing'.
65
    """
66
    import numpy as np
×
67
    size_index = dict_param['size_index']
×
68
    monotonicity = dict_param['monotonicity']
×
69
    if monotonicity == 'increasing':
×
70
        # increasing exponential, the 'max_value' is the value at x=1, i.e, at the end of the range
71
        x = 1 if params_size[size_index]-1 == 0 else indexes[size_index]/(params_size[size_index]-1)
×
72
        out = dict_param['max_value']*np.exp(dict_param['lambda']*(x-1))
×
73
    elif monotonicity == 'decreasing':
×
74
        # decreasing exponential, the 'max_value' is the value at x=0, i.e, at the beginning of the range
75
        x = 0 if params_size[size_index]-1 == 0 else indexes[size_index]/(params_size[size_index]-1)
×
76
        out = dict_param['max_value']*np.exp(-dict_param['lambda']*x)
×
77
    else:
78
        raise ValueError('The parameter monotonicity must be either increasing or decreasing.')
×
79
    return out
×
80

81
def init_lin(indexes, params_size, dict_param = {'size_index':0, 'first_value':1, 'last_value':0}):
1✔
82
    """
83
    Initializes parameters using a linear function.
84

85
    Parameters
86
    ----------
87
    indexes : list
88
        List of indexes for the parameters.
89
    params_size : list
90
        List of sizes for each dimension of the parameters.
91
    dict_param : dict, optional
92
        Dictionary containing the initialization parameters. Default is {'size_index': 0, 'first_value': 1, 'last_value': 0}.
93
        - size_index : int
94
            The index of the dimension to apply the linear function.
95
        - first_value : int or float
96
            The value at the start of the range.
97
        - last_value : int or float
98
            The value at the end of the range.
99
    """
100
    size_index = dict_param['size_index']
×
101
    x = 0 if params_size[size_index]-1 == 0 else indexes[size_index]/(params_size[size_index]-1)
×
102
    return (dict_param['last_value'] - dict_param['first_value']) * x + dict_param['first_value']
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc