Skip to content

Commit 99ac036

Browse files
authored
Dev/start5 (#67)
* Change to .NET Standard 2.0. Make structs readonly. Start to rip out statistics container classes. Add ChebyshevU. Add Benford and SkewNormal distributions. * Beta use unit interval. no Sample, and other cleanup. * Many mostly small improvements to accuracy and added tests.
1 parent f18eb8d commit 99ac036

File tree

137 files changed

+206367
-5308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+206367
-5308
lines changed

Numerics/Analysis/EvaluationSettings.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
namespace Meta.Numerics.Analysis {
66

77
/// <summary>
8-
/// Contains settings governing the evaluation of a function.
8+
/// Contains settings governing the evaluation of a function by a solver.
99
/// </summary>
1010
/// <remarks>
1111
/// <para>Negative values of <see cref="EvaluationBudget"/>,
1212
/// <see cref="RelativePrecision"/>, and <see cref="AbsolutePrecision"/>
13-
/// indicate that the analysis method should use its defaults for
14-
/// that property. Override the default for a property by
13+
/// indicate that the solver method should use its defaults for
14+
/// that property. You can override the default for a property by
1515
/// setting it explicitly. If you set values for some properties
1616
/// but not others, your setting will be applied to the property
1717
/// you set and the others will use defaults.</para>
18-
/// <para>When an analysis method returns an <see cref="EvaluationResult"/>
19-
/// object, its evaluation setting object will contain the specific
18+
/// <para>When a solver method returns an <see cref="EvaluationResult"/>,
19+
/// its evaluation setting object will contain the specific
2020
/// settings used, so you can see which default values were applied.</para>
2121
/// </remarks>
2222
public class EvaluationSettings {

Numerics/Analysis/FunctionMath.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ namespace Meta.Numerics.Analysis {
1717
/// </remarks>
1818
public static partial class FunctionMath {
1919

20-
// logic for finding function points is in other classes
21-
22-
private static readonly double AbsolutePrecision = Math.Pow(2.0, -192);
2320

2421
}
2522

Numerics/Analysis/FunctionMath_Extrema.cs

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static Extremum FindMaximum (Func<double, double> f, double x) {
7272
public static Extremum FindMaximum (Func<double, double> f, double x, ExtremumSettings settings) {
7373
if (f == null) throw new ArgumentNullException(nameof(f));
7474
if (settings == null) throw new ArgumentNullException(nameof(settings));
75-
return (FindMinimum(new Functor(f, true), x, settings).Negate());
75+
return (FindMinimum(new Functor(u => -f(u)), x, settings).Negate());
7676
}
7777

7878
/// <summary>
@@ -216,7 +216,7 @@ public static Extremum FindMaximum (Func<double, double> f, Interval r) {
216216
public static Extremum FindMaximum (Func<double, double> f, Interval r, ExtremumSettings settings) {
217217
if (f == null) throw new ArgumentNullException(nameof(f));
218218
if (settings == null) throw new ArgumentNullException(nameof(settings));
219-
return (FindMinimum(new Functor(f, true), r.LeftEndpoint, r.RightEndpoint, settings).Negate());
219+
return (FindMinimum(new Functor(x => -f(x)), r.LeftEndpoint, r.RightEndpoint, settings).Negate());
220220
}
221221

222222
/// <summary>
@@ -482,34 +482,6 @@ private static void ParabolicFit (
482482
}
483483

484484

485-
// This class is used to wrap a function, storing some associated state such as the evaluation count.
486-
// It isn't truly a functor in the C++ sense, since .NET doesn't allow () to be overloaded, but
487-
// it is a functor in the sense that it is a class used to represent a function.
488-
489-
internal class Functor {
490-
491-
public Functor (Func<double, double> f) : this(f, false) {}
492-
493-
public Functor (Func<double, double> f, bool negate) {
494-
Function = f;
495-
Negate = negate;
496-
}
497-
498-
public Func<double, double> Function { get; protected set; }
499-
500-
public int EvaluationCount { get; protected set; }
501-
502-
public bool Negate { get; set; }
503-
504-
public virtual double Evaluate (double x) {
505-
506-
double f = Function(x);
507-
if (Negate) f = -f;
508-
EvaluationCount++;
509-
return (f);
510-
511-
}
512-
513-
}
485+
514486

515487
}

Numerics/Analysis/FunctionMath_Integrate.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static partial class FunctionMath {
2828
/// </remarks>
2929
public static IntegrationResult Integrate(Func<double, double> integrand, double start, double end) {
3030
IntegrationSettings settings = new IntegrationSettings();
31-
return (Integrate(integrand, start, end, settings));
31+
return Integrate(integrand, start, end, settings);
3232
}
3333

3434
/// <summary>
@@ -50,7 +50,7 @@ public static IntegrationResult Integrate(Func<double, double> integrand, double
5050
/// </remarks>
5151
public static IntegrationResult Integrate (Func<double, double> integrand, Interval range) {
5252
IntegrationSettings settings = new IntegrationSettings();
53-
return (Integrate(integrand, range, settings));
53+
return Integrate(integrand, range, settings);
5454
}
5555

5656
internal static IntegrationSettings SetIntegrationDefaults (IntegrationSettings settings) {
@@ -76,7 +76,7 @@ internal static IntegrationSettings SetIntegrationDefaults (IntegrationSettings
7676
/// <para>For information, see <see cref="Integrate(Func{double, double}, double, double, IntegrationSettings)"/>.</para>
7777
/// </remarks>
7878
public static IntegrationResult Integrate (Func<double, double> integrand, Interval range, IntegrationSettings settings) {
79-
return (Integrate(integrand, range.LeftEndpoint, range.RightEndpoint, settings));
79+
return Integrate(integrand, range.LeftEndpoint, range.RightEndpoint, settings);
8080
}
8181

8282
/// <summary>
@@ -117,8 +117,8 @@ public static IntegrationResult Integrate (Func<double, double> integrand, Inter
117117
/// could be determined to the required precision.</exception>
118118
public static IntegrationResult Integrate (Func<double,double> integrand, double start, double end, IntegrationSettings settings) {
119119

120-
if (integrand == null) throw new ArgumentNullException(nameof(integrand));
121-
if (settings == null) throw new ArgumentNullException(nameof(settings));
120+
if (integrand is null) throw new ArgumentNullException(nameof(integrand));
121+
if (settings is null) throw new ArgumentNullException(nameof(settings));
122122

123123
// Deal with right-to-left integrals
124124
if (end < start) {
@@ -130,29 +130,29 @@ public static IntegrationResult Integrate (Func<double,double> integrand, double
130130
if (Double.IsNegativeInfinity(start) && Double.IsPositiveInfinity(end)) {
131131
// -\infty to +\infty
132132
// remap to (-\pi/2,\pi/2)
133-
Func<double, double> f1 = delegate (double t) {
133+
Func<double, double> f1 = (double t) => {
134134
double x = Math.Tan(t);
135-
return (integrand(x) * (1.0 + x * x));
135+
return integrand(x) * (1.0 + x * x);
136136
};
137-
return (Integrate(f1, -Global.HalfPI, +Global.HalfPI, settings));
137+
return Integrate(f1, -Math.PI / 2.0, +Math.PI / 2.0, settings);
138138
} else if (Double.IsPositiveInfinity(end)) {
139139
// finite to +\infty
140140
// remap to interval (-1,1)
141-
Func<double, double> f1 = delegate (double t) {
141+
Func<double, double> f1 = (double t) => {
142142
double q = 1.0 / (1.0 - t);
143143
double x = start + (1.0 + t) * q;
144-
return (integrand(x) * 2.0 * q * q);
144+
return integrand(x) * 2.0 * q * q;
145145
};
146-
return (Integrate(f1, -1.0, +1.0, settings));
146+
return Integrate(f1, -1.0, +1.0, settings);
147147
} else if (Double.IsNegativeInfinity(start)) {
148148
// -\infty to finite
149149
// remap to interval (-1,1)
150-
Func<double, double> f1 = delegate (double t) {
150+
Func<double, double> f1 = (double t) => {
151151
double q = t + 1.0;
152152
double x = end + (t - 1.0) / q;
153-
return(integrand(x) * (2.0 / q / q));
153+
return integrand(x) * (2.0 / q / q);
154154
};
155-
return(Integrate(f1, -1.0, +1.0, settings));
155+
return Integrate(f1, -1.0, +1.0, settings);
156156
}
157157

158158
// Fix settings.
@@ -162,7 +162,7 @@ public static IntegrationResult Integrate (Func<double,double> integrand, double
162162
Debug.Assert(end >= start);
163163
IAdaptiveIntegrator integrator = new GaussKronrodIntegrator(integrand, Interval.FromEndpoints(start, end));
164164
IntegrationResult result = Integrate_Adaptive(integrator, settings);
165-
return (result);
165+
return result;
166166
}
167167

168168
// the drivers

0 commit comments

Comments
 (0)