Finished proper implementation of etsiParas

This commit is contained in:
Waldir Leoncio 2020-01-15 17:05:36 +01:00
parent 1ad6616187
commit 6534d4fa4a
2 changed files with 46 additions and 5 deletions

View file

@ -1,9 +1,25 @@
etsiParas <- function = (osuus, osuusTaulu, omaFreqs, logml) {
ready <- 0;
#' @export
#' @title Etsi Paras
#' @description Search for the best?
#' @param osuus Percentages?
#' @param omaFreqs own Freqs?
#' @param osuusTaulu Percentage table?
#' @param logml log maximum likelihood
etsiParas <- function (osuus, osuusTaulu, omaFreqs, logml) {
ready <- 0
while (ready != 1) {
muutokset <- laskeMuutokset4(osuus, osuusTaulu, omaFreqs, logml)
[maxMuutos, indeksi] = max(muutokset[1:end]) # TODO: how does this work on Matlab?
if (maxMuutos > 0) {
# Work around R's max() limitation on complex numbers
if (any(sapply(muutokset, class) == "complex")) {
maxRe <- max(Re(as.vector(muutokset)))
maxIm <- max(Im(as.vector(muutokset)))
maxMuutos <- complex(real = maxRe, imaginary = maxIm)
} else {
maxMuutos <- max(as.vector(muutokset))
}
indeksi <- which(muutokset == maxMuutos)
if (Re(maxMuutos) > 0) {
osuusTaulu <- suoritaMuutos(osuusTaulu, osuus, indeksi)
logml <- logml + maxMuutos
} else {