# Author: Mike McKerns (mmckerns @caltech and @uqfoundation) # Copyright (c) 1997-2016 California Institute of Technology. # Copyright (c) 2016-2018 The Uncertainty Quantification Foundation. # License: 3-clause BSD. The full license text is available at: # - https://github.com/uqfoundation/mystic/blob/master/LICENSE import mystic.math.measures as mo from numpy import nan, isnan x = [1, 2, 3, 4, 5] y = [1, 2, 3, 4, 5, 6] z = [1, 5, 5, 5, 5, 5] w = [1, 2, 3, 4, 10] for i in (x, y, z, w): assert mo.moment(i, order=1) == 0.0 assert mo.impose_moment(0.0, i, order=1) == i assert sum(isnan(mo.impose_moment(5.0, i, order=1))) == len(i) assert mo.impose_moment(0.0, i, order=2) == [mo.mean(i)] * len(i) assert sum(isnan(mo.impose_moment(5.0, i, order=2))) == 0 assert mo.impose_moment(0.0, i, order=3) == [mo.mean(i)] * len(i) assert sum(isnan(mo.impose_moment(5.0, i, order=3))) == 0 assert sum(isnan(mo.impose_moment(5.0, x, order=3, skew=False))) == len(x) assert sum(isnan(mo.impose_moment(5.0, y, order=3, skew=False))) == 0 #XXX? assert sum(isnan(mo.impose_moment(5.0, z, order=3, skew=False))) == 0 assert sum(isnan(mo.impose_moment(5.0, w, order=3, skew=False))) == 0 for i in (x, y, z, w): tol = 1e-12 _i = [max(i) + min(i) - j for j in i] assert mo.moment(i, order=3) + mo.moment(_i, order=3) <= tol
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation) # Copyright (c) 1997-2016 California Institute of Technology. # Copyright (c) 2016-2017 The Uncertainty Quantification Foundation. # License: 3-clause BSD. The full license text is available at: # - https://github.com/uqfoundation/mystic/blob/master/LICENSE import mystic.math.measures as mo from numpy import nan, isnan x = [1,2,3,4,5] y = [1,2,3,4,5,6] z = [1,5,5,5,5,5] w = [1,2,3,4,10] for i in (x,y,z,w): assert mo.moment(i, order=1) == 0.0 assert mo.impose_moment(0.0, i, order=1) == i assert sum(isnan(mo.impose_moment(5.0, i, order=1))) == len(i) assert mo.impose_moment(0.0, i, order=2) == [mo.mean(i)]*len(i) assert sum(isnan(mo.impose_moment(5.0, i, order=2))) == 0 assert mo.impose_moment(0.0, i, order=3) == [mo.mean(i)]*len(i) assert sum(isnan(mo.impose_moment(5.0, i, order=3))) == 0 assert sum(isnan(mo.impose_moment(5.0, x, order=3, skew=False))) == len(x) assert sum(isnan(mo.impose_moment(5.0, y, order=3, skew=False))) == 0 #XXX? assert sum(isnan(mo.impose_moment(5.0, z, order=3, skew=False))) == 0 assert sum(isnan(mo.impose_moment(5.0, w, order=3, skew=False))) == 0 for i in (x,y,z,w): tol = 1e-12 _i = [max(i)+min(i)-j for j in i] assert mo.moment(i, order=3) + mo.moment(_i, order=3) <= tol