private MsiPropertyInfo(string name, int pid, Vt propertyType, string description, string valueFormatString = "{0}") { Name = name; Id = pid; _propertyType = propertyType; Description = description; Value = null; _valueFormatString = valueFormatString; }
public void Build(string[] Input) { try { Start = Input[0][0]; foreach (string s in Input) { if (s == string.Empty) { continue; } string[] tp = s.Split(new String[] { "→" }, StringSplitOptions.None); if (tp.Length != 2) { throw new Exception("产生式应该有且仅有一个→"); } if (tp[0].Length != 1 || !isVn(tp[0][0])) { throw new Exception("产生式左边应该是一个非终结符"); } char left = tp[0][0]; char empty = System.Configuration.ConfigurationManager.AppSettings["Empty"][0]; Vn.Add(left); string[] right = tp[1].Split('|'); for (int i = 0; i < right.Count(); ++i) { string part = right[i]; foreach (char c in part) { if (isVn(c)) { Vn.Add(c); } else { Vt.Add(c); } } Production p = new Production(left, part); if (!ProductionsMap.ContainsKey(p)) { Productions.Add(p); ProductionsMap.Add(p, ProductionsMap.Count() + 1); _ProductionsMap.Add(_ProductionsMap.Count() + 1, p); } } } } catch (Exception) { throw new Exception("输入不合法\n"); } }
public PendulumModelingResultViewModel(Tuple <List <double>, List <double>, List <double>, List <double> > numeric) { for (var i = 0; i < numeric.Item1.Count; ++i) { Thetat.Add(new ObservablePoint(numeric.Item1[i], numeric.Item2[i])); Vt.Add(new ObservablePoint(numeric.Item1[i], numeric.Item3[i])); E.Add(new ObservablePoint(numeric.Item1[i], numeric.Item4[i])); PhasePortrait.Add(new ObservablePoint(numeric.Item2[i], numeric.Item3[i])); } Collection.Add(new LineSeries() { Values = Thetat }); }
public HarmonicOscillatorModelingResultViewModel(Tuple <List <double>, List <double>, List <double>, List <double> > numeric) { for (var i = 0; i < numeric.Item1.Count; ++i) { Xt.Add(new ObservablePoint(numeric.Item1[i], numeric.Item2[i])); Vt.Add(new ObservablePoint(numeric.Item1[i], numeric.Item3[i])); E.Add(new ObservablePoint(numeric.Item1[i], numeric.Item4[i])); Vx.Add(new ObservablePoint(numeric.Item2[i], numeric.Item3[i])); } Collection.Add(new LineSeries() { Values = Xt }); }
private MsiPropertyInfo(int id, object value) { Id = id; Value = value; var prototype = GetPropertyInfoById(id); if (prototype != null) { Name = prototype.Name; _propertyType = prototype._propertyType; Description = prototype.Description; _valueFormatString = prototype._valueFormatString; switch (_propertyType) { case Vt.Filetime: //everything is coming from wix as a string, need to submit patch to wix: // _value = DateTime.FromFileTime((long)_value); break; case Vt.I2: case Vt.I4: if (Value is string && Value != null && ((string)Value).Length > 0) { try { Value = Int32.Parse((string)Value); } catch (FormatException) {} } break; } } else { Name = "non-standard"; _propertyType = Vt.Empty; Description = "Unknown."; } }
private static Vt GetVt(SyntaxTree syntaxTree) { // <Vt> ::= "null" | "identifier" | "number" | "constString" | constString ; Vt vt = null; if (syntaxTree.NodeType.Type == ContextfreeGrammarTreeNodeType.__Vt) { if (syntaxTree.Children[0].NodeType.Type == ContextfreeGrammarTreeNodeType.__nullLeave__) { //vt = new KeywordNull(); vt = null; } else if (syntaxTree.Children[0].NodeType.Type == ContextfreeGrammarTreeNodeType.__identifierLeave__) { vt = new KeywordIdentifier(); } else if (syntaxTree.Children[0].NodeType.Type == ContextfreeGrammarTreeNodeType.__numberLeave__) { vt = new KeywordNumber(); } else if (syntaxTree.Children[0].NodeType.Type == ContextfreeGrammarTreeNodeType.__constStringLeave__) { vt = new KeywordConstString(); } else if (syntaxTree.Children[0].NodeType.Type == ContextfreeGrammarTreeNodeType.constStringLeave__) { vt = GetConstString(syntaxTree.Children[0]); } else { throw new NotImplementedException(); } } return(vt); }
// SVD exhaustion alghoritm // reduction - threshold of nonexistent information public void SVDExhaustionAlghoritm(Matrix A, double reduction) { // min dimension int minSize = Math.Min(A.Row, A.Column); // vector norm squares u & v double utu = 1, vvt = 1; // singular numbers calculating for (int num = 0; num < minSize; num++) { // searching max row in A in ||.||2 int maxRow = A.NumberRowWithMaxNorm(out vvt); // if ||v|| = 0 if (Math.Sqrt(vvt) < CONST.EPS) { break; } Ut.Add(new double[A.Row]); Vt.Add(new double[A.Column]); // copy elements of max row to row in v for (int i = 0; i > A.Column; i++) { Vt[num][i] = A.Elem[maxRow - 1][i]; } // power method while (true) { double utuOld = utu; // vector u = A * vt / (v, vt) for (int i = 0; i < A.Row; i++) { Ut[num][i] = 0.0; for (int j = 0; j < A.Column; j++) { Ut[num][i] += A.Elem[i][j] * Vt[num][j]; } Ut[num][i] /= vvt; // vector u norm square utu += Ut[num][i] * Ut[num][i]; } // if dominative vector is found, then method breaks if (Math.Abs(utuOld - utu) / utu < CONST.EPS) { break; } vvt = 0.0; // vector v = ut * A / (ut, u) for (int i = 0; i < A.Column; i++) { Vt[num][i] = 0.0; for (int j = 0; j < A.Row; j++) { Vt[num][i] += A.Elem[j][i] * Ut[num][j]; } Vt[num][i] /= utu; vvt += Vt[num][i] * Vt[num][i]; } } // u & v norms utu = Math.Sqrt(utu); vvt = Math.Sqrt(vvt); // norm singular vectors and calculate singular number for (int i = 0; i < A.Row; i++) { Ut[num][i] /= utu; } for (int i = 0; i < A.Column; i++) { Vt[num][i] /= vvt; } // if singular number is less than reduction value then break SVD alghoritm if (utu * vvt < reduction) { Ut.RemoveAt(num); Vt.RemoveAt(num); break; } // else save singular number Sigma.Add(utu * vvt); // update matrix (exhaustion) for (int i = 0; i < A.Row; i++) { for (int j = 0; j < A.Column; j++) { A.Elem[i][j] -= Ut[num][i] * Sigma[num] * Vt[num][i]; } } } }
public override double[] Solve() { int m = A.RowCount; int n = A.ColCount; Debug.Assert(m >= n); IVector t = new SparseVector(n); for (int i = 0; i < m; ++i) { t[i] = 0; } IVector s = new SparseVector(n); IVector sy = new SparseVector(n); for (int i = 0; i < n; ++i) { s[i] = 0; } IVector s_old = s; IMatrix U; // U is a m x m orthogonal matrix IMatrix Vt; // V is a n x n orthogonal matrix IMatrix Sigma; // Sigma is a m x n diagonal matrix with non-negative real numbers on its diagonal SVD.Factorize(A, out U, out Sigma, out Vt); // A is a m x n matrix IMatrix Ut = U.Transpose(); IMatrix V = Vt.Transpose(); //SigmaInv is obtained by replacing every non-zero diagonal entry by its reciprocal and transposing the resulting matrix IMatrix SigmaInv = new SparseMatrix(m, n); for (int i = 0; i < n; ++i) // assuming m >= n { double sigma_i = Sigma[i, i]; if (sigma_i < epsilon) // model matrix A is rank deficient { throw new Exception("Near rank-deficient model matrix"); } SigmaInv[i, i] = 1.0 / sigma_i; } SigmaInv = SigmaInv.Transpose(); double[] W = new double[m]; for (int j = 0; j < mMaxIters; ++j) { Console.WriteLine("j: {0}", j); IVector z = new SparseVector(m); double[] g = new double[m]; double[] gprime = new double[m]; for (int k = 0; k < m; ++k) { g[k] = mLinkFunc.GetInvLink(t[k]); gprime[k] = mLinkFunc.GetInvLinkDerivative(t[k]); z[k] = t[k] + (b[k] - g[k]) / gprime[k]; } int tiny_weight_count = 0; for (int k = 0; k < m; ++k) { double w_kk = gprime[k] * gprime[k] / GetVariance(g[k]); W[k] = w_kk; if (w_kk < double.Epsilon * 2) { tiny_weight_count++; } } if (tiny_weight_count > 0) { Console.WriteLine("Warning: tiny weights encountered, (diag(W)) is too small"); } s_old = s; IMatrix UtW = new SparseMatrix(m, m); for (int k = 0; k < m; ++k) { for (int k2 = 0; k2 < m; ++k2) { UtW[k, k2] = Ut[k, k2] * W[k]; } } IMatrix UtWU = UtW.Multiply(U); // m x m positive definite matrix IMatrix L; // m x m lower triangular matrix Cholesky.Factorize(UtWU, out L); IMatrix Lt = L.Transpose(); // m x m upper triangular matrix IVector UtWz = UtW.Multiply(z); // m x 1 vector // (Ut * W * U) * s = Ut * W * z // L * Lt * s = Ut * W * z (Cholesky factorization on Ut * W * U) // L * sy = Ut * W * z, Lt * s = sy s = new SparseVector(n); for (int i = 0; i < n; ++i) { s[i] = 0; sy[i] = 0; } // forward solve sy for L * sy = Ut * W * z for (int i = 0; i < n; ++i) // since m >= n { double cross_prod = 0; for (int k = 0; k < i; ++k) { cross_prod += L[i, k] * sy[k]; } sy[i] = (UtWz[i] - cross_prod) / L[i, i]; } // backward solve s for Lt * s = sy for (int i = n - 1; i >= 0; --i) { double cross_prod = 0; for (int k = i + 1; k < n; ++k) { cross_prod += Lt[i, k] * s[k]; } s[i] = (sy[i] - cross_prod) / Lt[i, i]; } t = U.Multiply(s); if ((s_old.Minus(s)).Norm(2) < mTol) { break; } } IVector x = V.Multiply(SigmaInv).Multiply(Ut).Multiply(t); mX = new double[n]; for (int i = 0; i < n; ++i) { mX[i] = x[i]; } UpdateStatistics(W); return X; }