public static void InitSievingRequest(BigInteger N, int B, PolynomialFunction f, SieveRequest sievereq) { sievereq.AStart = (int)N.Sqrt() + 1; StartIdx = 0; sievereq.polyFunction = f; //the max amount of data we need to find the quadratic residues is the Bth prime (the highest one) sievereq.L = primeSupply[B]; SievingData sievedat = new SievingData(); EvaluatePoly(sievereq, sievedat); List <List <int> > tmpPrimeStarts = new List <List <int> >(); List <int> tmpPrimeIntervals = new List <int>(); for (int pI = 0; pI < B; pI++) { int p = primeSupply[pI]; List <int> tmp = new List <int>(); for (int a = 0; a < p; a++) { if (sievedat.V[a] % p == 0) { //we found a quadratic residue (there are two for each prime that isn't 2) tmp.Add(a); } } if (tmp.Count > 0) { //if the ith value is divisible by the prime k, then every k results after that will also be divisible tmpPrimeIntervals.Add(p); tmpPrimeStarts.Add(tmp); } } sievereq.PrimeIntervals = tmpPrimeIntervals.ToArray(); sievereq.PrimeStarts = tmpPrimeStarts.ToArray(); //remove primes with no quadratic residues sievereq.B = sievereq.PrimeIntervals.Length; }
/// <summary> v cQ1 /// Initializes a SievingRequest based on given parameters, and finds the quadratic residues for primes specified /// </summary> /// <param name="N">The number to factor</param> /// <param name="B">The limit for smooth numbers</param> /// <param name="f">The polynomial to sieve</param> /// <param name="sievereq">The SieveRequest that will be initialized</param> public static void InitSievingRequest(BigInteger N, int B, PolynomialFunction f, SieveRequest sievereq) { sievereq.AStart = (int)N.Sqrt() + 1; sievereq.StartIdx = 0; sievereq.polyFunction = f; sievereq.L = primeSupply[B]; SievingData sievedat = new SievingData(); EvaluatePoly(sievereq, sievedat); List<List<int>> tmpPrimeStarts = new List<List<int>>(); List<int> tmpPrimeIntervals = new List<int>(); for (int pI = 0; pI < B; pI++) { int p = primeSupply[pI]; List<int> tmp = new List<int>(); for (int a = 0; a < p; a++) { if (sievedat.V[a] % p == 0) { tmp.Add(a); } } if (tmp.Count > 0) { tmpPrimeIntervals.Add(p); tmpPrimeStarts.Add(tmp); } } sievereq.PrimeIntervals = tmpPrimeIntervals.ToArray(); sievereq.PrimeStarts = tmpPrimeStarts.ToArray(); sievereq.B = sievereq.PrimeIntervals.Length; }
public static string Fit(Altaxo.Gui.Graph.Gdi.Viewing.IGraphController ctrl, int order, double fitCurveXmin, double fitCurveXmax, bool showFormulaOnGraph) { string error; error = GetActivePlotPoints(ctrl, out var xarr, out var yarr); int numberOfDataPoints = xarr.Length; if (null != error) { return(error); } string[] plotNames = GetActivePlotName(ctrl); int numberOfParameter = order + 1; double[] parameter = new double[numberOfParameter]; var fit = LinearFitBySvd.FitPolymomialDestructive(order, xarr, yarr, null, numberOfDataPoints); // Output of results Current.Console.WriteLine(""); Current.Console.WriteLine("---- " + DateTime.Now.ToString() + " -----------------------"); Current.Console.WriteLine("Polynomial regression of order {0} of {1} over {2}", order, plotNames[1], plotNames[0]); Current.Console.WriteLine( "Name Value Error F-Value Prob>F"); for (int i = 0; i < fit.Parameter.Length; i++) { Current.Console.WriteLine("A{0,-3} {1,20} {2,20} {3,20} {4,20}", i, fit.Parameter[i], fit.StandardErrorOfParameter(i), fit.TofParameter(i), 1 - FDistribution.CDF(fit.TofParameter(i), numberOfParameter, numberOfDataPoints - 1) ); } Current.Console.WriteLine("R²: {0}, Adjusted R²: {1}", fit.RSquared, fit.AdjustedRSquared); Current.Console.WriteLine("Condition number: {0}, Loss of precision (digits): {1}", fit.ConditionNumber, Math.Log10(fit.ConditionNumber)); Current.Console.WriteLine("------------------------------------------------------------"); Current.Console.WriteLine("Source of Degrees of"); Current.Console.WriteLine("variation freedom Sum of Squares Mean Square F0 P value"); double regressionmeansquare = fit.RegressionCorrectedSumOfSquares / numberOfParameter; double residualmeansquare = fit.ResidualSumOfSquares / (numberOfDataPoints - numberOfParameter - 1); Current.Console.WriteLine("Regression {0,10} {1,20} {2,20} {3,20} {4,20}", numberOfParameter, fit.RegressionCorrectedSumOfSquares, fit.RegressionCorrectedSumOfSquares / numberOfParameter, regressionmeansquare / residualmeansquare, 1 - FDistribution.CDF(regressionmeansquare / residualmeansquare, numberOfParameter, numberOfDataPoints - 1) ); Current.Console.WriteLine("Residual {0,10} {1,20} {2,20}", numberOfDataPoints - 1 - numberOfParameter, fit.ResidualSumOfSquares, residualmeansquare ); Current.Console.WriteLine("Total {0,10} {1,20}", numberOfDataPoints - 1, fit.TotalCorrectedSumOfSquares ); Current.Console.WriteLine("------------------------------------------------------------"); // add the fit curve to the graph IScalarFunctionDD plotfunction = new PolynomialFunction(fit.Parameter); var fittedCurve = new XYFunctionPlotItem(new XYFunctionPlotData(plotfunction), new G2DPlotStyleCollection(LineScatterPlotStyleKind.Line, ctrl.Doc.GetPropertyContext())); var xylayer = ctrl.ActiveLayer as XYPlotLayer; if (null != xylayer) { xylayer.PlotItems.Add(fittedCurve); } return(null); }
static NormalDistribution() { double[] coeffs = { 0.31938153, -0.356563782, 1.781477937, -1.821255978, 1.330274429 }; _errorFunctionSeries = new PolynomialFunction(coeffs); }
public static string Fit(Altaxo.Graph.GUI.GraphController ctrl, int order, double fitCurveXmin, double fitCurveXmax, bool showFormulaOnGraph) { string error; int numberOfDataPoints; double[] xarr = null, yarr = null, earr = null; error = GetActivePlotPoints(ctrl, ref xarr, ref yarr, out numberOfDataPoints); if (null != error) { return(error); } string[] plotNames = GetActivePlotName(ctrl); // Error-Array earr = new double[numberOfDataPoints]; for (int i = 0; i < earr.Length; i++) { earr[i] = 1; } int numberOfParameter = order + 1; double[] parameter = new double[numberOfParameter]; LinearFitBySvd fit = new LinearFitBySvd( xarr, yarr, earr, numberOfDataPoints, order + 1, new FunctionBaseEvaluator(EvaluatePolynomialBase), 1E-5); // Output of results Current.Console.WriteLine(""); Current.Console.WriteLine("---- " + DateTime.Now.ToString() + " -----------------------"); Current.Console.WriteLine("Polynomial regression of order {0} of {1} over {2}", order, plotNames[1], plotNames[0]); Current.Console.WriteLine( "Name Value Error F-Value Prob>F"); for (int i = 0; i < fit.Parameter.Length; i++) { Current.Console.WriteLine("A{0,-3} {1,20} {2,20} {3,20} {4,20}", i, fit.Parameter[i], fit.StandardErrorOfParameter(i), fit.TofParameter(i), 1 - FDistribution.CDF(fit.TofParameter(i), numberOfParameter, numberOfDataPoints - 1) ); } Current.Console.WriteLine("R²: {0}, Adjusted R²: {1}", fit.RSquared, fit.AdjustedRSquared); Current.Console.WriteLine("------------------------------------------------------------"); Current.Console.WriteLine("Source of Degrees of"); Current.Console.WriteLine("variation freedom Sum of Squares Mean Square F0 P value"); double regressionmeansquare = fit.RegressionCorrectedSumOfSquares / numberOfParameter; double residualmeansquare = fit.ResidualSumOfSquares / (numberOfDataPoints - numberOfParameter - 1); Current.Console.WriteLine("Regression {0,10} {1,20} {2,20} {3,20} {4,20}", numberOfParameter, fit.RegressionCorrectedSumOfSquares, fit.RegressionCorrectedSumOfSquares / numberOfParameter, regressionmeansquare / residualmeansquare, 1 - FDistribution.CDF(regressionmeansquare / residualmeansquare, numberOfParameter, numberOfDataPoints - 1) ); Current.Console.WriteLine("Residual {0,10} {1,20} {2,20}", numberOfDataPoints - 1 - numberOfParameter, fit.ResidualSumOfSquares, residualmeansquare ); Current.Console.WriteLine("Total {0,10} {1,20}", numberOfDataPoints - 1, fit.TotalCorrectedSumOfSquares ); Current.Console.WriteLine("------------------------------------------------------------"); // add the fit curve to the graph IScalarFunctionDD plotfunction = new PolynomialFunction(fit.Parameter); XYFunctionPlotItem fittedCurve = new XYFunctionPlotItem(new XYFunctionPlotData(plotfunction), new G2DPlotStyleCollection(LineScatterPlotStyleKind.Line)); ctrl.ActiveLayer.PlotItems.Add(fittedCurve); return(null); }
public PolynomialFunction PolyFunction; //The polynomial function f(a) to seive for smooth things public SieveInitInfo(int B, PolynomialFunction f) { this.B = B; PolyFunction = f; AStart = f.PositivePoint(); }