Beispiel #1
0
        public override bool GetCosts(Floatarray costs, int page, int line, string variant = null)
        {
            costs.Clear();
            costs.Resize(10000);
            costs.Fill(1e38f);

            if (!File.Exists(PathFile(page, line, variant, "costs")))
                return false;
            FileStream fs = null;
            try
            {
                fs = Open(FileMode.Open, page, line, variant, "costs");
                StreamReader reader = new StreamReader(fs);
                int index;
                float cost;
                while (!reader.EndOfStream)
                {
                    string sline = reader.ReadLine();
                    string[] parts = sline.Split(new char[] { ' ' }, 2);
                    if (parts.Length == 2 && int.TryParse(parts[0], out index) && float.TryParse(parts[1], out cost))
                        costs[index] = cost;
                }
                reader.Close();
                fs.Close();
            }
            catch (FileNotFoundException e) { return false; }
            catch (Exception e)
            {
                if (fs != null) fs.Close();
                return false;
            }
            return true;
        }
Beispiel #2
0
 /// <summary>
 /// If it's initialized with an array, the result vector
 /// is copied into that array when the vector gets destroyed.
 /// This allows calls like classifier.Outputs(v,x); with
 /// floatarray v.
 /// </summary>
 public OutputVector(Floatarray v)
     : this()
 {
     _result = new Floatarray();
     _result.Copy(v);
     v.Clear();
 }
Beispiel #3
0
 public void Clear()
 {
     _keys.Fill(0);
     _keys.Clear();
     _values.Fill(0f);
     _values.Clear();
     _len = 0;
 }
Beispiel #4
0
 public void Clear()
 {
     parents.Clear();
     inputs.Clear();
     outputs.Clear();
     v1.Clear();
     v2.Clear();
     costs.Clear();
 }
Beispiel #5
0
        public float Outputs(Floatarray p, Floatarray x)
        {
            OutputVector ov   = new OutputVector();
            float        cost = XOutputs(ov, x);

            p.Clear();
            p.Copy(ov.AsArray());
            return(cost);
        }
Beispiel #6
0
 public override void Clear()
 {
     start = 0;
     m_targets.Clear();
     m_inputs.Clear();
     m_outputs.Clear();
     m_costs.Clear();
     accept_costs.Clear();
 }
Beispiel #7
0
 public void Clear()
 {
     nbest.Clear();
     all_targets1.Clear();
     all_targets2.Clear();
     all_inputs.Clear();
     all_outputs.Clear();
     all_costs.Clear();
     parent_trails.Clear();
 }
Beispiel #8
0
 public virtual void Extract(Floatarray outa, Floatarray ina)
 {
     outa.Clear();
     Narray<Floatarray> items = new Narray<Floatarray>();
     Extract(items, ina);
     //int num = 0;
     for (int i = 0; i < items.Length(); i++)
     {
         Floatarray a = items[i];
         outa.ReserveTo(outa.Length() + a.Length());    // optimization
         for (int j = 0; j < a.Length(); j++)
         {
             outa.Push(a.At1d(j));
             //outa[num++] = a.At1d(j);
         }
     }
 }
Beispiel #9
0
        public virtual void Extract(Floatarray outa, Floatarray ina)
        {
            outa.Clear();
            Narray <Floatarray> items = new Narray <Floatarray>();

            Extract(items, ina);
            //int num = 0;
            for (int i = 0; i < items.Length(); i++)
            {
                Floatarray a = items[i];
                outa.ReserveTo(outa.Length() + a.Length());    // optimization
                for (int j = 0; j < a.Length(); j++)
                {
                    outa.Push(a.At1d(j));
                    //outa[num++] = a.At1d(j);
                }
            }
        }
Beispiel #10
0
        public override bool GetCosts(Floatarray costs, int page, int line, string variant = null)
        {
            costs.Clear();
            costs.Resize(10000);
            costs.Fill(1e38f);

            if (!File.Exists(PathFile(page, line, variant, "costs")))
            {
                return(false);
            }
            FileStream fs = null;

            try
            {
                fs = Open(FileMode.Open, page, line, variant, "costs");
                StreamReader reader = new StreamReader(fs);
                int          index;
                float        cost;
                while (!reader.EndOfStream)
                {
                    string   sline = reader.ReadLine();
                    string[] parts = sline.Split(new char[] { ' ' }, 2);
                    if (parts.Length == 2 && int.TryParse(parts[0], out index) && float.TryParse(parts[1], out cost))
                    {
                        costs[index] = cost;
                    }
                }
                reader.Close();
                fs.Close();
            }
            catch (FileNotFoundException e) { return(false); }
            catch (Exception e)
            {
                if (fs != null)
                {
                    fs.Close();
                }
                return(false);
            }
            return(true);
        }
Beispiel #11
0
 public float Outputs(Floatarray p, Floatarray x)
 {
     OutputVector ov = new OutputVector();
     float cost = XOutputs(ov, x);
     p.Clear();
     p.Copy(ov.AsArray());
     return cost;
 }
Beispiel #12
0
 /// <summary>
 /// If it's initialized with an array, the result vector
 /// is copied into that array when the vector gets destroyed.
 /// This allows calls like classifier.Outputs(v,x); with
 /// floatarray v.
 /// </summary>
 public OutputVector(Floatarray v) : this()
 {
     _result = new Floatarray();
     _result.Copy(v);
     v.Clear();
 }