POTENTIAL潜力值是由一组与地点适应性因子相关的系数计算得到的,表达的是某个地块被开发的可能性。这些系数通过R语言中的Ime4包进行多级逻辑回归得到,系数随着区域的变化而变化,最佳的模型由MuMln包的dredge函数自动选择得到。

模块r.futures.potential 有两种运行模式,如果没有-d标志,它将使用所有给定的预测器来构建模型,而如果使用-d标志,它评估所有预测器的不同组合,并根据AIC选择最佳组合。

  • 输入数据

  • 输出数据

输出文件的格式是CSV文件(以制表符作为分隔符)。表头包含因子的名称,第一列是表示子区域的标识符。列的顺序很重要,第二列表示截距,第三列表示开发压力,然后是预测因子。因此,开发压力列必须指定为选项列中的第一列。

  • 源码解析

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
##############################################################################
#
# MODULE:       r.futures.potential
#
# AUTHOR(S):    Anna Petrasova (kratochanna gmail.com)
#
# PURPOSE:      FUTURES Potential submodel
#
# COPYRIGHT:    (C) 2016 by the GRASS Development Team
#
#               This program is free software under the GNU General Public
#               License (>=v2). Read the file COPYING that comes with GRASS
#               for details.
#
###############################################################################%module
#% description: Module for computing development potential as input to r.futures.pga
#% keyword: raster
#% keyword: statistics
#%end
#%option G_OPT_V_INPUT
#%end
#%option G_OPT_F_OUTPUT
#% description: Output Potential file
#%end
#%option G_OPT_DB_COLUMNS
#% description: Names of attribute columns representing sampled predictors
#% required: yes
#%end
#%option G_OPT_DB_COLUMN
#% key: developed_column
#% description: Name of attribute column representing development
#% required: yes
#%end
#%option G_OPT_DB_COLUMN
#% key: subregions_column
#% description: Name of attribute column representing subregions
#% required: yes
#%end
#%option
#% type: integer
#% key: min_variables
#% description: Minimum number of predictors considered
#% required: no
#% answer: 1
#% options: 1-20
#%end
#%option
#% type: integer
#% key: max_variables
#% description: Maximum number of predictors considered
#% required: no
#% options: 1-20
#%end
#%flag
#% key: d
#% description: Use dredge fuction to find best model
#%endimport sys
import atexit
import subprocess
import grass.script as gscript#R 语言脚本
rscript = """
# load required libraries
for (package in c("MuMIn", "lme4", "optparse")) {if (!(is.element(package, installed.packages()[,1]) ))stop(paste("Package", package, " not found"))}
suppressPackageStartupMessages(library(MuMIn))
suppressPackageStartupMessages(library(lme4))
suppressPackageStartupMessages(library(optparse))
option_list = list(make_option(c("-i","--input"), action="store", default=NA, type='character', help="input CSV file"),make_option(c("-o","--output"), action="store", default=NA, type='character', help="output CSV file"),make_option(c("-l","--level"), action="store", default=NA, type='character', help="level variable name"),make_option(c("-r","--response"), action="store", default=NA, type='character', help="binary response variable name"),make_option(c("-d","--usedredge"), action="store", default=NA, type='logical', help="use dredge to find best model"),make_option(c("-m","--minimum"), action="store", default=NA, type='integer', help="minimum number of variables for dredge"),make_option(c("-x","--maximum"), action="store", default=NA, type='integer', help="maximum number of variables for dredge")
)opt = parse_args(OptionParser(option_list=option_list))# 模型调用
# import data
input_data = read.csv(opt$input)
# create global model with all variables
predictors <- names(input_data)
if (!is.na(opt$level)) {predictors <- predictors[predictors != opt$level]
}
predictors <- predictors[predictors != opt$response]if (is.na(opt$level)) {fmla <- as.formula(paste(opt$response, " ~ ", paste(c(predictors), collapse= "+")))model = glm(formula=fmla, family = binomial, data=input_data, na.action = "na.fail")
} else {interc <- paste("(1|", opt$level, ")")fmla <- as.formula(paste(opt$response, " ~ ", paste(c(predictors, interc), collapse= "+")))model = glmer(formula=fmla, family = binomial, data=input_data, na.action = "na.fail")
}if(opt$usedredge) {#create all possible models, always include county as the levelif (is.na(opt$level)) {select.model <- dredge(model, evaluate=TRUE, rank="AIC", m.lim=c(opt$minimum, opt$maximum), trace=FALSE)} else {select.model <- dredge(model, evaluate=TRUE, rank="AIC", fixed=~(1|opt$level), m.lim=c(opt$minimum, opt$maximum), trace=FALSE)}# save the best modelmodel.best <- get.models(select.model, 1)if (is.na(opt$level)) {model = glm(formula(model.best[[1]]), family = binomial, data=input_data, na.action = "na.fail")} else {model = glmer(formula(model.best[[1]]), family = binomial, data=input_data, na.action = "na.fail")}
}
print(summary(model))
if (is.na(opt$level)) {coefs <- t(as.data.frame(coef(model)))
} else {coefs <- as.data.frame(coef(model)[[1]])
}
write.table(cbind(rownames(coefs), coefs), opt$output, row.names=FALSE, sep="\t")
"""TMP_CSV = None
TMP_POT = None
TMP_RSCRIPT = Nonedef cleanup():gscript.try_remove(TMP_CSV)gscript.try_remove(TMP_POT)gscript.try_remove(TMP_RSCRIPT)def main():vinput = options['input']columns = options['columns'].split(',')binary = options['developed_column']level = options['subregions_column']minim = int(options['min_variables'])dredge = flags['d']# 相关因子的数量判断if options['max_variables']:maxv = (options['max_variables'])else:maxv = len(columns)if dredge and minim > maxv:gscript.fatal(_("Minimum number of predictor variables is larger than maximum number"))global TMP_CSV, TMP_RSCRIPT, TMP_POT# 临时csv文件TMP_CSV = gscript.tempfile(create=False) + '.csv'# TMP_RSCRIPT = gscript.tempfile()include_level = True#distinct = gscript.read_command('v.db.select', flags='c', map=vinput,columns="distinct {l}".format(l=level)).strip()#组织输入文件if len(distinct.splitlines()) <= 1:include_level = Falsesingle_level = distinct.splitlines()[0]with open(TMP_RSCRIPT, 'w') as f:f.write(rscript)TMP_POT = gscript.tempfile(create=False) + '_potential.csv'columns += [binary]if include_level:columns += [level]where = "{c} IS NOT NULL".format(c=columns[0])for c in columns[1:]:where += " AND {c} IS NOT NULL".format(c=c)gscript.run_command('v.db.select', map=vinput, columns=columns, separator='comma', where=where, file=TMP_CSV)if dredge:gscript.info(_("Running automatic model selection ..."))else:gscript.info(_("Computing model..."))#调用R包cmd = ['Rscript', TMP_RSCRIPT, '-i', TMP_CSV,  '-r', binary,'-m', str(minim), '-x', str(maxv), '-o', TMP_POT, '-d', 'TRUE' if dredge else 'FALSE']if include_level:cmd += [ '-l', level]p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)stdout, stderr = p.communicate()print(stderr)if p.returncode != 0:print(stderr)gscript.fatal(_("Running R script failed, check messages above"))gscript.info(_("Best model summary:"))gscript.info("-------------------------")print(stdout)# 输出潜力文件with open(TMP_POT, 'r') as fin, open(options['output'], 'w') as fout:i = 0for line in fin.readlines():row = line.strip().split('\t')row = [each.strip('"') for each in row]if i == 0:row[0] = "ID"row[1] = "Intercept"if i == 1 and not include_level:row[0] = single_levelfout.write('\t'.join(row))fout.write('\n')i += 1if __name__ == "__main__":options, flags = gscript.parser()atexit.register(cleanup)sys.exit(main())

FUTURES模型 | 5. Potential 潜力子模块相关推荐

  1. FUTURES模型 | 4. Demand 需求子模块

    r.futures.demand模块决定预期的土地变化总量,它基于历史人口和土地发展数据之间的相关关系,创建了一个需求表格,记录在每个分区的每个步骤上转换的细胞数量.demand使用简单回归计算人口( ...

  2. 43_pytorch nn.Module,模型的创建,构建子模块,API介绍,Sequential(序号),ModuleList,ParameterList,案例等(学习笔记)

    1.40.PyTorch nn.Module 1.40.1.模型的创建 1.40.2.构建子模块 1.40.3.nn.Module API介绍 1.40.3.1.核心功能 1.40.3.2.查看模块 ...

  3. 模型类型与加速潜力的关系

    模型本身的类型也会对模型加速的潜力有影响,一个非常不严谨的大致印象是:加速潜力上卷积神经网络(CNN)> 循环神经网络(RNN)> 强化学习(RL).CNN 由于每一层的卷积核(神经元)都 ...

  4. [译] 探究 Swift 中的 Futures Promises

    本文讲的是[译] 探究 Swift 中的 Futures & Promises, 原文地址:Under the hood of Futures & Promises in Swift ...

  5. CVPR 2020 | 给Deepfake 假脸做 X-Ray,新模型把换脸图打回原形

    机器之心报道 作者:思源 计算机视觉顶会 CVPR 2020 接收结果已公布,6656 篇有效投稿中录取了 1470 篇论文,录取率约为 22%.本文介绍了微软亚洲研究院的研究者被 CVPR 2020 ...

  6. AAAI | 深度生成模型—NEVAE

    今天给大家介绍的是印度理工学院Niloy Ganguly教授课题组在AAAI2019发表的一篇关于分子生成的论文.作者基于VAE提出一种新的分子图生成模型NEVAE,其编码器和解码器经过特殊设计,通过 ...

  7. 观点|基础模型产业发展路在何方?李飞飞等共话基础模型未来趋势

    [专栏:前沿进展]8月,美国斯坦福大学李飞飞等学者联名发布「基础模型:机遇和挑战」的综述文章.8月23日,上述学者在纽约召开「Workshop of Foundation Models」研讨会,来自美 ...

  8. 透视鹏程.盘古:首个2000亿参数中文大模型是怎样炼成的?

    2021-05-19 10:21:00 机器之心原创 机器之心编辑部 给足算力和数据,就能训练出千亿参数的大模型?事实没有那么简单. 「70 年的人工智能研究史告诉我们,利用计算能力的一般方法最终是最 ...

  9. 浅议 JavaScript 的 Promises/Futures 模式

    翻译:疯狂的技术宅 原文:http://davidshariff.com/blog/... 本文首发微信公众号:jingchengyideng 欢迎关注,每天都给你推送新鲜的前端技术文章 随着 Jav ...

最新文章

  1. 普京谈“元宇宙”:这无疑是一种挑战
  2. 计算机科学家 成就,25年来的最高成就!MIT科学家让计算机提供创意,可自动设计机器人形态...
  3. ARMV8/ARMV9指令集概述(翻译)
  4. ftp 工具_ftp,ftp工具哪个好用
  5. 在Web应用中使用localforage存储离线数据
  6. java中统计括号配对_括号配对问题(C语言或JAVA语言代码)
  7. 卸载ncurses_linux中使用ncurses出现中文乱码解决方法
  8. JVM调优 dump文件怎么生成和分析
  9. leetcode面试题 08.04. 幂集(递归)
  10. mysql必知必会_MySQL必知必会
  11. azure机器学习_如何在Azure机器学习中使用JSON数据
  12. RabbitMQ 2.8.7 发布,AMQP 消息队列
  13. 回溯法求解背包问题java_背包问题回溯法的递归实现(java)
  14. LINUX下安装svn客户端
  15. 1.1 电 电流 电压 电路 基本电子元件
  16. 【《机器学习》周志华学习笔记2.3.4】~模型评估与选择-代价敏感错误率与代价曲线
  17. VMware虚拟机的创建
  18. 输入下载页面链接自动获取ipa下载地址,支持本地下载,支持蒲公英和fir及绝大多数自定义下载页
  19. 【生信可视化】ChemDraw基础操作教程
  20. “adb”不是内部或外部命令,也不是可运行的程序或批处理文件

热门文章

  1. 虚拟机jdk安装,配置环境变量
  2. 品读国学经典之一——管仲《牧民》
  3. mysql外键设置sql语句_sql设置外键(设置外键的sql语句)
  4. Vue3为什么要使用组合式API——Vue3的组合式API和Vue2的选项式API的优缺点
  5. linux性能分析工具:perf入门一页纸
  6. vscode里面进行git提交
  7. 生产图纸管理防泄密解决方案,完整的图纸安全管理体系
  8. Linux的ll命令详解
  9. laravel事务、seeder类、模型对象、成员属性
  10. 通过原生 js 隐藏和显示标签元素