constraint_likelihood: Title solving constraint likelihood function using the...

Description Usage Arguments Value Examples

View source: R/solmfd_ftns.R

Description

Title solving constraint likelihood function using the solution manifold.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
constraint_likelihood(
  nll,
  C,
  theta,
  s,
  alpha = 0.005,
  gamma = 0.005,
  Lambda = NULL,
  tol1 = 1e-07,
  tol2 = 1e-15,
  num_iter = 1e+05,
  num_iter2 = 20
)

Arguments

nll

function: negative log-likelihood

C

function: constraint

theta

vector: initial value to start

s

int output dimension for C

alpha

double gradient descent step for likelihood update

gamma

double gradient descent step for manifold converging

Lambda

matrix positive definite matrix

tol1

double tolerance for manifold convergence

tol2

double tolerance for gradient descents

num_iter

maximum iteration for gradient descent

num_iter2

maximum iteration for all process

Value

matrix (num_iter2 * length(theta)) each row is a trajactory of theta update. last row is final results

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
set.seed(10)
n = 100 # number of data
X = rnorm(n, mean = 1.5, sd = 3)
nll = function(theta) {return(-sum(dnorm(X, theta[[1]], theta[[2]], log = TRUE)))}
C = function(x) {return(pnorm(2, x[[1]], x[[2]]) - pnorm(-5, x[[1]], x[[2]]) - 0.5)}
theta_updated = constraint_likelihood(nll, C, c(1, 2), 1)
theta_updated[nrow(theta_updated), ] # final result
theta_tmp = theta_updated
const_val = apply(theta_tmp, 1, C) # constraint for each row for plot
plot(x = seq(1, nrow(theta_updated)), const_val, xlab = "step", ylab = "constraint", type = 'o')
theta_tmp = theta_updated
nll_val = apply(theta_tmp, 1, nll) # nll for each row for plot
plot(x = seq(1, nrow(theta_updated)), nll_val, xlab = "step", ylab = "nll", type = 'o')
plot(theta_updated, xlab = "mean", ylab = "sd", type = 'o')

wldyddl5510/SolMfd documentation built on Dec. 23, 2021, 5:18 p.m.