Ocronet.Dynamic.OcroFST.FstUtil.fst_sample C# (CSharp) Method

fst_sample() public static method

Randomly sample an FST, assuming any input.
public static fst_sample ( Intarray result, IGenericFst fst, int max = 1000 ) : double
result Intarray The array of output symbols, excluding epsilons.
fst Ocronet.Dynamic.Interfaces.IGenericFst The FST.
max int The maximum length of the result.
return double
        public static double fst_sample(Intarray result, IGenericFst fst, int max=1000)
        {
            double total_cost = 0;
            int current = fst.GetStart();

            for (int counter = 0; counter < max; counter++)
            {
                Intarray inputs  = new Intarray();
                Intarray outputs = new Intarray();
                Intarray targets = new Intarray();
                Floatarray costs = new Floatarray();

                fst.Arcs(inputs, targets, outputs, costs, current);

                // now we need to deal with the costs uniformly, so:
                costs.Push(fst.GetAcceptCost(current));
                int choice = sample_by_costs(costs);
                if (choice == costs.Length() - 1)
                    break;
                result.Push(outputs[choice]);
                total_cost += costs[choice];
                current = targets[choice];
            }
            return total_cost + fst.GetAcceptCost(current);
        }

Same methods

FstUtil::fst_sample ( string &result, IGenericFst fst, int max ) : double