Skip to content

Commit 8f8cdc0

Browse files
authored
Merge pull request #31 from shashi/s/simplify
make the simplification not hang
2 parents f6fb2e0 + 40dfd3f commit 8f8cdc0

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/sindy.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,31 @@ function sparseConvex(A::AbstractArray, Y::AbstractArray; ϵ::Float64 = 1e-3)
5050
return Ξ'
5151
end
5252

53+
function simplified_matvec(Ξ, basis)
54+
eqs = Operation[]
55+
for i=1:size(Ξ, 1)
56+
eq = nothing
57+
for j = 1:size(Ξ, 2)
58+
if !iszero(Ξ[i,j])
59+
if eq === nothing
60+
eq = basis[j]*Ξ[i,j]
61+
else
62+
eq += basis[j]*Ξ[i,j]
63+
end
64+
end
65+
end
66+
if eq === nothing
67+
push!(eqs, zero(basis[1]))
68+
else
69+
push!(eqs, eq)
70+
end
71+
end
72+
eqs
73+
end
74+
5375
# Returns a basis for the differential state
5476
function SInDy(X::AbstractArray, Ẋ::AbstractArray, Ψ::Basis; p::AbstractArray = [], ϵ::Number = 1e-1)
5577
θ = hcat([Ψ(xi, p = p) for xi in eachcol(X)]...)
5678
Ξ = sparseConvex', Ẋ, ϵ = ϵ)
57-
return Basis(simplify_constants.(Ξ*Ψ.basis), variables(Ψ), parameters = p)
79+
return Basis(simplified_matvec(Ξ, Ψ.basis), variables(Ψ), parameters = p)
5880
end

0 commit comments

Comments
 (0)