Browse Source

Generate: LogSpacedMap, F# func argument support in F# module

pull/197/head
Christoph Ruegg 13 years ago
parent
commit
29bc58398f
  1. 1
      src/FSharp/FSharp-Portable136.fsproj
  2. 1
      src/FSharp/FSharp-Portable47.fsproj
  3. 1
      src/FSharp/FSharp.fsproj
  4. 64
      src/FSharp/Generate.fs
  5. 19
      src/Numerics/Generate.cs

1
src/FSharp/FSharp-Portable136.fsproj

@ -49,6 +49,7 @@
<Compile Include="Statistics.fs" />
<Compile Include="Random.fs" />
<Compile Include="Distributions.fs" />
<Compile Include="Generate.fs" />
<Compile Include="LinearAlgebra.Vector.fs" />
<Compile Include="LinearAlgebra.Matrix.fs" />
<Compile Include="Complex.fs" />

1
src/FSharp/FSharp-Portable47.fsproj

@ -49,6 +49,7 @@
<Compile Include="Statistics.fs" />
<Compile Include="Random.fs" />
<Compile Include="Distributions.fs" />
<Compile Include="Generate.fs" />
<Compile Include="LinearAlgebra.Vector.fs" />
<Compile Include="LinearAlgebra.Matrix.fs" />
<Compile Include="Complex.fs" />

1
src/FSharp/FSharp.fsproj

@ -62,6 +62,7 @@
<Compile Include="Statistics.fs" />
<Compile Include="Random.fs" />
<Compile Include="Distributions.fs" />
<Compile Include="Generate.fs" />
<Compile Include="LinearAlgebra.Vector.fs" />
<Compile Include="LinearAlgebra.Matrix.fs" />
<Compile Include="Complex.fs" />

64
src/FSharp/Generate.fs

@ -0,0 +1,64 @@
// <copyright file="Generate.fs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics
open System
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Generate =
let inline private tobcl (f:'a->'b) = Func<'a,'b>(f)
let inline private tobcl2 (f:'a->'b->'c) = Func<'a,'b,'c>(f)
let inline map map points = Array.map map points
let inline mapSeq map points = Seq.map map points
let inline map2 map pointsA pointsB = Array.map2 map pointsA pointsB
let inline map2Seq map pointsA pointsB = Seq.map2 map pointsA pointsB
let inline linearSpacedMap length start stop map = Generate.LinearSpacedMap(length, start, stop, tobcl map)
let inline logSpacedMap length startExp stopExp map = Generate.LogSpacedMap(length, startExp, stopExp, tobcl map)
let inline linearRangeMap start step stop map = [| for x in start .. step .. stop -> map x |]
let inline periodicMap length map samplingRate frequency amplitude phase delay =
Generate.PeriodicMap(length, tobcl map, samplingRate, frequency, amplitude, phase, delay)
let inline periodicMapSeq map samplingRate frequency amplitude phase delay =
Generate.PeriodicMapSequence(tobcl map, samplingRate, frequency, amplitude, phase, delay)
let inline randomMap length distribution map = Generate.RandomMap(length, distribution, tobcl map)
let inline randomMapSeq distribution map = Generate.RandomMapSequence(distribution, tobcl map)
let inline randomMap2 length distribution map = Generate.RandomMap2(length, distribution, tobcl2 map)
let inline randomMap2Seq distribution map = Generate.RandomMap2Sequence(distribution, tobcl2 map)
let inline randomUniformMap length map = Generate.RandomUniformMap(length, tobcl map)
let inline randomUniformMapSeq map = Generate.RandomUniformMapSequence(tobcl map)
let inline randomUniformMap2 length map = Generate.RandomUniformMap2(length, tobcl2 map)
let inline randomUniformMap2Seq map = Generate.RandomUniformMap2Sequence(tobcl2 map)

19
src/Numerics/Generate.cs

@ -149,6 +149,25 @@ namespace MathNet.Numerics
return data;
}
/// <summary>
/// Generate samples by sampling a function at base 10 logarithmically spaced points between the specified decade exponents (inclusive).
/// </summary>
public static T[] LogSpacedMap<T>(int length, double startExponent, double stopExponent, Func<double, T> map)
{
if (length <= 0) return new T[0];
if (length == 1) return new[] { map(Math.Pow(10, stopExponent)) };
double step = (stopExponent - startExponent)/(length - 1);
var data = new T[length];
for (int i = 0; i < data.Length; i++)
{
data[i] = map(Math.Pow(10, startExponent + i*step));
}
data[data.Length - 1] = map(Math.Pow(10, stopExponent));
return data;
}
/// <summary>
/// Generate a linearly spaced sample vector within the inclusive interval (start, stop) and step 1.
/// Equivalent to MATLAB colon operator (:).

Loading…
Cancel
Save