public frmEditFunctionSettings(SpecialFunction _function, DBConnection _dbCon, string _tableName) { InitializeComponent(); function = _function; dbCon = _dbCon; tableName = _tableName; }
/// <summary> /// получиь параметр распределения вейбулла бета /// </summary> /// <returns></returns> private static double getVeybullBeta(double v0, double veybullGamma) { double arg = 1d + 1d / veybullGamma; double G = SpecialFunction.gamma(arg); return(v0 / G); }
public static SpecialFunction RemoveFlag(SpecialFunction value, SpecialFunction flag) { return(Enum.GetValues(typeof(SpecialFunction)) .Cast <SpecialFunction>() .Where(u => u != SpecialFunction.None && u != flag && value.HasFlag(u)) .Aggregate(SpecialFunction.None, (current, specialFunction) => current | specialFunction)); }
private SpecialFunction GetSpecFun() { var specFun = new SpecialFunction(1, "spec_cast_adept"); SpecFunRepository.Add(specFun.ID, specFun); return(specFun); }
public double kappa(double lambdaL, double lambdaS, double aL, double time) { //double temp = Math.Sqrt(Math.PI) * (lambdaL - lambdaS) / (2 * aL * Math.Sqrt(time)); double temp = SpecialFunction.gamma(0.2) * (lambdaL - lambdaS) / (5 * aL * Math.Pow(time, 0.2)); //double temp = Math.Sqrt(Math.PI) * (lambdaL - lambdaS) / (2 * aL * Math.Sqrt(time)); return(temp); }
/// <summary> /// Format SpecialFunction model to SpecialFunctionViewModel /// </summary> public static SpecialFunctionViewModel FormatSpecialFunctionModel(SpecialFunction model) { return(new SpecialFunctionViewModel() { Id = model.Id, Name = model.Name, Description = model.Description, PropertyType = model.IdPropertyTypeNavigation != null?FormatPropertyTypeCatalogModel(model.IdPropertyTypeNavigation) : null }); }
static void Assumption() { //int[] X1 = new int[] { 1, 1, 2, 2, 2, 2, 1, 2 }; //int[] X2 = new int[] { 2, 1, 1, 2, 1, 1, 2, 2 }; int[] X1 = new int[] { 1, 1, 1, 1, 2, 2, 2, 2 }; int[] X2 = new int[] { 1, 1, 1, 1, 2, 2, 2, 2 }; int numberOfX1Is1 = 0; int numberOfX1Is2 = 0; int numberOfX2Is1 = 0; int numberOfX2Is2 = 0; int numberOfX1Is1X2Is1 = 0; int numberOfX1Is2X2Is1 = 0; int numberOfX1Is1X2Is2 = 0; int numberOfX1Is2X2Is2 = 0; double N = Convert.ToDouble(X1.Length); for (int i = 0; i < X1.Length; ++i) { if (X1[i] == 1) { ++numberOfX1Is1; if (X2[i] == 1) { ++numberOfX2Is1; ++numberOfX1Is1X2Is1; } else { ++numberOfX2Is2; ++numberOfX1Is1X2Is2; } } else { ++numberOfX1Is2; if (X2[i] == 1) { ++numberOfX2Is1; ++numberOfX1Is2X2Is1; } else { ++numberOfX2Is2; ++numberOfX1Is2X2Is2; } } } double MI = (numberOfX1Is1X2Is1 / N) * Math.Log((numberOfX1Is1X2Is1 * N) / (numberOfX1Is1 * numberOfX2Is1), 2) //+ (numberOfX1Is1X2Is2 / N) * Math.Log((numberOfX1Is1X2Is2 * N) / (numberOfX1Is1 * numberOfX2Is2), 2) //+ (numberOfX1Is2X2Is1 / N) * Math.Log((numberOfX1Is2X2Is1 * N) / (numberOfX1Is2 * numberOfX2Is1), 2) + (numberOfX1Is2X2Is2 / N) * Math.Log((numberOfX1Is2X2Is2 * N) / (numberOfX1Is2 * numberOfX2Is2), 2); double X = SpecialFunction.chisqc(1, 2 * N * MI); //(右尾面积)越小越有联系(不独立),越大越独立 }
// ReSharper disable once UnusedMember.Local private double MantegnaRandom(double lambda) { double sigmaX = SpecialFunction.lgamma(lambda + 1) * Math.Sin(Math.PI * lambda * .5); double divider = SpecialFunction.lgamma(lambda * .5) * lambda * Math.Pow(2.0, (lambda - 1) * .5); sigmaX /= divider; double lambda1 = 1.0 / lambda; sigmaX = Math.Pow(Math.Abs(sigmaX), lambda1); double x = GaussianRandom(0, sigmaX); double y = Math.Abs(GaussianRandom(0, 1.0)); return(x / Math.Pow(y, lambda1)); }
private double density(double x) { double fx2 = 0; if (x <= 0) { fx2 = 0; } else { fx2 = (Math.Pow(2, -(size_segs) / 2.0) / SpecialFunction.gamma(size_segs / 2.0)) * Math.Pow(x, (size_segs) / 2.0 - 1) * Math.Exp(-x / 2.0); } return(fx2); }
private double f(double x) // плотность вероятности { double res = 0; if (x <= 0) { res = 0; } else { res = (Math.Pow(2, -((double)k_intervals - 1.0) / 2.0) / SpecialFunction.gamma(((double)k_intervals - 1.0) / 2.0)) * Math.Pow(x, (((double)k_intervals - 1.0) / 2.0) - 1.0) * Math.Exp(-x / 2.0); } //res = (Math.Pow(2, -((double)k_intervals - 1.0) / 2.0) / SpecialFunction.gamma(((double)k_intervals - 1.0) / 2.0)) * Math.Pow(x, ((double)k_intervals - 1.0) / 2.0 - 1.0) * Math.Exp(-x / 2.0); return(res); }
private void WriteFunction(SpecialFunction function, SpecialFunction function0 = SpecialFunction.None) { var x = CompressorSetting.Indexes?.SpecialFunctions.FirstOrDefault(u => u.SpecialFunction.HasFlag(function)); if (x != null) { ModbusTool.Write(x.Index, CompressorSetting, 1); } else if (function0 != SpecialFunction.None) { x = CompressorSetting.Indexes?.SpecialFunctions.FirstOrDefault(u => u.SpecialFunction.HasFlag(function0)); if (x != null) { ModbusTool.Write(x.Index, CompressorSetting, 0); } } }
public static SpecialFunction LuaCreateSpecialFunction(string name) { var newSpecFun = new SpecialFunction(_dbManager.GenerateNewId <SpecialFunction>(), name) { Value = SpecFunHandler.GetSpecFunReference(name) }; if (newSpecFun.Value == null) { throw new EntryNotFoundException("SpecFun {0} not found", name); } _luaManager.Proxy.CreateTable("specfun"); AddLastObject(newSpecFun); _dbManager.AddToRepository(newSpecFun); return(newSpecFun); }
/// <summary> /// возвращает экстремальную скорость ветра за 50 лет /// </summary> /// <param name="v0"></param> /// <param name="veybullGamma"></param> /// <returns></returns> private static double getExtremalSpeed(double v0, double veybullGamma) { double k; if (veybullGamma <= 1.77) { double T = 50d; double n = 23037d; double a, b, d; a = SpecialFunction.gamma(1d + 1d / veybullGamma); d = 1 - Math.Exp(Math.Log(1d - 1d / T) / n); b = -1 * Math.Log(d); k = (1 / a) * Math.Pow(b, 1 / veybullGamma); } else { k = 5; } return(v0 * k); }
public double concX() { return(Math.Round((((1 - ((SpecialFunction.erf((((x / (2 * Math.Sqrt((d0 * Math.Exp(-qd / (r * (temp + 273.15)))) * time))))))))) * (cs - c0)) + c0), 5)); }
public static bool HasFlag(this SpecialFunction value, SpecialFunction flag) { return((value & flag) != 0); }
public virtual void VisitSpecialFunction(SpecialFunction n) { }
static void Main(string[] args) { //double cS= 1000, cL= 1290, roS= 2679, roL= 2380, L= 390000, tempKrzep= 930, u0= 1213, uI= 298, lambdaL=104,lambdaS= 240; //double cS = 690, cL = 800, roS = 7500, roL = 7000, L = 270000, tempKrzep = 1773, u0 = 2213, uI = 323, lambdaL = 33, lambdaS = 30; double cS = 25, cL = 26, roS = 10, roL = 10, tempKrzep = 1, u0, uI, /*u0 = 1573, uI =973,*/ lambdaL = 130, lambdaS = 125; //double cS = 4217, cL = 4182, roS = 999.82, roL = 998.29, L = 334000, tempKrzep = 273, u0=293, uI=263, /*u0 = 1573, uI =973,*/ lambdaL = 0.6, lambdaS = 0.569; int lbIteracji = 200; double a, stalaA, stalaSigma; double aL = lambdaL / (roL * cL); //double entalpiaL = 3536280000, entalpiaS = 2491470000; //double entalpiaL = 11200275000, entalpiaS = 9175275000; //double entalpiaL = 500, entalpiaS = 250; double entalpiaS, entalpiaL; double b = 2; double alfa = 0.8; int granica = 0; int n = 1000; double deltaX = b / n, deltaT = 0.01; //double[] temp0= { 50,50,50,50,50}; //int n = temp0.Length; double[] temp0 = new double[n + 1]; for (int i = 0; i <= n; i++) { //temp0[i] = tempKrzep-i*dT; //temp0[i] = uI; //temp0[i] =Math.Exp(-deltaX*i); /*warunek początkowy T0 */ temp0[i] = Math.Exp(-deltaX * i); } double[] aVec = new double[n + 1]; double[] bVec = new double[n + 1]; double[] cVec = new double[n + 1]; double[] dVec = new double[n + 1]; double[,] tabH = new double[lbIteracji + 1, n + 1]; double[,] tabHKreska = new double[lbIteracji + 1, n + 1]; double[,] tabHDaszek = new double[lbIteracji + 1, n + 1]; double[,] tabH2Kreska = new double[lbIteracji + 1, n + 1]; double[,] tabH2Daszek = new double[lbIteracji + 1, n + 1]; int[] tabTx = new int[n + 1]; /*tablica, w której zapisane są czasy tx topnienia dla danego punktu x*/ double suma = 0; int j = 1; int l = 990; double[] temperatury = new double[n + 1]; funkcje.MetodaThomasa thomas = new funkcje.MetodaThomasa(); /* obiekt klasy MetodaThomasa do rozwiązania układu równań */ double[] wynikThomas; funkcje.Temperatura tempZEntalpii = new funkcje.Temperatura(); /* obiekt klasy Temperatura do wyznaczenia temperatury na podstawie entalpii */ double temp; funkcje.FunkcjaG funkcjaG = new funkcje.FunkcjaG(); /* obiekt klasy funkcjaG */ double wynikG; funkcje.Entalpia entZtemp = new funkcje.Entalpia(); double ent; funkcje.Kappa kap = new funkcje.Kappa(); double kappa; for (int i = 0; i <= n; i++) { tabTx[i] = lbIteracji; /* ustawiamy czas topnienia dla punktu x na lbIteracji */ } kappa = kap.kappa(lambdaL, lambdaS, aL, 1); entalpiaS = cS * roS * tempKrzep; entalpiaL = entalpiaS + kappa; for (int i = 0; i < temp0.Length; i++) { if (temp0[i] > tempKrzep) { tabH[0, i] = entZtemp.entalpia(temp0[i], tempKrzep, cL, roL, cS, roS, kappa); /* Etap 1: wyznaczamy entalpie w chwili 0 na podstawie T0*/ } else { tabH[0, i] = entZtemp.entalpia(temp0[i], tempKrzep, cL, roL, cS, roS, kappa); } } //Console.Write("tabH0[n-1]: {0}", tabH[0, 0]); /*Console.Write("tabH0: "); * for (int i = 0; i < n; i++) * Console.Write("{0} ", tabH[0, i]);*/ stalaSigma = 1 / (SpecialFunction.gamma(1 - alfa) * (1 - alfa) * Math.Pow(deltaT, alfa)); /* wartość funkcji sigma */ //for (int j = 1; j < lbIteracji; j++) while (granica < l && j <= lbIteracji) { a = lambdaL / (cL * roL); /* Etap 2a: sprowadzamy całość do fazy ciekłej */ stalaA = a / (Math.Pow(deltaX, 2)); kappa = kap.kappa(lambdaL, lambdaS, aL, deltaT * j); entalpiaS = cS * roS * tempKrzep; entalpiaL = entalpiaS + kappa; for (int i = 0; i < temp0.Length; i++) { tabHKreska[j - 1, i] = Math.Max(tabH[j - 1, i], entalpiaL); } //Console.WriteLine(" "); //Console.Write("tabHKreska: "); //for (int i = 0; i < n; i++) // Console.Write("{0} ", tabHKreska[j-1, i]); //Console.Write("tabHKreska[n-1]: {0}", tabHKreska[j-1, 0]); aVec[0] = 0; for (int i = 1; i < n; i++) { aVec[i] = -stalaA; } aVec[n] = -2 * stalaA; bVec[0] = 1; for (int i = 1; i < n + 1; i++) { bVec[i] = stalaSigma + 2 * stalaA; } cVec[0] = 0; for (int i = 1; i < n; i++) { cVec[i] = -stalaA; } cVec[n] = 0; //u0 = Math.Exp(a*(j)*deltaT); u0 = Math.Exp(a * (j) * deltaT); dVec[0] = entZtemp.entalpia(u0, tempKrzep, cL, roL, cS, roS, kappa); /* obliczenie entalpii dla brzegowej temperatury u0 */ Console.WriteLine(dVec[0] > entalpiaL); for (int i = 1; i <= n; i++) { suma = 0; for (int it = 2; it <= j; it++) { suma = suma + (Math.Pow(it, 1 - alfa) - Math.Pow(it - 1, 1 - alfa)) * (tabHKreska[j - it + 1, i] - tabHKreska[j - it, i]); } dVec[i] = stalaSigma * tabHKreska[j - 1, i] - stalaSigma * suma + cL * roL * funkcjaG.g(i, tabTx[i], tabHKreska, j, stalaSigma, alfa, cL, cS, roL, roS, tempKrzep, entalpiaL, entalpiaS, kappa); } wynikThomas = thomas.nowa(aVec, bVec, cVec, dVec); /* rozwiązanie układu równań metodą Thomasa */ for (int i = 0; i <= n; i++) { tabHDaszek[j, i] = wynikThomas[i]; } //Console.Write("tabHDaszek[n-1]: {0}", tabHDaszek[j, 0]); //Console.WriteLine(" "); //Console.Write("tabHDaszek wyznaczone z Thomasa: "); //for (int i = 0; i < n; i++) // Console.Write("{0} ", tabHDaszek[j, i]); for (int i = 0; i <= n; i++) { tabHKreska[j, i] = tabHDaszek[j, i] + (tabH[j - 1, i] - tabHKreska[j - 1, i]); /* korekta entalpii */ } //Console.Write("tabHKreska[n-1]: {0}", tabHKreska[j, 0]); /* Console.WriteLine(" "); * Console.Write("tabHKreska po korekcie: "); * for (int i = 0; i < n; i++) * Console.Write("{0} ", tabHKreska[j, i]); */ a = lambdaS / (cS * roS); /* Etap 2b: sprowadzamy całość do fazy stałej */ stalaA = a / (Math.Pow(deltaX, 2)); for (int i = 0; i <= n; i++) { tabH2Kreska[j - 1, i] = Math.Min(tabHKreska[j, i], entalpiaS); } //Console.Write("tabH2Kreska[n-1]: {0}", tabH2Kreska[j-1, 0]); //Console.WriteLine(" "); //Console.Write("tabH2Kreska (minimum): "); //for (int i = 0; i < n; i++) // Console.Write("{0} ", tabH2Kreska[j-1, i]); aVec[0] = 0; for (int i = 1; i < n; i++) { aVec[i] = -stalaA; } aVec[n] = 0; for (int i = 0; i < n; i++) { bVec[i] = stalaSigma + 2 * stalaA; } bVec[n] = 1; cVec[0] = -2 * stalaA; for (int i = 1; i < n; i++) { cVec[i] = -stalaA; } cVec[n] = 0; for (int i = 0; i < n; i++) { suma = 0; for (int it = 2; it <= j; it++) { suma = suma + (Math.Pow(it, 1 - alfa) - Math.Pow(it - 1, 1 - alfa)) * (tabH2Kreska[j - it + 1, i] - tabH2Kreska[j - it, i]); } dVec[i] = stalaSigma * tabH2Kreska[j - 1, i] - stalaSigma * suma + cL * roL * funkcjaG.g(i, tabTx[i], tabH2Kreska, j, stalaSigma, alfa, cL, cS, roL, roS, tempKrzep, entalpiaL, entalpiaS, kappa);; } uI = Math.Exp(a * (j) * deltaT - 2); //uI =Math.Exp(a*(j)*deltaT-1); dVec[n] = entZtemp.entalpia(uI, tempKrzep, cL, roL, cS, roS, kappa); Console.WriteLine(uI); wynikThomas = thomas.nowa(aVec, bVec, cVec, dVec); /* rozwiązanie układu równań metodą Thomasa */ for (int i = 0; i <= n; i++) { tabH2Daszek[j, i] = wynikThomas[i]; } //Console.Write("tabH2Daszek[n-1]: {0}", tabH2Daszek[j, 0]); //Console.WriteLine(" "); // Console.Write("tabH2Daszek z thomasa: "); // for (int i = 0; i < n; i++) // Console.Write("{0} ", tabH2Daszek[j, i]); for (int i = 0; i <= n; i++) { tabH[j, i] = tabH2Daszek[j, i] + (tabHKreska[j, i] - tabH2Kreska[j - 1, i]); /* korekta */ } //Console.Write("tabH[n-1]: {0}", tabH[j, 0]); //Console.WriteLine(" "); //Console.Write("tabH po korekcie: "); //for (int i = 0; i < n; i++) //{ // Console.Write("{0} ", tabH[j, i]); //} //Console.WriteLine(" "); //Console.Write("temp tabH: "); //for (int i = 0; i < n; i++) //{ // Console.Write("{0} ", tempZEntalpii.temperatura(tabH[j, i])); //} //Console.WriteLine(" "); for (int i = 0; i <= n; i++) { if (tabH[j, i] > entalpiaS && tabH[j - 1, i] <= entalpiaS) { tabTx[i] = j; } } for (int i = 1; i < n; i++) { if (tabH[j, i] <= entalpiaS && tabH[j, i + 1] <= entalpiaS && tabH[j, i - 1] > entalpiaS) { granica = i; } } Console.WriteLine("{0}", j); j++; } Console.Write("tabH: "); for (int i = 0; i <= n; i++) { Console.Write("{0} ", tabH[j - 1, i]); } string path = @"C:\Users\agata.chmielowska\Desktop\AlgorytmC1zestawDanych\Wyniki\entalpie.csv"; System.IO.StreamWriter str = new System.IO.StreamWriter(path, false); for (int i = 0; i <= n; i++) { str.WriteLine("{0} ", tabH[j - 1, i]); } str.Close(); Console.WriteLine(""); Console.Write("temp tabH: "); for (int i = 0; i <= n; i++) { temperatury[i] = tempZEntalpii.temperatura(tabH[j - 1, i], tempKrzep, cL, roL, cS, roS, kappa, entalpiaL, entalpiaS); Console.Write("{0} ", temperatury[i]); } path = @"C:\Users\agata.chmielowska\Desktop\AlgorytmC1zestawDanych\Wyniki\temperatury.csv"; str = new System.IO.StreamWriter(path, false); for (int i = 0; i <= n; i++) { str.WriteLine("{0} ", temperatury[i]); } str.Close(); Console.WriteLine(""); Console.Write("Wartość tabTx:"); for (int i = 0; i <= n; i++) { Console.Write("{0} ", tabTx[i]); } path = @"C:\Users\agata.chmielowska\Desktop\AlgorytmC1zestawDanych\Wyniki\granica.csv"; str = new System.IO.StreamWriter(path, false); for (int i = 0; i <= n; i++) { str.WriteLine("{0} ", tabTx[i] * deltaT); } str.Close(); Console.WriteLine(""); Console.WriteLine("Program zakończył działanie po {0} iteracjach", j - 1); Console.WriteLine(""); Console.WriteLine("Granica znajduje sie w punkcie: {0}", granica); temp = tempZEntalpii.temperatura(entalpiaL, tempKrzep, cL, roL, cS, roS, kappa, entalpiaL, entalpiaS); Console.WriteLine("Wartosc temperatury: {0}", temp); wynikG = funkcjaG.g(5, tabTx[5], tabH, 20, stalaSigma, alfa, cL, cS, roL, roS, tempKrzep, entalpiaL, entalpiaS, kappa); Console.WriteLine("Wartość g: {0} ", wynikG); Console.WriteLine("Wartość funkcji gamma: {0} ", SpecialFunction.gamma(0.5)); Console.ReadKey(); return; }
private void button2_Click(object sender, EventArgs e) { alfa = Convert.ToDouble(textBox4.Text); st_sv = size - 1; for (int j = 0; j < size; ++j) { ni[j] = 0; } dataGridView2.Rows.Clear(); dataGridView3.Rows.Clear(); dataGridView2.RowCount = size; dataGridView2.ColumnCount = 1; dataGridView3.ColumnCount = size + 2; dataGridView3.RowCount = 4; dataGridView2.Rows[0].Cells[0].Value = Convert.ToString(Int64.MinValue); for (int j = 1; j < size; ++j) { dataGridView2.Rows.Add(); board[j] = (min + ((max - min) / size) * j); dataGridView2.Rows[j].Cells[0].Value = Convert.ToString(board[j]); } dataGridView2.Rows[size].Cells[0].Value = Convert.ToString(Int64.MaxValue); for (int j = 0; j < size + 1; ++j) { zi[j] = (Convert.ToDouble(dataGridView2.Rows[j].Cells[0].Value)); dataGridView3.Rows[0].Cells[j + 1].Value = Convert.ToString(zi[j]); } Refresh(); for (int i = 0; i < n; i++) { for (int j = 1; j < size + 1; j++) { if ((ksi[i] <= zi[j]) && (ksi[i] >= zi[j - 1])) { ni[j - 1]++; break; } } } double R0 = 0; double tt = 0; double pp = 0; dataGridView3.Rows[1].Cells[0].Value = Convert.ToString("nj"); dataGridView3.Rows[2].Cells[0].Value = Convert.ToString("qj"); dataGridView3.Rows[3].Cells[0].Value = Convert.ToString("R0"); for (int j = 0; j < size; j++) { dataGridView3.Rows[1].Cells[j + 2].Value = Convert.ToString(ni[j]); if (zi[j] < 0) { tt = 1 - Math.Pow(Math.E, 0); } else { tt = 1 - Math.Pow(Math.E, -lambda * (zi[j])); } if (zi[j + 1] < 0) { pp = 1 - Math.Pow(Math.E, 0); } else { pp = 1 - Math.Pow(Math.E, -lambda * (zi[j + 1])); } dataGridView3.Rows[2].Cells[j + 2].Value = (pp - tt); R0 += Math.Pow(ni[j] - n * (pp - tt), 2) / (n * (pp - tt)); dataGridView3.Rows[3].Cells[j + 2].Value = R0; } label5.Text = Convert.ToString(R0); double FR0 = 0; double xi2 = 0; double R0_ = R0; R0 = 0; int jj = 0; chart1.Series["Series1"].Points.Clear(); while (R0 < R0_) { R0 = jj * 0.2; for (int i = 1; i < n; i++) { xi2 += R0 / (2 * n) * Math.Pow(2, -st_sv / 2) * Math.Pow(SpecialFunction.gamma(st_sv / 2), -1) * (Math.Pow(Math.E, -(R0 * (i - 1) / n) / 2) * Math.Pow((R0 * (i - 1) / n), st_sv / 2 - 1) + Math.Pow(Math.E, -(R0 * i / n) / 2) * Math.Pow((R0 * i / n), st_sv / 2 - 1)); } chart1.Series["Series1"].Points.AddXY(R0, xi2); xi2 = 0; jj++; } for (int i = 1; i < n; i++) { xi2 += R0_ / (2 * n) * Math.Pow(2, -st_sv / 2) * Math.Pow(SpecialFunction.gamma(st_sv / 2), -1) * (Math.Pow(Math.E, -(R0_ * (i - 1) / n) / 2) * Math.Pow((R0_ * (i - 1) / n), st_sv / 2 - 1) + Math.Pow(Math.E, -(R0_ * i / n) / 2) * Math.Pow((R0_ * i / n), st_sv / 2 - 1)); } FR0 = 1 - xi2; label8.Text = Convert.ToString(FR0); if (FR0 > alfa) { label9.Text = Convert.ToString("Гипотеза принята"); } else { label9.Text = Convert.ToString("Гипотеза отвержена"); } R0 = 0; }
public bool IsAWitnessByMI(IList <Label> witness, int group, double threshold)//BN用,PCAlgorithm { double MI = 0; double m = 0; for (int i = 0; i < Math.Pow(2, witness.Count); ++i) { //初始化 int numberOfXTrue = 0; int numberOfXFalse = 0; int numberOfYTrue = 0; int numberOfYFalse = 0; int numberOfXTrueYTrue = 0; int numberOfXTrueYFalse = 0; int numberOfXFalseYTrue = 0; int numberOfXFalseAYFalse = 0; int N = 0; int numberOfZ = 0; Labelset labelset = new Labelset(witness, i); //统计数量信息 foreach (Sentence sentence in Variable.Sentences) { foreach (Annotation annotation in sentence.AnnotaitonGroups[group].AnnotatorAnnotationDic.Values) { ++N; if (annotation.IsAccordingToLabelset(labelset)) { ++numberOfZ; if (annotation.Labels[First]) { ++numberOfXTrue; if (annotation.Labels[Second]) { ++numberOfYTrue; ++numberOfXTrueYTrue; } else { ++numberOfYFalse; ++numberOfXTrueYFalse; } } else { ++numberOfXFalse; if (annotation.Labels[Second]) { ++numberOfYTrue; ++numberOfXFalseYTrue; } else { ++numberOfYFalse; ++numberOfXFalseAYFalse; } } } } } MI += getConditionalMI(numberOfXTrue, numberOfXFalse, numberOfYTrue, numberOfYFalse, numberOfXTrueYTrue, numberOfXTrueYFalse, numberOfXFalseYTrue, numberOfXFalseAYFalse, numberOfZ, N); m = N; } return(SpecialFunction.chisqc(Math.Pow(2, witness.Count), 2 * m * MI) >= threshold);//(右尾面积)越小越有联系(不独立),越大越独立 }
public static void setSpecialHandler(SpecialFunction myFunction) { var button = GameObject.Find("SpecialButton").GetComponent <SpecialButton> (); button.SpecialCallback += myFunction; }
public SpecialFunctionIndex(SpecialFunction specialFunction, BaseIndex baseIndex) { SpecialFunction = specialFunction; Index = baseIndex; }
/// <summary> /// Symmetric tridiagonal QL algorithm. /// </summary> private void SymmetricDiagonalize() { // This is derived from the Algol procedures tql2, by // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for // Auto. Comp., Vol.ii-Linear Algebra, and the corresponding // Fortran subroutine in EISPACK. for (int i = 1; i < _n; i++) { _e[i - 1] = _e[i]; } _e[_n - 1] = 0.0; double f = 0.0; double tst1 = 0.0; double eps = SpecialFunction.PositiveRelativeAccuracy; for (int l = 0; l < _n; l++) { // Find small subdiagonal element tst1 = Math.Max(tst1, Math.Abs(_d[l]) + Math.Abs(_e[l])); int m = l; while (m < _n) { if (Math.Abs(_e[m]) <= eps * tst1) { break; } m++; } // If m == l, d[l] is an eigenvalue, // otherwise, iterate. if (m > l) { int iter = 0; do { iter = iter + 1; // (Could check iteration count here.) // Compute implicit shift double g = _d[l]; double p = (_d[l + 1] - g) / (2.0 * _e[l]); double r = SpecialFunction.Hypot(p, 1.0); if (p < 0) { r = -r; } _d[l] = _e[l] / (p + r); _d[l + 1] = _e[l] * (p + r); double dl1 = _d[l + 1]; double h = g - _d[l]; for (int i = l + 2; i < _n; i++) { _d[i] -= h; } f = f + h; // Implicit QL transformation. p = _d[m]; double c = 1.0; double c2 = c; double c3 = c; double el1 = _e[l + 1]; double s = 0.0; double s2 = 0.0; for (int i = m - 1; i >= l; i--) { c3 = c2; c2 = c; s2 = s; g = c * _e[i]; h = c * p; r = SpecialFunction.Hypot(p, _e[i]); _e[i + 1] = s * r; s = _e[i] / r; c = p / r; p = c * _d[i] - s * g; _d[i + 1] = h + s * (c * g + s * _d[i]); // Accumulate transformation. for (int k = 0; k < _n; k++) { h = _V[k][i + 1]; _V[k][i + 1] = s * _V[k][i] + c * h; _V[k][i] = c * _V[k][i] - s * h; } } p = (-s) * s2 * c3 * el1 * _e[l] / dl1; _e[l] = s * p; _d[l] = c * p; // Check for convergence. } while (Math.Abs(_e[l]) > eps * tst1); } _d[l] = _d[l] + f; _e[l] = 0.0; } // Sort eigenvalues and corresponding vectors. for (int i = 0; i < _n - 1; i++) { int k = i; double p = _d[i]; for (int j = i + 1; j < _n; j++) { if (_d[j] < p) { k = j; p = _d[j]; } } if (k != i) { _d[k] = _d[i]; _d[i] = p; for (int j = 0; j < _n; j++) { p = _V[j][i]; _V[j][i] = _V[j][k]; _V[j][k] = p; } } } }
double N(double x) { return(0.5 * (1.0 + SpecialFunction.erf(x / Math.Sqrt(2.0)))); }