Skip to content

Instantly share code, notes, and snippets.

@jason-xuan
Created April 11, 2019 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jason-xuan/5fc92e28d6c790b71b38ae935430fd89 to your computer and use it in GitHub Desktop.
Save jason-xuan/5fc92e28d6c790b71b38ae935430fd89 to your computer and use it in GitHub Desktop.
test code for degenerate
using Test, Distributions, CSV, GLM, Lasso, DataFrames
using Random, Distributed, LinearAlgebra, SparseArrays, SharedArrays
include("./test/testutils.jl")
include("./test/addworkers.jl")
import HurdleDMR; @everywhere using HurdleDMR
include("./test/testdata.jl")
testargs = Dict(:verbose=>false,:showwarnings=>true)
zcounts = deepcopy(counts);
zcounts[:,2] = zeros(n);
zcounts[:,3] = ones(n);
# make sure we are not adding all zero obseravtions
m = sum(zcounts, dims=2)
@test sum(m .== 0) == 0
# hurdle dmr parallel local cluster
hdmrcoefs = fit(HDMR,covars, zcounts; parallel=true, testargs...)
coefsHppos, coefsHpzero = coef(hdmrcoefs);
# hurdle dmr parallel remote cluster
hdmrcoefs2 = fit(HDMRPaths,covars, zcounts; parallel=true, local_cluster=false, testargs...)
coefsHppos2, coefsHpzero2 = coef(hdmrcoefs2)
@test coefsHppos ≈ coefsHppos2
@test coefsHpzero ≈ coefsHpzero2
η = predict(hdmrcoefs2,newcovars)
# 10×4 Array{Float64,2}:
# 0.00632811 0.0 0.0 0.993672
# 0.0820357 0.0 0.0 0.917964
# 0.120042 0.0 0.0 0.879958
# 0.000773842 0.0 0.0 0.999226
# 0.00158558 0.0 0.0 0.998414
# 0.0587256 0.0 0.0 0.941274
# 0.0155122 0.0 0.0 0.984488
# 0.00119599 0.0 0.0 0.998804
# 0.018085 0.0 0.0 0.981915
# 0.0141473 0.0 0.0 0.985853
@test sum(η, dims=2) ≈ ones(size(newcovars, 1))
# Test Passed
@test η[:,2] == zeros(size(newcovars,1))
# Test Passed
@test η[:,3] ≈ ones(size(newcovars,1))*0.36 rtol=0.05
# Test Failed at none:1
# Expression: ≈(η[:, 3], ones(size(newcovars, 1)) * 0.36, rtol=0.05)
# Evaluated: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] ≈ [0.36, 0.36, 0.36, 0.36, 0.36, 0.36, 0.36, 0.36, 0.36, 0.36] (rtol=0.05)
# ERROR: There was an error during testing
@test η[:,4] ≈ ones(size(newcovars,1))*0.6 rtol=0.06
# Test Failed at none:2
# Expression: ≈(η[:, 4], ones(size(newcovars, 1)) * 0.6, rtol=0.06)
# Evaluated: [0.993672, 0.917964, 0.879958, 0.999226, 0.998414, 0.941274, 0.984488, 0.998804, 0.981915, 0.985853] ≈ [0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6] (rtol=0.06)
# ERROR: There was an error during testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment