1 Star 2 Fork 7

kerrydu/malmq2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
malmq2.mata 3.16 KB
一键复制 编辑 原始数据 按行查看 历史
kerrydu 提交于 2021-08-01 16:57 . autocompiled
* 2 Nov 2019
version 16
// Versioning
_get_version malmq2
assert("`package_version'" != "")
mata: string scalar malmq2_version() return("`package_version'")
mata: string scalar malmq2_stata_version() return("`c(stata_version)'")
mata: string scalar malmq2_joint_version() return("`package_version'|`c(stata_version)'")
cap mata mata drop sdf_i()
cap mata mata drop sdf_o()
mata:
mata clear
void function sdf_o(string scalar d, ///
string scalar touse, ///
string scalar rflag, ///
real scalar k, ///
real scalar scale, ///
string scalar g, ///
real scalar maxiter, ///
real scalar tol)
{
data=st_data(.,d,touse)
data=data'
dataref=st_data(.,d,rflag)
dataref=dataref'
M=rows(data)
Xref=dataref[1..k,.]
Yref=dataref[k+1..M,.]
X=data[1..k,.]
Y=data[k+1..M,.]
N=cols(dataref)
class LinearProgram scalar q
q = LinearProgram()
if(maxiter!=-1){
q.setMaxiter(maxiter)
}
if (tol!=-1){
q.setTol(tol)
}
c = (1, J(1,N,0))
lowerbd =., J(1,N,0)
upperbd = J(1,N+1,.)
if(scale==1){
Aec= (0, J(1,N,1))
q.setEquality(Aec, 1)
}
theta=J(cols(data),1,.)
for(j=1;j<=cols(data);j++){
A1 = (J(k,1,0),Xref)
b1 = (X[.,j])
A2 = (Y[.,j],-Yref)
b2=J(M-k,1,0)
Aie=A1 \ A2
bie=b1 \ b2
q.setCoefficients(c)
q.setInequality(Aie, bie)
q.setBounds(lowerbd, upperbd)
theta[j]=q.optimize()
}
st_view(gen=.,.,g,touse)
gen[.,.]=theta
}
void function sdf_i(string scalar d, ///
string scalar touse, ///
string scalar rflag, ///
real scalar k, ///
real scalar scale, ///
string scalar g, ///
real scalar maxiter, ///
real scalar tol)
{
data=st_data(.,d,touse)
data=data'
dataref=st_data(.,d,rflag)
dataref=dataref'
M=rows(data)
Xref=dataref[1..k,.]
Yref=dataref[k+1..M,.]
X=data[1..k,.]
Y=data[k+1..M,.]
N=cols(dataref)
class LinearProgram scalar q
q = LinearProgram()
q.setMaxOrMin("min")
if(maxiter!=-1){
q.setMaxiter(maxiter)
}
if (tol!=-1){
q.setTol(tol)
}
c = (1, J(1,N,0))
lowerbd =., J(1,N,0)
upperbd = J(1,N+1,.)
if(scale==1){
Aec= (0, J(1,N,1))
q.setEquality(Aec, 1)
}
theta=J(cols(data),1,.)
for(j=1;j<=cols(data);j++){
A1 = (-X[.,j],Xref)
b1 = J(k,1,0)
A2 = (J(M-k,1,0),-Yref)
b2= -Y[.,j]
Aie=A1 \ A2
bie=b1 \ b2
q.setCoefficients(c)
q.setInequality(Aie, bie)
q.setBounds(lowerbd, upperbd)
theta[j]=q.optimize()
}
st_view(gen=.,.,g,touse)
gen[.,.]=theta
}
end
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kerrydu/malmq2.git
git@gitee.com:kerrydu/malmq2.git
kerrydu
malmq2
malmq2
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385