static private GetRange ( double>.Func |
||
source | double>.Func | |
range | DoubleRange | |
return | bool |
internal static bool GetRange(Func<double, double> source, out DoubleRange range)
{
ParameterInfo[] parameters = source.Method.GetParameters();
ParameterInfo first = parameters[0];
var obj = source.Target as IUnivariateDistribution;
if (obj != null && source.Method.Name == "ProbabilityDensityFunction")
{
range = obj.Support;
return true;
}
RangeAttribute[] attributes =
(RangeAttribute[])first.GetCustomAttributes(typeof(RangeAttribute), false);
if (attributes != null && attributes.Length > 0)
{
range = new DoubleRange((double)attributes[0].Minimum, (double)attributes[0].Maximum);
return true;
}
range = new DoubleRange();
return false;
}
}
private static DataSeriesBox show(String title, Func <double, double> function, double?min, double?max, double?step, int?npoints) { if (min == null || max == null) { DoubleRange range; if (ScatterplotBox.GetRange(function, out range)) { min = range.Min; max = range.Max; } else { min = 0; max = 1; } } if (npoints == null) { npoints = 1000; } if (step == null) { step = (max - min) / npoints; } double[] input = Vector.Interval(min.Value, max.Value, step.Value); double[] output = Matrix.Apply(input, function); return(show(title, input, new[] { output })); }