CSE 482 BigData Analysis Homework 2 2 Multiple Choices (15pts) For each problem, there is only one correct answer. 1. Which of the following algorithms we learned in class is race-free? A. Parallel BFS B. Parallel Knuth Shuffle C. Parallel Tree union D. Parallel Bellman-Ford 2. Which of the following statement about parallel SSSP is true? A. Parallel Bellman-Ford is always faster than Dijkstra in practice because it has better parallelism. B. We can combine parallel Bellman-Ford and Dijkstra to get a parallel SSSP algorithm that is work-efficient with polylogarithmic span. C. Parallel ∆-stepping has a better span (asymptotically lower) than parallel Bellman-Ford. D. Parallel Bellman-Ford can have reasonably good performance on low-diameter graphs. However, it can be expensive on large-diameter graphs. 3. In the quicksort, if we choose each pivot uniformly at random, then, each element is involved in O(log n) comparisons with high probability. This statement is . A. True B. False 4. We learned the reachability-based SCC algorithm in class. Given a directed graph below, assume we first run reachability searches on both the blue and orange vertices in parallel. After that, we will remove some edges based on the reachability search results. How many edges will we remove? A. 5 B. 6 C. 7 D. 8 E. 9 F. 10 5. Yihan wanted to design an algorithm to atomically increment a shared variable s by 1, and return the new value set by this atomic increment. For example, consider the current value of s is 5, and two invocations of atomic inc are called. Then they should add 1 to s, respectively, so the value of s will be 7 after they both finish. Also, one of these to invocations should return 6 (the one linearized earlier), and the other should return 7 (the one linearized later). She wrote the following pseudocode. CAS” means compare and swap, which is defined as we mentioned in class. shared variable int s = 0; int atomic_inc() { int ld = s; while (!CAS(&s, old, old+1)) { old = s; } return s; } Does this algorithm above work as expected? A. It does not work as expected – it is not atomic. B. It does not work as expected – It does not always add 1 to s. C. It does not work as expected – the return value does not match the specification (i.e., not the desired return value). D. It does not work as expected – there can be ABA problem. E. It works as expected.
COMP 1406A Assignment 3: Introduction to GUI’s The Commonwealth Games are a series of sporting events held every 4 years, which host competitors from a body of 72 member nations and territories, including Australia. The 2022 Commonwealth games have just ended, and the organisers are looking ahead towards the 2026 Games, which are to be held here in Victoria. Note: Some simplifications have been made compared to the real games, in particular we do not carefully consider round-based sports (e.g. basketball), do not consider qualifier data, etc. If at any point your understanding of The Games and this specification contradict, consider this specification as authoritative. Currently, 72 member nations (countries) compete in The Games. These nations are divided into 6 fixed regions: Africa, Americas, Caribbean, Europe, Asia, and Oceania. For each member nation we should store their name, and a link to an image of their flag. Sports, Events, and Competitors events may be added, or old ones removed, from future games. Events may be either ‘time-based’ or ‘score based’. Additionally, all events have a set of rules (which can be 10,000+ chars long) which we should store. Note that each country might be represented by several competitors in the same event. This is true for both group and individual events. For example, out of 10 swimmers in the ‘100m men’s breast-stroke’ (which is an individual event), there might be 2x Australian athletes who are competing separately and are thus separate competitors. As part of each event, we may store up to 1 photo per competitor that was taken during the event. These photos will have been uploaded online, and so we only store the link. For instance, for the ‘100m men’s breaststroke’ (an individual event), we might store a link for up to one photo that was taken during the event of each of the individual swimmers. For a group event like the ‘1000m men’s freestyle. relay’, where the ‘competitor’ is in fact 4 athletes, we still only store up to one photo per competitor/group of 4. For each competitor, we need to record their ‘performance’ in the event. Each event can be one of the following types depending on what performance means in that context: Score based events have a final score that the competitor earned (like diving, archery). They also have a field for ‘disqualification’ set to ‘true’ if the competitor was disqualified for any reason. Score-based events may also have been scored by a panel of judges (e.g. in diving), in which case we need to record the names of all judges on the panel for that event. The same judges will judge all competitors in the one instance of the event (e.g. the same judges assessed all of the competitors in the ‘2022 men’s springboard diving’) For all event types, we should also record the date and time that each event occurred, and the number of spectators present. For some events the average and maximum outside temperature recorded during that event must be recorded. Venues Some venues might be ‘inside’ of other venues. For example, a swimming event might be conducted in the ‘Queen Elizabeth Swimming Pool’, but this pool is a part of a larger venue called the ‘London Aquatics Center’. Business Requirements Which series of games did competitor ‘Emma McKeon’ participate in? List names of the events that belong to a sport ‘swimming’ but have never been held at The Games. List the names of all events that were held in the 1974 games. Find the youngest Badminton player that has ever represented Bermuda. Which athlete had the lowest time for the 2022 games’ Women’s Wheelchair Race event (and thus won the gold medal)?
MAST90138 Assignment 3 Instructions: • The assignment contains 3 problems worth a total of 100 points which will count towards 15% of the final mark for the course. If you LATEXand knitr your assignment in a nice way, you will potentially get up to a maximum of 0.75% towards the final mark for the course as extra credits. • Use tables, graphs and concise text explanations to support your answers. Unclear answers may not be marked at your own cost. All tables and graphs must be clearly commented and identified. • No late submission is allowed. Data: In the assignment you will analyze some rainfall data. The dataset is available in .txt format on the LMS website. To load the data into R you can use the function read.table() or any command of your choice. You may need to manipulate the data format (data frames or matrices) depending on the task. The data are separated in a training set and a test set. The training set contain p = 365 explanatory variables X1, . . . , Xp and one class membership (G = 0 or 1) for ntrain = 150 individuals. The test set contains p = 365 explanatory variabless X1, . . . , Xp and one class membership (G = 0 or 1) for ntest = 41 individuals. In these data, for each individual, X1, . . . , Xp correspond to the amount of rainfall at each of the p = 365 days in a year. Each individual in this case is a place in Australia coming either from the North (G = 0) or from the South (G = 1) of the country. Thus, the two classes (North and South) are coded by 0 and 1. You will use the training data to fit your models or train classifiers. Once you have fitted your model or trained your classifiers with the training data, you will need to check how well the fitted models/trained classifiers work on the test data. The test and training data are all placed in different text files: XGtrainRain.txt, which contains the training X data (values of the p explanatory X-variables) for ntrain = 150 indi- viduals as well as their class (0 or 1) label, and XGtestRain.txt, which contains the test X data (values of the p explanatory X-variables) for ntest = 41 as well as their class (0 or 1) label. The test class membership is provided to you ONLY TO COMPUTE THE ERROR OF CLASSIFICATION of your classifier. Please include all the necessary R code to answer the questions, but not super- fluous R code that are not relevant. Marks may be taken off for R code that is poorly presented. You may take classification error/test error to be the proportion/percentage out of the 41 test samples that are misclassified. Problem 1 [60 marks]: In this problem you will train quadratic discriminant (QDA) and the logistic regression classifiers to predict the class labels (0 or 1) in the test set. (a) Use standard functions in R to train the QDA classifier and the logistic classifier, with all the p predictors in the training set. What happened? And why did it happen? Do you recommend using these two classifiers on the test set? (Hint: For the logistic classifier, use the summary function to take a look at the trained model object) [10] (b) Use prcomp and the plsr (package pls) functions to obtain, respectively, the PCA and PLS (partial least square) components of the explanatory variables, in the training set. Here, when considering the covariance maximization problem of PLS, we maximise the covariance between X = (X1, . . . , Xp) T and Y = 1{G = 1}, the indicator variable that an individual belongs to group 1. For each case, you will need to use the “projection matrix” (i.e., Γ for PCA and Φ for PLS discussed in class) reported by the function to re-compute the components “manually” to check that you understand how the components are ob- tained. [10] (c) Train a QDA classifier with the PLS components, and another one with the PCA compo- nents. In each case, pick the number of components to use based on leave-one-out cross validation (LOOCV); consider up to using 50 components. Plot the leave-one-out CV error against the number of components considered. Report the final chosen number of components. (Refer to the lab in Week 7 to get some ideas) Do the same for the logistic classifier. (If you want to pick your number of components based on methods other than LOOCV, please explain your choice in a clear and concise manner) [20] (d) For each of the QDA and logistic classifiers, which version (PCA or PLS) do you prefer? Why? (Answer this question without any knowledge of the test-set results in the next problem) [5] (e) Apply your trained classifiers in (c) to the test set, and report the resulting classification error (test error). Be careful about how you should center the data in your test set to produce your prediction. The lab in Week 7 may give you some ideas again. [15] Problem 2 [30 marks]: In this problem you will train random forest (RF) classifiers to predict the class labels (0 or 1) in the test set. (a) Using the randomForest package in R, construct a random forest classifier using all p predictor variables in the training set. When training the classifier, use the default value of m (the number of random candidate variables for each split), but justify your choice for the number of trees B using the out-of-bag (OOB) classification error. Plot a graph showing the OOB error against the number of trees used. [15] (b) Show two graphs that illustrate the importance of the Xj variables, for both decrease in OOB prediction accuracy and decrease in node impurities measured by Gini index. Is there an explanation of why those particular Xj ’s are the most important for classification in this rainfall example? [5] (c) Apply the resulting trained classifier to the test data Xtest, and compute the resulting classification error. Try training your RF multiple times. Do you always get the same classification error? If yes, why? If not, why and what can you do to make the forest more stable and why? [10] Problem 3 [10 marks]: Compare the percentage of misclassification for each of the five classifiers (Logistic + PCA, Logistic + PLS, QDA + PCA, QDA + PLS, RF) considered in the previous problems. Identify the classifiers that worked the best, those which worked the worst, and comment those results. Provide an explanation of the poorer/better performance of some of the classifiers.
COMP528-JAN21 DEPARTMENT: Computer Science FIRST SEMESTER EXAMINATIONS 2020/21 Multi-Core and Multi-Processor Programming EXPECTED TIME: 3 hours INSTRUCTIONS TO CANDIDATES • The exam consists of FOUR questions. You must answer ALL questions • The expected writing time for the exam is 3 hours • You may write your answers using a word processor (please export the document to PDF before submitting), or you may write your answers by hand and either scan them, or take photos of them. If you write answers by hand, then both the handwriting and the scanned copy must be legible in order to be accepted. • The exam will be released at 9am on Friday 30 April 2021. You will then have 24 hours in which to prepare your answers, and the final deadline for submissions is 9am on Saturday 01 May 2021. All times and dates are BST (GMT +1). • All answers should be combined into a single PDF that should be uploaded to the relevant CANVAS area for the COMP528-JAN21 course 2020-2021. • Late submissions will not be accepted. PAPER CODE COMP528-JAN21 page 1 of 5 Continued Question 1 1. What are the reasons for the fast development and wide use of multi-core processors? What hardware approaches have been developed to overcome the limitations imposed by a single core processor? [7 marks] 2. Consider two small HPC clusters C1 and C2 where • C1 is composed of 4 nodes with 8 processors each, and each processor has 15 cores running at a fixed frequency of 2.5 GHz; and • C2 is composed of 2 nodes with 12 processors each, and each processor has 20 cores running at a fixed frequency of 2 GHz. How you would evaluate their peak performances? Assuming 2 floating point operation per CPU core cycle, which of the two small clusters has a better peak performance? [5 marks] 3. In your own words, explain and comment on Amdahl’s Law and Gustafson’s observation. For the former (i.e., Amdahl’s law), provide its equation, and define each used variable. Explain what is meant by “speed up” and express the theoretical maximum speed-up as a function of the serial proportion of a code. [8 marks] 4. A serial code takes 300 minutes to run. Timing different parts of the code shows that 294 of 300 minutes are spent on a parallelisable portion of the code. Using Amdahl’s Law, how long would it take to run a parallel version of the code on 3 cores? Assuming Amdahl’s Law is correct, what would be the parallel efficiency on 3 cores? And what is the maximum speed- up possible for this code on this architecture? [5 marks] Question 2 1. Describe the MPI Scatter and MPI Gather collectives, explaining what buffers are required to be allocated and initialised on which process. NOTE: the description should discuss both the high-level idea behind them, and the more practical aspects in an implementation. [8 marks] 2. Explain what a deadlock is, provide an example of an MPI program which might result is a deadlock, and provide a possible solution to your example (HINT: you do not have to provide PAPER CODE COMP528-JAN21 page 2 of 5 Continued the whole code, but just the relevant lines causing the deadlock and making clear which pro- cesses are executing them) [8 marks] 3. Explain what affects the time to send messages in an HPC cluster, and how a reduction pat- tern can have a positive impact on the total wall clock time. [5 marks] 4. Explain what is wrong in the following C code, and propose a possible solution. You can assume that each process has the integer array x initialised, NUM is an integer provided as input, and the number of processes is less than NUM. MPI_comm_size(MPI_COMM_WORLD, &size); MPI_comm_rank(MPI_COMM_WORLD, &myRank); int stepSize = NUM/size; int start = myRank*stepSize; int finish = start + stepSize; int global_sum=0; int local_sum = 0; for(i=start; i 0; i--) { res = res * (b[i]-a[i]); } PAPER CODE COMP528-JAN21 page 3 of 5 Continued Explain how you would parallelise this using OpenMP, giving the full and exact code needed to appropriately parallelise this loop, bearing in mind good programming practices [5 marks] 2. Explain, via the use of an example, what is wrong in the following code, and how you would fix it. You can assume that all variables have been initialised before the provided code (you might want to state what their values are for your example). #pragma omp parallel default(none) shared(NUM,A,B,x,y) private(i,j,k) { #pragma omp for nowait for(i=0;i
MAST90083: Computational Statistics and Data Science Assignment 2 Weight: 15% Some details about Question 1 and 2 For both questions, use library ”HRW” that contains the ”WarsawApts” dataset. The sym- bol n represents length of the variables for the given dataset (WarsawApts), and a bold 1 represents vector of ones. The mean squared error (MSE) is a normalized version of residual sum of squares (RSS) and is given as MSE=RSS/n. Notations Throughout this assignment, small letter represents a value, small letter attached with a subscript. represents an entry of a vector, small bold letter represents a vector, and capital bold letter represents a matrix. Question 1: Splines The aim of this question is to learn how to code linear spline basis in order to approximate a non-linear dataset via penalized spline regression (PSR). For PSR, a Cholesky decomposition (CD) and singular value decomposition (SVD) approach can be used, but for this task the regression based approach will be adopted, and any solution based on CD and SVD will not be accepted. All the questions here are connected and must be attempted sequentially. 1. Store construction.date variable from WarsawApts in x and areaPerMzloty in y. Generate 20 different location of knots and store them in vector k (ki corresponds to i-th value of k, i = 1, ..., 20) using quantile (ref: Tutorial 5 Question 2) function. To accomplish this task, you need a numeric vector of probabilities of length 22 that can be generated using seq(0,1,length=22), however extreme values of 0 and 1 should be excluded from this function in order to match the knots and the samples in x (x- intercepts). 2. Using these knot locations now generate a Z matrix containing 20 linear spline basis functions constructed using (x − ki)+. Also plot this matrix by limiting the range of y-axis between -1 and 2 as shown in Figure 1a. 3. Using the vector of ones, x, and Z, construct a C matrix of size n × 22 (ref: lecture slide 18 of the spline regression). Also, generate a D matrix of size 22× 22 consisting of ones on the diagonal entries and zeros elsewhere except the first two entries (ref: lecture slide 30 of the spline regression). Then, 100 values of tuning parameter (λ) Figure 1: Spline basis and fitted curve selected from 0 to 50 as seq(0,50,length=100) are used to estimate the fitted curves using penalized spline regression. 4. Now, compute the RSS errors, degrees of freedom, and generalized cross validation (GCV) associated with 100 tuning parameters. 5. For λ corresponding to minimum GCV, overlay the true plot with a fit of y as shown in Figure 1b. As you can see from the plot that with 20 linear spline basis the fitted curve looks a bit too linear and might not be a good fit. Lets increase the number of basis to 60 and obtain Figure 1c (similar to 1a) and 1d (similar to 1b). Were the results improved by increasing the number of basis? Compute the MSE to justify the improvement/deterioration. Question 2: Non-parametric Regression The aim of this question is to learn how to code kernel regression using different kernels. Here, question 2.1 and 2.2 are connected and must be attempted sequentially, whereas question 2.3, 2.4, and 2.5 are connected and must be attempted sequentially 1. Using 6 values of k selected from 3 to 23, write an R code for k-nearest-neighbor (NN) averaging. You can do this by firstly estimating the absolute difference between the current sample xi and the vector x as d = |xi1−x|, and secondly using d to find those indices that correspond to its k smallest values. These indices are the indices of the k NNs to the current xi. Use these indices to select the corresponding entries from the data vector y and take their mean as your i-th estimate yˆi. 2. For each case of k, generate a figure illustrating a fitted vector yˆ on the true vector y (6 sub-figures in total, must be plotted in a single figure using 3×2 subplots), and compute the MSE. For which case did you find the minimum MSE? In terms of MSE, what can be said regarding the fitting comparison between k-NN and linear spline basis? 3. Using slide 13 of the kernel regression lecture, write a single function to accommodate all 6 kernels. This function must be capable of returning 6 values, where each value corresponds to the output value of a single kernel. Figure 2: Cameraman picture and its density plot 4. Keeping the bandwidth fixed at h = 2 and using formula fˆ(xi) = ∑n j=1Kh(xi,xj)yj∑n j=1Kh(xi,xj) , (where {j = 1, ..., n}) code 6 kernel regression based fits for y by using 6 kernels from the previous question ( To elaborate, for each sample xi and xj, six different kernel values must be obtained in a single go to eventually generate six estimated values of the i-th fit fˆ(xi), where fˆ(xi) is a vector and has 6 entries). 5. For each of the six kernels, generate a figure illustrating a fitted vector fˆ(x) on the true vector y (6 sub-figures in total, must be plotted in a single figure using 3× 2 subplots). Also, for each kernel estimate the MSE. For which kernel, the MSE is found to be minimum? Question 3: Expectation-Maximization For this question, you are not allowed to use R’s built in function for the expectation- maximization (EM) algorithm. You have already learnt how to code EM algorithm for a gaussian mixture consisting of two probability density functions (pdfs), where both had same standard deviation. Here, you will extend that algorithm to three cases, where all three having different standard deviations. 1. In order to load relevant libraries and the provided image that is needed for the subse- quent questions, use the following code l i b r a r y (” p l o t . matrix ”) l i b r a r y (”png”) l i b r a r y (” f i e l d s ”) I
PMA3014 Set Theory 2021/22 Sheet 3—first marked homework Each question is worth 5 marks. Exercise 11. (i) Let S be a set of sets and let X be another set. Show that(⋃ S )×X =⋃{S ×X | S ∈ S}. (ii) For arbitrary sets A, B and C prove the identity A ∩ (B△C) = (A ∩B)△(A ∩ C), where △ denotes the symmetric difference. Exercise 12. Let X be a non-empty set. A filter on X is a non-empty setF of subsets of X which satisfies the following properties: (i) ∅ /∈ F; (ii) for all A,B ∈ F we have A ∩B ∈ F; (iii) for all A ∈ F and all Y ⊆ X we have: A ⊆ Y =⇒ Y ∈ F. Let X = N, the set of natural numbers. Let n≤ = {m ∈ N | n ≤ m} for each n ∈ N be the set of all natural numbers which are greater than or equal to n ∈ N. Let F = { Y ∈ P(X) | ∃n ∈ N : n≤ ⊆ Y }. Show that F is a filter on N. Exercise 13. In this question X, Y and Z denote non-empty sets. Suppose that f : Z → Y is a function from Z to Y . Define φ : XY −→ XZ , φ(g) = g ◦ f (g ∈ XY ). (i) Show that φ is a well-defined function. (ii) Suppose that f is surjective. Prove that φ is injective. (iii) Suppose that φ is injective. Under what conditions does it follow that f is surjec- tive?
MATH 60603A Statistical Learning Assignment #1 Fall 2021 Credit risk game • Individual assignment. • Upload your decision(s) before 8:30AM (EDT) on October 15th, 2021. • You are required to provide your R code (upload it on ZoneCours). • This round of business simulation is worth 10% of your final grade. Context: In order to minimize loss and maximize profits from lending, banks require careful assessment of their borrowers. This has led to credit risk computation becoming a commonly used application of statistics and data science. You are working with a large bank to help them optimize their profits from financing individuals who apply for a loan. The bank has provided you with the records and results of lending money to some customers. You will be using this information and R to decide how many and which individuals to lend money to. Your objective is to maximize the banks’ profits obtained from these loans. Data: A zip file containing the data is available on ZoneCours. The file CreditGame_TRAIN.csv contains records of previous loans provided by the bank. They include features about the customers and information about their default status as well as the magnitude of profit or loss incurred for each loan. The file CreditGame_Applications.csv contains information about current loan applications. You must decide who on this list get their loan approved. How to play the game: You need to prepare a one column CSV file with the list of IDs of the customers whose loan application you accept from CreditGame_Applications.csv. Upload this decision on https://dsgame.hec.ca/play (consult ZoneCours for instructions on setting up your access, and joining the game). When you upload a decision, you will get immediate feedback on the profit that the loans have generated for the bank after 24 months. The platform. allows for multiple uploads per person, up to 99, which means that you may try many different solutions. On the upload platform, you will see not only your results but also those of the whole group. While the game is being played, you will see the “interim leaderboard.” Before the deadline of the assignment, you must select your final decision as one of your uploads. When the game ends, the “real-life leaderboard” will be unveiled and will prevail for the final ranking. The “real-life leaderboard” plays the role of a test set: it is a holdout sample that is kept until the end to measure the performance of the final answers of everybody. Method: Your objective is based on a business outcome: profit. The process of prediction will involve cleaning, analyzing, modeling, and getting results. We do not give further instructions on the methods used; you are on your own for that. There is no single good answer and multiple strategies that can support the business problem reasonably well. We expect each student to come up with their own approach. Disclaimer: There are additional nuances for credit risk assessment in a real-life setting. Banks need to abide by the Basel accords and must comply with some rules to assess their credit risk. Credit risk typically implies a need to interpret the results of a model, and some standards in methodology apply. Although this business simulation is very realistic, both in terms of context and data, it does not depict those field-specific particularities. Evaluation: Look for the baseline on the upload platform. It corresponds to the profit made when all customer applications are approved. To get a passing grade, you must do better than that! The evaluation will be based on the results at the end of the game. Each student must select one of their uploads as their final answer, and that answer will prevail. You get: • 0% - if you are below the baseline on the interim leaderboard; at least 50% if your profit is above. • 100% - Top 10% of students on the “real-life leaderboard.” • The rest of the marks will be linearly interpolated using the following equation with values from the “real-life leaderboard”: 50{1 + ( − )/( − )} where is your profit, the baseline, and the profit of the last student with 100% from the previous criterion. You must upload your R code on ZoneCours. It will not be reviewed systematically, only if some precisions are needed. Your grades could be reduced if irregularities are found in the R code, or if there is evidence you have not used R. Variables: Variable name Description ID_TRAIN Unique borrower ID TYP_FIN Type of funding requested (Car, Mortgage, or Credit) NB_EMPT Number of borrowers (borrower variables are only for the principal borrower) R_ATD Total Debt Amortization (TDA) Ratio, i.e., monthly financial commitments over monthly income PRT_VAL The requested loan amount over the value of the goods DUREE Requested loan duration AGE_D Age of the borrower REV_BT Gross Income REV_NET Net Income TYP_RES Residence Type – P: Owner, L: Tenant, A: Others ST_EMPL Employment Status – R: Regular, P: Part-Time, T: Self Employed MNT_EPAR Savings Value NB_ER_6MS Number of transactions refused due to insufficient funds in the last 6 months NB_ER_12MS Number of transactions refused due to insufficient funds in the last 12 months NB_DEC_12MS Number of overdrafts in the last 12 months NB_OPER Total number of transactions in record NB_SATI Total number of satisfactory transactions in record (No payment delay) NB_COUR Number of current transactions NB_INTR_1M Number of inquiries in the last month NB_INTR_12M Number of inquiries in the last 12 months PIR_DEL Worst current delinquency NB_DEL_30 Number of 30–59 day delinquency in the last 12 months NB_DEL_60 Number of 60–89 day delinquency in the last 12 months NB_DEL_90 Number of 90+ day delinquency in the last 12 months MNT_PASS Value of financial Liabilities MNT_ACT Value of financial Assets MNT_AUT_REN Total authorized amount of revolving credit MNT_UTIL_REN Total used amount of revolving credit MNT_DEMANDE Loan amount requested DEFAULT Default is considered when payment is 90 days or more late within 24 months 1: Default, 0: Did not default PROFIT_LOSS Profit made or loss incurred with this loan after two years
CA5 for EE5110/EE6110 Selected Topics on Automation and Control Background Manual warehouse stock counting used to be a tiring, boring and (sometimes) dangerous job. A small-size unmanned aerial vehicle (UAV) equipped with sensors and smart software algorithms can be a very good solution to automate such a process. Figure 1: Autonomous warehouse stock counting by UAV Work Requirements: Write a report to survey existing state-of-the-art hardware products and software methods and propose your own UAV system that an be used for such an autonomous stock counting task by considering the following mission requirements: - Maximum take-off weight of the UAV: Less than 3 kg - Autonomously fly and conduct stock counting for both left and right sides racks of a warehouse aisle with the following specifications and the mission must be finished within one take-off flight without battery change: o Aisle length: 80 m o Aisle width: 2.5 m o Aisle height: 8 m (5 layers of cargos with equally distributed layer heights) o Cargo information is encoded within a barcode facing the aisle You should mainly focus on the following 3 topics for the considerations of the system design: 1. Platform. choice and component selection 2. Autonomous flight control 3. GPS-less navigation Report Format: - Size: A4 portrait - Font: Times New Roman 11.5 - Not more than 20 pages - Name your report as A1234567.pdf (where A1234567 is your matric number) Submission: Upload to LumiNUS system under Segment D submission folder before 15 November 2021, 12 noon. *Note that plagiarism and copying are serious offences and students caught doing so will be reported to university. Late reports will also be penalized (10% per day).
MAST20005/MAST90058: Assignment 3 Due date: 11am, Thursday 14 October 2021 Instructions: See the LMS for the full instructions, including the submission policy and how to submit your assignment. Remember to submit early and often: multiple submission are allowed, we will only mark your final one. Late submissions will receive zero marks. Problems: 1. (R) We have the following random sample of size 17 on paired variables (X, Y ). We wish to test whether X and Y differ in location. x 26.1 26.6 27.4 27.5 27.8 28.1 28.4 29.5 29.8 30.4 y 27.4 28.1 22.9 31.3 16.3 50.1 20.0 24.6 23.3 19.3 x 30.4 31.2 31.5 32.9 33.6 34.1 35.9 y 24.4 24.4 29.5 27.6 21.7 25.4 39.4 (a) Using a significance level of 5%, perform. an appropriate version of each of the fol- lowing tests. In each case, state the null and alternative hypothesis. i. Sign test. ii. Wilcoxon test. iii. T-test. (b) How do the conclusions of these tests compare with each other? Explain your answer and what conclusion you would form. overall. (c) Estimate, via simulation, the power of each of these three tests if the true distribu- tions are defined by X ∼ N(30, 32) and Y −X ∼ N(3, 52). 2. (R) A class of 80 biology students is carrying out a project. Each student is required to run 30 experiments to see how often the seed of a certain plant will germinate. The follow- ing table summarises the results from all of the students, with each student contributing a single observation (a number of germinations between 0 and 30): Germinations 3 4 5 6 7 8 9 10 11 12 13 17 Count 1 2 2 4 10 16 9 11 13 4 7 1 ( ∑ = 80) (a) Assuming that these follow a Bi(30, p) distribution, estimate p. (b) Design a set of classes suitable for carrying out a goodness-of-fit test for a binomial distribution. You will need to merge some of the classes in each tail until you have expected counts of at least 5 in each one. (c) Using your new version of the table, carry out the test using a 5% significance level and state your conclusion. 3. Let X have a Pareto distribution with pdf, f(x) = θx−(θ+1), x > 1, θ > 0. Suppose we have a random sample of n observations on X. (a) Find the cdf of the sample minimum, X(1). (b) Find the p quantile, pip, in terms of p and θ. (c) Find the asymptotic variance of the sample median, Mˆ . 4. (R) An experiment was carried out to measure the power output of solar panels mounted at different angles. Four different angles were used for each of 5 different types of panels, with two replicate panels for each combination. The data obtained were: Panel Angle 1 2 3 4 5 0◦ 42.3 42.2 37.6 36.8 45.8 41.4 40.3 35.7 34.9 43.7 10◦ 42.1 42.1 38.4 38.0 45.2 40.2 40.3 36.5 37.1 43.1 20◦ 42.6 42.7 38.6 40.2 46.9 40.8 40.8 36.7 38.3 44.8 30◦ 43.6 43.8 41.9 42.9 45.4 41.5 41.9 39.8 40.8 43.5 (a) Perform. a two-way analysis of variance to examine whether these data suggest that the output is affected by the angle of elevation. State and test appropriate hypotheses at a 5% significance level. You should report the value of the appropriate statistic, the p-value, the assumptions you have made and your conclusions. (b) Is it possible to test for interaction? If yes, then perform. the test and draw an interaction plot. Otherwise, explain why it is not possible.
CST 3130 – Advanced Web Development with Big Data – Coursework 1: Price Comparison Website CST 3130 - Coursework 1: Price Comparison Website 1. Summary Version: 1.0 Individual project Weighting: 50% of overall mark Deadline for project proposal: 16:00 Friday 15th October 2021 (end of Week 3) Deadline for final submission: 16:00 Friday 10th December 2021 (end of Week 11) 2. Key Points • You build a price comparison website that displays products and their prices from several different websites. • The user can search for products on the website. • Shopping functionality and customer registration/login are not required. • Your website provides links that enable users to navigate to the product on the original website. • You can propose a different type of project based on scraped data from multiple websites - for example a property search website. • Website scraping must be done using Java. • You must use a SQL database to store your data. MySQL/MariaDB is recommended. • Several threads should be used to download data. • There are marks for using Spring, Hibernate and Maven. • The back end of the website must be implemented in JavaScript. running on Node.js. No marks are available for functionality that is implemented in other programming languages. • Your application includes a REST API. This can be integrated into your front end (via AJAX). Or it can be a separate web service that enables third parties to access your data. • The front end must be written in HTML, CSS and JavaScript. You cannot write an app. • There are marks available for the quality and quantity of data that you have scraped. • Marks are available for code quality, unit testing and the front end of the website. • The final submission of your project will only receive a mark if your submission includes a video demonstration. 3. What Needs to be Submitted 3.1 Project Proposal (Deadline: 16:00 Friday 15th October 2021) Submit a zip file that contains: 1. Proposal document. This must contain: • Brief description of the proposed website. • Wireframe. sketches of the website or screenshots of early prototype. • List of websites and URLs that will be scraped. • Diagram showing database design. The proposal document must be in Word or PDF format. 2. Database SQL commands: • File containing the SQL commands that are used to create the database. This can be a dump of your implementation of your database design or a text file containing the SQL commands that were used to create the database. Upload the zip file using the link in the Coursework 1 section of the course website. We will use the project proposal to give you feedback about your idea and help you realize it in the time available. You can reuse material from the project proposal in the final project submission. The project proposal is worth 10% of the mark for Coursework 1. 3.2 Final Submission (Deadline: 16:00 Friday 10th December 2021) Submit a zip file that contains: 1. Project report. This must include: • Screenshots showing all of the website’s key functionality. • Description of the website. You should explain the web scraping, the RESTful web service and how the JavaScript. displays the data. • Diagram showing the final database design. • Documentation of the tests. The project report must be in Word or PDF format. 2. Source code. Your source code folder should contain the following files: • Maven build file (pom.xml). • Spring configuration file(s) (beans.xml). Not needed if you are using annotations. • Hibernate configuration file(s). • Java source code for web scraping. • Java source code for unit tests. • Java API documentation. • Node.js JavaScript. source code. • JavaScript. source code for unit tests. • Front end source code for website (JavaScript, HTML, CSS). • Other source files for website, for example. Vue files etc. • Please do not include the node_modules folder in your submission. It is likely to make your submission too large to upload! 3. Database dump: • Dump of the database and data using mysqldump or a similar tool. No marks will be awarded for a copy of the raw database files – your dump must be readable in a text editor. 4. 5-minute video demonstration. Video demonstrations are mandatory for the final submission. I strongly recommend that you watch the talk on recording video demonstrations on the course website. Upload the zip file using the link in the Coursework 1 section of the course website. The final submission is worth 90% of the mark for Coursework 1. 4. Formative Feedback Formative assessments do not directly contribute to the overall module mark but they do provide an important opportunity to receive feedback on your learning. They provide an opportunity to evaluate and reflect on your understanding of what you have learnt. They also help your tutors identify what further support and guidance can be given to improve your grade. We are happy to give you formative feedback about Coursework 1 in the labs and can also give formative feedback about drafts of Coursework 1 that are sent to us more than 1 week prior to the deadlines. 5. Extenuating Circumstances If you have personal problems that interfere with your studies, you can apply for extra time to complete coursework without a mark penalty. You have to provide appropriate documentary evidence. More information here: https://unihub.mdx.ac.uk/your-study/assessment-and-regulations/extenuating- circumstances. You must let the module leader know if you have been granted an extension. 6. Late Submission We are very unlikely to give extensions to coursework and very unlikely to accept excuses. So we strongly recommend that you hand coursework in on time. Contact the module leader before the deadline if you run into problems. Zero marks will be awarded for coursework that is received more than six hours after the deadline. 7. Plagiarism Plagiarism is a serious academic offence. Students that submit identical projects will be reported to the university. If they are found guilty, they will have to resubmit their work, their marks could be capped or they could fail the module. We recognize that there is often a blurry line between copying and collaboration. People work together and help each other to solve problems and apply the solutions to their own projects. We strongly encourage this kind of collaboration. But it is not acceptable for students to collaborate on a project which they submit as individual work. To penalize this, the mark for near-identical projects will be divided between the projects. So suppose a project gets a mark of 60% and near-identical versions are handed in by 3 people. Each person will get 20%, instead of 60%. This only applies to the marks for the parts of the project that are identical. We are not going to police this and make detailed investigations. So if you allow your project to be copied, you will be as liable for plagiarism as the person who submits it as their own work. Both the original and the copy will receive zero or reduced marks. Links to the relevant University regulations and additional support resources can be found here: • Academic Integrity Awareness Course: https://mdx.mrooms.net/mod/lesson/view.php?id=877307. (You will have to log into to MyUniHub and then MyLearning to access the course.) • Section F: Infringement of Assessment Regulations/Academic Misconduct: https://www.mdx.ac.uk/about- us/policies/university-regulations. • Referencing & Plagiarism: Suspected of plagiarism?: http://libguides.mdx.ac.uk/c.php?g=322119&p=2155601. • Referencing and avoiding plagiarism: http://unihub.mdx.ac.uk/your-study/learning-enhancement- team/online-resources/referencing-and-avoiding-plagiarism. The MDXSU Advice Service offers free and independent support face-to-face in making an appeal, complaint or responding to any allegations of academic or non-academic misconduct. https://www.mdxsu.com/advice.
FIT2090 Business Information Systems and Processes Assignment 2 (20%) Submission Deadline: 18 Oct 2021, 5:00 PM (AEDT) Group Assignment (two students from the same tutorial) Learning Objectives Successful completion of this assignment will lead to extend your knowledge and skills in the business information system and processes, including: ● Understanding of BPI and BPR. ● Selecting appropriate technologies to address the given problem. ● Investigating emerging and innovative BIS solutions. ● Critical analysis of a business process. ● Documenting and justifying recommendations for improving business processes. Group Assignment: ● This assignment promotes students' collaborations working in pairs. Students must form. their paired grouping within the same tutorial, the latest being Thursday Week 9. You can stay in the same group from Assignment One. Otherwise, you need to leave the original group, and create/choose your group via the Assignment Two Groups (see Moodle Assessments page). ● Every student in the group is required to participate and contribute to the assignment actively. These would be used as a basis for marks adjustment for the assignment's final score (if necessary). At the end of the assignment, all students must complete their Peer Assessment (to be made available in Moodle) confidentially and individually. Failure to complete the assignment peer assessment by the due date might result in a lower mark for the final score. Submission Requirements ● You are required to submit the assignment via Moodle as Microsoft Word and PowerPoint, or PDF formatted document. The file names should include the Unit Code, assignment number and your Group ID number, following either of these formats: FIT2090A2_GroupID.docx OR FIT2090A2_GroupID.pdf FIT2090A2_Present_GroupID.pptx OR FIT2090A2_Present_GroupID.pdf ● Only one of the group members will need to upload the assignment file on Moodle for the group, but all members must click the 'submit' button to accept the student submission statement. Late Submissions: Late submissions will be penalised, as stated in the submission link in Moodle. Task I Business Information Systems and Process (8%) Choose any one of the topics on business information systems for this task using a published case study. Some suggested topics/areas are (but not limited to): a. Business Process Improvement (BPI) b. Business Process Re-engineering (BPR) c. Customer Relationship Management (CRM) d. Enterprise Resource Planning (ERP) e. Supply Chain Management (SCM) f. Lean Operation g. Six Sigma For example, you could choose the BPR topic and use Qantas as a case study. Summarise the main findings from the case study to demonstrate your understanding of the philosophies of BPR. You could discuss the topic at a conceptual level, e.g. what is BPR, some background information, advantages and disadvantages, use the case study to illustrate how practical BPR is. Then you could discuss the high-level results (fail or success, how much they save cost), other interesting aspects such as the lessons learned, main challenges, the critical success factors, etc. 1. You need to choose a topic and/or case such that the information is available and can be easily obtained. Include at least four significant1 references – cite them in the body of your response and list them at the end of the report. Use the American Psychological Association (APA) style. of referencing (https://guides.lib.monash.edu/citing-referencing/apa). 2. You will also require approval from your tutors for the topic you chose. You are advised to finalise the topic by Week 9’s tutorial. 3. This part (Task I write-up) should be approximately 800 words (+/- 10%) in length. Oral Presentation – you will present your case study during Week 11 and Week 12 Tutorials. Your tutors will let you know about your presentation time in advance, e.g. in Week 10. All teams should submit their presentation slides (pptx or pdf format) to Moodle by the due date, regardless of their presentation being in Week 11 or Week 12. 1. Each presentation shall be no more than 8 minutes (including Question-and-Answer session). All team members are expected to participate in the presentation. 2. You will also be required to review and provide feedback on other students’ presentations (peer-review). Task II Business Process Improvement & Lean Operations (10%) Find and analyse a business process that can be improved or redesigned. Some suggested business processes are (but are not limited to): a. A retailer or a service business – the problematic business processes causing unsatisfactory customer experience can range from the selection of a product or service to the post-sale services. This could include businesses selling the products or services in either a physical store or online stores. Considering customers’ bad experiences, choose one particular business process with the most potential to improve. 1 These may include websites and newspaper articles and should be as current and substantive as possible – you are expected to provide at least two published peer-reviewed academic articles, e.g. journal, conference article, book, book chapter. You should acknowledge all sources of information. b. A local government services – find some of the business processes designed by local councils, state or federal government agencies or government authorities that can be improved. For example, which processes can be improved when a resident is applying for a parking permit or registering a pet in the local council, registering a car or getting a driver license from the local traffic authority? c. An insurance provider – find some of insurance claim processes that are inefficient and/or ineffective. The insurance policies include, but are not limited to, health insurance, car insurance, building and/or content insurance, travel insurance, and more. The improvement of the process could be similar to the example in Lecture 4, but your selected policy and process should be more comprehensive and on a larger scale. 1. You are advised to consult your tutors about the business process you are going to analyse to determine its suitability for this task. Do not use a case study that has already discussed the detailed improvement process and results, but find processes that you can demonstrate your high-level analytical skills of business process improvement. 2. You are required to seek information from various sources, e.g. company website, forums, etc. However, you are not required to contact the organisation for information. You may make reasonable assumptions, justify them in the report, and support them with references if appropriate. 3. Describe your selected business process in its current situation (in narration). 4. You could also model the current business process using the graphical tools that are discussed in this unit (e.g. system flowcharts, process flowcharts, etc). 5. Critique and discuss the aspects that are inefficient and/or ineffective in the current business process. 6. Propose a new business process model, justify how the business process is improved. Discuss what business process improvement approaches/techniques/principles/philosophies are applied. 7. You should use analytical tools and/or quality tools discussed in this unit (e.g. General Process Charts in Lecture 4, Cause-Effect Diagrams in Lecture 6b, etc.) to carry out business process performance analysis for the current and the proposed new business process. State your assumptions as and when necessary. 8. A summary of the roles that Information Technology (IT) /Business Information System (BIS) played in the proposed new business process. 9. We do not expect groups to present or rephrase the contents of Task I of this assignment in Task II, this task should be different from your Task I contents. 10. Include at least four significant2 references – cite them in the body of your response and list them at the end of the report. Use the American Psychological Association (APA) style. of referencing (https://guides.lib.monash.edu/citing-referencing/apa). 11. This part should be approximately 1500 words (+/- 10%) in length. 2 These may include websites and newspaper articles and should be as current and substantive as possible – you are expected to provide at least two published peer-reviewed academic articles, e.g. journal, conference article, book, book chapter. You should acknowledge all sources of information. Task III Emerging trends in Business Information Systems (2%) Huge information systems innovations in recent years have impacted various businesses across different industries. Business information systems (BIS) not only enables, but even triggers business strategies that transform. the traditional business processes, and enable organisations to achieve competitive advantages. 1. Look for BIS jobs from job advertising sites e.g. Seek.com, Indeed.com, etc, and discuss the nature of the business, the importance of BIS on these organisations and/or their business processes/activities, and summarise the skills and knowledge needed for these jobs. 2. Include at least two references – cite them in the body of your response and list them at the end of the report. Use the American Psychological Association (APA) style. of referencing (https://guides.lib.monash.edu/citing-referencing/apa). 3. This part should be approximately 400 words (+/- 10%) in length.
Communications Systems: Lab Script. 4 General instructions LI Communication Systems (13812) & LH Communication Systems for Aerospace A (33289) are practical modules. All of the assessments are via coursework, these assessments are based on the labs. In this lab you will apply what you have learnt in lectures, and you will demonstrate concepts from these lectures in MATLAB. When working on assessments within this session, make sure that you refer back to the lectures. You will also need to have done the MATLAB on ramp in advance of the lab. This can be found at:https://uk.mathworks.com/learn/tutorials/matlab-onramp.html?s_tid=tah_po_mlonramp When a question says ‘write a routine in MATLAB’ it means that you should create a .m file, which can be run by any user who opens the file in MATLAB and clicks ‘run’ . Ahead of the lab Before the lab, make sure that you have read through the lab script, watched the two introductory videos and completed the MATLAB on ramp (https://uk.mathworks.com/learn/tutorials/matlab-onramp.html?s_tid=tah_po_mlonramp). This will ensure that you get off to a flying start during the lab session. The videos mentioned here are the same as for the first and second lab so, if you remember these clearly, then you do not need to watch these again. Getting the best out of the lab Prioritise tasks which need to be done in MATLAB – these are the ones where you are most likely to need some help. Leave writing up the various exercises until after the lab session. The lab session Please attempt the following questions for the final assignment for this module. Please remember that these are design tasks. To get the highest marks you should clearly explain the reasoning behind the choices that you have made. You should use sensible numbers, for example if you were to choose a temperature of 5500 K (roughly equivalent to the temperature of the surface of the Sun), then this would be a poor choice for a practical communications system. Question 1 A binary signal is transmitted along a twisted pair of copper wires, with a potential difference of -1 V representing binary 0 and a potential difference of +1 V representing binary 1. This signal is affected by thermal noise, which can be assumed to follow a Gaussian distribution. You can assume that the noise level is not a function of frequency. Part a: Create a routine in MATLAB which models this system and where the user can vary the signal power, bandwidth and temperature. Produce a plot which shows the maximum possible information rate as a function of temperature: • At a fixed bandwidth • If the bandwidth is increased to a higher value • If the bandwidth is decreased to a lower value Produce a plot which shows the probability of a bit error as a function of temperature: • At a fixed bandwidth • If the bandwidth is increased to a higher value • If the bandwidth is decreased to a lower value You should make a recommendation for the operating characteristics (signal power, bandwidth and temperature) of the system. Please note that there is no unique right answer for this part of the question – I am interested in your reasoning, not the precise numerical value. Part b: Then, assuming that the attenuation of a signal is 2dB per km, write a Matlab code that produces a graph that shows how the signal to noise varies with distance for the operating characteristics that you have chosen. Your submission should include: • A detailed description of your work, including any plots which are needed to clearly explain your work • A single .m file for part a which can be run in MATLAB which contains your routine. This .m file should contain any comments which the user needs to be able to easily run this file and reproduce your results • A single .m file for part b which can be run in MATLAB which contains your routine. This .m file should contain any comments which the user needs to be able to easily run this file and reproduce your results If you find that you are unable to complete part a, then you can still attempt part b if you select a reasonable value for signal power and temperature. You can find such reasonable values in the lecture notes . Question 2 Question 3 of lab 3 was about amplitude modulation in a digital sense. You were asked to write a MATLAB code which created a sine wave, a binary digital signal, modulated the carrier wave with the signal, adds white Gaussian noise to the modulated signal and then decoded the modulated signal. You should use your work from question 3 of lab 3 as a starting point for question 2 of lab 4. You should begin by investigating what happens as you vary the amplitude of the Gaussian noise. When you decode the modulated signal, you should use a moving median filter (introduced in question 3 of lab 3) and you should vary the temporal length of the moving median filter (i.e. vary the number of points from the time series which are used by the moving median filter) and establish the optimum length for this filter. You should then try at least two other filters and make a recommendation as to which filter gives the best solution (i.e. which filter results in the best reproduction of the original message signal). Examples of filters which you could try are: • A filter which works in the frequency domain by using a Fourier transform (use a fast Fourier transform (the MATLAB command is fft)) to move from the temporal domain to the frequency domain, write code which removes unwanted frequencies and then transform the signal back into the temporal domain). • A filter in the temporal domain which works using the max or min functions (or a combination of both of these). • A Butterworth filter • A Chebyshev filter It is intended that you begin this question during the lab and continue working on this outside of the taught sessions. Butterworth and Chebyshev filters will be covered in the lectures in the last week of term (after this lab). Therefore, this question has been written in such a way that you can either use filters which you have already encountered or use those which you will encounter in the final lectures. The mark scheme has been written so that it does not matter which filters you choose (as long as they are properly implemented and your investigation is rigorous). Question 3 of lab 3 is a starting point for question 2 of lab 4, but you do not need to use the exact code from question 3 of lab 3. You can amend your work from lab 3 any way you like to get a good solution to question 2 of lab 4. State a limitation of this method of correcting errors in codes and suggests how this limitation could be addressed. Your submission should include: • A detailed description of your work • A .m file for part a containing your code, which can be run by another user. You should make sure that this code contains comments in an appropriate level of detail and any instructions that another user needs to be able to run this code. If you are unsure what level of detail is required, then you are advised to refer back to lab 1. • A recommendation of which filter gives the best solution, with a clear justification for your choice. Submission of work For the final assignment, you will submit a single word document on Canvas which contains your work for this assessment, plus MATLAB (.m) files where these are needed. You may spend as much time as you like on this, provided that your work is submitted on Canvas by 11:00 on Friday 9th January 2026. Format of files Your word document must be in one of the following formats: .doc, .docx or .pdf. Other file formats may not open or display correctly on university devices. Your Matlab file must be a single .m file for each question. You can write this in any version of Matlab that you like, but it will be tested in the online version of Matlab (matlab.mathworks.com), so you should ensure that your code runs on this platform. When you submit code on Canvas, it renames your files. Therefore, you should not use one Matlab file to call another. You should not declare functions – i.e. the following code calculates the average value of x. However this will not work after the file has been uploaded to Canvas. function ave = calculateAverage(x) ave = sum(x(:))/numel(x); end Instead, you should write a code which can be executed if the user opens the script and presses 'run'. An example of such a code is in on the Canvas page for this module under 'Modules' -> 'Lab 1' - > 'fib.m'
Department of Mechanical Engineering Coursework Assessment Brief Coversheet Module code MECH0059 Module name Advanced Computer Applications in Engineering Academic year 2025/26 Term Term 2 Assessment title FEA assignment Individual/group assessment Individual Word count or page count limit (if applicable) See details in the assignment sheet % contribution to module 50% Submission Date Please see the submission portal on Moodle for the due date for this assessment. Word count or page count penalty Work that exceeds the word/page/slide count by more than 10% will be reduced by 10 percentage points. This must not take the mark below the Pass Mark. Any material in addition to the 10% excess may not be taken into account in grading. Eligibility for Delayed Assessment Permit (DAP) This assessment is eligible for Delayed Assessment Permit. Mitigation available: Defer Assessment to next available opportunity – Late Summer Assessment period. Use of Generative AI This assignment is classified as Category 1: AI tools cannot be used. More implications of this can be found in the assessment brief. Assessment Brief MECHGM0059: Advanced Computer Applications in Engineering Finite Element Analysis THE PROBLEM Develop a finite element program based on 4 noded quadrilateral elements, using MATLAB to estimate the deformation of the structure shown in Figure 1A. Part 1: Write a MATLAB program to calculate the stiffness matrix of a two-dimensional plane stress 4 noded quadrilateral element as shown in Figure 1B. Assume E=40 GPa, ʋ=0.3 and plate thickness is 2 mm. Part 2: Use your program in Part 1 to determine the displacement and strain in Figure 1A, consisted of 2 and 4 quadrilateral elements. Assume E=40 GPa, ʋ=0.3 and plate thickness of 2 mm. Note do not change the dimensions in Figure 1 (except “L” as per Figure 1C) and use the element arrangement that you think is most appropriate. Part 3: Re-run your program in Part 2 to determine the displacement and strain, (i) for three additional elastic modulus (ii) for three additional loading conditions i.e. changing the loading direction from θ=90° . Keep other variables constant. Your slides must compare/comment on the: • displacement and strain results obtained from different elements, material properties and loading conditions • validity of your program, here you are expected to model the same structure using a commercial program (i.e. ANSYS Mechanical APDL) and compare your results against it. Figure 1: (A) A thin plate loaded; (B) a single four-noded element; (C) based on the first letter of your family name chose the right value of L for the plate design. GUIDELINES • Prepare 3 power point (.ppt) slides summarising your work. • Slides must be static i.e. simply include all information on the slides. • Prepare clear figures that are self-explanatory, examiners know what is the task so no need to repeat the task. • No need for introductory slides with your name, simply put your name in the top corner of the first slide. • You must submit your power point slides (in .pdf format i.e. save the .ppt as .pdf) together with the MATLAB code online on the relevant moodle page by 0900 (UK time) on 12th January 2026. The viva panel will use your submitted slides as the visual aid to begin their assessment and Q&A. • Attend an in person, individual based question and answer session (viva session) arranged in the week of 12th Jan 2026. The viva will be conducted by two independent examiners. The date for this will be announced on moodle by mid Dec 2025. • During the viva session you will be asked various questions about your work. Some examples include: o What is the finite element method and how it works? o Explaining the figures and findings included on your slides. o Explaining how your code works. o Rationale behind your findings. • At the end of the viva you will be provided with a short oral feedback on your viva that you can record on your phone. • If you can, bring your work on your own laptop including your MATLAB code. If you cannot bring your laptop you must bring your MATLAB code on a memory stick. • International System of Units (or SI units) must be adopted throughout the work. • This assignment is in Artificial Intelligence (AI) Category 1: AI tools cannot be used. • This is an individual assessment and any form. of collusion between students will be academic misconduct. • You might find the supporting information given in the following webpage useful: https://www.ucl.ac.uk/students/academic-support/second-year-undergraduate/support-your-assignments • Note this assessment will address all module learning outcomes outlined for this module (see L0 and L1 ofFEA lecture slides - e.g. to understand the fundamental ofFE method and appreciate structure ofFE programs). Moreover, it will guide you into scientific/professional presentation skills required at FHEQ Level 7. • You will be marked on three categories: Slides [20 marks]; technical content [50 marks]; discussion and critical analysis [30 marks]. See marking rubric document. REFERENCE [1] Seshu P. Textbook of finite element analysis. PHI Learning Private Limited 2003.
Multidisciplinary Software and Systems Engineering SysML report coursework 2025-26 SysML Coursework: Intelligent Hair Dryer Introduction Your coursework assignment involves developing a SysML description for an intelligent hair dryer/styler. You will submit three SysML diagrams: a Requirements Diagram, a Block Definition Diagram (or Internal Block Diagram), and an Activity Diagram. These diagrams should adhere to SysML notational standards, ensure representational consistency, and demonstrate clear traceability between key elements across the diagrams. This assignment meets the learning outcome to demonstrate competences in design abstraction employing standardised viewpoints. Figure 1 Intelligent Hair Dryer image generated by Google Gemini based on patent abstract Link to patent: https://patents.google.com/patent/US12178303B2 This active patent presents a system and method for an intelligent, cloud-connected hairdryer which can customise settings to the user’s hair condition. It features several diagrams that illustrate system functionality and structure as well as textual descriptions, albeit not employing SysML notation. Submission Details: Upload to Canvas a 5-page report in PDF format: 1) Title page: Include your name, username, and student ID and Generative AI declaration. 2) Requirements: A SysML Requirements diagram – landscape format. 3) Structure: A SysML Block Definition Diagram – landscape format. 4) Behaviour: A SysML Activity Diagram – landscape format. 5) References. 6) Appendix: Generative AI prompts and responses used to complete the assignment (if any). Ensure that all SysML diagrams are readable. They will be assessed on a computer screen, so please zoom into your final pdf and check. You can draw by hand or digitally. Each diagram should be no more than one page in landscape format. It should have approximately 20 nodes plus the relationships between them. Note that 20 is not an absolute minimum or maximum. Please check canvas for the deadline for this assignment. Please upload your PDF to the canvas assignment page. Please check the assignment page for updates to submission dates. Marking Criteria: This coursework is 30% of the module – 3 credits – which corresponds to 30 hours of study. It will be marked against the following criteria (with weightings): • English proficiency (10%) • Notational correctness / adherence to SysML standards (30%) • Design details for each diagram (30%) • Representational consistency across diagram (30%) Descriptions for the criteria are in the marking rubric on the canvas assignment. Use of generative AI will be considered when arriving at marks for all criteria. Benchmark statement of expectation: The following outlines an example of what an excellent and a failing submission could include. These are indicative and the final assessment will take account all aspects. Thus, you should only use this as an indication of what an excellent and a poor submission would include: An excellent submission (will attract first or upper second class marks): The work presented adheres to a commendable standard of English, showcasing accurate spelling, punctuation, vocabulary, sentence construction, and textual coherence. The SysML model is ofa calibre suitable for patent application, with supporting references provided in the introduction. The SysML diagrams, skilfully crafted using software, exhibit a professional appearance, accurate notation, and maintain a consistent level of detail throughout. The Requirements Diagram comprehensively captures both functional and non-functional requirements, encompassing all vital elements and providing thorough descriptions for each relationship. The SysML Block Definition Diagram effectively portrays the system's structure, demonstrating appropriate associations between blocks, as well as between blocks and external actors/systems/organizations. Key signal flows are also included. The SysML Activity diagram boasts a well-defined activity frame, complete with explicit input and output parameters. Energy, matter, data, and control flows within the activity frame are presented clearly, coherently, and distinctly. Descriptive notes enhance the clarity of all diagrams, facilitating comprehension and enabling easy identification of links between diagrams through consistent element naming. A poor submission (will invite fail) The work submitted exhibits a subpar command of written and spoken English, significantly hindering comprehension. The pervasive weaknesses in writing and expression severely impede effective communication. The provided model is superficial, unconvincing, and lacks any meaningful connection to the reference patent. The accompanying text is either unintelligible or overly generic. The SysML diagrams are incomplete, poorly organized, and riddled with errors. The handwritten drafts, submitted as low-quality scans on canvas, are barely legible. The Requirements diagram omits crucial requirements while including irrelevant elements. The SysML Block Definition Diagram fails to accurately represent system structure, showcasing incorrect block associations and lacking essential external actors, systems/organizations, and key signal flows. The SysML Activity diagram lacks proper activity boundaries, and the flows are either absent or flawed, suggesting a fundamental misunderstanding of these concepts. The overall presentation of the diagrams is disjointed and lacks consistent labelling. Examples of poor written presentations from past coursework submissions: (diagrams are blurred to prevent copying!) Examples of good written presentations from past coursework submissions: Past errors Students typically lose marks in this coursework from misunderstanding the SysML diagrams as covered in the lectures, sometimes submitting diagrams which have completely different notations! This is especially true of the activity diagram. We only cover a subset of the SysML diagram standard in the lectures, so it is strongly recommended you review the lecture materials before attempting this coursework. Guidance on completing the assignment. 1) Study the lectures and the intelligent kettle example. Consult the course text available through the canvas ResourceList to ensure your notation’s correct: Friedenthal, S., Moore, A., & Steiner, R. (2014). A practical guide to SysML: the systems modeling language. Morgan Kaufmann. 2) Download the patent. There are 26 pages of text and diagrams. You should note: a. What are the requirements and their types/directives. b. Are there any structural elements? These can typically be identified from nouns in the text. Many figures in the patent also identify the components. c. Any there any behavioural elements? These are typically verbs in the text. d. What is missing in the patent which you can assume in order to complete the design? 3) Start with your requirements – the SysML Requirements Diagram. Look at your list and select the requirements that you think best describe what the system does. Refine your diagram and add detail, following the advice given in the lecture and the intelligent kettle example. 4) Move onto Structure - the SysML Block Definition Diagram. You should be able to identify the key structural blocks from the text and figures. It may also help if you consult your requirements diagram as requirements blocks can be satisfied by structural blocks. Refine your Block Definition Diagram, once again following the intelligent kettle example. 5) Finally, tackle the Activity Diagram. This is the most difficult diagram to produce since it considers function and flows. Using the patent document, your requirements diagram and block definition diagram, identify a key activity frame consisting of several activities and the flows in and out of the activity frame. Remember to keep separate control and matter/information/energy flows! 6) To draw your final diagrams, use a basic drawing tool such as powerpoint. There are UML/SysML packages for drawing models, but I do not recommend these as there can be notational differences and added complexity. 7) I iterated over the intelligent kettle design used in the lectures many times to get it right, and so should you. I recommend you spend a day on the diagrams. 8) You do not need to completely replicate the design in the patent – your SysML diagrams would be too complex. Instead, you should model a similar system which is of sufficient detail to demonstrate you can use the SysML notation standard as covered in lectures to its fullest. 9) While Generative AI tools like Chat-GPT, Copilot, or Gemini can be utilised in this coursework (see next page), it's imperative to explicitly detail their usage in the appendix, including the specific prompts employed. Remember, these tools should serve as aids, not replacements for your own critical thinking and effort – use them as a support, not a crutch!
Machine Vision: Assignment II (Lab Practical 10) 10th December, 2025 1 Introduction After our 10th weekly in-person lab, you should complete the task and submit your work as the second (of two) marked courseworks for Machine Vision. This document sets out the directions that apply for both the lab and the assignment. Task: We want you to design, train, and submit a model which takes as input a video (in .mp4 format), and outputs an integer: count the number of pushups which were completed in the video. Despite huge advances (for example Veo-3, Sora, Flux 2, and many more), state-of-the-art AI models still struggle significantly at video-understanding. Particularly when asked questions about observed dynamics. We do not expect you to ‘solve’ this problem. In fact, we will be awarding relatively few marks for absolute model-performance. We are much more interested in how you approach this problem. See the Project Report section for more details on how to submit your work, and the Grading section for specific information on how your work will be marked in this assignment. 1.1 AI-tools In your previous assignment, it was expressly prohibited for you to use AI tools to complete the assignment. In this assignment, we now actively encourage you to use AI tools, with a caveat. As long as you don’t discuss the task itself on Moodle, it is OK (even encouraged) to share and discuss information about code LLM’s and coding environments on the shared Moodle forum. E.g. If the coding LLM built into Colab (Gemini) isn’t available, there are other options besides cut-and-pasting, and some are free, though with restrictions. However, now that we’re permitting you to use AI models to help you complete an assignment (something which previous cohorts that took this course did not have access to), we naturally expect a far higher standard of output. 1.1.1 The Caveat You are free to brainstorm your approach to this assignment with an LLM. You are also free to use an LLM to help you write code to complete this assignment. However, you must not use an LLM to write your project report. It’s a very good thing for you to use state of the art (SOTA) AI models to push the frontiers of your capabilities in designing and training models. However, that cannot come at the expense of your fundamental understanding of what you are doing. We are looking to see creative, nuanced, and interesting write-ups in the Project Reports. We want to hear about your efforts and iterations in your own words. We do not want to read AI-generated slop reports. If we detect that you have used an LLM to write your Project Report, you will score 0% on this assignment, and be subject to the UCL disciplinary procedure on cheating. 2 Deliverable One of the goals of this assignment, is to get you comfortable with using some of the tools and techniques that are useful for a career in computer vision (be that in industry, or in academia). The thing you actually need to submit on Moodle for the January deadline is exactly one PDF Project Report. However, that Project Report must clearly contain public links to your code that you used to complete this assignment. Only share the public link with the Instructor/TA’s by linking to it in the report - do NOT share it with others obviously! Do not modify the code any further once submitted, because the latest time-stamp (among the report, model, and each file of code) will be used as your time-of-submission for lateness purposes. Specific instructions for how to submit your code are below. 2.1 Code You must submit all of the code you used to complete this assignment. Please open each notebook in turn, go to ‘File’, ‘Save a copy in Drive’ (or, alternatively, ‘Save a copy in GitHub’), and proceed to fill in your code in-line. For saving in Google Drive, Google sign-in will be required. Optional, and we have not tested this yet, but you may be interested in the Google Colab Extension that lets you work in VS Code but run on Google’s computers. When it comes to time of submission, make your Colab notebooks public, and clearly include the links to your notebooks in your Project Report. Failure to clearly include the links to your completed versions of the above notebooks will result in you scoring zero marks for the Model Performance section. 2.1.1 Model Training Code This notebook should contain all of the code necessary to train your model from scratch, save it to disk, and, upload the model to a public repo on HuggingFace. Starter code is provided for you in this notebook, and a number of TODOs are set for you throughout. Completion of all of the given TODOs is the minimum requirement. The provided TODOs show a rough skeleton for a basic implementation of this assignment. The expectation is that students will invent their own model or combination of models to address this task. Think in terms of 3D, but also 2D or 1D. If you find you need to add more cells to this notebook to carry out the analysis necessary to write your Project Report, that is completely welcome. Please feel free to add as many cells as you see fit. Please note, however, we expect to see all plots, analysis, and discussion for this assignment in your Project Report. Please write the code you need in the notebook, but please keep all of your substantive analysis in one place: the Project Report. We do not want to be flicking back and forth endlessly between your code and your report. We will spend the vast majority of our time reading your report, and we will only go through your code afterwards, mainly just to make sure you have actually done the work. Your notebook, as submitted, should ‘just work’. That is to say, a TA should be able to open the notebook, click ‘Run all’, and observe your model train. Double, triple, even quadruple check that this is the case. If this is not the case, you will score 0 marks in the Model Performance section. 2.1.2 Model Inference Code This notebook is much more brief, and there is a lot less for you to do. This notebook will download your model from HuggingFace, and evaluate it against a set of video data. The TAs will use this exact notebook to grade your model performance. You do not have access to the test data, naturally, but it is your responsibility to make the notebook run without errors when evaluating against the provided training data. As long as you ensure this is the case, you can be safe in the knowledge your code will work when the TAs change the target to be the test dataset. While there are very few TODOs for you to complete in this notebook, it is paramount you take due care and attention to make sure that this notebook will work with your chosen model architecture. Failure to do so will result in you scoring zero marks on the Model Performance section. 2.2 Model 2.2.1 Model Weights You are not permitted to consume any model via API request. For example, you are not permitted to submit a video to Gemini 3.0, and prompt it to count the number of pushups completed in the video. You are permitted to use pre-trained model weights. So, for example, you may try and construct a model on top of Dinov2, or Dinov3, or SAM3D Body, provided that the combined footprint of your model does not exceed the memory footprint requirement. Put another way, all weights of any model you use must be loaded by your code onto your device, and the combined footprint of the model(s) on your device must not exceed the corresponding model footprint. 2.2.2 Model Submission Your model must be made public via HuggingFace Hub. You should make a HuggingFace account (if you don’t have one already) and upload your model to a public repository. This step must be clearly completed in the Model Training notebook. Code is provided to help you here. You should also clearly reference a public link to your model in your Project Report. 2.2.3 Footprint Your model, at inference time, must not have a memory footprint (RAM) of more than 12GB. Your model, at training time, must not have a memory footprint (RAM) of more than 20GB. 2.2.4 Training The model training code you submit in your Model Training Colab notebook, must run, from start to finish, on the training data which you have been provided, in under 5 hours, on an Nvidia T4 GPU. That is to say, a TA should be able to open your Model Training Colab notebook, select an T4 runtime, click ‘Run all’, come back in 5 hours, and see that execution has ended, and your model has fully trained. This includes any time taken for data preprocessing necessary for your model to train. As an explicit example: say you were to use a pose-estimation model to extract trajectories of pose data from the videos in the training data, and that takes 3 hours to complete, and then you were to subsequently train a model to estimate the number of completed pushups from the pose trajectories, and that took 3 hours, then that would count as 6 hours total execution time, and that would be over the time constraint. You can also (but are not required to) include some code in your training loop which prints a UNIX timestamp at: • The beginning of training. • A semi-regular cadence throughout training. • The end of training. This can also help convince the TAs that your model trains within the required time con- straint. If your model does not train from start-to-finish within the time constraint, you will score zero marks on the Model Performance section. 2.2.5 Latency Your model must be able to operate over 100 frames of test video in under 60 seconds, when run on an Nvidia T4 GPU. If it does not, you will score zero marks on the Model Performance section. 2.3 Training Data The training data can be accessed by running the first cell in the provided Model Training notebook. It is hosted in a public S3 bucket. You are not permitted to add additional new videos to the training data, however, you are permitted to augment the provided videos. We are particularly interested in discussion and evaluation regarding your approach here. For more information see 2.5.1. 2.4 Test Data The test data is, understandably, not provided to you. The TAs will use the held-out test data to test your model performance. You are told the following key pieces of information about the test data, however: Every video in the test data will comply with the below constraints: • Under 1,000 frames in length. • Under 1080p resolution. • Only contain one person. • Only contain whole, distinct (integer units of) pushups. Furthermore, you are made aware that there will not be any videos in the test data which contain more than 10 pushups. Should that persuade you to reframe the problem as a classification, rather than a regression problem, that is your prerogative. 2.5 Project Report This is the most important part of your submission, and is where we will be awarding the majority of the marks for this assignment. The format for this report is quite unique. We are looking for a very specific type of report. Please pay close attention to the instructions given in this section. The clue is in the name: Project Report. We are looking for a linear, descriptive, journal of your work on this project. We want to hear all of the details. We are particularly interested in content like: 1. I tried x because I thought y. 2. I evaluated my implementation of x by doing z. 3. Here are some plots of my evaluation metrics, and some discussion around why I chose them . 4. Surprisingly, it turned out, that actually my belief in y was misguided. In actual fact z is true (insert some novel realisation you happened upon by virtue of inspecting your results). 5. Therefore, I rearchitected my model in light of z, and, saw greatly improved perfor- mance, as evidenced by these informative plots of yet more evaluation metrics. Note, we are not looking for something resembling a paper here. A paper is designed to place the majority of the emphasis on the final product: the ground-breaking innovation, dataset, or architecture that the authors have come up with. In contrast, in this assignment, we care very little about your final product. We care far more about your experimental process. We want to see interesting evaluation metrics, thoughtful discussion about your architecture, and creative approaches around augmenting the training data. While marks will be awarded for model performance, comparatively, you can score far more marks by producing a well-written project report, than a well-performing model. A good report, would probably cover the below topics. This is not a prescriptive structure (feel free to structure the report however you like). 2.5.1 Data Augmentation As stated above, you are not permitted to add extra videos to the training data. However, you are permitted (and are encouraged) to augment the training data. The graphic in Figure 1 from this paper is quite informative in this respect. Put another way, you can perturb, translate, rotate, scale, mask, or make any modification you like to any of the provided videos, but you cannot add extra videos to the training data. 2.5.2 Data Preparation Before feeding your video data into your model, you will need to make some decisions as to how you transform your .mp4 data into data your model can understand. We are very Figure 1: Data Augmentation Techniques interested in your reasoning around your approach here. As an idea of some things to think about (you don’t have to address all of these points, these are just suggestions): 1. Frame rate. Are all of the videos in the training data the same frame rate? If you’re using any pretrained models, what frame rates do they operate over? What is the effect of varying frame rate on the final accuracy of your model? 2. Resolution. Are all of the videos in the training data the same resolution? If you’re using any pretrained models, what resolution do they operate over? What is the effect of varying resolution on the final accuracy of your model? 3. Positional Encoding. Dependent on your choice of model architecture, you might want to carry out some analysis on the impact of positional encodings (and choice thereof) on your model performance. 4. Video Length. How does your model cope with videos of varying lengths? If the input dimension of your model is fixed, what do you do? Do you then use padding in your input? Is that not a lot of wasted computation if you end up attending over padding tokens? Would you implement an attention mask in that case? 2.5.3 Model Architecture Starting with a concise summary of your architecture is generally a good idea. For example: ‘my final model uses a pre-trained 3D pose estimation model to detect trajec- tories of body pose, before passing the resultant sequence of pose data through a transformer architecture, which I trained from scratch, to output an integer count of pushups’. Then, please walk us through each component of your model in detail. Please pay particular attention to how the different components of your model connect to each other. Please be sure to walk us through the logic for your approach. We would love to see examples of ‘failed’ approaches. N.B. don’t just tell us you tried something and it didn’t work. Show us. We are looking for well reasoned arguments as to why you thought some approach was going to work, and then, some interesting plots of evaluation metrics which led to your initial belief being confounded, followed by a discussion of how you updated your beliefs / approach in light of the evidence presented. For example: ‘I first started out with a 2D pose estimation model, but the estimated pose trajectories were not accurate enough, especially when dealing with partially occluded video (see my 2D vs 3D pose-estimation evaluation section for more analysis on this). I switched to a 3D model and found that the improvement in performance justified the increase in model footprint, and in latency (see my latency evaluation section for more analysis on this)’. It would also be an extremely good idea for you to include a diagram of your model archi- tecture. Multiple examples abound in the literature (it is a rarity to see a paper without a model diagram). It’s usually also useful to see some explanation of how gradients flow through your model, in your diagram. 2.5.4 Evaluation This part of your Project Report should contain some overall evaluation of your final model. Note, this differs slightly from the evaluation you will have shown up until this point. Whereas beforehand, we were looking for you to show some evaluation which would have guided you in making a decision between various model architectures, or data pre-processing techniques, in this section, we would like to see a summative evaluation of your final model performance and characteristics. Things to include here would be: 1. Model footprint. 2. Model latency. 3. Edge cases / failure cases your model does not perform well on. 4. Some visualisation of the activations of your intermediate model layers on different inputs. 2.5.5 Extensions / Future Work If you have some insight as to potentially interesting extensions to your model, which you would like to attempt, if you had (A) more time, (B) more data, (C) more compute, (D) all of the above... Then please write about it here. 3 Grading This assignment will be graded out of 100 marks. NOTE: You must include two things from your code in the report, to show that your report lines up with your code and your experiments (the SUMMARY and your random seed) - see below. The breakdown of how marks are awarded will be as follows: 3.1 Model Performance 20 marks. Here’s how they’ll be awarded: We will open your Model Inference Code, and will select an Nvidia T4 runtime. We will click “Run all”. If your code doesn’t make it past this point (if it errors out already), you will score 0 out of 15 marks. We will then change the input source to be our own held out test set. This will be a folder of .mp4 files, compressed with the H.264 codec. The test data will respect the constraints outlined in section 2.4. The only thing we will change is a bucket name, and your code should ‘just work’. If your code runs correctly, you will score 5 marks out of 20 (regardless of your latency or accuracy figures). To get the most out of the 15 marks, 5 marks will be awarded for latency, and 10 marks will be awarded for accuracy on the test-set. Specifics: we will not be providing target latency / accuracy figures. As a rough guide however, we will count each prediction as ‘correct’ if and only if it matches the target number exactly. Unless your model scores over 55% accuracy averaged over the test-set, you are most likely scoring 0 out of the 10 marks for accuracy. There are no explicit marks for this section being awarded for your Model Training code. That is by design. However, you can lose marks for this section due to your Model Training code (if it takes too long to train, or doesn’t train at all). This section is for rewarding the performance of your model, provided that your model met the specified training constraints. If your code exceeds the strict model-footprint limit, and / or exceeds the latency limit, you will score 0 marks on this section. 3.2 Clean Code 10 marks. If your submitted code is easy to follow, not excessively verbose, and does not look like you just copy-pasted it from ChatGPT, you will score 10 points. If your submitted code is a hodge-podge of copy-pasted spaghetti, you will be penalised. It’s entirely condoned for you to use AI to help you generate code for this assignment, however, please ensure your code is of an acceptable standard. If your code is easy to read, and easy to use, you’ll make the TAs’ lives easier, and you’ll be rewarded! 3.3 Project Report • 70 marks • 2500 words maximum! (This is not a target number, and we assume reports would be around 3 pages if there were no figures.) • Figures, plots etc. are all encouraged! • Must include a screenshot of the SUMMARY from running your Model Inference note- book. This isn’t to encourage overfitting. It’s just so we can validate that the submitted code didn’t change after you wrote your report. • Must include the seed you used in the Model Training notebook, for that final model. We weren’t kidding when we said this is the most important part of the assignment. Don’t forget to include as much evaluation and insight into your model architecture as possible. This section is where you will be rewarded for your Model Training Code, to the extent that your work in your Model Training Code has permitted you to write up an interesting and creative Project Report. Remember, please keep the analysis to your Project Report. Generate the analysis in your Model Training Code, and present it to us in one cohesive narrative in your Project Report. Remember - we are looking for creative and interesting approaches, we don’t really care that much about absolute model performance, and visualisations are always a good idea.
CONTENTS CONTENTS Welcome to the second project in Programming Fundamentals II! In this project, you will use many of the various concepts you’ve learned in order to read, manipulate, and write binary image files. You will design a series of algorithms that can be applied to images in order to change their appearance. Then, you’ll make a interface to this program using your computer’s command line, allowing you to modify images on the fly. Along the way, you will grow and flex your knowledge of various C++ concepts! Contents 1 Overview 3 2 IDE and Compiler Installation 3 3 TGA Files 3 4 TGA File Specification 4 4.1 RGB and Pixels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4.2 File Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4.3 TGA Image Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 5 Reading and Writing 7 5.1 Implementation Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 6 Milestone 1: Image Manipulations 8 6.1 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 6.2 Clamping and Overflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 6.3 Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 6.4 Implementation Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 6.5 Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 6.5.1 External Comparison Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 6.5.2 Writing Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 6.6 Makefile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 6.6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 6.6.2 Using Makefiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 6.6.3 Creating a New Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 6.6.4 Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 6.6.5 Writing your Makefile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 6.7 Submission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 7 Milestone 2: Command-Line Interface 14 7.1 Accessing the Command-Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 7.1.1 CLion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 7.1.2 Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 7.1.3 Terminal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 7.2 Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 7.3 Developing The Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 7.3.1 Tracking Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 7.3.2 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 7.3.3 General Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 7.3.4 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 7.3.5 Implementation Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 7.4 Testing Your Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 7.5 Submission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 A Compatibility 21 A.1 Paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 A.2 Testing on Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 A.2.1 Testing on CISE Computers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 B Grading 22 B.1 Deductions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 C Submitting to Gradescope 23 C.1 Gradescope Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 D Document Revisions 25 3 TGA FILES 1 Overview Lots of applications need to process images in some way. Load them, store them, write them back out to files, scale them, rotate them, adjust the color in part (or all) of the image, etc. The purpose of this assignment is to show you how you can perform some of these operations on a particular type of file. In this assignment, you will: • Read data from binary .tga files • Process the image data stored within files in a variety of ways • Write out the new .tga files in the same binary format • Develop a command-line interface to handle user input • Develop a Makefile to allow others to compile and run your project quickly and easily ! 2 IDE and Compiler Installation If you haven’t already, you will need to install an IDE and compiler for this project. This will allow you to write and run your code on your local computer, which can speed up development and give you access to more tools for working with your project. If you need to install an IDE and/or compiler, please visit this page on Canvas for instructions. 3 TGA Files What is a TGA, or .tga, file? It’s simply an image file – just like your standard PNG, JPEG, or GIF files. However, the file format supporting TGA files is much simpler and easier to work with, especially when modifying the images through code. In this assignment, you will learn this specification in order to read and create your own TGA files in C++! How awesome is that? It’s like your own little Photoshop! Some operating systems won’t let you open TGA files natively (looking at you, Windows), so you will need to install some sort of viewer for them. If you already have a tool installed that lets you open and view these, great. You can tell if you have a tool installed already if you try clicking on one of the .tga files provided and observing if a program is able to show you the file. It’s recommended to install at least one of the following programs if you do not already have a TGA viewer installed: • Visual Studio: If you have installed Visual Studio, you should be able to click on a .tga file and have the file open up in a new Visual Studio tab. • Photoshop: If you use the popular Photoshop image manipulation tool, you can use this program to view your outputted .tga files. • GNU Image Manipulation Program (GIMP): A popular free and open-source image editor, GIMP will be able to open your .tga files and is completely free. • TGAViewer: A small, cute little program whose job is just to view .tga files. How nice!Although it is helpful to generate the images and check whether the output is correct visually, we acknowledge that not all people can see pictures correctly (ie, have an inability ability to perceive or distinguish certain color, or students with visual disabilities). This assignment has been developed with visually impaired students in mind, and can be completed entirely through code. As you move through the document and begin to work with TGA files, we recommend accomplishing your tasks using images with only a few pixels. For example, rather than testing your code using a 512×512 image, you could use an image of size 2×2 to check if your methods are implemented correctly at the channel level. This setup is more accommodating for screen readers and other assistive devices. 4 TGA File Specification 4.1 RGB and Pixels Before jumping into the format, we need to discuss how colors can be represented in computers. Without having a way to represent colors, you can’t represent pictures. For example, imagine trying to store an image of a sunflower on your computer. How do you store the golden color of the flower, or the pastel blue color of the sky, or the olive green color of the flower stem? One of the most common format for representing colors numerically is known as the RGB format. This format uses three numbers (0-255) to store the amount of red, green, and blue in the color. Figure 4.1 showcases some examples of this representation.R: 255 G: 0 B: 0R: 0 G: 255 B: 0 R: 0 G: 0 B: 255 R: 255 G: 0 B: 255 R: 255 G: 255 B: 255 R: 0 G: 0 B: 0 R: 240 G: 255 B: 48R: 61 G: 50 B: 161Red Green Blue Magenta White Black Yellow Purple Figure 4.1: Various colors represented in RGB format. You can see that colors high in red, green, and blue, but devoid of other colors, are unsurprisingly red, green, and blue, respectively. White is made by setting red, green, and blue to the max. Black is made by setting all values to zero. Other colors are made by combining various values of these three elements. If you would like to create your own colors, you can use a color picker tool, found on your computer or online. An example of such tool can be found at https://colorpicker.me/. In computers, these three numbers are commonly stored as 3 bytes, each made up of 8 bits. Each byte is able to represent a number between 0 and 255. Note that some file formats store the bytes in the reverse order of blue, green, red, rather than the conventional red, green, blue. This includes TGA – but more on that later! You should now feel comfortable understanding how a single color can be represented numerically. But, a picture is made up of many colors – how do we represent all of these various colors? This is the concept of pixel. Digital photos are made up of a series of these pixels which create a unique image. The height and width of an image are determined by the number of these pixels in a column and row, respectively. For example, a 1920×1080 image, or 1080p image, has 1,920 pixels in each row, and 1,080 pixels in each column. The image has a height of 1080 pixels and a width of 1920 pixels. Each pixel has three color attributes: red, green, and blue. 4.2 File Format Since binary files are all about bytes, they are typically an unreadable mess to any program (or person) that doesn’t know exactly how the data is structured. In order to read them properly, you must have some sort of blueprint, schematic, or breakdown of how the information is stored. Without this description of the file format, you would just be reading random combinations of bytes attempting to get some useful information out of it—not the most productive process. The TGA file format is a relatively simple format, though it has some options which can get a bit complex in some cases. The purpose of this assignment is not make you a master of this particular image 4.2 File Format format, so a few shortcuts will be taken (more on those later). First, let’s take a quick look at the file format, showcased in Table 4.1. Field Size Length Description Header ID Length Color Map Type Image Type Color Map Origin Color Map Length Color Map Depth 1 byte 1 byte 1 byte 2 bytes 2 bytes 1 byte Denotes the length of the Image ID. Specifies if a color map is present. Indicates the type (e.g., grayscale, true color, compressed). Starting index of the color map, usually 0. Length of the color map, usually 0. Bit depth of the color map, usually 0. X Origin 2 bytes Horizontal image origin, typically 0. Y Origin 2 bytes Vertical image origin, usually 0. Image Width 2 bytes Width of the image in pixels. Image Height 2 bytes Height of the image in pixels. Pixel Depth 1 byte Bit depth of each pixel, typically 24 for RGB. Image Descriptor 1 byte Provides additional details about the image. Data Image Data Variable Contains pixel data in BGR format. Starting from bottomleft to upper-right. Number of pixels is the product of width and height. Table 4.1: File specification for TGA files.Listing 4.1: Example of using a C++ struct to hold header information. Note that if you used char in your program, when you print out the char or unsigned char variable, you get a symbol that corresponds to its numeric value, instead of the number itself. If you want to see the numeric value of a char variable instead of its symbol, you would have to cast it to an integer, as shown in Listing 4.2. 4.3 TGA Image DataListing 4.2: Showcasing various methods of printing information about a character in C++. We’ve covered reading headers into memory, but how do we construct and write a header for an entirely new image? Here’s the great news: as long as the images are the same width and height, you can simply steal the header from either image and use that in the resulting image. In this project, all source images that will be used have headers that are compatible with each other. Note that if you need to change the width and height of the resulting image, you will need to modify this property in the resulting image’s header. 4.3 TGA Image Data After the header comes the really important part, the image data itself. In a TGA file, the image data is stored in a contiguous block of pixels. The number of pixels in the block is equal to the image’s length multiplied by the image’s width. The contents of a single pixel can vary depending on the properties of the file, but for this assignment we are using images with 24-bit color. This means that each pixel contains: • 1 byte (8 bits) for blue data • 1 byte (8 bits) for green data • 1 byte (8 bits) for red data Notice that the order of the color data is BGR, not RGB. Each of those bytes will contain a value from 0-255, representing the intensity of that color in the pixel. Conveniently, an unsigned char is able to store values in the range of 0-255! So if a file had a size of 200×300, it would contain 60,000 pixels, each of which contains 3 bytes of data. Figure 4.2 shows the start of the image data of an example TGA file, where pixels are stored in series.Figure 4.2: Series of pixels stored in the example.tga file. Pixels are stored in series, and each contain a B, G, and R value. To store these values in your program, you could make a 1-D array/vector with 180,000 entries, where there are three new entries in the array for every pixel (being the B, G, and R values for each pixel). Or, you could make a 2-D array/vector of 60,000 entries, with each entry being a vector storing three elements, the B, G, and R values of the specific pixel. The approach you take should depend on what you feel comfortable with. What about the order of the pixels themselves? In many image files (including TGA files), the first pixel in the file represents the bottom left corner of the image, while the last pixel represents the top right corner of the image, as shown in Figure 4.3. If you read, store, and write the pixel data in the same order, you don’t really have to worry too much about this. If you wanted to copy data into a particular part of the image, however… that can be a bit tricky. For example, to copy some 2×2 image into the top left corner would require you change pixels 16, 17, 24, and 25.Figure 4.3: Order in which pixels are retrieved and written to in a TGA file. So, to summarize: The file contains a header, which is 18 bytes in length. Stored within those 18 bytes are pieces of information describing the image content—the width and height of the image, how the color data is stored, and so on. All you need from the header is the width and the height. However, when writing a file, you should provide all the header data, whether you are using it or not. Because of this, you should store this data along with the image data itself. 5 Reading and Writing Great – you should now have a good understanding of TGA files. You should now have the skills to read and write to them. Now, we encourage you to try reading and writing one of the .tga files we give you. While this isn’t worth any points on its own, this part serves as good practice for the next section. Specifically, try: 1. Reading the header and pixel data from one of the TGA files provided to you. You can choose one of the files from the input/ folder provided to you in the assignment zip file. 2. Storing the information you read (image header, pixel content, etc.) in data structures. 3. Writing the contents of those data structures to another TGA file with a different name. 4. Verifying that the contents of the file you wrote and the file you read from are the same. For now, you can just visually inspect the two images. If you do not write the binary data in the correct format to the .tga file, your viewer will not be able to open the file. Try opening a file from the input/ folder to be sure your viewer is not broken. Once you feel confident reading and writing files, then you should be ready to move to Part 2. 5.1 Implementation Tips As you move throughout this project, we’ll offer some small bits of advice to help you along your journey. Like a great narrator, we’ll only complement your adventure. • If you try opening a .tga file created by your program and see that the file cannot be opened by your viewer, or that your viewer crashes when attempting to open the file, your code implementation is likely broken. • Start by planning out the data structures you will need, and how you’ll store those objects. Planning out the design early makes the later implementation much easier. • Remember to read the file in binary mode. This isn’t default, you need to pass an argument to your fstream constructor. • Use classes and structs. Do not try to not use them – you will save yourself more time by declaring these structures up front and using them throughout your project. • Pass objects around by reference, not by value, or your program might become very slow and memory inefficient. • A BGR value of (0, 0, 0) represents a black pixel. A BGR value of (255, 255, 255) represents a white pixel. If your image is all black or all white, you might be reading all zeroes or all max values. • If your output image has vertical or horizontal lines which are all the same color, then your loops are likely incorrect. You might be printing the same row/column of pixels repeatedly, without incrementing to the next row/column. 6 Milestone 1: Image Manipulations If you’ve used Photoshop or a similar tool, you’re likely aware of image manipulation. Tools in these programs allow you to change the pixel data in image data using common algorithms. These algorithms allow you to blend colors together, highlight certain colors, or even make objects disappear. You will be implementing some of these algorithms as part of this project. 6.1 Algorithms These algorithms are described in the Table 6.1. You will be implementing the formulas in the table in your own program. Each formula contains two values, P1 and P2. These represent the individual channel values of the two pixels used in the formula. Note that the order of the pixels matters for some algorithms – in these cases, the pixels in the “top layer” become P1, and the pixels in the “bottom layer” become P2. NP1 and NP2 refer to the normalized values of P1 and P2, as explained in subsection 6.2. Note that these formulas should be calculated for each channel of the input images, and then used in each channel of the resulting output image. You will need to use the equations in Table 6.1 three times per pixel, one time per channel. Method Channel Formula Multiply NP1 · NP2 NP NP Addition P1 + P2 Overlay ( NP2 ≤ 0.5 : 2 · NP1 · NP2 NP2 > 0.5 : 1 − [2 · (1 − NP1) · (1 − NP2)] Table 6.1: Formulas for common manipulation algorithms. Note that the “Overlay” method shown in Table 6.1 is a conditional algorithm, meaning the specific algorithm you’ll need to run varies based on the input pixel value. You can implement this in code using an if/else statement. 6.2 Clamping and Overflow If you attempt to implement some of the above algorithms using the suggested unsigned char data type, you will experience overflow. This occurs when one of the above calculations results in a number below zero or greater than 255 – values which can not be stored by that data type. As an example, imagine two pixels, one with a green value of 100, and one with a green value of 200. If you attempt to add the green components together, you will end up with a value of 300, which will overflow to 300 − 255 = 45. • For operations involving addition, you will need to clamp values. When completing an operation, you will likely need to use a data type that can support a large range of values, such as 6.3 Tasks int. Then, after the operation is complete, all values lower than zero become zero, and all values greater than 255 become 255. tinypink.tga tinygreen.tga correct.tga invalid.tga −=not −=not B G R B G R B G R B G R Figure 6.1: When clamping is not done, an entirely different image can arise. Notice how the green value is appropriately clamped to 0 in the correct image, while it overflows to 102 − 201 = −99 + 255 = 156 in the incorrect image. • For operations involving multiplication, you will need to use normalized values. These values are the original values of the pixel divided by 255. Therefore, the range of a normalized pixel is 0-1. In these operations, you will likely need to use float to store the intermediate values. After the operation, you just need to multiply the resulting float by 255, and voilà, you have a new pixel value! Keep in mind that operations involving float values will likely result in precision errors. Therefore, you should add 0.5f to the normalized value multiplied by 255, before converting to an unsigned char. Why 0.5f? This value is perfect for rounding numbers. Numbers closer to the next highest value (such as 79.7) will be rounded up (to 80, in our example). Numbers closer to the lower value (such as 79.2) will be rounded down (to 79). 6.3 Tasks In this project, you are expected to complete ten different tasks, each of which use different input images and image manipulation algorithms. Your program should be able to complete all ten tasks and produce images that match the images given in the examples/ folder. The output names for all files you generate should be output/partX.tga, where X is the task number. For now, all tasks should complete whenever your project is built and ran. The user should not need to enter any input. 1. Use the Multiply blending mode to combine layer1.tga (top layer) with pattern1.tga (bottom layer). 2. Use the Subtract blending mode to combine layer2.tga (bottom layer) with car.tga (top layer). 3. Use the Multiply blending mode to combine layer1.tga with pattern2.tga, and store the results temporarily, in memory (aka, don’t write this to a file somewhere, just store the pixel values somewhere in your program). Load the image text.tga and, using that as the bottom layer, combine it with the previous results of layer1/pattern2 using the Screen blending mode. 4. Multiply layer2.tga with circles.tga, and store it. Load pattern2.tga and, using that as the bottom layer, combine it with the previous result using the Subtract blending mode. 5. Combine layer1.tga (as the top layer) with pattern1.tga using the Overlay blending mode. 6. Load car.tga and add 200 to the green channel. 8. Load car.tga and write each channel to a separate file: the red channel should be part8_r.tga, the green channel should be part8_g.tga, and the blue channel should be part8_b.tga. (Hint: If your red channel image appears all red, try writing [Red, Red, Red] instead of [Red, 0, 0] to the file—ditto for green and blue!) 6.4 Implementation Tips 9. Load layer_red.tga, layer_green.tga and layer_blue.tga, and combine the three files into one file. The data from layer_red.tga is the red channel of the new image, layer_green is green, and layer_blue is blue. 10. Load text2.tga, and rotate it 180 degrees, flipping it upside down. This is easier than you think! Try diagramming the data of an image (such as earlier in this document). What would the data look like if you flipped it? Now, how to write some code to accomplish that…? 6.4 Implementation Tips Again, let’s talk about some tips that might help you out with this part of the project: • Re-read over the implementation tips listed in subsection 5.1. • Be careful when casting values to specific types. If you’re completing an operation and then casting to a specific type, remember to wrap the operation in parentheses, as in (unsigned char)(a + b), not (unsigned char)a + b. • Make sure you know which file is the “top layer” and which file is the “bottom layer” in operations where that matters. • Make separate functions for each operation. While you could just write all the operation code in your main() function, using separate functions will likely make Part 3 (the next part) easier to understand. 6.5 Testing After you have completed the tasks, you’ll want to make sure that your output matches the expected output we actually give you. To do this, you can use an external program to compare your output with our output, or you can write your own code to do so. We typically recommend both methods, as the external tools will always be correct in their analysis, while your tool will likely give you more helpful information about which pixels are wrong in your output. Your images and the example images given must match exactly. This includes the header and all pixels stored in both images. Looking at two images side-by-side is not a valid testing method. 6.5.1 External Comparison Tools To tell if two files are different, you can use command-line tools installed with your operating system. • Windows: In your terminal or PowerShell, you can use the fc.exe program to tell whether two binary files are different. Use the /b flag followed by the name of each of the binary files. If there are any differences, the program will print them to you. Otherwise, it will tell you that no differences were found. • macOS, Linux: Use the diff command. This command will simply output whether the two files you provided as arguments differ in content. If the program prints no output, then the two files provided as arguments have the same content.(a) Windows, using fc.exe (b) macOS/Linux, using diff Figure 6.2: Comparing the contents of two files, in Windows and macOS. First, the contents of two equivalent files are checked. Then, the contents of two different files are compared. 6.6 Makefile 6.5.2 Writing Tests If your files differ in content, you might have noticed that the commands aren’t super helpful in telling you how to fix your program. That’s where you come in! If your file differs in content from the examples provided, you will probably want to write a small extension to your program that shows you which pixels are different, and how they are different. This program doesn’t need to be too complex — but it should help you debug faster by showing you which pixels are incorrect, and how they are incorrect. This program should load both files into memory, and compare their pixels against each other, letting you know when it finds a difference. Writing this step is not required at all, so build it however you think it will help you most. 6.6 Makefile In your submission for this project, you will need to create a Makefile. This is a small file that allows us to build your project instantly, without needing to run any of our own commands. For this project, you will write a Makefile with just one rule to start. This rule should generate an executable named project2.out. This executable will be generated by g++, which will be the command you reference in your first rule. You can learn more about Makefiles below. 6.6.1 Introduction Compiling from the command-line interface (CLI) can be a much faster way to build a project. It’s not without its drawbacks, however. Consider the following example, where you have a file, main.cpp, that you want to build. A simple command to build it might be (for GCC):In this example: • g++ is the executable, and everything else is an argument sent to that program. • -std=c++11 sets which version of the C++ standard to use (C++11, in this case). Other values could be c++14, c++17, or other new versions when they are released. • -o sets the name of the output to whatever you specify in (in this example, the result is MyProgram). If nothing is specified, the file produced has a.out (or a.exe, on Windows) as the default name. main.cpp is, of course, the file that you want to compile and ultimately turn into an executable. So far so good. But, what if you wanted to add some additional files? Instead of just main.cpp, let’s say you have main.cpp and a class called FileReader which is split into FileReader.h and FileReader.cpp. The command to build this might now change to be this:Still not so bad, right? What if you then added classes called FileDatabase, UI, and UIControl? You’d again have to adjust the command:Still not the end of the world, but… having to type that every time could be a bit tiresome (not to mention how easy it gets to forget a single file from the list). What if you then added a class called Stopwatch, and another called UserPreferences, and another… A better way to do this would be to save that command in a file, and then call on that file to execute the command. That way, you only have to write the information once, and never need to worry about forgetting any part of it. The file that you would store this in is called a Makefile. 6.6 Makefile 6.6.2 Using Makefiles A makefile is a plain text file (very commonly just named Makefile with no extension) which can contain instructions to build your project (and possibly do a lot of other things). In order to execute these instructions you can simply run the following command from a directory that contains a makefile:Listing 6.4: Invoking make from the command-line. Note that the command used to run your Makefile varies between operating systems, and it might be neither make nor mingw32-make, especially if you use an advanced setup. This assignment is only going to scratch the surface of Makefiles and how to use them. 6.6.3 Creating a New Document You will need to write your Makefile in a file named Makefile, with no extension. The easiest way to make this file is to use your terminal to make this file. Remember to change directories before making the new file, so you know where it is!Listing 6.5: Creating a Makefile using the command-line. If you want to use your computer’s user interface, that works as well. You can create makefiles similarly to how you create any other text file: 1. Create a new text document using your file explorer. On Windows, right click and choose New ⇒ Text Document. On macOS, launch TextEdit.app, create the document in the appropriate folder, and choose Format ⇒ Make Plain Text (otherwise, it will be a rich text format). 3. If your file has the .txt extension, remove it before submitting. 6.6.4 Structure Great, you should now have a text file to write your Makefile in. Let’s begin writing your first Makefile. When you run make, the program looks for a Makefile in your current directory. If it finds one, it executes the top rule. A rule is a series of steps that executes based on a keyword. Here is an example of a Makefile with two rules:Listing 6.6: Makefile with two rules. Here, we can run either rule by calling make followed by the rule name— for example, make clean would run the two rm commands. As mentioned before, emitting the name of a rule executes whichever rule comes first in the file. 6.7 Submission Wildcards The build command shown Listing 6.6 is great, but we have to keep updating it as we add more and more C++ files. Luckily, there’s a wildly better way to do that, using wildcards. These are expressions using the * keyword to substitute the place of other terms. For example *.c targets any filename ending in .c. Let’s use this to update our build command from Listing 6.6:Listing 6.7: Makefile using a wildcard. This looks much better, and will update whenever we add more C++ files to our project. Appropriate Files There are two notes about the files you reference in your Makefile. 1. If you need to reference files in a given directory, you can use dirname/filename to reference that file. This works for wildcards, too, but note that this can be trickier. Wildcards matching directories and subdirectories can be confusing. In this assignment, you shouldn’t have too many levels of nested directories in your submission, so this won’t be an issue. 2. You should not use header files in your compiler command. Headers do not need to be compiled, only the implementation files do. After the implementation files are compiled, the header files will be appropriate linked with your source. 6.6.5 Writing your Makefile For this project, you will start with just one rule in your Makefile. The default (first) rule in your Makefile should build your project. For this rule, note that some characteristics we want from the build command include: • The output executable should be named project2.out. • The C++11 standard should be used. • You should compile all of the files relevant to your project. 6.7 Submission To submit your first milestone, submit your project zip file to the Milestone 1 assignment in Gradescope. For more information about how to package your project and submit to the Gradescope platform, see Appendix C. For details on grading, see Appendix B.7 Milestone 2: Command-Line Interface ! To solve this, you’re going to develop a command-line interface to your program. This will allow the end user to provide different arguments to your program, which will change the behavior of your program on the fly. This allows the end user to change the manipulation methods used, the input files used, or the name of the output file, all without needing to re-build. 7.1 Accessing the Command-Line First, we will need to understand the different ways to access your command-line, in order to test this part of your program. There’s nothing you need to build or test yet, this is just meant to show you how to access the command-line in your editor of choice. Typically, the command-line is accessed through a dedicated terminal app. However, most modern development environments today have embedded terminals that allow you to test a command-line app from the IDE itself, rather than needing to use an external program. Furthermore, many IDEs even support debugging of programs running with specific command-line arguments! We’ll take a look at how you can access these environments in the following subsections. 7.1.1 CLion Typically, programs are run in CLion by clicking the green triangle ( ) in the upper right-hand corner of the program, which builds and runs the project. However, this button does not allow us to input arguments into our program before running it. Therefore, we should instead use the hammer ( ) to only build the project. Then, navigate to the “Terminal” menu at the bottom of CLion — this is your command-line. The specific executable built by your program will be given the name listed in your CMakeLists.txt file. You can run your program by typing ./cmake-build-debug/executablename arg1 arg2 arg3 …Figure 7.1: Accessing the command line through CLion. 7.1 Accessing the Command-Line To enter debug mode while specifying command-line arguments, in your menu bar, go to Run ⇒ Edit configurations… ⇒ Program arguments, and input the list of arguments you’d like to have called in debug mode. 7.1.2 Visual Studio You can access the Terminal in Visual Studio by going to View ⇒ Terminal. The executable file is typically stored in Visual Studio under a folder named arm64Debug or amd64Debug, or something similar. You can call this executable and optionally pass arguments to it, as shown in Figure 7.2.Figure 7.2: Accessing the command line through Visual Studio. If you would like to open debug mode and still pass arguments in, you can add these arguments in your project settings, as shown in Figure 7.3.Figure 7.3: Altering the command-line arguments used in Debug mode. The option that is modified in the project properties is “Command Arguments”. 7.1.3 Terminal If you would like to test your command-line program using your Terminal, open up your terminal program of choice. On Windows, Windows Terminal is a good option, while on macOS, Terminal.app is a good option. After opening the Terminal, navigate to your project directory using the cd command. Then, use g++ to build your project files using the C++11 standard. Finally, run the executable with the desired arguments by typing ./executablename arg1 arg2 arg3 … 7.2 GoalsFigure 7.4: Accessing the command line through Terminal on macOS. Terminal applications on other operating systems should have a similar interface. 7.2 Goals The first step in developing your command-line interface is removing the code that automatically runs the ten tasks listed in part two of the assignment. You don’t have to delete the code for these tasks from the project, but they should no longer execute automatically. Before building the command-line interface, build your project and run it with no arguments to make sure none of the ten tasks execute automatically. The interface should not do anything other than what the user asks. If the user supplies only the –help argument, then simply print the help message and exit. If the user asks to multiply two images using the multiply method, then proceed with that method, and then exit. 7.3 Developing The Interface Now that you have access to your command-line, we can begin work on building the actual commandline interface. Your interface should use the argc and argv features of C++ to handle command-line arguments, as discussed in class. This section will discuss what methods you will need to implement in your interface, how arguments are passed to those methods, and the actual specification itself. 7.3.1 Tracking Image Just like the tasks you completed in Part 2, a user can request multiple image operations to be done one after the other, using the output of the previous step as an input to the next step. In order to support this, your command-line interface will need to keep track of a “tracking image.” This is what will be written to the output filename once all the image manipulations have been done on this image. The initial source for this tracking image will be given to you as the second argument (explained more later in subsubsection 7.3.3). It is recommended to load in the data from the source file into your tracking image first. Then read all the image manipulation algorithms requested by the user, in order. These algorithms will take in the tracking image as an input, and then the tracking image will be set to the output of the algorithm. In other words, each image manipulation algorithm will “act” on the tracking image. You can keep track of the tracking image by storing a variable representing your image before the user calls CLI arguments. This variable could be an image class you have written, it could be a vector of pixels, whatever makes sense in the context of the program. Ensure that it can be updated whenever a new image manipulation method is run. Note that this method of implementing the command-line interface is not necessarily required, but the specification was set up to support this style of developing your command-line interface. 7.3 Developing The Interface 7.3.2 Methods You will need to implement several methods in your CLI that the user can call. The methods are discussed below. • multiply: This method takes one additional argument, the second image to use in the multiplication process, alongside your tracking image. • subtract: This method takes one additional argument, the second image to use in the subtract algorithm, alongside your tracking image. The first image, the tracking image, will be the top layer. The additional image argument constitutes the bottom layer. • overlay: This method takes one additional argument, the second image to use in the overlay algorithm, alongside your tracking image. The first image, the tracking image, will be the top layer. The additional image argument constitutes the bottom layer. • screen: This method takes one additional argument, the second image to use in the screen algorithm, alongside your tracking image. The first image, the tracking image, will be the bottom layer. The additional image argument constitutes the top layer. • combine: This method is similar to what you did in task 9 of Part 2, where three individual files each provide one channel of the resulting image. This method takes two additional arguments, the source for the green layer (the first additional argument), and the source for the blue layer (the second additional argument). The source for the red layer is the tracking image. • flip: This method takes no additional argument, and simply flips the tracking image. • onlyred: This method takes no additional arguments, and simply retrieves the red channel from the image, similar to how you did in task 8. • onlygreen: This method takes no additional arguments, and simply retrieves the green channel from the image, similar to how you did in task 8. • onlyblue: This method takes no additional arguments, and simply retrieves the blue channel from the image, similar to how you did in task 8. • addred: This method adds a certain value to the red channel of an image. This method takes one additional argument, the amount to add to the red channel. This will need to be converted to an integer. • addgreen: This method adds a certain value to the green channel of an image. This method takes one additional argument, the amount to add to the red channel. This will need to be converted to an integer. • addblue: This method adds a certain value to the blue channel of an image. This method takes one additional argument, the amount to add to the red channel. This will need to be converted to an integer. • scalered: This method scales the red channel of an image. This method takes one additional argument, the amount to scale the red channel. This will need to be converted to an integer. • scalegreen: This method scales the green channel of an image. This method takes one additional argument, the amount to scale the red channel. This will need to be converted to an integer. • scaleblue: This method scales the blue channel of an image. This method takes one additional argument, the amount to scale the red channel. This will need to be converted to an integer. Each of the final six operations listed accept an integer as an additional argument. For addred, addgreen, and addblue, you should be able to accept negative integers. These will decrement the designated channel of each pixel by some value. You should ensure that the pixel value never falls out of the 0-255 range, clamping as appropriately, as described in subsection 6.2. The scalered, scalegreen, and scaleblue operations should accept any integer greater than or equal to zero — you will not be tested with negative numbers for these operations. 7.3.3 General Specification Your program should be able to handle commands in the following format: 7.3 Developing The Interface • If no arguments are provided, or if the first and only argument is –help, print the help message. The help message to print is shown as the first command example shown in Listing 7.2. Your help message should be exactly the same for the tests to pass. Note that the final line in the help message is indented with a tab character, not several spaces or another character. You are expected to use this character as well. • The first argument will be the name of the output file. If the argument does not end with .tga, print “Invalid file name.” If this argument is missing, you should proceed with the bullet point above. • The second argument will be the name of the source file for your tracking image. If this argument is not provided, or if the argument does not end with .tga, print “Invalid file name.” If the filename is not a real file, then print “File does not exist.” • The next few arguments describe the first image manipulation method. – The third argument will be the name of the first image manipulation method. If this argument is not provided, or if the method does not exist, print “Invalid method name.” – If the first image manipulation method selected requires additional arguments (such as the “multiply” method, which requires the name of a second file to multiply the first with), then those arguments will be provided after the name of the manipulation algorithm. If the arguments are not provided when they should be, print “Missing argument.” If the first method selected does not require additional methods (such as the “flip” method), then any following arguments will be related to the next image manipulation algorithm. ∗ If the method expects a filename argument, and the argument does not end in .tga, print “Invalid argument, invalid file name.” If the file does not exist, print “Invalid argument, file does not exist.” ∗ If the method expects an integer, but receives something other than an integer, print “Invalid argument, expected number.” • After the first image manipulation method arguments are read, any additional arguments should represent more steps in your program. Unlike the first step, these methods act on the tracking image, and therefore one image supplied to the method will be the output of the previous step. – The first argument of successive methods is the name of the image manipulation method. If the method does not exist, print “Invalid method name.” – Any additional arguments required by the method will be provided next. If an argument is missing, print “Missing argument.” For commands that are not invalid (commands where some image manipulation is successfully done), the output of the command does not matter. You can print whatever you like! 7.3.4 Examples Listing 7.1 highlights how your program should print its help message.Listing 7.1: Example of the desired help message. Note that the indent below “Usage:” is a tab character. 7.4 Testing Your Interface Listing 7.2 highlights how your program should be able to complete operations. Note that files referenced in a CLI command can be in a folder, but this is not required.Listing 7.2: Example successful outputs given various arguments. Listing 7.3 shows how your program should emit errors when improper arguments are encountered.Listing 7.3: Example successful outputs given various arguments. 7.3.5 Implementation Tips Here are some tips to assist you in your implementation of the command-line interface: • Don’t forget to handle –help and passing no arguments. That should be handled first. • Consume arguments one by one; you should only need to look at each argument once, in order. If an argument is missing, you can print an error right away. • You cannot compare char* to std::string directly. Instead, use std::strcmp(char* value, std::string otherValue), located in the header, which will return zero if the two string representations have the same value. Alternatively, you can cast construct an std::string from the argument. • Segmentation faults commonly occur from trying to access an array index that does not exist. • When handling receiving numbers via the command line, you can use std::stoi, which will convert a string representing a numeric value to an int. It will throw a std::invalid_argument exception if no conversion can be performed (aka, if the argument was not a number). 7.4 Testing Your Interface Once you feel confident with your interface, test it as a replacement for your tasks! Try running task 1 from subsection 6.3 using the command-line, and ensuring that the output file is the same as the example task 1 file. This might look like: 7.5 SubmissionListing 7.4: Running task 1 through the command-line. For best results, you should ensure that all ten tasks can be executed through the command-line (this might help with a later part of the project… hint, hint). Furthermore, ensure that your program reacts appropriately when you supply invalid or missing arguments. Currently, to test your tasks you have to re-type the executable name followed by a certain set of command-line arguments to run each task. In the next part of the assignment, we’ll use a Makefile to store these commands in a file. This will allow us to run commands that generate all ten parts of the project using just the command line. 7.5 Submission At this point, you should have a completed command-line interface to your image manipulation program. It should be able to handle variable file names and variable arguments, and should not run anything automatically. This should allow to pass several of the tasks you will be tested on. Again, Gradescope will be used to test out your command-line interface. There are three areas you will be tested on. Like Milestone 1, there are ten individual tasks, some of which you will add to your Makefile using your new command line arguments, and others will be compiled by Gradescope after you submit your submission. You won’t know some of the arguments your program is tested with. • Help Message and Error Messages: Your program should produce the correct help message when requested, and your program should produce the correct error messages when invalid arguments are supplied. • Tasks 11-13: As described below, you will add three new tasks into your Makefile under a new rule named tasks. Gradescope will expect that after this rule is called, the images for tasks 11-13 will be generated. • Tasks 14-20: Gradescope will call your command-line interface with variable arguments. Tasks 14-16 will have their arguments shown, while tasks 17-20 will have their arguments hidden. Your program should be able to handle these arguments and produce the correct images. For tasks 11-13, you will add one new rule to your Makefile: tasks. This rule should call your executable with the appropriate command-line arguments to generate the three images below. Gradescope will call make tasks to test your implementation. 11. Multiply circles.tga with layer1.tga. 12. Flip (or, rotate 180 degrees) layer1.tga. 13. Subtract layer2.tga (bottom layer) from layer1.tga (top layer). Tasks 14-16 will be executed by Gradescope calling your executable with the necessary command-line arguments. For debug purposes, they are listed below: 14. Flip car.tga four times. 15. Subtract layer1.tga from car.tga, then multiply the output with circles.tga, then flip it. 16. Given car.tga, scale its blue channel by 3, its red channel by 2, and its green channel by 0. Tasks 17-20 have been hidden from you. Gradescope will call your executable with the necessary command-line arguments.A COMPATIBILITY A Compatibility Once you believe you have completed the project, ensure that the following compatibility requirements are met. Failure to follow these principles could break your project when it is being graded, and will cause you to lose 10 points. A.1 Paths For compatibility purposes, you adhere to the following principles about paths. This applies for all aspects of the project, including the source code itself, and your Makefile. • Use forward slashes, not backward slashes: On some operating systems, especially Windows, backslashes can be used to specify folder names in paths. While this format is supported on some operating systems, this is not supported on all operating systems. Therefore, please use forward slashes. – Bad: folderfilename.txt – Good: folder/filename.txt • Use relative paths, not absolute paths: Absolute paths link to a file on your computer, and your computer only. Frequently, absolute file paths will include specific details about your computer that will break your program on other people’s computers. Therefore, use relative paths instead, which specify a filename relative to your current directory. Your paths should start with input/, output/, or examples/. A.2 Testing on Unix Your code will be run and graded in a Unix environment. Specific operating systems are out of the scope of this course, but generally, Unix refers to a Linux-like operating system. Most importantly, not Windows. You should ensure that your code is able to run in a Unix environment before submitting it. The recommended way to do this is to make a pretend submission (as described in Appendix C) and send this submission to a Unix computer. We recommend testing your code on the CISE computers in the CSE building on-campus, or using the CISE Thunder virtual machines. A.2.1 Testing on CISE Computers If you don’t already have an account with the CISE department, you will need to make an account, as listed on this page (you will need to sign in with your Gatorlink to view the page). Your account approval might take a few days to process, so we recommend doing this step early, even if you haven’t finished the project. After you have access to a CISE account, you can test your code. To ensure you can signin, try using SSH to enter your virtual machine:Listing A.1: Entering the virtual machine using SSH. If you are able to enter your virtual machine after entering your Gatorlink password, you’re all set! Next, let’s move your files over to your virtual machine. You can use a program like sftp or scp. In our examples, we’ll use scp: B GRADINGListing A.2: Copying the project zip file to the remote machine using scp. If this command does not produce any errors, you should have successfully transferred your project to your virtual machine, under the name of project2.zip. Congrats! You should also transfer the input/ and examples/ folders over as well so your program can reference these files when running. Now, re-enter your virtual machine using SSH, as shown in Listing A.1. Unzip your project using the unzip command and ensure that all files are present. Move your folders into the right structure, and then run make. Ensure that your executable builds without error. Run the executable using the proper command line arguments, and ensure that there are no differences between the files appearing in your output folder and those in the examples/ folder using the diff command as shown in Figure 6.2. If there are no differences, then you’ve completed the project. B Grading Task / Milestone Points Description Milestone 1 (80 points) Tasks 1-10 70 7 points possible per task. Complete task with matching pixels and header. Proportional points for pixel accuracy. Makefile 10 Makefile development: 5 points for correct executable, 5 points for make run completion. Deductions 0 Any deductions found from the Deductions section deduct 10 points. Milestone 2 (70 points) Command-Line Tests 6 Tests the help message and error messages. Tasks 11-13 15 5 points per task. Command-line tasks generated by your Makefile. Tasks 14-20 49 7 points per task. Command-line tasks generated by Gradescope. Total 150 Table B.1: Rubric for the entire project. B.1 Deductions 10 points will be deducted from the final project score if any of the following are true: • Your submission contains any other files than the src/ folder and your Makefile. (Explained more in the next section…) • Your Makefile build command does not use the C++11 standard, builds code from the wrong location, or includes header files. • Your Makefile is incorrectly named, or uses an improper encoding. Your Makefile cannot be named Makefile.txt, Makefile.rst, or anything similar, and it must be a plain-text file (ie, not created in Microsoft Word or macOS Rich Text Editor). No points will be deducted for the following: C SUBMITTING TO GRADESCOPE • Printing output when running a successful image manipulation (ie, where the user’s command input does not fail). • Warnings appearing when compiling the executable. Be careful, however, as these warnings might indicate that your program will fail under specific circumstances which you might want to be aware of. C Submitting to Gradescope If you’ve made it to this part, you might almost be done with your project! That’s exciting!! Let’s talk about how to actually submit your project to Gradescope. Gradescope is a machine grader that is used to test and grade your submission automatically. The grader has over fifty tests, and conforms to the rubric specified above. Your submission should be one zip file, containing: • Any source and header files, placed in a folder named src/. There should be only C++ files in here. Delete any object files or other files. • The Makefile you created to build your project. You do not need to include output/, input/, nor examples/ in your submission. These will be provided in the grading environment for you. An example structure is shown in Figure C.1. File.h and File.cpp are example alternate source files. lastname.firstname.project2.zip Makefilesrc/ main.cpp File.h File.cpp Figure C.1: The appropriate tree structure for your submission. Do not include any other files in your submission. This is not limited to the following: project images, executables, IDE-specific configurations, PDF files, etc. To submit to Gradescope, visit the Project 2 assignment on Canvas. At the bottom of the page, you will find a window to submit your assignment. Choose the zip file to upload, ensure that all files listed match the files you would like to submit, and press “Upload,” as shown in Figure C.2. C.1 Gradescope Environment C SUBMITTING TO GRADESCOPEFigure C.2: Uploading a submission through Gradescope. After pressing “Upload,” wait some time for the autograder complete. You can analyze the tests that passed and did not pass using the right sidebar. C.1 Gradescope Environment The Gradescope testing environment consists of four parts: 1. Deductions: Testing to see if your submission contains deductions. 2. Building: Using your Makefile to build your submission and generate tasks 1-10. If you do not provide a Makefile, your submission will be supplied one, but you will receive a zero for the Makefile in the rubric. This allows your submission to build even if you have not yet completed the part 4. 3. Tests: Testing tasks 1-10 for Milestone 1, or tasks 11-20 for Milestone 2. After each test is run, an accuracy comparison is run on the output image. The testing environment has been created to help ensure each student receives a fair amount of points. Here are some further tips on the testing environment: • Some TGA files tested by Gradescope are not provided to you. • Many of the commands tested in Gradescope are shown to the student. However, some of the commands tested are hidden and not accessible by the student. • Some TGA files tested by Gradescope have lengths and widths other than 512×512. • If make or an individual test takes a significant amount of time, the command will be aborted, and that test will receive zero points. This helps prevent infinite loops. D DOCUMENT REVISIONS D Document Revisions Table D.1 shows the edits have been made to the document since its initial release. Table D.1: Changes that have occurred in the document since its initial release.
HW 3 and 4: RLE with Images PythonOverview In this project students will develop routines to encode and decode data for images using run-length encoding (RLE). Students will implement encoding and decoding of raw data, conversion between data and strings, and display of information by creating procedures that can be called from within their programs and externally. This project will give students practice with loops, strings, Python lists, methods, and type-casting.Run-Length Encoding RLE is a form of lossless compression used in many industry applications, including imaging. It is intended to take advantage of datasets where elements (such as bytes or characters) are repeated several times in a row in certain types of data (such as pixel art in games). Black pixels often appear in long “runs” in some animation frames; instead of representing each black pixel individually, the color is recorded once, following by the number of instances.0 0 2 2 2 0 0 0 0 0 0 2 2 0_ 2 0 3 2 6 0 2 2 1 0_ For example, consider the first row of pixels from the pixel image of a gator (shown in Figure 1). The color black is “0”, and green is “2”:Flat (unencoded) data:Run-length encoded data: . Figure 1 – Gator Pixel Image The encoding for the entire image in RLE (in hexadecimal) – width, height, and pixels – is:2 0 3 2 6 0 2 2 2 0 1 2 1 F 1 0 7 2 1 A F 2 1 0 9 2 3 0 1 2 1 0 3 2 6 0 3 2 3 0 8 2 5 0 1 E |1 6 W/ H/ ——————————————PIXELS———————————————–/Image Formatting The images are stored in uncompressed / unencoded format natively. In addition, there are a few other rules to make the project more tractable:1. Images are stored as a list of numbers, with the first two numbers holding image width and height. 2. Pixels will be represented by a number between 0 and 15 (representing 16 unique colors).For example, the chubby smiley image (Figure 2) would contain the data shown in Figure 3.Figure 2 Figure 3 – Data for “Chubby Smiley” NOTE: Students do not need to work with the image file format itself – they only need to work with lists and encode or decode them. Information about image formatting is to provide context. Requirements Student programs must present a menu when run in standalone mode and must also implement several methods, defined below, during this assignment.Standalone Mode (Menu) When run as the program driver via the main() method, the program should:1) Display welcome message 2) Display color test (ConsoleGfx.test_rainbow) 3) Display the menu 4) Prompt for inputNote: for colors to properly display, it is highly recommended that student install the “CS1” theme on the project page.There are five ways to load data into the program that should be provided and four ways the program must be able to display data to the user.Loading a File Accepts a filename from the user and invokes ConsoleGfx.load_file(filename): Select a Menu Option: 1 Enter name of file to load: testfiles/uga.gfxLoading the Test Image Loads ConsoleGfx.test_image: Select a Menu Option: 2 Test image data loaded.Reading RLE String Reads RLE data from the user in decimal notation with delimiters (smiley example): Select a Menu Option: 3 Enter an RLE string to be decoded: 28:10:6B:10:10B:10:2B:10:12B:10:2B:10:5B:20:11B:10:6B:10Reading RLE Hex String Reads RLE data from the user in hexadecimal notation without delimiters (smiley example): Select a Menu Option: 4 Enter the hex string holding RLE data: 28106B10AB102B10CB102B105B20BB106B10Reading Flat Data Hex String Reads raw (flat) data from the user in hexadecimal notation (smiley example): Select a Menu Option: 5 Enter the hex string holding flat data: 880bbbbbb0bbbbbbbbbb0bb0bbbbbbbbbbbb0bb0bbbbb00bbbbbbbbbbb0bbbbbb0Displaying the Image Displays the current image by invoking the ConsoleGfx.display_image(image_data) method.Displaying the RLE String Converts the current data into a human-readable RLE representation (with delimiters): Select a Menu Option: 7 RLE representation: 28:10:6b:10:10b:10:2b:10:12b:10:2b:10:5b:20:11b:10:6b:10Note that each entry is 2-3 characters; the length is always in decimal, and the value in hexadecimal! Displaying the RLE Hex Data Converts the current data into RLE hexadecimal representation (without delimiters): Select a Menu Option: 8 RLE hex values: 28106b10ab102b10cb102b105b20bb106b10Displaying the Flat Hex Data Displays the current raw (flat) data in hexadecimal representation (without delimiters): Select a Menu Option: 9 Flat hex values: 880bbbbbb0bbbbbbbbbb0bb0bbbbbbbbbbbb0bb0bbbbb00bbbbbbbbbbb0bbbbbb0Class Methods Student classes are required to provide all of the following methods with defined behaviors. We recommend completing them in the following order:1. to_hex_string(data) Translates data (RLE or raw) a hexadecimal string (without delimiters). This method can also aid debugging.Ex: to_hex_string([3, 15, 6, 4]) yields string “3f64”.2. count_runs(flat_data) Returns number of runs of data in an image data set; double this result for length of encoded (RLE) list.Ex: count_runs([15, 15, 15, 4, 4, 4, 4, 4, 4]) yields integer 2.3. encode_rle(flat_data) Returns encoding (in RLE) of the raw data passed in; used to generate RLE representation of a data.Ex: encode_rle([15, 15, 15, 4, 4, 4, 4, 4, 4]) yields list [3, 15, 6, 4].4. get_decoded_length(rle_data) Returns decompressed size RLE data; used to generate flat data from RLE encoding. (Counterpart to #2)Ex: get_decoded_length([3, 15, 6, 4]) yields integer 9.5. decode_rle(rle_data) Returns the decoded data set from RLE encoded data. This decompresses RLE data for use. (Inverse of #3)Ex: decode_rle([3, 15, 6, 4]) yields list [15, 15, 15, 4, 4, 4, 4, 4, 4, 4].6. string_to_data(data_string) Translates a string in hexadecimal format into byte data (can be raw or RLE). (Inverse of #1)Ex: string_to_data (“3f64”) yields list [3, 15, 6, 4].7. to_rle_string(rle_data) Translates RLE data into a human-readable representation. For each run, in order, it should display the run length in decimal (1-2 digits); the run value in hexadecimal (1 digit); and a delimiter, ‘:’, between runs. (See examples in standalone section.)Ex: to_rle_string([15, 15, 6, 4]) yields string “15f:64”.8. string_to_rle(rle_string) Translates a string in human-readable RLE format (with delimiters) into RLE byte data. (Inverse of #7)Ex: string_to_rle(“15f:64”) yields list [15, 15, 6, 4].Submissions NOTE: Your output must match the example output *exactly*. If it does not, you will not receive full credit for your submission!File: initials_HW{nu m}.py Method: Submit on CanvasDo not submit any other files!HW 3A (10 points) For this assignment, students will set up the standalone menu alongside the 4 requirements listed on page 2 of this document. In addition to this, students should also set up menu options 1 (loading an image), 2 (loading specifically the test image), and 6 (displaying whatever image was loaded) in order to help grasp the bigger picture of the project.This involves correctly setting up the console_gfx.py file and utilizing its methods. You will use ConsoleGfx.display_image(…) to display images. Notice how it takes in a decoded list. This is the format in which you will locally (in your program) store any image data that you are working with. When the document mentions that something is “loaded” it means that something is stored as a list of flat (decoded) data.HW 3B (90 points)HW 4 (100 points) For this assignment, students will now complete the final 2 methods on page 3 of this document as well as the remainder of the project involving the menu options and understanding how all the individual methods are intertwined with each other. You will submit your whole program including the 8 methods listed above and the main method. We will only test your remaining 2 methods and the main method in HW4 .
HW 3 and 4: RLE with Images PythonOverview In this project students will develop routines to encode and decode data for images using run-length encoding (RLE). Students will implement encoding and decoding of raw data, conversion between data and strings, and display of information by creating procedures that can be called from within their programs and externally. This project will give students practice with loops, strings, Python lists, methods, and type-casting.Run-Length Encoding RLE is a form of lossless compression used in many industry applications, including imaging. It is intended to take advantage of datasets where elements (such as bytes or characters) are repeated several times in a row in certain types of data (such as pixel art in games). Black pixels often appear in long “runs” in some animation frames; instead of representing each black pixel individually, the color is recorded once, following by the number of instances.0 0 2 2 2 0 0 0 0 0 0 2 2 0_ 2 0 3 2 6 0 2 2 1 0_ For example, consider the first row of pixels from the pixel image of a gator (shown in Figure 1). The color black is “0”, and green is “2”:Flat (unencoded) data:Run-length encoded data: . Figure 1 – Gator Pixel Image The encoding for the entire image in RLE (in hexadecimal) – width, height, and pixels – is:2 0 3 2 6 0 2 2 2 0 1 2 1 F 1 0 7 2 1 A F 2 1 0 9 2 3 0 1 2 1 0 3 2 6 0 3 2 3 0 8 2 5 0 1 E |1 6 W/ H/ ——————————————PIXELS———————————————–/Image Formatting The images are stored in uncompressed / unencoded format natively. In addition, there are a few other rules to make the project more tractable:1. Images are stored as a list of numbers, with the first two numbers holding image width and height. 2. Pixels will be represented by a number between 0 and 15 (representing 16 unique colors).For example, the chubby smiley image (Figure 2) would contain the data shown in Figure 3.Figure 2 Figure 3 – Data for “Chubby Smiley” NOTE: Students do not need to work with the image file format itself – they only need to work with lists and encode or decode them. Information about image formatting is to provide context. Requirements Student programs must present a menu when run in standalone mode and must also implement several methods, defined below, during this assignment.Standalone Mode (Menu) When run as the program driver via the main() method, the program should:1) Display welcome message 2) Display color test (ConsoleGfx.test_rainbow) 3) Display the menu 4) Prompt for inputNote: for colors to properly display, it is highly recommended that student install the “CS1” theme on the project page.There are five ways to load data into the program that should be provided and four ways the program must be able to display data to the user.Loading a File Accepts a filename from the user and invokes ConsoleGfx.load_file(filename): Select a Menu Option: 1 Enter name of file to load: testfiles/uga.gfxLoading the Test Image Loads ConsoleGfx.test_image: Select a Menu Option: 2 Test image data loaded.Reading RLE String Reads RLE data from the user in decimal notation with delimiters (smiley example): Select a Menu Option: 3 Enter an RLE string to be decoded: 28:10:6B:10:10B:10:2B:10:12B:10:2B:10:5B:20:11B:10:6B:10Reading RLE Hex String Reads RLE data from the user in hexadecimal notation without delimiters (smiley example): Select a Menu Option: 4 Enter the hex string holding RLE data: 28106B10AB102B10CB102B105B20BB106B10Reading Flat Data Hex String Reads raw (flat) data from the user in hexadecimal notation (smiley example): Select a Menu Option: 5 Enter the hex string holding flat data: 880bbbbbb0bbbbbbbbbb0bb0bbbbbbbbbbbb0bb0bbbbb00bbbbbbbbbbb0bbbbbb0Displaying the Image Displays the current image by invoking the ConsoleGfx.display_image(image_data) method.Displaying the RLE String Converts the current data into a human-readable RLE representation (with delimiters): Select a Menu Option: 7 RLE representation: 28:10:6b:10:10b:10:2b:10:12b:10:2b:10:5b:20:11b:10:6b:10Note that each entry is 2-3 characters; the length is always in decimal, and the value in hexadecimal! Displaying the RLE Hex Data Converts the current data into RLE hexadecimal representation (without delimiters): Select a Menu Option: 8 RLE hex values: 28106b10ab102b10cb102b105b20bb106b10Displaying the Flat Hex Data Displays the current raw (flat) data in hexadecimal representation (without delimiters): Select a Menu Option: 9 Flat hex values: 880bbbbbb0bbbbbbbbbb0bb0bbbbbbbbbbbb0bb0bbbbb00bbbbbbbbbbb0bbbbbb0Class Methods Student classes are required to provide all of the following methods with defined behaviors. We recommend completing them in the following order:1. to_hex_string(data) Translates data (RLE or raw) a hexadecimal string (without delimiters). This method can also aid debugging.Ex: to_hex_string([3, 15, 6, 4]) yields string “3f64”.2. count_runs(flat_data) Returns number of runs of data in an image data set; double this result for length of encoded (RLE) list.Ex: count_runs([15, 15, 15, 4, 4, 4, 4, 4, 4]) yields integer 2.3. encode_rle(flat_data) Returns encoding (in RLE) of the raw data passed in; used to generate RLE representation of a data.Ex: encode_rle([15, 15, 15, 4, 4, 4, 4, 4, 4]) yields list [3, 15, 6, 4].4. get_decoded_length(rle_data) Returns decompressed size RLE data; used to generate flat data from RLE encoding. (Counterpart to #2)Ex: get_decoded_length([3, 15, 6, 4]) yields integer 9.5. decode_rle(rle_data) Returns the decoded data set from RLE encoded data. This decompresses RLE data for use. (Inverse of #3)Ex: decode_rle([3, 15, 6, 4]) yields list [15, 15, 15, 4, 4, 4, 4, 4, 4, 4].6. string_to_data(data_string) Translates a string in hexadecimal format into byte data (can be raw or RLE). (Inverse of #1)Ex: string_to_data (“3f64”) yields list [3, 15, 6, 4].7. to_rle_string(rle_data) Translates RLE data into a human-readable representation. For each run, in order, it should display the run length in decimal (1-2 digits); the run value in hexadecimal (1 digit); and a delimiter, ‘:’, between runs. (See examples in standalone section.)Ex: to_rle_string([15, 15, 6, 4]) yields string “15f:64”.8. string_to_rle(rle_string) Translates a string in human-readable RLE format (with delimiters) into RLE byte data. (Inverse of #7)Ex: string_to_rle(“15f:64”) yields list [15, 15, 6, 4].Submissions NOTE: Your output must match the example output *exactly*. If it does not, you will not receive full credit for your submission!File: initials_HW{nu m}.py Method: Submit on CanvasDo not submit any other files!HW 3A (10 points) For this assignment, students will set up the standalone menu alongside the 4 requirements listed on page 2 of this document. In addition to this, students should also set up menu options 1 (loading an image), 2 (loading specifically the test image), and 6 (displaying whatever image was loaded) in order to help grasp the bigger picture of the project.This involves correctly setting up the console_gfx.py file and utilizing its methods. You will use ConsoleGfx.display_image(…) to display images. Notice how it takes in a decoded list. This is the format in which you will locally (in your program) store any image data that you are working with. When the document mentions that something is “loaded” it means that something is stored as a list of flat (decoded) data.HW 3B (90 points)HW 4 (100 points) For this assignment, students will now complete the final 2 methods on page 3 of this document as well as the remainder of the project involving the menu options and understanding how all the individual methods are intertwined with each other. You will submit your whole program including the 8 methods listed above and the main method. We will only test your remaining 2 methods and the main method in HW4 .