/// <summary>
        /// compute sim btw src and tgt
        /// </summary>
        /// <param name="inSrc">in matrix format</param>
        /// <param name="inTgt">in matrix format</param>
        /// <param name="outScore"></param>
        public void PredictingV0(string inSrc, string inTgt, string outScore)
        {
            StreamWriter sw = new StreamWriter(outScore);

            int n = 0;

            foreach (Pair <string, string> p in
                     PairEnum <string, string> .E(FileEnum.GetLines(inSrc), FileEnum.GetLines(inTgt)))
            {
                double sim = 0;

                if (p.First.Trim() != "" && p.Second.Trim() != "")
                {
                    sim = CosineSim(p.First.Trim(), p.Second.Trim());
                }

                // UInt32 score = (UInt32)((1 + sim) / 2.0 * Int32.MaxValue);
                sw.WriteLine(sim);
                n++;
                if (n % 1000 == 0)
                {
                    Console.Write("{0}\r", n);
                }
            }

            sw.Close();
        }
Example #2
0
 public string GetPara(PairEnum key)
 {
     foreach (var kv in affixParameters)
     {
         if (kv.key == key)
         {
             return(kv.value);
         }
     }
     Debug.LogError("NotFindAffixPara " + effectType + " key " + key);
     return(null);
 }
        /// <summary>
        /// compute sim btw src and tgt
        /// </summary>
        /// <param name="inTSV">input labeled data file</param>
        /// <param name="inSrc">in vector format</param>
        /// <param name="inTgt">in vector format</param>
        /// <param name="FeatName">feature name</param>
        /// <param name="outTSV">output score file</param>
        /// <param name="bOutputVector">whether to output vector</param>
        public void PredictingV1(string inTSV, string inSrc, string inTgt, string FeatName, string outTSV, bool bOutputVector)
        {
            StreamWriter sw = new StreamWriter(outTSV);
            StreamReader sr = null;

            if (inTSV != "")
            {
                sr = new StreamReader(inTSV);
            }

            Console.WriteLine("computing sim...");
            string sLine = "";
            int    n     = 0;

            if (sr != null)
            {
                sLine = sr.ReadLine();

                sw.Write("{0}\t{1}", sLine, FeatName);
                if (bOutputVector)
                {
                    for (int i = 0; i < m_SrcModel.NumOutputNode; ++i)
                    {
                        sw.Write("\t{0}_s{1}", FeatName, i);
                    }
                    for (int i = 0; i < m_TgtModel.NumOutputNode; ++i)
                    {
                        sw.Write("\t{0}_t{1}", FeatName, i);
                    }
                }
                sw.Write("\n");
            }

            sLine = "";
            foreach (Pair <string, string> p in PairEnum <string, string> .E(FileEnum.GetLines(inSrc), FileEnum.GetLines(inTgt)))
            {
                if (sr != null)
                {
                    sLine = sr.ReadLine();
                }

                List <Dictionary <int, double> > srcMt = TextUtils.String2Matrix(p.First);
                List <Dictionary <int, double> > tgtMt = TextUtils.String2Matrix(p.Second);
                double[] srcVt = m_SrcModel.Fprop(srcMt);
                double[] tgtVt = m_TgtModel.Fprop(tgtMt);
                double   sim   = NNModelUtils.CosineSim(srcVt, tgtVt);

                if (sr != null)
                {
                    sw.Write("{0}\t{1}", sLine, (float)sim);
                }
                else
                {
                    sw.Write((float)sim);
                }

                if (bOutputVector)
                {
                    for (int i = 0; i < m_SrcModel.NumOutputNode; ++i)
                    {
                        sw.Write("\t{0}", (float)srcVt[i]);
                    }
                    for (int i = 0; i < m_TgtModel.NumOutputNode; ++i)
                    {
                        sw.Write("\t{0}", (float)tgtVt[i]);
                    }
                }
                sw.Write("\n");

                n++; if (n % 1000 == 0)
                {
                    Console.Error.Write("{0}\r", n);
                }
            }
            Console.WriteLine("{0} pairs.", n);

            sw.Close();
            if (sr != null)
            {
                sr.Close();
            }
        }