Skip to content

Commit 886d666

Browse files
committed
Fix truncated statistical distributions
- When a statistical distribution is truncated using the 'from' and 'to' arguments, it is now made sure that it retains the same mean value. - Fixed other bug.
1 parent c5fcf12 commit 886d666

File tree

7 files changed

+98
-93
lines changed

7 files changed

+98
-93
lines changed

VERSIONS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
New in 4.5.1-1 (12 Sep 2022):
1+
New in 4.5.1-2 (11 Oct 2022):
22
- documentation: made minor improvement.
3+
- fixed truncated statistical distributions (from and to).
34

45
New in 4.5.0 (07 Sep 2022):
56
- module -T: fixed -morpho cube, added -statcell and -statvox

doc/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import sphinx_rtd_theme
1212

1313
project = u'Neper'
14-
version = u'4.5.1-1'
15-
release = u'4.5.1-1'
14+
version = u'4.5.1-2'
15+
release = u'4.5.1-2'
1616
author = u'Romain Quey'
1717
copyright = u'Romain Quey'
1818
language = 'en'

doc/exprskeys.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ The following table lists the statistical distributions. Custom endpoints (not
107107
:data:`custom(<file_name>)` custom
108108
============================================= ==================== ======================================
109109

110-
:data:`mean` represents the mean (or centre), and :data:`sigma` represents the standard deviation (or scale, :math:`> 0`). :data:`gamma` depends on the distribution function (see the above table). For all distributions, custom endpoints can be added as last arguments, as :data:`<from_value>,\<to_value\>`, where :data:`from_value` is the lower endpoint and :data:`to_value` is the upper endpoint. The parameter keywords do not need to be provided, but, when they are, the parameters can be given in any order, as in :data:`moffat(gamma=1,from=0,to=1,sigma=0.1,mean=0.5)`. Endpoints are considered inclusive by default, but exclusive endpoints can be specified using :data:`fromexclusive=\<from_value\>` and :data:`toexclusive=\<to_value\>` (:data:`frominclusive=\<from_value\>` and :data:`toinclusive=\<to_value\>` can be used for inclusive endpoints). String completion is available for the keywords. Finally, a sum of distributions of increasing averages can be provided, as in :data:`0.3*lognormal(0.5,0.1)+0.7*normal(1,0.1)`.
110+
:data:`<mean>` represents the mean (or centre), and :data:`<sigma>` represents the standard deviation (or scale, :math:`> 0`). :data:`<gamma>` depends on the distribution function (see the above table). For all distributions, custom endpoints can be added as last arguments, as :data:`<from_value>,\<to_value\>`, where :data:`<from_value>` is the lower endpoint and :data:`<to_value>` is the upper endpoint. The parameter keywords do not need to be provided, but, when they are, the parameters can be given in any order, as in :data:`moffat(gamma=1,from=0,to=1,sigma=0.1,mean=0.5)`. Endpoints are considered inclusive by default, but exclusive endpoints can be specified using :data:`fromexclusive=\<from_value\>` and :data:`toexclusive=\<to_value\>` (:data:`frominclusive=\<from_value\>` and :data:`toinclusive=\<to_value\>` can be used for inclusive endpoints). String completion is available for the keywords. Finally, a sum of distributions of increasing averages can be provided, as in :data:`0.3*lognormal(0.5,0.1)+0.7*normal(1,0.1)`.
111+
112+
.. attention:: When :data:`from` and/or :data:`to` are used, they should preferably be so that the distribution retains the same mean; otherwise, the distribution is shifted after truncation to match the specified mean.
111113

112114
In the case of the :data:`custom` distribution, the numerical distribution must be provided in the file. The file must contain the x and y values of the distribution on successive lines. The x values must be provided in ascending order and form a regular grid. The distribution must contain at least 3 points and does not need to integrate to 1.
113115

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if(POLICY CMP0077)
77
cmake_policy(SET CMP0077 NEW)
88
endif()
99

10-
set(NEPER_VERSION \"4.5.1-1\")
10+
set(NEPER_VERSION \"4.5.1-2\")
1111
project(neper)
1212

1313
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8.1)

src/contrib/ut/src/ut_fct/ut_fct.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,13 @@ ut_fct_numericalfct (struct FCT Fct, double min, double max, int size,
560560
sum += ut_fct_binwidth (*pFct2, i) * (*pFct2).y[i];
561561
}
562562
ut_array_1d_scale ((*pFct2).y, (*pFct2).size, FctC.area / sum);
563+
564+
double xmean = 0;
565+
for (i = 0; i < (*pFct2).size; i++)
566+
xmean += (*pFct2).x[i] * (*pFct2).y[i] * ut_fct_binwidth (*pFct2, i);
567+
568+
// it is necessary to fix the distribution when (unbalanced) from and to bounds are specified
569+
ut_array_1d_addval ((*pFct2).x, (*pFct2).size, (*pFct2).mean - xmean, (*pFct2).x);
563570
}
564571

565572
(*pFct2).interp_type = (gsl_interp_type *) gsl_interp_cspline;

src/neper_t/net_tess/net_tess_opt/net_tess_opt_init/net_tess_opt_init2.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ net_tess_opt_init_target (struct IN_T In, struct MTESS MTess,
317317
}
318318

319319
Fct[j].sigma /= mean;
320+
Fct[j].from /= mean;
321+
Fct[j].to /= mean;
320322
}
321323
}
322324

tests/T/morphooptiobj_ad/ref.tess

Lines changed: 81 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -8,164 +8,157 @@
88
*crysym
99
triclinic
1010
*seed
11-
1 0.637316633924 0.339809602352 0.159391794127 0.492372510921
11+
1 0.489604880648 0.290572351259 0.159391794127 0.492372510921
1212
2 0.452028974213 0.195589598124 0.501814614272 0.492372510921
1313
*ori
1414
rodrigues:active
1515
-2.444015198417 0.618305125773 2.829029762200
1616
0.441042954395 0.731096527047 -0.307369633254
1717
**vertex
18-
13
19-
1 1.000000000000 0.000000000000 0.000000000000 0
20-
2 1.000000000000 1.000000000000 0.000000000000 0
21-
3 0.000000000000 1.000000000000 0.000000000000 0
22-
4 -0.000000000000 0.182517711481 -0.000000000000 0
23-
5 -0.000000000000 1.000000000000 0.344303277031 0
24-
6 1.000000000000 1.000000000000 0.885411079464 0
25-
7 1.000000000000 -0.000000000000 0.464235866415 0
26-
8 0.142063994776 -0.000000000000 -0.000000000000 0
27-
9 0.000000000000 0.000000000000 0.000000000000 0
28-
10 0.000000000000 0.000000000000 1.000000000000 0
29-
11 0.000000000000 1.000000000000 1.000000000000 0
30-
12 1.000000000000 1.000000000000 1.000000000000 0
31-
13 1.000000000000 0.000000000000 1.000000000000 0
18+
12
19+
1 0.000000000000 0.000000000000 0.000000000000 0
20+
2 1.000000000000 0.000000000000 0.000000000000 0
21+
3 1.000000000000 1.000000000000 0.000000000000 0
22+
4 0.000000000000 1.000000000000 0.000000000000 0
23+
5 -0.000000000000 -0.000000000000 0.211511044960 0
24+
6 -0.000000000000 1.000000000000 0.488895458461 0
25+
7 1.000000000000 1.000000000000 0.598630862249 0
26+
8 1.000000000000 -0.000000000000 0.321246448748 0
27+
9 0.000000000000 0.000000000000 1.000000000000 0
28+
10 0.000000000000 1.000000000000 1.000000000000 0
29+
11 1.000000000000 1.000000000000 1.000000000000 0
30+
12 1.000000000000 0.000000000000 1.000000000000 0
3231
**edge
33-
22
34-
1 3 4 0
35-
2 4 5 0
36-
3 5 3 0
37-
4 1 2 0
38-
5 2 6 0
39-
6 6 7 0
40-
7 7 1 0
41-
8 7 8 0
42-
9 8 1 0
43-
10 2 3 0
44-
11 5 6 0
45-
12 8 4 0
32+
20
33+
1 4 1 0
34+
2 1 5 0
35+
3 5 6 0
36+
4 6 4 0
37+
5 2 3 0
38+
6 3 7 0
39+
7 7 8 0
40+
8 8 2 0
41+
9 1 2 0
42+
10 8 5 0
43+
11 3 4 0
44+
12 6 7 0
4645
13 9 10 0
47-
14 10 11 0
48-
15 11 5 0
49-
16 4 9 0
50-
17 12 13 0
51-
18 13 7 0
52-
19 6 12 0
53-
20 13 10 0
54-
21 9 8 0
55-
22 11 12 0
46+
14 10 6 0
47+
15 5 9 0
48+
16 11 12 0
49+
17 12 8 0
50+
18 7 11 0
51+
19 12 9 0
52+
20 10 11 0
5653
**face
57-
12
58-
1 3 3 4 5
59-
3 1 2 3
54+
11
55+
1 4 4 1 5 6
56+
4 1 2 3 4
6057
-0.000000000000 -1.000000000000 -0.000000000000 -0.000000000000
6158
0 0 0.000000000000 0.000000000000 0.000000000000
62-
2 4 1 2 6 7
63-
4 4 5 6 7
59+
2 4 2 3 7 8
60+
4 5 6 7 8
6461
1.000000000000 1.000000000000 0.000000000000 0.000000000000
6562
0 0 0.000000000000 0.000000000000 0.000000000000
66-
3 3 1 7 8
67-
3 -7 8 9
63+
3 4 1 2 8 5
64+
4 9 -8 10 -2
6865
-0.000000000000 -0.000000000000 -1.000000000000 -0.000000000000
6966
0 0 0.000000000000 0.000000000000 0.000000000000
70-
4 4 2 3 5 6
71-
4 10 -3 11 -5
67+
4 4 3 4 6 7
68+
4 11 -4 12 -6
7269
1.000000000000 0.000000000000 1.000000000000 0.000000000000
7370
0 0 0.000000000000 0.000000000000 0.000000000000
74-
5 5 3 2 1 8 4
75-
5 -10 -4 -9 12 -1
71+
5 4 4 3 2 1
72+
4 -11 -5 -9 -1
7673
-0.000000000000 -0.000000000000 -0.000000000000 -1.000000000000
7774
0 0 0.000000000000 0.000000000000 0.000000000000
78-
6 5 4 5 6 7 8
79-
5 2 11 6 8 12
80-
0.063398888782 0.446269928439 0.347357460644 -0.824733863441
75+
6 4 5 6 7 8
76+
4 3 12 7 10
77+
-0.202685325651 0.105156475665 0.265809996786 -0.958273009760
8178
0 0 0.000000000000 0.000000000000 0.000000000000
82-
7 5 9 10 11 5 4
83-
5 13 14 15 -2 16
79+
7 4 9 10 6 5
80+
4 13 14 -3 15
8481
-0.000000000000 -1.000000000000 -0.000000000000 -0.000000000000
8582
0 0 0.000000000000 0.000000000000 0.000000000000
86-
8 4 12 13 7 6
87-
4 17 18 -6 19
83+
8 4 11 12 8 7
84+
4 16 17 -7 18
8885
1.000000000000 1.000000000000 0.000000000000 0.000000000000
8986
0 0 0.000000000000 0.000000000000 0.000000000000
90-
9 5 13 10 9 8 7
91-
5 20 -13 21 -8 -18
87+
9 4 12 9 5 8
88+
4 19 -15 -10 -17
9289
-0.000000000000 -0.000000000000 -1.000000000000 -0.000000000000
9390
0 0 0.000000000000 0.000000000000 0.000000000000
94-
10 4 11 12 6 5
95-
4 22 -19 -11 -15
91+
10 4 10 11 7 6
92+
4 20 -18 -12 -14
9693
1.000000000000 0.000000000000 1.000000000000 0.000000000000
9794
0 0 0.000000000000 0.000000000000 0.000000000000
98-
11 3 9 4 8
99-
3 -16 -12 -21
100-
-0.000000000000 -0.000000000000 -0.000000000000 -1.000000000000
101-
0 0 0.000000000000 0.000000000000 0.000000000000
102-
12 4 13 12 11 10
103-
4 -17 -22 -14 -20
95+
11 4 12 11 10 9
96+
4 -16 -20 -13 -19
10497
1.000000000000 0.000000000000 0.000000000000 1.000000000000
10598
0 0 0.000000000000 0.000000000000 0.000000000000
10699
**polyhedron
107100
2
108101
1 6 1 2 3 4 5 -6
109-
2 7 7 8 9 10 11 12 6
102+
2 6 7 8 9 10 11 6
110103
**domain
111104
*general
112105
cube
113106
*vertex
114107
8
115108
1 0.000000000000 0.000000000000 0.000000000000 x0y0z0
116-
1 9
117-
2 1.000000000000 0.000000000000 0.000000000000 x1y0z0
118109
1 1
119-
3 1.000000000000 1.000000000000 0.000000000000 x1y1z0
110+
2 1.000000000000 0.000000000000 0.000000000000 x1y0z0
120111
1 2
121-
4 0.000000000000 1.000000000000 0.000000000000 x0y1z0
112+
3 1.000000000000 1.000000000000 0.000000000000 x1y1z0
122113
1 3
114+
4 0.000000000000 1.000000000000 0.000000000000 x0y1z0
115+
1 4
123116
5 0.000000000000 0.000000000000 1.000000000000 x0y0z1
124-
1 10
117+
1 9
125118
6 0.000000000000 1.000000000000 1.000000000000 x0y1z1
126-
1 11
119+
1 10
127120
7 1.000000000000 1.000000000000 1.000000000000 x1y1z1
128-
1 12
121+
1 11
129122
8 1.000000000000 0.000000000000 1.000000000000 x1y0z1
130-
1 13
123+
1 12
131124
*edge
132125
12
133126
1 2 4 6
134127
x0y1
135-
2 3 15
128+
2 4 14
136129
2 2 6 5
137130
x0z1
138-
1 14
131+
1 13
139132
3 2 5 1
140133
x0y0
141-
1 13
134+
2 2 15
142135
4 2 1 4
143136
x0z0
144-
2 1 16
137+
1 1
145138
5 2 2 8
146139
x1y0
147-
2 7 18
140+
2 8 17
148141
6 2 8 7
149142
x1z1
150-
1 17
143+
1 16
151144
7 2 7 3
152145
x1y1
153-
2 5 19
146+
2 6 18
154147
8 2 3 2
155148
x1z0
156-
1 4
149+
1 5
157150
9 2 5 8
158151
y0z1
159-
1 20
152+
1 19
160153
10 2 2 1
161154
y0z0
162-
2 9 21
155+
1 9
163156
11 2 4 3
164157
y1z0
165-
1 10
158+
1 11
166159
12 2 7 6
167160
y1z1
168-
1 22
161+
1 20
169162
*face
170163
6
171164
1 4 4 6 5 1
@@ -197,11 +190,11 @@
197190
plane
198191
4 0.000000000000 0.000000000000 0.000000000000 1.000000000000
199192
z0
200-
2 5 11
193+
1 5
201194
6 4 5 6 7 8
202195
4 2 12 6 9
203196
plane
204197
4 -1.000000000000 -0.000000000000 -0.000000000000 -1.000000000000
205198
z1
206-
1 12
199+
1 11
207200
***end

0 commit comments

Comments
 (0)