Skip to content

Commit

Permalink
Merge pull request #6 from LAMPSPUC/change_package_name
Browse files Browse the repository at this point in the history
Change package name
  • Loading branch information
andreramosfdc authored Dec 15, 2023
2 parents 76501fb + 095486a commit cfd22d3
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 40 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NORTA"
name = "NonParametricNORTA"
uuid = "e97a57fc-2266-4ea9-80d8-a1f12fb1471b"
authors = ["andreramosfc <[email protected]>"]
version = "0.1.0"
version = "0.1.1"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +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=LKBAQWSW18)](https://codecov.io/gh/LAMPSPUC/NORTA) |
| [![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) |


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
using Distributions

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
Expand All @@ -27,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

Expand All @@ -53,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*β
Expand All @@ -77,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
Expand Down
2 changes: 1 addition & 1 deletion src/NORTA.jl → src/NonParametricNORTA.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module NORTA
module NonParametricNORTA

const ROBUST_ROUND = 1e-5

Expand Down
12 changes: 6 additions & 6 deletions test/NORTA.jl → test/NonParametricNORTA.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
@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]
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
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NORTA, Test
using NonParametricNORTA, Test

include("NORTA.jl")
include("NonParametricNORTA.jl")
include("transform_data.jl")
40 changes: 20 additions & 20 deletions test/transform_data.jl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cfd22d3

Please sign in to comment.