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