⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ml_check.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 2 页
字号:
*! version 3.0.9  21jan2004
program define ml_check
	version 6
	ml_defd
	syntax [, MAXFEAS(integer 1000)] 	/* undocumented; for testing
						   purposes */

	capture ml trace off
	capture ml count off

	Test1
	Test2

	if scalar($ML_f)==. {
		GetFeas `maxfeas'
		Test1
		Test2
	}

	Test3
	Test4

	Test5
	Test6

	tempname b0 f0 g0 V0
	matrix `b0' = $ML_b
	scalar `f0' = scalar($ML_f)
	capture matrix `g0' = $ML_g
	if _rc==1 { exit 1 }
	capture matrix `V0' = $ML_V
	if _rc==1 { exit 1 }

	GetFeas2
	if mreldif(matrix(`b0'),matrix($ML_b))==0 {
		di _n in gr "Stata found the same coefficient vector again!" /*
		*/ _n "That is unlikely.  Searching again:"
		GetFeas2
		if mreldif(matrix(`b0'),matrix($ML_b))==0 {
			#delimit ;
			di _n in gr
"Stata found the same coefficient vector a second time!" ;
			di in gr
"Given that Stata uses a random search method to find feasible vectors, to find"
_n
"the same vector twice in a row is so unlikely that the cause must be" _n
in ye "$ML_user" in gr "." ;
			#delimit cr
			exit 9
		}
	}
	Test7 `b0' `f0' `g0' `V0'
	Test8 `b0' `f0' `g0' `V0'
	Test9 `b0' `f0' `g0' `V0'

	di in smcl in ye _n "{hline 78}" _n _col(26)  /*
	*/ "$ML_user HAS PASSED ALL TESTS" /*
	*/ _n "{hline 78}"

	Test10

	SetVal
	if `r(val)'==0 {
		exit
	}

	di _n in gr "You should check that the derivatives are right."

	if "$ML_meth"=="d1" | "$ML_meth"=="d2" {
		di in gr _n "Stata recommends that you reissue the " /*
		*/ in ye "ml model"  /*
		*/ in gr " statement and this time specify" _n "method " /*
		*/ in ye "${ML_meth}debug" in gr ".  Then use " /*
		*/ in ye "ml maximize" in gr /*
		*/ " to obtain estimates."
	}
	else if "$ML_meth"=="d1debug" | "$ML_meth"=="d2debug" {
		di in gr _n "Use " in ye "ml maximize" in gr /*
			*/ " to obtain estimates."
	}
	else	exit

	#delimit ;
	di _n in gr
"The output will include a report comparing analytic to numeric derivatives." _n
"Do not be concerned if your analytic derivatives differ from the numeric ones"
_n "in early iterations." _n(2)
"The analytic gradient will differ from the numeric one in early iterations," _n
"then the mreldif() difference should become less than 1e-6 in the middle" _n
"iterations, and the difference will increase again in the final iterations" _n
"as the gradient goes to zero." ;

	if "$ML_meth"=="d1" | "$ML_meth"=="d1debug" { exit } ;

	di _n in gr
"The analytic negative Hessian will differ from the numeric one in early" _n
"iterations, but the mreldif() difference should decrease with each iteration"
_n
"and become less than 1e-6 in the final iterations." ;
	#delimit cr
end


program define Test1
	di _n in gr "Test 1:  Calling " in ye "$ML_user" in gr /*
	*/ " to check if it computes $ML_crtyp and" _n /*
	*/ _col(10) "does not alter coefficient vector..."
	tempname b0
	matrix `b0 ' = $ML_b
	capture scalar drop $ML_f
	capture $ML_eval 0
	if _rc==0 {
		CheckF			/* created f 	*/
					/* b undamaged 	*/
		if "$ML_meth"=="lf" {
			ML_elf
		}
		else	EqualB `b0'
		Passed
		exit
	}
	local rc = _rc
	Break
	Failed `rc'
	capture scalar drop $ML_f
	Trace 0 `rc'
	exit `rc'
end


program define Test2
	di _n in gr "Test 2:  Calling " in ye "$ML_user" in gr /*
	*/ " again to check if the same $ML_crtyp value" _n /*
	*/ _col(10) "is returned..."
	tempname f0
	scalar `f0' = scalar($ML_f)
	capture scalar drop $ML_f
	capture $ML_eval 0
	if _rc==0 {
		EqualF `f0'		/* created f and equal */
		Passed
		exit
	}
	local rc = _rc
	Break
	Failed `rc'
	di _col(10) in gr "Perhaps " in ye "$ML_user" in gr /*
	*/ " attempted to redefine something defined previously."
	di in gr _col(10) "Did you forget to drop some working variable?"
	Trace 0 `rc'
	exit `rc'
end


program define GetFeas /* #_maxfeas */
	di in smcl in gr _n "{hline 78}"
	#delimit ;
	di in gr
"The initial values are not feasible.  This may be because the initial values"
_n
"have been chosen poorly or because there is an error in "
in ye "$ML_user" in gr " and it" _n
"always returns missing no matter what the parameter values." ;
	di _n in gr
"Stata is going to use " in ye "ml search"
in gr " to find a feasible set of initial values." _n
"If " in ye "$ML_user" in gr
" is broken, this will not work and you will have to press "
in ye "Break" _n in gr "to make " in ye "ml search" in gr " stop". ;
	#delimit cr
	di _n in gr "Searching..."
	ml_searc, trace maxfeas(`1')
	di _n in smcl in gr "restarting tests..." _n "{hline 78}"
end

program define Test3
	di _n in gr "Test 3:  Calling " in ye "$ML_user" in gr /*
	*/ " to check if 1st derivatives are computed..."
	if "$ML_meth"=="lf" | "$ML_meth"=="d0" {
		NotRel
		exit
	}
	tempname f0 b0
	scalar `f0' = scalar($ML_f)
	matrix `b0' = $ML_b
	capture mat drop $ML_g
	capture $ML_eval 1
	if _rc==0 {
		EqualB `b0'		/* b undamaged	*/
		EqualF `f0'		/* equal f 	*/
		CheckG			/* created g	*/
		Passed
		exit
	}
	local rc = _rc
	Break
	Failed `rc'
	capture mat drop $ML_g
	Trace 1 `rc'
	exit `rc'
end

program define Test4
	di _n in gr "Test 4:  Calling " in ye "$ML_user" in gr /*
	*/ " again to check if the same 1st derivatives are" _n /*
	*/ _col(10) "returned..."
	if "$ML_meth"=="lf" | "$ML_meth"=="d0" {
		NotRel
		exit
	}
	tempname g0
	matrix `g0 ' = $ML_g
	capture mat drop $ML_g
	capture $ML_eval 1
	if _rc==0 {
		EqualG `g0'		/* equal g	*/
		Passed
		exit
	}
	local rc = _rc
	Break
	Failed `rc'
	capture mat drop $ML_g
	Trace 1 `rc'
	exit `rc'
end

program define Test5
	di _n in gr "Test 5:  Calling " in ye "$ML_user" in gr /*
	*/ " to check if 2nd derivatives are computed..."
	if "$ML_meth"=="lf" | "$ML_meth"=="d0" | "$ML_meth"=="d1" | /*
		*/ "$ML_meth" == "d1debug" {
		NotRel
		exit
	}
	tempname f0 b0 g0
	scalar `f0' = scalar($ML_f)
	matrix `b0' = $ML_b
	matrix `g0' = $ML_g
	capture mat drop $ML_V
	capture $ML_eval 2
	if _rc==0 {
		EqualB `b0'		/* b undamged	*/
		EqualF `f0'		/* equal f 	*/
		EqualG `g0'		/* equal g	*/
		CheckV			/* created g	*/
		Passed
		exit
	}
	local rc = _rc
	Break
	Failed `rc'
	capture mat drop $ML_V
	Trace 2 `rc'
	exit `rc'
end

program define Test6
	di _n in gr "Test 6:  Calling " in ye "$ML_user" in gr /*
	*/ " again to check if the same 2nd derivatives are" _n /*
	*/ _col(10) "returned..."
	if "$ML_meth"=="lf" | "$ML_meth"=="d0" | "$ML_meth"=="d1" | /*
		*/ "$ML_meth" == "d1debug" {
		NotRel
		exit
	}
	tempname V0
	matrix `V0' = $ML_V
	capture $ML_eval 2
	if _rc==0 {
		EqualV `V0'		/* equal V	*/
		Passed
		exit
	}
	local rc = _rc
	Break
	Failed `rc'
	capture mat drop $ML_V
	Trace 1 `rc'
	exit `rc'
end

program define Test7 /* b0 f0 g0 V0 */
	di _n in gr "Test 7:  Calling " in ye "$ML_user" in gr /*
	*/ " to check $ML_crtyp at the new values..."
	tempname b0
	capture scalar drop $ML_f
	capture $ML_eval 0
	if _rc==0 {
		CheckF			/* created f 	*/
		NoteqF `0'
		Passed
		exit
	}
	local rc = _rc
	Break
	Failed `rc'
	capture scalar drop $ML_f
	Trace 0 `rc'
	exit `rc'
end

program define Test8 /* b0 f0 g0 V0 */
	di _n in gr "Test 8:  Calling " in ye "$ML_user" in gr /*
	*/ " requesting 1st derivatives at the new values..."
	if "$ML_meth"=="lf" | "$ML_meth"=="d0" {
		NotRel
		exit
	}
	capture $ML_eval 1
	if _rc==0 {
		CheckG			/* created f 	*/
		NoteqG `0'
		Passed
		exit
	}
	local rc = _rc
	Break
	Failed `rc'
	Trace 0 `rc'
	exit `rc'
end

program define Test9 /* b0 f0 g0 V0 */
	di _n in gr "Test 9:  Calling " in ye "$ML_user" in gr /*
	*/ " requesting 2nd derivatives at the new values..."
	if "$ML_meth"=="lf" | "$ML_meth"=="d0" | "$ML_meth"=="d1" | /*
		*/ "$ML_meth" == "d1debug" {
		NotRel
		exit
	}
	capture $ML_eval 2
	if _rc==0 {
		CheckV
		NoteqV `0'
		Passed
		exit
	}
	local rc = _rc
	Break
	Failed `rc'
	Trace 0 `rc'
	exit `rc'
end

program define Test10
	#delimit ;
	di _n in gr "Test 10: Does " in ye "$ML_user" in gr
	" produce unanticipated output?" ;
	di _col(10) in gr
"This is a minor issue.  Stata has been running " in ye "$ML_user"
in gr " with all" _n _col(10)
"output suppressed.  This time Stata will not suppress the output." _n _col(10)
"If you see any unanticipated output, you need to place " in ye "quietly" in gr
" in" _n _col(10)
"front of some of the commands in " in ye "$ML_user" in gr "." ;

	#delimit cr

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -