Skip to content

Commit

Permalink
NNS 10.9.2 Beta
Browse files Browse the repository at this point in the history
  • Loading branch information
OVVO-Financial committed Sep 5, 2024
1 parent 8f58620 commit e65b95c
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 127 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.9.2
Date: 2024-09-04
Date: 2024-09-05
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.9.2.tar.gz
Binary file not shown.
Binary file modified NNS_10.9.2.zip
Binary file not shown.
2 changes: 0 additions & 2 deletions R/Boost.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ NNS.boost <- function(IVs.train,
}

if(feature.importance){
original.par <- par(no.readonly = TRUE)
par(mfrow = c(2,1))
par(mai = c(1.0,.5,0.8,0.5))
hist(results, main = "Distribution of Learner Trials Objective Function",
Expand Down Expand Up @@ -443,7 +442,6 @@ NNS.boost <- function(IVs.train,
xlab = "Frequency", las = 1)
}
par(mfrow=c(1,1))
par(original.par)
}


Expand Down
14 changes: 11 additions & 3 deletions R/Central_tendencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ NNS.mode <- function(x, discrete = FALSE, multi = TRUE){
z_ind <- max(1, (z_c - 1)):min(lz,(z_c + 1))
}



final <- sum(z_names[z_ind] * z$counts[z_ind] )/sum(z$counts[z_ind])
if(discrete) return(ifelse(final%%1 < .5, floor(final), ceiling(final))) else if(multi) return(final) else return(mean(final))

if(discrete){
final <- ifelse(final%%1 < .5, floor(final), ceiling(final))
return(final)
} else {
if(multi){
return(final)
} else {
return(mean(final))
}
}
}


Expand Down
4 changes: 2 additions & 2 deletions R/Dependence.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ NNS.dep = function(x,
res_xy <- suppressWarnings(tryCatch(PART_xy[1:eval(ll), dep_fn(x, y), by = prior.quadrant],
error = function(e) dep_fn(x, y)))

res_yx <- suppressWarnings(tryCatch(PART_yx[1:eval(ll), dep_fn(x, y), by = prior.quadrant],
error = function(e) dep_fn(x, y)))
res_yx <- suppressWarnings(tryCatch(PART_yx[1:eval(ll), dep_fn(y, x), by = prior.quadrant],
error = function(e) dep_fn(y, x)))

if(sum(is.na(res_xy))>0) res_xy[is.na(res_xy)] <- dep_fn(x, y)
if(is.null(ncol(res_xy))) res_xy <- cbind(res_xy, res_xy)
Expand Down
3 changes: 1 addition & 2 deletions R/Regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,13 @@ NNS.reg = function (x, y,

}

orig.dep <- NNS.copula(cbind(apply(cbind(x, y), 2, function(z) NNS.rescale(z, 0, 1))))

x <- Rfast::rowsums(x.star.matrix / sum( abs( x.star.coef) > 0), parallel = FALSE)
x.star <- data.table::data.table(x)

dependence <- tryCatch(NNS.dep(x, y, print.map = FALSE, asym = TRUE)$Dependence, error = function(e) .1)

dependence <- tryCatch(mean(c(dependence, NNS.copula(cbind(apply(cbind(x, x, y), 2, function(z) NNS.rescale(z, 0, 1)))), orig.dep)), error = function(e) dependence)
dependence <- tryCatch(mean(c(dependence, NNS.copula(cbind(apply(cbind(x, x, y), 2, function(z) NNS.rescale(z, 0, 1)))))), error = function(e) dependence)

dependence[is.na(dependence)] <- 0.1

Expand Down
16 changes: 7 additions & 9 deletions R/Stack.R
Original file line number Diff line number Diff line change
Expand Up @@ -257,22 +257,20 @@ NNS.stack <- function(IVs.train,
nns.ord[i] <- eval(obj.fn)

i_s[i] <- i


best.threshold <- ifelse(length(i_s <=2), var.cutoffs[1], var.cutoffs[mode_class(i_s) - 1])
THRESHOLDS[[b]] <- best.threshold

if(objective=="min"){
best.threshold <- var.cutoffs[mode_class(i_s)-1]
THRESHOLDS[[b]] <- best.threshold
best.nns.ord[[b]] <- min(na.omit(nns.ord))
if(is.na(nns.ord[1])) nns.ord[1] <- Inf
if(i > 2 && is.na(nns.ord[i])) break
if(i > 2 && (nns.ord[i] >= nns.ord[i-1]) && (nns.ord[i] >= nns.ord[i-2])) break
} else {
best.threshold <- var.cutoffs[mode_class(i_s)-1]
THRESHOLDS[[b]] <- best.threshold
best.nns.ord[[b]] <- max(na.omit(nns.ord))
if(is.na(nns.ord[1])) nns.ord[1] <- -Inf
if(i > 2 && is.na(nns.ord[i])) break
if(i > 2 && (nns.ord[i] <= nns.ord[i-1]) && (nns.ord[i] <= nns.ord[i-2])) break
}

if(i > 2 && is.na(nns.ord[i])) break
if(i > 2 && (nns.ord[i] >= nns.ord[i-1]) && (nns.ord[i] >= nns.ord[i-2])) break
}


Expand Down
24 changes: 12 additions & 12 deletions vignettes/NNSvignette_Correlation_and_Dependence.html

Large diffs are not rendered by default.

58 changes: 25 additions & 33 deletions vignettes/NNSvignette_Forecasting.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ sqrt(mean((nns_lin - tail(AirPassengers, 44)) ^ 2))
# sqrt(mean((nns_nonlin - tail(AirPassengers, 44)) ^ 2))

## ----nonlinearres, eval = FALSE-----------------------------------------------
# [1] 20.55102
# [1] 20.19599

## ----seasonal test, eval=TRUE-------------------------------------------------
seas = t(sapply(1 : 25, function(i) c(i, sqrt( mean( (NNS.ARMA(AirPassengers, h = 44, training.set = 100, method = "lin", seasonal.factor = i, plot=FALSE) - tail(AirPassengers, 44)) ^ 2) ) ) ) )
Expand Down Expand Up @@ -79,23 +79,24 @@ NNS.seas(AirPassengers, modulo = 12, plot = FALSE)
# [1] "CURRNET METHOD: nonlin"
# [1] "COPY LATEST PARAMETERS DIRECTLY FOR NNS.ARMA() IF ERROR:"
# [1] "NNS.ARMA(... method = 'nonlin' , seasonal.factor = c( 12 ) ...)"
# [1] "CURRENT nonlin OBJECTIVE FUNCTION = 20.5510211522245"
# [1] "CURRENT nonlin OBJECTIVE FUNCTION = 20.1959877511828"
# [1] "BEST method = 'nonlin' PATH MEMBER = c( 12 )"
# [1] "BEST nonlin OBJECTIVE FUNCTION = 20.5510211522245"
# [1] "BEST nonlin OBJECTIVE FUNCTION = 20.1959877511828"
# [1] "CURRNET METHOD: both"
# [1] "COPY LATEST PARAMETERS DIRECTLY FOR NNS.ARMA() IF ERROR:"
# [1] "NNS.ARMA(... method = 'both' , seasonal.factor = c( 12 ) ...)"
# [1] "CURRENT both OBJECTIVE FUNCTION = 19.4534618627141"
# [1] "CURRENT both OBJECTIVE FUNCTION = 19.5082249052739"
# [1] "BEST method = 'both' PATH MEMBER = c( 12 )"
# [1] "BEST both OBJECTIVE FUNCTION = 19.4534618627141"
# [1] "BEST both OBJECTIVE FUNCTION = 19.5082249052739"
#
# $periods
# [1] 12
#
# $weights
# NULL
#
# $obj.fn
# [1] 19.45346
# [1] 19.50822
#
# $method
# [1] "both"
Expand All @@ -107,41 +108,32 @@ NNS.seas(AirPassengers, modulo = 12, plot = FALSE)
# [1] FALSE
#
# $bias.shift
# [1] 8.983377
# [1] 11.34026
#
# $errors
# [1] -14.240300 -20.899691 -17.699956 -31.623457 -22.080467 -15.972663
# [7] -12.633377 -4.289462 -2.371119 2.417484 16.657475 24.096405
# [13] 8.926263 6.535789 1.826191 -27.314316 14.649727 2.812027
# [19] 10.087412 26.318135 8.130503 5.994088 5.810046 8.968724
# [25] -15.343831 11.107010 -9.030058 -37.870074 -6.868421 -13.948830
# [31] -13.833241 -10.076019 -19.089073 -16.278753 25.441499 -23.904395
# [37] -35.211740 -11.322375 -38.211436 -42.494907 -15.487474 -37.670592
# [43] -14.477746 -6.587231
# [1] -12.0495905 -19.5023885 -18.2981119 -30.4665605 -21.9967015 -16.3628298 -12.6732257 -4.2894621 -2.6001984
# [10] 2.4174837 16.6574755 24.0964052 12.0029210 7.8864972 -0.7526824 -26.4198893 13.6743157 1.1898601
# [19] 9.1072756 24.6494525 7.8148305 5.9940877 5.8100458 8.9687243 -11.4805859 12.7282091 -12.4809879
# [28] -36.8363281 -8.2269378 -16.1171482 -15.1770286 -12.3754742 -19.5291985 -16.2952067 25.2265398 -24.0729594
# [37] -30.8466826 -9.3810198 -42.3392122 -41.2587312 -17.0627050 -40.1705358 -16.0734602 -9.0786139
#
# $results
# [1] 349.7431 410.0837 456.2834 444.3599 390.9029 340.0107 301.3500 340.6939
# [9] 346.6123 329.4009 387.6409 381.0798 376.5337 442.1913 493.9687 479.2886
# [17] 421.0377 366.8738 324.8321 367.6235 371.9435 351.7882 414.2779 408.6346
# [25] 405.9523 477.0303 533.3005 516.6684 452.9214 394.5738 349.1661 394.8069
# [33] 397.6765 374.3703 441.9106 436.5026 434.6776 511.4234 571.8929 553.3783
# [41] 484.1285 421.4944 373.0609 421.2843
# [1] 354.2907 413.8379 458.0421 447.8737 393.3436 341.9774 303.6670 343.0508 348.7401 331.7577 389.9977 383.4367
# [13] 380.9157 445.1133 493.9374 481.8833 422.2942 367.7482 326.1741 368.2520 374.0967 354.1451 416.6348 410.9915
# [25] 410.2864 480.0025 531.6140 519.3302 454.3068 395.5812 350.6175 395.6273 399.2349 376.1436 443.3473 438.1093
# [37] 438.3493 513.6632 569.8738 555.3985 485.0235 422.3001 374.1886 422.0488
#
# $lower.pred.int
# [1] 302.5739 362.9145 409.1142 397.1907 343.7337 292.8415 254.1808 293.5247
# [9] 299.4430 282.2317 340.4716 333.9106 329.3645 395.0221 446.7995 432.1194
# [17] 373.8685 319.7046 277.6629 320.4543 324.7743 304.6190 367.1087 361.4654
# [25] 358.7831 429.8611 486.1313 469.4992 405.7521 347.4046 301.9968 347.6377
# [33] 350.5072 327.2011 394.7414 389.3334 387.5084 464.2542 524.7237 506.2091
# [41] 436.9593 374.3252 325.8917 374.1151
# [1] 301.7733 361.3205 405.5248 395.3563 340.8262 289.4601 251.1497 290.5334 296.2227 279.2404 337.4804 330.9193
# [13] 328.3984 392.5960 441.4200 429.3659 369.7768 315.2308 273.6567 315.7346 321.5793 301.6277 364.1174 358.4741
# [25] 357.7690 427.4851 479.0966 466.8128 401.7894 343.0638 298.1001 343.1099 346.7175 323.6262 390.8299 385.5920
# [37] 385.8320 461.1459 517.3564 502.8811 432.5061 369.7827 321.6712 369.5314
#
# $upper.pred.int
# [1] 384.0671 444.4077 490.6074 478.6839 425.2269 374.3347 335.6740 375.0179
# [9] 380.9363 363.7249 421.9648 415.4038 410.8577 476.5153 528.2927 513.6126
# [17] 455.3617 401.1978 359.1561 401.9475 406.2675 386.1122 448.6019 442.9586
# [25] 440.2763 511.3543 567.6245 550.9924 487.2453 428.8978 383.4900 429.1309
# [33] 432.0004 408.6943 476.2346 470.8266 469.0016 545.7474 606.2169 587.7023
# [41] 518.4525 455.8184 407.3849 455.6083
# [1] 390.2389 449.7861 493.9904 483.8219 429.2918 377.9257 339.6153 378.9990 384.6883 367.7060 425.9460 419.3849
# [13] 416.8640 481.0616 529.8856 517.8315 458.2425 403.6964 362.1223 404.2002 410.0450 390.0933 452.5830 446.9397
# [25] 446.2347 515.9507 567.5622 555.2784 490.2550 431.5294 386.5657 431.5755 435.1831 412.0918 479.2956 474.0576
# [37] 474.2976 549.6115 605.8220 591.3467 520.9717 458.2483 410.1368 457.9970

## ----extension,results='hide',fig.width=5,fig.height=3,fig.align = "center", eval=FALSE----
# NNS.ARMA.optim(AirPassengers,
Expand Down
Loading

0 comments on commit e65b95c

Please sign in to comment.