LCOV - code coverage report
Current view: top level - src/distributions - FDistribution.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: #32971 (54bef8) with base c6cf66 Lines: 40 41 97.6 %
Date: 2026-05-29 20:40:35 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #include "FDistribution.h"
      11             : #include "Beta.h"
      12             : 
      13             : registerMooseObject("StochasticToolsApp", FDistribution);
      14             : 
      15             : InputParameters
      16          14 : FDistribution::validParams()
      17             : {
      18          14 :   InputParameters params = Distribution::validParams();
      19          14 :   params.addClassDescription("F-distribution or Fisher-Snedecor distribution");
      20          28 :   params.addRequiredRangeCheckedParam<unsigned int>("df1", "df1 > 0", "Degrees of freedom 1.");
      21          28 :   params.addRequiredRangeCheckedParam<unsigned int>("df2", "df2 > 0", "Degrees of freedom 2.");
      22          14 :   return params;
      23           0 : }
      24             : 
      25           7 : FDistribution::FDistribution(const InputParameters & parameters)
      26             :   : Distribution(parameters),
      27           7 :     _df1(getParam<unsigned int>("df1")),
      28          21 :     _df2(getParam<unsigned int>("df2"))
      29             : {
      30           7 : }
      31             : 
      32             : Real
      33          14 : FDistribution::pdf(const Real & x, const unsigned int & df1, const unsigned int & df2)
      34             : {
      35             :   // Handy definitions
      36          14 :   Real d1 = static_cast<Real>(df1);
      37          14 :   Real d2 = static_cast<Real>(df2);
      38          14 :   Real d1x = d1 * x;
      39          14 :   Real d2pd1x = d2 + d1x;
      40             : 
      41             :   Real a;
      42             :   Real b;
      43             :   Real y;
      44             :   Real z;
      45          14 :   if (d1 * x > d2)
      46             :   {
      47           7 :     a = d2 / 2.0;
      48           7 :     b = d1 / 2.0;
      49           7 :     y = (d2 * d1) / (d2pd1x * d2pd1x);
      50           7 :     z = d2 / d2pd1x;
      51             :   }
      52             :   else
      53             :   {
      54           7 :     a = d1 / 2.0;
      55           7 :     b = d2 / 2.0;
      56           7 :     y = (d2pd1x * d1 - d1x * d1) / (d2pd1x * d2pd1x);
      57           7 :     z = d1x / d2pd1x;
      58             :   }
      59             : 
      60          14 :   return y * Beta::pdf(z, a, b);
      61             : }
      62             : 
      63             : Real
      64           7 : FDistribution::cdf(const Real & x, const unsigned int & df1, const unsigned int & df2)
      65             : {
      66             :   // Handy definitions
      67           7 :   Real d1 = static_cast<Real>(df1);
      68           7 :   Real d2 = static_cast<Real>(df2);
      69             : 
      70           7 :   return Beta::incompleteBeta(d1 / 2.0, d2 / 2.0, d1 * x / (d1 * x + d2));
      71             : }
      72             : 
      73             : Real
      74           7 : FDistribution::quantile(const Real & p, const unsigned int & df1, const unsigned int & df2)
      75             : {
      76             :   // Handy definitions
      77           7 :   Real d1 = static_cast<Real>(df1);
      78           7 :   Real d2 = static_cast<Real>(df2);
      79             : 
      80           7 :   Real z = Beta::incompleteBetaInv(d1 / 2.0, d2 / 2.0, p);
      81           7 :   return d2 * z / d1 / (1.0 - z);
      82             : }
      83             : 
      84             : Real
      85          14 : FDistribution::pdf(const Real & x) const
      86             : {
      87          14 :   return pdf(x, _df1, _df2);
      88             : }
      89             : 
      90             : Real
      91           7 : FDistribution::cdf(const Real & x) const
      92             : {
      93           7 :   return cdf(x, _df1, _df2);
      94             : }
      95             : 
      96             : Real
      97           7 : FDistribution::quantile(const Real & p) const
      98             : {
      99           7 :   return quantile(p, _df1, _df2);
     100             : }

Generated by: LCOV version 1.14