# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Test a narrow truncation range.
# Note:
# This is a very narrow truncation.
# The normalised value for the bound [(lower-u)/sd, (upper-u)/sd] is:
# [-1.0101010039621505E-8, 1.0101010129336497E-8]
# Here exp(-0.5*x*x) == 1 and the computation loses precision and variance -> 0

parameters = 7.1, 9.9, 7.0999999, 7.1000001

# scipy computes mean = 7.0999999999999996, var = 1.1358413484763297e-07 (too high)

# Computed using 128-bit quad precision test c++ program using Boost erf for the
# error function with variations on the computation creates values:
mean = 7.10000000000000008881784197001250783
# Variance has different values.
# Wikipedia formula
# 3.33333332242280748659034271839979628e-15
# Alternate formula to avoid cancellation
# 3.33333332242280748952284174437850924e-15
variance = 3.33333332242280748952284174437850924e-15

lower = 7.0999999
upper = 7.1000001

# Computed using Python with SciPy v1.6.0:
# mean, std, clip_a, clip_b = 7.1, 9.9, 7.0999999, 7.1000001
# a, b = (clip_a - mean) / std, (clip_b - mean) / std
# truncnorm.var(a, b, loc=mean, scale=std)

cdf.points = 7.0999999, 7.1, 7.1000001
cdf.values = 0, 0.5, 1
pdf.values = 5000000.00238838, 5000000.00238838, 5000000.00238838
logpdf.values = 15.42494847087604981084, 15.42494847087604981084, 15.42494847087604981084

# Overridden tolerances
# Limited by the computation of variance (which -> 0). Solved with absolute tolerance.
moments.absolute = 1e-14
cdf.relative = 5e-9
sf.relative = 5e-9
pdf.relative = 5e-9
logpdf.relative = 1e-10
