public override void Clear() { data.Clear(); classes.Clear(); nc = 0; nf = -1; }
protected virtual void GetLinesOfPage(Intarray lines, int ipage) { lines.Clear(); string dirName = String.Format("{0}{1}{2:0000}", prefix, Path.DirectorySeparatorChar, ipage); DirPattern dpattern = new DirPattern(dirName, @"([0-9][0-9][0-9][0-9])\.png"); if (dpattern.Length > 0) { lines.ReserveTo(dpattern.Length); } List <int> llist = new List <int>(dpattern.Length); for (int i = 0; i < dpattern.Length; i++) { int k = int.Parse(dpattern[i]); llist.Add(k); //lines.Push(k); } IEnumerable <int> query = llist.OrderBy(i => i); foreach (int iline in query) { lines.Push(iline); } }
public void Clear() { _keys.Fill(0); _keys.Clear(); _values.Fill(0f); _values.Clear(); _len = 0; }
/// <summary> /// Copy one FST to another, preserving only lowest-cost arcs. /// This is useful for visualization. /// </summary> /// <param name="dst">The destination. Will be cleared before copying.</param> /// <param name="src">The FST to copy.</param> public static void fst_copy_best_arcs_only(IGenericFst dst, IGenericFst src) { dst.Clear(); int n = src.nStates(); for (int i = 0; i < n; i++) { dst.NewState(); } dst.SetStart(src.GetStart()); for (int i = 0; i < n; i++) { dst.SetAccept(i, src.GetAcceptCost(i)); Intarray targets = new Intarray(), outputs = new Intarray(), inputs = new Intarray(); Floatarray costs = new Floatarray(); src.Arcs(inputs, targets, outputs, costs, i); int inlen = inputs.Length(); if (inlen != targets.Length()) { throw new Exception("ASSERT: inputs.length() == targets.length()"); } if (inlen != outputs.Length()) { throw new Exception("ASSERT: inputs.length() == outputs.length()"); } if (inlen != costs.Length()) { throw new Exception("ASSERT: inputs.length() == costs.length()"); } Dictionary <int, int> hash = new Dictionary <int, int>(); for (int j = 0; j < n; j++) { int t = targets[j]; int best_so_far = -1; if (hash.ContainsKey(t)) { best_so_far = hash[t]; } if (best_so_far == -1 || costs[j] < costs[best_so_far]) { hash[t] = j; } } Intarray keys = new Intarray(); //hash.keys(keys); keys.Clear(); foreach (int key in hash.Keys) { keys.Push(key); } for (int k = 0; k < keys.Length(); k++) { int j = hash[keys[k]]; dst.AddTransition(i, targets[j], outputs[j], costs[j], inputs[j]); } } }
public void Clear() { parents.Clear(); inputs.Clear(); outputs.Clear(); v1.Clear(); v2.Clear(); costs.Clear(); }
public void Init(params string[] books) { bool retrain = PGetb("retrain"); bool randomize = PGetb("randomize"); string cbookstore = PGet("cbookstore"); bookstores.Clear(); all_lines.Clear(); cseg_variant = "cseg.gt"; text_variant = "gt"; if (retrain) { cseg_variant = "cseg"; text_variant = ""; } int nbooks = books.Length; bookstores.Resize(nbooks); int totalNumberOfPages = 0; for (int i = 0; i < nbooks; i++) { bookstores[i] = ComponentCreator.MakeComponent <IBookStore>(cbookstore); bookstores[i].SetPrefix(books[i].Trim()); Global.Debugf("info", "{0}: {1} pages", books[i], bookstores[i].NumberOfPages()); totalNumberOfPages += bookstores[i].NumberOfPages(); } //CHECK_ARG(totalNumberOfPages > 0, "totalNumberOfPages > 0"); // compute a list of all lines Intarray triple = new Intarray(3); for (int i = 0; i < nbooks; i++) { for (int j = 0; j < bookstores[i].NumberOfPages(); j++) { for (int k = 0; k < bookstores[i].LinesOnPage(j); k++) { triple[0] = i; triple[1] = j; triple[2] = k; NarrayRowUtil.RowPush(all_lines, triple); } } } Global.Debugf("info", "got {0} lines", all_lines.Dim(0)); // randomly permute it so that we train in random order if (randomize) { Shuffle(); } index = 0; }
public void Clear() { nbest.Clear(); all_targets1.Clear(); all_targets2.Clear(); all_inputs.Clear(); all_outputs.Clear(); all_costs.Clear(); parent_trails.Clear(); }
protected override void GetLinesOfPage(Intarray lines, int ipage) { lines.Clear(); string dirName = String.Format("{0}{1}{2:0000}", prefix, Path.DirectorySeparatorChar, ipage); //DirPattern dpattern = new DirPattern(dirName, @"([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])\.png"); DirPattern dpattern = new DirPattern(dirName, @"([0-9][0-9][0-9][0-9][0-9][0-9])\.png"); if (dpattern.Length > 0) lines.ReserveTo(dpattern.Length); for (int i = 0; i < dpattern.Length; i++) { int k = int.Parse(dpattern[i]); lines.Push(k); } }
public bool GetCharSegmentation(Intarray image, int book, int page, int line) { image.Clear(); bookstores[book].GetCharSegmentation(image, page, line, "gt"); if (image.Length() > 0) { return(true); } bookstores[book].GetCharSegmentation(image, page, line, ""); if (image.Length() > 0) { return(true); } return(false); }
/// <summary> /// simple interface for line recognizers /// </summary> public virtual void SetString(string text, Floatarray costs, Intarray ids) { int n = text.Length; Intarray states = new Intarray(); states.Clear(); for (int i = 0; i < n + 1; i++) { states.Push(NewState()); } for (int i = 0; i < n; i++) { AddTransition(states[i], states[i + 1], text[i], costs[i], ids[i]); } SetStart(states[0]); SetAccept(states[n]); }
protected override void GetLinesOfPage(Intarray lines, int ipage) { lines.Clear(); string dirName = String.Format("{0}{1}{2:0000}", prefix, Path.DirectorySeparatorChar, ipage); //DirPattern dpattern = new DirPattern(dirName, @"([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])\.png"); DirPattern dpattern = new DirPattern(dirName, @"([0-9][0-9][0-9][0-9][0-9][0-9])\.png"); if (dpattern.Length > 0) { lines.ReserveTo(dpattern.Length); } for (int i = 0; i < dpattern.Length; i++) { int k = int.Parse(dpattern[i]); lines.Push(k); } }
public static void local_minima(ref Intarray result, Floatarray data, int r, float threshold) { int n = data.Length(); result.Clear(); Floatarray lmin = new Floatarray(); local_min(ref lmin, data, r); for (int i = 1; i < n - 1; i++) { if (data[i] <= threshold && data[i] <= lmin[i] && data[i] <= data[i - 1] && data[i] < data[i + 1]) { result.Push(i); } } }
public static void weighted_sample(Intarray samples, Floatarray weights, int n) { Floatarray cs = new Floatarray(); cs.Copy(weights); for (int i = 1; i < cs.Length(); i++) { cs[i] += cs[i - 1]; } cs /= NarrayUtil.Max(cs); samples.Clear(); for (int i = 0; i < n; i++) { float value = (float)DRandomizer.Default.drand(); int where = Binsearch(cs, value); samples.Push(where); } }
public void LoadOldFormat(BinaryReader reader) { string magic = BinIO.magic_get(reader, "linerec".Length); CHECK_ARG(magic == "linerec" || magic == "linerc2", "magic=='linerec' || magic=='linerc2'"); PLoad(reader); IComponent comp = ComponentIO.load_component(reader); IModel cmodel = comp as IModel; classifier.Object = cmodel; counts.Clear(); if (magic == "linerec") { PSet("minsize_factor", 0.0); } else if (magic == "linerc2") { Narray <int> intcount = counts; BinIO.narray_read(reader, intcount); } }
/// <summary> /// simple interface for line recognizers /// </summary> public virtual void SetString(string text, Floatarray costs, Intarray ids) { int n = text.Length; Intarray states = new Intarray(); states.Clear(); for(int i=0; i<n+1; i++) states.Push(NewState()); for(int i=0; i<n; i++) AddTransition(states[i], states[i+1], text[i], costs[i], ids[i]); SetStart(states[0]); SetAccept(states[n]); }
protected virtual void GetLinesOfPage(Intarray lines, int ipage) { lines.Clear(); string dirName = String.Format("{0}{1}{2:0000}", prefix, Path.DirectorySeparatorChar, ipage); DirPattern dpattern = new DirPattern(dirName, @"([0-9][0-9][0-9][0-9])\.png"); if (dpattern.Length > 0) lines.ReserveTo(dpattern.Length); List<int> llist = new List<int>(dpattern.Length); for (int i = 0; i < dpattern.Length; i++) { int k = int.Parse(dpattern[i]); llist.Add(k); //lines.Push(k); } IEnumerable<int> query = llist.OrderBy(i => i); foreach (int iline in query) lines.Push(iline); }
/// <summary> /// Copy one FST to another, preserving only lowest-cost arcs. /// This is useful for visualization. /// </summary> /// <param name="dst">The destination. Will be cleared before copying.</param> /// <param name="src">The FST to copy.</param> public static void fst_copy_best_arcs_only(IGenericFst dst, IGenericFst src) { dst.Clear(); int n = src.nStates(); for (int i = 0; i < n; i++) dst.NewState(); dst.SetStart(src.GetStart()); for(int i = 0; i < n; i++) { dst.SetAccept(i, src.GetAcceptCost(i)); Intarray targets = new Intarray(), outputs = new Intarray(), inputs = new Intarray(); Floatarray costs = new Floatarray(); src.Arcs(inputs, targets, outputs, costs, i); int inlen = inputs.Length(); if (inlen != targets.Length()) throw new Exception("ASSERT: inputs.length() == targets.length()"); if (inlen != outputs.Length()) throw new Exception("ASSERT: inputs.length() == outputs.length()"); if (inlen != costs.Length()) throw new Exception("ASSERT: inputs.length() == costs.length()"); Dictionary< int, int > hash = new Dictionary<int,int>(); for(int j = 0; j < n; j++) { int t = targets[j]; int best_so_far = -1; if (hash.ContainsKey(t)) best_so_far = hash[t]; if(best_so_far == -1 || costs[j] < costs[best_so_far]) hash[t] = j; } Intarray keys = new Intarray(); //hash.keys(keys); keys.Clear(); foreach (int key in hash.Keys) { keys.Push(key); } for(int k = 0; k < keys.Length(); k++) { int j = hash[keys[k]]; dst.AddTransition(i, targets[j], outputs[j], costs[j], inputs[j]); } } }