Commit 9993a834 by 陶然

init

parent 91845da6
......@@ -9,6 +9,7 @@ namespace LDA.LdaModel
public int K; //#Topics
public double alpha; // Dirichlet Prior Parameter for Document->Topic
public double beta; // Dirichlet Prior Parameter for Topic->Word
public double logLikelihood;
public double LogLikelihood
{
get
......
......@@ -130,26 +130,27 @@ namespace LDA.LdaModel
getLda.M = M;
getLda.phi = phi;
getLda.theta = theta;
getLda.logLikelihood = LogLikelihood;
return getLda;
}
public void PrintModelInfo()
{
Console.WriteLine("Aplha: " + alpha.ToString());
Console.WriteLine("Beta: " + beta.ToString());
Console.WriteLine("M: " + M);
Console.WriteLine("K: " + K);
Console.WriteLine("V: " + V);
Console.WriteLine("Total iterations:" + niters);
Console.WriteLine("Save at: " + savestep);
Console.WriteLine();
//Console.WriteLine("Aplha: " + alpha.ToString());
//Console.WriteLine("Beta: " + beta.ToString());
//Console.WriteLine("M: " + M);
//Console.WriteLine("K: " + K);
//Console.WriteLine("V: " + V);
//Console.WriteLine("Total iterations:" + niters);
//Console.WriteLine("Save at: " + savestep);
//Console.WriteLine();
}
private void GibbsSampling(int totalIter)
{
for (int iter = 1; iter <= totalIter; iter++)
{
Console.Write("Iteration " + iter + ":");
//Console.Write("Iteration " + iter + ":");
var stopWatch = new Stopwatch();
stopWatch.Start();
for (int i = 0; i < wn; i++)
......@@ -159,7 +160,7 @@ namespace LDA.LdaModel
}
stopWatch.Stop();
Console.WriteLine(stopWatch.ElapsedMilliseconds / 1000.0 + " seconds");
//Console.WriteLine(stopWatch.ElapsedMilliseconds / 1000.0 + " seconds");
if (iter % savestep == 0)
{
//保存参数、文档分布等
......@@ -195,7 +196,7 @@ namespace LDA.LdaModel
}
//主题编号
//sw.Write("Topic " + k + "th:\n");
Console.WriteLine("Topic " + k + "th:\n");
//Console.WriteLine("Topic " + k + "th:\n");
//主题词
var wordsProbsListOrdered = wordsProbsList.OrderBy(e => -e.Value).ToList();
......@@ -203,11 +204,11 @@ namespace LDA.LdaModel
{
string word = cor.GetStringByID(wordsProbsListOrdered[i].Key);
// sw.WriteLine("\t" + word + " " + wordsProbsListOrdered[i].Value);
Console.WriteLine("\t" + word + " " + wordsProbsListOrdered[i].Value);
//Console.WriteLine("\t" + word + " " + wordsProbsListOrdered[i].Value);
}
}
Console.WriteLine("LogLikelihood= " + LogLikelihood);
//Console.WriteLine("LogLikelihood= " + LogLikelihood);
}
}
}
......
......@@ -6,32 +6,32 @@ using System.Threading.Tasks;
namespace LDA.LdaModel
{
class TopicSimilarityCos
public static class TopicSimilarityCos
{
public double SimilarityCos()
public static double SimilarityCos(List<string> lstr1, List<string> lstr2)
{
List<string> lstr1 = new List<string>();
lstr1.Add("稀疏");
lstr1.Add("信号");
lstr1.Add("算法");
lstr1.Add("方法");
lstr1.Add("轴承");
lstr1.Add("故障");
lstr1.Add("贝叶斯");
lstr1.Add("模型");
lstr1.Add("发动机");
lstr1.Add("降低");
List<string> lstr2 = new List<string>();
lstr2.Add("测量");
lstr2.Add("发动机");
lstr2.Add("叶尖");
lstr2.Add("间隙");
lstr2.Add("性能");
lstr2.Add("控制");
lstr2.Add("微波");
lstr2.Add("叶片");
lstr2.Add("降低");
lstr2.Add("自主");
//List<string> lstr1 = new List<string>();
//lstr1.Add("稀疏");
//lstr1.Add("信号");
//lstr1.Add("算法");
//lstr1.Add("方法");
//lstr1.Add("轴承");
//lstr1.Add("故障");
//lstr1.Add("贝叶斯");
//lstr1.Add("模型");
//lstr1.Add("发动机");
//lstr1.Add("降低");
//List<string> lstr2 = new List<string>();
//lstr2.Add("测量");
//lstr2.Add("发动机");
//lstr2.Add("叶尖");
//lstr2.Add("间隙");
//lstr2.Add("性能");
//lstr2.Add("控制");
//lstr2.Add("微波");
//lstr2.Add("叶片");
//lstr2.Add("降低");
//lstr2.Add("自主");
//求并集
var strUnion = lstr1.Union(lstr2);
......@@ -58,8 +58,7 @@ namespace LDA.LdaModel
//求分母(2)
den2 += Math.Pow(int2[i], 2);
}
double cos = s / (Math.Sqrt(den1) * Math.Sqrt(den2));
Console.WriteLine(cos);
//Console.WriteLine(cos);
return s / (Math.Sqrt(den1) * Math.Sqrt(den2));
}
}
......
......@@ -28,7 +28,7 @@ namespace Njust.Pdf.Analysis.Entities
public string SourceTopic { get; set; }
[ApiMember(Description = "目标主题编号")]
public string TargeTopic { get; set; }
public string TargetTopic { get; set; }
[ApiMember(Description = "源主题词")]
public string SourceTopicWord { get; set; }
......@@ -37,6 +37,6 @@ namespace Njust.Pdf.Analysis.Entities
public string TargetTopicWord { get; set; }
[ApiMember(Description = "余弦相似度")]
public string CosSim { get; set; }
public double CosSim { get; set; }
}
}
......@@ -116,9 +116,11 @@ namespace Njust.Pdf.Analysis.Tranforms
foreach (var item in preInserts)
{
var stream = files[item.HashCode];
var exist = exists.FirstOrDefault(o => o.HashCode == item.HashCode);
if (exist != null)
{
KiviiContext.VirtualFiles.WriteFile(exist.ImportPath, stream);
rtns.Results.Add(exist);
continue;
}
......@@ -126,7 +128,6 @@ namespace Njust.Pdf.Analysis.Tranforms
conn.Insert(item);
item.RemoveAllOnlyProperties();
rtns.Results.Add(item);
var stream = files[item.HashCode];
stream.Position = 0;
KiviiContext.VirtualFiles.WriteFile(item.ImportPath, stream);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment