Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix code bug #8

Merged
merged 5 commits into from
Jun 21, 2024
Merged

fix code bug #8

merged 5 commits into from
Jun 21, 2024

Conversation

youdongguo
Copy link
Member

@youdongguo youdongguo commented Jun 17, 2024

fix code bug on $\xi$ and $\mathbf{u}$

Copy link
Member

@timholy timholy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks quite good, once you address these comments it can be merged.

test/runtests.jl Outdated
Comment on lines 24 to 25
W = Float64.([w1 w2])
H = Float64.([h1; h2])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
W = Float64.([w1 w2])
H = Float64.([h1; h2])
W = [w1 w2]
H = [h1; h2]

(If you need these, it's probably a code bug that should be fixed.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is normalization part W[:, j] = w/normw, input W is int, but w/normw is float number, this will through a bug.

test/runtests.jl Outdated
H_v = [Hn[i, :] for i in axes(Hn, 1)]

Q1, Q2, _, _, _, _ =build_Qs(W_v, H_v, 1, 2)
@test Q1 == Q1'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@test Q1 == Q1'
@test issymmetric(Q1)

test/runtests.jl Outdated

Q1, Q2, _, _, _, _ =build_Qs(W_v, H_v, 1, 2)
@test Q1 == Q1'
@test Q2 == Q2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always true?

test/runtests.jl Outdated
@test Q1 == Q1'
@test Q2 == Q2
F = eigen(Q1, Q2)
Fvals, Fvecs = F.values::Vector{eltype(Q2)}, F.vectors::Matrix{eltype(Q2)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to solve a type-stability issue? That's generally not something to worry about for tests, though of course it doesn't hurt.

But you can solve inference problems in eigen with Symmetric (or Hermitian if you're dealing with complex-valued matrices):

julia> @inferred eigen(Q1, Q2)
ERROR: return type GeneralizedEigen{Float64, Float64, Matrix{Float64}, Vector{Float64}} does not match inferred return type Union{GeneralizedEigen{ComplexF64, ComplexF64, Matrix{ComplexF64}, Vector{ComplexF64}}, GeneralizedEigen{Float64, Float64, Matrix{Float64}, Vector{Float64}}}
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] top-level scope
   @ REPL[34]:1

julia> @inferred eigen(Symmetric(Q1), Symmetric(Q2))
GeneralizedEigen{Float64, Float64, Matrix{Float64}, Vector{Float64}}
values:
2-element Vector{Float64}:
  4938.9585139612855
 84532.04148603871
vectors:
2×2 Matrix{Float64}:
  0.968769  -0.768621
 -1.19147   -0.331201

test/runtests.jl Outdated
λ_min = τ/2-sqrt(τ^2/4-δ)

@test abs(λ_max - maximum(F.values))<=1e-12
@test abs(λ_min - minimum(F.values))<=1e-12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, I got this:

julia> @test abs(λ_min - minimum(F.values))<=1e-12
Test Failed at REPL[44]:1
  Expression: abs(λ_min - minimum(F.values)) <= 1.0e-12
   Evaluated: 4.547473508864641e-12 <= 1.0e-12

Different library versions and CPUs can have slight differences in roundoff error. You might need to make this slightly less stringent. 1e-10, perhaps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that GitHub actions tests also failed, for the same reason.

test/runtests.jl Outdated

w = [u[1], u[2]]
@test norm(u[1].*W_v[1].+u[2].*W_v[2]) ≈ 1
@test norm(Q1*w - maximum(F.values)*Q2*w) < 1e-12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise here I got

julia> @test norm(Q1*w - maximum(F.values)*Q2*w) < 1e-12
Test Failed at REPL[51]:1
  Expression: norm(Q1 * w - maximum(F.values) * Q2 * w) < 1.0e-12
   Evaluated: 1.4551915228366852e-11 < 1.0e-12

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot got this fail on RIS.

@timholy timholy mentioned this pull request Jun 18, 2024
Copy link

codecov bot commented Jun 21, 2024

Codecov Report

Attention: Patch coverage is 81.63265% with 18 lines in your changes missing coverage. Please review.

Project coverage is 81.63%. Comparing base (81f091d) to head (95ebbcb).
Report is 1 commits behind head on main.

Files Patch % Lines
src/NMFMerge.jl 81.63% 18 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main       #8   +/-   ##
=======================================
  Coverage   81.63%   81.63%           
=======================================
  Files           1        1           
  Lines          98       98           
=======================================
  Hits           80       80           
  Misses         18       18           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@youdongguo youdongguo merged commit 5321ac4 into main Jun 21, 2024
5 checks passed
@youdongguo youdongguo deleted the yd/fix_code_bug branch June 21, 2024 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants