示例#1
0
        public static dMatrix getDeviation(List <dMatrix> list)
        {
            //check validity
            int r1 = list[0].R, c1 = list[0].C;

            foreach (dMatrix im in list)
            {
                if (r1 != im.R || c1 != im.C)
                {
                    throw new Exception("error");
                }
            }

            dMatrix m = new dMatrix(list[0]);

            m.set(0);

            for (int r = 0; r < m.R; r++)
            {
                for (int c = 0; c < m.C; c++)
                {
                    List <double> dList = new List <double>();
                    foreach (dMatrix im in list)
                    {
                        dList.Add(im[r, c]);
                    }
                    m[r, c] = getDeviation(dList);
                }
            }
            return(m);
        }
示例#2
0
        //the scalar version
        virtual public void getLogYY(double scalar, model m, dataSeq x, int i, ref dMatrix YY, ref List <double> Y, bool takeExp, bool mask)
        {
            YY.set(0);
            listTool.listSet(ref Y, 0);

            List <double>      w     = m.W;
            List <featureTemp> fList = _fGene.getFeatureTemp(x, i);
            int nTag = m.NTag;

            for (int j = 0; j < fList.Count; j++)
            {
                featureTemp ptr = fList[j];
                int         id  = ptr.id;
                double      v   = ptr.val;
                for (int s = 0; s < nTag; s++)
                {
                    int f = _fGene.getNodeFeatID(id, s);
                    Y[s] += w[f] * scalar * v;
                }
            }
            if (i > 0)
            {
                for (int s = 0; s < nTag; s++)
                {
                    for (int sPre = 0; sPre < nTag; sPre++)
                    {
                        int f = _fGene.getEdgeFeatID(sPre, s);
                        YY[sPre, s] += w[f] * scalar;
                    }
                }
            }
            double maskValue = double.MinValue;

            if (takeExp)
            {
                listTool.listExp(ref Y);
                YY.eltExp();
                maskValue = 0;
            }
            if (mask)
            {
                List <int> tagList = x.getTags();
                for (int s = 0; s < Y.Count; s++)
                {
                    if (tagList[i] != s)
                    {
                        Y[s] = maskValue;
                    }
                }
            }
        }
示例#3
0
        override public void getLogYY(model m, dataSeq x, int i, ref dMatrix YY, ref List <double> Y, bool takeExp, bool mask)
        {
            YY.set(0);
            listTool.listSet(ref Y, 0);

            float[]            w     = m.W;
            List <featureTemp> fList = _fGene.getFeatureTemp(x, i);
            int nState = m.NState;

            foreach (featureTemp ft in fList)
            {
                for (int s = 0; s < nState; s++)
                {
                    int f = _fGene.getNodeFeatID(ft.id, s);
                    Y[s] += w[f] * ft.val;
                }
            }
            if (i > 0)
            {
                foreach (featureTemp im in fList)
                {
                    for (int s = 0; s < nState; s++)
                    {
                        for (int sPre = 0; sPre < nState; sPre++)
                        {
                            int f = _fGene.getEdgeFeatID(im.id, sPre, s);
                            YY[sPre, s] += w[f] * im.val;
                        }
                    }
                }
            }
            double maskValue = double.MinValue;

            if (takeExp)
            {
                listTool.listExp(ref Y);
                YY.eltExp();
                maskValue = 0;
            }
            if (mask)
            {
                dMatrix statesPerNodes = m.getStatesPerNode(x);
                for (int s = 0; s < Y.Count; s++)
                {
                    if (statesPerNodes[i, s] == 0)
                    {
                        Y[s] = maskValue;
                    }
                }
            }
        }
示例#4
0
        public static void summarize(string fn = "f2")
        {
            StreamReader sr  = new StreamReader(Global.outDir + Global.fResRaw);
            string       txt = sr.ReadToEnd();

            sr.Close();
            txt = txt.Replace("\r", "");
            string[]     regions = txt.Split(Global.triLineEndAry, StringSplitOptions.RemoveEmptyEntries);
            StreamWriter sw      = new StreamWriter(Global.outDir + Global.fResSum);

            foreach (string region in regions)
            {
                string[]       blocks = region.Split(Global.biLineEndAry, StringSplitOptions.RemoveEmptyEntries);
                List <dMatrix> mList  = new List <dMatrix>();
                foreach (string im in blocks)
                {
                    dMatrix m = new dMatrix(im);
                    mList.Add(m);
                }

                //get average
                dMatrix avgM = new dMatrix(mList[0]);
                avgM.set(0);
                foreach (dMatrix m in mList)
                {
                    avgM.add(m);
                }
                avgM.divide(mList.Count);
                //get devi
                dMatrix deviM = mathTool.getDeviation(mList);

                sw.WriteLine("%averaged values:");
                avgM.write(sw, fn);
                sw.WriteLine();
                sw.WriteLine("%deviations:");
                deviM.write(sw, fn);
                sw.WriteLine();
                sw.WriteLine("%avg & devi:");

                sMatrix sAvgM = new sMatrix(avgM, fn);
                sAvgM.add("+-");
                sMatrix sDeviM = new sMatrix(deviM, fn);
                sAvgM.add(sDeviM);
                sAvgM.write(sw);
                sw.WriteLine("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n");
            }
            sw.Close();
        }
示例#5
0
        virtual public void getLogYY(model m, dataSeq x, int i, ref dMatrix YY, ref List <double> Y, bool takeExp, bool mask)
        {
            YY.set(0);
            listTool.listSet(ref Y, 0);

            float[]            w     = m.W;
            List <featureTemp> fList = _fGene.getFeatureTemp(x, i);
            int nTag = m.NTag;

            foreach (featureTemp ft in fList)
            {
                for (int s = 0; s < nTag; s++)
                {
                    int f = _fGene.getNodeFeatID(ft.id, s);
                    Y[s] += w[f] * ft.val;
                }
            }
            if (i > 0)
            {
                for (int s = 0; s < nTag; s++)
                {
                    for (int sPre = 0; sPre < nTag; sPre++)
                    {
                        int f = _fGene.getEdgeFeatID(sPre, s);
                        YY[sPre, s] += w[f];
                    }
                }
            }
            double maskValue = double.MinValue;

            if (takeExp)
            {
                listTool.listExp(ref Y);
                YY.eltExp();
                maskValue = 0;
            }
            if (mask)
            {
                List <int> tagList = x.getTags();
                for (int s = 0; s < Y.Count; s++)
                {
                    if (tagList[i] != s)
                    {
                        Y[s] = maskValue;
                    }
                }
            }
        }
示例#6
0
        public void getLogYY(model m, dataSeq x, int i, ref dMatrix YY, ref List <double> Y, bool takeExp, bool mask)
        {
            YY.set(0);
            listTool.listSet(ref Y, 0);

            float[]            w     = m.W;
            List <featureTemp> fList = _fGene.getFeatureTemp(x, i);
            int nTag = m.NTag;

            //node feature
            foreach (featureTemp im in fList)
            {
                nodeFeature[] features = Global.idNodeFeatures[im.id];
                foreach (nodeFeature feat in features)
                {
                    int f = feat._id;
                    int s = feat._s;

                    Y[s] += w[f] * im.val;
                }
            }

            if (i > 0)
            {
                //non-rich edge
                if (Global.useTraditionalEdge)
                {
                    for (int s = 0; s < nTag; s++)
                    {
                        for (int sPre = 0; sPre < nTag; sPre++)
                        {
                            int f = _fGene.getEdgeFeatID(sPre, s);
                            YY[sPre, s] += w[f];
                        }
                    }
                }

                //rich edge
                foreach (featureTemp im in fList)
                {
                    edgeFeature[] features = Global.idEdgeFeatures[im.id];
                    foreach (edgeFeature feat in features)
                    {
                        YY[feat._sPre, feat._s] += w[feat._id] * im.val;
                    }
                }

                //rich2
                if (Global.richFeat2)
                {
                    List <featureTemp> fList2 = _fGene.getFeatureTemp(x, i - 1);
                    foreach (featureTemp im in fList2)
                    {
                        edgeFeature[] features = Global.idEdgeFeatures2[im.id];
                        foreach (edgeFeature feat in features)
                        {
                            YY[feat._sPre, feat._s] += w[feat._id] * im.val;
                        }
                    }
                }
            }
            double maskValue = double.MinValue;

            if (takeExp)
            {
                listTool.listExp(ref Y);
                YY.eltExp();
                maskValue = 0;
            }
            if (mask)
            {
                dMatrix statesPerNodes = m.getStatesPerNode(x);
                for (int s = 0; s < Y.Count; s++)
                {
                    if (statesPerNodes[i, s] == 0)
                    {
                        Y[s] = maskValue;
                    }
                }
            }
        }
示例#7
0
        //the scalar version
        override public void getLogYY(double scalar, model m, dataSeq x, int i, ref dMatrix YY, ref List <double> Y, bool takeExp, bool mask)
        {
            YY.set(0);
            listTool.listSet(ref Y, 0);

            float[]            w     = m.W;
            List <featureTemp> fList = _fGene.getFeatureTemp(x, i);
            int nTag = m.NTag;

            foreach (featureTemp ft in fList)
            {
                for (int s = 0; s < nTag; s++)
                {
                    int f = _fGene.getNodeFeatID(ft.id, s);
                    Y[s] += w[f] * scalar * ft.val;
                }
            }
            if (i > 0)
            {
                //non-rich
                if (Global.useTraditionalEdge)
                {
                    for (int s = 0; s < nTag; s++)
                    {
                        for (int sPre = 0; sPre < nTag; sPre++)
                        {
                            int f = _fGene.getEdgeFeatID(sPre, s);
                            YY[sPre, s] += w[f] * scalar;
                        }
                    }
                }

                //rich
                foreach (featureTemp im in fList)
                {
                    int id = im.id;
                    if (id < _fGene.getNRichFeatTemp())
                    {
                        for (int s = 0; s < nTag; s++)
                        {
                            for (int sPre = 0; sPre < nTag; sPre++)
                            {
                                int f = _fGene.getEdgeFeatID(id, sPre, s);
                                YY[sPre, s] += w[f] * scalar * im.val;
                            }
                        }
                    }
                }
            }
            double maskValue = double.MinValue;

            if (takeExp)
            {
                listTool.listExp(ref Y);
                YY.eltExp();
                maskValue = 0;
            }
            if (mask)
            {
                List <int> tagList = x.getTags();
                for (int s = 0; s < Y.Count; s++)
                {
                    if (tagList[i] != s)
                    {
                        Y[s] = maskValue;
                    }
                }
            }
        }