-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add more tests * Small fixes
- Loading branch information
Showing
3 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
mset = CreateTotalOrder(1,3) | ||
opts = MapOptions() | ||
|
||
|
||
function test_CreateComponent_basisType() | ||
for bType in ["HermiteFunctions", "PhysicistHermite", "ProbabilistHermite"] | ||
opts = MapOptions(basisType = bType) | ||
component = CreateComponent(Fix(mset), opts) | ||
@test numCoeffs(component) == 4 | ||
@test all(CoeffMap(component) .== 0.) | ||
end | ||
end | ||
|
||
function test_CreateComponent_posFuncType() | ||
for pfType in ["Exp", "SoftPlus"] | ||
opts = MapOptions(posFuncType = pfType) | ||
component = CreateComponent(Fix(mset), opts) | ||
@test numCoeffs(component) == 4 | ||
@test all(CoeffMap(component) .== 0.) | ||
end | ||
end | ||
|
||
function test_CreateComponent_quadTypes() | ||
for qType in ["AdaptiveSimpson", "ClenshawCurtis", "AdaptiveClenshawCurtis"] | ||
# AdaptiveSimpson | ||
opts = MapOptions(quadType = qType) | ||
component = CreateComponent(Fix(mset), opts) | ||
@test numCoeffs(component) == 4 | ||
@test all(CoeffMap(component) .== 0.) | ||
end | ||
end | ||
|
||
function test_CreateTriangular() | ||
triangular = CreateTriangular(2,2,2,opts) | ||
@test numCoeffs(triangular) == 2 + 7 | ||
end | ||
|
||
function test_CreateSingleEntryMap_1() | ||
dim = 7 | ||
activeInd = 1 | ||
|
||
mset_csemap = CreateTotalOrder(activeInd, 3) | ||
component = CreateComponent(Fix(mset_csemap), opts) | ||
|
||
single_entry_map = CreateSingleEntryMap(dim, activeInd, component) | ||
@test numCoeffs(single_entry_map) == numCoeffs(component) | ||
end | ||
|
||
function test_CreateSingleEntryMap_2() | ||
dim = 7 | ||
activeInd = 7 | ||
|
||
mset_csemap = CreateTotalOrder(activeInd, 3) | ||
component = CreateComponent(Fix(mset_csemap), opts) | ||
|
||
single_entry_map = CreateSingleEntryMap(dim, activeInd, component) | ||
@test numCoeffs(single_entry_map) == numCoeffs(component) | ||
end | ||
|
||
function test_CreateSingleEntryMap_3() | ||
dim = 7 | ||
activeInd = 4 | ||
|
||
mset_csemap = CreateTotalOrder(activeInd, 3) | ||
component = CreateComponent(Fix(mset_csemap), opts) | ||
|
||
single_entry_map = CreateSingleEntryMap(dim, activeInd, component) | ||
@test numCoeffs(single_entry_map) == numCoeffs(component) | ||
end | ||
|
||
function test_CreateSigmoidMaps() | ||
input_dim = 6 | ||
num_sigmoid = 4 | ||
sigmoid_terms = num_sigmoid+3 | ||
centers_len = 2+(num_sigmoid*(num_sigmoid+1)) ÷ 2 | ||
max_degree = 3 | ||
centers = zeros(centers_len) | ||
center_idx = 1 | ||
bound = 3. | ||
# Edge terms | ||
centers[1] = -bound | ||
centers[2] = bound | ||
centers[3] = 0. | ||
# Sigmoid terms | ||
for order in 4:num_sigmoid | ||
for j in 0:order-1 | ||
centers[center_idx] = 1.9*bound*(j-(order-1)/2)/(order-1) | ||
center_idx += 1 | ||
end | ||
end | ||
opts = MapOptions(basisType="HermiteFunctions") | ||
sig = CreateSigmoidComponent(input_dim, max_degree, centers, opts) | ||
expected_num_coeffs = binomial(input_dim-1+max_degree, input_dim-1)*(sigmoid_terms+1) | ||
@test numCoeffs(sig) == expected_num_coeffs | ||
mset = FixedMultiIndexSet(input_dim, max_degree) | ||
sig_mset = CreateSigmoidComponent(mset, centers, opts) | ||
@test numCoeffs(sig_mset) == size(mset) | ||
output_dim = input_dim | ||
centers_total = reduce(hcat, centers for _ in 1:output_dim) | ||
sig_trimap = CreateSigmoidTriangular(input_dim, output_dim, max_degree, centers_total, opts) | ||
expected_num_coeffs_dim = d->(sigmoid_terms+1)*binomial(d-1+max_degree, d-1) | ||
expected_num_coeffs = sum(expected_num_coeffs_dim.(1:output_dim)) | ||
@test numCoeffs(sig_trimap) == expected_num_coeffs | ||
end | ||
|
||
test_CreateComponent_basisType() | ||
test_CreateComponent_posFuncType() | ||
test_CreateComponent_quadTypes() | ||
test_CreateTriangular() | ||
# test_CreateSingleEntryMap_1() | ||
# test_CreateSingleEntryMap_2() | ||
# test_CreateSingleEntryMap_3() | ||
test_CreateSigmoidMaps() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters