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

Correlation and indexing vectors when evaluating objective functions #1970

Open
mrejster opened this issue Aug 17, 2020 · 6 comments
Open

Correlation and indexing vectors when evaluating objective functions #1970

mrejster opened this issue Aug 17, 2020 · 6 comments
Assignees
Labels
gui:scripting HCOM, Python or Embedded scripting

Comments

@mrejster
Copy link

Is your improvement request related to a problem? Please describe.
When optimizing model with cyclical output, such as rockdrills, it is often useful to time-shift signals before comparing / matching. For example if I want to calculate an objective function based on the similarity of two piston location vectors. This could be done using Matlab etc by locating the time shfit using correlation, and then index the vectors appropriately. An (currently unsolvable?) issue arises when one wants to include such time shifts in an optimization in Hopsan.

Describe the solution you'd like
Either HCOM functionality to enable indexing of vectors, generating new vector based on indeces (such as A= B[10342:82739]). Or possibly by re-enabling the Python scripting environment, which I believe had such capabilities?

Describe alternatives you've considered
Currently, my best option is to add a time-shift parameter as an optimization parameter, letting it move the compared generation using a lookup table, and hoping for the best that Hopsan finds a good time shift value. This is much more computationally heavy than simply matching the signals before obj-function evaluation, and complicates the optimization.

Additional context

@robbr48
Copy link
Contributor

robbr48 commented Aug 18, 2020

I think we can add both a subvector function and a time shift function to HCOM. Perhaps subvec(vector, start, end) and tshift(vector, dt)?

@robbr48 robbr48 self-assigned this Aug 18, 2020
@robbr48 robbr48 added the gui:scripting HCOM, Python or Embedded scripting label Aug 18, 2020
@robbr48 robbr48 added this to the 2.15.0 milestone Aug 18, 2020
@mrejster
Copy link
Author

If possible, stealing some well known syntaxt would be nice. Such as matlab A(13:25) or numpy B[13:25].
But I'm guessing that's much more work to implement?

@peterNordin
Copy link
Member

peterNordin commented Aug 18, 2020

Hmm, for time shifting, I think that this should already work, in plots you can add time shifts, that then affect all plot variables using that time vector in the same generation. But maybe its not possible to do so from HCOM, or maybe it only affects the plots.

The following (needlessly complicated) command would shift the time vector by 5, for all time-domain variables with that particular Time variable. But I am not sure if that what was desired, or only to shift time for one particular variable ?
Time = Time + ones(size(Time)) * 5

@robbr48 oddly, the expression Time = Time + 5 * ones(size(Time)) does not evaluate. Did not debug, maybe a Symhop issue?

@peterNordin
Copy link
Member

Implementing new operators such as () and [] will take some time, parenthesis are used in functions so brackets would be better.
Quicker to do subvec solution first. In this case for time-domain and frequency-domain, a new subvec of the time or frequency vector would also have to be created.

@robbr48 When you say tshift(vector, dt) does that mean to shift the data left or right or change the underlying time data.
I assume its the former, so that we do not affect all variables using that time vector?

@mrejster
Copy link
Author

mrejster commented Aug 19, 2020 via email

@robbr48
Copy link
Contributor

robbr48 commented Aug 20, 2020

@peterNordin Yes, we must of course not modify the time vector variable. Only the specified variable must be changed. I think a positive value of dt means shift to the right, but I'm not sure.

@mrejster Operators would be nice, but is very non-HCOM. Compare e.g. with peek(vector,15) which equals vector[15].

@peterNordin peterNordin modified the milestones: 2.15.0, 2.16.0 Sep 9, 2020
@peterNordin peterNordin removed this from the 2.16.0 milestone Nov 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gui:scripting HCOM, Python or Embedded scripting
Projects
None yet
Development

No branches or pull requests

3 participants