From 4bde75b6d3cfe880b8d6e06b0b908be5d63ac90c Mon Sep 17 00:00:00 2001 From: andreramosfc Date: Fri, 15 Dec 2023 13:32:50 -0300 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=9A=9Achange=20package=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project.toml | 4 +-- README.md | 16 +++++----- src/{NORTA.jl => NonParametricNORTA.jl} | 2 +- test/{NORTA.jl => NonParametricNORTA.jl} | 12 +++---- test/runtests.jl | 4 +-- test/transform_data.jl | 40 ++++++++++++------------ 6 files changed, 39 insertions(+), 39 deletions(-) rename src/{NORTA.jl => NonParametricNORTA.jl} (98%) rename test/{NORTA.jl => NonParametricNORTA.jl} (61%) diff --git a/Project.toml b/Project.toml index 2886e78..05353b9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ -name = "NORTA" +name = "NonParametricNORTA" uuid = "e97a57fc-2266-4ea9-80d8-a1f12fb1471b" authors = ["andreramosfc "] -version = "0.1.0" +version = "0.1.1" [deps] Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" diff --git a/README.md b/README.md index 9678b7b..53e83db 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ -# NORTA +# NonParametricNORTA | **Build Status** | **Coverage** | |:-----------------:|:-----------------:| -| [![ci](https://github.com/LAMPSPUC/NORTA/actions/workflows/ci.yml/badge.svg)](https://github.com/LAMPSPUC/NORTA/actions/workflows/ci.yml) | [![codecov](https://codecov.io/gh/LAMPSPUC/NORTA/graph/badge.svg?token=VDpuXvPSI2)](https://codecov.io/gh/LAMPSPUC/NORTA) | +| [![ci](https://github.com/LAMPSPUC/NonParametricNORTA/actions/workflows/ci.yml/badge.svg)](https://github.com/LAMPSPUC/NORTA/actions/workflows/ci.yml) | [![codecov](https://codecov.io/gh/LAMPSPUC/NonParametricNORTA/graph/badge.svg?token=VDpuXvPSI2)](https://codecov.io/gh/LAMPSPUC/NonParametricNORTA) | -NORTA.jl is a Julia package designed to implement the concept of Normal to Anything (NORTA) introduced by Marne C. Cario and Barry L. Nelson in their work on "Modeling and Generating Random Vectors with Arbitrary Marginal Distributions and Correlation Matrix." NORTA.jl harnesses the power of Julia's framework to offer a novel approach. While staying true to the essence of the original concept, this package diverges by employing non-parametric distribution fitting methods (from KernelDensity.jl package) within the Julia environment. Consequently, it eliminates the necessity for explicit computation of proposed correlation matrices, enhancing the efficiency and flexibility of the process. +NonParametricNORTA.jl is a Julia package designed to implement the concept of Normal to Anything (NORTA) introduced by Marne C. Cario and Barry L. Nelson in their work on "Modeling and Generating Random Vectors with Arbitrary Marginal Distributions and Correlation Matrix." NonParametricNORTA.jl harnesses the power of Julia's framework to offer a novel approach. While staying true to the essence of the original concept, this package diverges by employing non-parametric distribution fitting methods (from KernelDensity.jl package) within the Julia environment. Consequently, it eliminates the necessity for explicit computation of proposed correlation matrices, enhancing the efficiency and flexibility of the process. ## Data transformation ```julia -using NORTA +using NonParametricNORTA using Plots y = rand(1000, 3)*rand(3).*15 #generate y as a regression -y_norta, non_parametric_distribution = NORTA.convertData(y) +y_norta, non_parametric_distribution = NonParametricNORTA.convertData(y) ``` ### Transformation visualization @@ -26,7 +26,7 @@ This transformation involves obtaining the non-parametric distribution's cumulat ## Data reverse transformation ```julia -sc = NORTA.reverseData(rand(Normal(0, 1), 100), non_parametric_distribution) +sc = NonParametricNORTA.reverseData(rand(Normal(0, 1), 100), non_parametric_distribution) ``` ### Reverse transformation visualization @@ -52,7 +52,7 @@ y = X*(rand(10).*10) + rand(T) y_train = y[train_idx] y_test = y[test_idx] -y_train_norta, np = NORTA.convertData(y_train) +y_train_norta, np = NonParametricNORTA.convertData(y_train) β = X_train\y_train_norta #Model the NORTA transformed data residuals = y_train_norta - X_train*β @@ -76,7 +76,7 @@ The modeled simulation, when visualized in the transformed scale, does not adher #### Original scale data results ```julia -scenarios = NORTA.reverseData(NORTA_scenarios, np) +scenarios = NonParametricNORTA.reverseData(NORTA_scenarios, np) plot(y_train, w=2, color = "black", lab = "Original Historic", legend=:outerbottom) for i in 1:N_scenarios diff --git a/src/NORTA.jl b/src/NonParametricNORTA.jl similarity index 98% rename from src/NORTA.jl rename to src/NonParametricNORTA.jl index 0630529..9a34283 100644 --- a/src/NORTA.jl +++ b/src/NonParametricNORTA.jl @@ -1,4 +1,4 @@ -module NORTA +module NonParametricNORTA const ROBUST_ROUND = 1e-5 diff --git a/test/NORTA.jl b/test/NonParametricNORTA.jl similarity index 61% rename from test/NORTA.jl rename to test/NonParametricNORTA.jl index 598a989..107c5e8 100644 --- a/test/NORTA.jl +++ b/test/NonParametricNORTA.jl @@ -1,12 +1,12 @@ @testset "Function: convertData" begin observations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - expected = NORTA.convertData(observations) + expected = NonParametricNORTA.convertData(observations) @test trunc.(expected[1], digits = 3) == [-1.281, -0.841, -0.524, -0.253, 0.0, 0.253, 0.524, 0.841, 1.281, 4.264] @test expected[2].support == observations @test expected[2].p == ones(10)./10 observations = [1, 1, 1, 1, 1, 3, 2, 2, 2, 2] - expected = NORTA.convertData(observations) + expected = NonParametricNORTA.convertData(observations) @test trunc.(expected[1], digits = 3) == [0, 0, 0, 0, 0, 4.264, 1.281, 1.281, 1.281, 1.281] @test expected[2].support == [1, 2, 3] @test expected[2].p == [0.5, 0.4, 0.1] @@ -14,12 +14,12 @@ end @testset "Function: reverseData" begin observations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - transformed_y, non_parametric_distribution = NORTA.convertData(observations) - expected = NORTA.reverseData(transformed_y, non_parametric_distribution) + transformed_y, non_parametric_distribution = NonParametricNORTA.convertData(observations) + expected = NonParametricNORTA.reverseData(transformed_y, non_parametric_distribution) @test trunc.(expected, digits = 3) == observations observations = collect(-1000:100:1000) - transformed_y, non_parametric_distribution = NORTA.convertData(observations) - expected = NORTA.reverseData(transformed_y, non_parametric_distribution) + transformed_y, non_parametric_distribution = NonParametricNORTA.convertData(observations) + expected = NonParametricNORTA.reverseData(transformed_y, non_parametric_distribution) @test trunc.(expected, digits = 3) == observations end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index cd93f31..fb44778 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,4 @@ -using NORTA, Test +using NonParametricNORTA, Test -include("NORTA.jl") +include("NonParametricNORTA.jl") include("transform_data.jl") \ No newline at end of file diff --git a/test/transform_data.jl b/test/transform_data.jl index 2cb4f60..f26e283 100644 --- a/test/transform_data.jl +++ b/test/transform_data.jl @@ -1,54 +1,54 @@ @testset "Function: get_discretenonparametric_distribution" begin observations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - expected = NORTA.get_discretenonparametric_distribution(observations) + expected = NonParametricNORTA.get_discretenonparametric_distribution(observations) @test expected.support == observations @test expected.p == ones(10)./10 observations = [1, 1, 1, 1, 1, 3, 2, 2, 2, 2] - expected = NORTA.get_discretenonparametric_distribution(observations) + expected = NonParametricNORTA.get_discretenonparametric_distribution(observations) @test expected.support == [1, 2, 3] @test expected.p == [0.5, 0.4, 0.1] end @testset "Function: get_transformed_observations" begin observations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - non_parametric_distribution = NORTA.get_discretenonparametric_distribution(observations) - expected = NORTA.get_transformed_observations(non_parametric_distribution, observations) + non_parametric_distribution = NonParametricNORTA.get_discretenonparametric_distribution(observations) + expected = NonParametricNORTA.get_transformed_observations(non_parametric_distribution, observations) @test trunc.(expected, digits = 3) == [-1.281, -0.841, -0.524, -0.253, 0.0, 0.253, 0.524, 0.841, 1.281, 4.264] end @testset "Function: get_normal_cdf" begin scenarios = [-1.281, -0.841, -0.524, -0.253, 0.0, 0.253, 0.524, 0.841, 1.281, 5.612] - expected = NORTA.get_normal_cdf(scenarios) + expected = NonParametricNORTA.get_normal_cdf(scenarios) @test round.(expected, digits = 1) == collect(0.1:0.1:1.0) scenarios = [1 2 3; 4 5 6] - expected = NORTA.get_normal_cdf(scenarios) + expected = NonParametricNORTA.get_normal_cdf(scenarios) @test round.(expected, digits = 3) == [0.841 0.977 0.999; 1.0 1.0 1.0] end @testset "Function: get_interpolation_function" begin - normal_cumulative_value = NORTA.get_normal_cdf([-1.281, -0.841, -0.524, -0.253, 0.0, 0.253, 0.524, 0.841, 1.281, 5.612]) + normal_cumulative_value = NonParametricNORTA.get_normal_cdf([-1.281, -0.841, -0.524, -0.253, 0.0, 0.253, 0.524, 0.841, 1.281, 5.612]) observations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - non_parametric_distribution = NORTA.get_discretenonparametric_distribution(observations) - expected = NORTA.get_interpolation_function(normal_cumulative_value, non_parametric_distribution) - @test isa(expected, NORTA.Interpolations.Extrapolation) + non_parametric_distribution = NonParametricNORTA.get_discretenonparametric_distribution(observations) + expected = NonParametricNORTA.get_interpolation_function(normal_cumulative_value, non_parametric_distribution) + @test isa(expected, NonParametricNORTA.Interpolations.Extrapolation) end @testset "Function: reverse_data" begin observations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - non_parametric_distribution = NORTA.get_discretenonparametric_distribution(observations) - transformed_obs = NORTA.get_transformed_observations(non_parametric_distribution, observations) - normal_cumulative_value = round.(NORTA.get_normal_cdf(transformed_obs), digits = 8) - interpolation = NORTA.get_interpolation_function(normal_cumulative_value, non_parametric_distribution) - expected = NORTA.reverse_data(interpolation, normal_cumulative_value, non_parametric_distribution) + non_parametric_distribution = NonParametricNORTA.get_discretenonparametric_distribution(observations) + transformed_obs = NonParametricNORTA.get_transformed_observations(non_parametric_distribution, observations) + normal_cumulative_value = round.(NonParametricNORTA.get_normal_cdf(transformed_obs), digits = 8) + interpolation = NonParametricNORTA.get_interpolation_function(normal_cumulative_value, non_parametric_distribution) + expected = NonParametricNORTA.reverse_data(interpolation, normal_cumulative_value, non_parametric_distribution) @test trunc.(expected, digits = 3) == observations observations = [1, 1, 1, 1, 1, 3, 2, 2, 2, 2] - non_parametric_distribution = NORTA.get_discretenonparametric_distribution(observations) - transformed_obs = NORTA.get_transformed_observations(non_parametric_distribution, observations) - normal_cumulative_value = round.(NORTA.get_normal_cdf(transformed_obs), digits = 8) - interpolation = NORTA.get_interpolation_function(normal_cumulative_value, non_parametric_distribution) - expected = NORTA.reverse_data(interpolation, normal_cumulative_value, non_parametric_distribution) + non_parametric_distribution = NonParametricNORTA.get_discretenonparametric_distribution(observations) + transformed_obs = NonParametricNORTA.get_transformed_observations(non_parametric_distribution, observations) + normal_cumulative_value = round.(NonParametricNORTA.get_normal_cdf(transformed_obs), digits = 8) + interpolation = NonParametricNORTA.get_interpolation_function(normal_cumulative_value, non_parametric_distribution) + expected = NonParametricNORTA.reverse_data(interpolation, normal_cumulative_value, non_parametric_distribution) @test trunc.(expected, digits = 3) == observations end \ No newline at end of file From abaddaa829a116133c9efce19dac1e6ff69e8769 Mon Sep 17 00:00:00 2001 From: andreramosfc Date: Fri, 15 Dec 2023 13:34:00 -0300 Subject: [PATCH 2/2] fix_path --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 53e83db..9f6635f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | **Build Status** | **Coverage** | |:-----------------:|:-----------------:| -| [![ci](https://github.com/LAMPSPUC/NonParametricNORTA/actions/workflows/ci.yml/badge.svg)](https://github.com/LAMPSPUC/NORTA/actions/workflows/ci.yml) | [![codecov](https://codecov.io/gh/LAMPSPUC/NonParametricNORTA/graph/badge.svg?token=VDpuXvPSI2)](https://codecov.io/gh/LAMPSPUC/NonParametricNORTA) | +| [![ci](https://github.com/LAMPSPUC/NonParametricNORTA/actions/workflows/ci.yml/badge.svg)](https://github.com/LAMPSPUC/NonParametricNORTA/actions/workflows/ci.yml) | [![codecov](https://codecov.io/gh/LAMPSPUC/NonParametricNORTA/graph/badge.svg?token=LKBAQWSW18)](https://codecov.io/gh/LAMPSPUC/NonParametricNORTA) | NonParametricNORTA.jl is a Julia package designed to implement the concept of Normal to Anything (NORTA) introduced by Marne C. Cario and Barry L. Nelson in their work on "Modeling and Generating Random Vectors with Arbitrary Marginal Distributions and Correlation Matrix." NonParametricNORTA.jl harnesses the power of Julia's framework to offer a novel approach. While staying true to the essence of the original concept, this package diverges by employing non-parametric distribution fitting methods (from KernelDensity.jl package) within the Julia environment. Consequently, it eliminates the necessity for explicit computation of proposed correlation matrices, enhancing the efficiency and flexibility of the process.