Skip to content

Commit c636841

Browse files
authored
Merge pull request #32 from dcwuser/dcwuser/dataAdaptation
Dcwuser/data adaptation
2 parents a2d5e49 + a9dcb11 commit c636841

File tree

78 files changed

+1304
-897
lines changed

Some content is hidden

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

78 files changed

+1304
-897
lines changed

Examples/project.fragment.lock.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"type": "project",
66
"framework": ".NETFramework,Version=v4.0",
77
"compile": {
8-
"bin/Release/Meta.Numerics.dll": {}
8+
"bin/Debug/Meta.Numerics.dll": {}
99
},
1010
"runtime": {
11-
"bin/Release/Meta.Numerics.dll": {}
11+
"bin/Debug/Meta.Numerics.dll": {}
1212
},
1313
"contentFiles": {
14-
"bin/Release/Meta.Numerics.pdb": {
14+
"bin/Debug/Meta.Numerics.pdb": {
1515
"buildAction": "None",
1616
"codeLanguage": "any",
1717
"copyToOutput": true

Numerics/Analysis/FunctionMath_Odes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public static OdeResult IntegrateOde (Func<double, double, double> rhs, double x
117117
/// the common case where the independent variable is time, but the algorithm works whether the independent variable
118118
/// resents a time, a location, or a completely non-physical quantity, as long as the problem has the form of an ODE.</para>
119119
/// <para>ODEs involving multiple, coupled dependent variables can be integrated using the
120-
/// <see cref="MultiFunctionMath.IntegrateOde(Func{double, IList{double}, IList{double}}, double, IList{double}, double, MultiOdeSettings)"/>
120+
/// <see cref="MultiFunctionMath.IntegrateOde(Func{double, IReadOnlyList{double}, IReadOnlyList{double}}, double, IReadOnlyList{double}, double, MultiOdeSettings)"/>
121121
/// method. Higher order ODEs can be integrated by representing them as coupled ODEs in which the zeroth component
122122
/// is the desired y, the first component is y', the second component is y'', etc. So-called conservative second order
123123
/// ODEs should be integrated using the

Numerics/Analysis/MultiFunctionMath_Extrema_ModelTrust.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -744,19 +744,4 @@ public double FindMinimumSeperation () {
744744

745745
}
746746

747-
// IList defines CopyTo. IReadOnlyList doesn't. So in order to switch from IList to IReadOnlyList,
748-
// we define an extension method to implement it.
749-
750-
internal static class CopyHelper {
751-
752-
public static void CopyTo<T> (this IReadOnlyList<T> source, T[] target, int startIndex) {
753-
Debug.Assert(source != null);
754-
Debug.Assert(target != null);
755-
Debug.Assert(startIndex >= 0);
756-
for (int i = 0; i < source.Count; i++) {
757-
target[startIndex + i] = source[i];
758-
}
759-
}
760-
761-
}
762747
}

Numerics/Analysis/MultiFunctionMath_Ode.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static partial class MultiFunctionMath {
2121
/// <returns>The solution, including the final value of the functions and their derivatives.</returns>
2222
/// <remarks>
2323
/// <para>For information on integrating coupled, conservative ODEs, see
24-
/// <see cref="IntegrateConservativeOde(Func{double, IList{double}, IList{double}}, double, IList{double}, IList{double}, double, MultiOdeSettings)"/>.</para>
24+
/// <see cref="IntegrateConservativeOde(Func{double, IReadOnlyList{double}, IReadOnlyList{double}}, double, IReadOnlyList{double}, IReadOnlyList{double}, double, MultiOdeSettings)"/>.</para>
2525
/// <para>This overload uses default settings for precision and evaluation budget. It targets a relative precision of
2626
/// about 10<sup>-12</sup> and an absolute precision of about 10<sup>-24</sup> with an evaluation budget of about 8000.
2727
/// </para>
@@ -32,7 +32,7 @@ public static partial class MultiFunctionMath {
3232
/// dimension.</exception>
3333
/// <exception cref="NonconvergenceException">The ODE could not be integrated to the required precision before exhausting
3434
/// the maximum allowed number of <paramref name="rhs"/>evaluations.</exception>
35-
public static MultiOdeResult IntegrateConservativeOde (Func<double, IList<double>, IList<double>> rhs, double x0, IList<double> y0, IList<double> yPrime0, double x1) {
35+
public static MultiOdeResult IntegrateConservativeOde (Func<double, IReadOnlyList<double>, IReadOnlyList<double>> rhs, double x0, IReadOnlyList<double> y0, IReadOnlyList<double> yPrime0, double x1) {
3636
return (IntegrateConservativeOde(rhs, x0, y0, yPrime0, x1, new MultiOdeSettings()));
3737
}
3838

@@ -55,7 +55,7 @@ public static MultiOdeResult IntegrateConservativeOde (Func<double, IList<double
5555
/// <remarks>
5656
/// <para>For information on conservative ODEs, see <see cref="FunctionMath.IntegrateConservativeOde(Func{double, double, double}, double, double, double, double, OdeSettings)"/>.</para>
5757
/// </remarks>
58-
public static MultiOdeResult IntegrateConservativeOde (Func<double, IList<double>, IList<double>> rhs, double x0, IList<double> y0, IList<double> yPrime0, double x1, MultiOdeSettings settings) {
58+
public static MultiOdeResult IntegrateConservativeOde (Func<double, IReadOnlyList<double>, IReadOnlyList<double>> rhs, double x0, IReadOnlyList<double> y0, IReadOnlyList<double> yPrime0, double x1, MultiOdeSettings settings) {
5959

6060
if (rhs == null) throw new ArgumentNullException(nameof(rhs));
6161
if (y0 == null) throw new ArgumentNullException(nameof(y0));
@@ -86,12 +86,12 @@ public static MultiOdeResult IntegrateConservativeOde (Func<double, IList<double
8686
/// the maximum allowed number of <paramref name="rhs"/> evaluations.</exception>
8787
/// <remarks>
8888
/// <para>For information about integrating coupled ODEs, see
89-
/// <see cref="IntegrateOde(Func{double, IList{double}, IList{double}}, double, IList{double}, double, MultiOdeSettings)"/>.</para>
89+
/// <see cref="IntegrateOde(Func{double, IReadOnlyList{double}, IReadOnlyList{double}}, double, IReadOnlyList{double}, double, MultiOdeSettings)"/>.</para>
9090
/// <para>This overload uses default settings for precision and evaluation budget. It targets a relative precision of
9191
/// about 10<sup>-12</sup> and an absolute precision of about 10<sup>-24</sup> with an evaluation budget of about 8000.
9292
/// </para>
9393
/// </remarks>
94-
public static MultiOdeResult IntegrateOde (Func<double, IList<double>, IList<double>> rhs, double x0, IList<double> y0, double x1) {
94+
public static MultiOdeResult IntegrateOde (Func<double, IReadOnlyList<double>, IReadOnlyList<double>> rhs, double x0, IReadOnlyList<double> y0, double x1) {
9595
return (IntegrateOde(rhs, x0, y0, x1, new MultiOdeSettings()));
9696
}
9797

@@ -115,7 +115,7 @@ public static MultiOdeResult IntegrateOde (Func<double, IList<double>, IList<dou
115115
/// of each component. Each component's derivative may depend itself and any other components, as well as on the independent variable.
116116
/// The independent variable x still takes only a single real value.</para>
117117
/// </remarks>
118-
public static MultiOdeResult IntegrateOde (Func<double, IList<double>, IList<double>> rhs, double x0, IList<double> y0, double x1, MultiOdeSettings settings) {
118+
public static MultiOdeResult IntegrateOde (Func<double, IReadOnlyList<double>, IReadOnlyList<double>> rhs, double x0, IReadOnlyList<double> y0, double x1, MultiOdeSettings settings) {
119119

120120
if (rhs == null) throw new ArgumentNullException(nameof(rhs));
121121
if (y0 == null) throw new ArgumentNullException(nameof(y0));
@@ -134,22 +134,26 @@ public static MultiOdeResult IntegrateOde (Func<double, IList<double>, IList<dou
134134

135135
internal abstract class MultiOdeEngine : OdeEngine {
136136

137-
public MultiOdeEngine (Func<double, IList<double>, IList<double>> rhs, double x, MultiOdeSettings settings) : base(x) {
137+
public MultiOdeEngine (Func<double, IReadOnlyList<double>, IReadOnlyList<double>> rhs, double x, MultiOdeSettings settings) : base(x) {
138138
Debug.Assert(rhs != null);
139139
Debug.Assert(settings != null);
140140
this.rhs = rhs;
141141
this.settings = settings;
142142
}
143143

144-
private readonly Func<double, IList<double>, IList<double>> rhs;
144+
private readonly Func<double, IReadOnlyList<double>, IReadOnlyList<double>> rhs;
145145

146146
protected readonly MultiOdeSettings settings;
147147

148-
public IList<double> Evaluate (double x, IList<double> y) {
148+
public IReadOnlyList<double> Evaluate (double x, IReadOnlyList<double> y) {
149149
if (count >= settings.EvaluationBudget) throw new NonconvergenceException();
150150
count++;
151-
ReadOnlyCollection<double> yWrapper = new ReadOnlyCollection<double>(y);
152-
IList<double> z = rhs(x, yWrapper);
151+
// ReadOnlyCollection doesn't have a constructor that accepts IReadOnlyList.
152+
// But being an IReadOnlyList doesn't protect us from be cast back to a mutable
153+
// type, so for the moment this is actually not safe from poorly behaved
154+
// rhs's.
155+
//ReadOnlyCollection<double> yWrapper = new ReadOnlyCollection<double>(y);
156+
IReadOnlyList<double> z = rhs(x, y);
153157
if (z == null) throw new InvalidOperationException();
154158
return (z);
155159
}
@@ -173,7 +177,7 @@ protected override void AcceptStep () {
173177

174178
internal class MultiBulrischStoerEngine : MultiOdeEngine, IBulrischStoerEngine {
175179

176-
public MultiBulrischStoerEngine (Func<double, IList<double>, IList<double>> rhs, double x, IList<double> y, MultiOdeSettings settings) : base(rhs, x, settings) {
180+
public MultiBulrischStoerEngine (Func<double, IReadOnlyList<double>, IReadOnlyList<double>> rhs, double x, IReadOnlyList<double> y, MultiOdeSettings settings) : base(rhs, x, settings) {
177181

178182
Debug.Assert(rhs != null);
179183
Debug.Assert(y != null);
@@ -218,7 +222,7 @@ private double[] TrialStep (int n) {
218222
double[] nY1 = new double[Y.Length];
219223
for (int i = 0; i < nY1.Length; i++) { nY0[i] = Y[i]; nY1[i] = Y[i] + h * YPrime[i]; }
220224

221-
IList<double> F;
225+
IReadOnlyList<double> F;
222226
for (int k = 1; k < n; k++) {
223227
F = Evaluate(X + k * h, nY1);
224228
for (int i = 0; i < nY1.Length; i++) { double t = nY1[i]; nY1[i] = nY0[i] + 2.0 * h * F[i]; nY0[i] = t; }
@@ -279,7 +283,7 @@ public override MultiOdeResult GetResult () {
279283

280284
internal class MultiStoermerEngine : MultiOdeEngine, IBulrischStoerEngine {
281285

282-
public MultiStoermerEngine (Func<double, IList<double>, IList<double>> rhs, double x, IList<double> y, IList<double> yPrime, MultiOdeSettings settings) : base(rhs, x, settings) {
286+
public MultiStoermerEngine (Func<double, IReadOnlyList<double>, IReadOnlyList<double>> rhs, double x, IReadOnlyList<double> y, IReadOnlyList<double> yPrime, MultiOdeSettings settings) : base(rhs, x, settings) {
283287

284288
Debug.Assert(rhs != null);
285289
Debug.Assert(y != null);
@@ -401,7 +405,7 @@ private void TrialStep (int n, out double[] Y1, out double[] YP1) {
401405

402406
int d = Y.Length;
403407

404-
IList<double> F;
408+
IReadOnlyList<double> F;
405409
Y1 = new double[d];
406410
double[] D1 = new double[d];
407411

Numerics/Core/ComplexMath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Meta.Numerics {
88

99
/// <summary>
10-
/// Provides simple functions of complex arguments.
10+
/// Contains methods that compute basic functions of complex arguments.
1111
/// </summary>
1212
public static class ComplexMath {
1313

Numerics/Core/Global.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Diagnostics;
3+
using System.Collections.Generic;
24

35
namespace Meta.Numerics {
46

@@ -23,6 +25,7 @@ public static void Swap<T> (ref T a, ref T b) {
2325
}
2426

2527
// pre-calculate some often-used factors
28+
// these are actually useless; the compiler pre-calculates them for us
2629

2730
public const double TwoPI = 2.0 * Math.PI;
2831

@@ -47,6 +50,17 @@ public static void Swap<T> (ref T a, ref T b) {
4750

4851
public static readonly double LogTwo = Math.Log(2.0);
4952

53+
// IList defines CopyTo. IReadOnlyList doesn't. So in order to switch from IList to IReadOnlyList,
54+
// we define an extension method to implement it.
55+
public static void CopyTo<T> (this IReadOnlyList<T> source, T[] target, int startIndex) {
56+
Debug.Assert(source != null);
57+
Debug.Assert(target != null);
58+
Debug.Assert(startIndex >= 0);
59+
for (int i = 0; i < source.Count; i++) {
60+
target[startIndex + i] = source[i];
61+
}
62+
}
63+
5064
}
5165

5266
}

Numerics/Core/UncertainMath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Meta.Numerics {
44

55

66
/// <summary>
7-
/// Contains methods for computing basic mathematical functions of uncertain values.
7+
/// Contains methods that compute basic functions of uncertain values.
88
/// </summary>
99
/// <remarks><para>The methods in this static class perform the same basic mathematical operations as the methods of
1010
/// the <see cref="System.Math"/> class, accounting for the uncertainty in the inputs to produce a corresponding

Numerics/Data/ComputedList.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
4+
using System.Diagnostics;
75

86
namespace Meta.Numerics.Data
97
{
108

119
internal class ComputedList<T> : NamedList, IEnumerable, IEnumerable<T>, IReadOnlyList<T>
1210
{
1311
internal ComputedList (FrameView frame, string name, Func<FrameRow,T> function) : base(name) {
12+
Debug.Assert(frame != null);
13+
Debug.Assert(function != null);
1414
this.frame = frame;
15-
this.name = name;
1615
this.function = function;
1716
}
1817

1918
private readonly FrameView frame;
20-
private readonly string name;
2119
private readonly Func<FrameRow, T> function;
2220

2321
public T this[int index]

Numerics/Data/FrameColumn.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ namespace Meta.Numerics.Data
88
{
99

1010
/// <summary>
11-
/// One column of a data frame.
11+
/// Represents one column of a data frame.
1212
/// </summary>
13+
/// <remarks>
14+
/// <para>To obtained strongly typed values of the data in the column,
15+
/// use the <see cref="As{T}" autoUpgrade="true"/> method.</para>
16+
/// </remarks>
1317
public sealed class FrameColumn : IEnumerable {
1418

1519
internal FrameColumn(FrameView frame, int c) {
@@ -61,14 +65,17 @@ public object this[int r] {
6165
}
6266

6367
/// <summary>
64-
/// Returns the column as a typed list.
68+
/// Exposes the column as a list of uniform type.
6569
/// </summary>
6670
/// <typeparam name="T">The type of the list.</typeparam>
6771
/// <returns>An object that allows the column to be accessed as a typed list.</returns>
6872
/// <remarks>
6973
/// <para>This operation is both time and memory efficient. It does not convert every element
7074
/// into a new list, but instead simply instantiates a converter that implements the list
7175
/// operations directly against the already existing storage.</para>
76+
/// <para>The type specified by <typeparamref name="T"/> need not be the same as the
77+
/// underlying stored type of the column. As long as the exposed values can be cast or
78+
/// converted to the specified type, the typed list returned will work as required.</para>
7279
/// </remarks>
7380
public IReadOnlyList<T> As<T> () {
7481
// If the requested column is of the requested type, expose it directly.

Numerics/Data/FrameColumnCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Meta.Numerics.Data
77
{
88

99
/// <summary>
10-
/// A collection of data frame columns.
10+
/// Represents a collection of columns of a data frame.
1111
/// </summary>
1212
public sealed class FrameColumnCollection : IReadOnlyCollection<FrameColumn>, IReadOnlyList<FrameColumn>, IEnumerable<FrameColumn> /*, IReadOnlyDictionary<string,FrameColumn> */
1313
{

0 commit comments

Comments
 (0)