public static bool a_star_in_composition(Intarray inputs, Intarray vertices1, Intarray vertices2, Intarray outputs, Floatarray costs, OcroFST fst1, OcroFST fst2) { CompositionFst composition = FstFactory.MakeCompositionFst(fst1, fst2); bool result; try { //Floatarray g1 = new Floatarray(); //Floatarray g2 = new Floatarray(); fst1.CalculateHeuristics(); fst2.CalculateHeuristics(); result = a_star2_internal(inputs, vertices1, vertices2, outputs, costs, fst1, fst2, fst1.Heuristics(), fst2.Heuristics(), composition); } catch (Exception ex) { composition.Move1(); composition.Move2(); throw ex; } composition.Move1(); composition.Move2(); return result; }
public static bool a_star_in_composition(Intarray inputs, Intarray vertices1, Intarray vertices2, Intarray outputs, Floatarray costs, OcroFST fst1, Floatarray g1, OcroFST fst2, Floatarray g2) { CompositionFst composition = FstFactory.MakeCompositionFst(fst1, fst2); bool result; try { result = a_star2_internal(inputs, vertices1, vertices2, outputs, costs, fst1, fst2, g1, g2, composition); } catch (Exception ex) { composition.Move1(); composition.Move2(); throw ex; } composition.Move1(); composition.Move2(); return(result); }
public static bool a_star_in_composition(Intarray inputs, Intarray vertices1, Intarray vertices2, Intarray outputs, Floatarray costs, OcroFST fst1, OcroFST fst2) { CompositionFst composition = FstFactory.MakeCompositionFst(fst1, fst2); bool result; try { //Floatarray g1 = new Floatarray(); //Floatarray g2 = new Floatarray(); fst1.CalculateHeuristics(); fst2.CalculateHeuristics(); result = a_star2_internal(inputs, vertices1, vertices2, outputs, costs, fst1, fst2, fst1.Heuristics(), fst2.Heuristics(), composition); } catch (Exception ex) { composition.Move1(); composition.Move2(); throw ex; } composition.Move1(); composition.Move2(); return(result); }
public static CompositionFst MakeCompositionFst(OcroFST l1, OcroFST l2, int override_start = -1, int override_finish = -1) { return(new CompositionFstImpl(l1, l2, override_start, override_finish)); }
public static CompositionFst MakeCompositionFst(OcroFST l1, OcroFST l2, int override_start = -1, int override_finish = -1) { return new CompositionFstImpl(l1, l2, override_start, override_finish); }
public static double a_star(out string result, OcroFST fst) { result = ""; Intarray inputs = new Intarray(); Intarray vertices = new Intarray(); Intarray outputs = new Intarray(); Floatarray costs = new Floatarray(); if (!a_star(inputs, vertices, outputs, costs, fst)) return 1e38; FstUtil.remove_epsilons(out result, outputs); return NarrayUtil.Sum(costs); }
public static double a_star(out string result, OcroFST fst1, OcroFST fst2) { result = ""; Intarray inputs = new Intarray(); Intarray v1 = new Intarray(); Intarray v2 = new Intarray(); Intarray outputs = new Intarray(); Floatarray costs = new Floatarray(); if (!a_star_in_composition(inputs, v1, v2, outputs, costs, fst1, fst2)) return 1e38; FstUtil.remove_epsilons(out result, outputs); return NarrayUtil.Sum(costs); }
public static double beam_search(out string result, OcroFST fst1, OcroFST fst2, int beam_width) { Intarray v1 = new Intarray(); Intarray v2 = new Intarray(); Intarray i = new Intarray(); Intarray o = new Intarray(); Floatarray c = new Floatarray(); //fprintf(stderr,"starting beam search\n"); beam_search(v1, v2, i, o, c, fst1, fst2, beam_width); //fprintf(stderr,"finished beam search\n"); FstUtil.remove_epsilons(out result, o); return NarrayUtil.Sum(c); }
public static bool a_star(Intarray inputs, Intarray vertices, Intarray outputs, Floatarray costs, OcroFST fst) { AStarSearch a = new AStarSearch(fst); if (!a.Loop()) return false; if (!a.reconstruct_vertices(vertices)) return false; a.reconstruct_edges(inputs, outputs, costs, vertices); return true; }
public static double a_star(out string result, OcroFST fst) { result = ""; Intarray inputs = new Intarray(); Intarray vertices = new Intarray(); Intarray outputs = new Intarray(); Floatarray costs = new Floatarray(); if (!a_star(inputs, vertices, outputs, costs, fst)) { return(1e38); } FstUtil.remove_epsilons(out result, outputs); return(NarrayUtil.Sum(costs)); }
public static double beam_search(out string result, OcroFST fst1, OcroFST fst2, int beam_width) { Intarray v1 = new Intarray(); Intarray v2 = new Intarray(); Intarray i = new Intarray(); Intarray o = new Intarray(); Floatarray c = new Floatarray(); //fprintf(stderr,"starting beam search\n"); beam_search(v1, v2, i, o, c, fst1, fst2, beam_width); //fprintf(stderr,"finished beam search\n"); FstUtil.remove_epsilons(out result, o); return(NarrayUtil.Sum(c)); }
public static double a_star(out string result, OcroFST fst1, OcroFST fst2) { result = ""; Intarray inputs = new Intarray(); Intarray v1 = new Intarray(); Intarray v2 = new Intarray(); Intarray outputs = new Intarray(); Floatarray costs = new Floatarray(); if (!a_star_in_composition(inputs, v1, v2, outputs, costs, fst1, fst2)) { return(1e38); } FstUtil.remove_epsilons(out result, outputs); return(NarrayUtil.Sum(costs)); }
/// <summary> /// Compose two FSTs. /// This function copies the composition of two given FSTs. /// That causes expansion (storing all arcs explicitly). /// </summary> public static void fst_expand_composition(IGenericFst outf, OcroFST f1, OcroFST f2) { CompositionFst composition = FstFactory.MakeCompositionFst(f1, f2); try { fst_copy(outf, composition); } catch (Exception ex) { composition.Move1(); composition.Move2(); throw ex; } composition.Move1(); composition.Move2(); }
public static void scale_fst(OcroFST fst, float scale) { if (Math.Abs(scale - 1.0f) < 1e-6f) { return; } for (int i = 0; i < fst.nStates(); i++) { Floatarray cost = fst.Costs(i); cost *= scale; float accept = fst.AcceptCost(i); if (accept >= 0.0f && accept < 1e37f) { fst.SetAcceptCost(i, accept * scale); } } }
public BeamSearch(OcroFST fst1, OcroFST fst2, int beam_width) { stree = new SearchTree(); beam = new Intarray(); beamcost = new Floatarray(); all_inputs = new Intarray(); all_targets1 = new Intarray(); all_targets2 = new Intarray(); all_outputs = new Intarray(); all_costs = new Floatarray(); parent_trails = new Intarray(); this.fst1 = fst1; this.fst2 = fst2; this.nbest = new PriorityQueue(beam_width); this.beam_width = beam_width; accepted_from1 = -1; accepted_from2 = -1; }
public static bool a_star(Intarray inputs, Intarray vertices, Intarray outputs, Floatarray costs, OcroFST fst) { AStarSearch a = new AStarSearch(fst); if (!a.Loop()) { return(false); } if (!a.reconstruct_vertices(vertices)) { return(false); } a.reconstruct_edges(inputs, outputs, costs, vertices); return(true); }
public static void beam_search( Intarray vertices1, Intarray vertices2, Intarray inputs, Intarray outputs, Floatarray costs, OcroFST fst1, OcroFST fst2, int beam_width) { BeamSearch b = new BeamSearch(fst1, fst2, beam_width); //CHECK(L_SIGMA < L_EPSILON); //CHECK(L_RHO < L_PHI); //CHECK(L_PHI < L_EPSILON); //CHECK(L_EPSILON < 1); fst1.SortByOutput(); fst2.SortByInput(); b.BestPath(vertices1, vertices2, inputs, outputs, costs); }
public static bool a_star_in_composition(Intarray inputs, Intarray vertices1, Intarray vertices2, Intarray outputs, Floatarray costs, OcroFST fst1, Floatarray g1, OcroFST fst2, Floatarray g2) { CompositionFst composition = FstFactory.MakeCompositionFst(fst1, fst2); bool result; try { result = a_star2_internal(inputs, vertices1, vertices2, outputs, costs, fst1, fst2, g1, g2, composition); } catch (Exception ex) { composition.Move1(); composition.Move2(); throw ex; } composition.Move1(); composition.Move2(); return result; }
public static void scale_fst(OcroFST fst, float scale) { if(Math.Abs(scale-1.0f)<1e-6f) return; for (int i = 0; i < fst.nStates(); i++) { Floatarray cost = fst.Costs(i); cost *= scale; float accept = fst.AcceptCost(i); if (accept >= 0.0f && accept < 1e37f) fst.SetAcceptCost(i, accept * scale); } }