I did some research by Google and found that Maxlik and MaxLik MT are different package or applications. So, do you have any instruction to write the equivalent code with MaxLik MT to the code written with Maxlik. From my point of view, MaxLik MT is an advanced version of Maxlik since MaxLik MT supports the feature of multi-threading. I am asking this question because I have existing code using Maxlik but I bought the application of MaxLik MT. The task facing me is to "translate" the code with Maxlik to the code with MaxLik MT.1

## 1 Answer

0

**How is Maxlik different from Maxlik MT?**

Maxlikmt is a more advanced version of Maxlik.

1. It uses a PV structure for parameters, and a DS structure for data. The PV structure allows you to store parameters in their original state, i.e., a matrix, or a vector, or symmetric matrix, and there is a method for specifying which elements are fixed and with are free parameters.

2. The use of structures means that the Maxlikmt run can be multi-threaded, i.e., you can run several of them at a time.

3. Maxlikmt allows for bounds on parameters.

4. MLMT is not backwards compatible. If a user wants to run older code, they may need to use Maxlik 5.0.

**Porting a Maxlik Command File to MaxlikMT**

The main issues here in porting to Maxlikmt is the two new structures, the PV structure for handling parameters, and the DS structure for handling data. The analytical gradient is also handled differently in that maxlikmt computes the gradient inside the log-likelihood procedure to reduce redundant calculations whereas in Maxlik the gradient is computed in its own procedure. See Chapter 2 in /wp-content/uploads/2012/10/structures.pdf for a discussion of the PV and DS structures.

The First example illustrates the case where the data are stored on a GAUSS dataset.

```
library maxlik;
#include maxlik.ext
maxset;
proc lpsn(b,z);
local m;
m = z[.,2:4]*b;
retp(z[.,1].*m-exp(m));
endp;
proc lgd(b,z);
retp((z[.,1]-exp(z[.,2:4]*b)).*z[.,2:4]);
endp;
x0 = { .5, .5, .5 };
_max_GradProc = &lgd;
_max_CovPar = 3;
_max_GradCheckTol = .01; /* check calculation of gradient */
{ x,f0,g,h,retcode } = maxlik("psn",0,&lpsn,x0);
call maxprt(x,f0,g,h,retcode);
print;
print "quasi-maximum likelihood v-c matrix of par's";
print h;
```

In this example, the Maxlik command file is using a GAUSS dataset by passing the name as the first argument. The following Maxlikmt command file shows how to accomplish this in Maxlikmt. It also illustrates the difference in how the analytical gradient is handled.

```
library maxlikmt;
proc lpsn(struct PV p, struct DS d, ind);
local m,y,x,b;
struct modelResults mm;
y = d.dataMatrix[.,1];
x = d.dataMatrix[.,2:4];
b = pvUnpack(p,"b");
m = x * b;
if ind[1];
mm.function = y .* m - exp(m);
endif;
if ind[2];
mm.gradient = (y - exp(x*b)) .* x;
endif;
retp(mm);
endp;
//Declare 'p0' to be a PV structure
struct PV p0;
//'Pack' a vector named 3x1 vector
//named 'b' into 'p0'
p0 = pvPack(pvCreate,0.5|0.5|0.5,"b");
//Declare c0 to be a maxlikMTControl struture
struct maxlikmtControl c0;
//Fill 'c0' with default values
c0 = maxlikmtControlCreate();
//Declare 'd0' to be a DS structure
struct DS d0;
d0 = dsCreate();
d0.dname = "psn";
//Declare 'out1' to be a maxlikmtResults structure
struct maxlikmtResults out1;
//Call maxlikmt and store results in 'out1'
out1 = maxlikmt(&lpsn,p0,d0,c0);
//Print results
call maxlikmtprt(out1);
print;
print "quasi-maximum likelihood v-c matrix of par's";
print out1.CovPar;
```

Here is an example where a matrix is being passed for data.

```
library maxlik;
#include maxlik.ext
maxset();
z0 = { 8.3 1, 10.3 2, 19.0 3, 16.0 4, 15.6 5, 19.8 7 };
proc lnlk(b,z);
local dev,s2;
dev = z[.,1] - b[1]*(1 - exp(-b[2]*z[.,2]));
s2 = (dev'dev)/rows(dev);
retp(lnpdfmvn(dev,s2));
endp;
start = { 20, .24 };
{ bhat,f,g,cov,retcode } = maxlik(z0,0,&lnlk,start));
call maxprt(bhat,f,g,cov,retcode);
```

```
library maxlikmt;
z0 = { 8.3 1, 10.3 2, 19.0 3, 16.0 4, 15.6 5, 19.8 7 };
proc lnlk(struct PV p, struct DS d);
local dev,s2,b,z;
b = pvUnpack(p,"b");
z = d.dataMatrix;
dev = z[.,1] - b[1]*(1 - exp(-b[2]*z[.,2]));
s2 = dev'dev/rows(dev);
retp(lnpdfmvn(dev,s2));
endp;
struct DS d0;
d0 = dsCreate();
d0.datamatrix = z0;
start = { 20, .24 };
struct PV p0;
p0 = pvPack(pvCreate,start);
struct maxlikmtControl c0;
struct maxlikmtResults out;
out = maxlikmt(&lnlk,p0,d0,c0);
call maxlikmtprt(out);
```

## Your Answer

## 1 Answer

**How is Maxlik different from Maxlik MT?**

Maxlikmt is a more advanced version of Maxlik.

1. It uses a PV structure for parameters, and a DS structure for data. The PV structure allows you to store parameters in their original state, i.e., a matrix, or a vector, or symmetric matrix, and there is a method for specifying which elements are fixed and with are free parameters.

2. The use of structures means that the Maxlikmt run can be multi-threaded, i.e., you can run several of them at a time.

3. Maxlikmt allows for bounds on parameters.

4. MLMT is not backwards compatible. If a user wants to run older code, they may need to use Maxlik 5.0.

**Porting a Maxlik Command File to MaxlikMT**

The main issues here in porting to Maxlikmt is the two new structures, the PV structure for handling parameters, and the DS structure for handling data. The analytical gradient is also handled differently in that maxlikmt computes the gradient inside the log-likelihood procedure to reduce redundant calculations whereas in Maxlik the gradient is computed in its own procedure. See Chapter 2 in /wp-content/uploads/2012/10/structures.pdf for a discussion of the PV and DS structures.

The First example illustrates the case where the data are stored on a GAUSS dataset.

```
library maxlik;
#include maxlik.ext
maxset;
proc lpsn(b,z);
local m;
m = z[.,2:4]*b;
retp(z[.,1].*m-exp(m));
endp;
proc lgd(b,z);
retp((z[.,1]-exp(z[.,2:4]*b)).*z[.,2:4]);
endp;
x0 = { .5, .5, .5 };
_max_GradProc = &lgd;
_max_CovPar = 3;
_max_GradCheckTol = .01; /* check calculation of gradient */
{ x,f0,g,h,retcode } = maxlik("psn",0,&lpsn,x0);
call maxprt(x,f0,g,h,retcode);
print;
print "quasi-maximum likelihood v-c matrix of par's";
print h;
```

In this example, the Maxlik command file is using a GAUSS dataset by passing the name as the first argument. The following Maxlikmt command file shows how to accomplish this in Maxlikmt. It also illustrates the difference in how the analytical gradient is handled.

```
library maxlikmt;
proc lpsn(struct PV p, struct DS d, ind);
local m,y,x,b;
struct modelResults mm;
y = d.dataMatrix[.,1];
x = d.dataMatrix[.,2:4];
b = pvUnpack(p,"b");
m = x * b;
if ind[1];
mm.function = y .* m - exp(m);
endif;
if ind[2];
mm.gradient = (y - exp(x*b)) .* x;
endif;
retp(mm);
endp;
//Declare 'p0' to be a PV structure
struct PV p0;
//'Pack' a vector named 3x1 vector
//named 'b' into 'p0'
p0 = pvPack(pvCreate,0.5|0.5|0.5,"b");
//Declare c0 to be a maxlikMTControl struture
struct maxlikmtControl c0;
//Fill 'c0' with default values
c0 = maxlikmtControlCreate();
//Declare 'd0' to be a DS structure
struct DS d0;
d0 = dsCreate();
d0.dname = "psn";
//Declare 'out1' to be a maxlikmtResults structure
struct maxlikmtResults out1;
//Call maxlikmt and store results in 'out1'
out1 = maxlikmt(&lpsn,p0,d0,c0);
//Print results
call maxlikmtprt(out1);
print;
print "quasi-maximum likelihood v-c matrix of par's";
print out1.CovPar;
```

Here is an example where a matrix is being passed for data.

```
library maxlik;
#include maxlik.ext
maxset();
z0 = { 8.3 1, 10.3 2, 19.0 3, 16.0 4, 15.6 5, 19.8 7 };
proc lnlk(b,z);
local dev,s2;
dev = z[.,1] - b[1]*(1 - exp(-b[2]*z[.,2]));
s2 = (dev'dev)/rows(dev);
retp(lnpdfmvn(dev,s2));
endp;
start = { 20, .24 };
{ bhat,f,g,cov,retcode } = maxlik(z0,0,&lnlk,start));
call maxprt(bhat,f,g,cov,retcode);
```

```
library maxlikmt;
z0 = { 8.3 1, 10.3 2, 19.0 3, 16.0 4, 15.6 5, 19.8 7 };
proc lnlk(struct PV p, struct DS d);
local dev,s2,b,z;
b = pvUnpack(p,"b");
z = d.dataMatrix;
dev = z[.,1] - b[1]*(1 - exp(-b[2]*z[.,2]));
s2 = dev'dev/rows(dev);
retp(lnpdfmvn(dev,s2));
endp;
struct DS d0;
d0 = dsCreate();
d0.datamatrix = z0;
start = { 20, .24 };
struct PV p0;
p0 = pvPack(pvCreate,start);
struct maxlikmtControl c0;
struct maxlikmtResults out;
out = maxlikmt(&lnlk,p0,d0,c0);
call maxlikmtprt(out);
```