OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort...

176

Transcript of OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort...

Page 1: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University

School of Innovation Design and Engineering

Västerås, Sweden

Thesis for the Degree of Master of Science in Engineering - Robotics

30.0 credits

OCEAN WAVES ESTIMATION

�AN ARTIFICIAL INTELLIGENCE APPROACH�

Andreas [email protected]

Examiner: Ning XiongMälardalen University, Västerås, Sweden

Supervisor: Giacomo SpampinatoMälardalen University, Västerås, Sweden

Company supervisor 1: George FodorQ-TAGG R&D AB, Västerås, Sweden

Company supervisor 2: Christopher EngströmQ-TAGG R&D AB, Västerås, Sweden

May 17, 2017

Page 2: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

This thesis aims to solve the mathematical inverse problem of characterizing sea waves basedon the responses obtained from a marine vessel sailing under certain sea conditions. By researchingthis problem the thesis contributes to the marine industry by improving products that are usingocean behavior for controlling ship's dynamics.

Knowledge about the current state of the sea, such as the wave frequency and height, is impor-tant for navigation, control, and for the safety of a vessel. This information can be retrieved fromspecialized weather reports. However, such information is not at all time possible to obtain duringa voyage, and if so usually comes with a certain delay. Therefore this thesis seeks solutions that canestimate on-line the waves' state using methods in the �eld of Arti�cial Intelligence. The speci�cinvestigation methods are Transfer Functions augmented with Genetic Algorithm, Arti�cial NeuralNetworks and Case-Based Reasoning. These methods have been con�gured and validated using then-fold cross validation method. All the methods have been tested with an actual implementation.The algorithms have been trained with data acquired from a marine simulation program developedin Simulink. The methods have also been trained and tested using monitored data acquired froman actual ship sailing on the Baltic Sea as well as wave data obtained from a buoy located nearbythe vessel's route. The proposed methods have been compared with state-of-the art reports inorder evaluate the novelty of the research and its potential applications in industry.

The results in this thesis show that the proposed methods can in fact be used for solving theinverse problem. It was also found that among the investigated methods it is the Transfer Functionaugmented with Genetic Algorithm which yields best results.

This Master Thesis is conducted under the Master of Engineering Program in Robotics atMälardalens högskola in Västerås, Sweden. The thesis was proposed by Q-TAGG R&D AB inVästerås, Sweden, a company which specializes in marine vessel dynamics research.

Keywords� Arti�cial Intelligence, Case-Based Reasoning, Encounter Angle, Encounter Spec-trum, Feedforward Neural Network, Genetic Algorithm, Inverse Problem, Marine Vessels, MasterThesis, MATLAB, Model Parameter Estimation, Ocean Theory, Peak Period, Response AmplitudeOperator, Ships, Signi�cant Wave Height, Transfer Function, Wave Spectrum, Waves

1

Page 3: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Contents

1 Introduction 51.1 The Inverse Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.2 Arti�cial Intelligence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.3 Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.4 Introduction Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.5 Hypothesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2 Background 82.1 Movement Of A Ship . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.2 Wave Spectrum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.2.1 Pierson-Moskowitz Spectrum De�nition . . . . . . . . . . . . . . . . . . . . 112.2.2 Bretschneider Spectrum De�nition . . . . . . . . . . . . . . . . . . . . . . . 122.2.3 JONSWAP Spectrum Defenition . . . . . . . . . . . . . . . . . . . . . . . . 132.2.4 ITTC Spectrum De�nition . . . . . . . . . . . . . . . . . . . . . . . . . . . 132.2.5 Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

2.3 Encounter Spectrum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152.4 Response Amplitude Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162.5 Rolling Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

2.5.1 Without Friction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162.5.2 With Friction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

2.6 Course Keeping And Roll Stabilization . . . . . . . . . . . . . . . . . . . . . . . . . 212.7 Simulation And Data Acquisition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

3 Problem Formulation 243.1 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.2 Research Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

4 Contribution 24

5 State-Of-The Art 255.1 On-Board Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255.2 O�-Board System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

6 Methodology 276.1 Research . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276.3 Test And Validate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

7 Possible Solutions 287.1 Feedforward Neural Network With Backpropagation . . . . . . . . . . . . . . . . . 297.2 Adaptive Neuro Fuzzy Inference System . . . . . . . . . . . . . . . . . . . . . . . . 297.3 Cased-Based Reasoning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307.4 Feedforward Neural Network Using Genetic Algorithm . . . . . . . . . . . . . . . . 307.5 Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

8 Implementation 328.1 Data Acquisition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328.2 Transfer Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

8.2.1 Loop For Transfer Function Based On One case . . . . . . . . . . . . . . . . 358.2.2 Optimize Transfer Function With Genetic Algorithm Based On One Case . 358.2.3 Optimize Transfer Function With Genetic Algorithm Based On Several Cases 378.2.4 Parameter Extraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

8.3 Feedforward Neural Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

2

Page 4: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

8.3.1 Feedforward Neural Network With Backpropagation . . . . . . . . . . . . . 398.3.2 Feedforward Neural Network With Genetic Algorithm . . . . . . . . . . . . 41

8.4 Case-Based Reasoning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418.4.1 Euclidean Distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428.4.2 Manhattan Distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

9 Validation 439.1 Loop For Transfer Function Based On One Case . . . . . . . . . . . . . . . . . . . 439.2 Optimize Transfer Function With Genetic Algorithm Based On One Case . . . . . 449.3 Optimize Transfer Function With Genetic Algorithm Based On Several Cases . . . 449.4 Feedforward Neural Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449.5 Case Based Reasoning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459.6 Simulated- And Logged Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459.7 Logged Data Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

10Result 4810.1 Transfer Function Based On One Case . . . . . . . . . . . . . . . . . . . . . . . . . 4810.2 Transfer Function Based On Several Cases . . . . . . . . . . . . . . . . . . . . . . . 5110.3 Feedforward Neural Network And Case-Based Reasoning . . . . . . . . . . . . . . . 5210.4 Parameter Accuracy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5410.5 Simulated- And Logged data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5610.6 Logged Data Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

11Conclusion 6011.1 Simulation Based Training And Validation . . . . . . . . . . . . . . . . . . . . . . . 60

11.1.1 Looping For Transfer Function . . . . . . . . . . . . . . . . . . . . . . . . . 6011.1.2 Genetic Algorithm Based Transfer Function Using 1 Example . . . . . . . . 6011.1.3 Genetic Algorithm Based Transfer Function Using Several Examples . . . . 6011.1.4 Feedforward Neural Network Using Resilient Backpropagation . . . . . . . 6011.1.5 Feedforward Neural Network Using Genetic Algorithm . . . . . . . . . . . . 6111.1.6 Case-Based Reasoning Using Euclidean Distance . . . . . . . . . . . . . . . 6111.1.7 Case-Based Reasoning Using Manhattan Distance . . . . . . . . . . . . . . 6111.1.8 General Conclusion Of All Methods . . . . . . . . . . . . . . . . . . . . . . 61

11.2 Simulation Based Training And Validation With Logged Data . . . . . . . . . . . . 6111.3 Logged Data For Training And Testing . . . . . . . . . . . . . . . . . . . . . . . . . 6211.4 Final Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6211.5 Veri�cation Of Hypothesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6311.6 Research Questions Answered . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

12Future Work 6412.1 Not Implemented . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6412.2 Improvements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6412.3 General Thoughts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

13Acknowledgments 66

References 68

Appendix A Models 69

Appendix B Abbreviations and Nomenclature 70

Appendix C List of Figures 72

Appendix D List of Tables 75

Appendix E Source Code 76

3

Page 5: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.1 Elevation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76E.2 Wave Spectra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79E.3 Harmonic Oscillations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81E.4 Transfer Function For Training And Validating With Simulated Data . . . . . . . . 83

E.4.1 Loop Based . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83E.4.2 Genetic Algorithm And One Example Based . . . . . . . . . . . . . . . . . 87E.4.3 Function For Validating The Transfer Function . . . . . . . . . . . . . . . . 91E.4.4 Present Loop And Genetic Algorithm Result Trained With One Example . 92E.4.5 Genetic Algorithm And Several Examples Based . . . . . . . . . . . . . . . 95E.4.6 Present Genetic Algorithm Result Trained With Several Examples . . . . . 99

E.5 Feedforward Neural Network For Training And Validating With Simulated Data . 100E.5.1 Using Resilient Backpropagation . . . . . . . . . . . . . . . . . . . . . . . . 100E.5.2 Using Genetic Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

E.6 Case Based Reasoning For Training And Validating With Simulated Data . . . . . 110E.6.1 Using Euclidian Distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110E.6.2 Euclidian Distance Function . . . . . . . . . . . . . . . . . . . . . . . . . . . 114E.6.3 Using Manhattan Distance . . . . . . . . . . . . . . . . . . . . . . . . . . . 115E.6.4 Manhattan Distance Function . . . . . . . . . . . . . . . . . . . . . . . . . . 119

E.7 Present Feedforward Neural Network And Case Based Reasoning . . . . . . . . . . 120E.8 Test All Pre-Trained Solutions With Actual Data . . . . . . . . . . . . . . . . . . . 126

E.8.1 Estimate Results With Previously Best Con�gurations . . . . . . . . . . . . 126E.8.2 Plot Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

E.9 Transfer Function For Training And Validating With Actual Data . . . . . . . . . 135E.9.1 Loop Based . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135E.9.2 Genetic Algorithm And One Example Based . . . . . . . . . . . . . . . . . 139E.9.3 Genetic Algorithm And Several Examples Based . . . . . . . . . . . . . . . 143

E.10 Feedforward Neural Network For Training And Validating With Actual Data . . . 147E.10.1 Using Resilient Backpropagation . . . . . . . . . . . . . . . . . . . . . . . . 147E.10.2 Using Genetic Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

E.11 Case Based Reasoning For Training And Validating With Actual Data . . . . . . . 157E.11.1 Using Euclidian Distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157E.11.2 Using Manhattan Distance . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

E.12 Estimate Wave Parameters With Transfer Function And Genetic Algorithm . . . . 167E.12.1 Encounter Spectrum Estimation . . . . . . . . . . . . . . . . . . . . . . . . 167E.12.2 Parameter Extraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171

Appendix F The Final Transfer Function 174

Appendix G Time Plan 175

4

Page 6: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

1 Introduction

Figure 1.0.1: The �gure depicts a realizationof the shipping network during the year 2012.The colors represents routes taken by varioustypes of ships. The �gure was retrieved and ex-tracted from the following website https://www.shipmap.org/1which was created by the com-pany KILN located in London, United Kingdom.Permission to use the image in this thesis wasgracefully granted by the CEO of KILN.

The world economy is dependent on a networkof trading routes between nations and conti-nents. And there are only two ways to trans-port goods between continents, which are ei-ther by air or by sea. Transport by sea exceedsby large margin cargo transport by plains2. Anexample of the shipping network can be seen in�gure 1.0.1.

A typical large marine vessel of MAERSKTriple-E class3 is capable of freighting 18000Twenty-foot Equivalent Unit (TEU) contain-ers4, which is almost the total weekly con-tainer volumes handled in Sweden5. The to-tal volume needed to freight that many con-tainers is enough to freight 7 constructed and�ight-ready BOING 747-2006. This shows thatmarine vessels are capable of shipping muchgreater amount of goods than aircraft andtherefore marine transportation is the key fortrading between countries. Due to large ves-sels such as the Triple-E class consuming greatamounts of energy, it is highly important to sailas fuel e�cient as possible to reduce unnecessary fuel usage and greenhouse gas emission.

Figure 1.0.2: The �gure de-picts the rolling center androlling angle of a ship inrolling motion.

Marine vessels rely on various factors to sail safely and withminimal fuel consumption across the sea. One important factorto achieve this is knowledge about the state of the sea. If the seaconditions are rough then the ocean most likely consists of largewaves traveling at a high speed. In such cases it is important thatthe ship is dynamically stable, i.e. has rolling within safety levels.This is achieved by the ship's design and by special control systemsthat ensure stability. The de�nition of rolling can be realized bystating that there is an axis, which is placed between the rear andfront of the ship, which the ship rotates around (the metacenter).Figure 1.0.2 presents an example of a small ship which which havestarted to roll.

If the rolling frequency correlates in a speci�c way with thewave frequency then the ship may start to roll uncontrollable andthe rolling amplitude can increase beyond the safety boundaries.This type of scenario is called parametric rolling. There are knownequations which specify the relation between the rolling frequencyof the ship and the wave frequency so that the control system can

1Available: 2017-05-092According to Eurostat 3.8 billion tonnes of goods were freighted by sea in the year of 2014, while only 14.4million

tonnes were transported by air. That means that marine vessels freighted approximately 264% more goods thanaircrafts. Information retrieved from http://ec.europa.eu/eurostat/statistics-explained/index.php/Freight_

transport_statistics, Available: 2017-05-09.3Until recently the Triple-E vessel was the largest ship from MAERSK. But since 2017 there exists an even larger

ship called Madrid, which is capable of freighting over 20000 containers.4Information retrieved from MAERSK webpage http://www.maersk.com/en/hardware/triple-e/

economy-of-scale, Available: 2017-05-04. 1 TEU container have the dimensions of 5.9 ∗ 2.4 ∗ 2.4m. Thetotal volume which the Triple-E vessel is capable of freighting is therefore 611712m3

5The APM terminals in Guthenburg, Sweden, handles 10000 containers each week, which is50% of the total weekly container volumes in Sweden. http://news.cision.com/se/apm-terminals/r/

apm-terminals-genomfor-spegellockout,c2261448, Available: 2017-05-116The length and height of a BOING 747-200 is 70.66 respectively 19.51m and the wing span is 59.64m, which

creates a squared volume space of 82218.31m3. Dimensions retrieved from http://www.boeing.com/resources/

boeingdotcom/company/about_bca/startup/pdf/freighters/747-200F_-200SF_-100SF.pdf, Available: 2017-05-04

5

Page 7: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

predict ahead of time if there is a risk of su�ering from parametric rolling. Since there are certainrisks such as cargo loss or even loss of ship when su�ering of parametric rolling, it is crucial thatthe wave frequency is predicted to avoid this event.

However, for large marine vessels parametric rolling rarely occurs anymore thanks to the pre-dictive models. There is however a relation between increased rolling of the ship and increased fuelconsumption, and it is therefore highly relevant to reduce the rolling as much as possible.

There are specialized organizations which make continuous measurements of the sea, usingbuoys and rigs located out on the ocean, to obtain the state of the sea and the behavior of waves.The obtained result from these measurements are �nalized in reports which marine vessels haveaccess to know the non-controllable parameters. However, retrieving measurements, analyzingthe data, and transfer the information to the marine vessels takes time. According to CoastalData Information Program (CDIP)'s7 webpage8 the information which marine vessels obtain is atleast 30 min old. Since the vessels sail out on the ocean they might not be fortunate enough toposes a continuous Internet connection to gather weather reports and the ships must use o�-lineinformation. This can be in the form the latest wave reports obtained which can be much olderthan 30 minutes. This means that marine vessels might in some cases navigate based on waveinformation which might be inaccurate. This can result with the control system inducing rollingonto the ship instead of reducing it. If this time resolution could be reduced, and the vessel couldobtain more recently measured wave information, then the marine industry would bene�t from itin terms of rolling- and fuel reduction.

1.1 The Inverse Problem

Calculating and predicting the motion of a ship based on the controlled and non-controlled pa-rameters is considered a direct problem. Performing the opposite and calculating the parametersbased on the motion is considered as the indirect problem or the inverse problem. The de�nitionof an inverse problem is that a scenario is observed and an attempt is then made to estimate themain reason behind the observed event. Nassim Taleb describes this in [1] by an intuitive example:

Operation 1 (the melting ice cube): Imagine an ice cube and consider how it may melt over the nexttwo hours while you play a few rounds of poker with your friends. Try to envision the shape of theresulting puddle.Operation 2 (where did the water come from?): Consider a puddle of water on the �oor. Now try toreconstruct in your mind's eye the shape of the ice cube it may once have been. Note that thepuddle may not have necessarily originated from an ice cube.

Nassim TalebThe black swan: The impact of the highly improbable, p. 196

As seen, the inverse problem is di�cult mathematically. More formally, if one has a model Mand the model is interpreted to produce dataD by a process G (e.g. G is a MATLAB9 simulation orsome experiments), then there is a straightforward generation of data from the model G(M) = D.The inverse problem is when there is available data D but the model M is unknown. Then theinverse problem means �nding the inverse of G such that M = G−1D is attained. There can bemany models Mi, where i is an integer in the interval [1 m]10, that would produce the same datasuch as Mi 6= Mi+1 ⇒ Di = Di+1, meaning the problem is often not determined due to manysolutions. There is much ongoing research in:

(a) trying to �nd the inverse functions analytically

(b) trying to decrease the indeterminacy using auxiliary knowledge about M or G

7CDIP is a network for monitoring waves along the coastline of the United States8A weblink to CDIP's webpage with information about data acquisition https://cdip.ucsd.edu/?nav=

documents&xitem=dacq#system, Available: 2017-05-049MATLAB is a programming environment which is very user friendly for mathematical computations. Weblink:

https://se.mathworks.com/products/matlab.html, Available: 2017-05-0410m is an arbitrarily integer indicating the amount of possible solutions

6

Page 8: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

There exists no particular implemented solution to the speci�c inverse problem of characterizingwaves based on ship responses due to the random nature of waves. Ocean waves can be representedusing their height, frequency, and direction, but these parameters can represent multiple variationsof waves and it is therefore di�cult to construct a numeric model which is capable of solving thisinverse problem. The approach considered in this thesis is the following. Having a data set Dand a ship and waves model M , the problem is to identify the inverse function M = G−1D usingidenti�cation methods from Arti�cial Intelligence (AI).

1.2 Arti�cial Intelligence

AI denotes the knowledge needed to make machines perform operations normally attributed tohumans. The simplest explanation of AI is a system which given the outcome of several eventsas well as the main reason behind the events, can �nd a relation between the outcomes and theinitial input. AI constructs a solution which yields minimal prediction error without any humaninteracting with it. The core purpose of AI is therefore to �nd relations between inputs and outputsquicker than humans could do and for systems that are more complex than human can handle.

Since there is no current solution for the inverse wave problem today, there is an ongoing researchfor �nding the best approach for this problem. Creating an accurate numerical solution for thisproblem is both complicated and time consuming in terms of development and implementation, andit is therefore highly relevant to utilize AI which are capable of estimating complicated scenariosin minimum time.

1.3 Application

Q-TAGG R&D AB is specialized in control systems which reduces the rolling of a ship based on thebehavior of waves. Vessels using this type of control systems are using information about waves topredict ship dynamics. By using one of the proposed inverse methods from this thesis, the rollingof a vessel could be reduced more e�ectively.

1.4 Introduction Summary

This Master Thesis focuses on implementing an inverse method to determine waves' behavior usinga number of AI learning algorithms. The algorithms are trained using a physical model of the shiprolling in waves. This thesis is a practical application of AI and Control Theory, two central �eldsof study in the Robotics Education curriculum at Mälardalen University.

1.5 Hypothesis

This master thesis has two hypotheses, where H1 describes the basic problem to be solved andH2 restricts the set of solutions.

H1: If the motion of a marine vessel in the sea and the dynamics of the vessel's control systemis known, then the behavior of the sea waves around the vessel and their wave spectrum can befound using inverse methods.

H2: One suitable method is Arti�cial Intelligence.

The hypotheses are supported and deemed true if and only if the inverse method succedes inde�ning the behaviour of waves when faced with a known scenario.

7

Page 9: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

2 Background

This section covers the background knowledge needed for understanding the nature of the problemas well as marine theory. A vast part of the information presented have been retrieved fromTristan Perez's published bok "Ship Motion Control: Course keeping and roll stabilisation usingrudder and �ns" [2], which is the main source of information throughout this thesis. The followingsubsections introduces how a ship moves in waves and how waves can be de�ned and representedusing wave spectrum reports.

2.1 Movement Of A Ship

Figure 2.1.1: The �gure de-picts a realization of theship's coordinate system.

The movement and motion of a ship can be described as a 6Degrees of Freedom (DOF) system, meaning it can be describedwith 6 load/force equations. Three of those equations representsthe translation- whereas the remaining three represents the rota-tion of the ship. The translation equations describes the linearmovement for the ship in the direction of the axes of the co-ordinate system. The ship's coordinate system is located withits origin in the ship's Center of Gravity (CG) with the x-axistowards the front of the ship, the y-axis towards the port (left-hand side) of the ship, and the z-axis perpendicular (downwards)to the ship, as seen in �gure 2.1.1. The translation movementsin the x,y,z-directions are named accordingly; surge, sway, andheave. And the equations representing the rotation of the shipare named; roll, pitch, and yaw. These equations represents therotation around each respective axis in the order x,y,z. Accordingto [3], the rotation and translation equations can be represented as follows:

Surge : ρ5 x = Xh1 +Xω1 (2.1.1a)

Sway : ρ5 y = Xh2+Xω2

(2.1.1b)

Heave : ρ5 z = Xh3+Xω3

(2.1.1c)

Roll : Ixxφ− Ixzψ = Xh4 +Xω4 (2.1.1d)

Pitch : Ixxθ = Xh5+Xω5

(2.1.1e)

Y aw : Izzψ − Izxφ = Xh6+Xω6

(2.1.1f)

Where:ρ is the density of water5 is the volume which the ship displaces in the waterIij is the ships moment of inertia between two axesXh1

, Xh2, Xh3

is hydromechanical forces in the respective direction of x,y,zXh4 , Xh5 , Xh6 is hydromechanical moments around the respective axes of x,y,zXω1 , Xω2 , Xω3 is exciting wave forces in the respective direction of x,y,zXω4

, Xω5, Xω6

is exciting wave moments around the respective axes of x,y,zx is the acceleration of the ship in the direction of axis xy is the acceleration of the ship in the direction of axis yz is the acceleration of the ship in the direction of axis zφ is the angular acceleration of the ship around axis xθ is the angular acceleration of the ship around axis yψ is the angular acceleration of the ship around axis z

As seen in the equations the movement of a ship in water follows the second law of Newton,which can be seen in equation 2.1.2 and 2.1.3.

8

Page 10: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

−→F = ma =

d

dtmv (2.1.2)

−→M =

d

dt

−→H (2.1.3)

Where:−→F is the external force applied to the center of gravityv is the velocity of the center of gravitym is the mass of the bodya is the acceleration of the center of gravity−→M is the external momentum applied at the center of gravity−→H is the angular momentum applied at the center of gravity

Equation 2.1.1a, 2.1.1b, and 2.1.1c are representations of equation 2.1.2, whereas equation 2.1.1d,2.1.1e, and 2.1.1f are representations of equation 2.1.3. By rearranging equations 2.1.1 the hy-dromechanical force, and momentum, can be expressed as an outcome from the ship's force andmomentum as well as the force and momentum of the waves. The rearranged equations can beseen in 2.1.4.

Surge : Xω1= ρ5 x−Xh1

(2.1.4a)

Sway : Xω2 = ρ5 y −Xh2 (2.1.4b)

Heave : Xω3= ρ5 z −Xh3

(2.1.4c)

Roll : Xω4= Ixxφ− Ixzψ −Xh4

(2.1.4d)

Pitch : Xω5 = Ixxθ −Xh5 (2.1.4e)

Y aw : Xω6= Izzψ − Izxφ−Xh6

(2.1.4f)

Equations 2.1.4 clearly show that waves increases/decreases the load for a ship since Xω1−6

a�ect all the loads. This means that knowledge of the state of sea and characteristics of the wavesis crucial when estimating the motion of a ship. Information such as the state- and behavior ofwaves can be obtained from wave spectrum reports.

2.2 Wave Spectrum

If a cut-section along a horizontal axis of the waves were to be made then it can be observed thatthe waves of the ocean does not behave like a simple sine function. However, according to JosephFourier almost any function can be represented as an in�nite series of sine and cosine functions withharmonic frequencies. This is the key concept for describing the waves of the ocean. According to[4] the wave elevation, for a wide area where the sea is traveling along the x-axis, can be describedas an summation of sinusoidal wave components seen in equation 2.2.1.

ζ =

N∑j=1

Ajsin(ωjt− kjx+ εj) (2.2.1)

Note!Each wave component includes a ran-dom phase shift εj . This is the sourceto the previous statement of waves hav-ing a random nature.

Where:ζ is the elevationN is the number of wave componentsAj is the wave amplitude for wave component jωj is the circular frequency for wave component jkj is the wave number for component j and calculated

as ω2

gx is the position at axis xεj is a random phase angle for component j

9

Page 11: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

It has also been proven in [4] that the amplitude Aj can be expressed by the wave spectrum11

as seen in equation 2.2.2.

1

2A2j = Sff (ωj)∆ω (2.2.2)

Where Sff (ωj) is the wave spectrum with respect to the circular frequency ωj and ∆ω isthe di�erence between consecutive frequencies. The relation between wave spectrum and realizedmotion of waves is that the realized motion of waves is described in time domain whereas wavespectrum is a description in frequency domain [5]. Conversion between one domain into the otheris possible through Fast Fourier Transform (FFT) and Inverse Fast Fourier Transform (IFFT), asseen in �gure 2.2.1. Through these relations the previously mentioned equations 2.2.1 and 2.2.2was found. This shows that the wave spectrum is a reasonable method for representing the stateof the sea. The relation found in equation 2.2.1 and 2.2.2 can be realized with a 3-dimensional�gure 2.2.2 representing the relation between wave spectrum and wave components.

Figure 2.2.1: The �gure depicts a visualization of how the frequency domain and time domaincorrelate with each other through FFT.

(a) 3-dimensional representation of relation be-tween wave spectrum and wave components

(b) 2-dimensional representation of relation betweenwave spectrum and wave components

Figure 2.2.2: The �gures present how the wave components at certain frequencies can be estimatedfrom the wave spectrum using the relation of ζ =

∑Nj=1Ajsin(ωjt−kjx+εj) and

12A

2j = S(ωj)∆ω.

It can be seen in the �gure that when the energy of the wave spectrum (red line) is greater atcertain frequencies that will result with a wave component (black lines) represented as a sinusfunction with a great amplitude, which will have a large impact when calculating the wave motionusing fourier series. These speci�c examples was generated in MATLAB using the sourcecodefound in the appendix section E.1.

By implementing equation 2.2.1 for all these wave components the elevation of the waves canbe found, seen in �gure 2.2.3.

11Wave spectrum is a spectrum which describes the amount of energy produced by the wave when it have a certainfrequency. Wave spectrum is usually presented as a diagram with amount of energy over frequency (Hz) or energyover angular frequency (rad/s).

10

Page 12: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Figure 2.2.3: The �gure depicts an example of how thewave elevation would be represented at one position byadding together the wave components found in �gure2.2.2. Note that there is a pattern repeating itselfwhich shows that waves are periodical. This speci�cexample was generated in MATLAB using the sourcecode found in the appendix section E.1.

Certain companies build platformsand place wave-buoys out on the sea[6] for monitoring and thereafter cal-culate the wave spectrum. The be-havior of waves can vary from timeto time, as well as location to lo-cation. This is due to certain fac-tors as wind speed and ocean depth[4]. An result of this is that thereis no clear de�nition of one �xed formfor wave spectrum which works for allwaves. However, several de�nitions ofthe wave spectrum under certain con-ditions have been proposed and ac-cepted by the community. The follow-ing sections presents several acceptedwave spectrum types, as well as ashort comparison, which can be uti-lized with equation 2.2.2 to represent thewaves.

2.2.1 Pierson-Moskowitz Spectrum De�nition

In [7], the Pierson-Moskowitz spectrum is presented as a function of angular frequency and de-pendent of the gravity constant g and the signi�cant waveheight12 Hs. The presented equationis:

Sff (ω) =0.0081g2

ω5exp[−0.032

g2

H2sω

4] (2.2.3)

This spectrum is considered to be one of the simpler methods out there. An example of thePierson-Moskowitz wave spectrum can be seen in �gure 2.2.4.

Figure 2.2.4: The �gure depicts an example of the Pierson-Moskowitz wave spectrum were thesigni�cant waveheight is 5m. The example was created in an MATLAB environment. The sourcecode for the example is found in the appendix E.2.

12Signi�cant waveheight is the mean-value of the 13highest waves. Meaning, the largest 33% of the waves is picked

out and an average of these waves' height is calculated and represented as the signi�cant waveheight.

11

Page 13: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

2.2.2 Bretschneider Spectrum De�nition

Along with the presented Pierson-Moskowitz spectrum in [7] is the Bretschneider wave spectrumwhich is a modi�ed version of the Pierson-Moskowitz wave spectrum. For the keen observer thisrelation can be expected when comparing the likeliness between the Bretschneider equation 2.2.4and Pierson-Moskowitz equation 2.2.3.

Sff (ω) =1.25

4

ω40

ω5H2s exp[−1.25(

ω0

ω)4] (2.2.4)

The Bretschneider spectrum is often referred to as the two-parameter spectrum since it imple-ment both the previously mentioned angular frequency ω and the model frequency ω0. The modalfrequency is expressed as an equation of the average wave period T1 seen in equation 2.2.5.

ω0 =2π

1.2957T1(2.2.5)

Equation 2.2.4 can then be expanded with equation 2.2.5 to obtain the Bretschneider spectrumwith regards to Hs and T1. The equation can be altered from a two-parameter spectrum into aone-parameter, as in [3], that there is a relation between the signi�cant waveheight and the averagewave period which can be seen in equation 2.2.6. This converison is mostly used as a demonstrationof the correlation between the Pierson-Moskowitz spectrum and the Bretschneider spectrum.

T1 = 3.861√Hs (2.2.6)

A one-parameter based equation can thereafter be constructed for the Bretschneider spectrumof the form:

Sff (ω) =1.25

4

( 2π1.2957∗(3.861

√Hs)

)4

ω5H2s exp[−1.25(

2π1.2957∗(3.861

√Hs)

ω)4] (2.2.7)

An example of the one- and the two-parameter Bretschneider wave spectrum can be seen in�gure 2.2.5.

Figure 2.2.5: The �gure depicts an example of the one-parameter Bretschneider wave spectrumwith a signi�cant waveheight of 5m and the two-parameter Bretschneider wave spectrum withwaveheight of 5m and modal frequency of 2π

9.7 rad/s 13. The source code for the examples is foundin the appendix E.2.

13The values were obtained from the following source https://ocw.mit.edu/courses/mechanical-engineering/

2-017j-design-of-electromechanical-robotic-systems-fall-2009/assignments/MIT2_017JF09_p04.pdf, Avail-able: 2017-05-04.

12

Page 14: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

2.2.3 JONSWAP Spectrum Defenition

A third accepted wave spectrum is the Joint North Sea Wave Project (JONSWAP) spectrum.This is an extended version of the Bretschneider wave spectrum which was accepted in 1978. Thepresented JONSWAP equation, in [4], can be seen in equation 2.2.8.

Sff (ω) = 155H2s

T 41 ω

5exp(

−944

T 41 ω

4)γY (2.2.8)

where:

Y = exp(−0.191ωT1 − 1√2σ

) (2.2.9)

and:

T1 =1, 086

1, 408∗ Tp (2.2.10)

σ is equal to 0.07 when the angular frequency is less or equal to 5.24/T1, otherwise σ is equal to0.09, Tp is the peak period14, and γ is a peak intensi�cation factor usually chosen as equal to 3.3.By expanding equation 2.2.8 with equation 2.2.9, 2.2.10, and 2.2.6, the JONSWAP wave spectrumcan be expressed as equation 2.2.11.

Sff (ω) = 155H2s

( 1,0861,408 ∗ Tp)4ω5

exp(−944

( 1,0861,408 ∗ Tp)4ω4

)3.3exp(−

0.191ω(1,0861,408

∗Tp)−1√

2σ)

(2.2.11)

An example of the JONSWAP equation can be seen in �gure 2.2.6.

Figure 2.2.6: The �gure depicts an example of the two-parameter JONSWAP wave spectrum witha signi�cant waveheight of 5m and the modal frequency 2π

9.7 rad/s. The source code for the exampleis found in the appendix E.2.

2.2.4 ITTC Spectrum De�nition

International Towing Tank Conference (ITTC)15 is an organization of voluntary associations whichwork with predicting the hydrodynamic performance amongst marine ships. This organization havecreated their own type of a two-parameter wave spectrum. The ITTC wave spectrum have beenaccepted by the community and is often implemented by researcher [8]. The spectrum functioncan be seen in equation 2.2.12.

14Peak period is the period for the wave component which have the greatest amplitude, meaning it is the periodthat when converted to frequency yields the peak of the spectrum.

15Homepage of ITTC http://www.ittc.info/, Available: 2017-05-04.

13

Page 15: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Sff (ω) =A

ω5exp(− B

ω4) (2.2.12)

Where:

A =173H2

s

T 41

(2.2.13a)

B =691

T 41

(2.2.13b)

From equations 2.2.12 and 2.2.13 it can be observed that the two parameters which de�ne theITTC wave spectrum is Hs and T1. By expanding equation 2.2.12 with equations 2.2.10 and 2.2.13,the ITTC wave spectrum can be expressed with the parameters Hs and Tp seen in equation 2.2.14.An example of the ITTC wave spectrum can be seen in �gure 2.2.7.

Sff (ω) =173H2

s

( 1,0861,408 ∗ Tp)4ω5

exp(− 691

( 1,0861,408 ∗ Tp)4ω4

) (2.2.14)

Figure 2.2.7: The �gure depicts an example of the two-parameter ITTC wave spectrum with asigni�cant waveheight of 5m and the modal frequency 2π

9.7 rad/s. The source code for the exampleis found in the appendix E.2.

2.2.5 Comparison

One characteristic which all the spectra have in common with each other is that they all dependon Hs which is the �rst unknown parameter. Since Pierson-Moskowitz (equation 2.2.3) and themodi�ed Bretschneider (equation 2.2.7) are one-parameter spectra there is no other comon relationwith the two-parameter spectra. However, since Bretschneider (equation 2.2.4), JONSWAP (equa-tion 2.2.8), and ITTC (equation 2.2.12) are two-parameter spectrum, there is a second commonparameter. For Bretschneider the second parameter is the ω0 whereas for JONSWAP and ITTCthe second parameter is T1. According to the equations 2.2.5 and 2.2.10 both ω0 and T1 can beexpressed as a function of Tp. This means that the second common parameter for these threemethods could be chosen as Tp. A comparison of all �ve spectra can be seen in �gure 2.2.8. Thecomparison �gure show that Bretschneider one-parameter equation present similar result whencompared to Pierson-Moskowitz, whereas the JONSWAP equation di�er from the other equationssince it result with a peak value twice as large as the others. This can be explained from [3] whichstates the JONSWAP is equal to the Bretschneider equation multiplied with a frequency functionand γ.

14

Page 16: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Figure 2.2.8: The �gure depicts a comparison between the wave spectrum equations Pierson-Moskowitz, Bretschneider, JONSWAP, and ITTC. The signi�cant waveheight is set to 5m for all�ve equations and the modal frequency is 2π

9.7 rad/s for all but Pierson-Moskowitz and Bretschneiderone-parameter. The source code for the examples is found in the appendix E.2.

2.3 Encounter Spectrum

Figure 2.3.1: The �gure depicts the en-counter angle χ, which is the angle atwhich the waves act on the ship.

It has been presented that the previously mentionedwave spectra can be implemented to de�ne the wavebehavior of one speci�c position of the ocean, meaningit is su�cient for calculating the e�ects on a rigid bodyin the ocean. However, a marine ship is not a rigid bodybut a continuously moving object in the ocean, and de-pendent on from where the waves appear and the rel-ative speed of the waves the transferring energy fromthe waves onto the ship will alter. This means that thewave spectrum must be altered to �nd a proper realiza-tion of the waves encountered by the ship. As stated in[2] and [9] a new spectrum representing the encounteredwaves by a moving object can be introduced by takingthe average ship speed U and encounter angle χ into account, which is the angle that the shipencounters the waves at as seen in �gure 2.3.1. This spectrum is called an encounter spectrum andis de�ned by equation 2.3.1.

S(ωe) =Sff (ω)

1− 2ωUg cos(χ)

(2.3.1)

Where S is the encounter spectrum and ωe is the encounter frequency.This representation of the wave spectrum can be utilized together with a Transfer Function (TF)

called Response Amplitude Operator (RAO) to �nd the actual rolling of a moving ship in the ocean.

15

Page 17: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

2.4 Response Amplitude Operator

As previously shown with equation 2.2.1 and 2.2.2 the wave spectrum can be implemented for�nding the elevation of waves, however, these equations show no direct connection with the ship'smovement equations 2.1.1. There is a connection between the wave spectrum and the ship'smovement but it requires the implementation of TFs. In the ship motion control there is a speci�cset of TFs which have been given the name RAO. RAO is utilized for predicting the expectedforces acting on the ship based on wave behavior as well as the expected motion of the shiponce subjected to these forces. Finding the forces and the motion have been separated into twosub-versions of RAO, namely Force Response Amplitude Operator (FRAO) and Motion ResponseAmplitude Operator (MRAO). Due to the complexity of these functions they will not be coveredin this thesis. For further coverage of the functionality and background of RAO see [2].

2.5 Rolling Examples

The following section presents simpli�ed models of how the maximum rolling amplitude can beretrieved from the information of waves as well as how the damping factor of the ocean can beretrieved. The information presented in these sections gives an understanding for why RAO TFare needed.

All information presented in these sections is not further utilized within this thesis but shouldinstead be viewed as an introduction to why the RAO TF are needed.

2.5.1 Without Friction

Figure 2.5.1: The following �gure de-picts the relation between CG and CBof a spherical object which have beenlowered into water.

The following section present a simpli�ed example forobtaining the rolling if considered that there is no fre-quency in the water that a�ect the ship. When a shipis lowered in in water it will displace a certain volume.This volume can be considered as a shape with its ownCG called CB. The CB will not typically have the sameposition has the CG, see �gure 2.5.1 and when a shipstarts to roll in water the CG for the ship will remainthe same while the relation between CG and CB will al-ter, see �gure 2.5.2a and 2.5.2b. Using trigonometry, arelation between CG and CB can be shown by introduc-ing two new variables, namely Metacentric Height (GM)and heel angle Θ16. The relation can be seen in �gure2.5.3 and equation 2.5.1. GM is a distance to the Meta-centreM and is considered to be �xed for small values ofΘ. The Metacentre is considered to be a position whichthe ship rotates around when set in rollingmotion.

(a) (b)

Figure 2.5.2: The �gures depicts how the CB changes while the CG remains the same when a shiprolls in water

GZ = GMsin(Θ) (2.5.1)

16Heel angle is the o�set angle induced by the rolling

16

Page 18: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Figure 2.5.3: The following�gure depicts the relation be-tween CG and CB using GMand Θ (depicted as ϑ in the�gure)

If considered that the ship rolls around the CB and an down-right force is acting on the CG, which is equal to displacementweight of the ship, a momentum equation can be de�ned as 2.5.2.

M = −∆GZ = −∆GMsin(Θ) (2.5.2)

Where ∆ Is the displacement weight equal to the density ofwater multiplied with the volume of the displaced water. Equation2.5.2 can be extended into 2.5.5 by inserting the general formulaof momentum,inertia, and heel angle 2.5.3 as well as the generalformula of inertia 2.5.4.

M = Id2Θ

dt2(2.5.3)

I = mk2xx (2.5.4)

mk2xx

d2Θ

dt2= M = −∆GMsin(Θ) (2.5.5)

The parametersm and kxx are the mass and radius of gyration,where the mass is equal to ∆

g . By rearranging and substituting equation 2.5.5, equation 2.5.6is obtained. It can be observed that this equation almost follows the structure of a harmonicoscillation function, which can be seen in equation 2.5.7.

M =∆

gk2xx

d2Θ

dt2= −∆GMsin(Θ) (2.5.6)

M = Id2x

dt2= −kx (2.5.7)

Since the vessels considered in this thesis is signi�cantly large, the rolling operates at smallangles. This yields that sin(Θ) can be approximated to the argument of Θ. By substitutingequation 2.5.6, the equation obtains the exact same structure as harmonic oscillation. It is knownthat for the harmonic oscillation equation the solution is x = Asin( 2π

T t), which is a standardsinusoidal equation with the amplitude A, period T , and time t. Since this solution have beenveri�ed in several papers, for example [10], it can be accepted as the solution for equation 2.5.6.Through substitution equation 2.5.8 can be obtained.

−4π2Asin( 2π

T t)

T 2

gk2xx = −∆GMAsin(

Tt) (2.5.8)

By multiplying each side of equation 2.5.8 with −∆Asin( 2πT t), equation 2.5.9 is obtained.

4π2k2xx

gT 2= GM (2.5.9)

Rearranging equation 2.5.9 an expression of the period T can be obtained 2.5.10. It can beseen that this equation follows the structure for the period of a pendulum 2.5.11 if L is denoted as

L = kxx√

gGM L =

k2xx

GM .

T =2πkxx√GMg

(2.5.10)

T = 2πL

g(2.5.11)

It can thereby be stated that a ship rolling in water, without friction, have the characteristicsof a pendulum. By inserting 2.5.11 into the solution for harmonic oscillation, expression 2.5.12 canbe obtained. Where Θ is the heel angle for the ship at time t, A is the rolling amplitude, kxx isthe radius of gyration, GM is the metacentric height, and g is the gravity constant.

17

Page 19: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Θ = Asin(2π

2πkxx√GMg

t) (2.5.12)

The potential energy of a harmonic oscillation can be expressed as U = 12kx

2. In this scenariox is replaced by Θ from equation 2.5.12 and k is replaced by ∆GM (found by comparing equation2.5.6 and 2.5.7). The sought for parameter is the rolling amplitude A, so by choosing time t equalthe T

4 , the energy U can be expressed as 2.5.13.

Up =1

2∆GMA2 (2.5.13)

If consider that the potential energy of the waves Ep = mgh is directly transfered to thepotential energy of the rolling, then by substituting equation 2.5.14 is obtained.

mgh =1

2∆GMA2 (2.5.14)

Where m is equal to the density of water ρ multiplied with the displaced volume of the waterV , and h is the variation of the height of the water. Substituting and rearranging the rollingamplitude of a ship in frictionless water can be expressed as equation 2.5.15.

A =

√2ρV gh

GM(2.5.15)

As seen in equation 2.5.15 the rolling amplitude, in frictionless water, can be expressed usingknown parameters17. Figure 2.5.4 depicts how Θ changes over time when a ship experiences rollingdescribed by harmonic oscillation.

Figure 2.5.4: The following �gure depicts the rolling of a ship in frictionless water, which can bedescribed as a harmonic oscillation system. The example was generated using the source codefound in appendix section E.3.

17

• ρ - Is the density of water which is known

• V - Is the volume of the displaced water, which can be found when knowledge of the ship's hull and weightis de�ned

• g Is the gravity constant which is known for all locations around the globe

• h - Is the change of water elevation, which is known when the wave spectrum is known according to equation2.2.1

• GM - Is the metacentric height, which is considered to be �xed for small rolling angles and can be calculatedwhen knowledge of the ship's dimensions is known

18

Page 20: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

2.5.2 With Friction

The following section presents how the damping coe�cient, realized by the friction of the water,can be found based on the simpli�ed example found in section 2.5.1. If it is considered that theship follows the harmonic oscillation equation when rolling without friction, then it is possible toadd friction to the harmonic oscillation equation to �nd a more accurate rolling behavior of theship. When adding friction to the harmonic oscillation equation a new equation is formed with thename damped harmonic oscillation, which is seen in 2.5.16.

d2Θ

dt2+ 2ζdω0

dt+ ω2

0Θ = 0 (2.5.16)

Where:ζd Is a damping coe�cient based on the friction of the waterω0 Is the natural frequency of the ship

If there is no friction then ζd is considered to be equal to 0 which would yield that equation2.5.16 would be of the form of harmonic oscillation. The solution to damped harmonic oscillationcan be expressed as Θ = eλt. By substituting equation 2.5.16 with the solution, equation 2.5.17 isobtained.

λ2eλt + 2ζdω0λeλt + ω2

0eλt = 0 (2.5.17)

Through rearranging of equation 2.5.17 it can be found that equation 2.5.18 must be true tosolve equation 2.5.17.

λ2 + 2ζdω0λ+ ω20 = 0 (2.5.18)

λ = ω0(−ζd ±√ζ2d − 12) (2.5.19)

The roots of equation 2.5.18 is found using equation 2.5.19. Here it can be observed that forcertain values of ζd the system will have various characteristics. For ζd < 1 an under dampedsystem is formed, with complex roots, which means that the value of λ will be proportional toω0 but with a slight reduction. This results with a oscillation of the rolling which decreases overtime. For ζd = 1 a critically damped system is formed which means that the value of λ will beproportional to ω0. A result of this is that the rolling angle of the ship will not oscillate but insteadreduce the angle over time and stabilize as quickly as possible. For ζd > 1 a over damped systemis formed which means that the value of λ will be proportional to ω0 but with a slight increase.A result of this is that the rolling angle of the ship will not oscillate but instead reduce the angleover time and stabilize but it will not achieve preferred state as fast as a critical damped systemsince this system experiences a resistance. These three characteristics is presented in �gure 2.5.5.For a ship sailing in waves it more likely that the ship's rolling angle will oscillate until stabilizedthen stabilize immediately. This means that the rolling of a ship sailing in waves can be describedas an under damped harmonic oscillation system. An under damped harmonic oscillation systemhave complex roots which can be seen in equation 2.5.19 when ζd < 1. The accepted solution forunder damped harmonic oscillation can be seen in equation 2.5.20.

Θ = e−ζω0t(A cosβt+B sinβt) (2.5.20)

Where:β is the imaginary part of the roots λA is the initial value of ΘB is constant based on A and the initial value of dΘ

dt , follows the form of B = 2ζω0A2β +

dΘdt

β

19

Page 21: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Figure 2.5.5: The following �gure depicts the di�erence of under-, critically-, and over dampedharmonic oscillation. The example was generated using the source code found in appendix sectionE.3.

For certain values of time t, βt = 2πn, where n ∈ Z. For these values equation 2.5.20 is reducedto equation 2.5.21. This equation can be implemented to �nd the peak values for the dampedharmonic oscillation equation. Figure 2.5.6 depicts the relation between the peak equation and thedamped harmonic oscillation solution.

Θpeaks = Ae−ζω0t (2.5.21)

Figure 2.5.6: The following �gure depicts how damped harmonic oscillation decays according tocharacteristics of the peak function Ae−ζω0t. The example was generated using the source codefound in appendix section E.3.

By implementing the rules of natural logarithm a new expression is found to determine thedamping factor ζd, see equation 2.5.22.

ζd =ln

Θpeaks(t1)Θpeaks(t2)

ω0(t2 − t1)(2.5.22)

Where:t1 and t2 are two di�erent time occurrences where the ship have changed its rolling direction tothe same direction

20

Page 22: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Θpeaks(t1) and Θpeaks(t2) are the heel angle at time t1 and t2ω0 is the natural frequency of the ship, equivalent to 2π

TT is the natural period of the ship

By implementing this simpli�ed method a control system can evaluate the current damping factorof the sea and include this information within the control system to make the correct assessmentsof how to navigate the vessel for rolling reduction.

2.6 Course Keeping And Roll Stabilization

The control and maneuvering of a marine vessel is usually performed by an autopilot. This autopilotmust take several parameters into account in order decide how to steer the vessel. Some of theseparameters are; Hs, Tp, χ, U , heading, rudder angle, and ζd of the ocean. If there are waves whichencounter the vessel at for example an 45 degree angle then these waves will force the vessel o� thedesignated course, as seen in �gure 2.6.1.To avoid this the autopilot can, for example, set the vesselslightly o� course before encountering the wave. The waves will then instead aid with correctingthe vessels heading to the intended, as seen in �gure 2.6.2. This means that the autopilot mustcontinuously alter the rudder angle throughout the journey.

Figure 2.6.1: The �gure depicts an example of how the waves disturb the intended heading of theship.

Figure 2.6.2: The �gure depicts an example of how the autopilot can steer the ship to neutralizethe disturbance which the waves cause on the heading.

21

Page 23: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

The autopilot implements a control system which takes the previously mentioned parametersinto account and provide information about how the rudder shall be altered. A speci�c kindof control system called Model Predictive Control (MPC) is implemented for this. The bene�tsof the MPC is that it is capable of predicting the outcome ahead, meaning it estimates futureresponses based on passed results. Another bene�t of the MPC method is that it is capable ofoperating with constraints. In the marine industry this is a crucial feature. The MPC can therebybe set to alter the rudder angle so that the vessel follows the intended heading with respect tothe impact of waves while also limiting the rolling angles of the vessel to be within a prede�nedrange. to estimate the future responses of the adjustments which the MPC computes the RAOTFs are implemented within the MPC. Using RAO the MPC can take the current/previousparameters obtained from measurements and predict the future responses based on slight changesof the rudder angle. Through this method the autopilot can steer the vessel while maintainingthe intended heading and reducing the rolling. Figure 2.6.3 presents a simpli�ed model of thecontrol/navigation of a marine vessel based on Tristan Perez [2] research.

Figure 2.6.3: The �gure depicts a simpli�ed example of the control and navigation of a marinevessel.

Since the control system constantly obtains the latest monitored values of the ship responses itis capable of correcting and adjust for faulty wave information by comparing the actual responsesto the predicted responses. However, this is a continuous process which means that the controlsystem will adjust and correct itself with slight changes over time. If the correct Waves were tobe known then the control system would not have to make slight changes to itself to maneuverproperly.

22

Page 24: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

2.7 Simulation And Data Acquisition

It has previously been stated from equation 2.2.1 and 2.2.2 that the wave spectrum can be im-plemented for estimating the wave motion. There is a toolbox called Marine System Simula-tor (MSS)18 for MATLAB/Simulink19 which contains functions for simulating marine ships at sea.This toolbox allows for an user to simulate ocean waves by de�ning the wave spectrum. Thisthesis will implement a simulation program, which utilizes this toolbox, developed by Q-TAGGR&D AB. The program simulates the rolling of the ship when encountering certain waves, thatare prede�ned by the user, as well as the angle of the rudder which the ship's control system setsto counteract the encountered waves. Due to con�dentiality the functionality of this program willnot be described further.

2.8 Summary

The behavior of the ocean waves can be measured using buoys and rigs. These measurementscan be utilized to �nd the amount of energy for various frequencies of the waves which is calledwave spectrum. Since waves are random in their nature and behave di�erently dependent on thelocation, there are no clear de�nition of a wave spectrum which de�nes all types of waves. Insteadthere are multiple types of wave spectrum. Once the wave spectrum have been retrieved frommeasuring the waves, it can be utilized to obtain the wave elevation in time domain. The retrievedwave spectrum can be utilized along with a set of TF called RAO. This system is an on-boardsystem which predicts the force that act on the vessel as well as the resulting motion of the vessel.Once this have been found a control system can make the necessary actions to reduce the fuelconsumption as well as reduce the rolling of the vessel. However, there currently exist no on-boardwave estimation system and monitoring waves, calculating the spectrum, and transferring thisinformation to a ship is time-consuming. This can result with the wave information obtained bythe vessel being in-accurate, and the vessel might then navigate poorly and induce rolling insteadof reducing it.

Estimating the motion of the ship based on the waves can be referred to as a direct methodsince the ship obtains parameters that are utilized for calculating an output, a model of this ispresented in �gure A.0.1 found in appendix A. Reducing the previously mentioned time for thisdirect method could be possible by also implementing an indirect method. This means that theoutput is utilized along with an inverse method to �nd the parameters. A model of this can beseen in �gure A.0.2 found in appendix A. If an indirect method could be utilized for retrievingthe behavior of waves then the inaccuracy which can occur due the delay may be prevented. Thiswill then result with reduced rolling and increased fuel saving since the ship will be capable ofnavigating as intended.

18A weblink to the homepage where the MSS toolbox can be downloaded http://www.marinecontrol.org/index.

html, Available: 2017-05-04.19Simulink is a block diagram invoroment integrated with MATLAB. It is a useful tool for simulating real world

scenarios. Weblink: https://se.mathworks.com/products/simulink.html, Available: 2017-05-08

23

Page 25: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

3 Problem Formulation

The problem of this thesis is to utilize the vessel itself as a buoy measurement system for esti-mating the state at sea. This resolves to the following inverse parametric problem of; Finding theparameters Hs, Tp, and χ, which together de�ne the wave- and encounter spectrum, when themovement and dynamics of the ship's control system is known.

3.1 Limitations

The �rst limitation of this thesis is that the proposed solutions are limited to only utilize infor-mation which is already monitored and stored within the current logging system. The secondlimitation of this thesis is that the newly proposed solutions should implement AI algorithm forsolving the inverse problem. The thesis will also limit the scope of waves by implementing onetype of wave spectrum. This is due to the various wave spectra having di�erent result dependingon the parameters.

3.2 Research Questions

This thesis have two sets of research questions, constructed in the initial phase of the thesis work,and answered in the end of the thesis based on the results. Set 1 include one question which whenanswered either aid with proving or disproving the hypothesizes. Set 2 are general questions whichare hoped to be answered throughout the thesis.

Set 1

• Will changes of the wave spectrum result with changes of the rolling?

Set 2

• What alternative methods could be used for solving this problem?

• What method would be most bene�cial when estimating the wave spectrum?

• What level of accuracy can be obtained when estimating the wave spectrum with AI?

• Would the knowledge of the ship's movement and dynamics of the control system be su�cientfor estimating wave direction as well?

4 Contribution

This thesis contributes to the aim of reducing rolling of marine vessels which in turns aids withreducing the fuel consumption. This is achieved by proposing an inverse method for estimating thewave spectrum at sea which can be faster than the traditional method of obtaining wave spectrumfrom organizations.

The ocean covers 71%20 of the earth's surface, which makes it nearly impossible to monitor allchanges of the ocean using buoys and riggs. This thesis aids with �lling the gaps not monitoredby organizations by proposing an algorithm for on-board wave measurement based on alreadymonitored data of marine vessels.

20The statistical information was retrieved from the Oceanic Institute of Hawaii. Weblink: http://www.

oceanicinstitute.org/aboutoceans/aquafacts.html, Available: 2017-05-04.

24

Page 26: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

5 State-Of-The Art

This section introduces state-art-the art research concerning the topic of the thesis. Since theproblem is an e�ect of the lag created when monitoring oceans, analyzing data, and transferringthe information, the ideal solution is not necessarily an on-board solution but instead a solutionwhich also improves the currently implemented methods. The following two subsections illustratethese aspects. These subsections covers on-board systems similar to the proposed methods withinthis thesis, but also o�-board systems which are not installed aboard a vessel. The presented on-board systems are of interest for comparison, but it should be kept in mind that it is the o�-boardsystems which the proposed methods are intended to replace.

5.1 On-Board Systems

J. G. Kusters et al. [11] presented in September 2016 a prototype of a system called FutureWavesTM .The system is a real-time ship motion forecasting system which was tested aboard four di�erentkinds of United States Naval Ship (USNS). The system obtained inputs from measurements ofthe ocean surface with a Doppler-radar, the characteristics of the ship, and measured motions ofthe ship. The main-, and most important, input is the Doppler radar. This radar allows for de-tailed measurement of the ocean surface's radial-velocities from right next to the ship up to severalthousand meters away. The system implement the measured data obtained from the radar forcalculating the wave-�eld amplitude and phase frequency. Once the system have calculated thesefactors the system predicts the wave interaction along the intended voyage as well as the currentinteraction of the waves on the ship's hull. The system also implements the wave-�eld amplitudeand phase-frequency to estimate the wave-spectrum and thereafter use this as inputs for simulat-ing the motion of the ship in time-domain. This simulation demands that the characteristics andmotion of the ship is known, which explains why this is one of the key inputs for the system. Thesystem's performance was compared to nearby CDIP wave-buoys21 and presented as diagrams.

Aditya N. Deshmukh et al. [12] published in October 2016 their paper on predicting futurevalues for Hs and Tp using an Arti�cial Neural Network (ANN) algorithm. The authors trainedtheir ANN to recognize a pattern based on measured waves and thereafter predict how theseparameters would change in time. The authors obtained their data from a wave measurementbuoy located in the east coast of India. The data extracted from this buoy was implemented alongwith the mathematical models called Simulating Waves Nearshore (SWAN) and WAVEWATCH-III (WW3). SWAN and WW3 are methods which could be implemented for modeling the wavemotion, calculate the wave force and wave spectrum, as well as obtain the key characteristics Hs

and Tp. Since there are several kinds of ANN methods Aditya N. Deshmukh et al. tested andevaluated di�erent sub-methods. In an early stage of the trials-phase it was found that both theFeedforward Backpropagation (FFBP)- and Nonlinear-Autoregressive (NAR)-type of ANN provedto be promising implementations for this kind of problem. The authors tested to predict the futureparameters with 4 di�erent time steps; 3-, 6-, 12-, and 24-hours into the future. The result obtainedindicate that AI algorithms indeed can be utilized for predicting the wave behavior. This speci�cresearch is of high interest since the authors strives to estimate Hs and Tp using AI, which is thesought for output and proposed method for this thesis. The di�erences between this publishedpaper and this thesis is that these authors implemented measured and calculated values for Hs

and Tp, utilized these for acquiring future predictions of the parameters. Whereas in this thesisthe goal is to estimate the parameters based on the motion of the ship. The proposed method inthis paper could be implemented along with the reports obtained from the organizations to makea prediction of the current wave state.

In November 2015 Wei Zeng et al. [13] published a paper on estimating waves based on shipmotion responses. The authors presented the idea of utilizing the motion of ship as a sensor formeasuring the ocean instead of buoys or rigs. The main idea behind this paper is the same asthe background for this thesis. Wei Zeng et al. implement a parametric method for predictingthe frequency fm1, signi�cant waveheight Hs1, and mean direction θm1

22. An exact parametricmethod for this type of problem can be time consuming, therefore Wei Zeng et al. strive to improve

21CDIP wave-buoys are buoys placed out on the ocean by the United States for monitoring the waves.22Mean direction is in this thesis referred to as encounter angle χ.

25

Page 27: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

and simplify a presented parametric method which calculates the directional spectrum23 in bothtime and accuracy. Their proposed solution for achieving this is to separate their model into twoparametric models instead which predict the wave distribution and wave power. The authors alsoassume chosen parameters with the model to be �xed so that the amount of parameters to estimateis reduced. The authors utilized RAO to construct the parametric models. Since RAO is a set ofTF which predict the motion responses of a ship based on the waves the authors state that RAOcan be utilized to develop a parametric method which performs the inverted action. With thehelp of the RAO function the authors reduce the number of parameters in the initial parametricmethod, and thereby reducing the calculation time. The �nal result indicates that their proposedmethod performs well under rough sea conditions and worse for better conditions. The authorsstate that this is to be expected due to the ship acting as a �lter and reducing the impact of smallerwaves, which means that the responses in calm seas is tougher to distinguish.

Another similar project was published in may 2007 by R. Pascoal et al. [14]. It was statedthat the parameters de�ning the waves could be sought for by monitoring the ship responsesand compare it to estimated ship responses. R. Pascoal et al. demonstrate two methods forcharacterizing the waves which is a parametric method and a non-parametric method. R. Pascoalet al. stated that by comparing the actual responses of the ship with estimated responses based onestimated wave characteristics, it would be possible to converge the initial estimation of waves toan approximate value. R. Pascoal et al. chose to implement Genetic Algorithm (GA) as estimatorsince it is capable of �nding useful approximations within minimum time, if the cost function isconstructed properly. to utilize a parametric method it was stated that a wave spectrum wouldhave to be chosen. For this R. Pascoal et al. chose the JONSWAP spectrum which allows for severalalterations via the peak intensi�cation factor. The GA was set to estimate the Hs, Tp, χ, and γ andutilized these within the cost function of the GA. The cost function was set to calculate the wavespectrum as well as the encounter spectrum. Thereafter the cost function utilized the encounterspectrum along with TFs created by R. Pascoal et al. to �nd the motion spectrum of the sway,heave, and pitch motions. The actual motions of the ship was thereafter converted into spectralrepresentations using FFT and compared with the estimated spectral motion representations. TheGA could thereby estimate the parameters which de�ned the waves that had set the ship in motion.

5.2 O�-Board System

F.M. Calafat et al. published [15] in february 2016 a paper where they proposed that the CryoSat-224 could be used for making measurements of the ocean just as well as the cryosphere. F.M Calafatet al. limited their research into measuring the sea surface height anomaly and the signi�cantwaveheight. The results obtained from the CryoSat-2 were compared against the result obtainedfrom buoys, tide gauge25, argo �oats26, and the model WW3. Even though the end result provedto be promising, it was established that the method was more suitable for cryosphere measurement.This conclusion was based on that the CryosSat-2 had a repeat cycle of approximately 369-dayswhereas the standard altimeters have a repeat cycle of 10- and 35-days. This method would be auseful method for monitoring changes of the oceans sea level, but since it cannot distinguish thefrequency nor the direction of the waves it does not bene�t the marine industry for applicationstargeted by this thesis.

A standard way of monitoring the motion- and elevation of the ocean is with buoys and/or�oats. Supreeth Subbaraya et al. [16] proposed in December 2016 a design for a speci�c kindof �oat called a drifter. A drifter is a passive device, which means that there are no actuatorsinstalled on the device to force a certain motion. Instead the device travels along with the oceanand its current. The drifter was designed with the following criterias; (1) winds and surface waveswould have less impact on the position of the drifter than the current, (2) the drifter should besmall and modular so that it would be easy to use, (3) the drifter should be power e�cient andcapable of operating for more than a month, (4) the drifter should be capable of periodically

23Directional spectrum is referred to as encounter spectrum within this thesis.24CryoSat-2 is a satellite orbiting earth which makes measurements of the earth's cryosphere.25Tide gauge is a device which measures the sea level.26Argo is a system which measures the temperature, salinity, and currents of the ocean. A �oat is speci�c kind

of tube which descend/ascend in the ocean.

26

Page 28: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

communicate location update from anywhere, and (5) rough conditions at sea should not a�ect thedrifter signi�cantly. Three drifters were tested in the ocean and proved to satisfy the criteria madefor the initial design of the project. Supreeth Subbaraya et al. stated that future work needed forthis monitoring system was improvement of the system design so that power consumption can bereduced, and improvement of the mobility of the drifter with the means of anchors and sails. Sincethis solution relies on the drifter traveling along with the current which it occupies it becomes astrong device for current measurements. But in terms of aiding the marine industry it is lackingsince no guarantee can be made that the drifter will be monitoring the ocean close to the intendedroute of a vessel.

Maricris Cuison Marimom et al. [17] published in March 2015 a paper on developing a newsensor node for monitoring waves at a local area. The proposed sensor system was developed onan Arduino pro microcontroller for ease of development. The sensors used for this system wasand triaxial accelerometer and a triaxial gyroscope, which together would allow to sense bothtranslation- and rotation-movement. The microcontroller was set to sample data from the sensorsevery 0.01s and log the data on an microSD card connected to the system. Together with theAndroid platform a HTC wild�re Android smartphone was utilized for sending the data i the formof text messages to a central receiver. For powering all these components a 9V LiPo battery wasconnected as well as a solar panel for charging. These components were mounted on a buoy sothat the measurements could be made out at the ocean. Although this wave buoy is capable ofretrieving accurate measurements of the ocean it does not improve the calculation- and transferringtime which creates the previously mentioned lag which is sought for to reduce. However, since thebuoy is mounted with a smartphone it would be possible to create an application which sends thelatest logged data directly to nearby vessels and thereby reducing some of the transferring time.

6 Methodology

The methodology of this thesis can be divided up into four phases. Each and every phase isexplained in the following subsections.

6.1 Research

The �rst phase of the thesis is a qualitative research phase, which involves research in wave the-ory, ship dynamics, state-of-the art methods, and possible AI solutions. The later also includesexecuting a literature review/study to determine which- and how many of the proposed methodsthat should be implemented within this thesis. The following list presents where in the thesis theinformation can be found for each step of the research phase.

• Wave theory - The research, and necessary knowledge needed, of wave theory can be foundin section 2.2.

• Ship dynamics - The research, and necessary knowledge needed, of ship's dynamics can befound in section 2.1 and 2.4.

• State-of-the art - The state-of-the art research, which involves related solutions to solvingthe problem as well as the standard way for �nding wave spectrum, can be found in section5.

• Possible solutions - The research and review of the possible solutions can be found insection 7.

6.2 Implementation

The implementation phase is an iterative phase since this part of the thesis repeats a similarprocedure. The �rst step involves repetitive acquisition of data from a direct simulation programso that there is enough data for both training an validation. The second step of this phase is toimplement a direct and indirect method using transfer functions similar to the solution presentedin [14]. Through this method the basic principle of the RAO TFs can be presented and further

27

Page 29: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

explained as well as an extended version the RAO principle can be investigated. The third stepinvolves implementing an AI algorithm for solving the inverse problem, meaning replacing the TFwhich estimates the wave spectrum based on the motion.

The data mentioned for training the algorithms is obtained by implementing the previouslymentioned simulation program (see section 2.7) which utilizes the MATLAB toolbox called MSS.This simulation will allow the user to enter a value for Hs, Tp, and χ as well as enter a speci�cwave spectrum type. This simulation will then provide the user with for example the roll-andrudder angles during a prede�ned time interval. Su�cient data can thereby be generated in orderfor proper training and validation of the proposed algorithms. However, with this approach the AIwill be trained for estimating one type of wave spectrum. Information about the chosen algorithmand how it operates can be seen in section 8.

6.3 Test And Validate

The testing and validation phase is an iterative phase since multiple tests are conducted to concludethe usefulness of these methods. The implemented methods will be tested with untrained dataobtained from the simulation program. The validation method called n-fold cross-validation27 willbe implemented for validating the methods. The result obtained from each test is utilized to decidean average accuracy for the algorithms. The implemented methods will then be compared againsteach other based on the accuracy to state which method would prove most useful.

The trained algorithms will thereafter be tested using logged data from an actual vessel, sailingon the Baltic Sea, where the result obtained will be compared to the measured wave informationprovided from the Swedish Meteorological and Hydrological Institute (SMHI)'s webpage28. Thefold which generated the best solution in the simulation test will be implemented as con�gurationfor this test. This test is to evaluate whether a solution can be created based on simulated dataand then implemented on actual scenarios.

Lastly the methods will be re-trained using solely actual data obtained from vessels and buoys.The same training procedure as for the simulation training is followed but the n-fold cross-validationmethod is not implemented. Instead the methods will be trained based on data acquired from twoconsecutive voyages. A third consecutive voyage will thereafter be implemented for testing. Thiscreates an applicable suggestion of using the most recent data for training a solution before avoyage.

The information about the validation of the methods can be found in section 9 and the resultfrom the validation is found in section 10.

6.4 Conclusion

Lastly the results obtained in section 10 are analyzed and conclusions are made concerning thevalidity and accuracy of the propose solutions. Statements concerning whether the hypothesizeshave been proved or disproved based on the results are made and similarly answers to the researchquestions are concluded as well. These are all found in section 11.

7 Possible Solutions

The following sections presents the AI algorithms considered for solving the problem. A briefintroduction is given for each algorithm as well as statements to why they could prove useful forthis particular problem. A comparison is made between the algorithms as well as a decision of thechoice of algorithms for this thesis. The chosen algorithms is then further explained in section 8.

27The n-fold cross-validation is a method which separates the data in n number of sets. One set is then chosento be implemented as validation set whereas the remainder is implemented for training. Each and every set isimplemented as a validation set once so that proper result can be obtained.

28Weblink to SMHI's wave monitoring site: http://opendata-download-ocobs.smhi.se/explore/?parameter=0#,Available: 2017-05-04

28

Page 30: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

7.1 Feedforward Neural Network With Backpropagation

The �rst considered algorithm is a standardized FFBP algorithm. The main reason for consideringthis algorithm is because it is the simplest kind of ANN and the algorithm have proved to be usefulin a similar scenario presented in [12]. The algorithm have obtained its name from its structure.The basic principle is that the algorithm takes inputs and calculates the output directly withoutany regression or loops, which generally is expressed as the algorithm feeds/goes forward.

Figure 7.1.1: The �gure depicts a simple example of the structure of a FFBP network. Thenetwork shows the how the inputs are weighted and implemented as inputs for the nodes. Thenodes summarizes the inputs and runs the result through an activation function which yields theoutput of the node.

Figure 7.1.1 depicts a simple example of a FFBP. The algorithm takes the inputs and scale themwith weights which are used as inputs for nodes in what is called the hidden layer. These nodes takethe weighted inputs, as well as a bias weighted input and summarize them. For example node 1 in�gure 7.1.1 preforms the following action Y = X1∗w11 +X2∗w14 +1∗w15. The node then executesthis value through an activation function which yields the node output. The standard choice ofactivation function is a sigmoid function Out = 1

1+e−Y. This output is thereafter implemented

along with a weight as an input for the next node. This process is repeated until the �nal outputof the network have been obtained. The algorithm trains with a Backpropagation (BP) methodwhich is a widely implemented approach for ANN. The method bases on that known scenarios arecomputed by the network and an error rate is calculated. The method then propagates backwardsin the network and alters the each weight one by one, based on for example Gradiant Descent (GD)which computes the derivative error for each weight, until all weights have been altered.

This AI algorithm is fairly easy to implement both for estimating and training. However, thereis a risk of not �nding the best combination of weights, but instead �nding a local minimum of theerror. There is also a risk of over�tting or over-train the network, which means that the networkperforms really well for the trained cases but have failed to �nd a combination of weights whichwill work well for unknown cases.

7.2 Adaptive Neuro Fuzzy Inference System

The Adaptive Neuro Fuzzy Inference System (ANFIS) algorithm is just as the FFBP algorithm aforward method, but ANFIS is a combination of ANN and fuzzy logic.

The following explanations refers to the ANFIS structure example in �gure 7.2.1. The �rststep of the ANFIS algorithm is that the inputs are executed through the fuzzy logic part of thealgorithm, which means that the inputs are utilized together with a membership function whichstates to which degree the inputs are characterized of certain group29. The degree obtained fromthe membership functions are utilized to decide which rules are �red. Each rules have variousparameters, that are trained during the training phase, which are implemented as weights for

29If one of the inputs are mass of an object, then this input can be characterized as belonging to a certain amountof group heavy or light

29

Page 31: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Figure 7.2.1: The �gure depicts an example of a structure for the ANFIS algorithm.

the ANN part of the algorithm. This ends the fuzzy logic part of the algorithm. Once thecorrect parameters have been decided by the rules they are normalized. After this the algorithmimplements the normalized weights along with weighted inputs in the ANN part of the algorithm..

The ANFIS algorithm have proved useful to a similar problem [18] of �nding the ship speedbased on Hs and wind speed. The ANFIS algorithm have the bene�ts of combining two good AIalgorithms for obtaining a result. However, the algorithm is much more complicated to create andtrain due to two learning methods (BP and Least Square Estimation (LSE)) are needed for trainingthe algorithm. Having both fuzzy logic and ANN also means that there are more parameters toadjust during the training which means that more training examples is needed to obtain goodresults.

7.3 Cased-Based Reasoning

The Case Based Reasoning (CBR) algorithm is based on how humans can anticipate a neverbefore encountered scenario. A human may compare a new experience to previously encounteredscenarios and from them make a conclusion of how to interact with the new experience. Thisis the foundation of CBR. A CBR algorithm compares the new scenario/event with previouslyknown cases stored in a database. One or more of the known cases is chosen as the most similarcase/cases. If one case is chosen then this case is presented as the solution, if more then one caseis chosen then a weighted combination of the solution for these solutions is made to �nd a newproposed solution for the new unknown case. Once a new solution have been found it is oftenadded to the database so that the exact same procedure will not be repeated.

The bene�ts of CBR is that no training is needed, unless weighted combination is utilized,which allows for quick use, and the method is fairly easy to implement. Some drawbacks of themethod are that there need to be a large database of known cases to search through and if thereis no similar case then the method will blindly choose bad cases to represent the solution.

7.4 Feedforward Neural Network Using Genetic Algorithm

According to [19] a Feedforward Genetic Algorithm (FFGA) performs better than FFBP. Justas FFBP a FFGA implements a standardized Feedforward Neural Network (FFNN) with thedi�erence of training the network with GA instead of BP. GA bases on the evolution of theanimal kingdom, meaning each new generation have taken the strongest genetic characteristicsfrom previous generation and performed a random mutation to evolve as a species. In terms oftraining a neural network this means that there are several initial populations or sets of weightsand biases for the neural network. The sets which yields result with minimum error are chosenas evolution sets. These sets are combined to create a new set/generation of weights and biases.The new set then mutates, which means that random chosen weights and biases of the new set arechosen to obtain a new random value. The newly created set then replaces the worst set of thepopulation if it yields a better result. This process can be realized by �gure 7.4.1 and is continuedfor an arbitrarily number of iterations. The set which yields the best result for the training dataafter arbitrarily number of iterations is chosen as the weights and biases for the FFNN.

30

Page 32: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Figure 7.4.1: The �gure depicts a simple example of how GA works. In terms for FFGA thegenetic information of the individuals are numerical values for a weight or bias of the net, and theindividuals is one con�guration of all the weights and biases.

Bene�ts of a FFGA is that it is easy to implement and it requires less computations30 than aFFBP. Another bene�t is that the random mutation of GA can prevent the algorithm from only�nding a set of weights which yields a local minimum error. One drawback of FFGA is that thereis a risk for over�tting which is a general problem for neural networks.

7.5 Comparison

A table 7.5.1 with the stated pros and cons have been derived to aid with the comparison of thealgorithms.

FFBP ANFIS CBR FFGA

Pros Easy to ImplementCombination oftwo algorithms

No TrainingNeeded, Easy to

Implement

Easy to Implement,Less ComputationThan FFBP, Riskof Finding LocalMinimum is LessThan FFBP

ConsFinds Local

Minimum, Risk forOver�tting

Harder toImplement, Needs

Much MoreTraining Examples

Than FFBP

Needs LargeDatabase, ReliesOn That ThereExists Similar

Cases In Database

Risk for Over�tting

Table 7.5.1: The table presents the stated pros and cons for the proposed algorithms.

FFBP, FFGA, and ANFIS are all several versions of ANN. The bene�t of implementing a ANNis that they tend perform well for numerical predictions due to the weight and bias calculations.Since the problem of this thesis is �nding the numerical values of Hs and Tp it becomes abundantlyclear that methods which performs well for numerical estimations are relevant. CBR is a methodwhich also can do well for numerical estimations. Implementing this method means that statisticalmethod can be implemented for �nding the most related cases and then implement the degree of

30BP calculates the error for each and every weight and alters them accordingly, whereas GA combines sets ofweights an alters certain weights at random. This means that BP requires more computations than GA.

31

Page 33: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

similarity to obtain a new estimated value forHs and Tp. Based on this all four method are relevantand could yield promising results. However due to time constraints not all four algorithms will beimplemented. Since FFBP, CBR, and FFGA are all considered as easy to implement solutions,these will be chosen for implementation. The result obtained from the ANN could indicate whetherit would be pro�table to implement an extended version of ANN such as the ANFIS algorithm.

8 Implementation

The following section covers the implementation of the proposed solutions. All of the implementedmethods have been developed in a MATLAB environment. It was decided to utilize MATLAB asdevelopment environment since it is an easy to develop concepts within it, and it handles vectorand matrix calculations swiftly which is a signi�cant bene�t for these solutions.

8.1 Data Acquisition

A MATLAB program was developed to execute the simulation program with various con�gurationsto obtain su�cient data for training and testing. The simulation program was set to simulate 500seconds with a sample time of 0.25sec which yielded 2001 data-points of rolling- and rudder-information. The simulation program was set to run with various con�gurations of Hs, Tp, and χwhich can be seen in table 8.1.1. The con�gurations yields a scope of calm seas as well as roughseas which can be veri�ed by comparing to the Douglas Scale31 seen in table 8.1.2.

Hs(m) Tp(s) χ(deg)

Lower Bound 1 2 20

Sample Step 1 1 20

Upper Bound 5 8 360

Table 8.1.1: The table presents the scope of the wave parameters when extracting data from thesimulation program

Code Sea State Waveheight

0 Calm (glassy) -

1 Calm (rippled) 0 - 0.10 meters

2 Smooth 0.10 - 0.50 meters

3 Slight 0.50 - 1.25 meters

4 Moderate 1.25 - 2.50 meters

5 Rough 2.50 - 4 meters

6 Very Rough 4 - 6 meters

7 High 6 - 9 meters

8 Very High 9 - 14 meters

9 Phenomenal over 14 meters

Table 8.1.2: The Douglas Scale which states the state at sea for various waveheights. The tablewas recovered from euro WEATHER's homepage http://www.eurometeo.com/english/read/

doc_douglas

The speed of the ship was con�gured to be the same for all of the simulations. This decision was

31The Douglas Scale is a scale which describes the state of the sea dependent on the wave height.

32

Page 34: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

made due to simulating data was time consuming. Morevover it was decided that analysing variouscon�gurations of wave parameters is more important than the increased precision from increaseddata size, which simulations with various speed-sets would su�ce. However, the simulation initiatesthe ship with a speed of 0 m/s and then it starts to accelerate towards the target speed-set. Sincethe state of the sea varies between simulations, the time needed for the ship to reach preferredspeed will also vary. This resolves with cases with various ship speed.

A decision was also made to split up the simulated data/cases into several cases with shortersimulation time. It was decided that the separated cases should include 101 consecutive datapointsfrom the original simulated case, which yields cases with a period of 25sec. This resulted with anincreased number of usable simulations for the estimations as well as several cases with varyingacceleration and average speed of the vessel. This separation of the simulated data resulted with11970 cases to utilize for the training and testing of the algorithms instead of the initial 630 casescreated by the simulation program. Figure 8.1.1 depicts a model of how one simulation was splitup into several cases to be used with the algorithms.

Figure 8.1.1: The �gure depicts a realization of how one generated simulation of a ship in certainwaves for 500sec was split into several simulations of a ship in the same type of waves during 25sec.

8.2 Transfer Function

The standard operation aboard a marine ship, as seen in �gure A.0.1, is that the wave spectrumis utilized with the RAO TF to �nd the actual rolling. R. Pascoal et al. [14] proposed a solutionfor the inverse problem based on this model which yielded highly accurate results. Implementinga similar method as R. Pascoal et al. and comparing it with the newly proposed methods as wellas the original method proposed by R. Pascoal et al.'s is of interest.

Based on this the �rst method chosen for this thesis was to create two discrete time TFs, one fordirect estimation and one for the indirect estimation. This method aids with proving or disprovinghypothesis H1 and demonstrates the complexity of RAO. The basis on utilizing discrete time TFsinstead of continuous TFs is due to the data being of discrete time form, which means that the datais sampled. Discrete time TF also take into account the previous states of the input and outputwhen calculating the output for the current input. This speci�c feature of the TF is importantsince the motion of the ship at time tn will di�er depending on the motion of the ship at time tn−1.The reasoning for implementing two separate TFs for solving the direct and indirect problem wasbecause of no invertible TF could be found within the time frame set aside for this phase.

The TF solution was conducted in three di�erent ways: (1) loop for best con�guration based onone simulation example, (2) implement GA to �nd the best con�guration based on one simulationexample, and (3) implement GA to �nd the best con�guration based on several simulation exam-ples. Since the sought for TF were to �nd a connection between the wave spectrum (measuredin frequency domain) and the rolling (measured in time domain) it was decided that the rollingshould be converted into frequency domain as well. Perez [9] presents that the rolling of a ship can

33

Page 35: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

be obtained the same way as the wave elevation if the roll spectrum is known. As mentioned insection 2.2 the wave elevation was obtained with Fourier series based on the wave spectrum, andin the same way the rolling of the ship can be obtained from the roll spectrum. Equation 8.2.1shows the correlation between roll spectrum and actual rolling of ship.

Θ(t) =

N∑k=1

Θkcos(ωekt+ εk) (8.2.1)

Where:Θ(t) is the heel angle or rolling angle at time tΘk is the individual rolling amplitude for component kωek is the individual frequency for component kεk is the individual random phase for component k

Equation 8.2.1 is a realization of IFFT which means that the roll spectrum can be obtainedfrom the actual rolling by applying FFT on the signal, and the actual rolling may be identi�edby applying IFFT on the roll spectrum. A model of the correlation between wave spectrum andactual rolling can now be created, see �gure 8.2.1.

Figure 8.2.1: The �gure depicts the model used for the TF based method, which solves the directand indirect problem of obtaining the rolling of the ship based on the wave spectrum, and obtainingthe wave spectrum based on the rolling of the ship.

There are certain problems that needs to be highlighted when implementing this solution.Firstly, the TF will be limited to estimating one type of wave spectrum which is not optimal dueto no wave spectrum can represent all types of waves. Secondly, an exact value for χ cannot beguaranteed to be found. This is due to the encounter spectrum, equation 2.3.1, utilizing χ ascos(χ). This means that if the encounter spectrum were to be analyzed it would generate twovalues for χ within the interval of [0 2π]. This could be circumvent if there were some way ofspecifying that the encountered waves are on port or starboard side of the vessel32. Similarly to R.Pascoal et al. [14], the implementation of GA could prove useful to estimate the wave parametersthat generated the encounter spectrum obtained from the TF. The following sections explainsfurther how the previous mentioned solutions were implemented in-order to satisfy the presentedmodel in 8.2.1.

32Port and starboard are the left and right side of the vessel. If it could be known which side the vessel encounteredthe waves on then it could be stated that χ is within the interval of [0 π] or [π 2π] instead of [0 2π]. This meansthat problem of obtaining two values for χ would be removed.

34

Page 36: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

8.2.1 Loop For Transfer Function Based On One Case

The �rst attempt of identifying the TFs utilizes the speci�c MATLAB command tfest. Thiscommand allows the user to enter which kind of TF is sought for and the speci�c input and outputwhich the TF shall shape itself to �t. The command then returns a TF which suits the giveninformation. For solving this speci�c problem the command is given the encounter spectrum andthe rolling spectrum as input and output for identifying the direct TF and the rolling spectrumand the encounter spectrum as input and output for identifying the indirect TF. The commandwas also given a speci�c value for number of poles and sample time of the data. The following listfurther explains the preparations of the inputs for the tfest command.

• Input/Output - The input and output for the TF are two vectors containing the energyobtained from encounter- and roll spectrum with the same number of samples as the rollingdata. For example, the rolling data was a 25sec simulation sampled with 0.25s, which re-sults with 101 datapoints. This means that the spectrum vectors contained 101 samplesrepresenting the spectrum

• Poles - The amount of poles for the TF are tested iteratively, by looping from 1 to 70 poles33.

• Zeros - The tfest command allows the user to not enter the number of zeros which resultswith the command searching for the best number of zeros that yields the best result. Thisfeature of the commands is utilized

• Sample time - The sample time is set to the scope of the encounter spectrum divided by thenumber of samples. Wave spectrum usually converges to 0 around the frequency of 2rad/s.The scope of the encounter spectrum is thereby decided as [0 2]rad/s. Which yields thesample time 2

100 rad/s

By executing the tfest command with the con�guration mentioned in the list the user obtainsa discrete TF of Z-transform. An example of the obtained TF can be seen in equation 8.2.2.

TF =

∑Mm=1 amz

1−m∑Nn=1 bnz

1−n(8.2.2)

Where m,n,M,N ∈ N and M ≥ N .As previously mentioned this method iterates through a loop to �nd the best TF for the directand indirect problem. This is achieved through implementing the tfest command and increasingthe amount of poles in each loop iteration, starting from number of poles equal to 1. Every newlyfound TF is compared to the previously best TF using a �tness34 value obtained from the tfestcommand. A �owchart of this method can be seen in �gure 8.2.2. This �owchart presents theexecution for one TF, which means that the �owchart is executed twice35. The limit chosen forthe number of poles is 70. This limit was chosen from testing. For large number of poles the tfestcommand requires su�cient amount of time to generate a TF.

8.2.2 Optimize Transfer Function With Genetic Algorithm Based On One Case

The second attempt of identifying the TFs for the direct and indirect problem is by replacing theloop and tfest command from the previous section with a GA that predicts the optimal values forthe am and bn variables presented in equation 8.2.2. This new method utilizes the optimizationtoolbox of MATLAB so that the in-built GA application can be utilized. From testing, it wasfound that the encounter spectrum consists of real parts whereas the roll spectrum consists of bothreal and imaginary parts. This means that the GA must predict complex numbers for am and bnto �nd the TFs. The GA is constructed to estimate a vector with 400 �oat values. The �rst 100values of the vector represents the real part- and the following 100 would represent the imaginary

3370 poles was arbitrarely chosen from testing the accuracy and time needed to generate the TF.34The tfest command returns not just the TF but also return a �tness value in percentage similarity. If the TF

yields an output which completely matches the sought for output then 100% is acquired as �tness value.35The �owchart only demonstrates how one TF is acquired, and since a direct TF and an indirect TF is sought

for the process described by the �owchart is executed twice

35

Page 37: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Figure 8.2.2: The �gure depicts the �owchart of the method which loops for the best TF.

part- of the am variables. In the same way the last 200 values of the vector represents the real andimaginary part of the bn variables. This allows the GA to estimate a TF with up to 99 poles andzeros36. The variables is sought for within a range of [-1 1], which allows the GA to set certain amand bn to 0, thereby reducing the number of poles and zeros. The setup of the GA is presented inthe following list.

• Population - The population size of the GA is set to be 100

• Generations - The number of maximum generations is set to in�nity. The reasoning behindthis choice is to ensure that the algorithms will continue estimating for a certain amount oftime

• Elite-count - The number of individual that are guaranteed to survive to the next generationis set to 5

• Crossover function - The implemented crossover function is scattered, which means thatrandomly selected variables of the parents are utilized to shape the children.

• Exit - The algorithm is con�gured to stop the execution once the time limit of 30 minuteshas been reached or the algorithm has failed to �nd a better individual for 1000 generations

Since two TF are sought for this algorithm is executed twice with the same con�gurations.However, the cost function37 di�ers depending on if the TF for the direct- or indirect problem issought for. Through testing it was found that the best estimation of a TF for the direct problemwas achieved by implementing the in-built �tness function in the command compare38 as �tnessvalue. Whereas for the indirect problem it was found that the best TF was obtained when the costfunction was the average of the Mean Squared Error (MSE) of the real part and the MSE of theimaginary part. A model of this implementation can be viewed in �gure 8.2.3

36Estimating 400 parameters was chosen since it yielded almost as many poles and zeros as the amount of inputand outputs.

37The cost function is a function which the GA implements to decide if the individuals in the generation are goodor bad.

38compare is a MATLAB command which takes a TF along with the input and expected output of the TF andcompares the obtained result to the expected result. The command can return the percentage similarity just as thepreviously explained command tfest.

36

Page 38: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Figure 8.2.3: The �gure depicts a �owchart of the program which utilize GA and one training caseto �nd a TF that solves the inverse problem.

8.2.3 Optimize Transfer Function With Genetic Algorithm Based On Several Cases

The third attempt is focused only on solving the indirect problem, since this is the problem ofthis master thesis. This attempt relates to the presented solution in the previous section. AGA is implemented to �nd a TF which predicts the encounter spectrum based on the rollingspectrum. The di�erence between this presented solution and the previously mentioned one, isthat this solution implements several training cases instead of just one training case, meaning eachindividual of parameters for the TF is tested for several cases instead of just one case. The GA iscon�gured with the same con�gurations as the GA for the single case solution. A slight change tothe �tness function utilized for the single case solution is made in-order to suit this multiple casessolution. The �tness function is altered to calculate MSE for all training cases and then calculatethe average MSE based on all training cases so that the GA is able to �nd a TF which suits allthe cases the best. The process of �nding the optimal TF suited for multiple cases is representedby �gure 8.2.4. The process is aborted when any of the stop criteria mentioned in previous sectionis met.

8.2.4 Parameter Extraction

This section covers the extraction of the wave parameters from the estimated encounter spectrumobtained from the TFs. A GA is utilized to estimate Hs within the interval of [0 10], Tp withinthe interval of [0 18], and χ within the interval of [0 π] or [π 2π] depending on which side theencountered waves attack39. The cost function of this GA calculates the values for the encounterspectrum based on the estimated wave parameter of the GA. It then compares the mean di�erencesof the estimated encounter spectrum and the encounter spectrum obtained from the TF, accordingto equation 8.2.3, which is then utilized as �tness value for the GA.

cost =

∑ 2∆ωn=1 |S(ωe)

GA − S(ωe)TF |

2∆ω

(8.2.3)

The GA is allowed to continue estimating the parameters up to 25sec since this is the chosenperiod for the monitoring of the ship's responses. This time can be increases if considering thatseveral monitored periods should be utilized with the cost function. Figure 8.2.5 presents a modelof the parameter extraction method.

39It is considered that an approximation can be known for the encounter angle whereas the encounter wavescharges from port-side or starboard-side of the ship. This can be estimated based on measurements of the windspeed/direction, visual inspection, or data recovery from organizations

37

Page 39: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Figure 8.2.4: The �gure depicts a �owchart of the program which utilize GA and several trainingcases to �nd a TF that solves the inverse problem.

Figure 8.2.5: The �gure depict a model for the method which extracts the parameter that havegenerated the estimated encounter spectrum.

38

Page 40: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

8.3 Feedforward Neural Network

This section focuses on replacing the previously mentioned TFs and parameter extraction with aFFNN instead which directly estimates the parameters Hs, Tp, and χ. As previously mentionedin section 7 a FFNN was considered a valid solution for this kind of problem, therefore this AIalgorithm is chosen as the next method to implement. The FFNNs presented in the followingsections were all developed in a MATLAB environment utilizing the neural network toolbox. Thisspeci�c toolbox allows the user to easily construct and train a neural network using the followingcommands feedforwardnet, con�gure, and train. The user can easily change between several di�er-ent training methods as well as set the end-of-training criteria. Two various implementations of aFFNN is implemented; the �rst is based on Resilient Backpropagation (RPROP), and the secondis based on GA.

8.3.1 Feedforward Neural Network With Backpropagation

The �rst implemented FFNN is trained using RPROP. This speci�c kind of training function forneural network was chosen based on the information found at MATLABs webpage40 stating �Thetrainrp function is the fastest algorithm on pattern recognition problems�. Since the FFNN shallestimate the parameters de�ning the wave spectrum based on the measurements of the boat, forexample the rolling, the problem becomes �nding a pattern of the measured data from the shapewhich can be directly connected to speci�c wave parameters. It was also stated by M. Riedmillerand H. Braun [20] that RPROP is capable of optimizing the weights of a neural network signi�cantlyfaster then the standard GD method. Due to time being a predicted limitation for this thesis it wasdecided that RPROP could be a promising learning method for the FFNN. The di�erence betweenRPROP and the regular GD is that RPROP does not take into account the magnitude of the errorfor the network but instead only focuses on the whether the error is positive or negative. This isachieved by introducing a weight update value ∆ij for each and every weight wij of the networkwhere j and i are neurons connected with weight wij . The weight wij either adds or subtractsthe value of ∆ij depending on if the error derivative is positive or negative. The weight updatingprocess for learning iteration t is given by equation 8.3.1 and 8.3.2 according to M. Riedmiller andH. Braun [20].

∆wtij =

−∆t

ij , if δEδwij

t> 0

+∆tij , if δE

δwij

t< 0

0, else

(8.3.1)

wt+1ij = wtij + ∆wtij (8.3.2)

The individual weight update value is increased with a learning factor η+ every iteration whichdoes not yield a change of the error derivatives sign. As soon as a change of the sign of the errorderivative is detected the ∆ij is instead decreased with a learning factor η

−. The update process forlearning iteration t of ∆ij , according to M. Riedmiller and H. Braun [20], can be seen in equation8.3.3.

∆tij =

η+ ∗∆t−1

ij , if δEδwij

t−1 ∗ δEδwij

t> 0

η− ∗∆t−1ij , if δE

δwij

t−1 ∗ δEδwij

t< 0

∆t−1ij , else

(8.3.3)

Where 0 < η− < 1 < η+.The implementation of the �rst FFNN was an iterative process. Several con�gurations of the

network was tested using short training times to �nd a con�guration which yielded results whichsu�ced. The following list states the �nal con�gurations chosen for the FFNN with RPROPimplemented within this thesis.

40Weblink to the speci�c page cited https://se.mathworks.com/help/nnet/ug/

choose-a-multilayer-neural-network-training-function.html, Available: 2017-05-04

39

Page 41: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

• Outputs - As previously mentioned the sought for outputs were Hs and Tp. However, asstated earlier χ a�ects the encounter spectrum which is utilized to estimate the rolling. Basedon this all three parameters are chosen as outputs for the neural network

• Inputs - A variety of inputs were considered, implemented, and tested to obtain the bestresult. It was found that the rolling angle, rudder angle, and pitch angle41 yielded the bestresult. All three features are represented by a vector of 101 samples with the sample time of0.25sec. Each sample of each feature is considered as one input for the FFNN, which resultswith 303 inputs

• Layers & Neurons - Several con�gurations of layers and neurons were implemented andtested, but one con�guration was chosen as the �nal con�guration for the network. Thenumber of hidden layers for that network is set to 3 and the respective amount of neuronsstarting from layer 1 is 81, 27, and 9. The output layer have 3 neurons since the outputs areequal to 3

• Activation function - Through testing it was found that a sigmoid function for the hiddenlayers and a linear function for the output layer yielded the best result

Figure 8.3.1: The �gure depicts the FFNN obtained through MATLAB with the speci�ed con�g-uration from the list.

Figure 8.3.1 presents the network realized by the con�guration speci�ed in the list. The net-work is fully connected, which means that all the inputs are connected to all the neurons of the�rst hidden layer, and all the neurons of the �rst layer are connected to all the neurons of thesecond layer. The numeric value seen in the �gure, below each layer, represent the amount ofneurons/biases of that layer. The total amount of weights of the network can be calculated usingequation 8.3.4.

Weightsamount =

L∑l=1

InlNel (8.3.4)

Where:L is a vector containing the hidden layers 1-3 and the output layerInl is the number of inputs for layer l of LNel is the number of neurons for layer l of L

Entering the values from the list into equation 8.3.4 yields that there are a total 27000 weights inthis network. Similarly the amount of biases can be calculated with equation 8.3.5.

Biasesamount =

N∑n=1

Nen (8.3.5)

By entering the values into equation 8.3.5 it is found that the network consists of 120 biases,giving a total of 27120 weights and biases in the network. The network is set to continue training,according to the model presented in �gure 8.3.2, until any of the criteria presented in the followinglist is ful�lled.

41The rolling- and pitch angles supplies information about how the waves have set the ship in motion. The shipis constantly moving which sourced the belief that the rudder angle needs to be included, since alterations of thiscan create a momentum on the ship which a�ects the rolling- and pitch angles.

40

Page 42: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

• Time - The network has trained for 30 minutes

• Epochs - The network has attempted to optimize itself 1000 times

• Failures - The network has failed to optimize itself 20 times in a row

• Goal - The network reached 0 MSE

Figure 8.3.2: The �gure depicts a representative model of how the FFNN were trained.

8.3.2 Feedforward Neural Network With Genetic Algorithm

The second attempt of implementing a FFNN includes attempt to train a network, with thesame architecture as the network found in section 8.3.1, with GA instead of RPROP. The GA iscon�gured to estimate values for the weights and biases within the interval of [−1 1]. It is also setto be time based and continue estimating new combinations during the time limit of 30min. Thereason for forcing the GA to not abort the estimation process earlier is to ensure that the algorithmhave investigated as many relevant and possible combinations as possible. The time limit is chosenwith respect to the time limit of theRPROP implementation. The same model for the trainingstructure was utilized when training the GA based FFNN (or FFGA), as seen in �gure 8.3.2.

8.4 Case-Based Reasoning

As previously stated both FFNN and CBR were chosen as possible algorithms for the problemof this thesis. This section covers the implementation of the CBR. Since the rolling-, rudder-,and pitch angle are all considered as the optimal inputs for the FFNN implementation, they arereuseds as inputs for the CBR as well. This decision were made so that the algorithms could beproperly compared against each other. The CBR is set to check the similarity of a new case topreviously known cases stored in a database. The similarity check is performed with Euclidean-and Manhattan distance, which is further explained later. The similarity check is based on thek-nearest neighbor method42, with k equal to 3. This decision was mainly based on that there are 3sought for outputs which yielded the assumption that 3 various known cases could be implementedto �nd an approximation of the 3 outputs. Once the similarity check has found the 3 mostsimilar cases the CBR implements weighted outputs. This means that the algorithm takes theoutputs/wave parameters for the most similar cases and multiply these parameters with a weightbefore summarizing the weighted parameters to obtain the estimated parameters of the new case.This is represented by equation 8.4.1.

42The k-nearest neighbor method bases on that the k-amount of most similar cases to the sought for case is chosento be combined to estimate the new case.

41

Page 43: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

O =

3∑n=1

wonCaseOn (8.4.1)

Where O are the estimated outputs Hs, Tp, and χ, won is the weight for output O with similarityrank n, and CaseOn is the output O from the case with similarity rank n. The weights arepredetermined/trained with a time-based GA of 30 minutes and known cases. The training ofweights for the CBR algorithms followed the model presented in �gure 8.4.1.

Figure 8.4.1: The �gure depicts a representative model of how the CBR were trained.

8.4.1 Euclidean Distance

The �rst similarity measurement method tested in this thesis for the CBR is the standard Euclideandistance similarity measurement method. This method is widely implemented when it comes toCBR and is therefore the �rst chosen method. The exact equation of the similarity calculation canbe seen in equation 8.4.2.

distance =

√∑I

∑D

(pID − qID)2 (8.4.2)

Where:I is the inputs rolling, rudder, and pitchD is the datapoints of said input featurep is the database caseq is the new case

By implementing this equation a numeric value is obtained, which represents the similarity be-tween the new case and a case in the database. If an exact match where to be found then thatwould result with a distance equal to 0.

8.4.2 Manhattan Distance

The second implemented similarity measurement method tested in this thesis is the Manhattandistance. The di�erence between the Euclidean and the Manhattan distance is that instead ofsquaring the di�erences, summarizing, and then take the square root, the Manhattan distancesimply takes the absolute value of the di�erences and summarizes it. Equation 8.4.3 represents theequation implemented to realize Manhattan distance.

distance =

√∑I

∑D

|pID − qID| (8.4.3)

42

Page 44: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Where:I is the inputs rolling, rudder, and pitchD is the datapoints of said input featurep is the database caseq is the new case

9 Validation

This section presents how the proposed solutions are validated. The n-fold cross-validation methodis implemented for the methods so that the comparison and conclusions based on the results canbe eased. However, some alterations to the validation method must be made between the varioussolutions, which is further explained in the following subsections. The n-fold cross-validation isbased on that the acquired data is divided up into n amount of training and validation folds/sets.In this thesis 10-fold cross-validation have been utilized, which means that all acquired data havebeen separated into 10 various folds/sets, where each fold contains a set of cases43. Each and everyfold is then utilized once as a validation set whereas the remaining folds are utilized as training sets.This way each solution is validated 10 times with the same data, but with various combinations.The results from the validation can be found in section 10. Figure 9.0.2 presents how the 10-fold cross-validation method is realized. All the data utilized for the training and validation wasextracted from the simulation program.

Besides validating with 10-fold cross-validation the methods are also tested with actual datawhich is further explained in the subsections.

(a) The �gure depicts the realization of trainingfold 1 and validation fold 1

(b) The �gure depicts the realizationof training fold 2 and validation fold2

Figure 9.0.2: The �gures depicts the realization of 10-fold cross-validation. Each block/fold includesseveral sets of simulated data.

9.1 Loop For Transfer Function Based On One Case

The validation of the method which utilized a loop to �nd the direct- and indirect TF is slightlyaltered. The algorithm only selects the �rst case from the training folds and implements that casefor �nding the TF. The algorithm then validates this TF with all the cases from the validationfold. The reason for not creating a TF for each case and then validate upon all other cases is dueto time consumption. Generating a TF takes time and validating that TF is also time consuming,and therefore it was decided to only utilize one case from the training folds when training thealgorithm. This validation process indicates whether it is possible to �nd a TF that can estimateunknown scenarios based on one known scenario. to decide whether the TF is a success or not theMATLAB command compare is utilized. This command allows the user to enter the TF, the input,and the output and presents the user with a graph comparing the actual output and the estimatedoutput based on the TF. The command also generates a percentage �tness which indicates to whichdegree the estimated output correspond to the actual output. This �tness value is implemented

43Each fold contains AmountcasesAmountfolds

number of cases

43

Page 45: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

to calculate the Mean Absolute Error (MAE) in percentage for the method according to equation9.1.1.

E =

∑Nn |100− fitn|

N(9.1.1)

Where:E is the error in percentage which should be equal to 0 when the solution is a perfect �tN is the amount of validation casesn is a speci�c validation casefitn is the �tness, in percentage, of the estimated case which should be equal to 100 when thesolution is a perfect �t

It was deemed that the parameter extraction was not necessary for this solution due to theresult obtained when estimating the encounter spectrum did not pass a preferable threshold.

9.2 Optimize Transfer Function With Genetic Algorithm Based On One

Case

The validation method utilized for estimating the TF with GA and one case is exactly the same asfor the looping method. This method implements the same training case and compare commandas the loop method. This way the two solutions can be directly compared to each other to statewhether the GA improves the possibility of �nding a TF based on one case which can estimateseveral unknown cases. Just as for the loop based solution, this solution did not generate thenecessary result to implement the parameter extraction method.

9.3 Optimize Transfer Function With Genetic Algorithm Based On Sev-

eral Cases

The method which utilizes several cases along with GA to �nd an indirect TF di�er to the previouspresented solutions in terms of validation. Since this method implements several cases to �nd theTF it is possible to implement the 10-fold cross-validation as intended. One fold is chosen forvalidation whereas the remaining folds are utilized for the training. Since this method estimatesa TF, the MATLAB command compare is once again utilized to �nd the percentage �tness ofthe output obtained with the generated TF. Similarly to the previous mentioned solutions theMAE is thereafter computed based on the �tness level. Through this validation the solution canbe compared with the single case TF to state whether multiple known cases can improve theestimation. The result obtained for this method was deemed to have too large of an error toimplement the parameter extraction method.

9.4 Feedforward Neural Network

There are two types of FFNN implemented in this thesis, with RPROP and with GA, which bothhave the same validation process. Just as for the several cases TF the validation of the FFNNsdirectly implement the 10-fold cross-validation. 9 folds are implemented for training the FFNNwith either RPROP or GA and when the training is �nished the validation fold is implementedto estimate the outputs. to know whether the FFNN have performed well or not the estimatedoutputs are compared to the actual output, and the MAE in percentage is then computed for eachoutput of all the cases in the validation fold. An average of the MAE is then calculated for eachoutput of the fold so that the performance of each fold can be presented. The MAE is calculatedaccording to equation 9.4.1.

E = 100 ∗

∑Nn |1−

PnestPnact

|N

(9.4.1)

44

Page 46: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Where:E is the error in percentage which should be equal to 0 when the solution is a perfect �tN is the amount of validation casesn is a speci�c validation casePnest is the estimation of any of the parameters for validation case nPnact is the actual parameter which Pnest should be close to

9.5 Case Based Reasoning

There two various CBR implementations in this thesis, with Euclidean distance and with Manhat-tan distance, and the validation process of these two are exactly the same. The CBR di�er slightlyfrom the FFNNs in terms of validation. The CBR does not utilize the full capacity of training foldsfor training the weights with GA. The CBR utilize 8 folds as database during the training and 1fold as training data. Once the weights have been found the training fold is added to the databaseand the remaining 10:th fold is utilized for validating the CBR algorithm. If fold 1 is utilized asCBR validation fold then the proceeding fold is utilized as training fold of the GA. Figure 9.5.1depicts the correlation between CBR validation fold, GA training fold, and database folds.

(a) The �gure depicts which fold is utilized for whatwhen implementing fold 1 as validation set.

(b) The �gure depicts which fold is utilizedfor what when implementing fold 2 as val-idation set.

Figure 9.5.1: The �gures depicts the utilization of the various folds for training the weights of theCBR as well as validating the CBR. The training fold is added to the database when evaluatingthe CBR with the validation fold.

To know whether the CBR performs well or not each output from the cases of the validationset is compared to the target. The MAE in percentage is then computed and an average MAE isthen calculated for each output of each fold according to equation 9.4.1.

9.6 Simulated- And Logged Data

As stated in section 6.3, all the presented solutions is also tested with actual measured dataobtained from the cruise vessel M/S Mariella and compared to the actual waves measured duringthe voyage. The wave parameters was retrieved from a buoy in the Baltic Sea, located outsideStockholm archipelago, and was acquired from SMHI. Since the wave buoy is located on onelocation and the vessel sails across the ocean, meaning the vessel will only be near the buoy fora short time, it is expected that exact matches cannot be found. All the various con�gurationsof each solution is not tested, but instead only the con�guration which yielded the best result foreach solution is tested. For example if validation fold 1 generated the best TF for the loop solutionand validation fold 2 generated the best solution for the CBR with Euclidean distance, then fold1 is chosen as con�guration of the TF and fold 2 is chosen as con�guration for the CBR.

The logged data from the vessel was recovered from one complete voyage. The data is re-sampled, using the MATLAB command resample44, to �t the requested structure for the algo-

44The resample command is a MATLAB command capable of interpolating multiple points and re-sample theinterpolation to generate a new dataset with the requested sample period

45

Page 47: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

rithms. Since the voyage stretches over several hours it will generate multiple cases. The �rst caseobtained from the data log starts from time equal to 0 and is then sampled 101 times with sampletime 0.25. And the second case will have start time 0.25 and will thereafter be sampled in the sameorder. The main reason for letting the test cases overlap each other is to ensure that all possiblesample periods are tested for result.

The wave parameters obtained from SMHI is retrieved with a sample period of 30min. To �tthe data obtained from the vessel the wave data is interpolated and re-sampled, using MATLABcommand resample, with sample time 0.25. An average value for each parameter is then calculatedbased on the newly sampled data so that there is one value of each wave parameter(Hs, Tp, χ) foreach test case. The scope of the waves is represented by table 9.6.1 and �gures 9.6.1.

Lower Bound Upper Bound

Hs (m) 0 1.59

Tp (s) 0 6.10

χ (deg) 0 231.26

Table 9.6.1: The table presents the scope of the waves acting on vessel M/S Marielle

Figure 9.6.1: The �gures depicts the actual scope of the waves acting on vessel M/S Marielle.

The result obtained from all the TF based solutions was considered as not good enough toimplement the parameter extraction method.

46

Page 48: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

9.7 Logged Data Test

As stated in section 6.3, all the methods are trained and tested using only the actual data obtainedfrom the ship's log and SMHI. Three consecutive voyages have been logged of the M/S Mariella.The �rst two voyages is implemented for training the algorithms whereas the third voyage isimplemented for validation. As previously mentioned this validation is not based on n-fold cross-validation. Two whole voyages is implemented to generate the necessary training cases were eachcase is subsequent to the previous case, meaning there is no overlapping of cases as in the previousvalidation test. This decision was made due to time restriction of the thesis, meaning the trainingand validation time is reduced(less data for the voyages). This decision allows for the possibility oftesting all the algorithms with various training times. The methods are therefore trained during30min and 60min to conclude whether increasing the training time for the algorithms could generatea more promising solution. The result for these tests are presented in the form of a MAE measuredin percentage which represents the average estimation error throughout the whole voyage. The erroris calculated according to equation 9.1.1. The cases utilized are consecutive 25sec measurementsof the ship responses.

Just as for the previously tested TF based solutions, the result obtained when utilizing actualdata was deemed not good enough to implement the parameter extraction. It was therefore decidedthat the several cases based TF should be altered and retrained to see if more accurate result of theencounter spectrum could be acquired and the parameter extraction method could be tested. R.Pascoal et al. [14] concluded that it is possible to acquire an error of 6% for Hs using TF and GA,which means that the TF proposed in this thesis should be capable of providing accurate resultwhen estimating the encounter spectrum. It was thereby decided that the amount of parametersgenerated by the GA should be increased so that the TF would have the same amount of polesand zeros as the amount of input and outputs, which is 101. This resolved with the decision ofincreasing the sought for parameters to 40845. It was decided that the initial training time of 30minshould be kept. The result obtained after executing these changes was considered good enough totest the parameter extraction method.

45400 parameters yields 100 numerators and denominators, which therafter yields 99 poles and zeros. Whereas408 parameters yields 102 nominators/denominators and 101 poles and zeros

47

Page 49: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

10 Result

The following section presents the result obtained from the various implemented solutions basedon the validation process described in section 9. The result is demonstrated with graphs and tablesrepresenting the MAE.

10.1 Transfer Function Based On One Case

Figures 10.1.1 and 10.1.2 presents the result obtained from the modi�ed 10-fold cross-validation forthe estimation of TF using a loop and GA. The result found in �gures 10.1.1 and 10.1.2 have beenextracted and summarized in tables 10.1.1 and 10.1.2. The presented results within this sectionwas generated using the source code described in appendices E.4.1, E.4.2, and E.4.4.

(a) The �gure depicts the MAE result ob-tained for the direct problem

(b) The �gure depicts the MAE result ob-tained for the direct method when extract-ing the estimated rolling based on the es-timated motion spectrum.

(c) The �gure depicts the MAE result ob-tained for the indirect problem

Figure 10.1.1: The �gures presents the MAE, in percentage, obtained from the 10-fold cross-validation method for the loop and GA solutions which estimates a TF based on one case.

48

Page 50: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

(a) The �gure depicts a zoomed in versionof �gure 10.1.1a.

(b) The �gure depicts a zoomed in versionof �gure 10.1.1b.

(c) The �gure depicts a zoomed in versionof �gure 10.1.1c.

Figure 10.1.2: The �gures presents the percentage MAE obtained from the 10-fold cross-validationmethod for the loop and GA solutions which estimates a TF based on one case.

Fold Motion Spectrum RollingEncounterSpectrum

1 2.68e+ 7 2.95e+ 14 7.11e+ 3

2 8.21e+ 6 7.85e+ 13 4.54e+ 4

3 2.86e+ 6 9.40e+ 12 956.53

4 1.39e+ 9 7.64e+ 17 4.59e+ 5

5 1.31e+ 9 6.30e+ 17 5.46e+ 4

6 4.83e+ 9 1.84e+ 19 5.20e+ 5

7 1.85e+ 7 3.35e+ 14 824.87

8 3.54e+ 7 3.55e+ 14 4.96e+ 3

9 7.40e+ 6 6.37e+ 13 708.08

10 1.23e+ 9 7.25e+ 17 6.40e+ 4

Average 8.85e+ 8 2.06e+ 18 1.16e+ 5

Table 10.1.1: The table presents the average MAE, in percentage, obtained from the 1 exampleTF, based on looping, for each fold

49

Page 51: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Fold Motion Spectrum RollingEncounterSpectrum

1 239.94 2.11e+ 4 108.57

2 233.81 5.60e+ 4 464.06

3 346.42 2.41e+ 5 279.42

4 445.73 1.00e+ 5 1.15e+ 3

5 1.97e+ 3 1.95e+ 6 100.14

6 186.14 1.77e+ 4 2.62e+ 3

7 474.00 4.60e+ 5 337.84

8 211.62 1.83e+ 4 500.82

9 427.13 1.20e+ 5 108.93

10 150.09 1.59e+ 5 81.90

Average 468.10 3.01e+ 5 574.88

Table 10.1.2: The table presents the average MAE, in percentage, obtained from the 1 exampleTF, based on GA, for each fold

50

Page 52: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

10.2 Transfer Function Based On Several Cases

Figure 10.2.1 presents the result obtained from the 10-fold cross-validation of the TF based onseveral cases. This result is also presented in table 10.2.1. The presented results within thissection was generated using the source code described in appendices E.4.5 and E.4.6.

Figure 10.2.1: The �gure depicts the result obtained from the validation of the several cases basedTF using 10-fold cross-validation.

FoldEncounterSpectrum

1 1.73e+ 3

2 2.36e+ 3

3 3.67e+ 3

4 3.66e+ 3

5 2.82e+ 3

6 2.84e+ 3

7 4.77e+ 3

8 2.95e+ 3

9 1.80e+ 3

10 1.24e+ 3

Average 2.88e+ 3

Table 10.2.1: The table presents the average MAE, in percentage, for each fold of the TF basedon GA and several examples

51

Page 53: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

10.3 Feedforward Neural Network And Case-Based Reasoning

Figures 10.3.1 presents the result obtained from the 10-fold cross-validation of the implementedFFNN and CBR algorithms. The result found in the �gures have also been compiled into tables10.3.1, 10.3.2,10.3.3, and 10.3.4. The presented results within this section was generated using thesource code described in appendices E.5.1, E.5.2, E.6.1, E.6.3, and E.7.

(a) The �gure depicts the MAE, in per-centage, result obtained from the 10-foldcross-validation of estimating Hs usingFFNN and CBR.

(b) The �gure depicts the MAE, in per-centage, result obtained from the 10-foldcross-validation of estimating Tp usingFFNN and CBR.

(c) The �gure depicts the MAE, in percent-age, result obtained from the 10-fold cross-validation of estimating χ using FFNN andCBR.

Figure 10.3.1: The �gures presents the MAE, in percentage, obtained from the 10-fold cross-validation method for the FFNN and CBR algorithms.

Fold Hs Tp χ

1 43.70 20.13 86.18

2 42.11 21.43 91.83

3 42.77 21.28 88.85

4 42.38 21.79 89.79

5 45.16 22.70 91.00

6 40.17 21.11 74.77

7 42.15 22.09 79.61

8 42.84 23.16 83.75

9 43.87 21.36 95.94

10 42.81 21.19 80.46

Average 42.79 21.62 86.22

Table 10.3.1: The table presents the average MAE, in percentage, for each fold obtained from theFFNN based on RPROP.

52

Page 54: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Fold Hs Tp χ

1 53.65 47.32 78.17

2 51.75 38.92 69.25

3 50.74 40.03 70.47

4 54.19 39.60 71.99

5 48.08 43.18 80.66

6 47.17 43.99 68.65

7 45.45 39.82 72.87

8 47.56 38.06 69.03

9 45.46 38.45 78.31

10 49.66 40.18 70.09

Average 49.37 40.95 72.95

Table 10.3.2: The table presents the average MAE, in percentage, for each fold obtained from theFFNN based on GA.

Fold Hs Tp χ

1 37.58 24.66 87.15

2 36.16 23.79 91.98

3 35.96 23.05 80.51

4 36.83 24.69 93.88

5 39.45 24.90 97.20

6 35.41 24.74 81.81

7 34.88 24.54 86.88

8 35.86 24.89 79.52

9 37.19 25.30 102.30

10 36.17 24.11 73.08

Average 36.55 24.47 87.43

Table 10.3.3: The table presents the average MAE, in percentage, for each fold obtained from theCBR based on Euclidean distance.

Fold Hs Tp χ

1 38.61 23.93 82.46

2 38.51 22.62 88.06

3 36.15 22.54 84.92

4 38.12 23.93 87.25

5 40.90 24.09 91.89

6 37.51 23.29 78.50

7 35.49 23.48 83.47

8 37.30 23.70 81.38

9 39.15 24.16 99.40

10 37.00 23.14 72.70

Average 37.87 23.49 85.00

Table 10.3.4: The table presents the average MAE, in percentage, for each fold obtained from theCBR based on Manhattan distance.

53

Page 55: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

10.4 Parameter Accuracy

The result presented in [13] indicates that it was harder to estimate smaller waves then largerwaves due to the ship acting as a �lter upon the smaller waves. Based on this the average MAE, inpercentage, for the various con�gurations of the parameters is presented in tables10.4.1,10.4.2,and10.4.3. The results presented in this section was generated using the source code presented inappendix E.7.

Hs (m) FFNN RPROP FFNN GA CBR Euclidian CBR Manhattan

1 113.89 57.22 82.03 88.37

2 33.24 34.83 35.84 35.86

3 21.56 47.92 23.72 23.18

4 19.73 54.51 18.30 18.59

5 25.65 59.57 22.85 23.34

Table 10.4.1: The table presents the average MAE, in percentage, of all folds based on the variousHs con�gurations.

Tp (m) FFNN RPROP FFNN GA CBR Euclidian CBR Manhattan

2 52.17 43.69 55.06 50.30

3 17.50 20.73 21.63 20.46

4 23.11 30.70 21.58 21.29

5 21.35 40.24 20.69 21.04

6 14.39 47.89 19.53 19.33

7 10.39 53.22 17.68 17.79

8 12.47 56.42 15.06 14.22

Table 10.4.2: The table presents the average MAE, in percentage, of all folds based on the variousTp con�gurations.

54

Page 56: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

χ (m) FFNN RPROP FFNN GA CBR Euclidian CBR Manhattan

20 676.46 292.32 667.43 661.76

40 265.85 154.30 301.57 291.39

60 140.77 94.39 124.48 123.56

80 82.35 84.51 70.49 66.37

100 65.61 48.06 63.10 58.97

120 45.16 53.54 34.07 31.74

140 31.85 40.39 25.21 24.67

160 18.56 37.21 14.85 15.59

180 21.74 59.78 18.30 18.24

200 11.36 51.87 15.02 15.56

220 17.56 51.48 20.26 19.93

240 21.51 55.14 25.49 24.51

260 21.57 63.08 29.06 23.95

280 23.94 69.09 29.85 26.71

300 24.87 78.91 29.19 27.44

320 28.46 84.19 38.00 35.73

340 35.09 81.59 44.67 41.70

360 29.52 79.75 19.41 20.67

Table 10.4.3: The table presents the average MAE, in percentage, of all folds based on the variousχ con�gurations.

55

Page 57: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

10.5 Simulated- And Logged Data

The following subsection presents the results obtained from the testing of the algorithms usingdata from an actual ship and wave buoy. Table 10.5.1 presents the MAE, in percentage, of theencounter spectrum estimation obtained from the TF solutions, as well as the fold con�gurationutilized when testing. And table 10.5.2 presents the MAE, in percentage, for the Hs, TP , and χestimations. The results presented in this section was generated using the source code presentedin appendix E.8.1 and E.8.2.

Loop with 1example

GA with 1 exampleGA with Several

examples

Fold utilized 7 10 1

MAE (%) 292.28 55.59 930.24

Table 10.5.1: The table presents the MAE in percentage for the encounter spectrum estimationwith the testing data obtained from an actual ship. The table also speci�es which con�gurationwas utilized for retrieving the data based on the validation fold.

FFNN RPROP FFNN GA CBR Euclidean CBR Manhattan

Fold utilized 6 8 3 3

Hs MAE (%) 243.77 151.72 252.61 238.99

Tp MAE (%) 23.32 46.61 18.41 16.41

χ MAE (%) 45.06 45.02 41.34 33.07

Table 10.5.2: The table presents the MAE in percentage for the Hs, Tp, and χ estimation withthe testing data obtained from an actual ship. The table also speci�es which con�guration wasutilized for retrieving the data based on the validation fold.

56

Page 58: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

10.6 Logged Data Test

The following subsection presents the results obtained when training the methods with two consec-tutive monitored voyages and testing them with a third consectutive voyage. Table 10.6.1 presentsthe MAE of the TFs based solutions trained for 30 minutes and tables 10.6.2, 10.6.3, and 10.6.4presents the MAE result obtained for the pure AI based solutions trained for 30min. Whereastables 10.6.5, 10.6.6, 10.6.7, and 10.6.8 presents the respective result when the algorithms havebeen trained for 60min. Tables 10.6.1 and 10.6.5 was generated using the source code presented inappendices E.9.1, E.9.2, and E.9.3. And tables 10.6.2, 10.6.3, 10.6.4, 10.6.6, 10.6.7, and 10.6.8 wasgenerated using the source code presented in appendices E.10.1, E.10.2, E.11.1, and E.11.2. Thesepresented source codes is presented with the con�guration of 30min runtime. But the exact samecode was implemented, with the di�erence of re-assigning the time dependent variable, to generatethe 60min result as well. Lastly the result presented in �gure 10.6.1 was obtained using the sourcecode presented in appendix E.12.1 and thereafter the result presented in table 10.6.9 was acquiredby implementing the source code presented in appendix E.12.2.

Encounter Spectrum ResultLoop 1 training

exampleGA 1 Training

ExampleGA Several

Training Examples

MAE (%) 137.37 96.53 10462.30

Table 10.6.1: The table depicts the Encounter Spectrum result obtained from the training(30min)and testing with only logged data

Hs Result FFNN RPROP FFNN GACBR Euclidian

DistanceCBR Euclidian

Distance

MAE (%) 27.81 38.05 42.99 43.89

Table 10.6.2: The table depicts the Hs result obtained from the training(30min) and testing withonly logged data

Tp Result FFNN RPROP FFNN GACBR Euclidian

DistanceCBR Euclidian

Distance

MAE (%) 46.36 38.05 39.35 35.23

Table 10.6.3: The table depicts the Tp result obtained from the training(30min) and testing withonly logged data

57

Page 59: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

χ Result FFNN RPROP FFNN GACBR Euclidian

DistanceCBR Euclidian

Distance

MAE (%) 36.18 38.04 34.36 38.90

Table 10.6.4: The table depicts the χ result obtained from the training(30min) and testing withonly logged data

Encounter Spectrum ResultLoop 1 training

exampleGA 1 Training

ExampleGA Several

Training Examples

MAE (%) 178.16 125.99 10635.74

Table 10.6.5: The table depicts the Encounter Spectrum result obtained from the training(60min)and testing with only logged data

Hs Result FFNN RPROP FFNN GACBR Euclidian

DistanceCBR Euclidian

Distance

MAE (%) 26.15 51.66 43.07 43.63

Table 10.6.6: The table depicts the Hs result obtained from the training(60min) and testing withonly logged data

Tp Result FFNN RPROP FFNN GACBR Euclidian

DistanceCBR Euclidian

Distance

MAE (%) 51.51 51.66 38.26 35.23

Table 10.6.7: The table depicts the Tp result obtained from the training(60min) and testing withonly logged data

χ Result FFNN RPROP FFNN GACBR Euclidian

DistanceCBR Euclidian

Distance

MAE (%) 39.27 51.66 34.79 38.59

Table 10.6.8: The table depicts the χ result obtained from the training(60min) and testing withonly logged data

Hs Tp χ

MAE (%) 18.81 1.22 27.91

Table 10.6.9: The table presents the MAE in percentage when estimating Hs, Tp, and χ with GAafter implementing the encounter spectrum estimation.

58

Page 60: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Figure 10.6.1: The �gure depicts the �tness of the encounter spectrum estimation based on the30min training of TF with 408 parameters. Each integer along the x-axis represents a 25sec longmonitored period were the encounter spectrum have been estimated.

59

Page 61: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

11 Conclusion

This section presents the conclusions of this paper based on similar research, implemented solutions,and the result obtained and presented. This includes statements of how the result found in section10 is assessed, statements to whether the hypothesizes have been proved or disproved, and answersto the research questions stated in the beginning of the thesis.

11.1 Simulation Based Training And Validation

The following sections covers the conclusions based of the results obtained from validating withsimulated data.

11.1.1 Looping For Transfer Function

As seen in �gures 10.1.1 and table 10.1.1 the looping method have failed to �nd a prominentsolution. This can however be explained in two ways; (1) The TF have been given just onetraining example for each fold which means that the TF would possibly be capable of �nding agood �t for extremely similar cases whereas non-trained cases would de�nitely generate errors, (2)since the method have looped and tested various setups for the TF the scope for the parametersde�ning the TF have been limited and will thereby limit the achievable results.

11.1.2 Genetic Algorithm Based Transfer Function Using 1 Example

As seen in �gures 10.1.1 and table 10.1.2 the GA based method using 1 example performs betterthan the looping method. This is to be expected since the second complication of the loopingmethod have been corrected. The GA algorithm broadens the scope of combinations for theparameters that de�nes the TF, which means that improved result should be possible. However,although better than previous result the performance is still considered poor. The solution stillsu�ers from the �rst complication highlighted for the looping method.

It can be observed that the estimation of the encounter spectrum succeeds better then theestimation of motion spectrum. There is a simple explanation to this extreme di�erence in per-formance. The GA for the motion spectrum implements the compare command for the �tnessfunction, which is time consuming, while the encounter spectrum implements simple MSE whichis much more time e�cient. Since the GA was time restricted, the motion spectrum were not ableto generate the same amount of generations as the GA for the encounter spectrum. This resultwith worse performance for the direct solution when compared to the indirect solution.

11.1.3 Genetic Algorithm Based Transfer Function Using Several Examples

As seen in �gure 10.2.1 and table 10.2.1 the GA based TF utilizing several examples performs betterthan the loop method but not better than the single case GA based TF. It was expected that thissolution should perform better than both the previous solutions. However, since the several casebased TF implements multiple cases for training it is not capable of generating the same amount ofgenerations as the single case TF when utilizing a time-based GA. It would therefore be possibleto �nd much better results if the GA were to be iteration-based instead of time-based.

11.1.4 Feedforward Neural Network Using Resilient Backpropagation

As seen in �gures 10.3.1 and table 10.3.1 the FFNN using RPROP is capable of achieving veryconsistent result no matter which cases were implemented for training or validation. The networkachieves an average percentage error of 42.79% for Hs, 21.62% for Tp, and 86.22% for χ. Based onthese results it can be stated that the network have been capable of �nding a connection betweenthe inputs and output Tp. It can also be observed that the network appears to have �nd someconnection between the inputs and output Hs although not as good as Tp. For χ the network havefailed to �nd accurate results.

60

Page 62: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

11.1.5 Feedforward Neural Network Using Genetic Algorithm

As seen in �gures 10.3.1 and table 10.3.2, the GA based FFNN performs worse then the RPROPbased algorithm for 2/3 parameters. Even though the χ estimation is better than the RPROP,it is not enough to outbalance the Hs and Tp estimations. Since the GA initializes weights forthe network at random it is possible for the GA to �nd the same con�guration as the RPROP.Based on this it is probable that the GA were not given su�cient time for generating weights or,the GA have over�tted the network so that the network have only found solutions to the trainedcases. Whether the GA would be capable of �nding a better solution then the RPROP for thisparticular problem cannot be stated without increasing the training time. However, both RPROPand GA were given the same amount of training time and it can thereby be stated that the GAFFNN performs worse than the RPROP FFNN when less training time is requested.

11.1.6 Case-Based Reasoning Using Euclidean Distance

As seen in �gures 10.3.1 and table 10.3.3, the CBR with Euclidean distance estimates Hs betterthan the FFNN for each fold. An the average MAE for Tp is almost as good as the RPROPestimation of Tp. However, for 7/10 folds the Euclidean based CBR obtained the worst estimationof χ. This is an indication of the chosen input features are not enough to conclude all the parametersof the waves.

11.1.7 Case-Based Reasoning Using Manhattan Distance

Figures 10.3.1 indicates that the CBR with Manhattan distance performs better than the Euclideanbased CBR for 2/3 parameters and almost as good for the third parameter. In general it appearsthat the Manhattan based CBR is the most stable algorithm since it never yields the worst resultand only performs slightly less accurate than the best solution(dependent on the parameter).

11.1.8 General Conclusion Of All Methods

It can be observed that none of the methods show signi�cant better result than the others. Thismeans that either the inputs are not optimal for estimating the waves, the methods are not optimalfor the problem, increased training time is needed, the methods have been over-trained and therebyfailed to learn,or there is to much data with to much variety to �nd a solution. Either way thebest solution cannot be decided based on the validation with simulated data.

It can be seen that according to table 10.4.1 the algorithms performs better at rougher seasthan calmer. This strengthens statements made by Wei Zeng et al. [13] that calmer seas will alwaysbe tougher to estimate due to the �lter resemblance of a ship. It can also be seen in table 10.4.2and 10.4.3 that there are certain periods and angles which signi�cantly aggravates the estimations.But there are in fact, for example, certain angles which the algorithms have done quite well whenestimating. For example for following waves46 (160 -180)◦ the error is quite low for all of thealgorithms. This can be explained by R. Pascoal et al. [14] who stated that due to the ship'shull not being spherical like a wave buoy, various waves will impact the ship di�erently. This onceagain demonstrates that a marine vessel can be seen as a �lter. Certain encounter angles will haveless impact on the ship due to the shape of the hull, and therefore be tougher to estimate.

11.2 Simulation Based Training And Validation With Logged Data

This section covers the result from the testing of algorithms with actual data, while trained usingsimulated data. Good results from this test would mean that the algorithms could be trainedwith simulated data and then be implemented in actual scenarios, which would be preferred dueto almost all possible scenarios could then be included within the algorithm. However, as seen intable 10.5.1 and 10.5.2 the results are not optimal. The loop based TF and several cases basedTF have utterly failed to estimate correct waves, and although the single cased GA based TF havean accuracy of 55% it is not considered good enough due the extended method needed to �nd theparameters would generate faulty parameters based on this. However, it can be observed that the

46Following waves are waves which travel in the direction as the vessel itself.

61

Page 63: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

AI based solution have found Tp and χ with an error below 50%. All four solutions have therebyachieved better result for the χ estimation then in the validation with simulated data, and theCBR methods have achieved better estimation of Tp as well when compared with the validationwith simulated data. However, all four algorithms have failed with estimating Hs which is highlyimportant since it is the utilized parameter for specifying the state of the sea (see Douglas scale8.1.2).

In conclusion although some result were better for the test than for the validation the algorithmshave failed to �nd a solution for the real scenarios based on simulated data.

11.3 Logged Data For Training And Testing

By observing tables 10.6.1, 10.6.2, 10.6.3, 10.6.4,10.6.5, 10.6.6, 10.6.7, and 10.6.8 it is noticedthat approximately the same result is obtained when basing the algorithms on actual data as theresult obtained when based on simulated data. This is shows that the simulation program is validto utilize when structuring a solution, meaning a database of actual scenarios is not necessarilyneeded until it is time to implement the algorithms on an actual ship. It is also observed that theresult is not necessarily improved through an increased training time, for example the several casesbased TF and FFNN with GA have yielded worse results when trained longer. This bears the ofconclusion that increasing the training time further yields over�tting.

However, �gure 10.6.1 con�rms that creating a TF which estimates the encounter spectrumbased on solely the rolling of the ship, as seen in �gure 8.2.1, is possible. Since the 30- and 60 mintraining of the TF yielded no prominent result it can be concluded that there were not enoughpoles and zeros within the TF to �nd a general solution. In table 10.6.9 it can be observed thatextracting the parameters, from the encounter spectrum estimated with TF, using GA actuallyperforms better than the other algorithms. The Tp estimation have almost succeeded completely.This is however based on that the encounter angle is known to be on either port or starboardside of the vessel. If this is not known then the parameter prediction would be worse. By furthercomparing encounter spectrum generated by the TF and the encounter spectrum generated by theGA predicted parameters, it is found that they are an almost perfect �t. This means that acquiringall three parameters from solely the rolling of the ship cannot be done.

11.4 Final Conclusion

This thesis have proposed multiple solutions for the inverse problem of de�ning the ocean waveswhich have generated the known ship responses. It have been concluded that the data acquired fromthe simulation program can be utilized to structure, train, and validate a solution for the problem.The solution trained and estimated with simulated data and tests con�rmed that simulated basedsolutions might not be compatible with actual scenarios. It is therefore recommended that oncea possible solution have been found and tested using simulated data, it should be retrained withactual data.

By observing the Motion Spectrum- and Rolling columns in table 10.1.1 and 10.1.2 the poorresult within this thesis can be understood. The solution which yielded these result were intendedto serve as examples for the complexity of the RAO TFs. These TF generated almost perfect�tness for the cases implemented in the training, but for the validation cases it can be observedthat the TF utterly failed. This shows that replacing the RAO with a simpli�ed solution is not aneasy task, which means that creating an inverse solution based on this is extremely hard.

None of the suggested solutions within this thesis have managed to acquire better results thanthe 6% Hs error presented by R. Pascoal et al. [14]. Although the �nal attempt of creating a TFyielded highly accurate results of the encounter spectrum and 1.2 % error for Tp.

Based on the results obtained from the AI based solutions it is concluded that the features roll-,pitch-, and rudder angles does not yield the necessary information needed to specify the waves.

62

Page 64: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

11.5 Veri�cation Of Hypothesis

The following section states whether the hypothesizes presented in section 1.5 have been veri�edthroughout this report.

H1: If the motion of a marine vessel in the sea and the dynamics of the vessel's control systemis known, then the behavior of the sea waves around the vessel and their wave spectrum can befound using inverse methods.The information presented in section 2 has shown that the waves can be represented by the wavespectrum and this will in return be used for controlling the motion of the ship. Since this is a directapproach of estimating an output based on the input it should be possible to do the opposite. Asseen in �gure 10.6.1 it is possible to create TF which estimates the encounter spectrum with highaccuracy, and since the encounter spectrum includes all the information needed for de�ning thewaves it can be stated that the waves can be found using inverse methods.

H2: One suitable method is Arti�cial Intelligence.Based on the training and testing with actual data an accuracy of [28 46] % error can be acquiredusing two similar voyages for training. It is therefore possible to implement AI for this problembut with the proposed structures and given results it is not suitable to implement the proposedAIs within this thesis. The most bene�cial solution is so the proposed solution by R. Pascoal et al.[14] of estimating the parameters which would lead to the same motion spectrum as the observedspectrum.

It can be stated that H1 have been supported and veri�ed using TF, while H2 is unsupported.However there are multiple con�gurations and methods to try which could to improve the result.H2 is therefore neither proven true or false.

11.6 Research Questions Answered

The following section states the answers to the research questions presented in section 3.2, basedon the work found in this thesis.

Set 1

• Will changes of the wave spectrum result with changes of the rolling?

Yes. As shown in section 2.1 the waves a�ect the rolling of a ship and since the waves can bedescribed by the wave spectrum, seen in section 2.2, it is safe to say that changes of the wavespectrum will result with changes of the rolling. An relation between the wave spectrum and therolling spectrum have been established using TF within this thesis, which proves that the wavespectrum and the rolling correlate.

Set 2

• What alternative methods could be used for solving this problem?

Other than the proposed and implemented solutions in this thesis one could implement an on-board Doppler radar such as in [11]. However, implementing such a system is far more costly thanthe systems proposed in this thesis where the data utilized is already monitored and found withinthe ship's logging. Another alternative system could be the one proposed in [12]. This system isbased on an ANN that takes the previous measured parameters of the waves and estimates thefuture expected parameters. Such a system could utilize data extracted from organizations whenan internet connection is established. If a connection is not established then the system couldutilize its predicted parameters for the next prediction.

Neither of these systems utilize the responses of the ship but they have been proven to beaccurate systems for measuring- and estimating the state of the sea.

63

Page 65: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

• What method would be most bene�cial when estimating the wave spectrum?

Based on the result obtained from this thesis the best approach would be to implement the solu-tion presented by R. Pascoal et al. [14],which was a GA based method that estimated the waveparameters which generated the monitored motions of the vessel.

• What level of accuracy can be obtained when estimating the wave spectrum with AI?

The accuracy can vary between solutions, but the actual cases based AI(30 min trained) were ableto obtain an MAE within the interval of [28 46]% and the TF with parameter extraction had aworst average error of 28%. If only the encounter spectrum is sought for then a TF can be createdwhich achieves an accuracy of almost 0% error.

• Would the knowledge of the ship's movement and dynamics of the control system be su�cientfor estimating wave direction as well?

Speci�c results such as the CBR with Euclidean distance result seen in �gures 10.3.1a, 10.3.1b,and 10.3.1c indicate that it is hard to estimate all three parameters based on the roll-, pitch-,and rudder angles. And extracting χ from the encounter spectrum gives 50% chance of obtainingthe correct value. In conclusion no, neither of the solutions presented within this thesis have beencapable of de�ning the encounter angle when considering that the waves can attack from any angle.However, R. Pascoal et al. [14] where capable of constructing a solution which estimated χ as well.It can therefore be speculated that it is possible but the chosen responses within this thesis wasinsu�cient.

12 Future Work

This section covers the future work for this thesis, which includes methods not implemented,improvements of implemented solution, and general thoughts and ideas to what more can be doneto solve the problem at hand.

12.1 Not Implemented

A proposed method which was never implemented due to time-limitation was the ANFIS algorithm.Since the FFNN have proven to be capable of producing close result, but not acceptable enough,it would be of interest to implement a more advanced ANN such as the ANFIS algorithm. Dueto this problem having no existing solution, the testing and validation of various methods is �rstpriority.

It was early proposed from the company that a vision based system would be of interest forsolving this problem. Similarly to the Doppler radar approach [11], a camera/cameras could bemounted on the ship or on an autonomous quadrocopter to retrieve image/videos of the ocean.A deep-learning network could thereafter be implemented along with feature detection algorithmsto estimate the behavior of the waves. This solution was never implemented for this thesis sinceit should �rst be evaluated if the problem can be solved solely by implementing already knowninformation and simple methods. Also, the proposed solution demands a database of wave imageswere the wave parameters are known, which will take a lot of time to extract. The vision basedsolution could however be a topic for a future thesis.

12.2 Improvements

In similar works it have been stated that combining the heave information of the ship along withthe roll and pitch would be enough information to de�ne the wave parameters. So combining thiswith the rudder information could prove to yield much better result. A second parameter whichcould make a di�erence is the wind speed and wind direction. Waves are mostly generated basedon the wind, so, if knowledge about the wind can be extracted then the wave estimation might bebetter. Neither the wind nor heave was implemented in this thesis. The reason for this was dueto time-limitations for learning how to con�gure the ship simulator so that this information couldbe extracted.

64

Page 66: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

In this thesis the data implemented for training and validation was stripped down to a 25secperiod with sample time of 0.25sec. This implementation eased the possibility of obtaining quickmoderate results and reduced the training time of all algorithms. However, there is a risk of havinga too narrowed scope so that there is not enough samples to conclude the wave parameters. Itwould thereby be of interest to increase the period for the data, meaning increase the amount ofsamples used, and allow the algorithms to train onto these for a vastly larger duration.

The CBR methods can be improved to store new solutions on the go, meaning once the CBRhave found a new solution it can add that solution to the database. The CBR could even bedeveloped to replace the estimated data with actual data retrieved from a wave buoy over time.Meaning once the algorithm have estimated the wave parameters it temporarily stores them. Andwhen the parameters is obtained from the organizations, for that speci�c location, the algorithmcan replace the estimated parameters with the actual ones. The algorithm would then estimatethe current waves acting on a ship, which have not yet been measured by the organizations, butthen only save the parameters from the organizations. It would be possible to separate the CBRinto three separate algorithms which individually identify one of the wave parameters based onseparated inputs for the similarity measurement. For example based on the result in this reportthe rolling, pitch, and rudder appears to be su�cient information for �nding Tp. Other parametersmight prove more useful for identifying Hs and χ. Identifying these and separate the CBR intothree separated algorithms would thereby be of interest.

Another con�guration of the CBR algorithm which could be tested would be to utilize spectruminformation instead of the amplitudes of the measured angles. Since the current CBR comparesthe angle, for example the rolling, at each time-step and compares it to the same time-step for allthe cases in the database this might result with wrong cases being picked from the database. Theremight be certain cases within the database which have similar rolling but is phase shifted. Thismeans that the current CBR will not consider the case to be as similar as it actually is. Replacingthe time based inputs with spectrum based input could thereby yield more prominent result.

12.3 General Thoughts

The generated data for this thesis was based on one speci�c kind of wave spectrum. Testing thealgorithms with waves based on other spectra would prove whether the algorithm is capable ofde�ning the parameters without regards to the spectrum.

Once an accurate solution have been found using the simulated and logged data then thealgorithm should be tested on-board an actual ship during the voyage to see whether the algorithmscan estimate correct parameters.

All AI utilized raw data within this thesis, it would therefor be interesting to convert or �lterthis data to utilize a simpler representation of the data for the algorithms. For example utilizingmotion spectrum or mean rolling amplitude could yield better results.

According to J. G. Kusters et al. [11] it was important to include the characteristics of the shipin their system. This means that the proposed solutions presented in this thesis could be restrictedfor the particular ship utilized in the training. This could explain the large error obtained for Hs

when testing the simulation based solutions with actual data. Therefore a �nalized solution needsto be tested for other ships than he ship utilized for training.

The method which is considered the best is the TF implementation, but this implementationsu�ers from the possibility of �nding false parameters which yields the same type of of encounterspectrum. R. Pascoal et al. [14] have however proven that by introducing more TFs which takeother DOF in consideration can reduce this error. It could therefore be of interest to generateseveral TFs which estimates other encounter spectra based on the other wave spectra. This couldreduce the amount of possible parameters.

65

Page 67: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

13 Acknowledgments

The author would �rst and most thank his �ancée for her support, encouragement, and her enduringof listening everyday to the latest �ndings in on-line wave estimation. The author would also liketo thank his family for their support along the thesis. The author would like to give special thanksto his supervisors at Q-TAGG, especially George Fodor, for without them the knowledge aboutwaves and marine industry would have taken much longer to understand. The author would alsolike to thank his supervisor at school for his inputs concerning the methods implemented. Not toforget, a big thanks to all at Q-TAGG for their support and their consent of allowing the authorto conduct this research at their premises. Lastly thank you for reading my thesis.

66

Page 68: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

References

[1] N. N. Taleb, The black swan: The impact of the highly improbable. Random house, 2007,vol. 2.

[2] T. Perez, Ship Motion Control: Course Keeping and Roll Stabilisation Using Rudder and Fins,1st ed. Springer Publishing Company, Incorporated, 2010.

[3] J. Journée, �Theoretical manual of seaway,� Delft University of Technology Shiphy-dromechanics Laboratory,(Release 4.19, 12-02-2001), http://www. shipmotions.nl/DUT/PapersReports/1370-StripTheory-03. pdf, 2001.

[4] O. Faltinsen, Sea loads on ships and o�shore structures. Cambridge university press, 1993,vol. 1.

[5] L. Bergdahl, �Wave-induced loads and ship motions,� Chalmers University of Technology,Tech. Rep., 2009.

[6] L. Borgman and E. Yfantis, �Measurement of directional ocean wave spectra from �xed plat-forms,� in OCEANS '78, Sept 1978, pp. 634�638.

[7] E. M. Lewandowski, The dynamics of marine craft: maneuvering and seakeeping. Worldscienti�c, 2004, vol. 22.

[8] X. Jing-bo, B. Xin-qian, and F. Ming-yu, �Simulation and spectral estimation of sea wave basedon shaping �lter,� in Proceedings of 2011 6th International Forum on Strategic Technology,vol. 2, Aug 2011, pp. 1243�1246.

[9] T. Perez and M. Blanke, �Simulation of ship motion in seaway,� Department of Electrical andComputer Engineering, The University of Newcastle, Australia, Tech. Rep. EE02037, 2002.

[10] P. S. Tambade, �Harmonic oscillator wave functions and probability density plots using spread-sheets,� Latin-American Journal of Physics Education, vol. 5, no. 1, p. 7, 2011.

[11] J. G. Kusters, K. L. Cockrell, B. S. H. Connell, J. P. Rudzinsky, and V. J. Vinciullo, �Future-waves #x2122;: A real-time ship motion forecasting system employing advanced wave-sensingradar,� in OCEANS 2016 MTS/IEEE Monterey, Sept 2016, pp. 1�9.

[12] A. N. Deshmukh, M. C. Deo, P. K. Bhaskaran, T. M. B. Nair, and K. G. Sandhya, �Neural-network-based data assimilation to improve numerical ocean wave forecast,� IEEE Journal ofOceanic Engineering, vol. 41, no. 4, pp. 944�953, Oct 2016.

[13] W. Zeng, H. Zhu, L. Hui, Z. Wang, and X. Ran, �Improved parametric method applied towave estimation based on ship motion responses,� in 2015 Sixth International Conference onIntelligent Control and Information Processing (ICICIP), Nov 2015, pp. 42�46.

[14] R. Pascoal, C. G. Soares, and A. Sørensen, �Ocean wave spectral estimation using vessel wavefrequency motions,� Journal of O�shore Mechanics and Arctic Engineering, vol. 129, no. 2,pp. 90�96, 2007.

[15] F. Calafat, P. Cipollini, J. Bou�ard, H. Snaith, and P. Féménias, �Evaluation of new cryosat-2products over the ocean,� Remote Sensing of Environment, vol. 191, pp. 131�144, 2017.

[16] S. Subbaraya, A. Breitenmoser, A. Molchanov, J. Muller, C. Oberg, D. A. Caron, and G. S.Sukhatme, �Circling the seas: Design of lagrangian drifters for ocean monitoring,� IEEERobotics Automation Magazine, vol. 23, no. 4, pp. 42�53, Dec 2016.

[17] M. C. Marimon, G. Tangonan, N. J. Libatique, and K. Sugimoto, �Development and evaluationof wave sensor nodes for ocean wave monitoring,� IEEE Systems Journal, vol. 9, no. 1, pp.292�302, March 2015.

67

Page 69: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

[18] M. Valcic, R. Antonic, and V. Tomas, �An�s based model for ship speed prediction,�Shipbuilding, vol. 62, no. 4, pp. 373�382, 2011. [Online]. Available: http://hrcak.srce.hr/75675?lang=en

[19] D. J. Montana and L. Davis, �Training feedforward neural networks using genetic algorithms.�in IJCAI, vol. 89, 1989, pp. 762�767.

[20] M. Riedmiller and H. Braun, �A direct adaptive method for faster backpropagation learning:the rprop algorithm,� in IEEE International Conference on Neural Networks, 1993, pp. 586�591 vol.1.

68

Page 70: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Appendix A Models

Figure A.0.1: The �gure depicts a model the direct way for maneuvering a ship based on waves.The behavior of the waves are obtained from reports and then utilized directly to estimate themovement of a ship, while the control system adjust certain parameters to reduce fuel consumptionand rolling.

Figure A.0.2: The �gure depicts an alternative model of maneuvering a ship in waves. Here aninverse method is utilized to retrieve the behaviour of waves. This is an indirect method sincethe output of the model is utilized for retrieving the input parameter called waves. Once theparameter waves have been found indirectly it is possible to use the direct method to estimatewhat the movement of the ship will become based on the rest of the inputs.

69

Page 71: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Appendix B Abbreviations And Nomenclature

AI Arti�cial Intelligence

ANFIS Adaptive Neuro Fuzzy InferenceSystem

ANN Arti�cial Neural Network

BP Backpropagation

CB Center of Buoyancy

CBR Case Based Reasoning

CDIP Coastal Data InformationProgram

CEO Chief Executive O�cer

CG Center of Gravity

DOF Degrees of Freedom

FFBP Feedforward Backpropagation

FFGA Feedforward Genetic Algorithm

FFNN Feedforward Neural Network

FFT Fast Fourier Transform

FRAO Force Response AmplitudeOperator

GA Genetic Algorithm

GD Gradiant Descent

GM Metacentric Height

HTC Hight Tech Computers

IFFT Inverse Fast Fourier Transform

ITTC International Towing TankConference

JONSWAP Joint North Sea Wave Project

LSE Least Square Estimation

MAE Mean Absolute Error

MPC Model Predictive Control

MRAO Motion Response AmplitudeOperator

MSE Mean Squared Error

MSS Marine System Simulator

NAR Nonlinear-Autoregressive

RAO Response Amplitude Operator

RMSE Root Mean Squared Error

RPROP Resilient Backpropagation

SMHI Swedish Meteorological andHydrological Institute

SWAN Simulating Waves Nearshore

TEU Twenty-foot Equivalent Unit

TF Transfer Function

USNS United States Naval Ship

WW3 WAVEWATCH-III

70

Page 72: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Nomenclature

5 The volume which the ship displaces inthe water

φ The angular acceleration of the shiparound axis x

ψ The angular acceleration of the shiparound axis z

θ The angular acceleration of the shiparound axis y

x The acceleration of the ship in the di-rection of axis x

y The acceleration of the ship in the di-rection of axis y

z The acceleration of the ship in the di-rection of axis z

∆ω The di�erence between consecutive fre-quencies

∆ij The individual weight update value forweight wij

εj A random phase angle for wave compo-nent j

δEδwij

The derivative error of the FFNN based

on weight wij

γ Peak intensi�cation factor

ω Circular frequency

ω0 Is the natural frequency of the ship/Themodal frequency

ωe The encounter frequency

ωj The circular frequency for wave compo-nent j

−→F The external force applied to the center

of gravity

−→H The angular momentum applied at the

center of gravity

−→M The external momentum applied at the

center of gravity

ρ The density of water

Θ Heel angle of a ship

ζ The elevation of waves

ζd Is a damping coe�cient based on thefriction of the water

A Is amplitude

a The acceleration of the center of gravity

Aj The wave amplitude for wave compo-nent j

g The gravity constant

GM Metacentric Height

h The height from ground to object

Hs The signi�cant wave height

Iij The ships moment of inertia betweentwo axes

kj The wave number for wave componentj

kxx Is the radius of gyration

M Metacentre

m Is the mass of a body

N The total number of wave components

S The encounter spectrum

s Spreading factor

Sff The wave spectrum

T Is the period

t Is a speci�c time

T1 The average wave period

Tp The peak period

U Is the ship speed

Up The potential energy of harmonic oscil-lation

v The velocity of the center of gravity

wij The weight which connect neuron i toneuron j in a FFNN

x Is the position at axis x

Xω4−6Exciting wave moments around the re-spective axes of x,y,z

Xω1−3Exciting wave forces in the respectivedirection of x,y,z

Xh1−3 Hydromechanical forces in the respec-tive direction of x,y,z

Xh4−6 Hydromechanical moments around therespective axes of x,y,z

71

Page 73: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Appendix C List Of Figures

The following section presents the various �gures included within this thesis, the respective captionof the �gure, and the page number where the �gure is found.

List of Figures

1.0.1: The �gure depicts a realization of the shipping network during the year 2012. Thecolors represents routes taken by various types of ships. The �gure was retrievedand extracted from the following website https://www.shipmap.org/47whichwas created by the company KILN located in London, United Kingdom. Permis-sion to use the image in this thesis was gracefully granted by the CEO of KILN.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1.0.2: The �gure depicts the rolling center and rolling angle of a ship in rolling motion. 52.1.1: The �gure depicts a realization of the ship's coordinate system. . . . . . . . . . 82.2.1: The �gure depicts a visualization of how the frequency domain and time domain

correlate with each other through FFT. . . . . . . . . . . . . . . . . . . . . . . 102.2.2: The �gures present how the wave components at certain frequencies can be es-

timated from the wave spectrum using the relation of ζ =∑Nj=1Ajsin(ωjt −

kjx+ εj) and12A

2j = S(ωj)∆ω. It can be seen in the �gure that when the energy

of the wave spectrum (red line) is greater at certain frequencies that will resultwith a wave component (black lines) represented as a sinus function with a greatamplitude, which will have a large impact when calculating the wave motion us-ing fourier series. These speci�c examples was generated in MATLAB using thesourcecode found in the appendix section E.1.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2.2.3: The �gure depicts an example of how the wave elevation would be represented atone position by adding together the wave components found in �gure 2.2.2. Notethat there is a pattern repeating itself which shows that waves are periodical.This speci�c example was generated in MATLAB using the source code found inthe appendix section E.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.2.4: The �gure depicts an example of the Pierson-Moskowitz wave spectrum werethe signi�cant waveheight is 5m. The example was created in an MATLABenvironment. The source code for the example is found in the appendix E.2. . . 11

2.2.5: The �gure depicts an example of the one-parameter Bretschneider wave spectrumwith a signi�cant waveheight of 5m and the two-parameter Bretschneider wavespectrum with waveheight of 5m and modal frequency of 2π

9.7 rad/s 48. The sourcecode for the examples is found in the appendix E.2. . . . . . . . . . . . . . . . . 12

2.2.6: The �gure depicts an example of the two-parameter JONSWAP wave spectrumwith a signi�cant waveheight of 5m and the modal frequency 2π

9.7 rad/s. Thesource code for the example is found in the appendix E.2. . . . . . . . . . . . . . 13

2.2.7: The �gure depicts an example of the two-parameter ITTC wave spectrum witha signi�cant waveheight of 5m and the modal frequency 2π

9.7 rad/s. The sourcecode for the example is found in the appendix E.2. . . . . . . . . . . . . . . . . 14

2.2.8: The �gure depicts a comparison between the wave spectrum equations Pierson-Moskowitz, Bretschneider, JONSWAP, and ITTC. The signi�cant waveheight isset to 5m for all �ve equations and the modal frequency is 2π

9.7 rad/s for all butPierson-Moskowitz and Bretschneider one-parameter. The source code for theexamples is found in the appendix E.2. . . . . . . . . . . . . . . . . . . . . . . . 15

2.3.1: The �gure depicts the encounter angle χ, which is the angle at which the wavesact on the ship.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

2.5.1: The following �gure depicts the relation between CG and CB of a spherical objectwhich have been lowered into water.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

72

Page 74: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

2.5.2: The �gures depicts how the CB changes while the CG remains the same when aship rolls in water. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

2.5.3: The following �gure depicts the relation between CG and CB using GM and Θ(depicted as ϑ in the �gure) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

2.5.4: The following �gure depicts the rolling of a ship in frictionless water, which canbe described as a harmonic oscillation system. The example was generated usingthe source code found in appendix section E.3. . . . . . . . . . . . . . . . . . . . 18

2.5.5: The following �gure depicts the di�erence of under-, critically-, and over dampedharmonic oscillation. The example was generated using the source code found inappendix section E.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

2.5.6: The following �gure depicts how damped harmonic oscillation decays accordingto characteristics of the peak function Ae−ζω0t. The example was generated usingthe source code found in appendix section E.3. . . . . . . . . . . . . . . . . . . . 20

2.6.1: The �gure depicts an example of how the waves disturb the intended heading ofthe ship.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

2.6.2: The �gure depicts an example of how the autopilot can steer the ship to neutralizethe disturbance which the waves cause on the heading. . . . . . . . . . . . . . . 21

2.6.3: The �gure depicts a simpli�ed example of the control and navigation of a marinevessel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

7.1.1: The �gure depicts a simple example of the structure of a FFBP network. Thenetwork shows the how the inputs are weighted and implemented as inputs forthe nodes. The nodes summarizes the inputs and runs the result through anactivation function which yields the output of the node.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

7.2.1: The �gure depicts an example of a structure for the ANFIS algorithm.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

7.4.1: The �gure depicts a simple example of how GA works. In terms for FFGA thegenetic information of the individuals are numerical values for a weight or biasof the net, and the individuals is one con�guration of all the weights and biases. 31

8.1.1: The �gure depicts a realization of how one generated simulation of a ship incertain waves for 500sec was split into several simulations of a ship in the sametype of waves during 25sec. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

8.2.1: The �gure depicts the model used for the TF based method, which solves thedirect and indirect problem of obtaining the rolling of the ship based on the wavespectrum, and obtaining the wave spectrum based on the rolling of the ship. . 34

8.2.2: The �gure depicts the �owchart of the method which loops for the best TF. . . 368.2.3: The �gure depicts a �owchart of the program which utilize GA and one training

case to �nd a TF that solves the inverse problem. . . . . . . . . . . . . . . . . . 378.2.4: The �gure depicts a �owchart of the program which utilize GA and several train-

ing cases to �nd a TF that solves the inverse problem. . . . . . . . . . . . . . . 388.2.5: The �gure depict a model for the method which extracts the parameter that have

generated the estimated encounter spectrum. . . . . . . . . . . . . . . . . . . . . 388.3.1: The �gure depicts the FFNN obtained through MATLAB with the speci�ed con-

�guration from the list.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

8.3.2: The �gure depicts a representative model of how the FFNN were trained. . . . . 418.4.1: The �gure depicts a representative model of how the CBR were trained. . . . . 429.0.2: The �gures depicts the realization of 10-fold cross-validation. Each block/fold

includes several sets of simulated data. . . . . . . . . . . . . . . . . . . . . . . . 439.5.1: The �gures depicts the utilization of the various folds for training the weights

of the CBR as well as validating the CBR. The training fold is added to thedatabase when evaluating the CBR with the validation fold.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

73

Page 75: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

9.6.1: The �gures depicts the actual scope of the waves acting on vessel M/S Marielle.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

10.1.1: The �gures presents the MAE, in percentage, obtained from the 10-fold cross-validation method for the loop and GA solutions which estimates a TF based onone case. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

10.1.2: The �gures presents the percentage MAE obtained from the 10-fold cross-validationmethod for the loop and GA solutions which estimates a TF based on one case. 49

10.2.1: The �gure depicts the result obtained from the validation of the several casesbased TF using 10-fold cross-validation. . . . . . . . . . . . . . . . . . . . . . . . 51

10.3.1: The �gures presents the MAE, in percentage, obtained from the 10-fold cross-validation method for the FFNN and CBR algorithms. . . . . . . . . . . . . . . 52

10.6.1: The �gure depicts the �tness of the encounter spectrum estimation based onthe 30min training of TF with 408 parameters. Each integer along the x-axisrepresents a 25sec long monitored period were the encounter spectrum have beenestimated.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

A.0.1: The �gure depicts a model the direct way for maneuvering a ship based on waves.The behavior of the waves are obtained from reports and then utilized directlyto estimate the movement of a ship, while the control system adjust certainparameters to reduce fuel consumption and rolling. . . . . . . . . . . . . . . . . 69

A.0.2: The �gure depicts an alternative model of maneuvering a ship in waves. Here aninverse method is utilized to retrieve the behaviour of waves. This is an indirectmethod since the output of the model is utilized for retrieving the input parametercalled waves. Once the parameter waves have been found indirectly it is possibleto use the direct method to estimate what the movement of the ship will becomebased on the rest of the inputs. . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

74

Page 76: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Appendix D List Of Tables

The following section presents the various tables included within this thesis, the respective captionof the table, and the page number where the table is found.

List of Tables

7.5.1: The table presents the stated pros and cons for the proposed algorithms. . . . . 318.1.1: The table presents the scope of the wave parameters when extracting data from

the simulation program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328.1.2: The Douglas Scale which states the state at sea for various waveheights. The

table was recovered from euro WEATHER's homepage http://www.eurometeo.com/english/read/doc_douglas . . . . . . . . . . . . . . . . . . . . . . . . . . 32

9.6.1: The table presents the scope of the waves acting on vessel M/S Marielle . . . . 4610.1.1: The table presents the average MAE, in percentage, obtained from the 1 example

TF, based on looping, for each fold . . . . . . . . . . . . . . . . . . . . . . . . . 4910.1.2: The table presents the average MAE, in percentage, obtained from the 1 example

TF, based on GA, for each fold . . . . . . . . . . . . . . . . . . . . . . . . . . . 5010.2.1: The table presents the average MAE, in percentage, for each fold of the TF based

on GA and several examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5110.3.1: The table presents the average MAE, in percentage, for each fold obtained from

the FFNN based on RPROP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5210.3.2: The table presents the average MAE, in percentage, for each fold obtained from

the FFNN based on GA. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5310.3.3: The table presents the average MAE, in percentage, for each fold obtained from

the CBR based on Euclidean distance. . . . . . . . . . . . . . . . . . . . . . . . 5310.3.4: The table presents the average MAE, in percentage, for each fold obtained from

the CBR based on Manhattan distance. . . . . . . . . . . . . . . . . . . . . . . . 5310.4.1: The table presents the average MAE, in percentage, of all folds based on the

various Hs con�gurations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5410.4.2: The table presents the average MAE, in percentage, of all folds based on the

various Tp con�gurations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5410.4.3: The table presents the average MAE, in percentage, of all folds based on the

various χ con�gurations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5510.5.1: The table presents the MAE in percentage for the encounter spectrum estimation

with the testing data obtained from an actual ship. The table also speci�es whichcon�guration was utilized for retrieving the data based on the validation fold. . 56

10.5.2: The table presents the MAE in percentage for the Hs, Tp, and χ estimation withthe testing data obtained from an actual ship. The table also speci�es whichcon�guration was utilized for retrieving the data based on the validation fold. . 56

10.6.1: The table depicts the Encounter Spectrum result obtained from the training(30min)and testing with only logged data . . . . . . . . . . . . . . . . . . . . . . . . . . 57

10.6.2: The table depicts the Hs result obtained from the training(30min) and testingwith only logged data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

10.6.3: The table depicts the Tp result obtained from the training(30min) and testingwith only logged data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

10.6.4: The table depicts the χ result obtained from the training(30min) and testing withonly logged data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

10.6.5: The table depicts the Encounter Spectrum result obtained from the training(60min)and testing with only logged data . . . . . . . . . . . . . . . . . . . . . . . . . . 58

10.6.6: The table depicts the Hs result obtained from the training(60min) and testingwith only logged data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

10.6.7: The table depicts the Tp result obtained from the training(60min) and testingwith only logged data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

10.6.8: The table depicts the χ result obtained from the training(60min) and testing withonly logged data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

75

Page 77: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

10.6.9: The table presents the MAE in percentage when estimating Hs, Tp, and χ withGA after implementing the encounter spectrum estimation. . . . . . . . . . . . . 58

Appendix E Source Code

Skip noteIf source code is not of interest then skipforward to The Final Transfer Functionp.174 or the Timeplan p.175.

This appendix (with its subsections) includes the sourcecode implemented to generate examples for this thesisas well the source code implemented for generating thepresented results in section 10. Bear in mind that thefollowing sources have been constructed to utilize thespeci�c data generated from the simulation program,the data obtained from M/S Mariella's log, and thedata obtained from SMHI's wave buoys. The sourcesare therefore not general applicable solutions but proofof concepts and speci�c research programs. The same solutions/algorithms was implemented whenutilizing simulated- and actual data, but speci�c changes had to be made (Due to the the sim-ulated data based algorithms utilized 10-fold cross-validation whereas the actual data based didnot). This resulted with copying the simulation based algorithms and perform the changes needed.As a result of this some of the source codes are doubles in speci�c sections of the code. Thesesources have been included so that veri�cation of the said implemented solutions can be veri�edand future replication can be established (requires the same or similar datasets as the ones im-plemented within this thesis). The data acquisition and preparation source code have been leftout since it relies on either the company's simulation program and the logs acquired from thecompany's installed systems. Furthermore, the description of the preparation of the data, withinthis thesis, is considered enough explanatory to replicate the work.

E.1 Elevation

c l cc l e a rc l o s e a l lf i g u r ehold ong r id ont i t l e ( 'Wame spectrum to wave components ' )x l ab e l ( ' f requency ' )y l ab e l ( ' time ' )z l a b e l ( ' en e r g i / e l eva t i on ' )s e t ( gca , ' XTickLabel ' , [ ] )s e t ( gca , ' YTickLabel ' , [ ] )s e t ( gca , ' ZTickLabel ' , [ ] )s e t ( gca , 'YLim' , [ 0 2∗ pi ] )

%%VARIABLESg = 9 . 8 2 ; %grav i ty consantHs = 5 ; %s i g n i f i c a n t waveheight%Hs = 2 ;%Tp = 18 ;%T1 = 18%(1.086/1.408) ∗Tp;omega_0 = (2∗ pi ) / 9 . 7 ;%obtained from%https : // ocw . mit . edu/ cour s e s /mechanical−eng ine e r i ng /2−017 j−design−of−

e l e c t romechan i ca l−robot i c−systems−f a l l −2009/ ass ignments /MIT2_017JF09_p04 . pdf

%T1 = (2∗ pi ) /(1 .2957∗omega_0) ;%PiersonSpectrum = @(omega ) ( ( 0 . 0 0 8 1 . ∗ ( g .^2) ) . / ( omega .^5) ) .∗ exp ( −0 .032 .∗ ( ( g .^2) . / ( ( Hs .^2) ∗(

omega .^4) ) ) ) ;

%ITTC%Spectrum = @(omega ) ( (173∗ (Hs .^2) . / (T1.^4) ) . / ( omega .^5) ) .∗ exp (−((691 ./(T1.^4) ) . / (

omega .^4) ) ) ;

76

Page 78: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

%Bretschneider_two_param%Spectrum = @(omega ) ( 1 . 2 5 . / 4 ) . ∗ ( ( ( ( 2 . ∗ pi ) . / ( 1 . 2 9 5 7 . ∗ (T1) ) ) .^4) . / ( omega .^5) ) . ∗ ( Hs

.^2) .∗ exp ( −1 . 2 5 .∗ ( ( ( ( 2 .∗ pi ) . / ( 1 . 2 9 5 7 . ∗ (T1) ) ) . / omega ) .^4) ) ;

%Jonswap%g=9.82;% [m/ s ^2]%alpha =(0.2∗(Hs^2) ∗(omega_0^4) ) /( g^2) ;%gamma = 3 . 3 ;%S1=alpha ∗g^2∗(w^−5)∗exp (−(5/4) ∗(w0/w) ^4) ;%S2=gamma^(exp(−(w−w0) ^2/(2∗( sigma∗w0) ^2) ) ) ;%S(w)=S1∗S2 [m^2 s ]%Spectrum = @(omega ) alpha .∗ g .^2 .∗ ( omega.^−5) .∗ exp (−(5./4) . ∗ ( omega_0 . / omega ) .^4) .∗

gamma.^( exp(−(omega−omega_0) . ^ 2 . / ( 2 . ∗ ( s igmafunc (omega , omega_0) .∗ omega_0) .^2) ) );

l im =2;components = 32 ;d e l t a = lim/components ;

pos1=0;noPer iods = 300 ;s i n s t e p = 100 ;s tep = 2∗ pi / s i n s t e p ;wavemotion = ze ro s (1 , noPer iods ∗ s i n s t e p+1) ;

f o r omega = 0 : de l t a : l imphase = rand ∗2∗ pi ;pos = 1 ;Amplitude = 2∗ Spectrum (omega ) ∗ de l t a ;WaveElevation ( ( omega/ de l t a )+1) = Amplitude ;f o r t imestep = 0 : s tep :2∗ pi ∗( noPer iods )

E levat ion = Amplitude∗ s i n ( omega∗ t imestep+phase ) ;X( pos ) = omega ;Y( pos ) = t imestep ;Z( pos ) = Elevat ion ;

%Check i f amplitude i s va l i di f ( i snan ( Elevat ion ) == f a l s e )

wavemotion ( pos ) = wavemotion ( pos ) + Elevat ion ;endpos = pos + 1 ;

end%Plot s i n e func t i onp lo t3 (X,Y, Z , ' k ' )

end

%p lo t spectrumx = 0 : 0 . 0 1 : l im ;s = s i z e ( x ) ;ze ro = ze ro s ( s ) ;p lo t3 (x , zero , Spectrum (x ) , ' r ' )

yl im = ( [ 0 4∗ pi ] ) ;

f i g u r ehold ong r id onx l ab e l ( ' f requency ' )y l ab e l ( ' en e r g i / e l eva t i on ' )p l o t (x , Spectrum (x ) , ' r ' )[ row , c o l ] = s i z e (WaveElevation ) ;f o r k = 1 : c o l

p l o t ( [ ( k−1)∗ de l t a (k−1)∗ de l t a ] , [−WaveElevation (k ) WaveElevation (k ) ] , ' k−o ' )endlegend ( 'Wave Spectrum ' , 'Wave component ' )

f i g u r e

77

Page 79: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

hold ong r id ont i t l e ( 'Wame motion ' )x l ab e l ( ' Time ( sec ) ' )y l ab e l ( ' E levat ion (m) ' )%s e t ( gca , ' XTickLabel ' , [ ] )%s e t ( gca , ' YTickLabel ' , [ ] )s e t ( gca , 'XLim' , [ 0 5000 ] )p l o t ( 1 : pos−1,wavemotion , ' k ' )

Code E.1.1: Above is the source code implemented in MATLAB to generate the relation betweenwave spectrum, wave components, and actual wave elevation

78

Page 80: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.2 Wave Spectra

c l cc l e a rc l o s e a l lhold ong r id on

g = 9 . 8 2 ;Hs = 5 ;omega_0 = (2∗ pi ) / 9 . 7 ;%obtained from%https : // ocw . mit . edu/ cour s e s /mechanical−eng ine e r i ng /2−017 j−design−of−

e l e c t romechan i ca l−robot i c−systems−f a l l −2009/ ass ignments /MIT2_017JF09_p04 . pdf

T1 = (2∗ pi ) /(1 .2957∗omega_0) ;

f o r pos = 1 : 1 : 2 01omega = ( pos−1) /100 ;

%omega_p = (2∗ pi ) /T;i f ( omega <= omega_0)%(5.24/T) )

sigma = 0 . 0 7 ;e l s e

sigma = 0 . 0 9 ;endY = exp (−(((0 .191∗ omega∗T1−1)/( sq r t (2 ) ∗ sigma ) ) ^2) ) ;JONSWAP( pos ) = 155∗ ( (Hs^2) / ( (T1^4) ∗( omega^5) ) ) ∗exp (−944/((T1^4) ∗( omega^4) ) )

∗ (3 .3^Y) ;

endPierson = @(omega ) ( ( 0 . 0 081∗ ( g^2) ) /( omega^5) ) ∗exp (−0.032∗(( g^2) / ( (Hs^2) ∗( omega^4) ) ) )

;Bretschneider_two_param = @(omega ) ( 1 . 25/4 ) ∗ ( ( ( ( 2∗ pi ) / (1 . 2957∗ (T1) ) ) ^4) /( omega^5) ) ∗(

Hs^2)∗exp ( −1 .25∗ ( ( ( (2∗ pi ) / (1 . 2957∗ (T1) ) ) /omega ) ^4) ) ;Bretschneider_one_param = @(omega ) ( 1 . 25/4 ) ∗ ( ( ( ( 2∗ pi ) / (1 . 2957∗ ( 3 . 861∗ s q r t (Hs) ) ) ) ^4)

/( omega^5) ) ∗(Hs^2)∗exp ( −1 .25∗ ( ( ( (2∗ pi ) / (1 . 2957∗ ( 3 . 861∗ s q r t (Hs) ) ) ) /omega ) ^4) ) ;

ITTC = @(omega ) ( (173∗ (Hs^2) /(T1^4) ) /( omega^5) ) ∗exp (−((691/(T1^4) ) /( omega^4) ) ) ;

%%

t i t l e ( ' P ier son Moskowitz ' )x l ab e l ( ' Angular Frequency ( rad/ s ) ' )y l ab e l ( ' Energy (m^2s / rad ) ' )f p l o t ( Pierson , [ 0 2 ] , ' co lo r ' , ' k ' )

f i g u r ehold ong r id ont i t l e ( ' Bretschne ider ' )x l ab e l ( ' Angular Frequency ( rad/ s ) ' )y l ab e l ( ' Energy (m^2s / rad ) ' )f p l o t ( Bretschneider_one_param , [ 0 2 ] , ' co lo r ' , ' k ' )f p l o t ( Bretschneider_two_param , [ 0 2] , '−−k ' )

l egend ( ' Bre t s chne ide r one−param ' , ' Bre t s chne ide r two−param ' )

f i g u r ehold ong r id ont i t l e ( 'JONSWAP' )x l ab e l ( ' Angular Frequency ( rad/ s ) ' )y l ab e l ( ' Energy (m^2s / rad ) ' )p l o t ( 0 : 0 . 0 1 : 2 , JONSWAP, ' co lo r ' , ' k ' )

f i g u r ehold ong r id on

79

Page 81: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

t i t l e ( ' ITTC' )x l ab e l ( ' Angular Frequency ( rad/ s ) ' )y l ab e l ( ' Energy (m^2s / rad ) ' )f p l o t ( ITTC, [ 0 2 ] , ' k ' )

f i g u r ehold ong r id ont i t l e ( ' Comparison ' )x l ab e l ( ' Angular Frequency ( rad/ s ) ' )y l ab e l ( ' Energy (m^2s / rad ) ' )

f p l o t ( Pierson , [ 0 2 ] , ' co lo r ' , ' g ' )f p l o t ( Bretschneider_one_param , [ 0 2 ] , ' r−−')f p l o t ( Bretschneider_two_param , [ 0 2 ] , ' co lo r ' , 'm' )p l o t ( 0 : 0 . 0 1 : 2 , JONSWAP, ' co lo r ' , ' b ' )f p l o t ( ITTC, [ 0 2 ] , ' k−−')

l egend ( ' Pierson ' , ' Bre t s chne ide r one−param ' , ' Bre t s chne ide r two−param ' , 'JONSWAP' , 'ITTC' )

Code E.2.1: Above is the source code implemented in MATLAB to generate examples for thevarious wave spectra.

80

Page 82: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.3 Harmonic Oscillations

c l cc l e a rc l o s e a l l

p = 1000 ;V = 1 ;g = 9 . 8 2 ;h = 0 . 5 ;GM = 461∗10^6;T = 5 ;w = (2∗ pi /T) ;ze ta = . 1 ;

A = sq r t ( (2∗p∗V∗g∗h) /GM) ;

kxx =sq r t ( g∗GM) ∗T/(2∗ pi ) ;

w=4.189; % 0 . 3142 ;T=10; % s imu la t i on time

lambda = −zeta ∗w;alpha = imag (w∗ s q r t ( ( ze ta ^2)−1) ) ;

c1 = A;c2 = ((2∗(− lambda ) ∗ c1 ) /(2∗ alpha ) )+ (0/ alpha ) ;

theta1 = @( t )A∗ s i n (w∗ t ) ;theta2 = @( t ) c1∗exp(−zeta .∗w.∗ t ) ;theta3 = @( t ) exp ( lambda .∗ t ) . ∗ ( c1∗ cos ( alpha .∗ t ) + c2∗ s i n ( alpha .∗ t ) ) ;t = 0 : 0 . 0 0 1 :T;

hold ong r id ont i t l e ( ' Harmonic Os c i l l a t i o n ' )p l o t ( t , 1 8 0 . ∗ ( theta1 ( t ) . / p i ) , ' k ' )x l ab e l ( ' time ' )y l ab e l ( ' Heel ang le ( deg ) ' )

f i g u r ehold ong r id ont i t l e ( ' Harmonic O s c i l l a t i o n and Damped Harmonic Os c i l l a t i o n ' )p l o t ( t , 1 8 0 . ∗ ( theta1 ( t ) . / p i ) , ' k ' )p l o t ( t , 1 8 0 . ∗ ( theta3 ( t ) . / p i ) , ' r ' )x l ab e l ( ' time ' )y l ab e l ( ' Heel ang le ( deg ) ' )l egend ( ' Harmonic O s c i l l a t i o n So lut ion ' , 'Damped Harmonic O s c i l l a t i o n So lut ion ' )

f i g u r ehold ong r id ont i t l e ( ' Decay o f Damped Harmonic Os c i l l a t i o n ' )p l o t ( t , 1 8 0 . ∗ ( theta2 ( t ) . / p i ) , ' b ' )p l o t ( t , 1 8 0 . ∗ ( theta3 ( t ) . / p i ) , ' r ' )p l o t ( t ,180.∗(− theta2 ( t ) . / p i ) , ' b ' )x l ab e l ( ' time ' )y l ab e l ( ' Heel ang le ( deg ) ' )l egend ( ' Peak funct ion ' , ' So lut ion ' , ' i n v e r s e Peak funct ion ' )

%%f i g u r ehold ong r id ont i t l e ( 'Damped Harmonic Os c i l l a t i o n ' )x l ab e l ( ' time ' )

81

Page 83: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

y l ab e l ( ' Heel ang le ( deg ) ' )

ze ta = . 1 ;lambda = −zeta ∗w;alpha = imag (w∗ s q r t ( ( ze ta ^2)−1) ) ;c1 = A;c2 = ((2∗(− lambda ) ∗ c1 ) /(2∗ alpha ) )+ (0/ alpha ) ;theta4 = @( t ) exp ( lambda .∗ t ) . ∗ ( c1∗ cos ( alpha .∗ t ) + c2∗ s i n ( alpha .∗ t ) ) ;p l o t ( t , 1 8 0 . ∗ ( theta4 ( t ) . / p i ) , ' r ' )

ze ta = 1 ;lambda = −zeta ∗w;alpha = 1 . 6 ;c1 = A;c2 = ((2∗(− lambda ) ∗ c1 ) /(2∗ alpha ) )+ (0/ alpha ) ;theta5 = @( t ) exp ( ( lambda+alpha ) .∗ t ) . ∗ ( c1 + c2∗ t ) ;p l o t ( t , 1 8 0 . ∗ ( theta5 ( t ) . / p i ) , ' g ' )

ze ta = 2 ;lambda = −zeta ∗w;alpha = (w∗ s q r t ( ( ze ta ^2)−1) ) ;c1 = A;c2 = ((2∗(− lambda ) ∗ c1 ) /(2∗ alpha ) )+ (0/ alpha ) ;theta6 = @( t ) exp ( lambda .∗ t ) . ∗ ( c1∗ cos ( alpha .∗ t ) + c2∗ s i n ( alpha .∗ t ) ) ;p l o t ( t , 1 8 0 . ∗ ( theta6 ( t ) . / p i ) , ' b ' )

l egend ( ' Under damped ' , ' C r i t i c a l l y damped ' , ' Over damped ' )

Code E.3.1: Above is the source code implemented in MATLAB to simulate the rolling behaviorof a ship when considered as damped- and undamped harmonic oscillation.

82

Page 84: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.4 Transfer Function For Training And Validating With Simulated

Data

The following sections presents the code implemented for the TF based solutions utilizing simulateddata.

E.4.1 Loop Based

%c l c%c l e a r v a r s −except f o l d%c l o s e a l lwarning ( ' o f f ' , ' a l l ' ) ;

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )d i sp ( f o l d )

Resu l t_fo lder = ' Resu l t s / ' ;

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )%f o l d = 1 ;f i l ename = [ Resu l t_fo lder ' Transfer_Function_Loop_1_example_fold_ ' num2str ( f o l d ) ' .

mat ' ] ;

%Check i f the v a r i a b l e s have been save from a prev ious t e s ti f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )

%The va r i a b l e s have not been saved to run the t e s te l s e

f o l d e r = ' Separated data / ' ;

%% −−−−−−−−−−−−−−−−−−−−−−−− INITIALIZE −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−% load the fo ld−va r i a b l e sload ( [ f o l d e r ' Rolling_Train_fold_ ' num2str ( f o l d ) ] ) ;Ro l l i ng = Ro l l i n g t r a i n ;load ( [ f o l d e r ' Rudder_Train_fold_ ' num2str ( f o l d ) ] ) ;Rudder = Ruddertrain ;load ( [ f o l d e r ' Pitch_Train_fold_ ' num2str ( f o l d ) ] ) ;Pitch = P i t ch t r a i n ;load ( [ f o l d e r 'Waves_Train_fold_ ' num2str ( f o l d ) ] ) ;Waves = Wavestrain ;load ( [ f o l d e r ' Speed_Train_fold_ ' num2str ( f o l d ) ] ) ;Cont_spd = Speedtra in ;

load ( [ f o l d e r ' Rolling_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r 'Rudder_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r ' Pitch_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r 'Waves_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r ' Speed_Val_fold_ ' num2str ( f o l d ) ] ) ;

% Convert Degrees to rad iansWaves ( 3 , : ) = Waves ( 3 , : ) ∗( p i /180) ;Wavesval ( 3 , : ) = Wavesval ( 3 , : ) ∗( p i /180) ;

[~ , C] = s i z e ( Ro l l i ng ) ;

%choose case to t r a i n and va l i d a t e upon%Chooses the f i r s t case with in the preceed ing f o l d o f the va l i d a t i o n%f o l d . E. g . i f v a l i d a t i o n f o l d = 1 then t r a i n i n g case i s case 1 from%fo l d 2 .TrainCase = ( fo ld −1)∗(C/9)+1;i f ( TrainCase > C)

TrainCase = 1 ;endRo l l i ng = Ro l l i ng ( : , TrainCase ) ; %Retr i eve the r o l l i n g o f the sh ipHs = Waves (1 , TrainCase ) ; %Retr i eve the s i g n i f i c a n t waveheightTp = Waves (2 , TrainCase ) ; %Retr i eve the peak per iod

83

Page 85: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Beta = Waves (3 , TrainCase ) ; %Retr i eve the encounter ang le

%Retr i eve the average sh ip speed during t h i s sample timeU = mean(Cont_spd ( : , TrainCase ) ) ;U = U ∗ 0 .5144443101 ; %convert to m/ s

g = 9 . 8 2 ; %grav i ty constant[ row , ~] = s i z e ( Ro l l i ng ) ;w_lim = 2 ;w_step = w_lim/row ;w = w_step : w_step : w_lim ; %Frequency vec to r

Ts = w_step ;%.25 ; %Sampling time o f the data i s a l s o constant

%Setup Wave Spectrum (ITTC)omega_0 = (2∗ pi ) /Tp ;T1 = (2∗ pi ) /(1 .2957∗omega_0) ;ITTC = @(x ) ( (173∗ (Hs^2) /(T1^4) ) . / ( x .^5) ) .∗ exp (−((691/(T1^4) ) . / ( x .^4) ) ) ;

%Use Tr i s tan Perez c a l c u l a t i o n s to r e t r i e v e the EncounterSpectrum%This i s the input o f the Trans fe r func t i on f o r the Di rec t Method%and output f o r the Trans fe r Function f o r the In−d i r e c t methodEncounterSpectrum = ITTC(w) . / ( abs (1−((2.∗w.∗U) . / ( g ) ) ∗ cos ( Beta ) ) ) ;EncounterSpectrum = EncounterSpectrum ' ;

%The output f o r the Trans fe r func t i on in Di rec t method i s g iven%by the motion spectrum f o r the r o l l i n g , which i s r e t r i e v e d with f f t .%And the input f o r the in−d i r e c t t r a n s f e r func t i on i s a l s o the motion%spectrumMotionSpectrum = f f t ( Ro l l i ng ) ;

%Var iab l e s f o r the loop ingnuminators_max = 70 ;numinators_min = 1 ;i t e r a t i o n = 0 ;e lapsedt ime = 0 ;s u c c e s s e s = 0 ;e r r o r s = 0 ;improvements = 0 ;t o t a l = 0 ;f o r n = numinators_min : numinators_max

t o t a l = t o t a l +1;end

%% −−−−−−−−−−−−−−−−−−LOOP FOR THE DIRECT METHOD−−−−−−−−−−−−−−−−−−−−−−−−−−−−Bar = waitbar (0 , ' Ca l cu l a t ing Motion TF' ) ;d i sp ( ' Begin Ca l cu l a t ing Motion TF' ) ;

%Setup the Input output data f o r t f e s t commandData = iddata (MotionSpectrum , EncounterSpectrum , Ts ) ;

%Estimate the f i r s t t r a n s f e r func t i onDirectTF = t f e s t (Data , 1 , 0 , ' Ts ' , Ts ) ;[~ , f i t ] = compare (Data , DirectTF ) ;

%% Loop f o r bes t setup o f t r a n s f e r func t i on%Loop which i n c r e a s e s the number o f numinators f o r the t r a n s f e r func t i on%and c a l c u l a t e s the best f i tf o r n = numinators_min : numinators_max

%Update the waitbart i c ;i t e r a t i o n = i t e r a t i o n +1;Time = (sum( e lapsedt ime ) / i t e r a t i o n ) ∗( t o ta l−i t e r a t i o n ) /60 ;EstimatedMinLeft = f l o o r (Time) ;Est imatedSecLeft = f l o o r ( (Time−EstimatedMinLeft ) ∗60) ;s t r i n g = [ ' no TF found = ' num2str ( s u c c e s s e s ) ' , e r r o r s = ' num2str ( e r r o r s )

' , no Improved TF = ' num2str ( improvements ) '\n cur rent i t e r a t i o n = 'num2str ( s u c c e s s e s + e r r o r s + 1) ' , t o t a l i t e r a t i o n s = ' num2str ( t o t a l )

84

Page 86: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

'\n Estimated time l e f t = ' num2str ( EstimatedMinLeft ) 'min ' num2str (Est imatedSecLeft ) ' sec ' ] ;

waitbar ( i t e r a t i o n / to ta l , Bar , s p r i n t f ( s t r i n g ) ) ;

% Search f o r new and be t t e r TFtry

temp = t f e s t (Data , n , [ ] , ' Ts ' , Ts ) ;[ y1 , f i t 1 ] = compare (Data , temp) ;i f ( f i t 1 > f i t )

DirectTF = temp ;f i t = f i t 1 ;improvements = improvements + 1 ;

endsu c c e s s e s = su c c e s s e s +1;

catche r r o r s = e r r o r s +1;

ende lapsedt ime ( i t e r a t i o n ) = toc ;

endc l o s e (Bar )

f i g u r ecompare (Data , DirectTF )[Y, f i t_motion ] = compare (Data , DirectTF ) ;hold ont i t l e ( ' Encounter Spectrum to Motion Spectrum ' )

Est_motion_spectrum = Y. y ; %The est imated motion Spectrum

f i g u r ehold ong r id ont i t l e ( ' Ro l l i ng o f ship , us ing t ra in ing ' )p l o t ( 0 : Ts : ( row−1)∗Ts , Rol l ing , ' k ' )p l o t ( 0 : Ts : ( row−1)∗Ts , i f f t ( Est_motion_spectrum ) ,'−−r ' )%c a l c u l a t e r o l l i n g accuracyPerc = 100−100∗sum( abs ( Rol l ing− i f f t ( Est_motion_spectrum ) ) .^2) /sum( abs ( Ro l l i ng )

.^2) ;f i t _ r o l l i n g = Perc ;l egend ( ' Act Rol l ing ' , [ ' Est Rol l ing ' num2str ( Perc ) '% ' ] )

%% −−−−−−−−−−−−−−−−−−LOOP FOR THE IN−DIRECT METHOD−−−−−−−−−−−−−−−−−−−−−−−−−−−−i t e r a t i o n = 0 ;e lapsedt ime = 0 ;s u c c e s s e s = 0 ;e r r o r s = 0 ;improvements = 0 ;

Bar = waitbar (0 , ' Ca l cu l a t ing Encounter TF' ) ;d i sp ( ' Ca l cu l a t ing Encounter TF' ) ;

%Setup the Input output data f o r t f e s t commandData = iddata ( EncounterSpectrum , MotionSpectrum , Ts ) ;

best_n = 1 ;%Estimate the f i r s t t r a n s f e r func t i onInDirectTF = t f e s t (Data , 1 , 1 , ' Ts ' , Ts ) ;[ y f i t ] = compare (Data , InDirectTF ) ;

%% Loop f o r bes t setup o f t r a n s f e r func t i on%Loop which i n c r e a s e s the number o f numinators f o r the t r a n s f e r func t i on%and c a l c u l a t e s the best f i tf o r n = numinators_min : numinators_max

%Update the waitbart i c ;i t e r a t i o n = i t e r a t i o n +1;Time = (sum( e lapsedt ime ) / i t e r a t i o n ) ∗( t o ta l−i t e r a t i o n ) /60 ;

85

Page 87: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

EstimatedMinLeft = f l o o r (Time) ;Est imatedSecLeft = f l o o r ( (Time−EstimatedMinLeft ) ∗60) ;s t r i n g = [ ' no TF found = ' num2str ( s u c c e s s e s ) ' , e r r o r s = ' num2str ( e r r o r s )

' , no Improved TF = ' num2str ( improvements ) '\n cur rent i t e r a t i o n = 'num2str ( s u c c e s s e s + e r r o r s + 1) ' , t o t a l i t e r a t i o n s = ' num2str ( t o t a l )'\n Estimated time l e f t = ' num2str ( EstimatedMinLeft ) 'min ' num2str (Est imatedSecLeft ) ' sec ' ] ;

waitbar ( i t e r a t i o n / to ta l , Bar , s p r i n t f ( s t r i n g ) ) ;

% Search f o r new and be t t e r TFtry

temp = t f e s t (Data , n , [ ] , ' Ts ' , Ts ) ;[ y1 , f i t 1 ] = compare (Data , temp) ;i f ( f i t 1 > f i t )

InDirectTF = temp ;f i t = f i t 1 ;improvements = improvements + 1 ;best_n = n ;

endsu c c e s s e s = su c c e s s e s +1;

catche r r o r s = e r r o r s +1;

ende lapsedt ime ( i t e r a t i o n ) = toc ;

endc l o s e (Bar )

f i g u r ecompare (Data , InDirectTF )[Y, f i t_encounte r ] = compare (Data , InDirectTF ) ;hold ont i t l e ( ' Est imation o f Encounter Spectrum , Using t r a i n i n g Data ' )

Est_encounter_spectrum = Y. y ; %Estimated encounter spectrum

%% VALIDATE THE TF[~ , c o l ] = s i z e (Wavesval ) ;f o r k = 1 : c o l

FIT ( : , k ) = ValidateMyTFs ( Ro l l i n gva l ( : , k ) ,Wavesval ( : , k ) , Speedval ( : , k ) ,DirectTF , InDirectTF ) ;

end

save ( f i l ename )end

Code E.4.1: Above is the source code implemented in MATLAB for the loop based TF using onlysimulated data for training and validation. The program demands that an integer named fold ispre-initialized and within the range of 1-10. The code utilized the function presented in appendixE.4.3.

86

Page 88: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.4.2 Genetic Algorithm And One Example Based

%c l c%c l e a r v a r s −except f o l d%c l o s e a l lwarning ( ' o f f ' , ' a l l ' ) ;

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )%f o l d = 1 ;d i sp ( f o l d )

Resu l t_fo lder = ' Resu l t s / ' ;

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )%f o l d = 1 ;d i sp ( f o l d )f i l ename = [ Resu l t_fo lder ' Transfer_Function_GA_1_example_fold_ ' num2str ( f o l d ) ' .

mat ' ] ;

%Check i f the v a r i a b l e s have been save from a prev ious t e s ti f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )

%The va r i a b l e s have not been saved to run the t e s te l s e

f o l d e r = ' Separated data / ' ;

%% −−−−−−−−−−−−−−−−−−−−−−−− INITIALIZE −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−load ( [ f o l d e r ' Rolling_Train_fold_ ' num2str ( f o l d ) ] ) ;Ro l l i ng = Ro l l i n g t r a i n ;load ( [ f o l d e r ' Rudder_Train_fold_ ' num2str ( f o l d ) ] ) ;Rudder = Ruddertrain ;load ( [ f o l d e r ' Pitch_Train_fold_ ' num2str ( f o l d ) ] ) ;Pitch = P i t ch t r a i n ;load ( [ f o l d e r 'Waves_Train_fold_ ' num2str ( f o l d ) ] ) ;Waves = Wavestrain ;load ( [ f o l d e r ' Speed_Train_fold_ ' num2str ( f o l d ) ] ) ;Cont_spd = Speedtra in ;

load ( [ f o l d e r ' Rolling_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r 'Rudder_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r ' Pitch_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r 'Waves_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r ' Speed_Val_fold_ ' num2str ( f o l d ) ] ) ;

Waves ( 3 , : ) = Waves ( 3 , : ) ∗( p i /180) ;Wavesval ( 3 , : ) = Wavesval ( 3 , : ) ∗( p i /180) ;

[~ , C] = s i z e ( Ro l l i ng ) ;

%chose case to t r a i n and va l i d a t e upon%TrainCase = 1 ;TrainCase = ( fo ld −1)∗(C/9)+1;i f ( TrainCase > C)

TrainCase = 1 ;endRo l l i ng = Ro l l i ng ( : , TrainCase ) ; %Retr i eve the r o l l i n g o f the sh ipHs = Waves (1 , TrainCase ) ; %Retr i eve the s i g n i f i c a n t waveheightTp = Waves (2 , TrainCase ) ; %Retr i eve the peak per iodBeta = Waves (3 , TrainCase ) ; %Retr i eve the encounter ang le

U = mean(Cont_spd ( : , TrainCase ) ) ; %Average sh ipspeed i s constant f o r a l l the data

U = U ∗ 0 .5144443101 ; %convert to m/ s

87

Page 89: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

g = 9 . 8 2 ; %grav i ty constant[ row , ~] = s i z e ( Ro l l i ng ) ;w_lim = 2 ;w_step = w_lim/row ;w = w_step : w_step : w_lim ; %Frequency vec to r

Ts = w_step ;%.25 ; %Sampling time o f the data i s a l s oconstant

%Setup Wave Spectrum (ITTC)omega_0 = (2∗ pi ) /Tp ;T1 = (2∗ pi ) /(1 .2957∗omega_0) ;ITTC = @(x ) ( (173∗ (Hs^2) /(T1^4) ) . / ( x .^5) ) .∗ exp (−((691/(T1^4) ) . / ( x .^4) ) ) ;

%Use Tr i s tan Perez c a l c u l a t i o n s to r e t r i e v e the EncounterSpectrum%This i s the input o f the Trans fe r func t i on f o r the Di rec t Method%and output f o r the Trans fe r Function f o r the In−d i r e c t methodEncounterSpectrum = ITTC(w) . / ( abs (1−((2.∗w.∗U) . / ( g ) ) ∗ cos ( Beta ) ) ) ;EncounterSpectrum = EncounterSpectrum ' ;

%The output f o r the Trans fe r func t i on in Di rec t method i s g iven%by the motion spectrum f o r the r o l l i n g , which i s r e t r i e v e d with f f t .%And the input f o r the in−d i r e c t t r a n s f e r func t i on i s a l s o the motion%spectrumMotionSpectrum = f f t ( Ro l l i ng ) ;

%%========================================================================================

disp ( ' Ca l cu l a t ing Motion TF' ) ;%Setup the Input output data f o r the d i r e c t methodDirect_Data = iddata (MotionSpectrum , EncounterSpectrum , Ts ) ;%Setup the Input output data f o r the in−d i r e c t methodInDirect_Data = iddata ( EncounterSpectrum , MotionSpectrum , Ts ) ;

nvars = 400 ; %number o f v a r i a b l e s to es t imate with the GA ( nvars = 200−> 50r e a l and 50 complex numerators , and 50 r e a l and 50 complex denominators )

%Setup the GAga_opts = gaopt imset (@ga) ;ga_opts . Display = ' i t e r ' ;ga_opts . Popu lat ionS ize = 100 ;

%hours = 1 ;minute = 30 ; %maximum minutes which the GA i s a l lowed to search f o r the

v a r i a b l e sga_opts . TimeLimit = minute ∗60 ;ga_opts . Generat ions = i n f ;ga_opts . PopInitRange = [ −1 ; 1 ] ;ga_opts . TolFun = 1e−20;ga_opts . TolCon = 1e−20;ga_opts . Sta l lGenLimit = 1000 ;%ga_opts . F i tne s sL imi t = 1 ;

%% FIND DIRECT TFData = Direct_Data ;[ x , ~ ] = ga ( @f i tnes s_di r r , nvars , ga_opts ) ;nom = nvars /4 ;a = x ( 1 , 1 :nom) + x (1 , (nom+1) :2∗nom) ∗1 i ;b = x (1 ,2∗nom+1:3∗nom) + x (1 ,3∗nom + 1 : nvars ) ∗1 i ;% a = x (1 , 1 : 2∗nom) ;% b = x (1 ,2∗nom+1:n) ;

DirectTF = t f (b , a , ' Ts ' , Ts , ' va r i ab l e ' , ' z^−1') ;

f i g u r ecompare ( Direct_Data , DirectTF ) ;

88

Page 90: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

[Y, f i t_motion ] = compare (Data , DirectTF ) ;Out = Y. y ;

%Plot the est imated r o l l i n g o f the sh ip based on d i r e c t methodf i g u r ehold ong r id ont i t l e ( ' Ro l l i ng o f ship , us ing t ra in ing ' )p l o t ( 0 : Ts : ( row−1)∗Ts , Rol l ing , ' k ' )p l o t ( 0 : Ts : ( row−1)∗Ts , i f f t (Out) ,'−−r ' )Perc = 100−100∗sum( abs ( Rol l ing− i f f t (Out) ) .^2) /sum( abs ( Ro l l i ng ) .^2) ;f i t _ r o l l i n g = Perc ;l egend ( ' Act Rol l ing ' , [ ' Est Rol l ing ' num2str ( Perc ) '% ' ] )

%% FIND INDIRECT TFData = InDirect_Data ;[ y , ~ ] = ga ( @f i tness_in_dirr , nvars , ga_opts ) ;nom = nvars /4 ;a = y ( 1 , 1 :nom) + y (1 , (nom+1) :2∗nom) ∗1 i ;b = y (1 ,2∗nom+1:3∗nom) + y (1 ,3∗nom + 1 : nvars ) ∗1 i ;% a = y (1 , 1 : 2∗nom) ;% b = y (1 ,2∗nom+1: nvars ) ;

InDirectTF = t f (b , a , ' Ts ' , Ts , ' va r i ab l e ' , ' z^−1') ;

%Plot the s o l u t i o n f o r in−d i r e c t methodf i g u r ehold ong r id oncompare (Data , InDirectTF )[Y, f i t_encounte r ] = compare (Data , InDirectTF ) ;hold ont i t l e ( ' Est imation o f Encounter Spectrum , Using t r a i n i n g Data ' )

%% VALIDATE THE TF[~ , c o l ] = s i z e (Wavesval ) ;f o r k = 1 : c o l

FIT ( : , k ) = ValidateMyTFs ( Ro l l i n gva l ( : , k ) ,Wavesval ( : , k ) , Speedval ( : , k ) ,DirectTF , InDirectTF ) ;

endsave ( f i l ename ) ;

end

%% DIRECT FITNESS FUNCTIONfunc t i on f i t = f i t n e s s_d i r r ( x )%Retr i eve s p e c i f i c v a r i a b l e s from workspacen = eva l i n ( ' base ' , ' nvars ' ) ;t s = eva l i n ( ' base ' , ' Ts ' ) ;data = eva l i n ( ' base ' , ' Data ' ) ;motion = eva l i n ( ' base ' , ' MotionSpectrum ' ) ;encounter = eva l i n ( ' base ' , ' EncounterSpectrum ' ) ;

t ry

nom = n/4 ;a = x ( 1 , 1 :nom) + x (1 , (nom+1) :2∗nom) ∗1 i ;b = x (1 ,2∗nom+1:3∗nom) + x (1 ,3∗nom + 1 : n) ∗1 i ;

%try to f i nd a TF us ing the va r i ab l e s , and c a l c u l a t e the f i tt f 1 = t f (b , a , ' Ts ' , ts , ' va r i ab l e ' , ' z^−1') ;[~ , f i t ] = compare ( data , t f 1 ) ;f i t = abs ( f i t −100) ;

catch% i f the v a r i a b l e s can ' t generate a TF then the f i t va lue f o r the se% va r i a b l e s i s s e t to nanf i t = nan ;

end

89

Page 91: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

end

%% IN DIRR FITNESS FUNCTIONfunc t i on f i t = f i tn e s s_ in_d i r r ( x )%Retr i eve s p e c i f i c v a r i a b l e s from workspacen = eva l i n ( ' base ' , ' nvars ' ) ;t s = eva l i n ( ' base ' , ' Ts ' ) ;data = eva l i n ( ' base ' , ' Data ' ) ;motion = eva l i n ( ' base ' , ' MotionSpectrum ' ) ;encounter = eva l i n ( ' base ' , ' EncounterSpectrum ' ) ;

t ry

nom = n/4 ;a = x ( 1 , 1 :nom) + x (1 , (nom+1) :2∗nom) ∗1 i ;b = x (1 ,2∗nom+1:3∗nom) + x (1 ,3∗nom + 1 : n) ∗1 i ;out = f i l t e r (b , a , motion ) ;

f i t 1 = sum( ( r e a l ( encounter )−r e a l ( out ) ) .^2) / l ength ( r e a l ( encounter ) ) ;f i t 2 = sum( ( imag ( encounter )−imag ( out ) ) .^2) / l ength ( imag ( encounter ) ) ;f i t = ( f i t 1+f i t 2 ) /2 ;

catch% i f the v a r i a b l e s can ' t generate a TF then the f i t va lue f o r the se% va r i a b l e s i s s e t to nanf i t = nan ;

end

end

Code E.4.2: Above is the source code implemented in MATLAB for the GA with 1 example basedTF using only simulated data for training and validation. The program demands that an integernamed fold is pre-initialized and within the range of 1-10. The code utilized the function presentedin appendix E.4.3.

90

Page 92: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.4.3 Function For Validating The Transfer Function

f unc t i on f i t n e s s = ValidateMyTFs ( Rol l ing ,Waves , Speed , DirectTF , InDirectTF )

encounter_f i t = 0 ;motion_fit = 0 ;Perc = 0 ;

Ro l l i ng = Ro l l i ng ( : , 1 ) ;Hs = Waves (1 , 1 ) ;Tp = Waves (2 , 1 ) ;Beta = Waves (3 , 1 ) ;%Beta = Beta ∗( p i /180) ;U = mean( Speed ) ;U = U ∗ 0 .5144443101 ; %convert to m/ s

g = 9 . 8 2 ;

[ row , ~] = s i z e ( Ro l l i ng ) ;w_lim = 2 ;w_step = w_lim/row ;w = w_step : w_step : w_lim ;omega_0 = (2∗ pi ) /Tp ;T1 = (2∗ pi ) /(1 .2957∗omega_0) ;ITTC = @(x ) ( (173∗ (Hs^2) /(T1^4) ) . / ( x .^5) ) .∗ exp (−((691/(T1^4) ) . / ( x .^4) ) ) ;

EncounterSpectrum = ITTC(w) . / ( abs (1−((2.∗w.∗U) . / ( g ) ) ∗ cos ( Beta ) ) ) ;EncounterSpectrum = EncounterSpectrum ' ;

MotionSpectrum = f f t ( Ro l l i ng ) ;Y = f f t ( Ro l l i ng ) ;

Ts = w_step ;%.25 ;

Data_Direct = iddata (MotionSpectrum , EncounterSpectrum , Ts ) ;Data_Inverse = iddata ( EncounterSpectrum , MotionSpectrum , Ts ) ;

%Check i f encounterspectrum s h a l l be va l i da t edi f ( isempty ( InDirectTF ) == 0)

[~ , encounter_f i t ] = compare ( Data_Inverse , InDirectTF ) ;end

%Check i f motionspectrum and r o l l i n g s h a l l be va l i da t edi f ( isempty ( DirectTF ) == 0)

[ Y_Dirr , motion_fit ] = compare ( Data_Direct , DirectTF ) ;Out_Dirr = Y_Dirr . y ;Perc = 100−100∗sum( abs ( Rol l ing− i f f t (Out_Dirr ) ) .^2) /sum( abs ( Ro l l i ng ) .^2) ;

end

f i t n e s s = [ encounter_f i t motion_fit Perc ] ' ;

end

Code E.4.3: The above is the source code utilized by all TF methods to obtain the �tness value ofthe estimation obtain for each case.

91

Page 93: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.4.4 Present Loop And Genetic Algorithm Result Trained With One Example

c l cc l e a r%c l o s e a l l

f i l ename = ' Present_loop_GA_result . mat ' ;

% Check t h i s f i l e have been compiled be f o r e and i f so load r e s u l t si f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )

% s e l e c t i f the f i g u r e s s h a l l be f o r the r epor t o f notPlot_For_Report = true ;

e l s e% Load r e s u l t s anew% s e l e c t i f the f i g u r e s s h a l l be f o r the r epor t o f notPlot_For_Report = f a l s e ;

% Execute the methods and s t o r e t h e i r r e s u l t sno_folds = 10 ;f o r f o l d = 1 : no_folds

Transfer_Function_Loop_1_exampletemp = FIT ( : , : ) ;temp = abs (100∗ ones ( s i z e ( temp) )−temp) ;Loop_val idat ion_di f f ( : , f o l d ) = mean( temp , 2 ) ;Loop_tra in ing_f it ( : , f o l d ) = [ f i t_encounter ; f i t_motion ; f i t _ r o l l i n g ] ;

Transfer_Function_GA_1_exampletemp = FIT ( : , : ) ;temp = abs (100∗ ones ( s i z e ( temp) )−temp) ;GA_validation_diff ( : , f o l d ) = mean( temp , 2 ) ;GA_training_fit ( : , f o l d ) = [ f i t_encounter ; f i t_motion ; f i t _ r o l l i n g ] ;

end

c l o s e a l lf i l ename = ' Present_loop_GA_result . mat ' ;save ( f i l ename )

end

%% Present the r e s u l t

i f ( Plot_For_Report )f i g u r e

e l s ef i g u r esubplot ( 3 , 1 , 1 )

end

hold ong r id onp lo t ( 1 : no_folds , Loop_train ing_f it ( 1 , : ) , ' k ' , 1 : no_folds , GA_training_fit ( 1 , : ) ,'−−r ' )t i t l e ( ' Tra in ing − encounter spectrum ' )x l ab e l ( ' f o ld ' )y l ab e l ( ' f i t n e s s ' )l egend ( ' loop ' , 'GA' )

i f ( Plot_For_Report )f i g u r e

e l s esubplot ( 3 , 1 , 2 )

endhold ong r id onp lo t ( 1 : no_folds , Loop_train ing_f it ( 2 , : ) , ' k ' , 1 : no_folds , GA_training_fit ( 2 , : ) ,'−−r ' )t i t l e ( ' Tra in ing − motion spectrum ' )

92

Page 94: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

x l ab e l ( ' f o ld ' )y l ab e l ( ' f i t n e s s ' )l egend ( ' loop ' , 'GA' )

i f ( Plot_For_Report )f i g u r e

e l s esubplot ( 3 , 1 , 3 )

endhold ong r id onp lo t ( 1 : no_folds , Loop_train ing_f it ( 3 , : ) , ' k ' , 1 : no_folds , GA_training_fit ( 3 , : ) ,'−−r ' )t i t l e ( ' Tra in ing − r o l l i n g ' )x l ab e l ( ' f o ld ' )y l ab e l ( ' f i t n e s s ' )l egend ( ' loop ' , 'GA' )

%%i f ( Plot_For_Report )

f i g u r ee l s e

f i g u r esubplot ( 3 , 1 , 1 )

endhold ong r id onp lo t ( 1 : no_folds , Loop_val idat ion_di f f ( 1 , : ) , ' k ' , 1 : no_folds , GA_validation_diff ( 1 , : )

,'−−r ' )t i t l e ( ' Va l idat i on − encounter spectrum ' )x l ab e l ( ' f o ld ' )y l ab e l ( ' Error (%) ' )l egend ( ' loop ' , 'GA' )

i f ( Plot_For_Report )f i g u r e

e l s esubplot ( 3 , 1 , 2 )

endhold ong r id onp lo t ( 1 : no_folds , Loop_val idat ion_di f f ( 2 , : ) , ' k ' , 1 : no_folds , GA_validation_diff ( 2 , : )

,'−−r ' )t i t l e ( ' Va l idat i on − motion spectrum ' )x l ab e l ( ' f o ld ' )y l ab e l ( ' Error (%) ' )l egend ( ' loop ' , 'GA' )

i f ( Plot_For_Report )f i g u r e

e l s esubplot ( 3 , 1 , 3 )

endhold ong r id onp lo t ( 1 : no_folds , Loop_val idat ion_di f f ( 3 , : ) , ' k ' , 1 : no_folds , GA_validation_diff ( 3 , : )

,'−−r ' )t i t l e ( ' Va l idat i on − r o l l i n g ' )x l ab e l ( ' f o ld ' )y l ab e l ( ' Error (%) ' )l egend ( ' loop ' , 'GA' )

rowbreak = '−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−';mean_loop_encounter_val_diff = [ 'Mean Loop Encounter Spectrum D i f f = ' num2str (mean

( Loop_val idat ion_di f f ( 1 , : ) ) ) ] ;mean_ga_encounter_val_diff = [ 'Mean GA Encounter Spectrum D i f f = ' num2str (mean(

GA_validation_diff ( 1 , : ) ) ) ] ;

mean_loop_motion_val_diff = [ 'Mean Loop Motion Spectrum D i f f = ' num2str (mean(Loop_val idat ion_di f f ( 2 , : ) ) ) ] ;

93

Page 95: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

mean_ga_motion_val_diff = [ 'Mean GA Motion Spectrum D i f f = ' num2str (mean(GA_validation_diff ( 2 , : ) ) ) ] ;

mean_loop_rol l ing_val_dif f = [ 'Mean Loop Ro l l i ng D i f f = ' num2str (mean(Loop_val idat ion_di f f ( 3 , : ) ) ) ] ;

mean_ga_roll ing_val_diff = [ 'Mean GA Ro l l i ng D i f f = ' num2str (mean(GA_validation_diff ( 3 , : ) ) ) ] ;

f p r i n t f ( [ rowbreak '\n ' . . .mean_loop_encounter_val_diff '\n ' . . .mean_ga_encounter_val_diff '\n ' . . .rowbreak '\n ' mean_loop_motion_val_diff '\n ' . . .mean_ga_motion_val_diff '\n ' . . .rowbreak '\n ' mean_loop_rol l ing_val_dif f '\n ' . . .mean_ga_roll ing_val_diff '\n ' . . .rowbreak ] )

Code E.4.4: Above is the source code implemented in MATLAB for the retrieving the �tnessvalue, calculate the MAE, and present the result obtained from the 10-fold cross-validation resultgenerated by the previous two source code examples (E.4.1 & E.4.2).

94

Page 96: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.4.5 Genetic Algorithm And Several Examples Based

%c l c%c l e a r v a r s −except f o l d%c l o s e a l lwarning ( ' o f f ' , ' a l l ' ) ;

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )%f o l d = 1 ;d i sp ( f o l d )

Resu l t_fo lder = ' Resu l t s / ' ;

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )%f o l d = 1 ;d i sp ( f o l d )f i l ename = [ Resu l t_fo lder ' Transfer_Function_GA_Several_examples_fold_ ' num2str (

f o l d ) ' . mat ' ] ;

%Check i f the v a r i a b l e s have been save from a prev ious t e s ti f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )

%The va r i a b l e s have not been saved to run the t e s te l s e

f o l d e r = ' Separated data / ' ;

%% −−−−−−−−−−−−−−−−−−−−−−−− INITIALIZE −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−load ( [ f o l d e r ' Rolling_Train_fold_ ' num2str ( f o l d ) ] ) ;Ro l l i ng = Ro l l i n g t r a i n ;load ( [ f o l d e r ' Rudder_Train_fold_ ' num2str ( f o l d ) ] ) ;Rudder = Ruddertrain ;load ( [ f o l d e r ' Pitch_Train_fold_ ' num2str ( f o l d ) ] ) ;Pitch = P i t ch t r a i n ;load ( [ f o l d e r 'Waves_Train_fold_ ' num2str ( f o l d ) ] ) ;Waves = Wavestrain ;load ( [ f o l d e r ' Speed_Train_fold_ ' num2str ( f o l d ) ] ) ;Cont_spd = Speedtra in ;

load ( [ f o l d e r ' Rolling_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r 'Rudder_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r ' Pitch_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r 'Waves_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r ' Speed_Val_fold_ ' num2str ( f o l d ) ] ) ;

d i sp ( ' data loaded ' )

Waves ( 3 , : ) = Waves ( 3 , : ) ∗( p i /180) ;Wavesval ( 3 , : ) = Wavesval ( 3 , : ) ∗( p i /180) ;

hours = 0 . 5 ;minute = hours ∗60 ;

[ Samples , Cases ] = s i z e ( Ro l l i ng ) ;

f o r Case = 1 : CasesU(Case ) = mean(Cont_spd ( : , Case ) ) ; %Average

sh ip speed i s constant f o r a l l the dataU(Case ) = U(Case ) ∗ 0 .5144443101 ; %convert to m/ s

end

g = 9 . 8 2 ; %grav i ty constantw_lim = 2 ;

95

Page 97: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

w_step = w_lim/Samples ;w = w_step : w_step : w_lim ; %Frequency vec to r

Ts = w_step ;%.25 ; %Sampling time o f the data i s a l s oconstant

Hs = Waves ( 1 , : ) ;Tp = Waves ( 2 , : ) ;Beta = Waves ( 3 , : ) ;

%Setup Wave Spectrum (ITTC)omega_0 =@(k ) (2∗ pi ) . /Tp(k ) ;T1 = @(k ) (2∗ pi ) . / ( 1 . 2 9 5 7 . ∗ omega_0(k ) ) ;ITTC = @(x , k ) ( (173∗ (Hs(k ) ^2) . / (T1(k ) ^4) ) . / ( x .^5) ) .∗ exp (−((691 ./(T1(k ) ^4) ) . / ( x

.^4) ) ) ;

%Use Tr i s tan Perez c a l c u l a t i o n s to r e t r i e v e the EncounterSpectrum%This i s the input o f the Trans fe r func t i on f o r the Di rec t Method%and output f o r the Trans fe r Function f o r the In−d i r e c t method%The output f o r the Trans fe r func t i on in Di rec t method i s g iven%by the motion spectrum f o r the r o l l i n g , which i s r e t r i e v e d with f f t .%And the input f o r the in−d i r e c t t r a n s f e r func t i on i s a l s o the motion%spectrumf o r k = 1 : Cases

ktemp = ITTC(w, k ) . / ( abs (1−((2.∗w.∗U(k ) ) . / ( g ) ) .∗ cos ( Beta (k ) ) ) ) ;i f k == 1

EncounterSpectrum = temp ' ;MotionSpectrum = f f t ( Ro l l i ng ( : , k ) ) ;

e l s eEncounterSpectrum = [ EncounterSpectrum temp ' ] ;MotionSpectrum = [ MotionSpectrum f f t ( Ro l l i ng ( : , k ) ) ] ;

endend

nvars = 400 ; %number o f v a r i a b l e s to es t imate with the GA ( nvars = 200−> 50r e a l and 50 complex numerators , and 50 r e a l and 50 complex denominators )

%Setup the GAga_opts = gaopt imset (@ga) ;ga_opts . Display = ' i t e r ' ;ga_opts . Popu lat ionS ize = 10 ;ga_opts . TimeLimit = minute ∗60 ;ga_opts . Generat ions = i n f ;ga_opts . PopInitRange = [ −1 ; 1 ] ;ga_opts . TolFun = 1e−20;ga_opts . TolCon = 1e−20;ga_opts . Sta l lGenLimit = 1000 ;

%%========================================================================================

disp ( ' Ca l cu l a t ing Di rec t TF' ) ;

% %% FIND DIRECT TF% [ x , ~ ] = ga ( @f i tnes s_di r r , nvars , ga_opts ) ;% nom = nvars /4 ;% a = x ( 1 , 1 :nom) + x (1 , (nom+1) :2∗nom) ∗1 i ;% b = x (1 ,2∗nom+1:3∗nom) + x (1 ,3∗nom + 1 : nvars ) ∗1 i ;%% DirectTF = t f (b , a , ' Ts ' , Ts , ' va r i ab l e ' , ' z^−1') ;%

%% FIND INDIRECT TF%Setup the GAdisp ( ' Ca l cu l a t ing In−Direc t TF' ) ;

[ y , ~ ] = ga ( @f i tness_in_dirr , nvars , ga_opts ) ;

96

Page 98: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

nom = nvars /4 ;a = y ( 1 , 1 :nom) + y (1 , (nom+1) :2∗nom) ∗1 i ;b = y (1 ,2∗nom+1:3∗nom) + y (1 ,3∗nom + 1 : nvars ) ∗1 i ;% a = y (1 , 1 : 2∗nom) ;% b = y (1 ,2∗nom+1: nvars ) ;

InDirectTF = t f (b , a , ' Ts ' , Ts , ' va r i ab l e ' , ' z^−1') ;

%% VALIDATE THE TF[~ , c o l ] = s i z e (Wavesval ) ;f o r k = 1 : c o l

FIT ( : , k ) = ValidateMyTFs ( Ro l l i n gva l ( : , k ) ,Wavesval ( : , k ) , Speedval ( : , k ) , [ ] ,InDirectTF ) ;

endsave ( f i l ename )

end

%% DIRECT FITNESS FUNCTIONfunc t i on FIT = f i t n e s s_d i r r ( x )%Retr i eve s p e c i f i c v a r i a b l e s from workspacen = eva l i n ( ' base ' , ' nvars ' ) ;t s = eva l i n ( ' base ' , ' Ts ' ) ;EncounterSpectrum = eva l i n ( ' base ' , ' EncounterSpectrum ' ) ;MotionSpectrum = eva l i n ( ' base ' , ' MotionSpectrum ' ) ;

[~ , c o l ] = s i z e (MotionSpectrum ) ;FIT = 0 ;f o r k = 1 : c o l

%Setup the Input output data f o r the d i r e c t methodmotion = MotionSpectrum ( : , k ) ;encounter = EncounterSpectrum ( : , k ) ;t ry

data = iddata (motion , encounter , ' Ts ' , t s ) ;nom = n/4 ;a = x ( 1 , 1 :nom) + x (1 , (nom+1) :2∗nom) ∗1 i ;b = x (1 ,2∗nom+1:3∗nom) + x (1 ,3∗nom + 1 : n) ∗1 i ;

%try to f i nd a TF us ing the va r i ab l e s , and c a l c u l a t e the f i tt f 1 = t f (b , a , ' Ts ' , ts , ' va r i ab l e ' , ' z^−1') ;[~ , f i t ] = compare ( data , t f 1 ) ;f i t = abs ( f i t −100) ;

catch% i f the v a r i a b l e s can ' t generate a TF then the f i t va lue f o r the se% va r i a b l e s i s s e t to nanf i t = nan ;

endFIT = FIT + f i t ;

endFIT = FIT / co l ;end

%% IN−DIRECT FITNESS FUNCTIONfunc t i on FIT = f i tn e s s_ in_d i r r ( x )%Retr i eve s p e c i f i c v a r i a b l e s from workspacen = eva l i n ( ' base ' , ' nvars ' ) ;

EncounterSpectrum = eva l i n ( ' base ' , ' EncounterSpectrum ' ) ;MotionSpectrum = eva l i n ( ' base ' , ' MotionSpectrum ' ) ;

[~ , c o l ] = s i z e ( EncounterSpectrum ) ;FIT = 0 ;f o r k = 1 : c o l

%Setup the Input output data f o r the d i r e c t methodmotion = MotionSpectrum ( : , k ) ;encounter = EncounterSpectrum ( : , k ) ;t ry

97

Page 99: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

nom = n/4 ;a = x ( 1 , 1 :nom) + x (1 , (nom+1) :2∗nom) ∗1 i ;b = x (1 ,2∗nom+1:3∗nom) + x (1 ,3∗nom + 1 : n) ∗1 i ;out = f i l t e r (b , a , motion ) ;

f i t 1 = sum( ( r e a l ( encounter )−r e a l ( out ) ) .^2) / l ength ( r e a l ( encounter ) ) ;f i t 2 = sum( ( imag ( encounter )−imag ( out ) ) .^2) / l ength ( imag ( encounter ) ) ;f i t = ( f i t 1+f i t 2 ) /2 ;

catch% i f the v a r i a b l e s can ' t generate a TF then the f i t va lue f o r the se% va r i a b l e s i s s e t to nanf i t = nan ;

endFIT = FIT + f i t ;

endFIT = FIT / co l ;end

Code E.4.5: Above is the source code implemented in MATLAB for the GA with several examplesbased TF using only simulated data for training and validation. The program demands that aninteger named fold is pre-initialized and within the range of 1-10. The code utilized the functionpresented in appendix E.4.3.

98

Page 100: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.4.6 Present Genetic Algorithm Result Trained With Several Examples

c l cc l e a rc l o s e a l l

f i l ename = ' Present_GA_several_examples_result . mat ' ;

% Check t h i s f i l e have been compiled be f o r e and i f so load r e s u l t si f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )e l s e

% Load r e s u l t s anew% Execute the methods and s t o r e t h e i r r e s u l t s

no_folds = 10 ;f o r f o l d = 1 : no_folds

f o l dTransfer_Function_GA_Several_examplestemp = FIT ( 1 , : ) ;temp = abs (100∗ ones ( s i z e ( temp) )−temp) ;D i f f e r e n c e ( : , f o l d ) = mean( temp , 2 ) ;

end

c l o s e a l lf i l ename = ' Present_GA_several_examples_result . mat ' ;save ( f i l ename )

end

%% Present the r e s u l t

f i g u r ehold ong r id onp lo t ( 1 : no_folds , D i f f e r e n c e ( 1 , : ) , ' k ' )t i t l e ( ' Va l idat i on − encounter spectrum ' )x l ab e l ( ' f o ld ' )y l ab e l ( ' Error (%) ' )

rowbreak = '−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−';mean_encounter_val_diff = [ 'Mean Encounter Spectrum D i f f = ' num2str (mean(

D i f f e r e n c e ( 1 , : ) ) ) ] ;

f p r i n t f ( [ rowbreak '\n ' mean_encounter_val_diff '\n ' rowbreak ] ) ;

Code E.4.6: Above is the source code implemented in MATLAB for the retrieving the �tnessvalue, calculate the MAE, and present the result obtained from the 10-fold cross-validation resultgenerated by the previous source code example (E.4.5).

99

Page 101: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.5 Feedforward Neural Network For Training And Validating With

Simulated Data

The following sections presents the code implemented for the FFNN solutions utilizing simulateddata.

E.5.1 Using Resilient Backpropagation

%c l c%c l e a r v a r s −except f o l d%c l o s e a l lwarning ( ' o f f ' , ' a l l ' ) ;rng ( ' s hu f f l e ' , ' tw i s t e r ' )

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )%f o l d = 1 ;d i sp ( f o l d )Resu l t_fo lder = ' Resu l t s / ' ;

f i l ename = [ Resu l t_fo lder 'ANN_with_RPROP_fold_' num2str ( f o l d ) ' . mat ' ] ;

%Check i f the v a r i a b l e s have been save from a prev ious t e s ti f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )%The va r i a b l e s have not been saved to run the t e s t

e l s ef o l d e r = ' Separated data / ' ;

%% −−−−−−−−−−−−−−−−−−−−−−−− INITIALIZE −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−load ( [ f o l d e r ' Rolling_Train_fold_ ' num2str ( f o l d ) ] ) ;Ro l l i ng = Ro l l i n g t r a i n ;load ( [ f o l d e r ' Rudder_Train_fold_ ' num2str ( f o l d ) ] ) ;Rudder = Ruddertrain ;load ( [ f o l d e r ' Pitch_Train_fold_ ' num2str ( f o l d ) ] ) ;Pitch = P i t ch t r a i n ;load ( [ f o l d e r 'Waves_Train_fold_ ' num2str ( f o l d ) ] ) ;Waves = Wavestrain ;load ( [ f o l d e r ' Speed_Train_fold_ ' num2str ( f o l d ) ] ) ;Speed = Speedtra in ;

load ( [ f o l d e r ' Rolling_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r 'Rudder_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r ' Pitch_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r 'Waves_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r ' Speed_Val_fold_ ' num2str ( f o l d ) ] ) ;

% Convert degree s to rad iansWaves ( 3 , : ) = Waves ( 3 , : ) ∗( p i /180) ;Wavesval ( 3 , : ) = Wavesval ( 3 , : ) ∗( p i /180) ;

d i sp ( ' done gather ing data ' )

% s e t t r a i n i n g timehours = 0 . 5 ;minute = hours ∗60 ;

[ Samples , c o l ] = s i z e ( Ro l l i ng ) ;

Ts = . 2 5 ; %Sampling time o f the datag = 9 . 8 2 ; %grav i ty constantw_lim = 2 ;w_step = w_lim/Samples ;w = w_step : w_step : w_lim;%Frequency vec to r

% Prepare inputs and outputs f o r the networkIn = [ Ro l l i ng Ro l l i n gva l ; Rudder Rudderval ; Pitch Pi tchva l ] ;[~ , co l 2 ] = s i z e ( In ) ;Va l idat ionVector = @(k ) [ Ro l l i n gva l ( : , k ) ; Rudderval ( : , k ) ; P i t chva l ( : , k ) ] ;

100

Page 102: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Tr = [Waves Wavesval ] ;

%% −−−−−−−−−−−−−−−−−−−−− BACK PROPAGATION NETWORK −−−−−−−−−−−−−−−−−−−−−−−−−

% se t l a y e r s and neuronsHiddenLayers =3;n = [ ] ;f o r k = HiddenLayers :−1:1

n = [ n 3^(k+1) ] ;end

% setup netnetBP = feed forwardnet (n , ' t ra in rp ' ) ;netBP . div ideFcn = ' d iv ide ind ' ;netBP . divideParam .Q = co l ;netBP . divideParam . t ra in Ind = 1 : c o l ;netBP . divideParam . va l Ind = co l +1: co l 2 ;netBP . divideParam . t e s t Ind = co l 2 : co l 2 ;netBP . trainParam .mu_dec = 0 . 0 1 ;netBP . trainParam .mu_inc = 1 . 1 ;netBP . trainParam . epochs = 5000 ; % epochnetBP . trainParam . goa l = 0 ; % ob j e c t i v e MSEnetBP . trainParam . time = minute ∗60 ;netBP . trainParam . max_fail = 100 ;

% s e t a c t i v a t i o n func t i on snetGA = feed fo rwardnet (n , ' t ra in rp ' ) ;f o r k = 1 : HiddenLayers

netGA . l a y e r s {k } . t rans f e rFcn = ' tans ig ' ;endnetGA . l a y e r s {HiddenLayers+1}. t rans f e rFcn = ' pure l in ' ;

netBP = con f i gu r e (netBP , In , Tr ) ;netBP . performFcn = 'mse ' ;

% t r a i n net based on r e s i l i e n t backpropagat ion[ netBP , t r ] = t r a i n (netBP , In , Tr ) ;

%% −−−−−−−−−−−−−−−−−−−− VALIDATE NETWORK −−−−−−−−−−−−−−−−−−−−−−−−−−−−

% Retr i eve amounts o f v a l i d a t i o n ca s e s[~ , c o l ] = s i z e (Wavesval ) ;

% loop f o r each va l i d a t i o n casef o r k = 1 : c o l

% Retr i eve est imated va lue s f o r cur r ent caseest_BP = netBP( Val idat ionVector ( k ) ) ;est_Hs = est_BP (1 , 1 ) ;est_Tp = est_BP (2 , 1 ) ;est_Beta = est_BP (3 , 1 ) ;

% est imated va lues in ve c t o r sest_Hs_vec (k ) = est_Hs ;est_Tp_vec (k ) = est_Tp ;est_Beta_vec (k ) = est_Beta ∗(180/ p i ) ;

% Sca l e the encounter ang le proper ly . I f the ac tua l ang le i s 0 then% i t must be converted to 2∗ pi s i n c e i t w i l l y i e l d nan in the% f i t n e s s c a l c u l a t i o n otherw i se . The est imated ang le i s always% sca l ed with 2∗ pi to ensure that i t i s c o r r e c t l y compared to the% actua l va lue . For example i f act i s p i and est imated i s 3∗ pi then% the f i t n e s s should y i e l d 100% f i t not 300%.% s i n c e 3∗ pi rad ians == pi rad iansi f ( est_Beta > 2∗ pi )

est_Beta = mod( est_Beta ,2∗ pi ) ;end

101

Page 103: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

i f (Wavesval (3 , k ) == 0)Wavesval (3 , k ) = 2∗ pi ;i f ( est_Beta < pi )

est_Beta = est_Beta + 2∗ pi ;end

e l s e i f ( est_Beta == 0)est_Beta = 2∗ pi ;i f (Wavesval (3 , k ) > pi )

Wavesval (3 , k ) = Wavesval (3 , k ) + 2∗ pi ;end

end

% Calcu la te the f i t n e s s o f est imated va lue sHs_fit ( k ) = 100∗ abs ( est_Hs/Wavesval (1 , k ) ) ;Tp_fit ( k ) = 100∗ abs ( est_Tp/Wavesval (2 , k ) ) ;Beta_f it ( k ) = 100∗ abs ( est_Beta/Wavesval (3 , k ) ) ;

Hscomp(k , 1 : 2 ) = [ Wavesval (1 , k ) est_Hs ] ;variable_BP_fit = ( ( Hs_fit + Tp_fit + Beta_f it ) /3) ;

% Ca lcu la te the d i f f e r e n c e or percentage e r r o rHs_dif f = abs (100−Hs_fit ( k ) ) ;Tp_diff = abs (100−Tp_fit ( k ) ) ;Beta_di f f = abs (100−Beta_fit ( k ) ) ;

% s t o r e e r r o rPerc ( : , k ) = [ Hs_dif f ; Tp_diff ; Beta_di f f ] ;

end

% ca l c u l a r e average and median e r r o r sMax_diff = max( Perc ( : ) ) ;Min_diff = min ( Perc ( : ) ) ;Average_dif f = mean( Perc ( : ) ) ;Median_diff = median ( Perc ( : ) ) ;s = s i z e ( Perc ) ;Better_than_avg = 100∗(sum( Perc ( : )<=Average_dif f ) ) /( s (1 ) ∗ s (2 ) ) ;

Average_Hs_diff = mean( Perc ( 1 , : ) ) ;Median_Hs_diff = median ( Perc ( 1 , : ) ) ;Min_Hs_diff = min ( Perc ( 1 , : ) ) ;Max_Hs_diff = max( Perc ( 1 , : ) ) ;

Average_Tp_diff = mean( Perc ( 2 , : ) ) ;Median_Tp_diff = median ( Perc ( 2 , : ) ) ;Min_Tp_diff = min ( Perc ( 2 , : ) ) ;Max_Tp_diff = max( Perc ( 2 , : ) ) ;

Average_Beta_diff = mean( Perc ( 3 , : ) ) ;Median_Beta_diff = median ( Perc ( 3 , : ) ) ;Min_Beta_diff = min ( Perc ( 3 , : ) ) ;Max_Beta_diff = max( Perc ( 3 , : ) ) ;

Result = [ ' \ n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nFOLD = 'num2str ( f o l d ) '\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nBP\nAverage Hs d i f f e r e n c e = ' num2str ( Average_Hs_diff ) '\ nMedian Hs d i f f e r e n c e= ' num2str (Median_Hs_diff ) '%%\nMin Hs d i f f e r e n c e = ' num2str (Min_Hs_diff) '%%\nMax Hs d i f f e r e n c e = ' num2str (Max_Hs_diff ) '%%\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nAverage Tp d i f f e r e n c e =' num2str ( Average_Tp_diff ) '\ nMedian Tp d i f f e r e n c e = ' num2str (

Median_Tp_diff ) '%%\nMin Tp d i f f e r e n c e = ' num2str (Min_Tp_diff ) '%%\nMax Tpd i f f e r e n c e = ' num2str (Max_Tp_diff ) '%%\n

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nAverage Beta d i f f e r e n c e= ' num2str ( Average_Beta_diff ) '\ nMedian Beta d i f f e r e n c e = ' num2str (Median_Beta_diff ) '%%\nMin Beta d i f f e r e n c e = ' num2str (Min_Beta_diff ) '%%\nMax Beta d i f f e r e n c e = ' num2str (Max_Beta_diff ) '%%\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− ' '\ nAverage va r i ab l ed i f f e r e n c e = ' num2str ( Average_dif f ( 1 , 1 ) ) '\ nMedian va r i ab l e d i f f e r e n c e = 'num2str ( Median_diff ( 1 , 1 ) ) '%%\nMaximum va r i ab l e d i f f e r e n c e = ' num2str (

Max_diff ) '%%\nMinimum va r i ab l e d i f f e r e n c e = ' num2str ( Min_diff ) '%%\n

102

Page 104: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nPerforms Better ThanAverage : ' num2str ( Better_than_avg ) '%% of the Time\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\n ' ] ;

save ( f i l ename )end

f p r i n t f ( Result )

Hscomp ( : , 3 ) = Perc ( 1 , : ) ' ;

f i g u r e ( ' name ' , [ 'ANN FOLD = ' num2str ( f o l d ) ] )subplot ( 3 , 2 , 1 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( [ 'Mean d i f f = ' num2str ( Average_Hs_diff ) ] )p l o t ( 1 : co l ,100∗ ones (1 , c o l ) , ' k ' )p l o t ( 1 : co l ,(100−sum( Perc ( 1 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )p l o t ( 1 : co l , Hs_fit , ' r ' )p l o t ( 1 : co l ,(100+sum( Perc ( 1 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )l egend ( ' Target ' , ' Average Bound ' , ' Hs ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( ' F i tne s s (%) ' )

subplot ( 3 , 2 , 3 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( [ 'Mean d i f f = ' num2str ( Average_Tp_diff ) ] )p l o t ( 1 : co l ,100∗ ones (1 , c o l ) , ' k ' )p l o t ( 1 : co l ,(100−sum( Perc ( 2 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )p l o t ( 1 : co l , Tp_fit , ' r ' )p l o t ( 1 : co l ,(100+sum( Perc ( 2 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )l egend ( ' Target ' , ' Average Bound ' , 'Tp ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( ' F i tne s s (%) ' )

subplot ( 3 , 2 , 5 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( [ 'Mean d i f f = ' num2str ( Average_Beta_diff ) ] )p l o t ( 1 : co l ,100∗ ones (1 , c o l ) , ' k ' )p l o t ( 1 : co l ,(100−sum( Perc ( 3 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )p l o t ( 1 : co l , Beta_fit , ' r ' )p l o t ( 1 : co l ,(100+sum( Perc ( 3 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )l egend ( ' Target ' , ' Average Bound ' , ' Beta ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( ' F i tne s s (%) ' )

subplot ( 3 , 2 , 2 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( [ 'MSE = ' num2str (mean ( ( est_Hs_vec−Wavesval ( 1 , : ) ) .^2) ) ] )p l o t ( 1 : co l , Wavesval ( 1 , : ) , ' k ' )p l o t ( 1 : co l , est_Hs_vec , ' r ' )l egend ( ' Target ' , ' Hs ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( 'Hs (m) ' )

subplot ( 3 , 2 , 4 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( [ 'MSE = ' num2str (mean ( ( est_Tp_vec−Wavesval ( 2 , : ) ) .^2) ) ] )p l o t ( 1 : co l , Wavesval ( 2 , : ) , ' k ' )p l o t ( 1 : co l , est_Tp_vec , ' r ' )

103

Page 105: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

l egend ( ' Target ' , 'Tp ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( 'Tp ( sec ) ' )

subplot ( 3 , 2 , 6 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( [ 'MSE = ' num2str (mean ( ( est_Beta_vec ∗( p i /180)−Wavesval ( 3 , : ) ) .^2) ) ] )p l o t ( 1 : co l , Wavesval ( 3 , : ) ∗(180/ p i ) , ' k ' )p l o t ( 1 : co l , est_Beta_vec , ' r ' )l egend ( ' Target ' , ' Beta ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( ' Beta ( deg ) ' )

Code E.5.1: The above source code was implemented in MATLAB to estimate the wave parametersusing a FFNN trained with RPROP. The program demands that an integer named fold is pre-initialized and within the range of 1-10

104

Page 106: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.5.2 Using Genetic Algorithm

%c l c%c l e a r v a r s −except f o l d%c l o s e a l lwarning ( ' o f f ' , ' a l l ' ) ;rng ( ' s hu f f l e ' , ' tw i s t e r ' )

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )%f o l d = 1 ;d i sp ( f o l d )

Resu l t_fo lder = ' Resu l t s / ' ;

f i l ename = [ Resu l t_fo lder 'ANN_with_GA_fold_' num2str ( f o l d ) ' . mat ' ] ;

%Check i f the v a r i a b l e s have been save from a prev ious t e s ti f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )%The va r i a b l e s have not been saved to run the t e s t

e l s ef o l d e r = ' Separated data / ' ;

%% −−−−−−−−−−−−−−−−−−−−−−−− INITIALIZE −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−load ( [ f o l d e r ' Rolling_Train_fold_ ' num2str ( f o l d ) ] ) ;Ro l l i ng = Ro l l i n g t r a i n ;load ( [ f o l d e r ' Rudder_Train_fold_ ' num2str ( f o l d ) ] ) ;Rudder = Ruddertrain ;load ( [ f o l d e r ' Pitch_Train_fold_ ' num2str ( f o l d ) ] ) ;Pitch = P i t ch t r a i n ;load ( [ f o l d e r 'Waves_Train_fold_ ' num2str ( f o l d ) ] ) ;Waves = Wavestrain ;load ( [ f o l d e r ' Speed_Train_fold_ ' num2str ( f o l d ) ] ) ;Speed = Speedtra in ;

load ( [ f o l d e r ' Rolling_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r 'Rudder_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r ' Pitch_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r 'Waves_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r ' Speed_Val_fold_ ' num2str ( f o l d ) ] ) ;

% Convert degree s to rad iansWaves ( 3 , : ) = Waves ( 3 , : ) ∗( p i /180) ;Wavesval ( 3 , : ) = Wavesval ( 3 , : ) ∗( p i /180) ;

d i sp ( ' done gather ing data ' )

% s e t t r a i n i n g timehours = 0 . 5 ;minute = hours ∗60 ;

[ Samples , Cases ] = s i z e ( Ro l l i ng ) ;

Ts = . 2 5 ; %Sampling time o f the data i s a l s o constantg = 9 . 8 2 ; %grav i ty constantw_lim = 2 ;w_step = w_lim/Samples ;w = w_step : w_step : w_lim ; %Frequency vec to r

% Prepare inputs and outputs f o r the networkIn = [ Ro l l i ng ; Rudder ; Pitch ] ;[~ , co l 2 ] = s i z e ( In ) ;Va l idat ionVector = @(k ) [ Ro l l i n gva l ( : , k ) ; Rudderval ( : , k ) ; P i t chva l ( : , k ) ] ;Tr = Waves ;

%% −−−−−−−−−−−−−−−−−−−−− GENETIC ALGORITTHM NETWORK −−−−−−−−−−−−−−−−−−−−−−−−−

% se t l a y e r s and neuronsHiddenLayers =3;

105

Page 107: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

n = [ ] ;f o r k = HiddenLayers :−1:1

n = [ n 3^(k+1) ] ;end

% se t a c t i v a t i o n func t i on snetGA = feed fo rwardnet (n , ' t ra in rp ' ) ;f o r k = 1 : HiddenLayers

netGA . l a y e r s {k } . t rans f e rFcn = ' tans ig ' ;endnetGA . l a y e r s {HiddenLayers+1}. t rans f e rFcn = ' pure l in ' ;

% prepare netnetGA = con f i gu r e (netGA , In , Tr ) ;[ row , ~ ] = s i z e ( getwb (netGA) ) ;nvars = row ;

%Setup the GAga_opts = gaopt imset (@ga) ;ga_opts . TolFun = 1e−10;ga_opts . Display = ' i t e r ' ;ga_opts . Popu lat ionS ize = 100 ;ga_opts . TimeLimit = minute ∗60 ;ga_opts . Generat ions = 500 ;ga_opts . PopInitRange = [ −1 ; 1 ] ;

%s t a r t t r a i n i n g the net[ x , ~ ] = ga ( @f i tnes s , nvars , ga_opts ) ;

%s e t f i n a l c on f i g u r a t i on based on GA t r a i n i n gnetGA = setwb (netGA , x ' ) ;

%% −−−−−−−−−−−−−−−−−−−− VALIDATE NETWORK −−−−−−−−−−−−−−−−−−−−−−−−−−−−

% Retr i eve amounts o f v a l i d a t i o n ca s e s[~ , c o l ] = s i z e (Wavesval ) ;

% loop f o r each va l i d a t i o n casef o r k = 1 : c o l

% Retr i eve est imated va lue s f o r cur r ent caseest_GA = netGA( Val idat ionVector ( k ) ) ;est_Hs = est_GA(1 ,1 ) ;est_Tp = est_GA(2 , 1 ) ;est_Beta = est_GA(3 ,1 ) ;

% est imated va lues in ve c t o r sest_Hs_vec (k ) = est_Hs ;est_Tp_vec (k ) = est_Tp ;est_Beta_vec (k ) = est_Beta ∗(180/ p i ) ;

% Sca l e the encounter ang le proper ly . I f the ac tua l ang le i s 0 then% i t must be converted to 2∗ pi s i n c e i t w i l l y i e l d nan in the% f i t n e s s c a l c u l a t i o n otherw i se . The est imated ang le i s always% sca l ed with 2∗ pi to ensure that i t i s c o r r e c t l y compared to the% actua l va lue . For example i f act i s p i and est imated i s 3∗ pi then% the f i t n e s s should y i e l d 100% f i t not 300%.% s i n c e 3∗ pi rad ians == pi rad iansi f ( est_Beta > 2∗ pi )

est_Beta = mod( est_Beta ,2∗ pi ) ;endi f (Wavesval (3 , k ) == 0)

Wavesval (3 , k ) = 2∗ pi ;i f ( est_Beta < pi )

est_Beta = est_Beta + 2∗ pi ;end

e l s e i f ( est_Beta == 0)est_Beta = 2∗ pi ;i f (Wavesval (3 , k ) > pi )

106

Page 108: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Wavesval (3 , k ) = Wavesval (3 , k ) + 2∗ pi ;end

end

% Calcu la te the f i t n e s s o f est imated va lue sHs_fit ( k ) = 100∗ abs ( est_Hs/Wavesval (1 , k ) ) ;Tp_fit ( k ) = 100∗ abs ( est_Tp/Wavesval (2 , k ) ) ;Beta_f it ( k ) = 100∗ abs ( est_Beta/Wavesval (3 , k ) ) ;

Hscomp(k , 1 : 2 ) = [ Wavesval (1 , k ) est_Hs ] ;variable_BP_fit = ( ( Hs_fit + Tp_fit + Beta_f it ) /3) ;

% Ca lcu la te the d i f f e r e n c e or percentage e r r o rHs_dif f = abs (100−Hs_fit ( k ) ) ;Tp_diff = abs (100−Tp_fit ( k ) ) ;Beta_di f f = abs (100−Beta_fit ( k ) ) ;

% s t o r e e r r o rPerc ( : , k ) = [ Hs_dif f ; Tp_diff ; Beta_di f f ] ;

end

% ca l c u l a r e average and median e r r o r sMax_diff = max( Perc ( : ) ) ;Min_diff = min ( Perc ( : ) ) ;Average_dif f = mean( Perc ( : ) ) ;Median_diff = median ( Perc ( : ) ) ;s = s i z e ( Perc ) ;Better_than_avg = 100∗(sum( Perc ( : )<=Average_dif f ) ) /( s (1 ) ∗ s (2 ) ) ;

Average_Hs_diff = mean( Perc ( 1 , : ) ) ;Median_Hs_diff = median ( Perc ( 1 , : ) ) ;Min_Hs_diff = min ( Perc ( 1 , : ) ) ;Max_Hs_diff = max( Perc ( 1 , : ) ) ;

Average_Tp_diff = mean( Perc ( 2 , : ) ) ;Median_Tp_diff = median ( Perc ( 2 , : ) ) ;Min_Tp_diff = min ( Perc ( 2 , : ) ) ;Max_Tp_diff = max( Perc ( 2 , : ) ) ;

Average_Beta_diff = mean( Perc ( 3 , : ) ) ;Median_Beta_diff = median ( Perc ( 3 , : ) ) ;Min_Beta_diff = min ( Perc ( 3 , : ) ) ;Max_Beta_diff = max( Perc ( 3 , : ) ) ;

Result = [ ' \ n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nFOLD = 'num2str ( f o l d ) '\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nBP\nAverage Hs d i f f e r e n c e = ' num2str ( Average_Hs_diff ) '\ nMedian Hs d i f f e r e n c e= ' num2str (Median_Hs_diff ) '%%\nMin Hs d i f f e r e n c e = ' num2str (Min_Hs_diff) '%%\nMax Hs d i f f e r e n c e = ' num2str (Max_Hs_diff ) '%%\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nAverage Tp d i f f e r e n c e =' num2str ( Average_Tp_diff ) '\ nMedian Tp d i f f e r e n c e = ' num2str (

Median_Tp_diff ) '%%\nMin Tp d i f f e r e n c e = ' num2str (Min_Tp_diff ) '%%\nMax Tpd i f f e r e n c e = ' num2str (Max_Tp_diff ) '%%\n

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nAverage Beta d i f f e r e n c e= ' num2str ( Average_Beta_diff ) '\ nMedian Beta d i f f e r e n c e = ' num2str (Median_Beta_diff ) '%%\nMin Beta d i f f e r e n c e = ' num2str (Min_Beta_diff ) '%%\nMax Beta d i f f e r e n c e = ' num2str (Max_Beta_diff ) '%%\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− ' '\ nAverage va r i ab l ed i f f e r e n c e = ' num2str ( Average_dif f ( 1 , 1 ) ) '\ nMedian va r i ab l e d i f f e r e n c e = 'num2str ( Median_diff ( 1 , 1 ) ) '%%\nMaximum va r i ab l e d i f f e r e n c e = ' num2str (

Max_diff ) '%%\nMinimum va r i ab l e d i f f e r e n c e = ' num2str ( Min_diff ) '%%\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nPerforms Better ThanAverage : ' num2str ( Better_than_avg ) '%% of the Time\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\n ' ] ;

save ( f i l ename )

107

Page 109: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

end

f p r i n t f ( Result )

Hscomp ( : , 3 ) = Perc ( 1 , : ) ' ;

f i g u r e ( ' name ' , [ ' Fold = ' num2str ( f o l d ) ] )subplot ( 3 , 2 , 1 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( num2str (mean( Hs_fit ( : ) ) ) )p l o t ( 1 : co l ,100∗ ones (1 , c o l ) , ' k ' )p l o t ( 1 : co l ,(100−sum( Perc ( 1 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )p l o t ( 1 : co l , Hs_fit , ' r ' )p l o t ( 1 : co l ,(100+sum( Perc ( 1 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )l egend ( ' Target ' , ' Average Bound ' , ' Hs ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( ' F i tne s s (%) ' )

subplot ( 3 , 2 , 3 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( num2str (mean( Tp_fit ( : ) ) ) )p l o t ( 1 : co l ,100∗ ones (1 , c o l ) , ' k ' )p l o t ( 1 : co l ,(100−sum( Perc ( 2 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )p l o t ( 1 : co l , Tp_fit , ' r ' )p l o t ( 1 : co l ,(100+sum( Perc ( 2 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )l egend ( ' Target ' , ' Average Bound ' , 'Tp ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( ' F i tne s s (%) ' )

subplot ( 3 , 2 , 5 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( num2str (mean( Beta_f it ( : ) ) ) )p l o t ( 1 : co l ,100∗ ones (1 , c o l ) , ' k ' )p l o t ( 1 : co l ,(100−sum( Perc ( 3 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )p l o t ( 1 : co l , Beta_fit , ' r ' )p l o t ( 1 : co l ,(100+sum( Perc ( 3 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )l egend ( ' Target ' , ' Average Bound ' , ' Beta ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( ' F i tne s s (%) ' )

%%

subplot ( 3 , 2 , 2 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( num2str ( Average_Hs_diff ) )p l o t ( 1 : co l , Wavesval ( 1 , : ) , ' k ' )p l o t ( 1 : co l , est_Hs_vec , ' r ' )l egend ( ' Target ' , ' Hs ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( 'Hs (m) ' )

subplot ( 3 , 2 , 4 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( num2str ( Average_Tp_diff ) )p l o t ( 1 : co l , Wavesval ( 2 , : ) , ' k ' )p l o t ( 1 : co l , est_Tp_vec , ' r ' )l egend ( ' Target ' , 'Tp ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( 'Tp ( sec ) ' )

108

Page 110: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

subplot ( 3 , 2 , 6 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( num2str ( Average_Beta_diff ) )p l o t ( 1 : co l , Wavesval ( 3 , : ) ∗(180/ p i ) , ' k ' )p l o t ( 1 : co l , est_Beta_vec , ' r ' )l egend ( ' Target ' , ' Beta ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( ' Beta ( deg ) ' )

%% −−−−−−−−−−−−−−−−−−−− FITNESS FUNCTION FOR GA −−−−−−−−−−−−−−−−−−−−−−−−−−−f unc t i on mse_calc = f i t n e s s ( x )netGA = eva l i n ( ' base ' , ' netGA ' ) ;inputs = eva l i n ( ' base ' , ' In ' ) ;t a r g e t s = eva l i n ( ' base ' , ' Tr ' ) ;% 'x ' conta in s the weights and b i a s e s vec to r% in row vecto r form as passed to i t by the% genetGAic a lgor i thm . This must be transposed% when being s e t as the weights and b i a s e s% vecto r f o r the netGAwork .% To s e t the weights and b i a s e s vec to r to the% one given as inputnetGA = setwb (netGA , x ' ) ;% To eva luate the ouputs based on the g iven% weights and b i a s e s vec to ry = netGA( inputs ) ;% Ca l cu l a t ing the mean squared e r r o r

[~ , c o l ] = s i z e ( t a r g e t s ) ;

f o r k = 1 : c o li f ( t a r g e t s (3 , k ) == 0)

t a r g e t s (3 , k ) = 2∗ pi ;y (3 , k ) = y (3 , k )+2∗pi ;

endend

One = ones ( s i z e ( t a r g e t s ) ) ;e r r = abs (One − ( y . / t a r g e t s ) ) ;mse_calc = 100∗mean( e r r ( : ) ) ;

end

Code E.5.2: The above source code was implemented in MATLAB to estimate the wave parametersusing a FFNN trained with GA. The program demands that an integer named fold is pre-initializedand within the range of 1-10

109

Page 111: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.6 Case Based Reasoning For Training And Validating With Simulated

Data

The following sections presents the code implemented for the CBR solutions utilizing simulateddata.

E.6.1 Using Euclidian Distance

%c l c%c l e a r v a r s −except f o l d Ro l l i ng Rudder Pitch Speed Yaw Surge Sway Ro l l i n gva l

Rudderval P i t chva l Speedval Yawval Surgeva l Swayvalc l o s e a l lwarning ( ' o f f ' , ' a l l ' ) ;rng ( ' s hu f f l e ' , ' tw i s t e r ' )format long

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )%f o l d = 1 ;d i sp ( f o l d )Resu l t_fo lder = ' Resu l t s / ' ;f i l ename = [ Resu l t_fo lder ' CBR_with_Euclidian_fold_ ' num2str ( f o l d ) ' . mat ' ] ;

%Check i f the v a r i a b l e s have been save from a prev ious t e s ti f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )%The va r i a b l e s have not been saved to run the t e s t

e l s ef o l d e r = ' Separated data / ' ;

%% −−−−−−−−−−−−−−−−−−−−−−−− INITIALIZE −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−load ( [ f o l d e r ' Rolling_Train_fold_ ' num2str ( f o l d ) ] ) ;Ro l l i ng = Ro l l i n g t r a i n ;load ( [ f o l d e r ' Rudder_Train_fold_ ' num2str ( f o l d ) ] ) ;Rudder = Ruddertrain ;load ( [ f o l d e r ' Pitch_Train_fold_ ' num2str ( f o l d ) ] ) ;Pitch = P i t ch t r a i n ;load ( [ f o l d e r 'Waves_Train_fold_ ' num2str ( f o l d ) ] ) ;Waves = Wavestrain ;load ( [ f o l d e r ' Speed_Train_fold_ ' num2str ( f o l d ) ] ) ;Speed = Speedtra in ;

load ( [ f o l d e r ' Rolling_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r 'Rudder_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r ' Pitch_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r 'Waves_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r ' Speed_Val_fold_ ' num2str ( f o l d ) ] ) ;

% Convert deg r e e s to rad iansWaves ( 3 , : ) = Waves ( 3 , : ) ∗( p i /180) ;Wavesval ( 3 , : ) = Wavesval ( 3 , : ) ∗( p i /180) ;

% r e t r i e v e the amount o f ca s e s in the 9 t r a i n i n g f o l d s and c a l c u l a t e% the amount o f ca s e s in each f o l d[~ , c o l ] = s i z e ( Ro l l i ng ) ;f o l d s i z e = co l /9 ;

%%% sepe ra t e the t r a i n i n g data so that the data used f o r e s t imat ing the% weights i s not found in the database . In conc lu s i on s e l e c t i n g one o f% the database f o l d s as t r a i n i n g f o l d f o r the GAi f ( f o l d < 10)

Rolling_GA_database = [ Ro l l i ng ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Ro l l i ng ( : , f o l d ∗f o l d s i z e : end ) ] ;

Rolling_GA_train = Ro l l i ng ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;

Rudder_GA_database = [ Rudder ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Rudder ( : , f o l d ∗ f o l d s i z e :end ) ] ;

110

Page 112: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Rudder_GA_train = Rudder ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;

Pitch_GA_database = [ Pitch ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Pitch ( : , f o l d ∗ f o l d s i z e : end) ] ;

Pitch_GA_train = Pitch ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;

Waves_GA_database = [Waves ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Waves ( : , f o l d ∗ f o l d s i z e : end) ] ;

Waves_GA_train = Waves ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;e l s e

Rolling_GA_database = Ro l l i ng ( : , f o l d s i z e +1:end ) ;Rolling_GA_train = Ro l l i ng ( : , 1 : f o l d s i z e ) ;

Rudder_GA_database = Rudder ( : , f o l d s i z e +1:end ) ;Rudder_GA_train = Rudder ( : , 1 : f o l d s i z e ) ;

Pitch_GA_database = Pitch ( : , f o l d s i z e +1:end ) ;Pitch_GA_train = Pitch ( : , 1 : f o l d s i z e ) ;

Waves_GA_database = Waves ( : , f o l d s i z e +1:end ) ;Waves_GA_train = Waves ( : , 1 : f o l d s i z e ) ;

endd i sp ( ' done gather ing data ' )

% Se t t i ng t r a i n i n g time f o r GAminute = 30 ;

%% setup GAga_opts = gaopt imset (@ga) ;ga_opts . Display = ' i t e r ' ;ga_opts . Popu lat ionS ize = 10 ;ga_opts . TimeLimit = minute ∗60 ;ga_opts . Generat ions = i n f ;ga_opts . PopInitRange = [ −1 ; 1 ] ;ga_opts . TolFun = 1e−100;ga_opts . TolCon = 1e−100;ga_opts . Sta l lGenLimit = i n f ;

% s e l e c t i n g the amount o f weights to es t imate . This CBR u t i l i z e 3% weights f o r each wave parameter . E . g . 3−nea r e s t ne ighbor method i s% implementednvars = 3 ;nvars = nvars ∗3 ;[ samples , c a s e s ] = s i z e (Waves_GA_train) ;

d i sp ( ' s ea r ch ing f o r nea r e s t neighbor ' )%% Find the nea r e s t waves f o r GA t r a i n i n gf o r Case = 1 : ca s e s

Case[ temp1 , temp2 ] = Euc l id ian_dis tance (Case , nvars , . . .

Rolling_GA_database , Rudder_GA_database , . . .Pitch_GA_database , Rolling_GA_train , . . .Rudder_GA_train , Pitch_GA_train , . . .Waves_GA_database ) ;

nearest_waves ( : , Case ) = temp1 ' ;rmse ( : , Case ) = temp2 ' ;

end

%% Ut i l i z e GA f o r s e l e c t i o n o f weights[ x , ~ ] = ga ( @f i tnes s , nvars , ga_opts ) ;

%% Find the nea r e s t waves f o r the Va l idat i on f o l d[~ , c a s e s ] = s i z e (Wavesval ) ;f o r Case = 1 : ca s e s

[ temp1 , temp2 ] = Euc l id ian_dis tance (Case , nvars , . . .Ro l l ing , Rudder , . . .Pitch , Ro l l i ngva l , . . .Rudderval , Pitchval , . . .Waves) ;

111

Page 113: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

nearest_waves ( : , Case ) = temp1 ' ;rmse ( : , Case ) = temp2 ' ;

end

%% Estimate the waves based on va l i d a t i o n f o l dK = nvars /3 ;f o r Case = 1 : ca s e s

est_Hs (Case ) = 0 ;est_Tp (Case ) = 0 ;est_Beta (Case ) = 0 ;f o r k = 1 :K

est_Hs (Case ) = est_Hs (Case ) + x(k ) ∗Waves (1 , nearest_waves (k , Case ) ) ;est_Tp (Case ) = est_Tp (Case ) + x(k+K) ∗Waves (2 , nearest_waves (k , Case ) ) ;est_Beta (Case ) = est_Beta (Case ) + x(k+(2∗K) ) ∗Waves (3 , nearest_waves (k ,

Case ) ) ;endi f (Wavesval (3 , Case )== 0)

Wavesval (3 , Case ) = 2∗ pi ;est_Beta (Case ) = est_Beta (Case ) + 2∗ pi ;

endend

save ( f i l ename )end

%% Plot r e s u l t sf i g u r e ( ' name ' , [ 'CBR FOLD = ' num2str ( f o l d ) ] )subplot ( 3 , 2 , 2 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( 'Hs (m) ' )xlim ( [ 0 ca s e s +1])e r r = ( est_Hs−Wavesval ( 1 , : ) ) . ^ 2 ;mse = mean( e r r ) ;s t r i n g = [ 'MSE = ' num2str (mse ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Wavesval ( 1 , : ) , ' k ' , 1 : cases , est_Hs ,'−−r ' )

subplot ( 3 , 2 , 1 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' f i t n e s s (%) ' )xlim ( [ 0 ca s e s +1])Perc = 100∗( est_Hs . /Wavesval ( 1 , : ) ) ;Optimal_Perc = 100∗ ones (1 , c a s e s ) ;d i f f = 100∗ ones ( s i z e ( Perc ) )−Perc ;mean_Hs_diff = mean( abs ( d i f f ) ) ;s t r i n g = [ 'Mean d i f f = ' num2str (mean_Hs_diff ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Optimal_Perc , ' k ' , 1 : cases , Perc ,'−−r ' )

subplot ( 3 , 2 , 4 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( 'Tp ( sec ) ' )xlim ( [ 0 ca s e s +1])e r r = ( est_Tp−Wavesval ( 2 , : ) ) . ^ 2 ;mse = mean( e r r ) ;s t r i n g = [ 'MSE = ' num2str (mse ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Wavesval ( 2 , : ) , ' k ' , 1 : cases , est_Tp,'−−r ' )

subplot ( 3 , 2 , 3 , ' r ep lace ' ) ;

112

Page 114: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' f i t n e s s (%) ' )xlim ( [ 0 ca s e s +1])Perc = 100∗( est_Tp ./Wavesval ( 2 , : ) ) ;Optimal_Perc = 100∗ ones (1 , c a s e s ) ;d i f f = 100∗ ones ( s i z e ( Perc ) )−Perc ;mean_Tp_diff = mean( abs ( d i f f ) ) ;s t r i n g = [ 'Mean d i f f = ' num2str (mean_Tp_diff ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Optimal_Perc , ' k ' , 1 : cases , Perc ,'−−r ' )

subplot ( 3 , 2 , 6 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' Beta ( deg ) ' )xlim ( [ 0 ca s e s +1])e r r = ( est_Beta−Wavesval ( 3 , : ) ) . ^ 2 ;mse = mean( e r r ) ;s t r i n g = [ 'MSE = ' num2str (mse ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Wavesval ( 3 , : ) ∗(180/ p i ) , ' k ' , 1 : cases , est_Beta ∗(180/ p i ) ,'−−r ' )

subplot ( 3 , 2 , 5 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' f i t n e s s (%) ' )xlim ( [ 0 ca s e s +1])Perc = 100∗( est_Beta . /Wavesval ( 3 , : ) ) ;Optimal_Perc = 100∗ ones (1 , c a s e s ) ;d i f f = 100∗ ones ( s i z e ( Perc ) )−Perc ;mean_Beta_diff = mean( abs ( d i f f ) ) ;s t r i n g = [ 'Mean d i f f = ' num2str (mean_Beta_diff ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Optimal_Perc , ' k ' , 1 : cases , Perc ,'−−r ' )

% Cost func t i on f o r GAfunc t i on mse_calc = f i t n e s s ( x )Waves = eva l i n ( ' base ' , 'Waves_GA_database ' ) ;Wavesval = eva l i n ( ' base ' , 'Waves_GA_train ' ) ;K = eva l i n ( ' base ' , ' nvars ' ) ;nearest_waves = eva l i n ( ' base ' , ' nearest_waves ' ) ;

[~ , c a s e s ] = s i z e (Wavesval ) ;

K = K /3 ;

mse_calc = 0 ;f o r Case = 1 : ca s e s

est_Hs = 0 ;est_Tp = 0 ;est_Beta = 0 ;f o r k = 1 :K

est_Hs = est_Hs + x(k ) ∗Waves (1 , nearest_waves (k , Case ) ) ;est_Tp = est_Tp + x(k+K) ∗Waves (2 , nearest_waves (k , Case ) ) ;est_Beta = est_Beta + x(k+(2∗K) ) ∗Waves (3 , nearest_waves (k , Case ) ) ;

endmse_calc = mse_calc + ( ( est_Hs−Wavesval (1 , Case ) ) ^2)+ ( ( est_Tp−Wavesval (2 , Case ) )

^2)+ ( ( est_Beta−Wavesval (3 , Case ) ) ^2) ;%mse_calc = mse_calc + 100∗ abs (1−( e s t imat i on /Wavesval (1 , Case ) ) ) ;

endmse_calc = mse_calc /(3∗ ca s e s ) ;end

113

Page 115: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Code E.6.1: The above source code was implemented in MATLAB to estimate the wave parametersusing a CBR and Euclidian Distance. The program demands that an integer named fold is pre-initialized and within the range of 1-10. The method utilizes the function presented in appendixE.6.2.

E.6.2 Euclidian Distance Function

f unc t i on [ temp , distance_min ] = Euc l id ian_dis tance (Case ,K, Rol l ing , Rudder , Pitch ,Ro l l i ngva l , Rudderval , Pitchval ,Waves)

r o l l v a l = Ro l l i n gva l ( : , Case ) ;rudderva l = Rudderval ( : , Case ) ;p i t chva l = Pi tchva l ( : , Case ) ;

c a s e s = s i z e ( Ro l l i ng ) ;

%Euc l id ian d i s t ancer o l l_ s e = sum( ( Ro l l i ng ( : , : )− r o l l v a l ∗ ones (1 , c a s e s (2 ) ) ) .^2) ;rudder_se = sum( ( Rudder ( : , : )−rudderva l ∗ ones (1 , c a s e s (2 ) ) ) .^2) ;pitch_se = sum( ( Pitch ( : , : )−p i t chva l ∗ ones (1 , c a s e s (2 ) ) ) .^2) ;

se = ro l l_s e+rudder_se+pitch_se ;d i s t ance = sq r t ( se ) ;

no_sim = K;f o r l = 1 : no_sim

[ distance_min ( l ) , index ] = min ( d i s t anc e ) ;d i s t anc e ( index ) = i n f ;temp( l ) = index ;

end

end

Code E.6.2: The above is the source code to the Euclidian Distance function implemented withthe CBR.

114

Page 116: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.6.3 Using Manhattan Distance

%c l c%c l e a r v a r s −except f o l d Ro l l i ng Rudder Pitch Speed Yaw Surge Sway Ro l l i n gva l

Rudderval P i t chva l Speedval Yawval Surgeva l Swayvalc l o s e a l lwarning ( ' o f f ' , ' a l l ' ) ;rng ( ' s hu f f l e ' , ' tw i s t e r ' )format long

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )%f o l d = 1 ;d i sp ( f o l d )Resu l t_fo lder = ' Resu l t s / ' ;f i l ename = [ Resu l t_fo lder 'CBR_with_Manhattan_fold_ ' num2str ( f o l d ) ' . mat ' ] ;

%Check i f the v a r i a b l e s have been save from a prev ious t e s ti f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )%The va r i a b l e s have not been saved to run the t e s t

e l s ef o l d e r = ' Separated data / ' ;

%% −−−−−−−−−−−−−−−−−−−−−−−− INITIALIZE −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−load ( [ f o l d e r ' Rolling_Train_fold_ ' num2str ( f o l d ) ] ) ;Ro l l i ng = Ro l l i n g t r a i n ;load ( [ f o l d e r ' Rudder_Train_fold_ ' num2str ( f o l d ) ] ) ;Rudder = Ruddertrain ;load ( [ f o l d e r ' Pitch_Train_fold_ ' num2str ( f o l d ) ] ) ;Pitch = P i t ch t r a i n ;load ( [ f o l d e r 'Waves_Train_fold_ ' num2str ( f o l d ) ] ) ;Waves = Wavestrain ;load ( [ f o l d e r ' Speed_Train_fold_ ' num2str ( f o l d ) ] ) ;Speed = Speedtra in ;

load ( [ f o l d e r ' Rolling_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r 'Rudder_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r ' Pitch_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r 'Waves_Val_fold_ ' num2str ( f o l d ) ] ) ;load ( [ f o l d e r ' Speed_Val_fold_ ' num2str ( f o l d ) ] ) ;

% Convert deg r e e s to rad iansWaves ( 3 , : ) = Waves ( 3 , : ) ∗( p i /180) ;Wavesval ( 3 , : ) = Wavesval ( 3 , : ) ∗( p i /180) ;

% r e t r i e v e the amount o f ca s e s in the 9 t r a i n i n g f o l d s and c a l c u l a t e% the amount o f ca s e s in each f o l d[~ , c o l ] = s i z e ( Ro l l i ng ) ;f o l d s i z e = co l /9 ;

%%% sepe ra t e the t r a i n i n g data so that the data used f o r e s t imat ing the% weights i s not found in the database . In conc lu s i on s e l e c t i n g one o f% the database f o l d s as t r a i n i n g f o l d f o r the GAi f ( f o l d < 10)

Rolling_GA_database = [ Ro l l i ng ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Ro l l i ng ( : , f o l d ∗f o l d s i z e : end ) ] ;

Rolling_GA_train = Ro l l i ng ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;

Rudder_GA_database = [ Rudder ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Rudder ( : , f o l d ∗ f o l d s i z e :end ) ] ;

Rudder_GA_train = Rudder ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;

Pitch_GA_database = [ Pitch ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Pitch ( : , f o l d ∗ f o l d s i z e : end) ] ;

Pitch_GA_train = Pitch ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;

115

Page 117: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Waves_GA_database = [Waves ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Waves ( : , f o l d ∗ f o l d s i z e : end) ] ;

Waves_GA_train = Waves ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;e l s e

Rolling_GA_database = Ro l l i ng ( : , f o l d s i z e +1:end ) ;Rolling_GA_train = Ro l l i ng ( : , 1 : f o l d s i z e ) ;

Rudder_GA_database = Rudder ( : , f o l d s i z e +1:end ) ;Rudder_GA_train = Rudder ( : , 1 : f o l d s i z e ) ;

Pitch_GA_database = Pitch ( : , f o l d s i z e +1:end ) ;Pitch_GA_train = Pitch ( : , 1 : f o l d s i z e ) ;

Waves_GA_database = Waves ( : , f o l d s i z e +1:end ) ;Waves_GA_train = Waves ( : , 1 : f o l d s i z e ) ;

endd i sp ( ' done gather ing data ' )

% Se t t i ng t r a i n i n g time f o r GAminute = 30 ;

%% setup GAga_opts = gaopt imset (@ga) ;ga_opts . Display = ' i t e r ' ;ga_opts . Popu lat ionS ize = 10 ;ga_opts . TimeLimit = minute ∗60 ;ga_opts . Generat ions = i n f ;ga_opts . PopInitRange = [ −1 ; 1 ] ;ga_opts . TolFun = 1e−100;ga_opts . TolCon = 1e−100;ga_opts . Sta l lGenLimit = i n f ;

% s e l e c t i n g the amount o f weights to es t imate . This CBR u t i l i z e 3% weights f o r each wave parameter . E . g . 3−nea r e s t ne ighbor method i s% implementednvars = 3 ;nvars = nvars ∗3 ;[ samples , c a s e s ] = s i z e (Waves_GA_train) ;

d i sp ( ' s ea r ch ing f o r nea r e s t neighbor ' )%% Find the nea r e s t waves f o r GA t r a i n i n gf o r Case = 1 : ca s e s

Case[ temp1 , temp2 ] = Manhattan_distance (Case , nvars , . . .

Rolling_GA_database , Rudder_GA_database , . . .Pitch_GA_database , Rolling_GA_train , . . .Rudder_GA_train , Pitch_GA_train , . . .Waves_GA_database ) ;

nearest_waves ( : , Case ) = temp1 ' ;rmse ( : , Case ) = temp2 ' ;

end

%% Ut i l i z e GA f o r s e l e c t i o n o f weights[ x , ~ ] = ga ( @f i tnes s , nvars , ga_opts ) ;

%% Find the nea r e s t waves f o r the Va l idat i on f o l d[~ , c a s e s ] = s i z e (Wavesval ) ;f o r Case = 1 : ca s e s

[ temp1 , temp2 ] = Manhattan_distance (Case , nvars , . . .Ro l l ing , Rudder , . . .Pitch , Ro l l i ngva l , . . .Rudderval , Pitchval , . . .Waves) ;

nearest_waves ( : , Case ) = temp1 ' ;rmse ( : , Case ) = temp2 ' ;

end

116

Page 118: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

%% Estimate the waves based on va l i d a t i o n f o l dK = nvars /3 ;f o r Case = 1 : ca s e s

est_Hs (Case ) = 0 ;est_Tp (Case ) = 0 ;est_Beta (Case ) = 0 ;f o r k = 1 :K

est_Hs (Case ) = est_Hs (Case ) + x(k ) ∗Waves (1 , nearest_waves (k , Case ) ) ;est_Tp (Case ) = est_Tp (Case ) + x(k+K) ∗Waves (2 , nearest_waves (k , Case ) ) ;est_Beta (Case ) = est_Beta (Case ) + x(k+(2∗K) ) ∗Waves (3 , nearest_waves (k ,

Case ) ) ;endi f (Wavesval (3 , Case )== 0)

Wavesval (3 , Case ) = 2∗ pi ;est_Beta (Case ) = est_Beta (Case ) + 2∗ pi ;

endend

save ( f i l ename )end

%% Plot r e s u l t sf i g u r e ( ' name ' , [ 'CBR FOLD = ' num2str ( f o l d ) ] )subplot ( 3 , 2 , 2 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( 'Hs (m) ' )xlim ( [ 0 ca s e s +1])e r r = ( est_Hs−Wavesval ( 1 , : ) ) . ^ 2 ;mse = mean( e r r ) ;s t r i n g = [ 'MSE = ' num2str (mse ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Wavesval ( 1 , : ) , ' k ' , 1 : cases , est_Hs ,'−−r ' )

subplot ( 3 , 2 , 1 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' f i t n e s s (%) ' )xlim ( [ 0 ca s e s +1])Perc = 100∗( est_Hs . /Wavesval ( 1 , : ) ) ;Optimal_Perc = 100∗ ones (1 , c a s e s ) ;d i f f = 100∗ ones ( s i z e ( Perc ) )−Perc ;mean_Hs_diff = mean( abs ( d i f f ) ) ;s t r i n g = [ 'Mean d i f f = ' num2str (mean_Hs_diff ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Optimal_Perc , ' k ' , 1 : cases , Perc ,'−−r ' )

subplot ( 3 , 2 , 4 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( 'Tp ( sec ) ' )xlim ( [ 0 ca s e s +1])e r r = ( est_Tp−Wavesval ( 2 , : ) ) . ^ 2 ;mse = mean( e r r ) ;s t r i n g = [ 'MSE = ' num2str (mse ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Wavesval ( 2 , : ) , ' k ' , 1 : cases , est_Tp,'−−r ' )

subplot ( 3 , 2 , 3 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' f i t n e s s (%) ' )xlim ( [ 0 ca s e s +1])

117

Page 119: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Perc = 100∗( est_Tp ./Wavesval ( 2 , : ) ) ;Optimal_Perc = 100∗ ones (1 , c a s e s ) ;d i f f = 100∗ ones ( s i z e ( Perc ) )−Perc ;mean_Tp_diff = mean( abs ( d i f f ) ) ;s t r i n g = [ 'Mean d i f f = ' num2str (mean_Tp_diff ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Optimal_Perc , ' k ' , 1 : cases , Perc ,'−−r ' )

subplot ( 3 , 2 , 6 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' Beta ( deg ) ' )xlim ( [ 0 ca s e s +1])e r r = ( est_Beta−Wavesval ( 3 , : ) ) . ^ 2 ;mse = mean( e r r ) ;s t r i n g = [ 'MSE = ' num2str (mse ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Wavesval ( 3 , : ) ∗(180/ p i ) , ' k ' , 1 : cases , est_Beta ∗(180/ p i ) ,'−−r ' )

subplot ( 3 , 2 , 5 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' f i t n e s s (%) ' )xlim ( [ 0 ca s e s +1])Perc = 100∗( est_Beta . /Wavesval ( 3 , : ) ) ;Optimal_Perc = 100∗ ones (1 , c a s e s ) ;d i f f = 100∗ ones ( s i z e ( Perc ) )−Perc ;mean_Beta_diff = mean( abs ( d i f f ) ) ;s t r i n g = [ 'Mean d i f f = ' num2str (mean_Beta_diff ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Optimal_Perc , ' k ' , 1 : cases , Perc ,'−−r ' )

% Cost func t i on f o r GAfunc t i on mse_calc = f i t n e s s ( x )Waves = eva l i n ( ' base ' , 'Waves_GA_database ' ) ;Wavesval = eva l i n ( ' base ' , 'Waves_GA_train ' ) ;K = eva l i n ( ' base ' , ' nvars ' ) ;nearest_waves = eva l i n ( ' base ' , ' nearest_waves ' ) ;

[~ , c a s e s ] = s i z e (Wavesval ) ;

K = K /3 ;

mse_calc = 0 ;f o r Case = 1 : ca s e s

est_Hs = 0 ;est_Tp = 0 ;est_Beta = 0 ;f o r k = 1 :K

est_Hs = est_Hs + x(k ) ∗Waves (1 , nearest_waves (k , Case ) ) ;est_Tp = est_Tp + x(k+K) ∗Waves (2 , nearest_waves (k , Case ) ) ;est_Beta = est_Beta + x(k+(2∗K) ) ∗Waves (3 , nearest_waves (k , Case ) ) ;

endmse_calc = mse_calc + ( ( est_Hs−Wavesval (1 , Case ) ) ^2)+ ( ( est_Tp−Wavesval (2 , Case ) )

^2)+ ( ( est_Beta−Wavesval (3 , Case ) ) ^2) ;%mse_calc = mse_calc + 100∗ abs (1−( e s t imat i on /Wavesval (1 , Case ) ) ) ;

endmse_calc = mse_calc /(3∗ ca s e s ) ;end

118

Page 120: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Code E.6.3: The above source code was implemented in MATLAB to estimate the wave parametersusing a CBR and Manhattan Distance. The program demands that an integer named fold is pre-initialized and within the range of 1-10. The method utilizes the function presented in appendixE.6.4.

E.6.4 Manhattan Distance Function

f unc t i on [ temp , distance_min ] = Manhattan_distance (Case ,K, Rol l ing , Rudder , Pitch ,Ro l l i ngva l , Rudderval , Pitchval ,Waves)

r o l l v a l = Ro l l i n gva l ( : , Case ) ;rudderva l = Rudderval ( : , Case ) ;p i t chva l = Pi tchva l ( : , Case ) ;

c a s e s = s i z e ( Ro l l i ng ) ;

%Manhattan d i s t ancer o l l_ s e = sum( abs ( Ro l l i ng ( : , : )− r o l l v a l ∗ ones (1 , c a s e s (2 ) ) ) ) ;rudder_se = sum( abs (Rudder ( : , : )−rudderva l ∗ ones (1 , c a s e s (2 ) ) ) ) ;pitch_se = sum( abs ( Pitch ( : , : )−p i t chva l ∗ ones (1 , c a s e s (2 ) ) ) ) ;

d i s t anc e = ro l l_s e+rudder_se+pitch_se ;

no_sim = K;f o r l = 1 : no_sim

[ distance_min ( l ) , index ] = min ( d i s t anc e ) ;d i s t anc e ( index ) = i n f ;temp( l ) = index ;

end

end

Code E.6.4: The above is the source code to the Manhattan Distance function implemented withthe CBR.

119

Page 121: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.7 Present Feedforward Neural Network And Case Based Reasoning

c l cc l e a rc l o s e a l l

P r e s e n t f i l e = 'Present_CBR_ANN_result . mat ' ;

% Check t h i s f i l e have been compiled be f o r e and i f so load r e s u l t si f ( e x i s t ( P r e s e n t f i l e , ' f i l e ' ) == 2)

load ( P r e s e n t f i l e )

% s e l e c t i f the f i g u r e s s h a l l be f o r the r epor t o f notPlot_For_Report = f a l s e ;

e l s e% Load r e s u l t s anew% s e l e c t i f the f i g u r e s s h a l l be f o r the r epor t o f notPlot_For_Report = f a l s e ;

% Execute the methods and s t o r e t h e i r r e s u l t sno_folds = 10 ;f o r f o l d = 1 : no_folds

load ( [ ' Separated data/Waves_val_fold_ ' num2str ( f o l d ) ] ) ;cu r r ent_va l ida t i on = Wavesval ;Va l idat i on = cur rent_va l ida t i on ;Va l idat i on ( 3 , : ) = Va l idat i on ( 3 , : ) . ∗ ( p i /180) ;

d i sp ( 'CBR_Manhattan ' )CBR_Manhattantemp = [ mean_Hs_diff mean_Tp_diff mean_Beta_diff ] ;Avg_values_CBR_for_folds ( fo ld , 1 : 3 ) = temp ;

f o r hs = 1 : 5[~ , ca s e s ] = s i z e ( Va l idat i on ) ;temporary = [ ] ;f o r c = 1 : ca s e s

i f ( Va l idat i on (1 , c ) == hs )temporary = [ temporary 100−(100∗( est_Hs ( c ) /Va l idat i on (1 , c ) ) ) ] ;

endendCBR_Manhattan_Hs_performance ( hs , f o l d ) = mean( abs ( temporary ) ) ;

endf o r tp = 2 : 8

[~ , ca s e s ] = s i z e ( Va l idat i on ) ;temporary = [ ] ;f o r c = 1 : ca s e s

i f ( Va l idat i on (2 , c ) == tp )temporary = [ temporary 100−(100∗(est_Tp ( c ) /Va l idat i on (2 , c ) ) ) ] ;

endendCBR_Manhattan_Tp_performance ( tp−1, f o l d ) = mean( abs ( temporary ) ) ;

endf o r beta = 20∗( p i /180) : 20∗ ( p i /180) : 2∗ pi

[~ , ca s e s ] = s i z e ( Va l idat i on ) ;temporary = [ ] ;f o r c = 1 : ca s e s

i f ( round (100∗ Val idat i on (3 , c ) ) == round (100∗ beta ) )i f Va l idat i on (3 , c ) == 0

Val idat i on (3 , c ) = 2∗ pi ;endtemporary = [ temporary 100−(100∗( est_Beta ( c ) /Va l idat i on (3 , c ) ) )

] ;end

endCBR_Manhattan_Beta_performance ( round ( round ( beta /(20∗ ( p i /180) ) ) ) , f o l d ) =

mean( abs ( temporary ) ) ;end%

120

Page 122: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

c l cc l o s e a l lc l e a r v a r s −except Plot_For_Report no_folds P r e s e n t f i l e f o l d . . .

Avg_values_CBR_for_folds Avg_values_ANN_for_folds . . .Avg_values_CBR_with_Euclidian_for_folds Avg_values_ANN_GA_for_folds . . .CBR_Manhattan_Hs_performance CBR_Euclidian_Hs_performance . . .ANN_RPROP_Hs_performance ANN_GA_Hs_performance . . .CBR_Manhattan_Tp_performance CBR_Euclidian_Tp_performance . . .ANN_RPROP_Tp_performance ANN_GA_Tp_performance . . .CBR_Manhattan_Beta_performance CBR_Euclidean_Beta_performance . . .ANN_RPROP_Beta_performance ANN_GA_Beta_performance . . .cu r r ent_va l ida t i on Va l idat i on

Va l idat i on = cur rent_va l ida t i on ;Va l idat i on ( 3 , : ) = Va l idat i on ( 3 , : ) . ∗ ( p i /180) ;

d i sp ( ' CBR_Euclidian ' )CBR_Euclidiantemp = [ mean_Hs_diff mean_Tp_diff mean_Beta_diff ] ;Avg_values_CBR_with_Euclidian_for_folds ( fo ld , 1 : 3 ) = temp ;

f o r hs = 1 : 5[~ , ca s e s ] = s i z e ( Va l idat i on ) ;temporary = [ ] ;f o r c = 1 : ca s e s

i f ( Va l idat i on (1 , c ) == hs )temporary = [ temporary 100−(100∗( est_Hs ( c ) /Va l idat i on (1 , c ) ) ) ] ;

endendCBR_Euclidian_Hs_performance ( hs , f o l d ) = mean( abs ( temporary ) ) ;

endf o r tp = 2 : 8

[~ , ca s e s ] = s i z e ( Va l idat i on ) ;temporary = [ ] ;f o r c = 1 : ca s e s

i f ( Va l idat i on (2 , c ) == tp )temporary = [ temporary 100−(100∗(est_Tp ( c ) /Va l idat i on (2 , c ) ) ) ] ;

endendCBR_Euclidian_Tp_performance ( tp−1, f o l d ) = mean( abs ( temporary ) ) ;

endf o r beta = 20∗( p i /180) : 20∗ ( p i /180) : 2∗ pi

[~ , ca s e s ] = s i z e ( Va l idat i on ) ;temporary = [ ] ;f o r c = 1 : ca s e s

i f ( round (100∗ Val idat i on (3 , c ) ) == round (100∗ beta ) )i f Va l idat i on (3 , c ) == 0

Val idat i on (3 , c ) = 2∗ pi ;endtemporary = [ temporary 100−(100∗( est_Beta ( c ) /Va l idat i on (3 , c ) ) )

] ;end

endCBR_Euclidean_Beta_performance ( round ( beta /(20∗ ( p i /180) ) ) , f o l d ) = mean(

abs ( temporary ) ) ;end%%

c l cc l o s e a l lc l e a r v a r s −except Plot_For_Report no_folds P r e s e n t f i l e f o l d . . .

Avg_values_CBR_for_folds Avg_values_ANN_for_folds . . .Avg_values_CBR_with_Euclidian_for_folds Avg_values_ANN_GA_for_folds . . .CBR_Manhattan_Hs_performance CBR_Euclidian_Hs_performance . . .ANN_RPROP_Hs_performance ANN_GA_Hs_performance . . .CBR_Manhattan_Tp_performance CBR_Euclidian_Tp_performance . . .ANN_RPROP_Tp_performance ANN_GA_Tp_performance . . .

121

Page 123: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

CBR_Manhattan_Beta_performance CBR_Euclidean_Beta_performance . . .ANN_RPROP_Beta_performance ANN_GA_Beta_performance . . .cu r r ent_va l ida t i on Va l idat i on

Va l idat i on = cur rent_va l ida t i on ;Va l idat i on ( 3 , : ) = Va l idat i on ( 3 , : ) . ∗ ( p i /180) ;

d i sp ( 'ANN_RPROP' )ANN_RPROPtemp = [ Average_Hs_diff Average_Tp_diff Average_Beta_diff ] ;Avg_values_ANN_for_folds ( fo ld , 1 : 3 ) = temp ;

f o r hs = 1 : 5[~ , ca s e s ] = s i z e ( Va l idat i on ) ;temporary = [ ] ;f o r c = 1 : ca s e s

i f ( Va l idat i on (1 , c ) == hs )temporary = [ temporary 100−(100∗( est_Hs_vec ( c ) /Va l idat i on (1 , c ) )

) ] ;end

endANN_RPROP_Hs_performance( hs , f o l d ) = mean( abs ( temporary ) ) ;

endf o r tp = 2 : 8

[~ , ca s e s ] = s i z e ( Va l idat i on ) ;temporary = [ ] ;f o r c = 1 : ca s e s

i f ( Va l idat i on (2 , c ) == tp )temporary = [ temporary 100−(100∗( est_Tp_vec ( c ) /Va l idat i on (2 , c ) )

) ] ;end

endANN_RPROP_Tp_performance( tp−1, f o l d ) = mean( abs ( temporary ) ) ;

endf o r beta = 20∗( p i /180) : 20∗ ( p i /180) : 2∗ pi

[~ , ca s e s ] = s i z e ( Va l idat i on ) ;temporary = [ ] ;f o r c = 1 : ca s e s

i f ( round (100∗ Val idat i on (3 , c ) ) == round (100∗ beta ) )i f Va l idat i on (3 , c ) == 0

Val idat i on (3 , c ) = 2∗ pi ;est_Beta_vec ( c ) = est_Beta_vec ( c ) + 360 ;

endtemporary = [ temporary 100−(100∗(( est_Beta_vec ( c ) ∗( p i /180) ) /

Va l idat i on (3 , c ) ) ) ] ;end

endANN_RPROP_Beta_performance( round ( beta /(20∗ ( p i /180) ) ) , f o l d ) = mean( abs (

temporary ) ) ;end

%%

c l cc l o s e a l lc l e a r v a r s −except Plot_For_Report no_folds P r e s e n t f i l e f o l d . . .

Avg_values_CBR_for_folds Avg_values_ANN_for_folds . . .Avg_values_CBR_with_Euclidian_for_folds Avg_values_ANN_GA_for_folds . . .CBR_Manhattan_Hs_performance CBR_Euclidian_Hs_performance . . .ANN_RPROP_Hs_performance ANN_GA_Hs_performance . . .CBR_Manhattan_Tp_performance CBR_Euclidian_Tp_performance . . .ANN_RPROP_Tp_performance ANN_GA_Tp_performance . . .CBR_Manhattan_Beta_performance CBR_Euclidean_Beta_performance . . .ANN_RPROP_Beta_performance ANN_GA_Beta_performance . . .cu r r ent_va l ida t i on Va l idat i on

Va l idat i on = cur rent_va l ida t i on ;Va l idat i on ( 3 , : ) = Va l idat i on ( 3 , : ) . ∗ ( p i /180) ;

d i sp ( 'ANN_GA' )

122

Page 124: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

ANN_GAtemp = [ Average_Hs_diff Average_Tp_diff Average_Beta_diff ] ;Avg_values_ANN_GA_for_folds ( fo ld , 1 : 3 ) = temp ;

f o r hs = 1 : 5[~ , ca s e s ] = s i z e ( Va l idat i on ) ;temporary = [ ] ;f o r c = 1 : ca s e s

i f ( Va l idat i on (1 , c ) == hs )temporary = [ temporary 100−(100∗( est_Hs_vec ( c ) /Va l idat i on (1 , c ) )

) ] ;end

endANN_GA_Hs_performance( hs , f o l d ) = mean( abs ( temporary ) ) ;

end

f o r tp = 2 : 8[~ , ca s e s ] = s i z e ( Va l idat i on ) ;temporary = [ ] ;f o r c = 1 : ca s e s

i f ( Va l idat i on (2 , c ) == tp )temporary = [ temporary 100−(100∗( est_Tp_vec ( c ) /Va l idat i on (2 , c ) )

) ] ;end

endANN_GA_Tp_performance( tp−1, f o l d ) = mean( abs ( temporary ) ) ;

endf o r beta = 20∗( p i /180) : 20∗ ( p i /180) : 2∗ pi

[~ , ca s e s ] = s i z e ( Va l idat i on ) ;temporary = [ ] ;f o r c = 1 : ca s e s

i f ( round (100∗ Val idat i on (3 , c ) ) == round (100∗ beta ) )i f Va l idat i on (3 , c ) == 0

Val idat i on (3 , c ) = 2∗ pi ;est_Beta_vec ( c ) = est_Beta_vec ( c ) + 360 ;

endtemporary = [ temporary 100−(100∗(( est_Beta_vec ( c ) ∗( p i /180) ) /

Va l idat i on (3 , c ) ) ) ] ;end

endANN_GA_Beta_performance( round ( beta /(20∗ ( p i /180) ) ) , f o l d ) = mean( abs (

temporary ) ) ;end

c l cc l o s e a l lc l e a r v a r s −except Plot_For_Report no_folds P r e s e n t f i l e f o l d . . .

Avg_values_CBR_for_folds Avg_values_ANN_for_folds . . .Avg_values_CBR_with_Euclidian_for_folds Avg_values_ANN_GA_for_folds . . .CBR_Manhattan_Hs_performance CBR_Euclidian_Hs_performance . . .ANN_RPROP_Hs_performance ANN_GA_Hs_performance . . .CBR_Manhattan_Tp_performance CBR_Euclidian_Tp_performance . . .ANN_RPROP_Tp_performance ANN_GA_Tp_performance . . .CBR_Manhattan_Beta_performance CBR_Euclidean_Beta_performance . . .ANN_RPROP_Beta_performance ANN_GA_Beta_performance . . .cu r r ent_va l ida t i on Va l idat i on

end

c l o s e a l lsave ( P r e s e n t f i l e )

end

%% St ru c tu r i z e the i nd i v i dua l parameter performance% Stepping setup% Hs = 1 : 1 : 1 0 m

123

Page 125: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

% Tp = 10 : 1 : 1 8 sec% Beta = 0 : 20 : 360 degCBR_Manhattan_Hs_performance = nanmean(CBR_Manhattan_Hs_performance , 2 ) ;CBR_Manhattan_Tp_performance = nanmean(CBR_Manhattan_Tp_performance , 2 ) ;CBR_Manhattan_Beta_performance = nanmean(CBR_Manhattan_Beta_performance , 2 ) ;

CBR_Euclidian_Hs_performance = nanmean(CBR_Euclidian_Hs_performance , 2 ) ;CBR_Euclidian_Tp_performance = nanmean(CBR_Euclidian_Tp_performance , 2 ) ;CBR_Euclidean_Beta_performance = nanmean(CBR_Euclidean_Beta_performance , 2 ) ;

ANN_RPROP_Hs_performance = nanmean(ANN_RPROP_Hs_performance , 2 ) ;ANN_RPROP_Tp_performance = nanmean(ANN_RPROP_Tp_performance , 2 ) ;ANN_RPROP_Beta_performance =nanmean(ANN_RPROP_Beta_performance , 2 ) ;

ANN_GA_Hs_performance = nanmean(ANN_GA_Hs_performance , 2 ) ;ANN_GA_Tp_performance = nanmean(ANN_GA_Tp_performance , 2 ) ;ANN_GA_Beta_performance = nanmean(ANN_GA_Beta_performance , 2 ) ;

Hs_performance = [ANN_RPROP_Hs_performance ANN_GA_Hs_performanceCBR_Euclidian_Hs_performance CBR_Manhattan_Hs_performance ] ;

Tp_performance = [ANN_RPROP_Tp_performance ANN_GA_Tp_performanceCBR_Euclidian_Tp_performance CBR_Manhattan_Tp_performance ] ;

Beta_performance = [ANN_RPROP_Beta_performance ANN_GA_Beta_performanceCBR_Euclidean_Beta_performance CBR_Manhattan_Beta_performance ] ;

%% Present the r e s u l ti f ( Plot_For_Report )

f i g u r ee l s e

f i g u r esubplot ( 3 , 1 , 1 )

endhold ong r id onp lo t ( 1 : no_folds , Avg_values_CBR_for_folds ( 1 : no_folds , 1 ) , ' k ' , . . .

1 : no_folds , Avg_values_ANN_for_folds ( 1 : no_folds , 1 ) , ' r ' , . . .1 : no_folds , Avg_values_CBR_with_Euclidian_for_folds ( 1 : no_folds , 1 ) , ' g ' , . . .1 : no_folds , Avg_values_ANN_GA_for_folds ( 1 : no_folds , 1 ) , ' b ' )

t i t l e ( 'Hs ' )x l ab e l ( ' f o ld ' )y l ab e l ( 'Mean % d i f f ' )l egend ( 'CBR Manhattan ' , 'ANN RPROP' , 'CBR Eucl id ian ' , 'ANN GA' )

i f ( Plot_For_Report )f i g u r e

e l s esubplot ( 3 , 1 , 2 )

endhold ong r id onp lo t ( 1 : no_folds , Avg_values_CBR_for_folds ( 1 : no_folds , 2 ) , ' k ' , . . .

1 : no_folds , Avg_values_ANN_for_folds ( 1 : no_folds , 2 ) , ' r ' , . . .1 : no_folds , Avg_values_CBR_with_Euclidian_for_folds ( 1 : no_folds , 2 ) , ' g ' , . . .1 : no_folds , Avg_values_ANN_GA_for_folds ( 1 : no_folds , 2 ) , ' b ' )

t i t l e ( 'Tp ' )x l ab e l ( ' f o ld ' )y l ab e l ( 'Mean % d i f f ' )l egend ( 'CBR Manhattan ' , 'ANN RPROP' , 'CBR Eucl id ian ' , 'ANN GA' )

i f ( Plot_For_Report )f i g u r e

e l s esubplot ( 3 , 1 , 3 )

endhold ong r id onp lo t ( 1 : no_folds , Avg_values_CBR_for_folds ( 1 : no_folds , 3 ) , ' k ' , . . .

1 : no_folds , Avg_values_ANN_for_folds ( 1 : no_folds , 3 ) , ' r ' , . . .1 : no_folds , Avg_values_CBR_with_Euclidian_for_folds ( 1 : no_folds , 3 ) , ' g ' , . . .1 : no_folds , Avg_values_ANN_GA_for_folds ( 1 : no_folds , 3 ) , ' b ' )

124

Page 126: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

t i t l e ( ' Encounter Angle ' )x l ab e l ( ' f o ld ' )y l ab e l ( 'Mean % d i f f ' )l egend ( 'CBR Manhattan ' , 'ANN RPROP' , 'CBR Eucl id ian ' , 'ANN GA' )

rowbreak = '−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−';mean_Hs_CBR_diff = [ 'Mean Hs CBR Manhattan D i f f = ' num2str (mean(

Avg_values_CBR_for_folds ( 1 : no_folds , 1 ) ) ) ] ;mean_Hs_CBR_Euclidian_diff = [ 'Mean Hs Euc l id ian CBR Di f f = ' num2str (mean(

Avg_values_CBR_with_Euclidian_for_folds ( 1 : no_folds , 1 ) ) ) ] ;mean_Hs_ANN_diff = [ 'Mean Hs ANN BP Di f f = ' num2str (mean(Avg_values_ANN_for_folds

( 1 : no_folds , 1 ) ) ) ] ;mean_Hs_ANN_GA_diff = [ 'Mean Hs ANN GA Di f f = ' num2str (mean(

Avg_values_ANN_GA_for_folds ( 1 : no_folds , 1 ) ) ) ] ;

mean_Tp_CBR_diff = [ 'Mean Tp CBR Manhattan D i f f = ' num2str (mean(Avg_values_CBR_for_folds ( 1 : no_folds , 2 ) ) ) ] ;

mean_Tp_CBR_Euclidian_diff = [ 'Mean Tp Euc l id ian CBR Di f f = ' num2str (mean(Avg_values_CBR_with_Euclidian_for_folds ( 1 : no_folds , 2 ) ) ) ] ;

mean_Tp_ANN_diff = [ 'Mean Tp ANN BP Di f f = ' num2str (mean(Avg_values_ANN_for_folds( 1 : no_folds , 2 ) ) ) ] ;

mean_Tp_ANN_GA_diff = [ 'Mean Tp ANN GA Di f f = ' num2str (mean(Avg_values_ANN_GA_for_folds ( 1 : no_folds , 2 ) ) ) ] ;

mean_Beta_CBR_diff = [ 'Mean Beta CBR Manhattan D i f f = ' num2str (mean(Avg_values_CBR_for_folds ( 1 : no_folds , 3 ) ) ) ] ;

mean_Beta_CBR_Euclidian_diff = [ 'Mean Beta Euc l id ian CBR Di f f = ' num2str (mean(Avg_values_CBR_with_Euclidian_for_folds ( 1 : no_folds , 3 ) ) ) ] ;

mean_Beta_ANN_diff = [ 'Mean Beta ANN BP Di f f = ' num2str (mean(Avg_values_ANN_for_folds ( 1 : no_folds , 3 ) ) ) ] ;

mean_Beta_ANN_GA_diff = [ 'Mean Beta ANN GA Di f f = ' num2str (mean(Avg_values_ANN_GA_for_folds ( 1 : no_folds , 3 ) ) ) ] ;

Methods = { 'CBR Manhattan ' , 'CBR Euclidean ' , 'ANN RPROP' , 'ANN GA' } ;

[~ , index ] = min ( [ mean(Avg_values_CBR_for_folds ( 1 : no_folds , 1 ) ) . . .mean(Avg_values_CBR_with_Euclidian_for_folds ( 1 : no_folds , 1 ) ) . . .mean(Avg_values_ANN_for_folds ( 1 : no_folds , 1 ) ) . . .mean(Avg_values_ANN_GA_for_folds ( 1 : no_folds , 1 ) ) ] ) ;

Best_Hs = s t r i n g ( [ ' Best Hs = ' s t r j o i n (Methods ( index ) ) ] ) ;

[~ , index ] = min ( [ mean(Avg_values_CBR_for_folds ( 1 : no_folds , 2 ) ) . . .mean(Avg_values_CBR_with_Euclidian_for_folds ( 1 : no_folds , 2 ) ) . . .mean(Avg_values_ANN_for_folds ( 1 : no_folds , 2 ) ) . . .mean(Avg_values_ANN_GA_for_folds ( 1 : no_folds , 2 ) ) ] ) ;

Best_Tp = [ ' Best Tp = ' s t r j o i n (Methods ( index ) ) ] ;

[~ , index ] = min ( [ mean(Avg_values_CBR_for_folds ( 1 : no_folds , 3 ) ) . . .mean(Avg_values_CBR_with_Euclidian_for_folds ( 1 : no_folds , 3 ) ) . . .mean(Avg_values_ANN_for_folds ( 1 : no_folds , 3 ) ) . . .mean(Avg_values_ANN_GA_for_folds ( 1 : no_folds , 3 ) ) ] ) ;

Best_Beta = [ ' Best Beta = ' s t r j o i n (Methods ( index ) ) ] ;

f p r i n t f ( [ rowbreak '\n ' . . .mean_Hs_CBR_diff '\n ' . . .mean_Hs_CBR_Euclidian_diff '\n ' . . .mean_Hs_ANN_diff '\n ' . . .mean_Hs_ANN_GA_diff '\n ' . . .rowbreak '\n ' . . .mean_Tp_CBR_diff '\n ' . . .mean_Tp_CBR_Euclidian_diff '\n ' . . .mean_Tp_ANN_diff '\n ' . . .mean_Tp_ANN_GA_diff '\n ' . . .rowbreak '\n ' . . .mean_Beta_CBR_diff '\n ' . . .mean_Beta_CBR_Euclidian_diff '\n ' . . .mean_Beta_ANN_diff '\n ' . . .mean_Beta_ANN_GA_diff '\n ' . . .rowbreak '\n ' ] ) ;

125

Page 127: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Code E.7.1: Above is the source code implemented in MATLAB for the retrieving the �tnessvalue, calculate the MAE, and present the result obtained from the 10-fold cross-validation resultgenerated by the FFNN (E.5.1 & E.5.2) and CBR (E.6.1 & E.6.3) programs.

E.8 Test All Pre-Trained Solutions With Actual Data

The following sections presents the code implemented for testing the simulation trained algorithmswith actual data.

E.8.1 Estimate Results With Previously Best Con�gurations

c l cc l e a rc l o s e a l lformat shor t

%=========================================================================%%% Prepare the ac tua l dataload ( ' Ship_data ' )load ( ' columnLabels ' )load ( 'Waves_2017_04_05 ' )

Ro l l i n gva l = Ship_data ( : , columnLabels . RollRaw ) ;P i t chva l = Ship_data ( : , columnLabels . PitchRaw ) ;Rudderval = Ship_data ( : , columnLabels . RudderPos ) ;Cont_spdval = Ship_data ( : , columnLabels . SpeedThroughWater ) ;Wavesval = Waves_2017_04_05 ( : , 2 : 4 ) ;

Wavesval ( : , 3 ) = Wavesval ( : , 3 ) ∗( p i /180) ;

pos = 0 ;f o r l = 1 : 1 0 1 : l ength ( Ro l l i n gva l )−100

pos = pos+1;Rol l ingVal ( : , pos ) = Ro l l i n gva l ( l : l +100 ,1) ;PitchVal ( : , pos ) = Pi tchva l ( l : l +100 ,1) ;RudderVal ( : , pos ) = Rudderval ( l : l +100 ,1) ;Cont_Spd_Val ( : , pos ) = Cont_spdval ( l : l +100 ,1) ;WavesVal ( 1 : 3 , pos ) = mean(Wavesval ( l : l +100 , :) , 1 ) ' ;

end

%=========================================================================%%% Test loop TF 1 example% use the best f o l dWaitbarHandle = waitbar (0 , 'TF Loop ' ) ;f o l d = 7;%4;f o l d e r = ' Resu l t s / ' ;

load ( [ num2str ( f o l d e r ) . . .' Transfer_Function_Loop_1_example_fold_ ' num2str ( f o l d ) ] ) ;

Ts = Data . Ts ;w = Ts : Ts : 2 ;

c l e a r v a r s −except InDirectTF Ts w Rol l ingVal PitchVal . . .RudderVal WavesVal Cont_Spd_Val WaitbarHandle

[ samples , c a s e s ] = s i z e (WavesVal ) ;

g = 9 . 8 2 ;

f o r k = 1 : ca s e st i c ;

126

Page 128: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Hs = WavesVal (1 , k ) ;Tp = WavesVal (2 , k ) ;Beta = WavesVal (3 , k ) ;

U = mean(Cont_Spd_Val ( : , k ) ) ;U = U ∗ 0 .5144443101 ; %convert to m/ s

omega_0 = (2∗ pi ) . /Tp ;T1 = (2∗ pi ) . / ( 1 . 2 9 5 7 . ∗ omega_0) ;ITTC = @(x ) ( (173∗ (Hs^2) /(T1^4) ) . / ( x .^5) ) .∗ exp (−((691/(T1^4) ) . / ( x .^4) ) ) ;

temp = ITTC(w) . / ( abs (1−((2.∗w.∗U) . / ( g ) ) ∗ cos ( Beta ) ) ) ;EncounterSpectrum ( : , k ) = temp ' ;

MotionSpectrum = f f t ( Ro l l ingVal ( : , k ) ) ;Data_Inverse = iddata ( EncounterSpectrum ( : , k ) ,MotionSpectrum , Ts ) ;

[~ , TF_loop_1_example_fit ( k ) ] = compare ( Data_Inverse , InDirectTF ) ;

e lapsedt ime (k ) = toc ;Time = (sum( e lapsedt ime ) /k ) ∗( cases−k ) /60 ;EstimatedMinLeft = f l o o r (Time) ;Est imatedSecLeft = f l o o r ( (Time−EstimatedMinLeft ) ∗60) ;

s t r i n g = [ 'TF Loop 1 \n Estimated time l e f t = ' num2str ( EstimatedMinLeft ) 'min' num2str ( Est imatedSecLeft ) ' sec ' ] ;

waitbar ( ( k/ ca s e s ) ,WaitbarHandle , s p r i n t f ( s t r i n g ) ) ;

end

TF_loop_1_example_error = abs (100∗ ones ( s i z e (TF_loop_1_example_fit ) ) −TF_loop_1_example_fit ) ;

save ( ' TF_loop_1_example_error ' , ' TF_loop_1_example_error ' ) ;save ( ' TF_loop_1_example_fit ' , ' TF_loop_1_example_fit ' ) ;

%=========================================================================%% Test GA TF 1 exampleWaitbarHandle = waitbar (0 , 'TF GA 1 ' ) ;f o l d = 10;%4;f o l d e r = ' Resu l t s / ' ;

load ( [ num2str ( f o l d e r ) . . .' Transfer_Function_GA_1_example_fold_ ' num2str ( f o l d ) ] ) ;

Ts = Data . Ts ;w = Ts : Ts : 2 ;

c l e a r v a r s −except InDirectTF Ts w Rol l ingVal PitchVal . . .RudderVal WavesVal Cont_Spd_Val WaitbarHandle

[ samples , c a s e s ] = s i z e (WavesVal ) ;

g = 9 . 8 2 ;

f o r k = 1 : ca s e st i c ;Hs = WavesVal (1 , k ) ;Tp = WavesVal (2 , k ) ;Beta = WavesVal (3 , k ) ;

U = mean(Cont_Spd_Val ( : , k ) ) ;U = U ∗ 0 .5144443101 ; %convert to m/ s

omega_0 = (2∗ pi ) . /Tp ;T1 = (2∗ pi ) . / ( 1 . 2 9 5 7 . ∗ omega_0) ;ITTC = @(x ) ( (173∗ (Hs^2) /(T1^4) ) . / ( x .^5) ) .∗ exp (−((691/(T1^4) ) . / ( x .^4) ) ) ;

temp = ITTC(w) . / ( abs (1−((2.∗w.∗U) . / ( g ) ) ∗ cos ( Beta ) ) ) ;EncounterSpectrum ( : , k ) = temp ' ;

127

Page 129: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

MotionSpectrum = f f t ( Ro l l ingVal ( : , k ) ) ;Data_Inverse = iddata ( EncounterSpectrum ( : , k ) ,MotionSpectrum , Ts ) ;

[~ , TF_GA_1_example_fit ( k ) ] = compare ( Data_Inverse , InDirectTF ) ;

e lapsedt ime (k ) = toc ;Time = (sum( e lapsedt ime ) /k ) ∗( cases−k ) /60 ;EstimatedMinLeft = f l o o r (Time) ;Est imatedSecLeft = f l o o r ( (Time−EstimatedMinLeft ) ∗60) ;

s t r i n g = [ 'TF GA 1 \n Estimated time l e f t = ' num2str ( EstimatedMinLeft ) 'min 'num2str ( Est imatedSecLeft ) ' sec ' ] ;

waitbar ( ( k/ ca s e s ) ,WaitbarHandle , s p r i n t f ( s t r i n g ) ) ;

end

TF_GA_1_example_error = abs (100∗ ones ( s i z e (TF_GA_1_example_fit ) ) −TF_GA_1_example_fit ) ;

save ( 'TF_GA_1_example_error ' , ' TF_GA_1_example_error ' ) ;save ( 'TF_GA_1_example_fit ' , ' TF_GA_1_example_fit ' ) ;

%=========================================================================%%% Test GA TF s ev e r a l examplesWaitbarHandle = waitbar (0 , 'TF GA Severa l ' ) ;f o l d = 1;%2;f o l d e r = ' Resu l t s / ' ;

load ( [ num2str ( f o l d e r ) . . .' Transfer_Function_GA_Several_examples_fold_ ' num2str ( f o l d ) ] ) ;

w = Ts : Ts : 2 ;

c l e a r v a r s −except InDirectTF Ts w Rol l ingVal PitchVal . . .RudderVal WavesVal Cont_Spd_Val WaitbarHandle

[ samples , c a s e s ] = s i z e (WavesVal ) ;

g = 9 . 8 2 ;

f o r k = 1 : ca s e st i c ;Hs = WavesVal (1 , k ) ;Tp = WavesVal (2 , k ) ;Beta = WavesVal (3 , k ) ;

U = mean(Cont_Spd_Val ( : , k ) ) ;U = U ∗ 0 .5144443101 ; %convert to m/ s

omega_0 = (2∗ pi ) . /Tp ;T1 = (2∗ pi ) . / ( 1 . 2 9 5 7 . ∗ omega_0) ;ITTC = @(x ) ( (173∗ (Hs^2) /(T1^4) ) . / ( x .^5) ) .∗ exp (−((691/(T1^4) ) . / ( x .^4) ) ) ;

temp = ITTC(w) . / ( abs (1−((2.∗w.∗U) . / ( g ) ) ∗ cos ( Beta ) ) ) ;EncounterSpectrum ( : , k ) = temp ' ;

MotionSpectrum = f f t ( Ro l l ingVal ( : , k ) ) ;Data_Inverse = iddata ( EncounterSpectrum ( : , k ) ,MotionSpectrum , Ts ) ;

[~ , TF_GA_Several_examples_fit ( k ) ] = compare ( Data_Inverse , InDirectTF ) ;

e lapsedt ime (k ) = toc ;Time = (sum( e lapsedt ime ) /k ) ∗( cases−k ) /60 ;EstimatedMinLeft = f l o o r (Time) ;Est imatedSecLeft = f l o o r ( (Time−EstimatedMinLeft ) ∗60) ;

s t r i n g = [ 'TF GA Seve ra l \n Estimated time l e f t = ' num2str ( EstimatedMinLeft ) 'min ' num2str ( Est imatedSecLeft ) ' sec ' ] ;

waitbar ( ( k/ ca s e s ) ,WaitbarHandle , s p r i n t f ( s t r i n g ) ) ;

128

Page 130: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

end

TF_GA_Several_examples_error = abs (100∗ ones ( s i z e (TF_GA_Several_examples_fit ) ) −TF_GA_Several_examples_fit ) ;

save ( ' TF_GA_Several_examples_fit ' , ' TF_GA_Several_examples_fit ' ) ;save ( ' TF_GA_Several_examples_error ' , ' TF_GA_Several_examples_error ' ) ;

%=========================================================================%%% Test ANN RPROPWaitbarHandle = waitbar (0 , 'ANN RPROP' ) ;f o l d = 6;%1;f o l d e r = ' Resu l t s / ' ;

load ( [ num2str ( f o l d e r ) . . .'ANN_with_RPROP_fold_' num2str ( f o l d ) ] ) ;

w = Ts : Ts : 2 ;

c l e a r v a r s −except Rol l ingVal PitchVal . . .RudderVal WavesVal netBP WaitbarHandle

[ samples , c a s e s ] = s i z e (WavesVal ) ;

f o r k = 1 : ca s e st i c ;Hs = WavesVal (1 , k ) ;Tp = WavesVal (2 , k ) ;Beta = WavesVal (3 , k ) ;

e s t imat i on s ( : , k ) = netBP ( [ Ro l l ingVal ( : , k ) ; RudderVal ( : , k ) ; PitchVal ( : , k ) ] ) ;e s t imat i on s (3 , k ) = mod( e s t imat i on s (3 , k ) ,2∗ pi ) ;

i f ( Beta == 0)Beta = 2∗ pi ;e s t imat i on s (3 , k ) = e s t imat i on s (3 , k ) + 2∗ pi ;

end

ANN_RPROP_fit( 1 : 3 , k ) = 100 .∗ [ e s t imat i on s (1 , k ) /Hs ; e s t imat i on s (2 , k ) /Tp ;e s t imat i on s (3 , k ) /Beta ; ] ;

e l apsedt ime (k ) = toc ;Time = (sum( e lapsedt ime ) /k ) ∗( cases−k ) /60 ;EstimatedMinLeft = f l o o r (Time) ;Est imatedSecLeft = f l o o r ( (Time−EstimatedMinLeft ) ∗60) ;

s t r i n g = [ 'ANN RPROP \n Estimated time l e f t = ' num2str ( EstimatedMinLeft ) 'min' num2str ( Est imatedSecLeft ) ' sec ' ] ;

waitbar ( ( k/ ca s e s ) ,WaitbarHandle , s p r i n t f ( s t r i n g ) ) ;

end

ANN_RPROP_error = abs (100∗ ones ( s i z e (ANN_RPROP_fit) ) − ANN_RPROP_fit) ;

save ( 'ANN_RPROP_fit' , 'ANN_RPROP_fit' ) ;save ( 'ANN_RPROP_error' , 'ANN_RPROP_error ' ) ;

%=========================================================================%%% Test ANN GAWaitbarHandle = waitbar (0 , 'ANN GA' ) ;f o l d = 8;%5;f o l d e r = ' Resu l t s / ' ;

load ( [ num2str ( f o l d e r ) . . .'ANN_with_GA_fold_' num2str ( f o l d ) ] ) ;

w = Ts : Ts : 2 ;

129

Page 131: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

c l e a r v a r s −except Rol l ingVal PitchVal . . .RudderVal WavesVal netGA WaitbarHandle

[ samples , c a s e s ] = s i z e (WavesVal ) ;

f o r k = 1 : ca s e st i c ;Hs = WavesVal (1 , k ) ;Tp = WavesVal (2 , k ) ;Beta = WavesVal (3 , k ) ;

e s t imat i on s ( : , k ) = netGA ( [ Ro l l ingVal ( : , k ) ; RudderVal ( : , k ) ; PitchVal ( : , k ) ] ) ;e s t imat i on s (3 , k ) = mod( e s t imat i on s (3 , k ) ,2∗ pi ) ;

i f ( Beta == 0)Beta = 2∗ pi ;e s t imat i on s (3 , k ) = e s t imat i on s (3 , k ) + 2∗ pi ;

end

ANN_GA_fit ( 1 : 3 , k ) = 100 .∗ [ e s t imat i on s (1 , k ) /Hs ; e s t imat i on s (2 , k ) /Tp ; e s t imat i on s(3 , k ) /Beta ; ] ;

e l apsedt ime (k ) = toc ;Time = (sum( e lapsedt ime ) /k ) ∗( cases−k ) /60 ;EstimatedMinLeft = f l o o r (Time) ;Est imatedSecLeft = f l o o r ( (Time−EstimatedMinLeft ) ∗60) ;

s t r i n g = [ 'ANN GA \n Estimated time l e f t = ' num2str ( EstimatedMinLeft ) 'min 'num2str ( Est imatedSecLeft ) ' sec ' ] ;

waitbar ( ( k/ ca s e s ) ,WaitbarHandle , s p r i n t f ( s t r i n g ) ) ;

end

ANN_GA_error = abs (100∗ ones ( s i z e (ANN_GA_fit) ) − ANN_GA_fit) ;

save ( 'ANN_GA_fit ' , 'ANN_GA_fit ' ) ;save ( 'ANN_GA_error ' , 'ANN_GA_error ' ) ;

%=========================================================================%%% Test CBR EUCLIDIANWaitbarHandle = waitbar (0 , 'CBR Eucl id ian ' ) ;f o l d = 3;%1;f o l d e r = ' Resu l t s / ' ;

load ( [ num2str ( f o l d e r ) . . .' CBR_with_Euclidian_fold_ ' num2str ( f o l d ) ] ) ;

c l e a r v a r s −except Rol l ingVal PitchVal . . .RudderVal WavesVal x K nvars Ro l l i ng . . .Rudder Pitch Waves WaitbarHandle

[ samples , c a s e s ] = s i z e (WavesVal ) ;

e s t imat i on s = ze ro s (3 , c a s e s ) ;

f o r k = 1 : ca s e st i c ;Hs = WavesVal (1 , k ) ;Tp = WavesVal (2 , k ) ;Beta = WavesVal (3 , k ) ;

Case = 1 ;[ temp , ~ ] = Euc l id ian_dis tance (Case , nvars , . . .

Ro l l ing , Rudder , . . .Pitch , Ro l l ingVal ( : , k ) , . . .RudderVal ( : , k ) , PitchVal ( : , k ) ) ;

nearest_waves = temp ' ;

130

Page 132: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

f o r l = 1 :Ke s t imat i on s (1 , k ) = e s t imat i on s (1 , k ) + x( l ) ∗Waves (1 , nearest_waves ( l ) ) ;e s t imat i on s (2 , k ) = e s t imat i on s (2 , k ) + x( l+K) ∗Waves (2 , nearest_waves ( l ) ) ;e s t imat i on s (3 , k ) = e s t imat i on s (3 , k ) + x( l +(2∗K) ) ∗Waves (3 , nearest_waves ( l ) ) ;

end

i f ( Beta == 0)Beta = 2∗ pi ;e s t imat i on s (3 , k ) = e s t imat i on s (3 , k ) + 2∗ pi ;

end

CBR_Euclidian_fit ( 1 : 3 , k ) = 100 .∗ [ e s t imat i on s (1 , k ) /Hs ; e s t imat i on s (2 , k ) /Tp ;e s t imat i on s (3 , k ) /Beta ; ] ;

e l apsedt ime (k ) = toc ;Time = (sum( e lapsedt ime ) /k ) ∗( cases−k ) /60 ;EstimatedMinLeft = f l o o r (Time) ;Est imatedSecLeft = f l o o r ( (Time−EstimatedMinLeft ) ∗60) ;

s t r i n g = [ 'CBR Euc l id ian \n Estimated time l e f t = ' num2str ( EstimatedMinLeft ) 'min ' num2str ( Est imatedSecLeft ) ' sec ' ] ;

waitbar ( ( k/ ca s e s ) ,WaitbarHandle , s p r i n t f ( s t r i n g ) ) ;

end

CBR_Euclidian_error = abs (100∗ ones ( s i z e ( CBR_Euclidian_fit ) ) − CBR_Euclidian_fit ) ;

save ( ' CBR_Euclidian_fit ' , ' CBR_Euclidian_fit ' ) ;save ( ' CBR_Euclidian_error ' , ' CBR_Euclidian_error ' ) ;

%=========================================================================%%% Test CBR MANHATTANWaitbarHandle = waitbar (0 , 'CBR Manhattan ' ) ;f o l d = 3;%1;f o l d e r = ' Resu l t s / ' ;

load ( [ num2str ( f o l d e r ) . . .'CBR_with_Manhattan_fold_ ' num2str ( f o l d ) ] ) ;

c l e a r v a r s −except Rol l ingVal PitchVal . . .RudderVal WavesVal x K nvars Ro l l i ng . . .Rudder Pitch Waves WaitbarHandle

[ samples , c a s e s ] = s i z e (WavesVal ) ;

e s t imat i on s = ze ro s (3 , c a s e s ) ;

f o r k = 1 : ca s e st i c ;Hs = WavesVal (1 , k ) ;Tp = WavesVal (2 , k ) ;Beta = WavesVal (3 , k ) ;

Case = 1 ;[ temp , ~ ] = Manhattan_distance (Case , nvars , . . .

Ro l l ing , Rudder , . . .Pitch , Ro l l ingVal ( : , k ) , . . .RudderVal ( : , k ) , PitchVal ( : , k ) ) ;

nearest_waves = temp ' ;

f o r l = 1 :Ke s t imat i on s (1 , k ) = e s t imat i on s (1 , k ) + x( l ) ∗Waves (1 , nearest_waves ( l ) ) ;e s t imat i on s (2 , k ) = e s t imat i on s (2 , k ) + x( l+K) ∗Waves (2 , nearest_waves ( l ) ) ;e s t imat i on s (3 , k ) = e s t imat i on s (3 , k ) + x( l +(2∗K) ) ∗Waves (3 , nearest_waves ( l ) ) ;

end

i f ( Beta == 0)Beta = 2∗ pi ;e s t imat i on s (3 , k ) = e s t imat i on s (3 , k ) + 2∗ pi ;

131

Page 133: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

end

CBR_Manhattan_fit ( 1 : 3 , k ) = 100 .∗ [ e s t imat i on s (1 , k ) /Hs ; e s t imat i on s (2 , k ) /Tp ;e s t imat i on s (3 , k ) /Beta ; ] ;

e l apsedt ime (k ) = toc ;Time = (sum( e lapsedt ime ) /k ) ∗( cases−k ) /60 ;EstimatedMinLeft = f l o o r (Time) ;Est imatedSecLeft = f l o o r ( (Time−EstimatedMinLeft ) ∗60) ;

s t r i n g = [ 'CBR Manhattan \n Estimated time l e f t = ' num2str ( EstimatedMinLeft ) 'min ' num2str ( Est imatedSecLeft ) ' sec ' ] ;

waitbar ( ( k/ ca s e s ) ,WaitbarHandle , s p r i n t f ( s t r i n g ) ) ;

end

CBR_Manhattan_error = abs (100∗ ones ( s i z e (CBR_Manhattan_fit ) ) − CBR_Manhattan_fit ) ;

save ( ' CBR_Manhattan_fit ' , ' CBR_Manhattan_fit ' ) ;save ( ' CBR_Manhattan_error ' , ' CBR_Manhattan_error ' ) ;

Code E.8.1: Presented above is the source code utilized to test the pre-trained solutions (usingsimulated data) with actual data obtained from a wave buoy and M/S Mariella. The code utilizesthe functions presented in appendices E.4.3, E.6.2, and E.6.4.

132

Page 134: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.8.2 Plot Results

c l cc l e a rc l o s e a l l

load ( ' TF_loop_1_example_error ' )load ( 'TF_GA_1_example_error ' )load ( ' TF_GA_Several_examples_error ' )

load ( 'ANN_RPROP_error ' )load ( 'ANN_GA_error ' )load ( ' CBR_Euclidian_error ' )load ( ' CBR_Manhattan_error ' )

t = . 2 5 . ∗ ( 0 : l ength (TF_loop_1_example_error )−1) ;

f i g u r e (1 )hold ong r id ont i t l e ( ' Estimate Encounter spectrum us ing TF' )y l ab e l ( ' e r r o r (%) ' )x l ab e l ( ' time ( sec ) ' )p l o t ( t , TF_loop_1_example_error ) ;p l o t ( t , TF_GA_1_example_error ) ;p l o t ( t , TF_GA_Several_examples_error ) ;l egend ( ' loop ' , 'GA 1 ' , 'GA seve ra l ' )

Mean_loop = mean(TF_loop_1_example_error )

Mean_GA1 = mean(TF_GA_1_example_error )

Mean_GA_Several = mean(TF_GA_Several_examples_error )

f i g u r e (2 )hold ong r id ont i t l e ( ' Estimate Hs us ing AIs ' )y l ab e l ( ' e r r o r (%) ' )x l ab e l ( ' time ( sec ) ' )p l o t ( t , ANN_RPROP_error ( 1 , : ) ) ;p l o t ( t , ANN_GA_error ( 1 , : ) ) ;p l o t ( t , CBR_Euclidian_error ( 1 , : ) ) ;p l o t ( t , CBR_Manhattan_error ( 1 , : ) ) ;l egend ( 'ANN RPROP' , 'ANN GA' , 'CBR Eucl id ian ' , 'CBR Manhattan ' )

f i g u r e (3 )hold ong r id ont i t l e ( ' Estimate Tp us ing AIs ' )y l ab e l ( ' e r r o r (%) ' )x l ab e l ( ' time ( sec ) ' )p l o t ( t , ANN_RPROP_error ( 2 , : ) ) ;p l o t ( t , ANN_GA_error ( 2 , : ) ) ;p l o t ( t , CBR_Euclidian_error ( 2 , : ) ) ;p l o t ( t , CBR_Manhattan_error ( 2 , : ) ) ;l egend ( 'ANN RPROP' , 'ANN GA' , 'CBR Eucl id ian ' , 'CBR Manhattan ' )

f i g u r e (4 )hold ong r id ont i t l e ( ' Estimate Beta us ing AIs ' )y l ab e l ( ' e r r o r (%) ' )x l ab e l ( ' time ( sec ) ' )p l o t ( t , ANN_RPROP_error ( 3 , : ) ) ;p l o t ( t , ANN_GA_error ( 3 , : ) ) ;p l o t ( t , CBR_Euclidian_error ( 3 , : ) ) ;p l o t ( t , CBR_Manhattan_error ( 3 , : ) ) ;l egend ( 'ANN RPROP' , 'ANN GA' , 'CBR Eucl id ian ' , 'CBR Manhattan ' )

133

Page 135: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Mean_ANN_RPROP = mean(ANN_RPROP_error, 2 )

Mean_ANN_GA = mean(ANN_GA_error , 2 )

Mean_CBR_Euclidian = mean(CBR_Euclidian_error , 2 )

Mean_CBR_Manhattan = mean(CBR_Manhattan_error , 2 )

Code E.8.2: Presented above is the source code utilized to plot and present the result obtainedwith the program presented in appendix E.8.1.

134

Page 136: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.9 Transfer Function For Training And Validating With Actual Data

The following sections presents the code implemented for the TF based solutions utilizing actualdata.

E.9.1 Loop Based

%c l c%c l e a r v a r s −except f o l d%c l o s e a l lwarning ( ' o f f ' , ' a l l ' ) ;

%Use va r i ab l e f o l d to change which case to use f o r the t r a i n i n gf i l ename = [ ' TF_Loop_Based_On_Actual_Data .mat ' ] ;

f o l d = 9 ;

%Check i f the v a r i a b l e s have been save from a prev ious t e s ti f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )%The va r i a b l e s have not been saved to run the t e s t

e l s e%% −−−−−−−−−−−−−−−−−−−−−−−− INITIALIZE −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−load ( ' columnLabels ' ) ;load ( ' Ship_data ' ) ;Ship_data1 = Ship_data ;load ( 'D_2017−04−03') ;Ship_data2 = Ship_data ;load ( 'D_2017−04−04') ;Ship_data3 = Ship_data ;load ( 'Waves_2017_04_03 ' ) ;load ( 'Waves_2017_04_04 ' ) ;load ( 'Waves_2017_04_05 ' ) ;

[ row , c o l ] =s i z e (Waves_2017_04_04) ;Ship_data = [ Ship_data1 ( : , 1 : 7 3 ) ; Ship_data2 ( 1 : row , : ) ] ;

[ row , c o l ] =s i z e ( Ship_data1 ) ;Waves_init = [Waves_2017_04_03 ( 1 : row , : ) ;Waves_2017_04_04 ( : , : ) ] ;

%TrainingAmount = 1/2 ;

[ samples , ~ ] = s i z e ( Ship_data ) ;t r a i n c a s e s = f l o o r ( samples /101) ;

[ samples , ~ ] = s i z e ( Ship_data3 ) ;v a l c a s e s = f l o o r ( samples /101) ;

f o r k = 1 : t r a i n c a s e sa = 1+(k−1) ∗100 ;Ro l l i ng ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RollRaw ) ;Pitch (1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudder ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RudderPos ) ;Cont_spd (1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . SpeedThroughWater ) ;Waves (1 , k ) = mean(Waves_init ( ( a : a+100) ,2 ) ) ;Waves (2 , k ) = mean(Waves_init ( ( a : a+100) ,3 ) ) ;Waves (3 , k ) = mod(360 + mean(Waves_init ( ( a : a+100) ,4 ) )−mean( Ship_data ( ( a : a

+100) , columnLabels . Heading ) ) ,360) ;end

f o r k = 1 : va l c a s e sa = 1+(k−1) ∗100 ;Ro l l i n gva l ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RollRaw ) ;P i t chva l ( 1 : 1 01 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudderval ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RudderPos ) ;Cont_spdval ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . SpeedThroughWater )

;Wavesval (1 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,2 ) ) ;Wavesval (2 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,3 ) ) ;

135

Page 137: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Wavesval (3 , k ) = mod(360 + mean(Waves_2017_04_05 ( ( a : a+100) ,4 ) )−mean(Ship_data3 ( ( a : a+100) , columnLabels . Heading ) ) ,360) ;

end

% Convert Degrees to rad iansWaves ( 3 , : ) = Waves ( 3 , : ) ∗( p i /180) ;Wavesval ( 3 , : ) = Wavesval ( 3 , : ) ∗( p i /180) ;

[~ , C] = s i z e ( Ro l l i ng ) ;

%choose case to t r a i n and va l i d a t e upon%Chooses the f i r s t case with in the preceed ing f o l d o f the va l i d a t i o n%f o l d . E. g . i f v a l i d a t i o n f o l d = 1 then t r a i n i n g case i s case 1 from%fo l d 2 .TrainCase = ( fo ld −1)∗(C/9)+1;TrainCase = round ( TrainCase ) ;i f ( TrainCase > C)

TrainCase = 1 ;endRo l l i ng = Ro l l i ng ( : , TrainCase ) ; %Retr i eve the r o l l i n g o f the sh ipHs = Waves (1 , TrainCase ) ; %Retr i eve the s i g n i f i c a n t waveheightTp = Waves (2 , TrainCase ) ; %Retr i eve the peak per iodBeta = Waves (3 , TrainCase ) ; %Retr i eve the encounter ang le

%Retr i eve the average sh ip speed during t h i s sample timeU = mean(Cont_spd ( : , TrainCase ) ) ;U = U ∗ 0 .5144443101 ; %convert to m/ s

g = 9 . 8 2 ; %grav i ty constant[ row , ~] = s i z e ( Ro l l i ng ) ;w_lim = 2 ;w_step = w_lim/row ;w = w_step : w_step : w_lim ; %Frequency vec to r

Ts = w_step ;%.25 ; %Sampling time o f the data i s a l s o constant

%Setup Wave Spectrum (ITTC)omega_0 = (2∗ pi ) /Tp ;T1 = (2∗ pi ) /(1 .2957∗omega_0) ;ITTC = @(x ) ( (173∗ (Hs^2) /(T1^4) ) . / ( x .^5) ) .∗ exp (−((691/(T1^4) ) . / ( x .^4) ) ) ;

%Use Tr i s tan Perez c a l c u l a t i o n s to r e t r i e v e the EncounterSpectrum%This i s the input o f the Trans fe r func t i on f o r the Di rec t Method%and output f o r the Trans fe r Function f o r the In−d i r e c t methodEncounterSpectrum = ITTC(w) . / ( abs (1−((2.∗w.∗U) . / ( g ) ) ∗ cos ( Beta ) ) ) ;EncounterSpectrum = EncounterSpectrum ' ;

%The output f o r the Trans fe r func t i on in Di rec t method i s g iven%by the motion spectrum f o r the r o l l i n g , which i s r e t r i e v e d with f f t .%And the input f o r the in−d i r e c t t r a n s f e r func t i on i s a l s o the motion%spectrumMotionSpectrum = f f t ( Ro l l i ng ) ;

%Var iab l e s f o r the loop ingnuminators_max = 70 ;numinators_min = 1 ;i t e r a t i o n = 0 ;e lapsedt ime = 0 ;s u c c e s s e s = 0 ;e r r o r s = 0 ;improvements = 0 ;t o t a l = 0 ;f o r n = numinators_min : numinators_max

t o t a l = t o t a l +1;end

%% −−−−−−−−−−−−−−−−−−LOOP FOR THE DIRECT METHOD−−−−−−−−−−−−−−−−−−−−−−−−−−−−Bar = waitbar (0 , ' Ca l cu l a t ing Motion TF' ) ;d i sp ( ' Begin Ca l cu l a t ing Motion TF' ) ;

136

Page 138: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

%Setup the Input output data f o r t f e s t commandData = iddata (MotionSpectrum , EncounterSpectrum , Ts ) ;

%Estimate the f i r s t t r a n s f e r func t i onDirectTF = t f e s t (Data , 1 , 0 , ' Ts ' , Ts ) ;[~ , f i t ] = compare (Data , DirectTF ) ;

%% Loop f o r bes t setup o f t r a n s f e r func t i on%Loop which i n c r e a s e s the number o f numinators f o r the t r a n s f e r func t i on%and c a l c u l a t e s the best f i tf o r n = numinators_min : numinators_max

%Update the waitbart i c ;i t e r a t i o n = i t e r a t i o n +1;Time = (sum( e lapsedt ime ) / i t e r a t i o n ) ∗( t o ta l−i t e r a t i o n ) /60 ;EstimatedMinLeft = f l o o r (Time) ;Est imatedSecLeft = f l o o r ( (Time−EstimatedMinLeft ) ∗60) ;s t r i n g = [ ' no TF found = ' num2str ( s u c c e s s e s ) ' , e r r o r s = ' num2str ( e r r o r s )

' , no Improved TF = ' num2str ( improvements ) '\n cur rent i t e r a t i o n = 'num2str ( s u c c e s s e s + e r r o r s + 1) ' , t o t a l i t e r a t i o n s = ' num2str ( t o t a l )'\n Estimated time l e f t = ' num2str ( EstimatedMinLeft ) 'min ' num2str (Est imatedSecLeft ) ' sec ' ] ;

waitbar ( i t e r a t i o n / to ta l , Bar , s p r i n t f ( s t r i n g ) ) ;

% Search f o r new and be t t e r TFtry

temp = t f e s t (Data , n , [ ] , ' Ts ' , Ts ) ;[ y1 , f i t 1 ] = compare (Data , temp) ;i f ( f i t 1 > f i t )

DirectTF = temp ;f i t = f i t 1 ;improvements = improvements + 1 ;

endsu c c e s s e s = su c c e s s e s +1;

catche r r o r s = e r r o r s +1;

ende lapsedt ime ( i t e r a t i o n ) = toc ;

endc l o s e (Bar )

f i g u r ecompare (Data , DirectTF )[Y, f i t_motion ] = compare (Data , DirectTF ) ;hold ont i t l e ( ' Encounter Spectrum to Motion Spectrum ' )

Est_motion_spectrum = Y. y ; %The est imated motion Spectrum

f i g u r ehold ong r id ont i t l e ( ' Ro l l i ng o f ship , us ing t ra in ing ' )p l o t ( 0 : Ts : ( row−1)∗Ts , Rol l ing , ' k ' )p l o t ( 0 : Ts : ( row−1)∗Ts , i f f t ( Est_motion_spectrum ) ,'−−r ' )%c a l c u l a t e r o l l i n g accuracyPerc = 100−100∗sum( abs ( Rol l ing− i f f t ( Est_motion_spectrum ) ) .^2) /sum( abs ( Ro l l i ng )

.^2) ;f i t _ r o l l i n g = Perc ;l egend ( ' Act Rol l ing ' , [ ' Est Rol l ing ' num2str ( Perc ) '% ' ] )

%% −−−−−−−−−−−−−−−−−−LOOP FOR THE IN−DIRECT METHOD−−−−−−−−−−−−−−−−−−−−−−−−−−−−i t e r a t i o n = 0 ;e lapsedt ime = 0 ;s u c c e s s e s = 0 ;e r r o r s = 0 ;

137

Page 139: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

improvements = 0 ;

Bar = waitbar (0 , ' Ca l cu l a t ing Encounter TF' ) ;d i sp ( ' Ca l cu l a t ing Encounter TF' ) ;

%Setup the Input output data f o r t f e s t commandData = iddata ( EncounterSpectrum , MotionSpectrum , Ts ) ;

best_n = 1 ;%Estimate the f i r s t t r a n s f e r func t i onInDirectTF = t f e s t (Data , 1 , 1 , ' Ts ' , Ts ) ;[ y f i t ] = compare (Data , InDirectTF ) ;

%% Loop f o r bes t setup o f t r a n s f e r func t i on%Loop which i n c r e a s e s the number o f numinators f o r the t r a n s f e r func t i on%and c a l c u l a t e s the best f i tf o r n = numinators_min : numinators_max

%Update the waitbart i c ;i t e r a t i o n = i t e r a t i o n +1;Time = (sum( e lapsedt ime ) / i t e r a t i o n ) ∗( t o ta l−i t e r a t i o n ) /60 ;EstimatedMinLeft = f l o o r (Time) ;Est imatedSecLeft = f l o o r ( (Time−EstimatedMinLeft ) ∗60) ;s t r i n g = [ ' no TF found = ' num2str ( s u c c e s s e s ) ' , e r r o r s = ' num2str ( e r r o r s )

' , no Improved TF = ' num2str ( improvements ) '\n cur rent i t e r a t i o n = 'num2str ( s u c c e s s e s + e r r o r s + 1) ' , t o t a l i t e r a t i o n s = ' num2str ( t o t a l )'\n Estimated time l e f t = ' num2str ( EstimatedMinLeft ) 'min ' num2str (Est imatedSecLeft ) ' sec ' ] ;

waitbar ( i t e r a t i o n / to ta l , Bar , s p r i n t f ( s t r i n g ) ) ;

% Search f o r new and be t t e r TFtry

temp = t f e s t (Data , n , [ ] , ' Ts ' , Ts ) ;[ y1 , f i t 1 ] = compare (Data , temp) ;i f ( f i t 1 > f i t )

InDirectTF = temp ;f i t = f i t 1 ;improvements = improvements + 1 ;best_n = n ;

endsu c c e s s e s = su c c e s s e s +1;

catche r r o r s = e r r o r s +1;

ende lapsedt ime ( i t e r a t i o n ) = toc ;

endc l o s e (Bar )

f i g u r ecompare (Data , InDirectTF )[Y, f i t_encounte r ] = compare (Data , InDirectTF ) ;hold ont i t l e ( ' Est imation o f Encounter Spectrum , Using t r a i n i n g Data ' )

Est_encounter_spectrum = Y. y ; %Estimated encounter spectrum

%% VALIDATE THE TF[~ , c o l ] = s i z e (Wavesval ) ;f o r k = 1 : c o l

FIT ( : , k ) = ValidateMyTFs ( Ro l l i n gva l ( : , k ) ,Wavesval ( : , k ) , Cont_spdval ( : , k ) ,DirectTF , InDirectTF ) ;

end

save ( f i l ename )end

Code E.9.1: Above is the source code implemented in MATLAB for the loop based TF usingonly actual logged data for training and validation. The code utilized the function presented inappendix E.4.3.

138

Page 140: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.9.2 Genetic Algorithm And One Example Based

%c l c%c l e a r v a r s −except f o l d%c l o s e a l lwarning ( ' o f f ' , ' a l l ' ) ;

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )%f o l d = 1 ;f i l ename = [ 'TF_GA_1_Based_On_Actual_Data .mat ' ] ;

f o l d = 9 ;

%Check i f the v a r i a b l e s have been save from a prev ious t e s ti f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )%The va r i a b l e s have not been saved to run the t e s t

e l s e%% −−−−−−−−−−−−−−−−−−−−−−−− INITIALIZE −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−load ( ' columnLabels ' ) ;load ( ' Ship_data ' ) ;Ship_data1 = Ship_data ;load ( 'D_2017−04−03') ;Ship_data2 = Ship_data ;load ( 'D_2017−04−04') ;Ship_data3 = Ship_data ;load ( 'Waves_2017_04_03 ' ) ;load ( 'Waves_2017_04_04 ' ) ;load ( 'Waves_2017_04_05 ' ) ;

[ row , c o l ] =s i z e (Waves_2017_04_04) ;Ship_data = [ Ship_data1 ( : , 1 : 7 3 ) ; Ship_data2 ( 1 : row , : ) ] ;

[ row , c o l ] =s i z e ( Ship_data1 ) ;Waves_init = [Waves_2017_04_03 ( 1 : row , : ) ;Waves_2017_04_04 ( : , : ) ] ;

%TrainingAmount = 1/2 ;

[ samples , ~ ] = s i z e ( Ship_data ) ;t r a i n c a s e s = f l o o r ( samples /101) ;

[ samples , ~ ] = s i z e ( Ship_data3 ) ;v a l c a s e s = f l o o r ( samples /101) ;

f o r k = 1 : t r a i n c a s e sa = 1+(k−1) ∗100 ;Ro l l i ng ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RollRaw ) ;Pitch (1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudder ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RudderPos ) ;Cont_spd (1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . SpeedThroughWater ) ;Waves (1 , k ) = mean(Waves_init ( ( a : a+100) ,2 ) ) ;Waves (2 , k ) = mean(Waves_init ( ( a : a+100) ,3 ) ) ;Waves (3 , k ) = mod(360 + mean(Waves_init ( ( a : a+100) ,4 ) )−mean( Ship_data ( ( a : a

+100) , columnLabels . Heading ) ) ,360) ;end

f o r k = 1 : va l c a s e sa = 1+(k−1) ∗100 ;Ro l l i n gva l ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RollRaw ) ;P i t chva l ( 1 : 1 01 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudderval ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RudderPos ) ;Cont_spdval ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . SpeedThroughWater )

;Wavesval (1 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,2 ) ) ;Wavesval (2 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,3 ) ) ;Wavesval (3 , k ) = mod(360 + mean(Waves_2017_04_05 ( ( a : a+100) ,4 ) )−mean(

Ship_data3 ( ( a : a+100) , columnLabels . Heading ) ) ,360) ;end

139

Page 141: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Waves ( 3 , : ) = Waves ( 3 , : ) ∗( p i /180) ;Wavesval ( 3 , : ) = Wavesval ( 3 , : ) ∗( p i /180) ;

[~ , C] = s i z e ( Ro l l i ng ) ;

%chose case to t r a i n and va l i d a t e upon%TrainCase = 1 ;TrainCase = ( fo ld −1)∗(C/9)+1;TrainCase = round ( TrainCase ) ;i f ( TrainCase > C)

TrainCase = 1 ;endRo l l i ng = Ro l l i ng ( : , TrainCase ) ; %Retr i eve the r o l l i n g o f the sh ipHs = Waves (1 , TrainCase ) ; %Retr i eve the s i g n i f i c a n t waveheightTp = Waves (2 , TrainCase ) ; %Retr i eve the peak per iodBeta = Waves (3 , TrainCase ) ; %Retr i eve the encounter ang le

U = mean(Cont_spd ( : , TrainCase ) ) ; %Average sh ipspeed i s constant f o r a l l the data

U = U ∗ 0 .5144443101 ; %convert to m/ s

g = 9 . 8 2 ; %grav i ty constant[ row , ~] = s i z e ( Ro l l i ng ) ;w_lim = 2 ;w_step = w_lim/row ;w = w_step : w_step : w_lim ; %Frequency vec to r

Ts = w_step ;%.25 ; %Sampling time o f the data i s a l s oconstant

%Setup Wave Spectrum (ITTC)omega_0 = (2∗ pi ) /Tp ;T1 = (2∗ pi ) /(1 .2957∗omega_0) ;ITTC = @(x ) ( (173∗ (Hs^2) /(T1^4) ) . / ( x .^5) ) .∗ exp (−((691/(T1^4) ) . / ( x .^4) ) ) ;

%Use Tr i s tan Perez c a l c u l a t i o n s to r e t r i e v e the EncounterSpectrum%This i s the input o f the Trans fe r func t i on f o r the Di rec t Method%and output f o r the Trans fe r Function f o r the In−d i r e c t methodEncounterSpectrum = ITTC(w) . / ( abs (1−((2.∗w.∗U) . / ( g ) ) ∗ cos ( Beta ) ) ) ;EncounterSpectrum = EncounterSpectrum ' ;

%The output f o r the Trans fe r func t i on in Di rec t method i s g iven%by the motion spectrum f o r the r o l l i n g , which i s r e t r i e v e d with f f t .%And the input f o r the in−d i r e c t t r a n s f e r func t i on i s a l s o the motion%spectrumMotionSpectrum = f f t ( Ro l l i ng ) ;

%%========================================================================================

disp ( ' Ca l cu l a t ing Motion TF' ) ;%Setup the Input output data f o r the d i r e c t methodDirect_Data = iddata (MotionSpectrum , EncounterSpectrum , Ts ) ;%Setup the Input output data f o r the in−d i r e c t methodInDirect_Data = iddata ( EncounterSpectrum , MotionSpectrum , Ts ) ;

nvars = 400 ; %number o f v a r i a b l e s to es t imate with the GA ( nvars = 200−> 50r e a l and 50 complex numerators , and 50 r e a l and 50 complex denominators )

%Setup the GAga_opts = gaopt imset (@ga) ;ga_opts . Display = ' i t e r ' ;ga_opts . Popu lat ionS ize = 100 ;

%hours = 1 ;minute = 30 ; %maximum minutes which the GA i s a l lowed to search f o r the

v a r i a b l e s

140

Page 142: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

ga_opts . TimeLimit = minute ∗60 ;ga_opts . Generat ions = i n f ;ga_opts . PopInitRange = [ −1 ; 1 ] ;ga_opts . TolFun = 1e−20;ga_opts . TolCon = 1e−20;ga_opts . Sta l lGenLimit = 1000 ;%ga_opts . F i tne s sL imi t = 1 ;

%% FIND DIRECT TFData = Direct_Data ;[ x , ~ ] = ga ( @f i tnes s_di r r , nvars , ga_opts ) ;nom = nvars /4 ;a = x ( 1 , 1 :nom) + x (1 , (nom+1) :2∗nom) ∗1 i ;b = x (1 ,2∗nom+1:3∗nom) + x (1 ,3∗nom + 1 : nvars ) ∗1 i ;% a = x (1 , 1 : 2∗nom) ;% b = x (1 ,2∗nom+1:n) ;

DirectTF = t f (b , a , ' Ts ' , Ts , ' va r i ab l e ' , ' z^−1') ;

f i g u r ecompare ( Direct_Data , DirectTF ) ;[Y, f i t_motion ] = compare (Data , DirectTF ) ;Out = Y. y ;

%Plot the est imated r o l l i n g o f the sh ip based on d i r e c t methodf i g u r ehold ong r id ont i t l e ( ' Ro l l i ng o f ship , us ing t ra in ing ' )p l o t ( 0 : Ts : ( row−1)∗Ts , Rol l ing , ' k ' )p l o t ( 0 : Ts : ( row−1)∗Ts , i f f t (Out) ,'−−r ' )Perc = 100−100∗sum( abs ( Rol l ing− i f f t (Out) ) .^2) /sum( abs ( Ro l l i ng ) .^2) ;f i t _ r o l l i n g = Perc ;l egend ( ' Act Rol l ing ' , [ ' Est Rol l ing ' num2str ( Perc ) '% ' ] )

%% FIND INDIRECT TFData = InDirect_Data ;[ y , ~ ] = ga ( @f i tness_in_dirr , nvars , ga_opts ) ;nom = nvars /4 ;a = y ( 1 , 1 :nom) + y (1 , (nom+1) :2∗nom) ∗1 i ;b = y (1 ,2∗nom+1:3∗nom) + y (1 ,3∗nom + 1 : nvars ) ∗1 i ;% a = y (1 , 1 : 2∗nom) ;% b = y (1 ,2∗nom+1: nvars ) ;

InDirectTF = t f (b , a , ' Ts ' , Ts , ' va r i ab l e ' , ' z^−1') ;

%Plot the s o l u t i o n f o r in−d i r e c t methodf i g u r ehold ong r id oncompare (Data , InDirectTF )[Y, f i t_encounte r ] = compare (Data , InDirectTF ) ;hold ont i t l e ( ' Est imation o f Encounter Spectrum , Using t r a i n i n g Data ' )

%% VALIDATE THE TF[~ , c o l ] = s i z e (Wavesval ) ;f o r k = 1 : c o l

FIT ( : , k ) = ValidateMyTFs ( Ro l l i n gva l ( : , k ) ,Wavesval ( : , k ) , Cont_spdval ( : , k ) ,DirectTF , InDirectTF ) ;

endsave ( f i l ename ) ;

end

%% DIRECT FITNESS FUNCTIONfunc t i on f i t = f i t n e s s_d i r r ( x )%Retr i eve s p e c i f i c v a r i a b l e s from workspacen = eva l i n ( ' base ' , ' nvars ' ) ;

141

Page 143: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

t s = eva l i n ( ' base ' , ' Ts ' ) ;data = eva l i n ( ' base ' , ' Data ' ) ;motion = eva l i n ( ' base ' , ' MotionSpectrum ' ) ;encounter = eva l i n ( ' base ' , ' EncounterSpectrum ' ) ;

t ry

nom = n/4 ;a = x ( 1 , 1 :nom) + x (1 , (nom+1) :2∗nom) ∗1 i ;b = x (1 ,2∗nom+1:3∗nom) + x (1 ,3∗nom + 1 : n) ∗1 i ;

%try to f i nd a TF us ing the va r i ab l e s , and c a l c u l a t e the f i tt f 1 = t f (b , a , ' Ts ' , ts , ' va r i ab l e ' , ' z^−1') ;[~ , f i t ] = compare ( data , t f 1 ) ;f i t = abs ( f i t −100) ;

catch% i f the v a r i a b l e s can ' t generate a TF then the f i t va lue f o r the se% va r i a b l e s i s s e t to nanf i t = nan ;

end

end

%% IN DIRR FITNESS FUNCTIONfunc t i on f i t = f i tn e s s_ in_d i r r ( x )%Retr i eve s p e c i f i c v a r i a b l e s from workspacen = eva l i n ( ' base ' , ' nvars ' ) ;t s = eva l i n ( ' base ' , ' Ts ' ) ;data = eva l i n ( ' base ' , ' Data ' ) ;motion = eva l i n ( ' base ' , ' MotionSpectrum ' ) ;encounter = eva l i n ( ' base ' , ' EncounterSpectrum ' ) ;

t ry

nom = n/4 ;a = x ( 1 , 1 :nom) + x (1 , (nom+1) :2∗nom) ∗1 i ;b = x (1 ,2∗nom+1:3∗nom) + x (1 ,3∗nom + 1 : n) ∗1 i ;out = f i l t e r (b , a , motion ) ;

f i t 1 = sum( ( r e a l ( encounter )−r e a l ( out ) ) .^2) / l ength ( r e a l ( encounter ) ) ;f i t 2 = sum( ( imag ( encounter )−imag ( out ) ) .^2) / l ength ( imag ( encounter ) ) ;f i t = ( f i t 1+f i t 2 ) /2 ;

catch% i f the v a r i a b l e s can ' t generate a TF then the f i t va lue f o r the se% va r i a b l e s i s s e t to nanf i t = nan ;

end

end

Code E.9.2: Above is the source code implemented in MATLAB for the GA with 1 examplebased TF using only actual logged data for training and validation. The code utilizes the functionpresented in appendix E.4.3.

142

Page 144: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.9.3 Genetic Algorithm And Several Examples Based

%c l c%c l e a r v a r s −except f o l d%c l o s e a l lwarning ( ' o f f ' , ' a l l ' ) ;

Resu l t_fo lder = ' Resu l t s / ' ;

f i l ename = [ ' TF_GA_Several_Based_On_Actual_Data .mat ' ] ;

f o l d = 9 ;

%Check i f the v a r i a b l e s have been save from a prev ious t e s ti f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )%The va r i a b l e s have not been saved to run the t e s t

e l s e%% −−−−−−−−−−−−−−−−−−−−−−−− INITIALIZE −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−load ( ' columnLabels ' ) ;load ( ' Ship_data ' ) ;Ship_data1 = Ship_data ;load ( 'D_2017−04−03') ;Ship_data2 = Ship_data ;load ( 'D_2017−04−04') ;Ship_data3 = Ship_data ;load ( 'Waves_2017_04_03 ' ) ;load ( 'Waves_2017_04_04 ' ) ;load ( 'Waves_2017_04_05 ' ) ;

[ row , c o l ] =s i z e (Waves_2017_04_04) ;Ship_data = [ Ship_data1 ( : , 1 : 7 3 ) ; Ship_data2 ( 1 : row , : ) ] ;

[ row , c o l ] =s i z e ( Ship_data1 ) ;Waves_init = [Waves_2017_04_03 ( 1 : row , : ) ;Waves_2017_04_04 ( : , : ) ] ;

[ samples , ~ ] = s i z e ( Ship_data ) ;t r a i n c a s e s = f l o o r ( samples /101) ;

[ samples , ~ ] = s i z e ( Ship_data3 ) ;v a l c a s e s = f l o o r ( samples /101) ;

f o r k = 1 : t r a i n c a s e sa = 1+(k−1) ∗100 ;Ro l l i ng ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RollRaw ) ;Pitch (1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudder ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RudderPos ) ;Cont_spd (1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . SpeedThroughWater ) ;Waves (1 , k ) = mean(Waves_init ( ( a : a+100) ,2 ) ) ;Waves (2 , k ) = mean(Waves_init ( ( a : a+100) ,3 ) ) ;Waves (3 , k ) = mod(360 + mean(Waves_init ( ( a : a+100) ,4 ) )−mean( Ship_data ( ( a : a

+100) , columnLabels . Heading ) ) ,360) ;end

f o r k = 1 : va l c a s e sa = 1+(k−1) ∗100 ;Ro l l i n gva l ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RollRaw ) ;P i t chva l ( 1 : 1 01 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudderval ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RudderPos ) ;Cont_spdval ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . SpeedThroughWater )

;Wavesval (1 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,2 ) ) ;Wavesval (2 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,3 ) ) ;Wavesval (3 , k ) = mod(360 + mean(Waves_2017_04_05 ( ( a : a+100) ,4 ) )−mean(

Ship_data3 ( ( a : a+100) , columnLabels . Heading ) ) ,360) ;endd i sp ( ' data loaded ' )

143

Page 145: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Waves ( 3 , : ) = Waves ( 3 , : ) ∗( p i /180) ;Wavesval ( 3 , : ) = Wavesval ( 3 , : ) ∗( p i /180) ;

hours = . 5 ;minute = hours ∗60 ;

[ Samples , Cases ] = s i z e ( Ro l l i ng ) ;

f o r Case = 1 : CasesU(Case ) = mean(Cont_spd ( : , Case ) ) ; %Average

sh ip speed i s constant f o r a l l the dataU(Case ) = U(Case ) ∗ 0 .5144443101 ; %convert to m/ s

end

g = 9 . 8 2 ; %grav i ty constantw_lim = 2 ;w_step = w_lim/Samples ;w = w_step : w_step : w_lim ; %Frequency vec to r

Ts = w_step ;%.25 ; %Sampling time o f the data i s a l s oconstant

Hs = Waves ( 1 , : ) ;Tp = Waves ( 2 , : ) ;Beta = Waves ( 3 , : ) ;

%Setup Wave Spectrum (ITTC)omega_0 =@(k ) (2∗ pi ) . /Tp(k ) ;T1 = @(k ) (2∗ pi ) . / ( 1 . 2 9 5 7 . ∗ omega_0(k ) ) ;ITTC = @(x , k ) ( (173∗ (Hs(k ) ^2) . / (T1(k ) ^4) ) . / ( x .^5) ) .∗ exp (−((691 ./(T1(k ) ^4) ) . / ( x

.^4) ) ) ;

%Use Tr i s tan Perez c a l c u l a t i o n s to r e t r i e v e the EncounterSpectrum%This i s the input o f the Trans fe r func t i on f o r the Di rec t Method%and output f o r the Trans fe r Function f o r the In−d i r e c t method%The output f o r the Trans fe r func t i on in Di rec t method i s g iven%by the motion spectrum f o r the r o l l i n g , which i s r e t r i e v e d with f f t .%And the input f o r the in−d i r e c t t r a n s f e r func t i on i s a l s o the motion%spectrumf o r k = 1 : Cases

ktemp = ITTC(w, k ) . / ( abs (1−((2.∗w.∗U(k ) ) . / ( g ) ) .∗ cos ( Beta (k ) ) ) ) ;i f k == 1

EncounterSpectrum = temp ' ;MotionSpectrum = f f t ( Ro l l i ng ( : , k ) ) ;

e l s eEncounterSpectrum = [ EncounterSpectrum temp ' ] ;MotionSpectrum = [ MotionSpectrum f f t ( Ro l l i ng ( : , k ) ) ] ;

endend

nvars = 400 ; %number o f v a r i a b l e s to es t imate with the GA ( nvars = 200−> 50r e a l and 50 complex numerators , and 50 r e a l and 50 complex denominators )

%Setup the GAga_opts = gaopt imset (@ga) ;ga_opts . Display = ' i t e r ' ;ga_opts . Popu lat ionS ize = 10 ;ga_opts . TimeLimit = minute ∗60 ;ga_opts . Generat ions = i n f ;ga_opts . PopInitRange = [ −1 ; 1 ] ;ga_opts . TolFun = 1e−20;ga_opts . TolCon = 1e−20;ga_opts . Sta l lGenLimit = 1000 ;

%%========================================================================================

144

Page 146: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

di sp ( ' Ca l cu l a t ing Di rec t TF' ) ;

% %% FIND DIRECT TF% [ x , ~ ] = ga ( @f i tnes s_di r r , nvars , ga_opts ) ;% nom = nvars /4 ;% a = x ( 1 , 1 :nom) + x (1 , (nom+1) :2∗nom) ∗1 i ;% b = x (1 ,2∗nom+1:3∗nom) + x (1 ,3∗nom + 1 : nvars ) ∗1 i ;%% DirectTF = t f (b , a , ' Ts ' , Ts , ' va r i ab l e ' , ' z^−1') ;%

%% FIND INDIRECT TF%Setup the GAdisp ( ' Ca l cu l a t ing In−Direc t TF' ) ;

[ y , ~ ] = ga ( @f i tness_in_dirr , nvars , ga_opts ) ;nom = nvars /4 ;a = y ( 1 , 1 :nom) + y (1 , (nom+1) :2∗nom) ∗1 i ;b = y (1 ,2∗nom+1:3∗nom) + y (1 ,3∗nom + 1 : nvars ) ∗1 i ;% a = y (1 , 1 : 2∗nom) ;% b = y (1 ,2∗nom+1: nvars ) ;

InDirectTF = t f (b , a , ' Ts ' , Ts , ' va r i ab l e ' , ' z^−1') ;

%% VALIDATE THE TF[~ , c o l ] = s i z e (Wavesval ) ;f o r k = 1 : c o l

FIT ( : , k ) = ValidateMyTFs ( Ro l l i n gva l ( : , k ) ,Wavesval ( : , k ) , Cont_spdval ( : , k ) , [ ] ,InDirectTF ) ;

endsave ( f i l ename )

end

%% DIRECT FITNESS FUNCTIONfunc t i on FIT = f i t n e s s_d i r r ( x )%Retr i eve s p e c i f i c v a r i a b l e s from workspacen = eva l i n ( ' base ' , ' nvars ' ) ;t s = eva l i n ( ' base ' , ' Ts ' ) ;EncounterSpectrum = eva l i n ( ' base ' , ' EncounterSpectrum ' ) ;MotionSpectrum = eva l i n ( ' base ' , ' MotionSpectrum ' ) ;

[~ , c o l ] = s i z e (MotionSpectrum ) ;FIT = 0 ;f o r k = 1 : c o l

%Setup the Input output data f o r the d i r e c t methodmotion = MotionSpectrum ( : , k ) ;encounter = EncounterSpectrum ( : , k ) ;t ry

data = iddata (motion , encounter , ' Ts ' , t s ) ;nom = n/4 ;a = x ( 1 , 1 :nom) + x (1 , (nom+1) :2∗nom) ∗1 i ;b = x (1 ,2∗nom+1:3∗nom) + x (1 ,3∗nom + 1 : n) ∗1 i ;

%try to f i nd a TF us ing the va r i ab l e s , and c a l c u l a t e the f i tt f 1 = t f (b , a , ' Ts ' , ts , ' va r i ab l e ' , ' z^−1') ;[~ , f i t ] = compare ( data , t f 1 ) ;f i t = abs ( f i t −100) ;

catch% i f the v a r i a b l e s can ' t generate a TF then the f i t va lue f o r the se% va r i a b l e s i s s e t to nanf i t = nan ;

endFIT = FIT + f i t ;

145

Page 147: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

endFIT = FIT / co l ;end

%% IN−DIRECT FITNESS FUNCTIONfunc t i on FIT = f i tn e s s_ in_d i r r ( x )%Retr i eve s p e c i f i c v a r i a b l e s from workspacen = eva l i n ( ' base ' , ' nvars ' ) ;

EncounterSpectrum = eva l i n ( ' base ' , ' EncounterSpectrum ' ) ;MotionSpectrum = eva l i n ( ' base ' , ' MotionSpectrum ' ) ;

[~ , c o l ] = s i z e ( EncounterSpectrum ) ;FIT = 0 ;f o r k = 1 : c o l

%Setup the Input output data f o r the d i r e c t methodmotion = MotionSpectrum ( : , k ) ;encounter = EncounterSpectrum ( : , k ) ;t ry

nom = n/4 ;a = x ( 1 , 1 :nom) + x (1 , (nom+1) :2∗nom) ∗1 i ;b = x (1 ,2∗nom+1:3∗nom) + x (1 ,3∗nom + 1 : n) ∗1 i ;out = f i l t e r (b , a , motion ) ;

f i t 1 = sum( ( r e a l ( encounter )−r e a l ( out ) ) .^2) / l ength ( r e a l ( encounter ) ) ;f i t 2 = sum( ( imag ( encounter )−imag ( out ) ) .^2) / l ength ( imag ( encounter ) ) ;f i t = ( f i t 1+f i t 2 ) /2 ;

catch% i f the v a r i a b l e s can ' t generate a TF then the f i t va lue f o r the se% va r i a b l e s i s s e t to nanf i t = nan ;

endFIT = FIT + f i t ;

endFIT = FIT / co l ;end

Code E.9.3: Above is the source code implemented in MATLAB for the GA with several examplesbased TF using only actual logged data for training and validation. The code utilized the functionpresented in appendix E.4.3.

146

Page 148: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.10 Feedforward Neural Network For Training And Validating With

Actual Data

The following sections presents the code implemented for the FFNN solutions utilizing actual data.

E.10.1 Using Resilient Backpropagation

%c l c%c l e a r v a r s −except f o l d%c l o s e a l lwarning ( ' o f f ' , ' a l l ' ) ;rng ( ' s hu f f l e ' , ' tw i s t e r ' )TrainingAmount =1;

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )%f o l d = 1 ;

f i l ename = [ 'ANN_with_RPROP_Based_On_Actual_Data .mat ' ] ;

f o l d = 1 ;

%Check i f the v a r i a b l e s have been save from a prev ious t e s ti f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )%The va r i a b l e s have not been saved to run the t e s t

e l s e%% −−−−−−−−−−−−−−−−−−−−−−−− INITIALIZE −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−load ( ' columnLabels ' ) ;load ( ' Ship_data ' ) ;Ship_data1 = Ship_data ;load ( 'D_2017−04−03') ;Ship_data2 = Ship_data ;load ( 'D_2017−04−04') ;Ship_data3 = Ship_data ;load ( 'Waves_2017_04_03 ' ) ;load ( 'Waves_2017_04_04 ' ) ;load ( 'Waves_2017_04_05 ' ) ;

[ row , c o l ] =s i z e (Waves_2017_04_04) ;Ship_data = [ Ship_data1 ( : , 1 : 7 3 ) ; Ship_data2 ( 1 : row , : ) ] ;

[ row , c o l ] =s i z e ( Ship_data1 ) ;Waves_init = [Waves_2017_04_03 ( 1 : row , : ) ;Waves_2017_04_04 ( : , : ) ] ;

[ samples , ~ ] = s i z e ( Ship_data ) ;t r a i n c a s e s = f l o o r ( samples /101) ;

[ samples , ~ ] = s i z e ( Ship_data3 ) ;v a l c a s e s = f l o o r ( samples /101) ;

f o r k = 1 : t r a i n c a s e sa = 1+(k−1) ∗100 ;Ro l l i ng ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RollRaw ) ;Pitch (1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudder ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RudderPos ) ;Waves (1 , k ) = mean(Waves_init ( ( a : a+100) ,2 ) ) ;Waves (2 , k ) = mean(Waves_init ( ( a : a+100) ,3 ) ) ;Waves (3 , k ) = mod(360 + mean(Waves_init ( ( a : a+100) ,4 ) )−mean( Ship_data ( ( a : a

+100) , columnLabels . Heading ) ) ,360) ;end

f o r k = 1 : va l c a s e sa = 1+(k−1) ∗100 ;Ro l l i n gva l ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RollRaw ) ;P i t chva l ( 1 : 1 01 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudderval ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RudderPos ) ;Wavesval (1 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,2 ) ) ;Wavesval (2 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,3 ) ) ;

147

Page 149: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Wavesval (3 , k ) = mod(360 + mean(Waves_2017_04_05 ( ( a : a+100) ,4 ) )−mean(Ship_data3 ( ( a : a+100) , columnLabels . Heading ) ) ,360) ;

end

% Convert degree s to rad iansWaves ( 3 , : ) = Waves ( 3 , : ) ∗( p i /180) ;Wavesval ( 3 , : ) = Wavesval ( 3 , : ) ∗( p i /180) ;

d i sp ( ' done gather ing data ' )

% s e t t r a i n i n g timehours = . 5 ;minute = hours ∗60 ;

[ Samples , c o l ] = s i z e ( Ro l l i ng ) ;

Ts = . 2 5 ; %Sampling time o f the datag = 9 . 8 2 ; %grav i ty constantw_lim = 2 ;w_step = w_lim/Samples ;w = w_step : w_step : w_lim;%Frequency vec to r

% Prepare inputs and outputs f o r the networkIn = [ Ro l l i ng Ro l l i n gva l ; Rudder Rudderval ; Pitch Pi tchva l ] ;[~ , co l 2 ] = s i z e ( In ) ;Va l idat ionVector = @(k ) [ Ro l l i n gva l ( : , k ) ; Rudderval ( : , k ) ; P i t chva l ( : , k ) ] ;Tr = [Waves Wavesval ] ;

%% −−−−−−−−−−−−−−−−−−−−− BACK PROPAGATION NETWORK −−−−−−−−−−−−−−−−−−−−−−−−−

% se t l a y e r s and neuronsHiddenLayers =3;n = [ ] ;f o r k = HiddenLayers :−1:1

n = [ n 3^(k+1) ] ;end

% setup netnetBP = feed forwardnet (n , ' t ra in rp ' ) ;netBP . div ideFcn = ' d iv ide ind ' ;netBP . divideParam .Q = co l ;netBP . divideParam . t ra in Ind = 1 : c o l ;netBP . trainParam .mu_dec = 0 . 0 1 ;netBP . trainParam .mu_inc = 1 . 1 ;netBP . trainParam . epochs = 5000 ; % epochnetBP . trainParam . goa l = 0 ; % ob j e c t i v e MSEnetBP . trainParam . time = minute ∗60 ;netBP . trainParam . max_fail = 100 ;

% s e t a c t i v a t i o n func t i on snetGA = feed fo rwardnet (n , ' t ra in rp ' ) ;f o r k = 1 : HiddenLayers

netGA . l a y e r s {k } . t rans f e rFcn = ' tans ig ' ;endnetGA . l a y e r s {HiddenLayers+1}. t rans f e rFcn = ' pure l in ' ;

netBP = con f i gu r e (netBP , In , Tr ) ;netBP . performFcn = 'mse ' ;

% t r a i n net based on r e s i l i e n t backpropagat ion[ netBP , t r ] = t r a i n (netBP , In , Tr ) ;

%% −−−−−−−−−−−−−−−−−−−− VALIDATE NETWORK −−−−−−−−−−−−−−−−−−−−−−−−−−−−

% Retr i eve amounts o f v a l i d a t i o n ca s e s[~ , c o l ] = s i z e (Wavesval ) ;

148

Page 150: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

% loop f o r each va l i d a t i o n casef o r k = 1 : c o l

% Retr i eve est imated va lue s f o r cur r ent caseest_BP = netBP( Val idat ionVector ( k ) ) ;est_Hs = est_BP (1 , 1 ) ;est_Tp = est_BP (2 , 1 ) ;est_Beta = est_BP (3 , 1 ) ;

% est imated va lues in ve c t o r sest_Hs_vec (k ) = est_Hs ;est_Tp_vec (k ) = est_Tp ;est_Beta_vec (k ) = est_Beta ∗(180/ p i ) ;

% Sca l e the encounter ang le proper ly . I f the ac tua l ang le i s 0 then% i t must be converted to 2∗ pi s i n c e i t w i l l y i e l d nan in the% f i t n e s s c a l c u l a t i o n otherw i se . The est imated ang le i s always% sca l ed with 2∗ pi to ensure that i t i s c o r r e c t l y compared to the% actua l va lue . For example i f act i s p i and est imated i s 3∗ pi then% the f i t n e s s should y i e l d 100% f i t not 300%.% s i n c e 3∗ pi rad ians == pi rad iansi f ( est_Beta > 2∗ pi )

est_Beta = mod( est_Beta ,2∗ pi ) ;endi f (Wavesval (3 , k ) == 0)

Wavesval (3 , k ) = 2∗ pi ;i f ( est_Beta < pi )

est_Beta = est_Beta + 2∗ pi ;end

e l s e i f ( est_Beta == 0)est_Beta = 2∗ pi ;i f (Wavesval (3 , k ) > pi )

Wavesval (3 , k ) = Wavesval (3 , k ) + 2∗ pi ;end

end

% Calcu la te the f i t n e s s o f est imated va lue sHs_fit ( k ) = 100∗ abs ( est_Hs/Wavesval (1 , k ) ) ;Tp_fit ( k ) = 100∗ abs ( est_Tp/Wavesval (2 , k ) ) ;Beta_f it ( k ) = 100∗ abs ( est_Beta/Wavesval (3 , k ) ) ;

Hscomp(k , 1 : 2 ) = [ Wavesval (1 , k ) est_Hs ] ;variable_BP_fit = ( ( Hs_fit + Tp_fit + Beta_f it ) /3) ;

% Ca lcu la te the d i f f e r e n c e or percentage e r r o rHs_dif f = abs (100−Hs_fit ( k ) ) ;Tp_diff = abs (100−Tp_fit ( k ) ) ;Beta_di f f = abs (100−Beta_fit ( k ) ) ;

% s t o r e e r r o rPerc ( : , k ) = [ Hs_dif f ; Tp_diff ; Beta_di f f ] ;

end

% ca l c u l a r e average and median e r r o r sMax_diff = max( Perc ( : ) ) ;Min_diff = min ( Perc ( : ) ) ;Average_dif f = mean( Perc ( : ) ) ;Median_diff = median ( Perc ( : ) ) ;s = s i z e ( Perc ) ;Better_than_avg = 100∗(sum( Perc ( : )<=Average_dif f ) ) /( s (1 ) ∗ s (2 ) ) ;

Average_Hs_diff = mean( Perc ( 1 , : ) ) ;Median_Hs_diff = median ( Perc ( 1 , : ) ) ;Min_Hs_diff = min ( Perc ( 1 , : ) ) ;Max_Hs_diff = max( Perc ( 1 , : ) ) ;

Average_Tp_diff = mean( Perc ( 2 , : ) ) ;Median_Tp_diff = median ( Perc ( 2 , : ) ) ;

149

Page 151: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Min_Tp_diff = min ( Perc ( 2 , : ) ) ;Max_Tp_diff = max( Perc ( 2 , : ) ) ;

Average_Beta_diff = mean( Perc ( 3 , : ) ) ;Median_Beta_diff = median ( Perc ( 3 , : ) ) ;Min_Beta_diff = min ( Perc ( 3 , : ) ) ;Max_Beta_diff = max( Perc ( 3 , : ) ) ;

Result = [ ' \ n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nFOLD = 'num2str ( f o l d ) '\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nBP\nAverage Hs d i f f e r e n c e = ' num2str ( Average_Hs_diff ) '\ nMedian Hs d i f f e r e n c e= ' num2str (Median_Hs_diff ) '%%\nMin Hs d i f f e r e n c e = ' num2str (Min_Hs_diff) '%%\nMax Hs d i f f e r e n c e = ' num2str (Max_Hs_diff ) '%%\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nAverage Tp d i f f e r e n c e =' num2str ( Average_Tp_diff ) '\ nMedian Tp d i f f e r e n c e = ' num2str (

Median_Tp_diff ) '%%\nMin Tp d i f f e r e n c e = ' num2str (Min_Tp_diff ) '%%\nMax Tpd i f f e r e n c e = ' num2str (Max_Tp_diff ) '%%\n

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nAverage Beta d i f f e r e n c e= ' num2str ( Average_Beta_diff ) '\ nMedian Beta d i f f e r e n c e = ' num2str (Median_Beta_diff ) '%%\nMin Beta d i f f e r e n c e = ' num2str (Min_Beta_diff ) '%%\nMax Beta d i f f e r e n c e = ' num2str (Max_Beta_diff ) '%%\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− ' '\ nAverage va r i ab l ed i f f e r e n c e = ' num2str ( Average_dif f ( 1 , 1 ) ) '\ nMedian va r i ab l e d i f f e r e n c e = 'num2str ( Median_diff ( 1 , 1 ) ) '%%\nMaximum va r i ab l e d i f f e r e n c e = ' num2str (

Max_diff ) '%%\nMinimum va r i ab l e d i f f e r e n c e = ' num2str ( Min_diff ) '%%\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nPerforms Better ThanAverage : ' num2str ( Better_than_avg ) '%% of the Time\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\n ' ] ;

save ( f i l ename )end

f p r i n t f ( Result )

Hscomp ( : , 3 ) = Perc ( 1 , : ) ' ;

f i g u r e ( ' name ' , [ 'ANN FOLD = ' num2str ( f o l d ) ] )subplot ( 3 , 2 , 1 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( [ 'Mean d i f f = ' num2str ( Average_Hs_diff ) ] )p l o t ( 1 : co l ,100∗ ones (1 , c o l ) , ' k ' )p l o t ( 1 : co l ,(100−sum( Perc ( 1 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )p l o t ( 1 : co l , Hs_fit , ' r ' )p l o t ( 1 : co l ,(100+sum( Perc ( 1 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )l egend ( ' Target ' , ' Average Bound ' , ' Hs ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( ' F i tne s s (%) ' )

subplot ( 3 , 2 , 3 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( [ 'Mean d i f f = ' num2str ( Average_Tp_diff ) ] )p l o t ( 1 : co l ,100∗ ones (1 , c o l ) , ' k ' )p l o t ( 1 : co l ,(100−sum( Perc ( 2 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )p l o t ( 1 : co l , Tp_fit , ' r ' )p l o t ( 1 : co l ,(100+sum( Perc ( 2 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )l egend ( ' Target ' , ' Average Bound ' , 'Tp ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( ' F i tne s s (%) ' )

subplot ( 3 , 2 , 5 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( [ 'Mean d i f f = ' num2str ( Average_Beta_diff ) ] )p l o t ( 1 : co l ,100∗ ones (1 , c o l ) , ' k ' )

150

Page 152: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

p lo t ( 1 : co l ,(100−sum( Perc ( 3 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )p l o t ( 1 : co l , Beta_fit , ' r ' )p l o t ( 1 : co l ,(100+sum( Perc ( 3 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )l egend ( ' Target ' , ' Average Bound ' , ' Beta ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( ' F i tne s s (%) ' )

subplot ( 3 , 2 , 2 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( [ 'MSE = ' num2str (mean ( ( est_Hs_vec−Wavesval ( 1 , : ) ) .^2) ) ] )p l o t ( 1 : co l , Wavesval ( 1 , : ) , ' k ' )p l o t ( 1 : co l , est_Hs_vec , ' r ' )l egend ( ' Target ' , ' Hs ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( 'Hs (m) ' )

subplot ( 3 , 2 , 4 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( [ 'MSE = ' num2str (mean ( ( est_Tp_vec−Wavesval ( 2 , : ) ) .^2) ) ] )p l o t ( 1 : co l , Wavesval ( 2 , : ) , ' k ' )p l o t ( 1 : co l , est_Tp_vec , ' r ' )l egend ( ' Target ' , 'Tp ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( 'Tp ( sec ) ' )

subplot ( 3 , 2 , 6 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( [ 'MSE = ' num2str (mean ( ( est_Beta_vec ∗( p i /180)−Wavesval ( 3 , : ) ) .^2) ) ] )p l o t ( 1 : co l , Wavesval ( 3 , : ) ∗(180/ p i ) , ' k ' )p l o t ( 1 : co l , est_Beta_vec , ' r ' )l egend ( ' Target ' , ' Beta ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( ' Beta ( deg ) ' )

Code E.10.1: The above source code was implemented in MATLAB to estimate the waveparameters using a FFNN trained with RPROP.

151

Page 153: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.10.2 Using Genetic Algorithm

%c l c%c l e a r v a r s −except f o l d%c l o s e a l lwarning ( ' o f f ' , ' a l l ' ) ;rng ( ' s hu f f l e ' , ' tw i s t e r ' )

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )%f o l d = 1 ;f i l ename = [ 'ANN_with_GA_Based_On_Actual_Data .mat ' ] ;

f o l d = 1 ;

%Check i f the v a r i a b l e s have been save from a prev ious t e s ti f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )%The va r i a b l e s have not been saved to run the t e s t

e l s e%% −−−−−−−−−−−−−−−−−−−−−−−− INITIALIZE −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−load ( ' columnLabels ' ) ;load ( ' Ship_data ' ) ;Ship_data1 = Ship_data ;load ( 'D_2017−04−03') ;Ship_data2 = Ship_data ;load ( 'D_2017−04−04') ;Ship_data3 = Ship_data ;load ( 'Waves_2017_04_03 ' ) ;load ( 'Waves_2017_04_04 ' ) ;load ( 'Waves_2017_04_05 ' ) ;

[ row , c o l ] =s i z e (Waves_2017_04_04) ;Ship_data = [ Ship_data1 ( : , 1 : 7 3 ) ; Ship_data2 ( 1 : row , : ) ] ;

[ row , c o l ] =s i z e ( Ship_data1 ) ;Waves_init = [Waves_2017_04_03 ( 1 : row , : ) ;Waves_2017_04_04 ( : , : ) ] ;

%TrainingAmount = 1/2 ;

[ samples , ~ ] = s i z e ( Ship_data ) ;t r a i n c a s e s = f l o o r ( samples /101) ;

[ samples , ~ ] = s i z e ( Ship_data3 ) ;v a l c a s e s = f l o o r ( samples /101) ;

f o r k = 1 : t r a i n c a s e sa = 1+(k−1) ∗100 ;Ro l l i ng ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RollRaw ) ;Pitch (1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudder ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RudderPos ) ;Waves (1 , k ) = mean(Waves_init ( ( a : a+100) ,2 ) ) ;Waves (2 , k ) = mean(Waves_init ( ( a : a+100) ,3 ) ) ;Waves (3 , k ) = mod(360 + mean(Waves_init ( ( a : a+100) ,4 ) )−mean( Ship_data ( ( a : a

+100) , columnLabels . Heading ) ) ,360) ;end

f o r k = 1 : va l c a s e sa = 1+(k−1) ∗100 ;Ro l l i n gva l ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RollRaw ) ;P i t chva l ( 1 : 1 01 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudderval ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RudderPos ) ;Wavesval (1 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,2 ) ) ;Wavesval (2 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,3 ) ) ;Wavesval (3 , k ) = mod(360 + mean(Waves_2017_04_05 ( ( a : a+100) ,4 ) )−mean(

Ship_data3 ( ( a : a+100) , columnLabels . Heading ) ) ,360) ;end

% Convert degree s to rad iansWaves ( 3 , : ) = Waves ( 3 , : ) ∗( p i /180) ;Wavesval ( 3 , : ) = Wavesval ( 3 , : ) ∗( p i /180) ;

152

Page 154: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

di sp ( ' done gather ing data ' )

% s e t t r a i n i n g timehours = . 5 ;minute = hours ∗60 ;

[ Samples , Cases ] = s i z e ( Ro l l i ng ) ;

Ts = . 2 5 ; %Sampling time o f the data i s a l s o constantg = 9 . 8 2 ; %grav i ty constantw_lim = 2 ;w_step = w_lim/Samples ;w = w_step : w_step : w_lim ; %Frequency vec to r

% Prepare inputs and outputs f o r the networkIn = [ Ro l l i ng ; Rudder ; Pitch ] ;[~ , co l 2 ] = s i z e ( In ) ;Va l idat ionVector = @(k ) [ Ro l l i n gva l ( : , k ) ; Rudderval ( : , k ) ; P i t chva l ( : , k ) ] ;Tr = Waves ;

%% −−−−−−−−−−−−−−−−−−−−− GENETIC ALGORITTHM NETWORK −−−−−−−−−−−−−−−−−−−−−−−−−

% se t l a y e r s and neuronsHiddenLayers =3;n = [ ] ;f o r k = HiddenLayers :−1:1

n = [ n 3^(k+1) ] ;end

% se t a c t i v a t i o n func t i on snetGA = feed fo rwardnet (n , ' t ra in rp ' ) ;f o r k = 1 : HiddenLayers

netGA . l a y e r s {k } . t rans f e rFcn = ' tans ig ' ;endnetGA . l a y e r s {HiddenLayers+1}. t rans f e rFcn = ' pure l in ' ;

% prepare netnetGA = con f i gu r e (netGA , In , Tr ) ;[ row , ~ ] = s i z e ( getwb (netGA) ) ;nvars = row ;

%Setup the GAga_opts = gaopt imset (@ga) ;ga_opts . TolFun = 1e−10;ga_opts . Display = ' i t e r ' ;ga_opts . Popu lat ionS ize = 100 ;ga_opts . TimeLimit = minute ∗60 ;ga_opts . Generat ions = 500 ;ga_opts . PopInitRange = [ −1 ; 1 ] ;

%s t a r t t r a i n i n g the net[ x , ~ ] = ga ( @f i tnes s , nvars , ga_opts ) ;

%s e t f i n a l c on f i g u r a t i on based on GA t r a i n i n gnetGA = setwb (netGA , x ' ) ;

%% −−−−−−−−−−−−−−−−−−−− VALIDATE NETWORK −−−−−−−−−−−−−−−−−−−−−−−−−−−−

% Retr i eve amounts o f v a l i d a t i o n ca s e s[~ , c o l ] = s i z e (Wavesval ) ;

% loop f o r each va l i d a t i o n casef o r k = 1 : c o l

% Retr i eve est imated va lue s f o r cur r ent caseest_GA = netGA( Val idat ionVector ( k ) ) ;est_Hs = est_GA(1 ,1 ) ;

153

Page 155: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

est_Tp = est_GA(2 , 1 ) ;est_Beta = est_GA(3 ,1 ) ;

% est imated va lues in ve c t o r sest_Hs_vec (k ) = est_Hs ;est_Tp_vec (k ) = est_Tp ;est_Beta_vec (k ) = est_Beta ∗(180/ p i ) ;

% Sca l e the encounter ang le proper ly . I f the ac tua l ang le i s 0 then% i t must be converted to 2∗ pi s i n c e i t w i l l y i e l d nan in the% f i t n e s s c a l c u l a t i o n otherw i se . The est imated ang le i s always% sca l ed with 2∗ pi to ensure that i t i s c o r r e c t l y compared to the% actua l va lue . For example i f act i s p i and est imated i s 3∗ pi then% the f i t n e s s should y i e l d 100% f i t not 300%.% s i n c e 3∗ pi rad ians == pi rad iansi f ( est_Beta > 2∗ pi )

est_Beta = mod( est_Beta ,2∗ pi ) ;endi f (Wavesval (3 , k ) == 0)

Wavesval (3 , k ) = 2∗ pi ;i f ( est_Beta < pi )

est_Beta = est_Beta + 2∗ pi ;end

e l s e i f ( est_Beta == 0)est_Beta = 2∗ pi ;i f (Wavesval (3 , k ) > pi )

Wavesval (3 , k ) = Wavesval (3 , k ) + 2∗ pi ;end

end

% Calcu la te the f i t n e s s o f est imated va lue sHs_fit ( k ) = 100∗ abs ( est_Hs/Wavesval (1 , k ) ) ;Tp_fit ( k ) = 100∗ abs ( est_Tp/Wavesval (2 , k ) ) ;Beta_f it ( k ) = 100∗ abs ( est_Beta/Wavesval (3 , k ) ) ;

Hscomp(k , 1 : 2 ) = [ Wavesval (1 , k ) est_Hs ] ;variable_BP_fit = ( ( Hs_fit + Tp_fit + Beta_f it ) /3) ;

% Ca lcu la te the d i f f e r e n c e or percentage e r r o rHs_dif f = abs (100−Hs_fit ( k ) ) ;Tp_diff = abs (100−Tp_fit ( k ) ) ;Beta_di f f = abs (100−Beta_fit ( k ) ) ;

% s t o r e e r r o rPerc ( : , k ) = [ Hs_dif f ; Tp_diff ; Beta_di f f ] ;

end

% ca l c u l a r e average and median e r r o r sMax_diff = max( Perc ( : ) ) ;Min_diff = min ( Perc ( : ) ) ;Average_dif f = mean( Perc ( : ) ) ;Median_diff = median ( Perc ( : ) ) ;s = s i z e ( Perc ) ;Better_than_avg = 100∗(sum( Perc ( : )<=Average_dif f ) ) /( s (1 ) ∗ s (2 ) ) ;

Average_Hs_diff = mean( Perc ( 1 , : ) ) ;Median_Hs_diff = median ( Perc ( 1 , : ) ) ;Min_Hs_diff = min ( Perc ( 1 , : ) ) ;Max_Hs_diff = max( Perc ( 1 , : ) ) ;

Average_Tp_diff = mean( Perc ( 2 , : ) ) ;Median_Tp_diff = median ( Perc ( 2 , : ) ) ;Min_Tp_diff = min ( Perc ( 2 , : ) ) ;Max_Tp_diff = max( Perc ( 2 , : ) ) ;

Average_Beta_diff = mean( Perc ( 3 , : ) ) ;Median_Beta_diff = median ( Perc ( 3 , : ) ) ;Min_Beta_diff = min ( Perc ( 3 , : ) ) ;Max_Beta_diff = max( Perc ( 3 , : ) ) ;

154

Page 156: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Result = [ ' \ n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nFOLD = 'num2str ( f o l d ) '\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nBP\nAverage Hs d i f f e r e n c e = ' num2str ( Average_Hs_diff ) '\ nMedian Hs d i f f e r e n c e= ' num2str (Median_Hs_diff ) '%%\nMin Hs d i f f e r e n c e = ' num2str (Min_Hs_diff) '%%\nMax Hs d i f f e r e n c e = ' num2str (Max_Hs_diff ) '%%\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nAverage Tp d i f f e r e n c e =' num2str ( Average_Tp_diff ) '\ nMedian Tp d i f f e r e n c e = ' num2str (

Median_Tp_diff ) '%%\nMin Tp d i f f e r e n c e = ' num2str (Min_Tp_diff ) '%%\nMax Tpd i f f e r e n c e = ' num2str (Max_Tp_diff ) '%%\n

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nAverage Beta d i f f e r e n c e= ' num2str ( Average_Beta_diff ) '\ nMedian Beta d i f f e r e n c e = ' num2str (Median_Beta_diff ) '%%\nMin Beta d i f f e r e n c e = ' num2str (Min_Beta_diff ) '%%\nMax Beta d i f f e r e n c e = ' num2str (Max_Beta_diff ) '%%\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− ' '\ nAverage va r i ab l ed i f f e r e n c e = ' num2str ( Average_dif f ( 1 , 1 ) ) '\ nMedian va r i ab l e d i f f e r e n c e = 'num2str ( Median_diff ( 1 , 1 ) ) '%%\nMaximum va r i ab l e d i f f e r e n c e = ' num2str (

Max_diff ) '%%\nMinimum va r i ab l e d i f f e r e n c e = ' num2str ( Min_diff ) '%%\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\nPerforms Better ThanAverage : ' num2str ( Better_than_avg ) '%% of the Time\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\n ' ] ;

save ( f i l ename )

end

f p r i n t f ( Result )

Hscomp ( : , 3 ) = Perc ( 1 , : ) ' ;

f i g u r e ( ' name ' , [ ' Fold = ' num2str ( f o l d ) ] )subplot ( 3 , 2 , 1 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( num2str (mean( Hs_fit ( : ) ) ) )p l o t ( 1 : co l ,100∗ ones (1 , c o l ) , ' k ' )p l o t ( 1 : co l ,(100−sum( Perc ( 1 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )p l o t ( 1 : co l , Hs_fit , ' r ' )p l o t ( 1 : co l ,(100+sum( Perc ( 1 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )l egend ( ' Target ' , ' Average Bound ' , ' Hs ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( ' F i tne s s (%) ' )

subplot ( 3 , 2 , 3 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( num2str (mean( Tp_fit ( : ) ) ) )p l o t ( 1 : co l ,100∗ ones (1 , c o l ) , ' k ' )p l o t ( 1 : co l ,(100−sum( Perc ( 2 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )p l o t ( 1 : co l , Tp_fit , ' r ' )p l o t ( 1 : co l ,(100+sum( Perc ( 2 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )l egend ( ' Target ' , ' Average Bound ' , 'Tp ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( ' F i tne s s (%) ' )

subplot ( 3 , 2 , 5 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( num2str (mean( Beta_f it ( : ) ) ) )p l o t ( 1 : co l ,100∗ ones (1 , c o l ) , ' k ' )p l o t ( 1 : co l ,(100−sum( Perc ( 3 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )p l o t ( 1 : co l , Beta_fit , ' r ' )p l o t ( 1 : co l ,(100+sum( Perc ( 3 , : ) ) / c o l ) ∗ ones (1 , c o l ) ,'−−k ' )l egend ( ' Target ' , ' Average Bound ' , ' Beta ' )x l ab e l ( ' Va l idat i on case ' )

155

Page 157: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

y l ab e l ( ' F i tne s s (%) ' )

%%

subplot ( 3 , 2 , 2 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( num2str ( Average_Hs_diff ) )p l o t ( 1 : co l , Wavesval ( 1 , : ) , ' k ' )p l o t ( 1 : co l , est_Hs_vec , ' r ' )l egend ( ' Target ' , ' Hs ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( 'Hs (m) ' )

subplot ( 3 , 2 , 4 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( num2str ( Average_Tp_diff ) )p l o t ( 1 : co l , Wavesval ( 2 , : ) , ' k ' )p l o t ( 1 : co l , est_Tp_vec , ' r ' )l egend ( ' Target ' , 'Tp ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( 'Tp ( sec ) ' )

subplot ( 3 , 2 , 6 , ' r ep lace ' ) ;drawnowhold ong r id ont i t l e ( num2str ( Average_Beta_diff ) )p l o t ( 1 : co l , Wavesval ( 3 , : ) ∗(180/ p i ) , ' k ' )p l o t ( 1 : co l , est_Beta_vec , ' r ' )l egend ( ' Target ' , ' Beta ' )x l ab e l ( ' Va l idat i on case ' )y l ab e l ( ' Beta ( deg ) ' )

%% −−−−−−−−−−−−−−−−−−−− FITNESS FUNCTION FOR GA −−−−−−−−−−−−−−−−−−−−−−−−−−−f unc t i on mse_calc = f i t n e s s ( x )netGA = eva l i n ( ' base ' , ' netGA ' ) ;inputs = eva l i n ( ' base ' , ' In ' ) ;t a r g e t s = eva l i n ( ' base ' , ' Tr ' ) ;% 'x ' conta in s the weights and b i a s e s vec to r% in row vecto r form as passed to i t by the% genetGAic a lgor i thm . This must be transposed% when being s e t as the weights and b i a s e s% vecto r f o r the netGAwork .% To s e t the weights and b i a s e s vec to r to the% one given as inputnetGA = setwb (netGA , x ' ) ;% To eva luate the ouputs based on the g iven% weights and b i a s e s vec to ry = netGA( inputs ) ;% Ca l cu l a t ing the mean squared e r r o r

[~ , c o l ] = s i z e ( t a r g e t s ) ;

f o r k = 1 : c o li f ( t a r g e t s (3 , k ) == 0)

t a r g e t s (3 , k ) = 2∗ pi ;y (3 , k ) = y (3 , k )+2∗pi ;

endend

One = ones ( s i z e ( t a r g e t s ) ) ;e r r = abs (One − ( y . / t a r g e t s ) ) ;mse_calc = 100∗mean( e r r ( : ) ) ;

156

Page 158: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

end

Code E.10.2: The above source code was implemented in MATLAB to estimate the waveparameters using a FFNN trained with GA.

E.11 Case Based Reasoning For Training And Validating With Actual

Data

The following sections presents the code implemented for the CBR solutions utilizing actual data.

E.11.1 Using Euclidian Distance

%c l c%c l e a r v a r s −except f o l d Ro l l i ng Rudder Pitch Speed Yaw Surge Sway Ro l l i n gva l

Rudderval P i t chva l Speedval Yawval Surgeva l Swayvalc l o s e a l lwarning ( ' o f f ' , ' a l l ' ) ;rng ( ' s hu f f l e ' , ' tw i s t e r ' )format long

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )%f o l d = 1 ;

f i l ename = [ ' CBR_with_Euclidean_Based_On_Actual_Data .mat ' ] ;

f o l d = 5 ;

%Check i f the v a r i a b l e s have been save from a prev ious t e s ti f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )%The va r i a b l e s have not been saved to run the t e s t

e l s e%% −−−−−−−−−−−−−−−−−−−−−−−− INITIALIZE −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−load ( ' columnLabels ' ) ;load ( ' Ship_data ' ) ;Ship_data1 = Ship_data ;load ( 'D_2017−04−03') ;Ship_data2 = Ship_data ;load ( 'D_2017−04−04') ;Ship_data3 = Ship_data ;load ( 'Waves_2017_04_03 ' ) ;load ( 'Waves_2017_04_04 ' ) ;load ( 'Waves_2017_04_05 ' ) ;

[ row , c o l ] =s i z e (Waves_2017_04_04) ;Ship_data = [ Ship_data1 ( : , 1 : 7 3 ) ; Ship_data2 ( 1 : row , : ) ] ;

[ row , c o l ] =s i z e ( Ship_data1 ) ;Waves_init = [Waves_2017_04_03 ( 1 : row , : ) ;Waves_2017_04_04 ( : , : ) ] ;

%TrainingAmount = 1/2 ;

[ samples , ~ ] = s i z e ( Ship_data ) ;t r a i n c a s e s = f l o o r ( samples /101) ;

[ samples , ~ ] = s i z e ( Ship_data3 ) ;v a l c a s e s = f l o o r ( samples /101) ;

f o r k = 1 : t r a i n c a s e sa = 1+(k−1) ∗100 ;Ro l l i ng ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RollRaw ) ;Pitch (1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudder ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RudderPos ) ;Waves (1 , k ) = mean(Waves_init ( ( a : a+100) ,2 ) ) ;Waves (2 , k ) = mean(Waves_init ( ( a : a+100) ,3 ) ) ;Waves (3 , k ) = mod(360 + mean(Waves_init ( ( a : a+100) ,4 ) )−mean( Ship_data ( ( a : a

+100) , columnLabels . Heading ) ) ,360) ;

157

Page 159: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

end

f o r k = 1 : va l c a s e sa = 1+(k−1) ∗100 ;Ro l l i n gva l ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RollRaw ) ;P i t chva l ( 1 : 1 01 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudderval ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RudderPos ) ;Wavesval (1 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,2 ) ) ;Wavesval (2 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,3 ) ) ;Wavesval (3 , k ) = mod(360 + mean(Waves_2017_04_05 ( ( a : a+100) ,4 ) )−mean(

Ship_data3 ( ( a : a+100) , columnLabels . Heading ) ) ,360) ;end

% Convert deg r e e s to rad iansWaves ( 3 , : ) = Waves ( 3 , : ) ∗( p i /180) ;Wavesval ( 3 , : ) = Wavesval ( 3 , : ) ∗( p i /180) ;

% r e t r i e v e the amount o f ca s e s in the 9 t r a i n i n g f o l d s and c a l c u l a t e% the amount o f ca s e s in each f o l d[~ , c o l ] = s i z e ( Ro l l i ng ) ;f o l d s i z e = co l /9 ;

%%% sepe ra t e the t r a i n i n g data so that the data used f o r e s t imat ing the% weights i s not found in the database . In conc lu s i on s e l e c t i n g one o f% the database f o l d s as t r a i n i n g f o l d f o r the GA

Rolling_GA_database = [ Ro l l i ng ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Ro l l i ng ( : , f o l d ∗f o l d s i z e : end ) ] ;

Rolling_GA_train = Ro l l i ng ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;

Rudder_GA_database = [ Rudder ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Rudder ( : , f o l d ∗ f o l d s i z e :end ) ] ;

Rudder_GA_train = Rudder ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;

Pitch_GA_database = [ Pitch ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Pitch ( : , f o l d ∗ f o l d s i z e : end) ] ;

Pitch_GA_train = Pitch ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;

Waves_GA_database = [Waves ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Waves ( : , f o l d ∗ f o l d s i z e : end) ] ;

Waves_GA_train = Waves ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;

d i sp ( ' done gather ing data ' )

% Se t t i ng t r a i n i n g time f o r GAminute = 30 ;

%% setup GAga_opts = gaopt imset (@ga) ;ga_opts . Display = ' i t e r ' ;ga_opts . Popu lat ionS ize = 10 ;ga_opts . TimeLimit = minute ∗60 ;ga_opts . Generat ions = i n f ;ga_opts . PopInitRange = [ −1 ; 1 ] ;ga_opts . TolFun = 1e−100;ga_opts . TolCon = 1e−100;ga_opts . Sta l lGenLimit = i n f ;

% s e l e c t i n g the amount o f weights to es t imate . This CBR u t i l i z e 3% weights f o r each wave parameter . E . g . 3−nea r e s t ne ighbor method i s% implementednvars = 3 ;nvars = nvars ∗3 ;[ samples , c a s e s ] = s i z e (Waves_GA_train) ;

d i sp ( ' s ea r ch ing f o r nea r e s t neighbor ' )%% Find the nea r e s t waves f o r GA t r a i n i n gf o r Case = 1 : ca s e s

Case

158

Page 160: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

[ temp1 , temp2 ] = Euc l id ian_dis tance (Case , nvars , . . .Rolling_GA_database , Rudder_GA_database , . . .Pitch_GA_database , Rolling_GA_train , . . .Rudder_GA_train , Pitch_GA_train , . . .Waves_GA_database ) ;

nearest_waves ( : , Case ) = temp1 ' ;rmse ( : , Case ) = temp2 ' ;

end

%% Ut i l i z e GA f o r s e l e c t i o n o f weights[ x , ~ ] = ga ( @f i tnes s , nvars , ga_opts ) ;

%% Find the nea r e s t waves f o r the Va l idat i on f o l d[~ , c a s e s ] = s i z e (Wavesval ) ;f o r Case = 1 : ca s e s

[ temp1 , temp2 ] = Euc l id ian_dis tance (Case , nvars , . . .Ro l l ing , Rudder , . . .Pitch , Ro l l i ngva l , . . .Rudderval , Pitchval , . . .Waves) ;

nearest_waves ( : , Case ) = temp1 ' ;rmse ( : , Case ) = temp2 ' ;

end

%% Estimate the waves based on va l i d a t i o n f o l dK = nvars /3 ;f o r Case = 1 : ca s e s

est_Hs (Case ) = 0 ;est_Tp (Case ) = 0 ;est_Beta (Case ) = 0 ;f o r k = 1 :K

est_Hs (Case ) = est_Hs (Case ) + x(k ) ∗Waves (1 , nearest_waves (k , Case ) ) ;est_Tp (Case ) = est_Tp (Case ) + x(k+K) ∗Waves (2 , nearest_waves (k , Case ) ) ;est_Beta (Case ) = est_Beta (Case ) + x(k+(2∗K) ) ∗Waves (3 , nearest_waves (k ,

Case ) ) ;endi f (Wavesval (3 , Case )== 0)

Wavesval (3 , Case ) = 2∗ pi ;est_Beta (Case ) = est_Beta (Case ) + 2∗ pi ;

endend

save ( f i l ename )end

%% Plot r e s u l t sf i g u r e ( ' name ' , [ 'CBR FOLD = ' num2str ( f o l d ) ] )subplot ( 3 , 2 , 2 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( 'Hs (m) ' )xlim ( [ 0 ca s e s +1])e r r = ( est_Hs−Wavesval ( 1 , : ) ) . ^ 2 ;mse = mean( e r r ) ;s t r i n g = [ 'MSE = ' num2str (mse ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Wavesval ( 1 , : ) , ' k ' , 1 : cases , est_Hs ,'−−r ' )

subplot ( 3 , 2 , 1 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' f i t n e s s (%) ' )xlim ( [ 0 ca s e s +1])Perc = 100∗( est_Hs . /Wavesval ( 1 , : ) ) ;

159

Page 161: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Optimal_Perc = 100∗ ones (1 , c a s e s ) ;d i f f = 100∗ ones ( s i z e ( Perc ) )−Perc ;mean_Hs_diff = mean( abs ( d i f f ) ) ;s t r i n g = [ 'Mean d i f f = ' num2str (mean_Hs_diff ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Optimal_Perc , ' k ' , 1 : cases , Perc ,'−−r ' )

subplot ( 3 , 2 , 4 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( 'Tp ( sec ) ' )xlim ( [ 0 ca s e s +1])e r r = ( est_Tp−Wavesval ( 2 , : ) ) . ^ 2 ;mse = mean( e r r ) ;s t r i n g = [ 'MSE = ' num2str (mse ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Wavesval ( 2 , : ) , ' k ' , 1 : cases , est_Tp,'−−r ' )

subplot ( 3 , 2 , 3 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' f i t n e s s (%) ' )xlim ( [ 0 ca s e s +1])Perc = 100∗( est_Tp ./Wavesval ( 2 , : ) ) ;Optimal_Perc = 100∗ ones (1 , c a s e s ) ;d i f f = 100∗ ones ( s i z e ( Perc ) )−Perc ;mean_Tp_diff = mean( abs ( d i f f ) ) ;s t r i n g = [ 'Mean d i f f = ' num2str (mean_Tp_diff ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Optimal_Perc , ' k ' , 1 : cases , Perc ,'−−r ' )

subplot ( 3 , 2 , 6 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' Beta ( deg ) ' )xlim ( [ 0 ca s e s +1])e r r = ( est_Beta−Wavesval ( 3 , : ) ) . ^ 2 ;mse = mean( e r r ) ;s t r i n g = [ 'MSE = ' num2str (mse ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Wavesval ( 3 , : ) ∗(180/ p i ) , ' k ' , 1 : cases , est_Beta ∗(180/ p i ) ,'−−r ' )

subplot ( 3 , 2 , 5 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' f i t n e s s (%) ' )xlim ( [ 0 ca s e s +1])Perc = 100∗( est_Beta . /Wavesval ( 3 , : ) ) ;Optimal_Perc = 100∗ ones (1 , c a s e s ) ;d i f f = 100∗ ones ( s i z e ( Perc ) )−Perc ;mean_Beta_diff = mean( abs ( d i f f ) ) ;s t r i n g = [ 'Mean d i f f = ' num2str (mean_Beta_diff ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Optimal_Perc , ' k ' , 1 : cases , Perc ,'−−r ' )

% Cost func t i on f o r GAfunc t i on mse_calc = f i t n e s s ( x )Waves = eva l i n ( ' base ' , 'Waves_GA_database ' ) ;Wavesval = eva l i n ( ' base ' , 'Waves_GA_train ' ) ;K = eva l i n ( ' base ' , ' nvars ' ) ;nearest_waves = eva l i n ( ' base ' , ' nearest_waves ' ) ;

160

Page 162: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

[~ , c a s e s ] = s i z e (Wavesval ) ;

K = K /3 ;

mse_calc = 0 ;f o r Case = 1 : ca s e s

est_Hs = 0 ;est_Tp = 0 ;est_Beta = 0 ;f o r k = 1 :K

est_Hs = est_Hs + x(k ) ∗Waves (1 , nearest_waves (k , Case ) ) ;est_Tp = est_Tp + x(k+K) ∗Waves (2 , nearest_waves (k , Case ) ) ;est_Beta = est_Beta + x(k+(2∗K) ) ∗Waves (3 , nearest_waves (k , Case ) ) ;

endmse_calc = mse_calc + ( ( est_Hs−Wavesval (1 , Case ) ) ^2)+ ( ( est_Tp−Wavesval (2 , Case ) )

^2)+ ( ( est_Beta−Wavesval (3 , Case ) ) ^2) ;%mse_calc = mse_calc + 100∗ abs (1−( e s t imat i on /Wavesval (1 , Case ) ) ) ;

endmse_calc = mse_calc /(3∗ ca s e s ) ;end

Code E.11.1: The above source code was implemented in MATLAB to estimate the waveparameters using a CBR and Euclidian distance. The code above implements the functionpresented in appendix E.6.2.

161

Page 163: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.11.2 Using Manhattan Distance

%c l c%c l e a r v a r s −except f o l d Ro l l i ng Rudder Pitch Speed Yaw Surge Sway Ro l l i n gva l

Rudderval P i t chva l Speedval Yawval Surgeva l Swayvalc l o s e a l lwarning ( ' o f f ' , ' a l l ' ) ;rng ( ' s hu f f l e ' , ' tw i s t e r ' )format long

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )%f o l d = 1 ;

f i l ename = [ ' CBR_with_Manhattan_Based_On_Actual_Data .mat ' ] ;

f o l d = 5 ;

%Check i f the v a r i a b l e s have been save from a prev ious t e s ti f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )%The va r i a b l e s have not been saved to run the t e s t

e l s e%% −−−−−−−−−−−−−−−−−−−−−−−− INITIALIZE −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−load ( ' columnLabels ' ) ;load ( ' Ship_data ' ) ;Ship_data1 = Ship_data ;load ( 'D_2017−04−03') ;Ship_data2 = Ship_data ;load ( 'D_2017−04−04') ;Ship_data3 = Ship_data ;load ( 'Waves_2017_04_03 ' ) ;load ( 'Waves_2017_04_04 ' ) ;load ( 'Waves_2017_04_05 ' ) ;

[ row , c o l ] =s i z e (Waves_2017_04_04) ;Ship_data = [ Ship_data1 ( : , 1 : 7 3 ) ; Ship_data2 ( 1 : row , : ) ] ;

[ row , c o l ] =s i z e ( Ship_data1 ) ;Waves_init = [Waves_2017_04_03 ( 1 : row , : ) ;Waves_2017_04_04 ( : , : ) ] ;

%TrainingAmount = 1/2 ;

[ samples , ~ ] = s i z e ( Ship_data ) ;t r a i n c a s e s = f l o o r ( samples /101) ;

[ samples , ~ ] = s i z e ( Ship_data3 ) ;v a l c a s e s = f l o o r ( samples /101) ;

f o r k = 1 : t r a i n c a s e sa = 1+(k−1) ∗100 ;Ro l l i ng ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RollRaw ) ;Pitch (1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudder ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RudderPos ) ;Waves (1 , k ) = mean(Waves_init ( ( a : a+100) ,2 ) ) ;Waves (2 , k ) = mean(Waves_init ( ( a : a+100) ,3 ) ) ;Waves (3 , k ) = mod(360 + mean(Waves_init ( ( a : a+100) ,4 ) )−mean( Ship_data ( ( a : a

+100) , columnLabels . Heading ) ) ,360) ;end

f o r k = 1 : va l c a s e sa = 1+(k−1) ∗100 ;Ro l l i n gva l ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RollRaw ) ;P i t chva l ( 1 : 1 01 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudderval ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RudderPos ) ;Wavesval (1 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,2 ) ) ;Wavesval (2 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,3 ) ) ;Wavesval (3 , k ) = mod(360 + mean(Waves_2017_04_05 ( ( a : a+100) ,4 ) )−mean(

Ship_data3 ( ( a : a+100) , columnLabels . Heading ) ) ,360) ;end

162

Page 164: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

% Convert deg r e e s to rad iansWaves ( 3 , : ) = Waves ( 3 , : ) ∗( p i /180) ;Wavesval ( 3 , : ) = Wavesval ( 3 , : ) ∗( p i /180) ;

% r e t r i e v e the amount o f ca s e s in the 9 t r a i n i n g f o l d s and c a l c u l a t e% the amount o f ca s e s in each f o l d[~ , c o l ] = s i z e ( Ro l l i ng ) ;f o l d s i z e = co l /9 ;

%%% sepe ra t e the t r a i n i n g data so that the data used f o r e s t imat ing the% weights i s not found in the database . In conc lu s i on s e l e c t i n g one o f% the database f o l d s as t r a i n i n g f o l d f o r the GA

Rolling_GA_database = [ Ro l l i ng ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Ro l l i ng ( : , f o l d ∗f o l d s i z e : end ) ] ;

Rolling_GA_train = Ro l l i ng ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;

Rudder_GA_database = [ Rudder ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Rudder ( : , f o l d ∗ f o l d s i z e :end ) ] ;

Rudder_GA_train = Rudder ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;

Pitch_GA_database = [ Pitch ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Pitch ( : , f o l d ∗ f o l d s i z e : end) ] ;

Pitch_GA_train = Pitch ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;

Waves_GA_database = [Waves ( : , 1 : ( f o ld −1)∗ f o l d s i z e ) Waves ( : , f o l d ∗ f o l d s i z e : end) ] ;

Waves_GA_train = Waves ( : , ( f o ld −1)∗ f o l d s i z e +1: f o l d ∗ f o l d s i z e ) ;

d i sp ( ' done gather ing data ' )

% Se t t i ng t r a i n i n g time f o r GAminute = 30 ;

%% setup GAga_opts = gaopt imset (@ga) ;ga_opts . Display = ' i t e r ' ;ga_opts . Popu lat ionS ize = 10 ;ga_opts . TimeLimit = minute ∗60 ;ga_opts . Generat ions = i n f ;ga_opts . PopInitRange = [ −1 ; 1 ] ;ga_opts . TolFun = 1e−100;ga_opts . TolCon = 1e−100;ga_opts . Sta l lGenLimit = i n f ;

% s e l e c t i n g the amount o f weights to es t imate . This CBR u t i l i z e 3% weights f o r each wave parameter . E . g . 3−nea r e s t ne ighbor method i s% implementednvars = 3 ;nvars = nvars ∗3 ;[ samples , c a s e s ] = s i z e (Waves_GA_train) ;

d i sp ( ' s ea r ch ing f o r nea r e s t neighbor ' )%% Find the nea r e s t waves f o r GA t r a i n i n gf o r Case = 1 : ca s e s

Case[ temp1 , temp2 ] = Manhattan_distance (Case , nvars , . . .

Rolling_GA_database , Rudder_GA_database , . . .Pitch_GA_database , Rolling_GA_train , . . .Rudder_GA_train , Pitch_GA_train , . . .Waves_GA_database ) ;

nearest_waves ( : , Case ) = temp1 ' ;rmse ( : , Case ) = temp2 ' ;

end

%% Ut i l i z e GA f o r s e l e c t i o n o f weights

163

Page 165: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

[ x , ~ ] = ga ( @f i tnes s , nvars , ga_opts ) ;

%% Find the nea r e s t waves f o r the Va l idat i on f o l d[~ , c a s e s ] = s i z e (Wavesval ) ;f o r Case = 1 : ca s e s

[ temp1 , temp2 ] = Manhattan_distance (Case , nvars , . . .Ro l l ing , Rudder , . . .Pitch , Ro l l i ngva l , . . .Rudderval , Pitchval , . . .Waves) ;

nearest_waves ( : , Case ) = temp1 ' ;rmse ( : , Case ) = temp2 ' ;

end

%% Estimate the waves based on va l i d a t i o n f o l dK = nvars /3 ;f o r Case = 1 : ca s e s

est_Hs (Case ) = 0 ;est_Tp (Case ) = 0 ;est_Beta (Case ) = 0 ;f o r k = 1 :K

est_Hs (Case ) = est_Hs (Case ) + x(k ) ∗Waves (1 , nearest_waves (k , Case ) ) ;est_Tp (Case ) = est_Tp (Case ) + x(k+K) ∗Waves (2 , nearest_waves (k , Case ) ) ;est_Beta (Case ) = est_Beta (Case ) + x(k+(2∗K) ) ∗Waves (3 , nearest_waves (k ,

Case ) ) ;endi f (Wavesval (3 , Case )== 0)

Wavesval (3 , Case ) = 2∗ pi ;est_Beta (Case ) = est_Beta (Case ) + 2∗ pi ;

endend

save ( f i l ename )end

%% Plot r e s u l t sf i g u r e ( ' name ' , [ 'CBR FOLD = ' num2str ( f o l d ) ] )subplot ( 3 , 2 , 2 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( 'Hs (m) ' )xlim ( [ 0 ca s e s +1])e r r = ( est_Hs−Wavesval ( 1 , : ) ) . ^ 2 ;mse = mean( e r r ) ;s t r i n g = [ 'MSE = ' num2str (mse ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Wavesval ( 1 , : ) , ' k ' , 1 : cases , est_Hs ,'−−r ' )

subplot ( 3 , 2 , 1 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' f i t n e s s (%) ' )xlim ( [ 0 ca s e s +1])Perc = 100∗( est_Hs . /Wavesval ( 1 , : ) ) ;Optimal_Perc = 100∗ ones (1 , c a s e s ) ;d i f f = 100∗ ones ( s i z e ( Perc ) )−Perc ;mean_Hs_diff = mean( abs ( d i f f ) ) ;s t r i n g = [ 'Mean d i f f = ' num2str (mean_Hs_diff ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Optimal_Perc , ' k ' , 1 : cases , Perc ,'−−r ' )

subplot ( 3 , 2 , 4 , ' r ep lace ' ) ;hold ong r id on

164

Page 166: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

x l ab e l ( ' case ' )y l ab e l ( 'Tp ( sec ) ' )xlim ( [ 0 ca s e s +1])e r r = ( est_Tp−Wavesval ( 2 , : ) ) . ^ 2 ;mse = mean( e r r ) ;s t r i n g = [ 'MSE = ' num2str (mse ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Wavesval ( 2 , : ) , ' k ' , 1 : cases , est_Tp,'−−r ' )

subplot ( 3 , 2 , 3 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' f i t n e s s (%) ' )xlim ( [ 0 ca s e s +1])Perc = 100∗( est_Tp ./Wavesval ( 2 , : ) ) ;Optimal_Perc = 100∗ ones (1 , c a s e s ) ;d i f f = 100∗ ones ( s i z e ( Perc ) )−Perc ;mean_Tp_diff = mean( abs ( d i f f ) ) ;s t r i n g = [ 'Mean d i f f = ' num2str (mean_Tp_diff ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Optimal_Perc , ' k ' , 1 : cases , Perc ,'−−r ' )

subplot ( 3 , 2 , 6 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' Beta ( deg ) ' )xlim ( [ 0 ca s e s +1])e r r = ( est_Beta−Wavesval ( 3 , : ) ) . ^ 2 ;mse = mean( e r r ) ;s t r i n g = [ 'MSE = ' num2str (mse ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Wavesval ( 3 , : ) ∗(180/ p i ) , ' k ' , 1 : cases , est_Beta ∗(180/ p i ) ,'−−r ' )

subplot ( 3 , 2 , 5 , ' r ep lace ' ) ;hold ong r id onx l ab e l ( ' case ' )y l ab e l ( ' f i t n e s s (%) ' )xlim ( [ 0 ca s e s +1])Perc = 100∗( est_Beta . /Wavesval ( 3 , : ) ) ;Optimal_Perc = 100∗ ones (1 , c a s e s ) ;d i f f = 100∗ ones ( s i z e ( Perc ) )−Perc ;mean_Beta_diff = mean( abs ( d i f f ) ) ;s t r i n g = [ 'Mean d i f f = ' num2str (mean_Beta_diff ) ] ;t i t l e ( s t r i n g ) ;p l o t ( 1 : cases , Optimal_Perc , ' k ' , 1 : cases , Perc ,'−−r ' )

% Cost func t i on f o r GAfunc t i on mse_calc = f i t n e s s ( x )Waves = eva l i n ( ' base ' , 'Waves_GA_database ' ) ;Wavesval = eva l i n ( ' base ' , 'Waves_GA_train ' ) ;K = eva l i n ( ' base ' , ' nvars ' ) ;nearest_waves = eva l i n ( ' base ' , ' nearest_waves ' ) ;

[~ , c a s e s ] = s i z e (Wavesval ) ;

K = K /3 ;

mse_calc = 0 ;f o r Case = 1 : ca s e s

est_Hs = 0 ;est_Tp = 0 ;

165

Page 167: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

est_Beta = 0 ;f o r k = 1 :K

est_Hs = est_Hs + x(k ) ∗Waves (1 , nearest_waves (k , Case ) ) ;est_Tp = est_Tp + x(k+K) ∗Waves (2 , nearest_waves (k , Case ) ) ;est_Beta = est_Beta + x(k+(2∗K) ) ∗Waves (3 , nearest_waves (k , Case ) ) ;

endmse_calc = mse_calc + ( ( est_Hs−Wavesval (1 , Case ) ) ^2)+ ( ( est_Tp−Wavesval (2 , Case ) )

^2)+ ( ( est_Beta−Wavesval (3 , Case ) ) ^2) ;%mse_calc = mse_calc + 100∗ abs (1−( e s t imat i on /Wavesval (1 , Case ) ) ) ;

endmse_calc = mse_calc /(3∗ ca s e s ) ;end

Code E.11.2: The above source code was implemented in MATLAB to estimate the waveparameters using a CBR and Manhattan distance. The code above implements the functionpresented in appendix E.6.4.

166

Page 168: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.12 Estimate Wave Parameters With Transfer Function And Genetic

Algorithm

The following sections presents the code implemented for the extended TF with parameter extrac-tion utilizing actual data.

E.12.1 Encounter Spectrum Estimation

%c l c%c l e a r v a r s −except f o l d%c l o s e a l lwarning ( ' o f f ' , ' a l l ' ) ;

%Use va r i ab l e f o l d to va l i d a t e each and every f o l d : )%f o l d = 1 ;

f i l ename = 'TF_GA_Several_Based_On_Actual_Data .mat ' ;

%Check i f the v a r i a b l e s have been save from a prev ious t e s ti f ( e x i s t ( f i l ename , ' f i l e ' ) == 2)

load ( f i l ename )%The va r i a b l e s have not been saved to run the t e s t

e l s e%% −−−−−−−−−−−−−−−−−−−−−−−− INITIALIZE −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−load ( ' columnLabels ' ) ;load ( ' Ship_data ' ) ;Ship_data1 = Ship_data ;load ( 'D_2017−04−03') ;Ship_data2 = Ship_data ;load ( 'D_2017−04−04') ;Ship_data3 = Ship_data ;load ( 'Waves_2017_04_03 ' ) ;load ( 'Waves_2017_04_04 ' ) ;load ( 'Waves_2017_04_05 ' ) ;

[ row , c o l ] =s i z e (Waves_2017_04_04) ;Ship_data = [ Ship_data1 ( : , 1 : 7 3 ) ; Ship_data2 ( 1 : row , : ) ] ;

[ row , c o l ] =s i z e ( Ship_data1 ) ;Waves_init = [Waves_2017_04_03 ( 1 : row , : ) ;Waves_2017_04_04 ( : , : ) ] ;

%TrainingAmount = 1/2 ;

[ samples , ~ ] = s i z e ( Ship_data ) ;t r a i n c a s e s = f l o o r ( samples /101) ;

[ samples , ~ ] = s i z e ( Ship_data3 ) ;v a l c a s e s = f l o o r ( samples /101) ;

f o r k = 1 : t r a i n c a s e sa = 1+(k−1) ∗100 ;Ro l l i ng ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RollRaw ) ;Pitch (1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudder ( 1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . RudderPos ) ;Cont_spd (1 : 101 , k ) = Ship_data ( ( a : a+100) , columnLabels . SpeedThroughWater ) ;Waves (1 , k ) = mean(Waves_init ( ( a : a+100) ,2 ) ) ;Waves (2 , k ) = mean(Waves_init ( ( a : a+100) ,3 ) ) ;Waves (3 , k ) = mod(360 + mean(Waves_init ( ( a : a+100) ,4 ) )−mean( Ship_data ( ( a : a

+100) , columnLabels . Heading ) ) ,360) ;end

f o r k = 1 : va l c a s e sa = 1+(k−1) ∗100 ;Ro l l i n gva l ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RollRaw ) ;P i t chva l ( 1 : 1 01 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . PitchRaw ) ;Rudderval ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . RudderPos ) ;Cont_spdval ( 1 : 101 , k ) = Ship_data3 ( ( a : a+100) , columnLabels . SpeedThroughWater )

;

167

Page 169: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Wavesval (1 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,2 ) ) ;Wavesval (2 , k ) = mean(Waves_2017_04_05 ( ( a : a+100) ,3 ) ) ;Wavesval (3 , k ) = mod(360 + mean(Waves_2017_04_05 ( ( a : a+100) ,4 ) )−mean(

Ship_data3 ( ( a : a+100) , columnLabels . Heading ) ) ,360) ;endd i sp ( ' data loaded ' )

Waves ( 3 , : ) = Waves ( 3 , : ) ∗( p i /180) ;Wavesval ( 3 , : ) = Wavesval ( 3 , : ) ∗( p i /180) ;

hours = 0 . 5 ;minute = hours ∗60 ;

[ Samples , Cases ] = s i z e ( Ro l l i ng ) ;

f o r Case = 1 : CasesU(Case ) = mean(Cont_spd ( : , Case ) ) ; %Average

sh ip speed i s constant f o r a l l the dataU(Case ) = U(Case ) ∗ 0 .5144443101 ; %convert to m/ s

end

g = 9 . 8 2 ; %grav i ty constantw_lim = 2 ;w_step = w_lim/Samples ;w = w_step : w_step : w_lim ; %Frequency vec to r

Ts = w_step ;%.25 ; %Sampling time o f the data i s a l s oconstant

Hs = Waves ( 1 , : ) ;Tp = Waves ( 2 , : ) ;Beta = Waves ( 3 , : ) ;

%Setup Wave Spectrum (ITTC)omega_0 =@(k ) (2∗ pi ) . /Tp(k ) ;T1 = @(k ) (2∗ pi ) . / ( 1 . 2 9 5 7 . ∗ omega_0(k ) ) ;ITTC = @(x , k ) ( (173∗ (Hs(k ) ^2) . / (T1(k ) ^4) ) . / ( x .^5) ) .∗ exp (−((691 ./(T1(k ) ^4) ) . / ( x

.^4) ) ) ;

%Use Tr i s tan Perez c a l c u l a t i o n s to r e t r i e v e the EncounterSpectrum%This i s the input o f the Trans fe r func t i on f o r the Di rec t Method%and output f o r the Trans fe r Function f o r the In−d i r e c t method%The output f o r the Trans fe r func t i on in Di rec t method i s g iven%by the motion spectrum f o r the r o l l i n g , which i s r e t r i e v e d with f f t .%And the input f o r the in−d i r e c t t r a n s f e r func t i on i s a l s o the motion%spectrumf o r k = 1 : Cases

ktemp = ITTC(w, k ) . / ( abs (1−((2.∗w.∗U(k ) ) . / ( g ) ) .∗ cos ( Beta (k ) ) ) ) ;i f k == 1

EncounterSpectrum = temp ' ;MotionSpectrum = f f t ( Ro l l i ng ( : , k ) ) ;

e l s eEncounterSpectrum = [ EncounterSpectrum temp ' ] ;MotionSpectrum = [ MotionSpectrum f f t ( Ro l l i ng ( : , k ) ) ] ;

endend

nvars = 408 ; %number o f v a r i a b l e s to es t imate with the GA ( nvars = 200−> 50r e a l and 50 complex numerators , and 50 r e a l and 50 complex denominators )

%Setup the GAga_opts = gaopt imset (@ga) ;ga_opts . Display = ' i t e r ' ;ga_opts . Popu lat ionS ize = 10 ;ga_opts . TimeLimit = minute ∗60 ;ga_opts . Generat ions = i n f ;

168

Page 170: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

ga_opts . PopInitRange = [ −1 ; 1 ] ;ga_opts . TolFun = 1e−20;ga_opts . TolCon = 1e−20;ga_opts . Sta l lGenLimit = 1000 ;

%%========================================================================================

disp ( ' Ca l cu l a t ing Di rec t TF' ) ;

% %% FIND DIRECT TF% [ x , ~ ] = ga ( @f i tnes s_di r r , nvars , ga_opts ) ;% nom = nvars /4 ;% a = x ( 1 , 1 :nom) + x (1 , (nom+1) :2∗nom) ∗1 i ;% b = x (1 ,2∗nom+1:3∗nom) + x (1 ,3∗nom + 1 : nvars ) ∗1 i ;%% DirectTF = t f (b , a , ' Ts ' , Ts , ' va r i ab l e ' , ' z^−1') ;%

%% FIND INDIRECT TF%Setup the GAdisp ( ' Ca l cu l a t ing In−Direc t TF' ) ;

[ y , ~ ] = ga ( @f i tness_in_dirr , nvars , ga_opts ) ;nom = nvars /4 ;a = y ( 1 , 1 :nom) + y (1 , (nom+1) :2∗nom) ∗1 i ;b = y (1 ,2∗nom+1:3∗nom) + y (1 ,3∗nom + 1 : nvars ) ∗1 i ;% a = y (1 , 1 : 2∗nom) ;% b = y (1 ,2∗nom+1: nvars ) ;

InDirectTF = t f (b , a , ' Ts ' , Ts , ' va r i ab l e ' , ' z^−1') ;

%% VALIDATE THE TF[~ , c o l ] = s i z e (Wavesval ) ;f o r k = 1 : c o l

d i sp ( [ num2str ( k ) '/ ' num2str ( c o l ) ] )FIT ( : , k ) = ValidateMyTFs ( Ro l l i n gva l ( : , k ) ,Wavesval ( : , k ) , Cont_spdval ( : , k ) , [ ] ,

InDirectTF ) ;endsave ( f i l ename )

end

f i g u r et i t l e ( ' Results ' )hold ong r id onx l ab e l ( ' Monitored Per iods o f the Voyage ' )y l ab e l ( ' F i tne s s (%) ' )ylim ( [ min (FIT ( 1 , : ) ) 100 ] )p l o t (FIT ( 1 , : ) , ' k ' )

%% DIRECT FITNESS FUNCTIONfunc t i on FIT = f i t n e s s_d i r r ( x )%Retr i eve s p e c i f i c v a r i a b l e s from workspacen = eva l i n ( ' base ' , ' nvars ' ) ;t s = eva l i n ( ' base ' , ' Ts ' ) ;EncounterSpectrum = eva l i n ( ' base ' , ' EncounterSpectrum ' ) ;MotionSpectrum = eva l i n ( ' base ' , ' MotionSpectrum ' ) ;

[~ , c o l ] = s i z e (MotionSpectrum ) ;FIT = 0 ;f o r k = 1 : c o l

%Setup the Input output data f o r the d i r e c t methodmotion = MotionSpectrum ( : , k ) ;encounter = EncounterSpectrum ( : , k ) ;t ry

data = iddata (motion , encounter , ' Ts ' , t s ) ;

169

Page 171: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

nom = n/4 ;a = x ( 1 , 1 :nom) + x (1 , (nom+1) :2∗nom) ∗1 i ;b = x (1 ,2∗nom+1:3∗nom) + x (1 ,3∗nom + 1 : n) ∗1 i ;

%try to f i nd a TF us ing the va r i ab l e s , and c a l c u l a t e the f i tt f 1 = t f (b , a , ' Ts ' , ts , ' va r i ab l e ' , ' z^−1') ;[~ , f i t ] = compare ( data , t f 1 ) ;f i t = abs ( f i t −100) ;

catch% i f the v a r i a b l e s can ' t generate a TF then the f i t va lue f o r the se% va r i a b l e s i s s e t to nanf i t = nan ;

endFIT = FIT + f i t ;

endFIT = FIT / co l ;end

%% IN−DIRECT FITNESS FUNCTIONfunc t i on FIT = f i tn e s s_ in_d i r r ( x )%Retr i eve s p e c i f i c v a r i a b l e s from workspacen = eva l i n ( ' base ' , ' nvars ' ) ;

EncounterSpectrum = eva l i n ( ' base ' , ' EncounterSpectrum ' ) ;MotionSpectrum = eva l i n ( ' base ' , ' MotionSpectrum ' ) ;

[~ , c o l ] = s i z e ( EncounterSpectrum ) ;FIT = 0 ;f o r k = 1 : c o l

%Setup the Input output data f o r the d i r e c t methodmotion = MotionSpectrum ( : , k ) ;encounter = EncounterSpectrum ( : , k ) ;t ry

nom = n/4 ;a = x ( 1 , 1 :nom) + x (1 , (nom+1) :2∗nom) ∗1 i ;b = x (1 ,2∗nom+1:3∗nom) + x (1 ,3∗nom + 1 : n) ∗1 i ;out = f i l t e r (b , a , motion ) ;

f i t 1 = sum( ( r e a l ( encounter )−r e a l ( out ) ) .^2) / l ength ( r e a l ( encounter ) ) ;f i t 2 = sum( ( imag ( encounter )−imag ( out ) ) .^2) / l ength ( imag ( encounter ) ) ;f i t = ( f i t 1+f i t 2 ) /2 ;

catch% i f the v a r i a b l e s can ' t generate a TF then the f i t va lue f o r the se% va r i a b l e s i s s e t to nanf i t = nan ;

endFIT = FIT + f i t ;

endFIT = FIT / co l ;end

Code E.12.1: The above presented source code was utilized to estimate the encounter spectrumwith a TF based on several cases and trained with GA. Unlike the previous presented examples,this TF have been con�gured to estimate a larger TF during the training time of 30 minutes.

170

Page 172: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

E.12.2 Parameter Extraction

c l cc l e a rc l o s e a l lformat shor t

load ( 'TF_GA_Several_Based_On_Actual_Data .mat ' )

ActRol l ing = Ro l l i n gva l ;TF = InDirectTF ;Speed = Cont_spdval ;Waves = Wavesval ;

c l e a r v a r s −except ActRol l ing TF Speed Waves w w_step

DirectionKnown = true ;

[ samples , c a s e s ] = s i z e ( ActRol l ing ) ;SpeedConverter = 0 .5144443101 ; %convert to m/ sg = 9 . 8 2 ;e lapsedt ime = 0 ;Error = 0 ;AE = [0 0 0 ] ;

f i g u r e (1 )subplot ( 3 , 1 , 1 )hold ong r id ont i t l e ( 'Hs ' )x l ab e l ( ' Cases ' )y l ab e l ( ' Error (%) ' )h1 = p lo t (0 , 0 ) ;

subplot ( 3 , 1 , 2 )hold ong r id ont i t l e ( 'Tp ' )x l ab e l ( ' Cases ' )y l ab e l ( ' Error (%) ' )h2 = p lo t (0 , 0 ) ;

subplot ( 3 , 1 , 3 )hold ong r id ont i t l e ( ' Beta ' )x l ab e l ( ' Cases ' )y l ab e l ( ' Error (%) ' )h3 = p lo t (0 , 0 ) ;

Bar = waitbar (0 , ' Est imating Parameters ' ) ;

f o r k = 1 : ca s e s

MAE = mean(AE, 1 ) ;

t i c ;Time = (sum( e lapsedt ime ) /(k−1) ) ∗( cases −(k−1) ) /(60∗60) ;EstimatedHoursLeft = f l o o r (Time) ;Min = (Time−EstimatedHoursLeft ) ∗60 ;EstimatedMinLeft = f l o o r (Min) ;Est imatedSecLeft = f l o o r ( (Min−EstimatedMinLeft ) ∗60) ;s t r i n g = [ ' Estimated time l e f t = ' num2str ( EstimatedHoursLeft ) 'h ' . . .

num2str ( EstimatedMinLeft ) 'min ' num2str ( Est imatedSecLeft ) ' s e c \n ' . . .'MAE Hs = ' num2str (MAE(1) ) ' , MAE Tp = ' num2str (MAE(2) ) . . .' , MAE Beta = ' num2str (MAE(3) ) ] ;

waitbar ( k / cases , Bar , s p r i n t f ( s t r i n g ) ) ;

U = mean( Speed ( : , k ) ) ∗SpeedConverter ;

171

Page 173: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Hs = Waves (1 , k ) ;Tp = Waves (2 , k ) ;Beta = Waves (3 , k ) ;

omega_0 = (2∗ pi ) /Tp ;T1 = (2∗ pi ) /(1 .2957∗omega_0) ;ITTC = @(x ) ( (173∗ (Hs^2) /(T1^4) ) . / ( x .^5) ) .∗ exp (−((691/(T1^4) ) . / ( x .^4) ) ) ;ActualEncounterSpectrum = ITTC(w) . / ( abs (1−((2.∗w.∗U) . / ( g ) ) ∗ cos ( Beta ) ) ) ;

MotionSpectrum = f f t ( ActRol l ing ( : , k ) ) ;

Ts = w_step ;Data_Inverse = iddata ( ActualEncounterSpectrum ' , MotionSpectrum , Ts ) ;

%r e t r i e v e the f i t n e s s o f the t r a n s f e r func t i on to mark the p l o t i f the%encounter spectrum es t imat ion have f a i l e d[ y , f i t ] = compare ( Data_Inverse ,TF) ;

%Estimated EncounterSpectrumEstEncounterSpectrum = y . y ;

opt ions = opt imopt ions (@ga , ' Populat ionSize ' , 20 , ' TolFun ' , 1e−20 , 'TolCon ' , 1e−20 , ' Generations ' , 1000 , ' Stal lGenLimit ' , 200 , 'Time ' , 2 5 ) ;

Object iveFunct ion = @simple_f i tness ;nvars = 3 ; % Number o f v a r i a b l e s

i f ( DirectionKnown )i f ( Beta < pi )

LB = [0 0 0 ] ; % Lower boundUB = [5 10 p i ] ; % Upper bound

e l s eLB = [0 0 p i ] ; % Lower boundUB = [5 10 2∗ pi ] ; % Upper bound

ende l s e

LB = [0 0 0 ] ; % Lower boundUB = [5 10 2∗ pi ] ; % Upper bound

end

[ x , f v a l ] = ga ( Object iveFunct ion , nvars , [ ] , [ ] , [ ] , [ ] , LB,UB, [ ] , opt i ons ) ;

F i tne s s (k , 1 : 3 ) = 100 .∗ [ x (1 ) /Hs x (2 ) /Tp x (3) /Beta ] ;AE = abs (100∗ ones ( s i z e ( F i tne s s ) )−Fi tne s s ) ;

Parameters ( 1 : 3 , k ) = [ x (1 ) ; x (2 ) ; x (3 ) ] ;

subp lot ( 3 , 1 , 1 )hold onax i s ( [ 0 k+1 0 100 ] )d e l e t e ( h1 ) ;h1 = p lo t ( 1 : k ,AE( 1 : k , 1 ) , ' rx− ') ;i f ( abs (100− f i t ) >0.1)

p l o t ( [ k k ] , [ 0 100 ] , ' ko−−') ;endsubplot ( 3 , 1 , 2 )hold onax i s ( [ 0 k+1 0 100 ] )d e l e t e ( h2 ) ;h2 = p lo t ( 1 : k ,AE( 1 : k , 2 ) , ' rx− ') ;i f ( abs (100− f i t ) >0.1)

p l o t ( [ k k ] , [ 0 100 ] , ' ko−−') ;endsubplot ( 3 , 1 , 3 )hold onax i s ( [ 0 k+1 0 100 ] )d e l e t e ( h3 ) ;h3 = p lo t ( 1 : k ,AE( 1 : k , 3 ) , ' rx− ') ;

172

Page 174: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

i f ( abs (100− f i t ) >0.1)p l o t ( [ k k ] , [ 0 100 ] , ' ko−−') ;

enddrawnowe lapsedt ime (k ) = toc ;

end

func t i on FIT = s imp l e_ f i tn e s s ( x )ES = eva l i n ( ' base ' , ' EstEncounterSpectrum ' ) ;w = eva l i n ( ' base ' , 'w' ) ;U = eva l i n ( ' base ' , 'U' ) ;g = eva l i n ( ' base ' , ' g ' ) ;

omega_0 = (2∗ pi ) /x (2 ) ;T1 = (2∗ pi ) /(1 .2957∗omega_0) ;ITTC = @(y ) ( (173∗ ( x (1 ) ^2) /(T1^4) ) . / ( y .^5) ) .∗ exp (−((691/(T1^4) ) . / ( y .^4) ) ) ;EncounterSpectrum = ITTC(w) . / ( abs (1−((2.∗w.∗U) . / ( g ) ) ∗ cos ( x (3 ) ) ) ) ;

FIT = mean( abs (ES−EncounterSpectrum ' ) ) ;

end

Code E.12.2: The above presented source code was utilized to extract the parameters whichgenerated the estimated encounter spectrum. The code is dependent on the TF obtained fromthe code presented in appendix E.12.1. The �nal TF utilized for this code can also be acquired byexecuting the commands presented in appendix F.

173

Page 175: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Appendix F The Final Transfer Function

To acquire the TF utilized for the result presented in �gure 10.6.1, open MATLAB and enter thefollowing commands in the Command Window.

num = s t r r e p ([(−1.9139−3.1022 i ) (7 .3127+2.3876 i ) (−0.150635+10.4708 i ) (6.257−1.3142i ) (1 .6151+4.1672 i ) (−3.7854+2.0455 i ) (−2.4327−4.3087 i ) (1.4037−4.1706 i )(2 .6116+9.5678 i ) (−6.9849−2.2105 i ) (6.8283−6.2354 i ) (−5.0039+7.3832 i )(1.4515−4.8002 i ) (−2.0612−5.834 i ) (−0.12652−7.0868 i ) (−5.4952−2.0886 i )(1.9388−2.9641 i ) (−1.4266+2.7591 i ) (−8.5792+3.1011 i ) (0.65026−6.2312 i )(2 .9148+7.3219 i ) (−1.5734+2.096 i ) (−9.0071−1.8338 i ) (−2.9675−2.1384 i )(0 .42241+0.679 i ) (−2.1118−1.643 i ) (−4.6478−6.9327 i ) (8.04383−7.42872 i )(5 .1788+5.1493 i ) (−8.1665+4.4335 i ) (−1.8968−8.7456 i ) (−0.54237+0.17758 i )(−5.0843−0.78167 i ) (−4.0371−3.3144 i ) (−2.3082+1.7854 i ) (2 .6898+1.0219 i )(3.29444−10.5955 i ) (5 .8408+0.88482 i ) (−6.3809−11.5216 i ) (1.8225−6.8614 i )(0.13167−3.4098 i ) (0.8381−0.28885 i ) (−5.0135+3.724 i ) (7 .9472+0.77565 i )(2.8287−1.4576 i ) (3.4984−7.5346 i ) (4 .9608+6.6201 i ) (2 .4332+2.1113 i )(2 .6009+0.66703 i ) (1 .6005+1.8492 i ) (−4.39166+8.99827 i ) (0.33847−2.3677 i )(−9.8537+0.097684 i ) (6.5589−8.18584 i ) (2 .093+6.0021 i ) (1.0371−0.37714 i )(8 .3373+4.3903 i ) (2 .3473+3.8084 i ) (−3.1603−2.6449 i ) (0 .067286+4.6334 i )(8.7013−3.0095 i ) (10.7506+1.47447 i ) (2 .3792+4.1205 i ) (5.1911−0.030638 i )(−4.8493−0.61616 i ) (−0.85092+6.0318 i ) (−5.1512−0.72464 i ) (1 .1659+1.612 i )(−3.32−1.5191 i ) (−0.92874−3.1178 i ) (−9.67679−8.94375 i ) (−1.1628+0.47652 i )(−3.0386−2.0237 i ) (−4.3719−3.7464 i ) (−2.422−4.2452 i ) (8 .15651+10.4407 i )(−2.2432+2.7433 i ) (3.4629−2.5804 i ) (−2.8201+8.574 i ) (1.8871−0.13813 i )(5.4297−3.0352 i ) (−12.9358+0.191911 i ) (2.8063−0.032231 i ) (2 .0244+3.8022 i )(0 .054623+4.2014 i ) (1 .6219+2.9661 i ) (7 .2387+2.8484 i ) (7 .7044+1.532 i )(11.0152−1.68834 i ) (9.57642−6.17175 i ) (2 .0496+4.3988 i ) (−0.89689−0.074936 i )(−0.24672+6.58 i ) (3.88294−13.2933 i ) (0 .91998+2.9156 i ) (1.2405−1.0159 i )(1.4678−1.4811 i ) (−11.1084−5.89626 i ) (−1.5627−5.0545 i ) (−7.6057+4.423 i )(2.2074−1.446 i ) (2 .27706+19.2145 i ) ] , ' , ' , ' . ' ) ;

den=s t r r e p ([(−116.8234−19.90907 i ) (1.75577−12.5202 i ) (−9.6139−0.87595 i )(8 .0146+0.58271 i ) (−12.7593−4.04414 i ) (7 .2525+2.3958 i ) (2 .0416+5.265 i )(−1.0564−7.7919 i ) (−0.01121+6.942 i ) (3 .9348+8.2719 i ) (8 .0836+4.2762 i )(−6.307+0.84998 i ) (−0.41814−3.2764 i ) (−8.4851−2.8594 i ) (2 .3119+3.1239 i )(1 .1352+2.2382 i ) (7.65456−8.93965 i ) (−0.13186+2.6166 i ) (−0.010174−7.5752 i )(−5.6423+5.8965 i ) (−1.6743−0.22757 i ) (−1.6926−4.1183 i ) (−1.73145−18.4951 i )(7.82634−10.7316 i ) (−0.72765−6.7145 i ) (8 .53697+5.85528 i ) (−9.53041−7.23466 i )(4 .2008+6.2424 i ) (−7.93421+8.11338 i ) (4 .9049+3.2884 i ) (10.9535+7.27573 i )(−3.65044−12.2456 i ) (−4.9156+3.4893 i ) (−6.4117−2.2883 i ) (4.0261−8.2755 i )(2.5054−2.8072 i ) (0.037116−5.1024 i ) (14.2136−2.1084 i ) (−1.6533−2.3924 i )(2.62491−12.1682 i ) (−6.9267−3.1806 i ) (−9.3978+1.8836 i ) (3 .2998+6.9717 i )(−4.6129−8.13 i ) (−9.2716−0.16089 i ) (1 .2496+0.62452 i ) (9 .37177+4.76697 i )(−6.37796−17.467 i ) (4.7274−3.1439 i ) (14.6695−0.0882168 i ) (6.8346−4.2721 i )(1 .6227+1.6587 i ) (2.55874−13.4888 i ) (0.30465−7.4399 i ) (6.6813−3.9728 i )(−2.747−2.485 i ) (11.5144−7.33959 i ) (−4.3704+0.91126 i ) (−7.63842−7.67872 i )(11.7782−6.29099 i ) (−7.5692+0.91474 i ) (10.1467+3.64559 i ) (−2.7437−3.6095 i )(−5.61935−13.2075 i ) (−4.7159−4.7967 i ) (−1.3888+5.7967 i ) (1 .3664+3.0414 i )(−1.7087+8.151 i ) (−0.108+0.83522 i ) (2 .97373+18.6985 i ) (−3.6155+6.7459 i )(2 .648+7.6185 i ) (8.395−4.83 i ) (5.84419−15.7567 i ) (5.658−0.13433 i ) (−8.2825−1.1907 i )(−1.4708−8.9622 i ) (−8.3986+6.83559 i ) (−11.2463−3.70057 i ) (−1.15216−15.1402 i )(17.9087+21.4178 i ) (−5.4279+1.9586 i ) (1 .8358+0.15571 i ) (−14.6716+8.81504 i )(−0.28684−4.7092 i ) (−12.6272+12.8152 i ) (2.1057−4.7522 i ) (2.14698−10.7524 i )(6 .64295+9.22471 i ) (−4.4389+0.0889 i ) (−1.618−2.8141 i ) (−4.1623+2.0679 i )(2 .6066+5.7154 i ) (−2.0988−0.32717 i ) (−10.537−5.83367 i ) (12.0215+5.82911 i )(−2.46955+10.9628 i ) (−3.581−1.0435 i ) (−8.18937+7.04659 i ) (10.1468+6.05996 i )(9.73276−4.67064 i ) (−10.5869+2.58136 i ) ] , ' , ' , ' . ' ) ;

t s = 0 . 0 198 ;

TF = t f (num, den , ts , ' va r i ab l e ' , ' z^−1') ;

Code F.0.3: The source code above presents how the best obtained TF can be acquired inMATLAB. The numerator and denominator both have a degree of −101

174

Page 176: OCEAN WAVES ESTIMATION - DiVA portal1108695/... · 2017-06-12 · ther by air or by sea. ranspTort by sea exceeds by large margin cargo transport by plains 2. An example of the shipping

Mälardalen University Master Thesis

Appendix G Time Plan

The following section presents the initial time-plan of the master thesis week-by-week. The work-load is full time which according to Swedish standard is 40 hours/week. If needed, overtime andworking on weekends may occur to ensure that deadlines are met. As seen from the list, su�cienttime have been put away for the test phase. This is to ensure that su�cient time is provided toacquire results and making improvements of implemented solutions. Updating the report contin-uously throughout the process is mandatory to ensure that no relevant information is forgotten.

• Week 1 - Make updates to the �rst proposal and hand it in. Do research about wave theoryand state-of-the art research concerning the problem

• Week 2 - Do research about wave theory and state-of-the art research concerning the problem

• Week 3 - Continue the research of wave-theory and state-of-the art research. Prepare thestatus and planning report

• Week 4 - Continue the research of wave-theory and state-of-the art research. Prepare andattend status and planning seminar.

• Week 5 - Finalize the research of wave-theory and state-of-the art research.

• Week 6 - Increase knowledge and do research about the proposed solutions.

• Week 7 - Compare the proposed solutions against each other and make a decision concerningwhich solution to implement.

• Week 8 - Begin modeling the solution in MATLAB

• Week 9 - Continue with modeling

• Week 10 - Finalize the modeling

• Week 11 - Start implementing the modeled solution and test it

• Week 12 - Continue with tests

• Week 13 - Continue with tests

• Week 14 - Finalize the tests

• Week 15 - Analyze the results

• Week 16 - Read/Write/Structure the �nal report

• Week 17 - Finalize the report

• Week 18 - Submit the report and start preparing for presentation

• Week 19 - Sign up for opponentship, prepare for the opponentship and the presentation

• Week 20 - Attend presentations

The intended plan has been part-wise followed. It was found that the time set aside for wave-theory was not nearly enough. The time set aside for the modeling of the solutions was neitherenough since multiple solutions were to be implemented to conduct a proper study. The time neededfor testing and analyzing was however more than enough, which lead to this phase becoming atime reserve for the previous phases. The report was continuously updated throughout the wholesemester so that a focus of improving the report by the end of the semester was possible.

175