Пример #1
0
        public void add(Node _lnode, Node _rnode)
        {
            lnode = _lnode;
            rnode = _rnode;

            lnode.rpathList.Add(this);
            rnode.lpathList.Add(this);
        }
Пример #2
0
        public void Init()
        {
            if (x.Length == 0)
            {
                return;
            }

            var ysize_ = x[0].ysize_;
            max_xsize_ = 0;
            for (var i = start_i; i < x.Length; i += thread_num)
            {
                if (max_xsize_ < x[i].word_num)
                {
                    max_xsize_ = x[i].word_num;
                }
            }

            result_ = new short[max_xsize_];
            node_ = new Node[max_xsize_, ysize_];
            for (var i = 0; i < max_xsize_; i++)
            {
                for (var j = 0; j < ysize_; j++)
                {
                    node_[i, j] = new Node();
                    node_[i, j].x = (short)i;
                    node_[i, j].y = (short)j;
                    node_[i, j].lpathList = new List<Path>(ysize_);
                    node_[i, j].rpathList = new List<Path>(ysize_);
                }
            }

            for (short cur = 1; cur < max_xsize_; ++cur)
            {
                for (short j = 0; j < ysize_; ++j)
                {
                    for (short i = 0; i < ysize_; ++i)
                    {
                        var path = new Path();
                        path.fid = -1;
                        path.cost = 0.0;
                        path.add(node_[cur - 1, j], node_[cur, i]);
                    }
                }
            }

            merr = new int[ysize_, ysize_];
        }
Пример #3
0
 public void Init(short[] result, Node[,] node)
 {
     result_ = result;
     node_ = node;
 }
Пример #4
0
 public Path()
 {
     rnode = null;
     lnode = null;
     cost = 0;
 }
Пример #5
0
 public void calcCost(Node n)
 {
     double c = 0;
     var f = feature_cache_[n.fid];
     for (var i = 0; i < f.Length && f[i] != -1; i++)
     {
         c += featureIndex.GetAlpha(f[i] + n.y);
     }
     n.cost = featureIndex.cost_factor_ * c;
 }
Пример #6
0
        public int forward_backward_stat; //前向后向过程运行状态,0为未运行,1为已经运行

        //概率计算函数
        double toprob(Node n, double Z)
        {
            return Math.Exp(n.alpha + n.beta - n.cost - Z);
        }
Пример #7
0
        //使用模型初始化tag,必须先使用该函数初始化才能使用add和parse                                                                    
        //正常返回为0, 错误返回<0
        public int init_by_model(ModelReader model_p)
        {
            featureIndex = model_p;
            ysize_ = (short)model_p.ysize();

            if (nbest_ > 1)
            {
                //Only allocate heap when nbest is more than 1
                heap_queue = Utils.heap_init((int)(crf_max_word_num * ysize_ * ysize_));
            }

            //Initialize feature set cache according unigram and bigram templates
            InitializeFeatureCache();

            node_ = new Node[crf_max_word_num, ysize_];
            result_ = new short[crf_max_word_num];

            //Create node and path cache
            for (short cur = 0; cur < crf_max_word_num; cur++)
            {
                for (short i = 0; i < ysize_; i++)
                {
                    var n = new Node();
                    node_[cur, i] = n;

                    n.lpathList = new List<Path>();
                    n.rpathList = new List<Path>();
                    n.x = cur;
                    n.y = i;
                }
            }

            for (var cur = 1; cur < crf_max_word_num; cur++)
            {
                for (var j = 0; j < ysize_; ++j)
                {
                    for (var i = 0; i < ysize_; ++i)
                    {
                        var p = new CRFSharp.Path();
                        p.add(node_[cur - 1, j], node_[cur, i]);
                    }
                }
            }

            return Utils.ERROR_SUCCESS;
        }