def GIS():
global C
global FeaWeights
for wid in WordDic.keys():
FeaWeights[wid] = {}
for classid in ClassList:
FeaWeights[wid][classid] = 0.0
n = 0
prelogllh = -1000000.0
logllh = -10000.0
while logllh - prelogllh >= LogLLDiff and n < MaxIteration:
n += 1
prelogllh = logllh
logllh = 0.0
print "Iteration", n
for wid in WordDic.keys():
for classid in ClassList:
FeaClassTable[wid][1][classid] = 0.0
#compute expected values of features subject to the model p(y|x)
for doc in DocList:
classProbs = [0.0] * len(ClassList)
sum = 0.0
for i in range(len(ClassList)):
classid = ClassList[i]
pyx = 0.0
for wid in doc[0].keys():
pyx += FeaWeights[wid][classid]
pyx = math.exp(pyx)
classProbs[i] = pyx
sum += pyx
for i in range(len(ClassList)):
classProbs[i] = classProbs[i] / sum
for i in range(len(ClassList)):
classid = ClassList[i]
if classid == doc[1]:
logllh += math.log(classProbs[i])
for wid in doc[0].keys():
FeaClassTable[wid][1][classid] += classProbs[i] * doc[0][wid]
#update feature weights
for wid in WordDic.keys():
for classid in ClassList:
empValue = 0.0
if classid in FeaClassTable[wid][0]:
empValue = FeaClassTable[wid][0][classid]
modelValue = 0.0
if classid in FeaClassTable[wid][1]:
modelValue = FeaClassTable[wid][1][classid]
if empValue == 0.0 or modelValue == 0.0:
continue
FeaWeights[wid][classid] += math.log(
FeaClassTable[wid][0][classid] / FeaClassTable[wid][1][classid]) / C
print "Loglikelihood:", logllh
return

最新文章

  1. Selenium WebDriver Code
  2. Connect to Database Using Custom params链接数据库配置参数说明
  3. java appium api
  4. jquery: json树组数据输出到表格Dom树的处理方法
  5. PostgreSQL数据库基本配置
  6. jquery控制css的display(控制元素的显示与隐藏)
  7. iOS 的 Gif 渲染引擎 FLAnimatedImage-b
  8. 深入了解当前ETL中用到的一些基本技术
  9. C++ 虚函数详解
  10. spring MVC中文乱码相关总结
  11. 新项目引入gulp
  12. heartbeat集群安装配置
  13. Win 7/10 安装Oracle 11g
  14. mysql日志分析工具之mysqlsla
  15. java问题
  16. phpcms中set_config和get_sysinfo函数
  17. Qt中QSlider的样式表设置
  18. top 学习
  19. gson 设置多个别名SerializedName
  20. jquery中的load方法加载页面无法缓存问题

热门文章

  1. DateTimePicker控件为空 分类: WinForm 2014-04-15 09:46 239人阅读 评论(0) 收藏
  2. PHP学习路径
  3. HDFS Users Guide--官方文档
  4. Django初探--开发环境搭建(笔记)
  5. 教学项目之-通过Python实现简单的计算器
  6. aspx页面中获取当前浏览器url
  7. HDU5339
  8. 高健壮性css---Float详细
  9. ViewPager循环广告位的实现
  10. oracle事务特性详解