public void GenerateNewGGH(int dim, int l) { UiServices.SetBusyState(); GGH = GGH != null && GGH.dim == dim ? new GGHModel(dim, l, GGH.errorVector) : new GGHModel(dim, l); Paragraph paragraph = new Paragraph(); paragraph.Inlines.Add(new Bold(new Underline(new Run("** " + Languages.buttonGenerateNewCryptosystem + " **\r\n")))); paragraph.Inlines.Add(new Bold(new Run(Languages.labelPrivateKeyR + ":"))); paragraph.Inlines.Add(" " + GGH.privateKeyR + "\r\n"); paragraph.Inlines.Add(new Bold(new Run(Languages.labelPrivateKeyR1 + ":"))); paragraph.Inlines.Add(" " + GGH.privateKeyR1.ToStringLog() + "\r\n"); paragraph.Inlines.Add(new Bold(new Run(Languages.labelPublicKeyB + ":"))); paragraph.Inlines.Add(" " + GGH.publicKeyB + "\r\n"); paragraph.Inlines.Add(new Bold(new Run(Languages.labelPublicKeyB1 + ":"))); paragraph.Inlines.Add(" " + GGH.publicKeyB1.ToStringLog() + "\r\n"); paragraph.Inlines.Add(new Bold(new Run(Languages.labelUnimodularTransformationMatrix + ":"))); paragraph.Inlines.Add(" " + Lattice.LatticeTransformationToString() + "\r\n"); paragraph.Inlines.Add(new Bold(new Run(Languages.labelParameterL))); paragraph.Inlines.Add(" " + GGH.l + "\r\n"); paragraph.Inlines.Add(new Bold(new Run(Languages.labelErrorVector))); paragraph.Inlines.Add(" " + GGH.errorVector + "\r\n"); if (History.Document.Blocks.FirstBlock != null) { History.Document.Blocks.InsertBefore(History.Document.Blocks.FirstBlock, paragraph); } else { History.Document.Blocks.Add(paragraph); } NotifyPropertyChanged("ErrorVector"); }
public Lattice GetLattice() { global::System.IntPtr cPtr = pocketsphinxPINVOKE.Decoder_GetLattice(swigCPtr); Lattice ret = (cPtr == global::System.IntPtr.Zero) ? null : new Lattice(cPtr, false); return(ret); }
public void CountArray_WhenHasMatchedColor_ShouldReturnNumber() { // Arrange int width = 4, height = 4; Lattice[,] lattice = new Lattice[width, height]; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { lattice[i, j] = new Lattice(i, j, Color.Black); } } Color target = Color.White; int expected = 0; for (int i = 1; i < width - 1; i++) { lattice[i, 0].color = target; expected++; } Simulation simulation = new Simulation(); // Act int actual = simulation.CountColor(lattice, target); // Assert Assert.AreEqual(expected, actual, 0.001, "return different value"); }
public static void Main() { int typeB = 2; // Binomial Lattice Type int typeT = 3; // Trinomial Lattice Type int depth = 4; // Number of periods of time double val = 0.0; Lattice <double> lattice1 = new Lattice <double>(depth, typeB, val); Lattice <double> lattice2 = new Lattice <double>(depth, typeT, val); // Trinomial lattice with matrix NRows X NCols entries int NRows = 3; int NCols = 2; int startIndex = 1; int N = 10; // Number of time steps Matrix <double> nodeStructure = new Matrix <double>(NRows, NCols, startIndex, startIndex); Lattice <Matrix <double> > trinomialLattice = new Lattice <Matrix <double> >(N, typeT, nodeStructure); // Examining the vector at base of lattice Vector <double> base1 = lattice1.BasePyramidVector(); Vector <double> base2 = lattice2.BasePyramidVector(); Console.WriteLine(base1.Size); Console.WriteLine(base2.Size); }
public Tracker(TypedInstructionCollection instructions) { var graph = new ControlFlowGraph(instructions); var initialState = new Lattice(instructions, new State(0)); var data = new DataFlow <Lattice>(instructions, graph.Roots); Dictionary <BasicBlock, Lattice> lattices = data.Analyze(new Lattice.Functions(), initialState); m_states = new State[instructions.Length]; foreach (var entry in lattices) { BasicBlock block = entry.Key; if (block.Length > 0) { Lattice lattice = entry.Value; for (int index = block.First.Index; index <= block.Last.Index; ++index) // it'd be nice to assert that every index was set, but methods often have dead code so it's a little difficult { m_states[index] = lattice.State; lattice = lattice.Transform(index); } } } for (int index = 0; index < instructions.Length; ++index) { Log.DebugLine(this, "{0:X2}: {1}", instructions[index].Untyped.Offset, m_states[index]); } }
IEnumerator Move(Lattice startLat, Lattice endLat, int flag) { Vector3 start = startLat.Position; Vector3 end = endLat.Position; Vector3 speed = (end - start) / 5; for (int i = 0; i < 5; i++) { startLat.Chess.ChessGameObject.transform.Translate(speed, Space.Self); yield return(0); } startLat.Chess.ChessGameObject.transform.localPosition = start; if (flag == 0) { UpdateLattice(endLat); UpdateLattice(startLat); } else { UpdateLattice(endLat); UpdateLattice(startLat); endLat.Chess.MyAnimation.Play("ChessScale"); } StopCoroutine("Move"); }
public static Cardinal GetDirection(Lattice lattice, int Cell1ID, int Cell2ID) { var Cell1 = lattice.GetCell(Cell1ID); var Cell2 = lattice.GetCell(Cell2ID); return(GetDirection(lattice, Cell1, Cell2)); }
public double eval(IBlauPoint bp) { IBlauPoint qp = Lattice.quantize(bp); if (_evaluationData.ContainsKey(qp)) { return(_evaluationData[qp]); } throw new Exception("No evaluation found for specified IBlauPoint in BlauSpaceEvaluation!"); }
public void Evolve() { this._Lattice = _Lattice.Clone(); int sz = _Lattice.Size; for (int i = 0; i < sz; i++) { _Lattice[i] = _Rule.Next(_Lattice[i - 1], _Lattice[i], _Lattice[i + 1]); } }
public void FixedUpdate(Matrix View, Matrix Projection) { Lattice.FixedUpdate( ); LatticePointControl.Update(Device, View, Projection); for (int i = 0; i < LatticePoint.Count; i++) { var point = LatticePoint[i]; point.Position = Lattice.LatticeData[i].Value.Position; point.DrawAllSubSet(View, Projection); } }
// Print a lattice // public void printLatticeInExcel<T>(Lattice<T> lattice, Vector<T> xarr, Vector<T> yarr, string SheetName) public void printLatticeInExcel(Lattice <double> lattice, Vector <double> xarr, string SheetName) { List <string> rowlabels = new List <string>(); for (int i = xarr.MinIndex; i <= xarr.MaxIndex; i++) { rowlabels.Add(xarr[i].ToString()); } excel.AddLattice(SheetName, lattice, rowlabels); }
// Add Lattice to the spreadsheet with row and column labels. public void AddLattice(string name, Lattice <double> lattice, List <string> rowLabels) { try { // Check label count vs. matrix. /* if (lattice.Columns != columnLabels.Count) * { * throw (new IndexOutOfRangeException("Count mismatch between # matrix columns and # column labels")); * } * if (lattice.Rows != rowLabels.Count) * { * throw (new IndexOutOfRangeException("Count mismatch between # matrix rows and # row labels")); * } */ // Add sheet. Excel.Workbook pWorkbook; Excel.Worksheet pSheet; if (pExcel.ActiveWorkbook == null) { pWorkbook = (Excel.Workbook)InvokeMethodInternational(pExcel.Workbooks, "Add", Excel.XlWBATemplate.xlWBATWorksheet); pSheet = (Excel.Worksheet)pWorkbook.ActiveSheet; } else { pWorkbook = pExcel.ActiveWorkbook; pSheet = (Excel.Worksheet)InvokeMethodInternational(pWorkbook.Worksheets, "Add", Type.Missing, Type.Missing, 1, Type.Missing); } pSheet.Name = name; // Add row labels + values. int sheetColumn = 1; int sheetRow = 1; for (int i = lattice.MinIndex; i <= lattice.MaxIndex; i++) { Vector <double> row = lattice.PyramidVector(i); ToSheetHorizontal <double>(pSheet, sheetRow, sheetColumn, rowLabels[i - lattice.MinIndex], row); sheetRow++; } for (int i = lattice.MinIndex; i <= lattice.MaxIndex; i++) { Vector <double> row = lattice.PyramidVector(i); ToSheetHorizontal <double>(pSheet, sheetRow, sheetColumn, rowLabels[i], row); sheetRow++; // sheetColumn++; } } catch (IndexOutOfRangeException e) { Console.WriteLine("Exception: " + e); } }
public static void Main() { int typeB = 2; // Binomial Lattice Type int typeT = 3; // Trinomial Lattice Type int depth = 4; // Number of periods of time double val = 4.0; Lattice <double> lattice1 = new Lattice <double>(depth, typeB, val); Lattice <double> lattice2 = new Lattice <double>(depth, typeT, val); // Examining the vector at base of lattice Vector <double> base1 = lattice1.BasePyramidVector(); Vector <double> base2 = lattice2.BasePyramidVector(); // Print columms of lattice for (int j = lattice1.MinIndex; j <= lattice1.MaxIndex; j++) { lattice1.PyramidVector(j).print(); } string s = Console.ReadLine(); // Arrays int startIndex = lattice1.MinIndex; Vector <double> xarr = new Vector <double>(depth + 1, startIndex); xarr[xarr.MinIndex] = 0.0; double T = 1.0; int NT = 10; double delta_T = T / NT; for (int j = xarr.MinIndex + 1; j <= xarr.MaxIndex; j++) { xarr[j] = xarr[j - 1] + delta_T; } Console.WriteLine(base1.Size); Console.WriteLine(base2.Size); ExcelMechanisms exl = new ExcelMechanisms(); try { exl.printLatticeInExcel(lattice2, xarr, "Lattice"); } catch (Exception e) { Console.WriteLine(e); } }
public void set(IBlauPoint p, double val) { IBlauPoint qp = Lattice.quantize(p); if (_evaluationData.ContainsKey(qp)) { throw new Exception("Duplicate assignment for the same IBlauPoint in BlauSpaceEvaluation"); } else { _evaluationData.Add(qp, val); } }
public void TestRepr() { using (var doc = PdfDocument.Open(@"Files\foo.pdf", new ParsingOptions() { ClipPaths = true })) { Lattice lattice = new Lattice(new OpenCvImageProcesser(), new BasicSystemDrawingProcessor()); var tables = lattice.ExtractTables(doc.GetPage(1), layout_kwargs: null); Assert.Single(tables); Assert.Equal((7, 7), tables[0].Shape); Assert.Equal("<Cell x1=120.33 y1=218.33 x2=164.67 y2=234.01>", tables[0].Cells[0][0].ToString()); // "<Cell x1=120.48 y1=218.43 x2=164.64 y2=233.77>" in Python } }
void UpdateLattice(Lattice lat) { if (lat.Exist == true) { lat.Chess.ChessGameObject.SetActive(true); lat.Chess.ChessGameObject.transform.localScale = new Vector3(1, 1, lat.Level); lat.Chess.MyMaterial.material = materials[lat.Level - 1]; lat.Chess.CObject.transform.localScale = new Vector3(73, 73, 5); } else { lat.Chess.ChessGameObject.SetActive(false); } }
public void StartSystem() { metaballs = new List <Metaball>(); // get the metaballs in the scene GameObject[] metaballObjects = GameObject.FindGameObjectsWithTag("Metaball"); for (int i = 0; i < metaballObjects.Length; i++) { metaballs.Add(metaballObjects[i].GetComponent <Metaball>()); } lattice = new Lattice(30, 30, 30, this); InitialiseVectors(); }
public void TestLatticeShiftTtext() { using (var doc = PdfDocument.Open(@"Files\column_span_2.pdf", new ParsingOptions() { ClipPaths = true })) { var page = doc.GetPage(1); Lattice lattice = new Lattice(new OpenCvImageProcesser(), new BasicSystemDrawingProcessor(), line_scale: 40); var tables = lattice.ExtractTables(page, layout_kwargs: new DlaOptions[] { new DocstrumBoundingBoxes.DocstrumBoundingBoxesOptions() { WithinLineMultiplier = 2 } }); Assert.Single(tables); Assert.Equal(DataLatticeShiftTextLeftTop.Length, tables[0].Cells.Count); Assert.Equal(DataLatticeShiftTextLeftTop, tables[0].Data().Select(r => r.Select(c => c).ToArray()).ToArray()); lattice = new Lattice(new OpenCvImageProcesser(), new BasicSystemDrawingProcessor(), line_scale: 40, shift_text: new[] { "" }); tables = lattice.ExtractTables(page, layout_kwargs: new DlaOptions[] { new DocstrumBoundingBoxes.DocstrumBoundingBoxesOptions() { WithinLineMultiplier = 2 } }); Assert.Single(tables); Assert.Equal(DataLatticeShiftTextDisable.Length, tables[0].Cells.Count); Assert.Equal(DataLatticeShiftTextDisable, tables[0].Data().Select(r => r.Select(c => c).ToArray()).ToArray()); lattice = new Lattice(new OpenCvImageProcesser(), new BasicSystemDrawingProcessor(), line_scale: 40, shift_text: new[] { "r", "b" }); tables = lattice.ExtractTables(page, layout_kwargs: new DlaOptions[] { new DocstrumBoundingBoxes.DocstrumBoundingBoxesOptions() { WithinLineMultiplier = 2 } }); Assert.Single(tables); Assert.Equal(DataLatticeShiftTextRightBottom.Length, tables[0].Cells.Count); Assert.Equal(DataLatticeShiftTextRightBottom, tables[0].Data().Select(r => r.Select(c => c).ToArray()).ToArray()); } }
public void Analyze(ControlFlowGraph graph) { DBC.Pre(graph != null, "graph is null"); Profile.Start("Splicing"); var visited = new List <BasicBlock>(); foreach (BasicBlock root in graph.Roots) { DoSpliceHandlers(m_instructions, root, visited); } visited.Clear(); foreach (BasicBlock root in graph.Roots) { DoSpliceNullCheck(m_instructions, root, visited); } var data = new DataFlow <Lattice>(m_instructions, graph.Roots); m_skipped = data.Skipped; Profile.Stop("Splicing"); var functions = new Lattice.Functions(); Dictionary <BasicBlock, Lattice> lattices = data.Analyze(functions, m_initialState); Profile.Start("Post Transform"); m_states = new State[m_instructions.Length]; foreach (var entry in lattices) { BasicBlock block = entry.Key; if (block.Length > 0) { Lattice lattice = entry.Value; for (int index = block.First.Index; index <= block.Last.Index; ++index) // it'd be nice to assert that every index was set, but methods often have dead code so it's a little difficult { m_states[index] = lattice.State; lattice = lattice.Transform(index); } } } Profile.Stop("Post Transform"); for (int index = 0; index < m_instructions.Length; ++index) { Log.DebugLine(this, "{0:X2}: {1}", m_instructions[index].Untyped.Offset, m_states[index]); } }
// Useful function public void UpdateLattice(Lattice <double> source, double rootValue) { // Find the depth of the lattice; this a Template Method Pattern int si = source.MinIndex; source[si, si] = rootValue; // Loop from the min index to the end index for (int n = source.MinIndex + 1; n <= source.MaxIndex; n++) { for (int i = 0; i < source.NumberColumns(n); i++) { source[n, i] = d * source[n - 1, i]; source[n, i + 1] = u * source[n - 1, i]; } } }
// Use this for initialization void Start() { SetChessPosition(); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { lattices[i, j] = new Lattice(); lattices[i, j].Position = chessPosition[i * 4 + j]; lattices[i, j].Chess = new Chess(); lattices[i, j].Chess.ChessGameObject = chesses[i * 4 + j]; lattices[i, j].Chess.CObject = chesses[i * 4 + j].transform.Find("GameObject").gameObject; lattices[i, j].Chess.MyMaterial = lattices[i, j].Chess.CObject.transform.GetComponent <Renderer>(); lattices[i, j].Chess.MyAnimation = lattices[i, j].Chess.CObject.transform.GetComponent <Animation>(); } } }
public void set(IBlauPoint p, double val) { IBlauPoint qp = Lattice.quantize(p); LinkedList <IScore> bin = null; if (_evaluationData.ContainsKey(qp)) { bin = _evaluationData[qp]; } else { bin = new LinkedList <IScore>(); _evaluationData.Add(qp, bin); } bin.AddLast(new Score(p, val)); }
private static void test12() //****************************************************************************80 // // Purpose: // // TEST12 tests Lattice.lattice_print. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 23 November 2008 // // Author: // // John Burkardt // // Reference: // // Ian Sloan, Stephen Joe, // Lattice Methods for Multiple Integration, // Oxford, 1994, page 18. // { const int dim_num = 2; const int m = 8; int[] z = new int[dim_num]; z[0] = 1; z[1] = 3; Console.WriteLine(""); Console.WriteLine("TEST12"); Console.WriteLine(" Lattice.lattice_print prints out the lattice generated"); Console.WriteLine(" by a single generator vector."); Console.WriteLine(""); Console.WriteLine(" The spatial dimension DIM_NUM = " + dim_num + ""); typeMethods.i4vec_print(dim_num, z, " The generator vector:"); Lattice.lattice_print(dim_num, m, z, " The total lattice:"); }
public SquareFrame Run_kNN(ushort k) { lattice_pointer = first_lattice; while (lattice_pointer != null) { if (lattice_pointer.mark == MARK.NULL) { List <Vector> distance_list = new List <Vector>(); foreach (var item in givenpoint_list) { distance_list.Add(item - lattice_pointer.coord); } if (distance_list.Count() >= k) { distance_list.Sort(); Dictionary <MARK, uint> mark_num_dic = new Dictionary <MARK, uint>(); for (int i = k - 1; i >= 0; i--) { Lattice l_target = lattice_dic[lattice_pointer.coord + distance_list[i]]; if (mark_num_dic.ContainsKey(l_target.mark)) { mark_num_dic[l_target.mark]++; } else { mark_num_dic.Add(l_target.mark, 1); } } MARK mark_max = MARK.NULL; uint mark_max_uint = 0; foreach (var item in mark_num_dic) { if (item.Value >= mark_max_uint) { mark_max_uint = item.Value; mark_max = item.Key; } } lattice_pointer.mark = (MARK)((int)(mark_max) + 2); } } lattice_pointer = lattice_pointer.next_lattice; } return(this); }
public SquareFrame Print() { lattice_pointer = first_lattice; while (lattice_pointer != null) { if (lattice_pointer.coord.x == width_0) { lattice_pointer.PrintLine(); } else { lattice_pointer.Print(); } lattice_pointer = lattice_pointer.next_lattice; } Console.WriteLine(); return(this); }
public override void newResult(Result result) { String @ref = result.getReferenceText(); if (result.isFinal() && @ref != null) { Lattice lattice = new Lattice(result); LatticeOptimizer optimizer = new LatticeOptimizer(lattice); optimizer.optimize(); lattice.computeNodePosteriors(languageModelWeight); SausageMaker sausageMaker = new SausageMaker(lattice); Sausage sausage = sausageMaker.makeSausage(); sausage.removeFillers(); getAligner().alignSausage(@ref, sausage); showFullPath(result); showDetails(result.ToString()); } }
public void TestPosterior() { var logMath = LogMath.GetLogMath(); var lattice = new Lattice(); var a = lattice.AddNode("A", "A", 0, 0); var b = lattice.AddNode("B", "B", 0, 0); var c = lattice.AddNode("C", "C", 0, 0); var d = lattice.AddNode("D", "D", 0, 0); const double acousticAb = 4; const double acousticAc = 6; const double acousticCb = 1; const double acousticBd = 5; const double acousticCD = 2; lattice.InitialNode = a; lattice.TerminalNode = d; lattice.AddEdge(a, b, logMath.LinearToLog(acousticAb), 0); lattice.AddEdge(a, c, logMath.LinearToLog(acousticAc), 0); lattice.AddEdge(c, b, logMath.LinearToLog(acousticCb), 0); lattice.AddEdge(b, d, logMath.LinearToLog(acousticBd), 0); lattice.AddEdge(c, d, logMath.LinearToLog(acousticCD), 0); lattice.ComputeNodePosteriors(1.0f); const double pathAbd = acousticAb * acousticBd; const double pathAcbd = acousticAc * acousticCb * acousticBd; const double pathAcd = acousticAc * acousticCD; const double allPaths = pathAbd + pathAcbd + pathAcd; const double bPosterior = (pathAbd + pathAcbd) / allPaths; const double cPosterior = (pathAcbd + pathAcd) / allPaths; const double delta = 1e-4; Assert.AreEqual(logMath.LogToLinear((float)a.Posterior), 1.0, delta); Assert.AreEqual(logMath.LogToLinear((float)b.Posterior), bPosterior, delta); Assert.AreEqual(logMath.LogToLinear((float)c.Posterior), cPosterior, delta); Assert.AreEqual(logMath.LogToLinear((float)d.Posterior), 1.0, delta); }
// Add Lattice to the spreadsheet with row and column labels. public void AddLattice(string name, Lattice <double> lattice, List <string> rowLabels) { try { // Check label count vs. matrix. /* if (lattice.Columns != columnLabels.Count) * { * throw (new IndexOutOfRangeException("Count mismatch between # matrix columns and # column labels")); * } * if (lattice.Rows != rowLabels.Count) * { * throw (new IndexOutOfRangeException("Count mismatch between # matrix rows and # row labels")); * } */ // Add sheet. ExcelWorksheet pSheet = _pExcel.Workbook.Worksheets.Add(name); // Add row labels + values. int sheetColumn = 1; int sheetRow = 1; for (int i = lattice.MinIndex; i <= lattice.MaxIndex; i++) { Vector <double> row = lattice.PyramidVector(i); ToSheetHorizontal <double>(pSheet, sheetRow, sheetColumn, rowLabels[i - lattice.MinIndex], row); sheetRow++; } for (int i = lattice.MinIndex; i <= lattice.MaxIndex; i++) { Vector <double> row = lattice.PyramidVector(i); ToSheetHorizontal <double>(pSheet, sheetRow, sheetColumn, rowLabels[i], row); sheetRow++; // sheetColumn++; } } catch (IndexOutOfRangeException e) { Console.WriteLine("Exception: " + e); } }
//public static float x_pos = 0; //public static float y_pos = 0; bool isValidGridPos() { foreach (Transform child in transform) { Vector2 v = Lattice.roundVec2(child.position); // Not inside Border? if (!Lattice.insideBorder(v)) { return(false); } // Block in grid cell (and not part of same group)? if (Lattice.grid[(int)v.x, (int)v.y] != null && Lattice.grid[(int)v.x, (int)v.y].parent != transform) { return(false); } } return(true); }
public void CountColor_WhenFoundColor_ShouldReturnCount() { // Arrange int width = 4, height = 1; Lattice[,] lattices = new Lattice[width, height]; for (int i = 0; i < width; i++) { lattices[i, 0] = new Lattice(i, 0, Color.Black); } lattices[3, 0].color = Color.White; Simulation simulation = new Simulation(); Color searchColor = Color.White; int expected = 1; // Act and Assert int actual = simulation.CountColor(lattices, searchColor); Assert.AreEqual(expected, actual, 0.001, "matched"); }
/// <summary> /// Set v to a new value that is abstracted by av /// </summary> /// <param name="v"></param> /// <param name="av"></param> private void AssignAVal(Variable v, Lattice.AVal av) { ISymValue sv = this.egraph.FreshSymbol(); ISymValue addr = Address(v); this.egraph[ValueOf, addr] = sv; this.egraph[sv] = av; }
/// <summary> /// Set v to a new value that is abstracted by av /// </summary> /// <param name="v"></param> /// <param name="av"></param> private void AssignAVal(Variable v, Lattice.AVal av) { ISymValue sv = this.egraph.FreshSymbol(); this.egraph[v] = sv; this.egraph[sv] = av; }