zekeriyasari / Causal.jl

Causal.jl - A modeling and simulation framework adopting causal modeling approach.
https://zekeriyasari.github.io/Causal.jl/dev/
Other
115 stars 7 forks source link

Confusing dead code in "Gain" static system definition #44

Closed NumHack closed 4 years ago

NumHack commented 4 years ago

I was trying to understand this piece of Causal.jl code that defines the "Gain" static system : https://github.com/zekeriyasari/Causal.jl/blob/master/src/components/systems/staticsystems/staticsystems.jl :

@def_static_system struct Gain{G, IP, OP, RO} <: AbstractStaticSystem
    gain::G = 1.
    input::IP = Inport() 
    output::OP = Outport(length(gain * zeros(length(input)))) 
    readout::RO = (u, t, gain=gain) -> gain * u
end

Shouldn't the 'output' line be (remove 'gain *'):

    output::OP = Outport(length(zeros(length(input))))
end

Probably a typo since 'gain *' is also present on next line.

Created Pull Request https://github.com/NumHack/Causal.jl/pull/1

zekeriyasari commented 4 years ago

Gain is a static system whose input-output relation (i.e. the readout function) is of the form

y = K u

where K is the gain, u is the input and y is the output. The relation here is a general matrix-vector product. umay be an m-dimensional vector and y may be a n-dimensional vector, which implies K is mxn-dimensional matrix. In the code line length(gain * zeros(length(input))), the length m of y is inferred from the sizes of K and u.

Here, the general case is assumed where m is not equal to n. If the specific case where m is equal to n, then the code you suggest length(zeros(length(input))) becomes true.

NumHack commented 4 years ago

Thank you for your very clear answer. Another powerful Julia trick learned :+1:

I closed the Pull Request and this issue.