Skip to content

Commit

Permalink
Student's t-distribution #256, #238
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuszgromada committed Mar 28, 2022
1 parent 5322454 commit af31d97
Show file tree
Hide file tree
Showing 20 changed files with 2,126 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)Expression.cs 5.0.0 2022-03-21
* @(#)Expression.cs 5.0.0 2022-03-28
*
* You may use this software under the condition of "Simplified BSD License"
*
Expand Down Expand Up @@ -3682,6 +3682,10 @@ private void UDF_PARAM(int pos) {
}
f1SetDecreaseRemove(pos, value );
}
public void RND_STUDENT_T(int pos) {
double v = getTokenValue(pos+1);
f1SetDecreaseRemove(pos, ProbabilityDistributions.rndStudentT(v) );
}
/**
* Logarithm
* Sets tokens to number token
Expand Down Expand Up @@ -3768,6 +3772,21 @@ private void LOG_BETA(int pos) {
double y = getTokenValue(pos+2);
f2SetDecreaseRemove(pos, SpecialFunctions.logBeta(x, y) );
}
private void PDF_STUDENT_T(int pos) {
double x = getTokenValue(pos+1);
double v = getTokenValue(pos+2);
f2SetDecreaseRemove(pos, ProbabilityDistributions.pdfStudentT(x, v) );
}
private void CDF_STUDENT_T(int pos) {
double x = getTokenValue(pos+1);
double v = getTokenValue(pos+2);
f2SetDecreaseRemove(pos, ProbabilityDistributions.cdfStudentT(x, v) );
}
private void QNT_STUDENT_T(int pos) {
double p = getTokenValue(pos+1);
double v = getTokenValue(pos+2);
f2SetDecreaseRemove(pos, ProbabilityDistributions.qntStudentT(p, v) );
}
/**
* Bernoulli Number
*
Expand Down Expand Up @@ -6107,6 +6126,7 @@ private void f1ArgCalc(int pos) {
case Function1Arg.LOG_GAMMA_ID: LOG_GAMMA(pos); break;
case Function1Arg.DI_GAMMA_ID: DI_GAMMA(pos); break;
case Function1Arg.PARAM_ID: UDF_PARAM(pos); break;
case Function1Arg.RND_STUDENT_T_ID: RND_STUDENT_T(pos); break;
}
}
/**
Expand Down Expand Up @@ -6142,6 +6162,9 @@ private void f2ArgCalc(int pos) {
case Function2Arg.PERMUTATIONS_ID: PERMUTATIONS(pos); break;
case Function2Arg.BETA_ID: BETA(pos); break;
case Function2Arg.LOG_BETA_ID: LOG_BETA(pos); break;
case Function2Arg.PDF_STUDENT_T_ID: PDF_STUDENT_T(pos); break;
case Function2Arg.CDF_STUDENT_T_ID: CDF_STUDENT_T(pos); break;
case Function2Arg.QNT_STUDENT_T_ID: QNT_STUDENT_T(pos); break;
}
}
/**
Expand Down Expand Up @@ -6467,6 +6490,7 @@ private void addParserKeyWords() {
addKeyWord(Function1Arg.SGN_GAMMA_STR, Function1Arg.SGN_GAMMA_DESC, Function1Arg.SGN_GAMMA_ID, Function1Arg.SGN_GAMMA_SYN, Function1Arg.SGN_GAMMA_SINCE, Function1Arg.TYPE_ID);
addKeyWord(Function1Arg.LOG_GAMMA_STR, Function1Arg.LOG_GAMMA_DESC, Function1Arg.LOG_GAMMA_ID, Function1Arg.LOG_GAMMA_SYN, Function1Arg.LOG_GAMMA_SINCE, Function1Arg.TYPE_ID);
addKeyWord(Function1Arg.DI_GAMMA_STR, Function1Arg.DI_GAMMA_DESC, Function1Arg.DI_GAMMA_ID, Function1Arg.DI_GAMMA_SYN, Function1Arg.DI_GAMMA_SINCE, Function1Arg.TYPE_ID);
addKeyWord(Function1Arg.RND_STUDENT_T_STR, Function1Arg.RND_STUDENT_T_DESC, Function1Arg.RND_STUDENT_T_ID, Function1Arg.RND_STUDENT_T_SYN, Function1Arg.RND_STUDENT_T_SINCE, Function1Arg.TYPE_ID);
/*
* 2 args functions key words
*/
Expand Down Expand Up @@ -6500,6 +6524,9 @@ private void addParserKeyWords() {
addKeyWord(Function2Arg.PERMUTATIONS_STR, Function2Arg.PERMUTATIONS_DESC, Function2Arg.PERMUTATIONS_ID, Function2Arg.PERMUTATIONS_SYN, Function2Arg.PERMUTATIONS_SINCE, Function2Arg.TYPE_ID);
addKeyWord(Function2Arg.BETA_STR, Function2Arg.BETA_DESC, Function2Arg.BETA_ID, Function2Arg.BETA_SYN, Function2Arg.BETA_SINCE, Function2Arg.TYPE_ID);
addKeyWord(Function2Arg.LOG_BETA_STR, Function2Arg.LOG_BETA_DESC, Function2Arg.LOG_BETA_ID, Function2Arg.LOG_BETA_SYN, Function2Arg.LOG_BETA_SINCE, Function2Arg.TYPE_ID);
addKeyWord(Function2Arg.PDF_STUDENT_T_STR, Function2Arg.PDF_STUDENT_T_DESC, Function2Arg.PDF_STUDENT_T_ID, Function2Arg.PDF_STUDENT_T_SYN, Function2Arg.PDF_STUDENT_T_SINCE, Function2Arg.TYPE_ID);
addKeyWord(Function2Arg.CDF_STUDENT_T_STR, Function2Arg.CDF_STUDENT_T_DESC, Function2Arg.CDF_STUDENT_T_ID, Function2Arg.CDF_STUDENT_T_SYN, Function2Arg.CDF_STUDENT_T_SINCE, Function2Arg.TYPE_ID);
addKeyWord(Function2Arg.QNT_STUDENT_T_STR, Function2Arg.QNT_STUDENT_T_DESC, Function2Arg.QNT_STUDENT_T_ID, Function2Arg.QNT_STUDENT_T_SYN, Function2Arg.QNT_STUDENT_T_SINCE, Function2Arg.TYPE_ID);
/*
* 3 args functions key words
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* @(#)BinaryRelations.cs 4.1.0 2017-06-13
* @(#)BinaryRelations.cs 5.0.0 2022-03-28
*
* You may use this software under the condition of "Simplified BSD License"
*
* Copyright 2010-2019 MARIUSZ GROMADA. All rights reserved.
* Copyright 2010-2022 MARIUSZ GROMADA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
Expand Down Expand Up @@ -76,7 +76,7 @@ namespace org.mariuszgromada.math.mxparser.mathcollection {
* <a href="https://play.google.com/store/apps/details?id=org.mathparser.scalar.pro" target="_blank">Scalar Pro</a><br>
* <a href="http://scalarmath.org/" target="_blank">ScalarMath.org</a><br>
*
* @version 4.1.0
* @version 5.0.0
*/
[CLSCompliant(true)]
public sealed class BinaryRelations {
Expand Down Expand Up @@ -169,6 +169,19 @@ public static double eq(double a, double b) {
} else if (a == b) result = BooleanAlgebra.TRUE;
return result;
}
/**
* Test for equality or almost equality.
*
* @param a First number
* @param b Second number
* @return Returns true if both number are equal or are almost equal.
*
* @see #DEFAULT_COMPARISON_EPSILON
*/
public static bool isEqualOrAlmost(double a, double b) {
if (Math.Abs(a - b) <= BinaryRelations.DEFAULT_COMPARISON_EPSILON) return true;
else return false;
}
/**
* Inequality relation.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* @(#)MathConstants.cs 4.3.4 2019-12-2
* @(#)MathConstants.cs 5.0.0 2022-03-28
*
* You may use this software under the condition of "Simplified BSD License"
*
* Copyright 2010-2019 MARIUSZ GROMADA. All rights reserved.
* Copyright 2010-2022 MARIUSZ GROMADA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
Expand Down Expand Up @@ -76,7 +76,7 @@ namespace org.mariuszgromada.math.mxparser.mathcollection {
* <a href="https://play.google.com/store/apps/details?id=org.mathparser.scalar.pro" target="_blank">Scalar Pro</a><br>
* <a href="http://scalarmath.org/" target="_blank">ScalarMath.org</a><br>
*
* @version 4.3.4
* @version 5.0.0
*/
[CLSCompliant(true)]
public sealed class MathConstants {
Expand All @@ -88,6 +88,10 @@ public sealed class MathConstants {
* Pi/2
*/
public static readonly double PIBY2 = PI / 2.0;
/**
* 1/Pi
*/
public static readonly double PIINV = 1.0 / PI;
/**
* Napier's constant, or Euler's number, base of Natural logarithm
*/
Expand Down Expand Up @@ -308,6 +312,10 @@ public sealed class MathConstants {
* SQRT3BY3
*/
public static readonly double SQRT3BY3 = SQRT3 / 3.0;
/**
* SQRT5
*/
public static readonly double SQRT5 = Math.Sqrt(5.0);
/**
* Not-a-Number
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* @(#)MathFunctions.java 4.4.2 2020-01-25
* @(#)MathFunctions.java 5.0.0 2022-03-28
*
* You may use this software under the condition of "Simplified BSD License"
*
* Copyright 2010-2020 MARIUSZ GROMADA. All rights reserved.
* Copyright 2010-2022 MARIUSZ GROMADA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
Expand Down Expand Up @@ -81,7 +81,7 @@ namespace org.mariuszgromada.math.mxparser.mathcollection {
* <a href="https://play.google.com/store/apps/details?id=org.mathparser.scalar.pro" target="_blank">Scalar Pro</a><br>
* <a href="http://scalarmath.org/" target="_blank">ScalarMath.org</a><br>
*
* @version 4.4.2
* @version 5.0.0
*/
[CLSCompliant(true)]
public sealed class MathFunctions {
Expand Down Expand Up @@ -314,6 +314,45 @@ public static double factorial(double n) {
return Double.NaN;
return factorial( (int)Math.Round(n) );
}
/**
* Falling factorial polynomial
* @param x Argument
* @param n Polynomial degree
* @return Falling factorial polynomial of degree n at point x
*/
public static double factorialFalling(double x, double n){
if (Double.IsNaN(x)) return Double.NaN;
if (Double.IsNaN(n)) return Double.NaN;
if (n < 0) return Double.NaN;
if (BinaryRelations.isEqualOrAlmost(n, 0)) return 1.0;
double k, y;
y = 1;
for (k = 0; k <= n - 1; k = k + 1) {
if (mXparser.isCurrentCalculationCancelled()) return Double.NaN;
y = y * (x - k);
}
return y;
}
/**
* Rising factorial polynomial
* @param x Argument
* @param n Polynomial degree
* @return Rising factorial polynomial of degree n at point x
*/
public static double factorialRising(double x, double n){
if (Double.IsNaN(x)) return Double.NaN;
if (Double.IsNaN(n)) return Double.NaN;
if (n < 0) return Double.NaN;
if (BinaryRelations.isEqualOrAlmost(n, 0)) return 1.0;
double k, y;
y = 1;
for (k = 0; k <= n - 1; k = k + 1) {
if (mXparser.isCurrentCalculationCancelled()) return Double.NaN;
y = y * (x + k);
}
return y;
}

/**
* Generalized binomial coefficient
*
Expand Down
Loading

0 comments on commit af31d97

Please sign in to comment.