Skip to content

Commit

Permalink
NNS 10.2 Beta
Browse files Browse the repository at this point in the history
  • Loading branch information
OVVO-Financial authored Sep 30, 2023
1 parent 36fbccb commit f921949
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: NNS
Type: Package
Title: Nonlinear Nonparametric Statistics
Version: 10.2
Date: 2023-09-28
Date: 2023-09-30
Authors@R: c(
person("Fred", "Viole", role=c("aut","cre"), email="ovvo.financial.systems@gmail.com"),
person("Roberto", "Spadim", role=c("ctb"))
Expand Down
Binary file modified NNS_10.2.tar.gz
Binary file not shown.
Binary file modified NNS_10.2.zip
Binary file not shown.
32 changes: 19 additions & 13 deletions R/NNS_Distance.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,41 @@ NNS.distance <- function(rpm, rpm_class, dist.estimate, type, k, class){
return(rpm$y.hat[1])
}
}

ll <- min(k, l)

uni_weights <- rep(1/min(k,l), min(k,l))
uni_weights <- rep(1/ll, ll)

t_weights <- dt(rpm$Sum, df = min(k,l))
t_weights <- dt(rpm$Sum, df = ll)
t_weights <- t_weights/sum(t_weights)
if(any(is.na(t_weights))) t_weights <- 0
if(any(is.na(t_weights))) t_weights <- rep(0, ll)

emp <- rpm$Sum^(-1)
emp_weights <- emp / sum(emp)
if(any(is.na(emp_weights))) emp_weights <- 0
if(any(is.na(emp_weights))) emp_weights <- rep(0, ll)

exp <- dexp(1:min(k,l), rate = 1/min(k,l))
exp <- dexp(1:ll, rate = 1/ll)
exp_weights <- exp / sum(exp)
if(any(is.na(exp_weights))) exp_weights <- 0
if(any(is.na(exp_weights))) exp_weights <- rep(0, ll)

lnorm <- abs(rev(dlnorm(1:min(k, l), meanlog = 0, sdlog = sd(1:min(k, l)), log = TRUE)))
lnorm <- abs(rev(dlnorm(1:ll, meanlog = 0, sdlog = sd(1:ll), log = TRUE)))
lnorm_weights <- lnorm / sum(lnorm)
if(any(is.na(lnorm_weights))) lnorm_weights <- 0
if(any(is.na(lnorm_weights))) lnorm_weights <- rep(0, ll)

pl_weights <- (1:min(k, l)) ^ (-2)
pl_weights <- (1:ll) ^ (-2)
pl_weights <- pl_weights / sum(pl_weights)
if(any(is.na(pl_weights))) pl_weights <- 0
if(any(is.na(pl_weights))) pl_weights <- rep(0, ll)

norm_weights <- dnorm(rpm$Sum, mean = 0, sd = sd(rpm$Sum))
norm_weights <- norm_weights / sum(norm_weights)
if(any(is.na(norm_weights))) norm_weights <- 0
if(any(is.na(norm_weights))) norm_weights <- rep(0, ll)

rbf_weights <- exp(- rpm$Sum / (2*var(rpm$Sum)))
rbf_weights <- rbf_weights / sum(rbf_weights)
if(any(is.na(rbf_weights))) rbf_weights <- rep(0, ll)

weights <- (emp_weights + exp_weights + lnorm_weights + norm_weights + pl_weights + t_weights + uni_weights)/
sum(emp_weights + exp_weights + lnorm_weights + norm_weights + pl_weights + t_weights + uni_weights)
weights <- (emp_weights + exp_weights + lnorm_weights + norm_weights + pl_weights + t_weights + uni_weights + rbf_weights)/
sum(emp_weights + exp_weights + lnorm_weights + norm_weights + pl_weights + t_weights + uni_weights + rbf_weights)


if(is.null(class)) single.estimate <- rpm$y.hat%*%weights else single.estimate <- mode_class(rep(rpm$y.hat, ceiling(100*weights)))
Expand Down

0 comments on commit f921949

Please sign in to comment.