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

Calculate standard error on PS results #203

Closed
wants to merge 21 commits into from

Conversation

H0R5E
Copy link
Member

@H0R5E H0R5E commented Nov 24, 2020

Description

This commit uses the central value theorem to facilitate calculation of the error on the mean results of the PS controller, using the standard error from a normal distribution.

Two new functions are added to the WecOptTool.math package called standardErrorMeasure and standardErrorReduce, the first of which measures the standard error after a given number of samples and the second of which keeps sampling until a desired level of error is found.

An example script to show how the standard error varies with the stroke of the RM3 device using the PS controller is added to the RM3 example directory called PSError.m. The results of this simulation are shown here:

RM3_PS_standard_error

Fixes #56

Checklist:

  • All new files contain the GPL header
  • [ ] If examples/RM3/optimization.m has been modified, the content / line
    numbers in docs/user/optimization.rst are still valid or have been fixed
  • Add docstrings
  • Add tests
  • [ ] Add something to the documentation? -> Do as part of Document SeaState class example #153

This commit uses the central value theorem to facilitate calculation
of the error on the mean results of the PS controller, using the
standard error from a normal distribution.

Two new functions are added to the WecOptTool.math package called
standardErrorMeasure and standardErrorReduce, the first of which
measures the standard error after a given number of samples and the
second of which keeps sampling until a desired level of error is
found.

An example script to show how the standard error varies with the
stroke of the RM3 device using the PS controller is added to the
RM3 example directory called PSError.m
@H0R5E
Copy link
Member Author

H0R5E commented Nov 25, 2020

Hi Ryan,

I implemented your algorithm, but I'm not sure it's behaving the way you expected it to do. The diagram below shows a simulation with the tolerance set to 1e-6.

ryan_algorithm

I don't think this is converging as you were expecting, but I'm not really surprised because of the random numbers.

I'm also not sure what the tolerance is telling you. I set the tolerance to 1e-4 and ran the algorithm 10 times. The range on the results was 69039.8 Watts, but 1e-4 * max(power) is 395.2 Watts, so the tolerance is kind of misleading.

ryan_algorithm_2

How do you want to proceed?

@H0R5E
Copy link
Member Author

H0R5E commented Nov 25, 2020

I've added a metric which calculates the sum of the standard errors over the sum of the mean (per frequency component). It produces results as such:

RM3_PS_standard_error_of_mean

I'll do the reverse and set a limit on the error and show how many iterations are required.

@H0R5E
Copy link
Member Author

H0R5E commented Nov 25, 2020

OK, so here is the same situation recording the number of iterations required:

RM3_PS_standard_error_N

So, I really think the question is whether the user wants to set a particular accuracy and wait for the realisations, or choose a number of realisations and suffer the inaccuracy. I suggest we offer both options.

When a struct is provided a target field must be given to use for the
error calculation
Allow options to either measure the error or reduce it to a certain
value in the PS controller option to simulateDevice.

By default it will reduce the error to 1% of the mean.
Only targets 1% in the mean value with no options to change it.
@H0R5E H0R5E marked this pull request as ready for review December 1, 2020 12:12
@H0R5E H0R5E requested a review from ryancoe December 1, 2020 12:12
@H0R5E
Copy link
Member Author

H0R5E commented Dec 1, 2020

Just a note that this would need to be updated if #170 is merged first and visa-versa.

@H0R5E
Copy link
Member Author

H0R5E commented Dec 1, 2020

As part of the testing process I noticed that when summing the errors the results were somewhat better than expected. Turns out, that's because summing the standard error is not the correct approach and taking the 2norm is the correct way to go. I've implemented that and the results are now more consistent.

@H0R5E
Copy link
Member Author

H0R5E commented Dec 3, 2020

Add option when reducing error for max samples - return error.

Done.

@H0R5E H0R5E marked this pull request as draft December 3, 2020 15:56
Adds the option 'maxN' to standardError to control the maximum number
of samples when in reduce mode. standardError now always returns both
the error and the number of samples in its results.

The option 'onError' is also added to control behavior when maxN is
exceeded. In 'warn' mode a warning will be issued and in 'raise' mode
an error is raised.
@H0R5E H0R5E marked this pull request as ready for review December 4, 2020 11:28
@H0R5E
Copy link
Member Author

H0R5E commented Dec 4, 2020

@ryancoe

@H0R5E H0R5E self-assigned this Feb 4, 2021
@H0R5E H0R5E removed their assignment Sep 1, 2022
@H0R5E H0R5E closed this Jul 4, 2023
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.

Ensure sufficient number of phase realizations in PS
1 participant