public static void Predict(PredictionModel <NumberData, NumberPrediction> model, BigInteger n, out string trueValue, out string predictedValue) { string str = ConvertBigIntegerToBinary(n); BigInteger t = new BigInteger(Int32.MaxValue); BigInteger v = t * t; string val = ConvertBigIntegerToBinary(v); while (str.Length < val.Length) { str = "0," + str; } NumberData nd = CreateNumberDataFromBinary(str); bool tval = IsPrimeMillerRabin(n); NumberPrediction np = model.Predict(nd); trueValue = tval ? "Prime" : "NotPrime"; predictedValue = np.PredictedLabel; /*DEBUG * Console.WriteLine("Number: {0}. Is it Prime?", n); * Console.WriteLine("True Value: {0}", trueValue); * Console.WriteLine("Predicted Value: {0}", np.PredictedLabel); */ }
public static NumberData CreateNumberDataFromBinary(string bi) { string[] b = bi.Split(','); NumberData nd = new NumberData(); nd.b0 = (float)Convert.ToInt32(b[0]); nd.b1 = (float)Convert.ToInt32(b[1]); nd.b2 = (float)Convert.ToInt32(b[2]); nd.b3 = (float)Convert.ToInt32(b[3]); nd.b4 = (float)Convert.ToInt32(b[4]); nd.b5 = (float)Convert.ToInt32(b[5]); nd.b6 = (float)Convert.ToInt32(b[6]); nd.b7 = (float)Convert.ToInt32(b[7]); nd.b8 = (float)Convert.ToInt32(b[8]); nd.b9 = (float)Convert.ToInt32(b[9]); nd.b10 = (float)Convert.ToInt32(b[10]); nd.b11 = (float)Convert.ToInt32(b[11]); nd.b12 = (float)Convert.ToInt32(b[12]); nd.b13 = (float)Convert.ToInt32(b[13]); nd.b14 = (float)Convert.ToInt32(b[14]); nd.b15 = (float)Convert.ToInt32(b[15]); nd.b16 = (float)Convert.ToInt32(b[16]); nd.b17 = (float)Convert.ToInt32(b[17]); nd.b18 = (float)Convert.ToInt32(b[18]); nd.b19 = (float)Convert.ToInt32(b[19]); nd.b20 = (float)Convert.ToInt32(b[20]); nd.b21 = (float)Convert.ToInt32(b[21]); nd.b22 = (float)Convert.ToInt32(b[22]); nd.b23 = (float)Convert.ToInt32(b[23]); nd.b24 = (float)Convert.ToInt32(b[24]); nd.b25 = (float)Convert.ToInt32(b[25]); nd.b26 = (float)Convert.ToInt32(b[26]); nd.b27 = (float)Convert.ToInt32(b[27]); nd.b28 = (float)Convert.ToInt32(b[28]); nd.b29 = (float)Convert.ToInt32(b[29]); nd.b30 = (float)Convert.ToInt32(b[30]); nd.b31 = (float)Convert.ToInt32(b[31]); nd.b32 = (float)Convert.ToInt32(b[32]); nd.b33 = (float)Convert.ToInt32(b[33]); nd.b34 = (float)Convert.ToInt32(b[34]); nd.b35 = (float)Convert.ToInt32(b[35]); nd.b36 = (float)Convert.ToInt32(b[36]); nd.b37 = (float)Convert.ToInt32(b[37]); nd.b38 = (float)Convert.ToInt32(b[38]); nd.b39 = (float)Convert.ToInt32(b[39]); nd.b40 = (float)Convert.ToInt32(b[40]); nd.b41 = (float)Convert.ToInt32(b[41]); nd.b42 = (float)Convert.ToInt32(b[42]); nd.b43 = (float)Convert.ToInt32(b[43]); nd.b44 = (float)Convert.ToInt32(b[44]); nd.b45 = (float)Convert.ToInt32(b[45]); nd.b46 = (float)Convert.ToInt32(b[46]); nd.b47 = (float)Convert.ToInt32(b[47]); nd.b48 = (float)Convert.ToInt32(b[48]); nd.b49 = (float)Convert.ToInt32(b[49]); nd.b50 = (float)Convert.ToInt32(b[50]); nd.b51 = (float)Convert.ToInt32(b[51]); nd.b52 = (float)Convert.ToInt32(b[52]); nd.b53 = (float)Convert.ToInt32(b[53]); nd.b54 = (float)Convert.ToInt32(b[54]); nd.b55 = (float)Convert.ToInt32(b[55]); nd.b56 = (float)Convert.ToInt32(b[56]); nd.b57 = (float)Convert.ToInt32(b[57]); nd.b58 = (float)Convert.ToInt32(b[58]); nd.b59 = (float)Convert.ToInt32(b[59]); nd.b60 = (float)Convert.ToInt32(b[60]); nd.b61 = (float)Convert.ToInt32(b[61]); nd.b62 = (float)Convert.ToInt32(b[62]); nd.b63 = (float)Convert.ToInt32(b[63]); nd.b64 = (float)Convert.ToInt32(b[64]); nd.b65 = (float)Convert.ToInt32(b[65]); nd.b66 = (float)Convert.ToInt32(b[66]); nd.b67 = (float)Convert.ToInt32(b[67]); nd.b68 = (float)Convert.ToInt32(b[68]); nd.b69 = (float)Convert.ToInt32(b[69]); nd.b70 = (float)Convert.ToInt32(b[70]); nd.b71 = (float)Convert.ToInt32(b[71]); nd.b72 = (float)Convert.ToInt32(b[72]); nd.b73 = (float)Convert.ToInt32(b[73]); nd.b74 = (float)Convert.ToInt32(b[74]); nd.b75 = (float)Convert.ToInt32(b[75]); if (b.Length > 76) { nd.Label = b[76]; } return(nd); }