public void Init(LLNAModel model) { var phiVal = (double)1 / (double)model.K; var logPhiVal = -Math.Log(model.K); Phi.SetValue(phiVal); LogPhi.SetValue(logPhiVal); Zeta = 10; int i = 0; for (i = 0; i < (model.K - 1); i++) { Nu[i] = 10; Lambda[i] = 0; } Nu[i] = 0; Lambda[i] = 0; NIter = 0; LHood = 0; for (i = 0; i < 4; i++) { _temp.Add(Vector <double> .Build.Dense(model.K - 1)); } }
internal B(Phi phi, uint metadata, uint collectionID, B nextBlock) // check whether it is faster with ref or without ref for nextBlock. { if (phi == Phi.RightEnd) { omega = 1; } /// Following method has 2 ints and one extra read on /// nextBlock.lambda. I prefered this method over `copying /// all items satisfying the condition to a list and /// converting a list to array` because this method has /// less footprints and copies lambda only once. int i = 1; foreach (var item in nextBlock.lambda) { if (item.phi != Phi.LeftEnd) { i++; } } _lambda = new Lambda[i]; _lambda[0] = new Lambda(phi: phi, atI: metadata, collectionID: collectionID); i = 1; foreach (var item in nextBlock.lambda) { if (item.phi != Phi.LeftEnd) { _lambda[i++] = new Lambda(phi: Phi.Middle, atI: item.atI, collectionID: collectionID); } } }
/// <summary> /// Represents the interval intersecting with /// the e of corresponding keyBookmark. /// <para>For intervals of possibly different types, /// it is recommended to define this generic type /// parameter in terms of Lowest Common Denominator. /// </para> /// </summary> /// <param name="phi">The intersection type of interval /// wtih e of corresponding keyBookmark.</param> /// <param name="atI">Descriptive hashKey of the intereval.</param> internal Lambda(Phi phi, uint atI, uint collectionID) : this() { this.phi = phi; this.atI = atI; this.collectionID = collectionID; }
internal B(Phi phi, uint atI, uint collectionID, B nextBookmark) { mu = nextBookmark.mu; omega = 0; switch (phi) { case Phi.LeftEnd: _lambda = new Lambda[] { new Lambda(phi: Phi.LeftEnd, atI: atI, collectionID: collectionID) }; break; // I don't think this condition would be possibly ever met :) case Phi.Middle: mu++; break; case Phi.RightEnd: omega++; _lambda = new Lambda[] { new Lambda(phi: Phi.RightEnd, atI: atI, collectionID: collectionID) }; break; } /*foreach (var item in nextBookmark.lambda) * if (item.phi == false) * mu++;*/ mu += nextBookmark.omega; }
private void Xoa() { try { if (vtIndex != -1) //khi click lên tiêu đề header của datagrid thì bỏ qua { if (MSG.BanCoChacChanMuonXoaKhong() == System.Windows.Forms.DialogResult.Yes) { Phi temp = Utils.DataGridViewRow_to_Phi(DataGridView.Rows[vtIndex]); int kq = PhiBiz.DeletePhi(temp); //if (kq > 0) MSG.XoaThanhCong(); //else MSG.XoaThatBai(); if (kq <= 0) { MSG.XoaThatBai(); } HienThi(); } } } catch (Exception ex) { MSG.Error(ex); } }
private B(ushort omega, Lambda[] lambda, Phi phi, uint hashKey, uint collectionID) { this.omega = phi == Phi.RightEnd ? (ushort)(omega + 1) : omega; _lambda = new Lambda[lambda.Length + 1]; Array.Copy(lambda, _lambda, lambda.Length); _lambda[lambda.Length] = new Lambda(phi: phi, atI: hashKey, collectionID: collectionID); }
public static Phi DataGridViewRow_to_Phi(System.Windows.Forms.DataGridViewRow Input) { Phi kq = new Phi(); kq.MaPhi = Input.Cells["MaPhi"].Value.ToString(); kq.TenPhi = Input.Cells["TenPhi"].Value.ToString(); return(kq); }
protected override IDataFlowGraphExpressionNode Visit(Phi phi) { var names = phi.AssignedNames.Select(n => Visit(new Variable(n))).ToArray(); var op = new PhiOp(Guid.NewGuid(), names, phi.SSA); _dataFlowGraph._ops.Add(op); return(op); }
protected override BaseExpression Visit(Phi phi) { foreach (var name in phi.AssignedNames) { Add(name); } return(phi); }
public void FieldsCanBeWeldIntoParts() { var contentItem = _manager.New(DefaultAlphaName); var part = contentItem.As <FlavoredPart>(); var field = new Phi(); part.Weld(field); Assert.That(part.Has(typeof(Phi), "Phi")); }
public void Phi_Hash() { var hasher = new Phi(); var hash = new byte[32]; hasher.Digest(testValue, hash); var result = hash.ToHexString(); Assert.Equal("5ba2b8af7b58e359e98087ff8860ded5cdb72adcb46fee05151db1d235c81918", result); }
private B(ushort omega, Lambda[] lambda, uint atI, Phi phi, uint collectionID) { this.omega = omega; _lambda = new Lambda[lambda.Length + 1]; Array.Copy(lambda, _lambda, lambda.Length); _lambda[lambda.Length] = new Lambda(phi: phi, atI: atI, collectionID: collectionID); if (phi == Phi.RightEnd) { this.omega++; } }
public void bind_add_method_factory_extension_generic() { // Demonstrates that a generic interface implementation can // supply add methods PropertyTreeReader pt = LoadContent("phi.xml"); Assert.True(pt.Read()); Phi p = pt.Bind <Phi>(); Assert.NotNull(p.G); }
public void updateTime(float t, float measuredAccel) // t is the time to propagate { // Variable time propigation // Basic equations to simulate // xnew = Phi * xold // Pnew = Phi * Pold * PhiT + Int [Phi*G*Q*GT*PhiT] * dt timeUpdateSetPrevious(); // Setup the Phi and PhiTranspose //Phi.identity();// Depends on time, overkill for this example. Only need to rewrite the same elements Phi[0][1] = t; Phi[0][2] = -t * t * 0.5f; Phi[1][2] = -t; //PhiTranspose.identity();// Depends on time, overkill for this example. Only need to rewrite the same elements PhiTranspose[1][0] = t; PhiTranspose[2][0] = -t * t * 0.5f; PhiTranspose[2][1] = -t; TVectorN <3, float>& X = *pX; TVectorN <3, float>& Xprev = *pXprev; // Update the state vector. Phi.transform(Xprev, ref X); // xnew = Phi * xold X[0] += measuredAccel * t * t * 0.5f; // These will not be here for an eerror state Kalman Filter X[1] += measuredAccel * t; // These will not be here for an eerror state Kalman Filter TMatrixMxN <3, 3, float>& P = *pP; // Points to Current Covariance matrix TMatrixMxN <3, 3, float>& Pprev = *pPprev; // Points to Previous Covariance matrix // Now update teh covariance matrix. Yay lots of temps. TMatrixMxN <3, 3, float> temp33; temp33.mul(Phi, Pprev); P.mul(temp33, PhiTranspose); // Since Q and G are independent of time can make into one easy vector the is integrated by hand const float Q11 = timePropNoiseVector[0] * timePropNoiseVector[0]; const float Q22 = timePropNoiseVector[1] * timePropNoiseVector[1]; //const float Q12 = 0.0f * timePropNoiseVector[0] * timePropNoiseVector[1]; 0.0f means tehy are uncorrelated temp33[0][0] = (Q11 / 3.0f + Q22 * t * t / 20.0f) * t * t * t; temp33[0][1] = (Q11 * 0.5f + Q22 * t * t / 8.0f) * t * t; temp33[0][2] = -Q22 * t * t * t / 6.0f; temp33[1][0] = temp33[0][1]; temp33[1][1] = (Q11 + Q22 * t * t / 3.0f) * t; temp33[1][2] = -Q22 * t * t * 0.5f; temp33[2][0] = temp33[0][2]; temp33[2][1] = temp33[1][2]; temp33[2][2] = Q22 * t; P += temp33; }
public void PartGetReturnsFieldWithName() { var contentItem = _manager.New(DefaultAlphaName); var part = contentItem.As <FlavoredPart>(); var field = new Phi(); part.Weld(field); var phi = part.Get(typeof(Phi), "Phi"); var phi2 = part.Get(typeof(Phi), "Phi2"); Assert.That(phi.Name, Is.EqualTo("Phi")); Assert.That(phi2, Is.Null); }
public frmXuLyDMPhi(DataGridViewRow dgvr) {//Sửa InitializeComponent(); try { Them = false; Phi temp = Utils.DataGridViewRow_to_Phi(dgvr); txtMa.Text = temp.MaPhi; txtMa.Enabled = false; txtTen.Text = temp.TenPhi; } catch { } }
protected override Type Visit(Phi phi) { var result = Type.Unassigned; foreach (var type in phi.AssignedNames.Select(_types.TypeOf)) { if (type.HasValue) { result |= type.Value; } } return(result); }
public static List <Phi> getListPhi() { List <Phi> kq = new List <Phi>(); string sql = "SELECT [MaPhi],[TenPhi] FROM [VNAAccounting].[dbo].[Phi]"; System.Data.DataTable dt = DAL.CSDL.hienthi(sql); for (int i = 0; i < dt.Rows.Count; i++) { Phi temp = new Phi(); temp.MaPhi = dt.Rows[i]["MaPhi"].ToString(); temp.TenPhi = dt.Rows[i]["TenPhi"].ToString(); kq.Add(temp); } return(kq); }
private void button3_Click(object sender, EventArgs e) { long message = Int32.Parse(m.Text); long qE = Int32.Parse(E.Text); long Q = Int32.Parse(q.Text); long P = Int32.Parse(p.Text); listBox2.Items.Clear(); string lajna = "φ(" + P.ToString() + "∙" + Q.ToString() + ")" + " = "; long Pz = P; long Qz = Q; P = Phi.phi((int)P); Q = Phi.phi((int)Q); long d = P * Q; lajna = lajna + P.ToString() + "∙" + Q.ToString() + " = " + d.ToString(); listBox2.Items.Add(lajna); lajna = d.ToString() + "d" + " ≡ " + "0"; listBox2.Items.Add(lajna); lajna = qE.ToString() + "d" + " ≡ " + "1"; listBox2.Items.Add(lajna); listBox2.Items.Add("-------------------------"); DHRovnice rovnice = Inverze.Run(listBox2, d, qE); listBox2.Items.Add("--------------------------"); long umocneni = rovnice.Prava; lajna = "m ≡" + message + "^" + umocneni + "≡"; long c1 = message % Pz; long m1 = umocneni % Phi.phi((int)Pz); lajna = lajna + c1 + "^" + m1; listBox2.Items.Add(lajna); long finalni1 = Umocnovac.Run(listBox2, c1, m1, Pz); lajna = "m" + " ≡ " + finalni1 + " (mod" + Pz + ")"; listBox2.Items.Add(lajna); long c2 = message % Qz; long m2 = umocneni % Phi.phi((int)Qz); lajna = "m ≡" + message + "^" + umocneni + "≡" + c2 + "^" + m2; listBox2.Items.Add(lajna); long finalni2 = Umocnovac.Run(listBox2, c2, m2, Qz); lajna = "m" + " ≡ " + finalni2 + " (mod" + Qz + ")"; listBox2.Items.Add(lajna); listBox2.Items.Add("-----------------------------"); Rovnice.Run(listBox2, finalni1, Pz, finalni2, Qz); }
public KalmanFilter() { pX = &Xa; pXprev = &Xb; pP = &Pa; pPprev = &Pb; Xa.zero(); Xb.zero(); Z.zero(); F.zero(); F[0][1] = 1.0f; F[1][2] = -1.0f; Phi.identity(); // Depends on time PhiTranspose.identity(); // Depends on time G.zero(); G[1][0] = 1.0f; G[2][1] = 1.0f; GTranspose.zero(); GTranspose[0][1] = 1.0f; GTranspose[1][2] = 1.0f; H.zero(); H[0][0] = 1.0f; HTranspose.zero(); HTranspose[0][0] = 1.0f; K.zero(); // gain // The above will not change for our filter. For a general filter they will. // These are the intial covariance estimates, feel free to muck with them. Pa.zero(); Pa[0][0] = 0.05f * 0.05f; Pa[1][1] = 0.5f * 0.5f; Pa[2][2] = 10.0f * 10.0f; Pb = Pa; // The following will change to appropriate values for noise. timePropNoiseVector[0] = 0.01f; // m / s^2 timePropNoiseVector[1] = 0.10f; // m / s^2 / s measurmentNoiseVector[0] = 0.005f; // =1/2 cm; }
public static void phi_values_test( ) //****************************************************************************80 // // Purpose: // // PHI_VALUES_TEST tests PHI_VALUES. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 09 February 2007 // // Author: // // John Burkardt // { int fn = 0; int n = 0; Console.WriteLine(""); Console.WriteLine("PHI_VALUES_TEST:"); Console.WriteLine(" PHI_VALUES returns values of"); Console.WriteLine(" the PHI function."); Console.WriteLine(""); Console.WriteLine(" N PHI(N)"); Console.WriteLine(""); int n_data = 0; for ( ; ;) { Phi.phi_values(ref n_data, ref n, ref fn); if (n_data == 0) { break; } Console.WriteLine(" " + n.ToString().PadLeft(6) + " " + fn.ToString().PadLeft(10) + ""); } }
public virtual TResult Visit(BaseExpression expression) { return(expression switch { Phi a => Visit(a), Increment a => Visit(a), Decrement a => Visit(a), ErrorExpression a => Visit(a), Bracketed a => Visit(a), Abs a => Visit(a), Sqrt a => Visit(a), Sine a => Visit(a), Cosine a => Visit(a), Tangent a => Visit(a), ArcSine a => Visit(a), ArcCos a => Visit(a), ArcTan a => Visit(a), PostIncrement a => Visit(a), PreIncrement a => Visit(a), PostDecrement a => Visit(a), PreDecrement a => Visit(a), Add a => Visit(a), Subtract a => Visit(a), Multiply a => Visit(a), Divide a => Visit(a), Modulo a => Visit(a), Negate a => Visit(a), Exponent a => Visit(a), Or a => Visit(a), And a => Visit(a), Not a => Visit(a), Factorial a => Visit(a), Variable a => Visit(a), ConstantNumber a => Visit(a), ConstantString a => Visit(a), EqualTo a => Visit(a), NotEqualTo a => Visit(a), GreaterThan a => Visit(a), GreaterThanEqualTo a => Visit(a), LessThan a => Visit(a), LessThanEqualTo a => Visit(a), _ => VisitUnknown(expression) });
internal B(Phi phi, uint atI, uint collectionID) { mu = 0; omega = 0; switch (phi) { case Phi.LeftEnd: _lambda = new Lambda[] { new Lambda(phi: Phi.LeftEnd, atI: atI, collectionID: collectionID) }; break; case Phi.Middle: mu = 1; break; case Phi.RightEnd: omega = 1; _lambda = new Lambda[] { new Lambda(phi: Phi.RightEnd, atI: atI, collectionID: collectionID) }; break; } }
private void btnDongY_Click(object sender, EventArgs e) { if (Them) {//Thêm Phi temp = new Phi(); temp.MaPhi = txtMa.Text; temp.TenPhi = txtTen.Text; if (!CheckLoi(temp)) { return; } int kq = PhiBiz.AddPhi(temp); if (kq > 0) { MSG.ThemThanhCong(); } else { MSG.ThemThatBai(); } } else {//Sửa Phi temp = new Phi(); temp.MaPhi = txtMa.Text; temp.TenPhi = txtTen.Text; int kq = PhiBiz.EditPhi(temp); if (kq > 0) { MSG.SuaThanhCong(); } else { MSG.SuaThatBai(); } } this.Close(); }
bool CheckLoi(Phi data) { bool kq = true; //mã phí rỗng if (string.IsNullOrEmpty(data.MaPhi)) { MSG.ErrorStand("Bạn chưa nhập mã phí!"); txtMa.Focus(); return(false); } //mã phí đã có trong cơ sở dữ liệu foreach (Phi item in frmDMPhi.Ldata) { if (item.MaPhi.ToUpper().Equals(txtMa.Text.ToUpper())) { MSG.ErrorStand("Mã phí đã có trong cơ sở dữ liệu!"); txtMa.Focus(); return(false); } } return(kq); }
protected override bool Visit(Phi phi) => phi.AssignedNames.All(_bools.Contains);
public override string ToString() { string text = ""; return(text + BienSo + "#" + CaTruc.ToString() + "#" + GioQuaTram + "#" + LanXe.ToString() + "#" + MSNV + "#" + NgayQuaTram + "#" + Phi.ToString() + "#" + PLVe.ToString() + "#" + PLXeSau.ToString() + "#" + PLXeTruoc.ToString() + "#" + PTTT.ToString() + "#" + SoVe.ToString() + "#" + TenHinhXe.ToString() + "#" + TTXeQua.ToString()); }
public void Train(DenseMatrix X, DenseVector d, DenseVector Kd) { int R = X.RowCount; int N = X.ColumnCount; int U = 0; //the number of neurons in the structure var c = new DenseMatrix(R, 1); var sigma = new DenseMatrix(R, 1); var Q = new DenseMatrix((R + 1), (R + 1)); var O = new DenseMatrix(1, (R + 1)); var pT_n = new DenseMatrix((R + 1), 1); double maxPhi = 0; int maxIndex; var Psi = new DenseMatrix(N, 1); Console.WriteLine("Running..."); //for each observation n in X for (int i = 0; i < N; i++) { Console.WriteLine(100 * (i / (double)N) + "%"); var x = new DenseVector(R); X.Column(i, x); //if there are neurons in structure, //update structure recursively. if (U == 0) { c = (DenseMatrix)x.ToColumnMatrix(); sigma = new DenseMatrix(R, 1, SigmaZero); U = 1; Psi = CalculatePsi(X, c, sigma); UpdateStructure(X, Psi, d, ref Q, ref O); pT_n = (DenseMatrix) (CalculateGreatPsi((DenseMatrix)x.ToColumnMatrix(), (DenseMatrix)Psi.Row(i).ToRowMatrix())) .Transpose(); } else { StructureRecurse(X, Psi, d, i, ref Q, ref O, ref pT_n); } bool KeepSpinning = true; while (KeepSpinning) { //Calculate the error and if-part criteria double ee = pT_n.Multiply(O)[0, 0]; double approximationError = Math.Abs(d[i] - ee); DenseVector Phi; double SumPhi; CalculatePhi(x, c, sigma, out Phi, out SumPhi); maxPhi = Phi.Maximum(); maxIndex = Phi.MaximumIndex(); if (approximationError > delta) { if (maxPhi < threshold) { var tempSigma = new DenseVector(R); sigma.Column(maxIndex, tempSigma); double minSigma = tempSigma.Minimum(); int minIndex = tempSigma.MinimumIndex(); sigma[minIndex, maxIndex] = k_sigma * minSigma; Psi = CalculatePsi(X, c, sigma); UpdateStructure(X, Psi, d, ref Q, ref O); var psi = new DenseVector(Psi.ColumnCount); Psi.Row(i, psi); pT_n = (DenseMatrix) CalculateGreatPsi((DenseMatrix)x.ToColumnMatrix(), (DenseMatrix)psi.ToRowMatrix()) .Transpose(); } else { //add a new neuron and update strucutre double distance = 0; var cTemp = new DenseVector(R); var sigmaTemp = new DenseVector(R); //foreach input variable for (int j = 0; j < R; j++) { distance = Math.Abs(x[j] - c[j, 0]); int distanceIndex = 0; //foreach neuron past 1 for (int k = 1; k < U; k++) { if ((Math.Abs(x[j] - c[j, k])) < distance) { distanceIndex = k; distance = Math.Abs(x[j] - c[j, k]); } } if (distance < Kd[j]) { cTemp[j] = c[j, distanceIndex]; sigmaTemp[j] = sigma[j, distanceIndex]; } else { cTemp[j] = x[j]; sigmaTemp[j] = distance; } } //end foreach c = (DenseMatrix)c.InsertColumn(c.ColumnCount - 1, cTemp); sigma = (DenseMatrix)sigma.InsertColumn(sigma.ColumnCount - 1, sigmaTemp); Psi = CalculatePsi(X, c, sigma); UpdateStructure(X, Psi, d, ref Q, ref O); U++; KeepSpinning = false; } } else { if (maxPhi < threshold) { var tempSigma = new DenseVector(R); sigma.Column(maxIndex, tempSigma); double minSigma = tempSigma.Minimum(); int minIndex = tempSigma.MinimumIndex(); sigma[minIndex, maxIndex] = k_sigma * minSigma; Psi = CalculatePsi(X, c, sigma); UpdateStructure(X, Psi, d, ref Q, ref O); var psi = new DenseVector(Psi.ColumnCount); Psi.Row(i, psi); pT_n = (DenseMatrix) CalculateGreatPsi((DenseMatrix)x.ToColumnMatrix(), (DenseMatrix)psi.ToRowMatrix()) .Transpose(); } else { KeepSpinning = false; } } } } out_C = c; out_O = O; out_Sigma = sigma; Console.WriteLine("Done."); }
public ModuleType GetModuleType(Planetbase.Module module) { return(Phi.GetPrivateField <ModuleType>(module, "mModuleType")); }
[NotNull] protected abstract TResult Visit([NotNull] Phi phi);