Question1Introduction Automatic detection of faults can be found in many…1IntroductionAutomatic detection of faults can be found in many engineering systems. There are systems to automatically diagnose faults in engines, chemical plants, photovoltaic plants, manufacturing processes and on on.This assignment isinspiredby a fault detection system in a water treatment plant[1]. There are two main types of water treatment plants. One is to produce potable water (colloquially known as drinking water) and the other is to treat wastewater before discharging it into the natural environment. In both cases, water quality is an important issue. Therefore, there are instruments in the plants to constantly measure water quality and there are computers to process the collected data to check whether the plant is working correctly. If a fault has been developed, then the plant technicians should be alerted automatically so that they can fix the faults as soon as possible.In this assignment, you will write Python programs to perform fault detection. The aims of your program is to process data sequences to determine whether there are faults, the type of faults and when the fault is detected.Note that we chose the word inspired earlier because we have adapted the fault detection problem in[1]as a programming assignment by simplifying and liberally changing a few aspects of the original problem. In particular, we have made changes so that, in this assignment, you will have to use the various Python constructs that you have learnt. This means a few details of this assignment may not be realistic in engineering terms, but on the whole, you will still get a taste on how programming can be used to perform automatic fault detection.1.1Learning objectivesBy completing this assignment, you will learn:To apply basic programming concepts of variable declaration, assignment, conditional, functions, loops and import.To use the Python data types: list, float, int and BooleanTo translate an algorithm described in a natural language to a computer language.To organize programs into modules by using functionsTo use good program style including comments and documentationTo get a practice on software development, which includes incremental development, testing and debugging.1.2ProhibitionFor this assignment, the only external Python library that you are allowed to use is themathlibrary. Any other libraries, such asnumpy,scipyetc., arenotallowed.This is an individual assignment, sonogroup work.2Intuition behind the fault detection algorithmThe reference[1]uses a fault detection algorithm called CUSUM and you will be programming this algorithm in the assignment. We want to give you some intuition behind CUSUM. The name CUSUM is short forcumulative sumbecause the algorithm does the action of accumulating, as you will see in a moment.Figures 1a and 1b plot two signals (or data sequences) that you will be using in your testing. These two signals may look the same but they are actually slightly different. In fact, some of the data in one signal have slightly higher values because of a fault. Since the difference is small, it is not possible to use only one data point to decide whether there is a fault. However, each data point is important. Although a data point may only give us a tiny amount of evidence on whether there is a fault or not, what we can do is toaccumulatethe evidence from many data points. If in the end, the cumulative evidence that there is a fault is large, then we can be confident that a fault has in fact been developed. The blue curves in Figures 1c and 1d show the cumulative evidence of whether there is a fault in the signals in, respectively, Figures 1a and 1b. The red horizontal dashed lines can be thought of as the threshold of evidence that we need to decide whether there is a fault. If the cumulative evidence goes above the threshold, as in Figure 1c, then we say that a fault has occurred. If the cumulative evidence stays below the threshold, as in Figure 1d, then a fault has not been detected. The computer programs that you will write in this assignment will enable you to calculate the cumulative evidence.Fig 1a. The signal used in the test case 0 of the test filetest_fault_detection_main_1.py Fig 1b. The signal used in the test case 1 of the test filetest_fault_detection_main_1.pyFig 1c. The CUSUM of the signal in Fig. 1a. CUSUM can be thought of as cumulative evidence that a fault has occurred. Fig 1d. The CUSUM of the signal in Fig. 1b. CUSUM can be thought of as cumulative evidence that a fault has occurred.3Requirements for fault detectionThis section describes the requirements on the fault detection algorithm that you will be programming in this assignment. You should be able to implement these requirements by using only the Python skills that you have learnt in the first four weeks’ of the lectures in this course.We begin with describing the data that the algorithm will operate on. We will use the following Python code as an example. In the following, we will refer to the following code as thesample code. Note that the data and parameter values in the sample code are for illustration only; your code should work with any valid input data and parameter values.#%%Testdataandparameters#Theconcsignalconc_signal=[6.55,6.40,6.76,6.45,6.87,6.92,6.45,7.36,7.41,6.67]#Parametersusedtodetectwhetherthereisafaultintheconc_signalconc_range=[6.1,6.9]conc_var=0.5conc_cusum_limit=1.55#Theflow_signalflow_signal=[22.94,23.07,23.97,23.9,24.05,23.65,23.78,23.78,23.94,23.91]#Theparametersusedtodetectwhetherthereisafaultintheflow_signalflow_range=[22.5,23.5]flow_control_window=3#%%Callthefaultdetectionfunctionimportdetect_fault_mainasdffault_type_your=df.detect_fault_main(conc_signal,conc_range,conc_var,conc_cusum_limit,flow_signal,flow_range,flow_control_window)In the sample code, there are two data series which contain, respectively, concentration and flow measurements. Both series are Python lists, and their variable names areconc_signalandflow_signal.In addition to the two data series, your programs will make use of five algorithmic parameters with the namesconc_range,conc_var,conc_cusum_limit,flow_range, andflow_control_window. We will introduce these parameters when we describe the algorithm.We break the algorithm down into a number of steps. The first step is to compute what we called “a tiny amount of evidence in Section2. Formally speaking, “a tiny amount of evidence is referring to log-probability ratio, which we will shorten to log-prob ratio. You do not need to know what log-prob ratio to complete this assignment but an explanation is in Section12which you can read at your own time later on.3.1Computing the log-prob ratio for one concentration measurementLetbe a concentration measurement. We calculate the log-prob ratio ofusing the formula:where,andare three parameters.We will use an example to illustrate how you can use this formula. This example uses values from thesample code. Letbe the first entry inconc_signalwhich means. Theandvalues come fromconc_range, we haveand. The value ofiswhich comes fromconc_var. Substituting these values into (1), the log-prob ratio is.You may wonder why we use the term log-prob ratio but you do not see any logarithm in the formula in (1), this is because the logarithm has been cancelled out when (1) is derived.3.2Computing the log-prob ratio forconc_signalSection3.1explains how the log-prob ratio for one measurement inconc_signalcan be computed. The same procedure can be applied to each measurement inconc_signalto compute the log-prob ratios for all the entries inconc_signal. We will use the Python variableconc_lprto refer to this result. For thesample code, theconc_lpris expected to be:[0.08,-0.16,0.416,-0.08,0.592,0.672,-0.08,1.376,1.456,0.272]3.3Computing the CUSUMThe CUSUM is computed afterconc_lprhas been calculated. The CUSUM is a sequence of numbers (or list) which has the same number of entries asconc_lpr. We will useconc_cusumto denote this list. The first entry ofconc_cusumis related to the first entry ofconc_lprby the following relationship:For entries inconc_cusumwith indiceskgreater than or equal to 1, they are calculated using:For thesample code, we have calculatedconc_lprin Section3.2. By using thatconc_lpr, we can calculateconc_cusumshould be:[0.08,0,0.416,0.336,0.928,1.6,1.52,2.896,4.352,4.624]Note that the definition in (2) implies that ifconc_lpr[0]is negative, thenconc_cusum[0]will be zero.3.4Determining whether the concentration signal indicates a faultWe will useconc_cusum(which can be thought of as the cumulative evidence that there is a fault) and the parameterconc_cusum_limitto determine whether there is a fault. We say the concentration measurements indicate that there is a fault if at least an entry inconc_cusumis greater than or equal toconc_cusum_limit. For thesample code, there is a fault.We are interested to determine two pieces of information fromconc_cusumandconc_cusum_limit. First, we want to determine the time at which the fault is detected. We use thesample codeto illustrate how this time is to be determines. In this example, the entries at indices 5, 7, 8 and 9 ofconc_cusumare at or aboveconc_cusum_limit. The smallest of all these indices is 5 and we say that the fault is detected at time 5. Second, we want to determine the number of entries inconc_cusumthat are at or aboveconc_cusum_limit. For thesample code, the answer is 4.The above example is for the case where there is a fault inconc_cusum. In the case where a fault is absent, we will assignmath.inf(i.e. infinity in themathlibrary) to the time at which fault is detected. The number of entries inconc_cusumthat are at or aboveconc_cusum_limitshould be zero.Note that Figures 1c and 1d in Section2plot the CUSUM. The red dashed lines in these figures indicate the level ofconc_cusum_limit.3.5Classifying the type of faultIf the concentration measurements indicate that there is a fault, we want to determine whether the fault is limited to the concentration only or whether there is also a fault in the flow. We will describe the procedure to determine whether there is a fault in the flow in two steps.In the first step, we compute the average of a number of consecutive entries inflow_signal. The number of entries to be used is specified by the parameterflow_control_window. Another requirement is that the last of these consecutive entries is at the index at which the concentration fault is detected. Let us use thesample codeas an illustration. Since the valueflow_control_windowis 3, this means we will use 3 consecutive entries inflow_signalto compute the average. We know from Section3.4that the concentration fault is detected at index 5, so the three consecutive entries have indices 3, 4 and 5. Hence, we compute the average of 23.9, 24.05 and 23.65, which is 23.87.In the second step, we determine whether the average flow computed is within an acceptable range. We assume that the two numbers inflow_rangeform a closed interval, i.e. inclusive of the ends. If the average flow is inside the interval, then there are no faults in the flow; otherwise there is. In thesample code, the closed interval is[22.5,23.5]and the computed average of 23.87 is not inside of this interval, so there is a fault in the flow.Note that the above procedure requires that the time at which the concentration fault is detected is greater than or equal to the value inflow_control_window. You can assume that all the tests that we use for testing your code will meet this requirement.3.6Validity checksThe description above explains how the data (conc_signalandflow_signal) and algorithmic parameters (conc_range,conc_var,conc_cusum_limit,flow_range, andflow_control_window) are used to determine whether there are faults. Note that the algorithmic parameters must be valid so that the computation can be carried out. We require that your code performs a number of validity checks before determining if there are any faults. For example, we assume that the algorithmic parameterflow_control_windowis required to be a strictly positive integer. The following table states the requirements for the algorithmic parameters to be valid and what assumptions you can make when testing. Algorithmic parameters Requirements for the parameter to be valid Assumptions you can make when testing or further explanation conc_range,flow_range Must have exactly 2 entries.The value of the second entry in the list must be strictly greater than that of the first. You can assume that the givenconc_rangeandflow_rangeare of Python list type, their entries are numbers (int or float) which are strictly positive.Examples of invalid inputs:[2.5,3.1,3.5],[7.2,6.7] conc_var,conc_cusum_limit Must be strictly positive. You can assume that the givenconc_varandconc_cusum_limitare numbers (int or float).Examples of invalid inputs: -1.5, 0 flow_control_window Data type must be int and its value is strictly positive You can assume that the givenflow_control_windowis always a number.Examples of invalid inputs: -5, -5.2, 5.7. You can assume that we will only use valid data sequencesconc_signalandflow_signalfor testing. You can assume that these variables are Python lists whose entries are strictly positive numbers. You can assume that, for a given test case, these data sequences have the same length.4Implementation requirementsYou need to implement the following six functions. These six functions work together to implement the the fault detection algorithm.The requirement is that you implement each function in a separate file.This is so that we can test them independently, see Section6on testing. We have provided template files, see Section5on Getting Started.In order to facilitate testing, you need to make sure that within each submitted file, you only have the code required for that function. Donotinclude test code in your submitted file.defcalc_log_prob_ratio(measurement,conc_range,conc_var):This function computes the log-prob ratio for one concentration measurement as described in Section3.1.Note in the inputmeasurementis referring to one concentration measurement.This function should return one output which is the value of the log-prob ratio calculated.You can test this function using the filetest_calc_log_prob_ratio.pydefcalc_signal_log_prob_ratio(conc_signal,conc_range,conc_var):This function computes the log-prob ratio forconc_signalas described in Section3.2.This function should return one output which is a list of log-prob ratios.You can test this function using the filetest_calc_signal_log_prob_ratio.pyThis function requires the functioncalc_log_prob_ratio(). An import line has been included in the template file for you. Please do not change it.defcusum(conc_lpr):This function computes the CUSUM forconc_lpras described in Section3.3.This function should return one output which is a Python list.You can test this function using the filetest_cusum.pydefdetect_fault_in_conc(conc_cusum,conc_cusum_limit):This function determines whetherconc_cusumindicates that there is a fault. The procedure has been described in Section3.4.This function should returntwo (2)outputs:The first output is the time at which the fault inconc_cusumis detected.The second output is number of entries inconc_cusumthat are at or aboveconc_cusum_limitNote that the first input is either a non-negative integer ormath.inf.You can test this function using the filetest_detect_fault_in_conc.pydefclassify_fault(conc_signal,conc_range,conc_var,conc_cusum_limit,flow_signal,flow_range,flow_control_window):This function should return one output which should be a python string. There are three possible outputs for this function.Ifconc_signaldoes not indicate a fault, the function should return the string’nofaults’. Note that ifconc_signaldoes not indicate a fault, you do not need to check whether there is a fault inflow_signal.If there is fault inconc_signalbut not inflow_signal, the returned string should be’concfaultonly’If faults are found in bothconc_signalandflow_signal, the returned string should be’flowandconcfaults’The procedure for determining the fault type has been described in Section3.5.You can test this function using the filetest_classify_fault.pyThis function requires the functionscalc_signal_log_prob_ratio(),cusum(),detect_fault_in_conc(). Three import lines have been included in the template file for you. Please do not change them.Note that this function will only require one of the two values returned by the functiondetect_fault_in_conc(). You may want to use the method described in Section4.1to handle this.defdetect_fault_main(conc_signal,conc_range,conc_var,conc_cusum_limit,flow_signal,flow_range,flow_control_window):The expected steps within the functiondetect_fault_main()are:The function should first check whether all algorithmic parameters are valid. If any algorithmic parameter is invalid, the function should return the string’invalidparameters’. It should not proceed to execute the next step. See Section3.6on validity checks for the requirements on the algorithmic parameters.If all algorithmic parameters are valid, then the function should proceed to classify the fault type and return a string indicating the fault type.The function should return one output which is a string. The four possible outputs are:’invalidparameters’,’nofaults’,’concfaultonly’, and’flowandconcfaults’.This function can be tested by the following test files:test_detect_fault_main_0.py,test_detect_fault_main_1.pyandtest_detect_fault_main_2.py.The test filetest_detect_fault_main_0.pyis based on thesample code.The tests intest_detect_fault_main_1.pyhave valid parameters. The signals in these test cases are a lot longer than the signals in other tests. Test case 0 in the file correspond to Figures 1a and 1c. Test case 1 in the file correspond to Figures 1b and 1d.The test filetest_detect_fault_main_2.pycontains a number of test cases where the algorithmic parameters are invalid. However, we havenotincluded all the possibilities and you are asked to ensure that you code checks for all the requirements given in Section3.6.This function requires the functionclassify_fault(). An import line has been included in the template file for you. Please do not change it.4.1An implementation noteLet us say the functionfoo()returns two output values. You know that you can assign these output values to two variables using the syntax:a,b=foo()Let us say that you only need the variableabut not the variableb, there is no point in creating the variableb. You can use the following syntax:a,_=foo()so that only the variableais created.5Getting StartedDownload the zip fileassign1_prelim.zipand unzip it. This will create the directory (folder) named ‘assign1_prelim’.Rename/move the directory (folder) you just created named ‘assign1_prelim’ to ‘assign1’. The name is different to avoid possibly overwriting your work if you were to download the ‘assign1_prelim.zip’ file again later.The zip file that we have provided contains 6 template files, 8 test files and 9 data files. We ask you to first browse through all the files provided including the test files. Note that the 9 data files are used by the test filetest_detect_fault_main_1.pywhere you will be using longerconc_signalandflow_signalfor testing. So, instead of cluttering the test file with a large trunk of numbers, we have put these numbers into files.(Incremental development) Do not try to implement too much at once, just one function at a time and test that it is working before moving on.Start implementing the first function, properly test it using the given testing file, and once you are happy, move on to the the second function, and so on.Please do not useprintorinputstatements. We will not be able to assess your program properly if you do. Remember, all the required values are part of the parameters, and your function needs to return the required answer.6TestingTest your functions thoroughly before submission.You can use the provided test programs (files liketest_cusum.pyetc.) to test your functions. Please note that each file covers a limited number of test cases. We have purposely not included all the cases because we want you to think about how you should be testing your code. You are welcome to use the forum to discuss additional tests that you should use to test your code.We will test each of your files independently. Let us give you an example. Let us assume we are testing three files:prog_a.py,prog_b.pyandprog_c.py. These files contain one function each and they are:prog_a(),prog_b()andprog_c(). Let us sayprog_b()callsprog_a(); andprog_c()calls bothprog_b()andprog_a(). We will test your files as follows:We will first test yourprog_a().When we test yourprog_b(), we will test yourprog_b()together with our working version ofprog_a(). In this way, if yourprog_a()does not work for some reason, there is a chance that yourprog_b()may work and you may still receive marks forprog_b().When we test yourprog_c(), we will test yourprog_c()together with our working version ofprog_a()andprog_b().7SubmissionYou need to submit the following six files. Do not submit any other files. For example, you do not need to submit your modified test files. To submit this assignment, go to the Assignment 1 page and click theMake Submissiontab.calc_log_prob_ratio.pycalc_signal_log_prob_ratio.pycusum.pydetect_fault_in_conc.pyclassify_fault.pydetect_fault_main.py,8Assessment CriteriaWe will test your program thoroughly and objectively. This assignment will be marked out of 27 where 21 marks are for correctness and 6 marks are for style.8.1CorrectnessThe 21 marks for correctness are awarded according to these criteria. Criteria Nominal marks Functioncalc_log_prob_ratio 2 Functioncalc_signal_log_prob_ratio 3 Functioncusum 4 Functiondetect_fault_in_conc 4 Functionclassify_fault 4 Functiondetect_fault_mainCase 1: There are invalid algorithmic parameters. 3 Functiondetect_fault_mainCase 2: All algorithmic parameters are valid. 1 8.2StyleSix (6) marks are awarded by your tutor for style and complexity of your solution. The style assessment includes the following, in no particular order:Use of meaningful variable names where applicableUse of sensible comments to explain what you are doingUse of docstring for documentation to identify purpose, author, date, data dictionary, parameters, return value(s) and program description at the top of the file.9Assignment OriginalityYou are reminded that work submitted for assessment must be your own. Sophisticated software is used to identify submissions that are unreasonably similar, and marks will be reduced or removed in such cases.10Further InformationWe will run Help Sessions for this assignment during Weeks 4-7. These consultations allow you to get one-on-one help on a first-come-first-serve basis. The timetable for the Help Sessions can be found on the course website.Use the forum to ask general questions about the assignment, but take specific ones to Help Sessions.Keep an eye on the course webpage notice board for updates and responses.11Assignment conditionsJoint work is not permitted on this assignment.This is an individual assignment. The work you submit must be entirely your own work: submission of work even partly written by any other person is not permitted.Do not request help from anyone other than the teaching staff of ENGG1811 – for example, in the course forum, or in help sessions.Do not post your assignment code to the course forum.Assignment submissions are routinely examined both automatically and manually for work written by others.The use of code-synthesis tools, such as GitHub Copilot, is not permitted on this assignment.Rationale: this assignment is designed to develop your understanding of basic concepts. Using synthesis tools will stop you learning these fundamental concepts, which will significantly impact your ability to complete future courses.Sharing, publishing, or distributing your assignment work is not permitted.Do not provide or show your assignment work to any other person, other than the teaching staff of ENGG1811. For example, do not message your work to friends.Do not publish your assignment code via the Internet. For example, do not place your assignment in a public GitHub repository.Sharing, publishing, or distributing your assignment work after the completion of ENGG1811 is not permitted. For example, do not place your assignment in a public GitHub repository after this offering of ENGG1811 is over.Rationale: ENGG1811 may reuse assignment themes covering similar concepts and content. If students in future terms find your assignment work and submit part or all of it as their own work, you may become involved in an academic integrity investigation.Violation of any of the above conditions may result in an academic integrity investigation, with possible penalties up to and including a mark of 0 in ENGG1811, and exclusion from future studies at UNSW. For more information, read the UNSW Student Code, or contact the course account.Computer ScienceEngineering & TechnologyPython ProgrammingENGG 1811Share Question

Order your essay today and save 20% with the discount code ESSAYHELP