Question
Calculate Pearson's correlation coefficient () between the variables Weight and Head in the babyanth.complete data frame using the following formula. Include the correlation value you
Calculate Pearson's correlation coefficient () between the variables Weight and Head in the babyanth.complete data frame using the following formula. Include the correlation value you calculated in a comment. =()()=1()2=1()2=1
In the above equation,
is the number of babies or rows in the babyanth data frame = 1,2,3,.... and indexes each row or baby in the data frame and are the weight and head circumference measurements in the data frame is the mean of the weight measurements and is the mean of the head circumference measurements c. Create a matrix containing NA values called rmat using the following command: rmat <- matrix(NA, nrow = 4, ncol = 4). Use for loops to loop through th columns babyanth.complete data frame and calculate the Pearson's correlation coefficient between all possible pairs of variables in the dataset, i.e., all 16 pairs of variables (see below), and store all 16 Pearson's correlation coefficients in the matrix rmat. Copy and paste the output stored in rmat into a comment. All possible pairs of variables in the babyanth data frame
Weight and Weight, Weight and Head, Weight and Arm, and Weight and Length
Head and Weight, Head and Head, Head and Arm, and Head and Length,
Arm and Weight, Arm and Head, Arm and Arm, and Arm and Length,
Length and Weight, Length and Head, Length and Arm, and Length and Length
Note: All information have been provided above, I got no more information to provided but feel free to comment below hing that is unsure to you sir/madam. Thank you.
a) For a MIPS-32 processor executing a jump to subroutine, how are state and control passed between the function and the caller? Indicate what state is passed, but details of particular register numbers are not required. [5 marks] (b) On the MIPS-32 processor the flow of control can be changed using branch or jump instructions, or by three other mechanisms. What are the three other mechanisms for changing the flow of control and what are they used for? [6 marks] (c) What is a control hazard and what hardware and software techniques can be used to resolv control hazards? [5 marks] (d) Some instruction sets make all instructions conditional (e.g. the ARM) or have conditional move instructions (e.g. IA32). How can these conditional instructions be used to avoid control hazards? [4 marks] 4 CST.2009.5.5 5 Concurrent Systems and Applications (a) Reflection. (i) Give Java code fragments demonstrating two different ways of obtaining a Class object that describes an array of java.lang.Strings. [2 marks] (ii) Given an object x, write a Java expression that uses reflection to create a new objectatatype as x. [2 marks] (iii) The clone() method creates an exact object, including all of its fields. Briefly describe how you might implment this functionality using reflection, ignoring inherited fields. ssume that the object is not an array, has a zero-argument constructor, and contains only primitive fields. (You need not give code for an actual complete implmentation.) [4 marks] (b) Generics. (i) Suppose a class B is a subclass of A. Is the class Set a subclass of Set? Explain why or why not, with regard to type safety. [2 marks] (ii) The default clone method returns an Object that must be cast to the correct type. Using generics, give a declaration of a static myclone method that takes a single argument type and returns an object same type. [2 marks] (iii) T Contraste interface is used to compare objects. Its declaration is: interface{ boolean greaterThan(T obj1, T obj2); } Suppose we want to declare a class SortedList whose constructor takes a single ster argument that will be used to compare its elements. Give a declaration for the constructor that permits the choice of contraste implemntation to be as general as possible, and explain your reasoning. [4 marks] (c) Reference objects. The get() method PhantomReference class always returns null. Why is this so, and why must a PhantomReference always be used together with a ReferenceQueue? [4 marks] 5 (TURN OVER) CST.2009.5.6 6 Concurrent Systems and Applications (a) The following method is intended to return unique integer values to callers: volatile int x = 0; int getNext() { x = x + 1; return x; } (i) Two threads call getNext concurrently on same object. Explain how both threads can receive the result 1. [1 mark] (ii) Explain the semantics synchronized keyword in Java, and illustrate this by correcting getNext (you may ignore the possibility of integer overflow). [6 marks] (iii) Explain the meaning o volatile modifier. Explain whether or not you need to use it with your new impleentation of getNext. [2 marks] (b) The following method is intended to implment a barrier for synchronization between four threads. The first three threads to call the barrier method are meant to block. These threads are all unblocked when the fourth call is made. int barrierCount = 0; void synchronized barrier() throws InterruptedException { barrierCount ++; if (barrierCount < 4) { wait(); } else { notifyAll();
Game Description:
SaveMonkeys is a 2D game in a 10 x 10 grid maze map. Unfortunately, because of bushfire, the map will be in fire after a time limit. The goal is to move the player to save all Monkeys in the map and leave the map at the exit door within the time limit.
To simplify the design, assume each movement, or a step, of the play equals to one time unit. The maze map consists e following items:
An entrance to the maze, which is located at the bottom left grid. An exit maze, which is located at the top right grid. A player, who is place at the entrance at the beginning of a game. 5 monkeys, each of which is placed at a random grid. Some traps, each of which is placed at a random grid. Once in a trap, the player needs to use 10 steps to move out orap. Some magic fountains, each of which is placed at a random grid. Visiting/consuming a fountain can increase time limit by 6.
The followings are its key features and settings. To start a new game: 1. The player input an integer d, the difficulty level o game. d should be in the range of 0 - 10, and it has the default value of 5. 2. The player clicks a "Run" button to start the game, which triggers the random generation map.
Random generation map: 1. An entrance cell is placed at the bottom left cell. 2. An exit cell is placed at the top right cell. 3. A time limit, which is initially set up as 200 steps. 4. The player will appear in the entrance cell with the step counter as "0". 5. 5 monkeys are placed randomly in the map. 6. d traps are placed randomly in the map. 7. (10 - d) fountains are placed randomly in the map. 8. The entrance, exit, monkeys, traps, and fountains should not overlap.
To play a game: 1. The player can move in 4 directions: left, right, up, and down inside the map. Each movement is considered as 1 step, unless stated otherwise. 2. Moving out of a trap uses 10 steps. The trap remains there after the visit. 3. Visiting a fountain increases the time limit by 6. After the visit, the fountain is consumed, and the cell becomes empty. 4. Visiting a monkey saves 1 monkey. The monkey is picked up, and the cell becomes empty. 5. The game finishes when (Win) The player saves all 5 monkeys and is at the exit cell. The score is: (time limit - steps player). (Lose) The time limit has reached. The score is -1. 6. The score is shown at the end of a game.
Other requirements: The game can be played in the text UI in which the interaction is enabled by typing keywords, e.g. "u" for up and "d" for down. In the game, different items should be displayed with different icons/symbols. Time limit e map is displayed and updated during the play. Steps player is displayed and updated during the play. The number of saved monkeys is displayed and updated during the play. In the GUI, a player can play by clicking 4 control buttons. In the GUI, a "Help" button to get instructions on the game play. In the GUI, a "Save" button to save the game play as a .txt file. In the GUI, a "Load" button to load a saved game.
It is recommended that implment the 'engine' ogame first. Then should write some unit tests to check that the game logic works correctly.
Then can use JavaFX to add a graphical user interface (GUI) to the game, which displays the 2D board and allows the user to play the game. MUST use JavaFX, not any other Java GUI libraries.
Questions:
Question 1: Make a Data Design Decisions: Think carefully about whether each cell in the map should be a primitive value (like an integer or an enum value), or should it be an object? Using objects is more flexible, since it allows to use Java subtyping to make different cells have different behaviour.
Question 2 Impleent and Test the Game Engine: GameEngine.java is provided as the base for engine development. Need to add more details to it, and may also want to add other class files in the "savemonkeys.engine" package to support the engine development. TDD is recommended, but not necessary, to develop unit tests and game engine at the time, in parallel. Recall: Design a test for each new feature and check that it fails, then implement that feature in the engine classes and rerun the test to check that it now passes. Repeat... can refactor (rename and reorganise) the code at any stage, if see a way of making it simpler and more elegant. By the time have finished implementing the game engine, one (or several) of tests should be stepping through a complete game from start to end, calling the methods of your engine API and checking the results, including the game win/lose verdict at the end. 1. Text-based play: The main() method of GameEngine class should support a text-based game play in the console. 2. Class Relationships: engine needs to include several Java classes, with some association/composition relationships between them, and if possible, some inheritance/interface usage. Think about where can best use these Java features.
Question 3: Game GUI: The goal of this stage is to use JavaFX to add an elegant and fully functional GUI to the game so that it can more easily be played on desktop computers. GUI should have the following features:
event-handling of mouse events, including buttons for starting game and moving up/down/left/right;
display of bitmap images (recommend use some large images for the background whole game, and use some small images for different items/cells in the map, so that the game looks professional and entertaining);
multiple panels, with a main gaming panel to display the game, plus one or more panels around the edges to display game options, score information, and control and help buttons etc.;
a clean separation between the back-end (game engine) and front-end (GUI) classes using different Java package names, as described above;
Start by drawing one or two paper sketches GUI plan to build. Take a photo of each sketch, as will need to include these as well 1 Compiler Construction (a) Give two reasons why a compiler is typically broken down into passes (or phases) and indicate a typical set of passes and the data structures passed between them. [4 marks] (b) nd run within many browsers, might differ from that of compiling an application and running it multiple times on a single machine. [2 marks] (c) Explain the difference between a file textual assembly code and a file an object module. Indicate the essential structure object file, for example ELF, highlighting the purpose of each section. Give assemblylevel or C-level code that produces entries in each ese sections. [7 marks] (d) Explain the actions of a linker, the role of libraries and what makes certain object files directly executable. [4 marks] (e) Explain the difference between static and dynamic linking giving one advantage of each. Which is most appropriate for an applet stored on a web site to be loaded into a browser? [3 marks] 2 CST.2009.5.3 2 Compiler Construction Consider an ML-like language in which the set of values includes functions and these functions may have nested definitions. (a) Explain how a function value may be represented at run-time, both in a syntaxtree interpreter and in compiled code. What is the importance word "nested" above? [3 marks] (b) Give an example program that gives different results in static and dynamic scoping. In each case, explain how an interpreter or compiled code might perform function application. [3 marks] (c) Considering only static scoping from now on, explain what restrictions are necessary to implment function values without using an auxiliary heap. Explain the notions of static and dynamic chains, giving an example of a situation in which they differ (i.e. reference to the wrong one would access the wrong variable). Illustrate how updating (by assignment to) a free variable can be impleented. [5 marks] (d) Give an alternative heap-based implmentation for function values when the restrictions in part (c) do not hold. Explain how free variables (and particularly their update) can now be impleented. [4 marks] (e) Java normally holds local variables in stack frames and instance variables on the heap. Consider a Java-like language with nested classes, and a possible program form: class C { int f(int x) { class D { int addx(int y) { return x+y; } void updtx(int y) { x = y; } } ...
b. Calculate Pearson's correlation coefficient () between the variables Weight and Head in the babyanth.complete data frame using the following formula. Include the correlation value you calculated in a comment. =()()=1()2=1()2=1
In the above equation,
is the number of babies or rows in the babyanth data frame = 1,2,3,.... and indexes each row or baby in the data frame and are the weight and head circumference measurements in the data frame is the meaneight measurements and is the mean of the head circumference measurements c. Create a matrix containing NA values called rmat using the following command: t <- matrix(NA, nrow = 4, ncol = 4). Use for loops to loop through th columns of the babyanth.complete data frame and calculate the Pearson's correlation coefficient between all possible pairs of variables in the dataset, i.e., all 16 pairs of variables (see below), and store all 16 Pearson's correlation coefficients in the matrix rmat. Copy and paste the output stored in rmat into a comment. All possible pairs of variables in the babyanth data frame
Weight and Weight, Weight and Head, Weight and Arm, and Weight and Length,
Head and Weight, Head and Head, Head and Arm, and Head and Length,
Arm and Weight, Arm and Head, Arm and Arm, and Arm and Length,
Length and Weight, Length and Head, Length and Arm, and Length and Length
Note: All information have been provided above, I got no more information to provided but feel free to comment below anything that is unsure to you sir/madam. Thank you.
a) For a MIPS-32 processor executing a jump to subroutine, how are state and control passed between the function and the caller? Indicate what state is passed, but details of particular register numbers are not required. [5 marks] (b) On the MIPS-32 processor the flow of control can be changed using branch or jump instructions, or by three other mechanisms. What are the three other mechanisms for changing the flow of control and what are they used for? [6 marks] (c) What is a control hazard and what hardware and software techniques can be used to r control hazards? [5 marks] (d) Some instruction sets make all instructions conditional (e.g. the ARM) or have conditional move instructions (e.g. IA32). How can these conditional instructions be used to avoid control hazards? [4 marks] 4 CST.2009.5.5 5 Concurrent Systems and Applications (a) Reflection. (i) Give Java code fragments demonstrating two different ways of obtaining a Class object that describes an array of java.lang.Strings. [2 marks] (ii) Given an object x, write a Java expression that uses reflection to create a new object same datatype as x. [2 marks] (iii) The clone() method creates an exact ject, including all of its fields. Briefly describe how you might impleent this functionality using reflection, ignoring inherited fields. Assume that the object is not an array, has a zero-argument constructor, and contains only primitive fields. (You need not give code for an actual complete implmentation.) [4 marks] (b) Generics. (i) Suppose a class B is a subclass of A. Is the class Set a subclass of Set? Explain why or why not, with regard to type safety. [2 marks] (ii) The default clone method returns an Object that must be cast to the correct type. Using generics, give a declaration of a static myclone method that takes a single argument \ any type and returns an object same type. [2 marks] (iii) Ther interface is used to compare objects. Its declaration is: interfacer { boolean greaterThan(T obj1, T obj2); } Suppose we want to declare a class SortedList whose constructor takes a singContrastr argument that will be used to compare its elements. Give a declaration for the constructor that permits the choice of contraste implmentation to be as general as possible, and explain your reasoning. [4 marks] (c) Reference objects. The get() method PhantomReference class always returns null. Why is this so, and why must a PhantomReference always be used together with a ReferenceQueue? [4 marks] 5 (TURN OVER) CST.2009.5.6 6 Concurrent Systems and Applications (a) The following method is intended to return unique integer values to callers: volatile int x = 0; int getNext() { x = x + 1; return x; } (i) Two threads call getNext concurrently on t object. Explain how both threads can receive the result 1. [1 mark] (ii) Explain the semanticssynchronized keyword in Java, and illustrate this by correcting getNext (you may ignore the possibility of integer overflow). [6 marks] (iii) Explain the meaning e volatile modifier. Explain whether or not you need to use it with your new imlementation of getNext. [2 marks] (b) The following method is intended to impement a barrier for synchronization between four threads. The first three threads to call the barrier method are meant to block. These threads are all unblocked when the fourth call is made. int barrierCount = 0; void synchronized barrier() throws InterruptedException { barrierCount ++; if (barrierCount < 4) { wait(); } else { notifyAll();
Game Description:
SaveMonkeys is a 2D game in a 10 x 10 grid maze map. Unfortunately, because of bushfire, the map will be in fire after a time limit. The goal is to move the player to save all Monkeys in the map and leave the map at the exit door within the time limit.
To simplify the design, assume each movement, or a step, of the play equals to one time unit. The maze map consistsollowing items:
An entrance to the maze, which is located at the bottom left grid. An exit maze, which is located at the top right grid. A player, who is place at the entrance at the beginning of a game. 5 monkeys, each of which is placed at a random grid. Some traps, each of which is placed at a random grid. Once in a trap, the player needs to use 10 steps to move out rap. Some magic fountains, each of which is placed at a random grid. Visiting/consuming a fountain can increase time limit by 6.
The followings are its key features and settings. To start a new game: 1. The player input an integer d, the difficulty level game. d should be in the range of 0 - 10, and it has the default value of 5. 2. The player clicks a "Run" button to start the game, which triggers the random generation map.
Random generation map: 1. An entrance cell is placed at the bottom left cell. 2. An exit cell is placed at the top right cell. 3. A time limit, which is initially set up as 200 steps. 4. The player will appear in the entrance cell with the step counter as "0". 5. 5 monkeys are placed randomly in the map. 6. d traps are placed randomly in the map. 7. (10 - d) fountains are placed randomly in the map. 8. The entrance, exit, monkeys, traps, and fountains should not overlap.
To play a game: 1. The player can move in 4 directions: left, right, up, and down inside the map. Each movement is considered as 1 step, unless stated otherwise. 2. Moving out of a trap uses 10 steps. The trap remains there after the visit. 3. Visiting a fountain increases the time limit by 6. After the visit, the fountain is consumed, and the cell becomes empty. 4. Visiting a monkey saves 1 monkey. The monkey is picked up, and the cell becomes empty. 5. The game finishes when (Win) The player saves all 5 monkeys and is at the exit cell. The score is: (time limit - steps player). (Lose) The time limit has reached. The score is -1. 6. The score is shown at the end of a game.
Other requirements: The game can be played in the text UI in which the interaction is enabled by typing keywords, e.g. "u" for up and "d" for down. In the game, different items should be displayed with different icons/symbols. Time limit map is displayed and updated during the play. Steps o player is displayed and updated during the play. The number of saved monkeys is displayed and updated during the play. In the GUI, a player can play by clicking 4 control buttons. In the GUI, a "Help" button to get instructions on the game play. In the GUI, a "Save" button to save the game play as a .txt file. In the GUI, a "Load" button to load a saved game.
It is recommended that impleent the 'engine' game first. Then should write some unit tests to check that the game logic works correctly.
Then can use JavaFX to add a graphical user interface (GUI) to the game, which displays the 2D board and allows the user to play the game. MUST use JavaFX, not any other Java GUI libraries.
Questions:
Question 1: Make a Data Design Decisions: Think carefully about whether each cell in the map should be a primitive value (like an integer or an enum value), or should it be an object? Using objects is more flexible, since it allows to use Java subtyping to make different cells have different behaviour.
Question 2 Implement and Test the Game Engine: GameEngine.java is provided as the base for engine development. Need to add more details to it, and may also want to add other class files in the "savemonkeys.engine" package to support the engine development. TDD is recommended, but not necessary, to develop unit tests and game engine attime, in parallel. Recall: Design a test for each new feature and check that it fails, then implement that feature in the engine classes and rerun the test to check that it now passes. Repeat... can refactor (rename and reorganise) the code at any stage, if see a way of making it simpler and more elegant. By the time have finished implemnting the game engine, one (or several) of tests should be stepping through a complete game from start to end, calling the methods of your engine API and checking the results, including the game win/lose verdict at the end. 1. Text-based play: The main() method of GameEngine class should support a text-based game play in the console. 2. Class Relationships: engine needs to include several Java classes, with some association/composition relationships between them, and if possible, some inheritance/interface usage. Think about where can best use these Java features.
Question 3: Game GUI: The goal of this stage is to use JavaFX to add an elegant and fully functional GUI to the game so that it can more easily be played on desktop computers. GUI should have the following features:
event-handling of mouse events, including buttons for starting game and moving up/down/left/right;
display of bitmap images (recommend use some large images for the background o whole game, and use some small images for different items/cells in the map, so that the game looks professional and entertaining);
multiple panels, with a main gaming panel to display the game, plus one or more panels around the edges to display game options, score information, and control and help buttons etc.;
a clean separation between the back-end (game engine) and front-end (GUI) classes using different Java package names, as described above;
Start by drawing one or two paper sketches GUI plan to build. Take a photo of each sketch, as will need to include these as well 1 Compiler Construction (a) Give two reasons why a compiler is typically broken down into passes (or phases) and indicate a typical set of passes and the data structures passed between them. [4 marks] (b) nd run within many browsers, might differ from that of compiling an application and running it multiple times on a single machine. [2 marks] (c) Explain the difference between a textual assembly code and a aining an object module. Indicate the essential structure object file, for example ELF, highlighting the purpose of each section. Give assemblylevel or C-level code that produces entries in eachse sections. [7 marks] (d) Explain the actions of a linker, the role of libraries and what makes certain object files directly executable. [4 marks] (e) Explain the difference between static and dynamic linking giving one advantage of each. Which is most appropriate for an applet stored on a web site to be loaded into a browser? [3 marks] 2 CST.2009.5.3 2 Compiler Construction Consider an ML-like language in which the set of values includes functions and these functions may have nested definitions. (a) Explain how a function value may be represented at run-time, both in a syntaxtree interpreter and in compiled code. What is the importance word "nested" above? [3 marks] (b) Give an example program that gives different results in static and dynamic scoping. In each case, explain how an interpreter or compiled code might perform function application. [3 marks] (c) Considering only static scoping from now on, explain what restrictions are necessary to implment function values without using an auxiliary heap. Explain the notions of static and dynamic chains, giving an example of a situation in which they differ (i.e. reference to the wrong one would access the wrong variable). Illustrate how updating (by assignment to) a free variable can be impleented. [5 marks] (d) Give an alternative heap-based implmentation for function values when the restrictions in part (c) do not hold. Explain how free variables (and particularly their update) can now be impemented. [4 marks] (e) Java normally holds local variables in stack frames and instance variables on the heap. Consider a Java-like language with nested classes, and a possible program form: class C { int f(int x) { class D { int addx(int y) { return x+y; } void updtx(int y) { x = y; } } ... } }; Explain a possible imlementation of such nested classes based on your answers above; also give and justify a restriction on methods like updtx that eases the cost of implemntation. [5 marks] 3 (TURN OVER) CST.2009.5.4 3 Computer Design (a) Why are control-flow machines sensitive to memory access latency? [4 marks] (b) What statistical properties of data access patterns do caches exploit to reduce memory access latency? [4 marks] (c) What cache line replacement policies might be used for set-associative and direct-mapped caches? [4 marks] (d) What are two write-back policies for a cache? [4 marks] (e) What does a snoopy cache do in a dual-core machine? [4 marks] 4 Computer Design (a) For a MIPS-32 processor executing a jump to subroutine, how are state and control passed between the function and the caller? Indicate what state is passed, but details of particular register numbers are not required. [5 marks] (b) On the MIPS-32 processor the flow of control can be changed using branch or jump instructions, or by three other mechanisms. What are the three other mechanisms for changing the flow of control and what are they used for? [6 marks] (c) What is a control hazard and what hardware and software techniques can be used to resolve control hazards? [5 marks] (d) Some instruction sets make all instructions conditional (e.g. the ARM) or have conditional move instructions (e.g. IA32). How can these conditional instructions be used to avoid control hazards? [4 marks] 4 CST.2009.5.5 5 Concurrent Systems and Applications (a) Reflection. (i) Give Java code fragments demonstrating two different ways of obtaining a Class object that describes an array of java.lang.Strings. [2 marks] (ii) Given an object x, write a Java expression that uses reflection to create a new object same datatype as x. [2 marks] (iii) The clone() method creates a copy object, including all of its fields. Briefly describe how you might implment this functionality using reflection, ignoring inherited fields. Assume that the object is not an array, has a zero-argument constructor, and contains only primitive fields. (You need not give code for an actual complete iplementation.) [4 marks] (b) Generics. (i) Suppose a class B is a subclass of A. Is the class Set a subclass of Set? Explain why or why not, with regard to type safety. [2 marks] (ii) The default clone method returns an Object that must be cast to the correct type. Using generics, give a declaration of a static myclone method that takes a single argument type and returns an object same type. [2 marks] (iii) The Contrastterface is used to compares. Its declaration is: interface Contrastr { boolean greaterThan(T obj1, T obj2); } Suppose we want to declare a class SortedList whose constructor takes a single Contrast argument that will be used to compare its elements. Give a declaration for the constructor that permits the choice of contrast imlementation to be as general as possible, and explain your reasoning. [4 marks] (c) Reference objects. The get() method antomReference class always returns null. Why is this so, and why must a PhantomReference always be used together with a ReferenceQueue? [4 marks] 5 (TURN OVER) CST.2009.5.6 6 Concurrent Systems and Applications (a) The following method is intended to return unique integer values to callers: volatile int x = 0; int getNext() { x = x + 1; return x; } (i) Two threads call getNext concurrently on object. Explain how both threads can receive the result 1. [1 mark] (ii) Explain the semanticssynchronized keyword in Java, and illustrate this by correcting getNext (you may ignore the possibility of integer overflow). [6 marks] (iii) Explain the meaning volatile modifier. Explain whether or not you need to use it with your new implmentation of getNext. [2 marks] (b) The following method is intended to implemnt a barrier for synchronization between four threads. The first three threads to call the barrier method are meant to block. These threads are all unblocked when the fourth call is made. int barrierCount = 0; void synchronized barrier() throws InterruptedException { barrierCount ++; if (barrierCount < 4) { wait(); } else {
Create a data frame called babyanth.complete that contains the complete cases.
b. Calculate Pearson's correlation coefficient () between the variables Weight and Head in the babyanth.complete data frame using the following formula. Include the correlation value you calculated in a comment. =()()=1()2=1()2=1
In the above equation,
is the number of babies or rows in the babyanth data frame = 1,2,3,.... and indexes each row or baby in the data frame and are the weight and head circumference measurements in the data frame is the mean weight measurements and is the mean of the head circumference measurements c. Create a matrix containing NA values called rmat using the following command: <- matrix(NA, nrow = 4, ncol = 4). Use for loops to loop through the columns of the babyanth.complete data frame and calculate the Pearson's correlation coefficient between all possible pairs of variables in the dataset, i.e., all 16 pairs of variables (see below), and store all 16 Pearson's correlation coefficients in the matrix rmat. Copy and paste the output stored in rmat into a comment. All possible pairs of variables in the babyanth data frame
Weight and Weight, Weight and Head, Weight and Arm, and Weight and Length,
Head and Weight, Head and Head, Head and Arm, and Head and Length,
Arm and Weight, Arm and Head, Arm and Arm, and Arm and Length,
Length and Weight, Length and Head, Length and Arm, and Length and Length } }; Explain a possible implmentation of such nested classes based on your answers above; also give and justify a restriction on methods like updtx that eases the cost of implmentation. [5 marks] 3 (TURN OVER) CST.2009.5.4 3 Computer Design (a) Why are control-flow machines sensitive to memory access latency? [4 marks] (b) What statistical properties of data access patterns do caches exploit to reduce memory access latency? [4 marks] (c) What cache line replacement policies might be used for set-associative and direct-mapped caches? [4 marks] (d) What are two write-back policies for a cache? [4 marks] (e) What does a snoopy cache do in a dual-core machine? [4 marks] 4 Computer Design (a) For a MIPS-32 processor executing a jump to subroutine, how are state and control passed between the function and the caller? Indicate what state is passed, but details of particular register numbers are not required. [5 marks] (b) On the MIPS-32 processor the flow of control can be changed using branch or jump instructions, or by three other mechanisms. What are the three other mechanisms for changing the flow of control and what are they used for? [6 marks] (c) What is a control hazard and what hardware and software techniques can be used to resolve control hazards? [5 marks] (d) Some instruction sets make all instructions conditional (e.g. the ARM) or have conditional move instructions (e.g. IA32). How can these conditional instructions be used to avoid control hazards? [4 marks] 4 CST.2009.5.5 5 Concurrent Systems and Applications (a) Reflection. (i) Give Java code fragments demonstrating two different ways of obtaining a Class object that describes an array of java.lang.Strings. [2 marks] (ii) Given an object x, write a Java expression that uses reflection to create a new object same datatype as x. [2 marks] (iii) The clone() method creates an exct copy object, including all of its fields. Briefly describe how you might implment this functionality using reflection, ignoring inherited fields. Assume that the object is not an array, has a zero-argument constructor, and contains only primitive fields. (You need not give code for an actual complete implmentation.) [4 marks] (b) Generics. (i) Suppose a class B is a subclass of A. Is the class Set a subclass of Set? Explain why or why not, with regard to type safety. [2 marks] (ii) The default clone method returns an Object that must be cast to the correct type. Using generics, give a declaration of a static myclone method that takes a single argument of type and returns an object same type. [2 marks] (iii) The Contraste interface is used to compare objects. Its declaration is: interface Contraste { boolean greaterThan(T obj1, T obj2); } Suppose we want to declare a class SortedList whose constructor takes a single Contrster argument that will be used to compare its elements. Give a declaration for the constructor that permits the choice of contrastr impleentation to be as general as possible, and explain your reasoning. [4 marks] (c) Reference objects. The get() method oPhantomReference class always returns null. Why is this so, and why must a PhantomReference always be used together with a ReferenceQueue? [4 marks] 5 (TURN OVER) CST.2009.5.6 6 Concurrent Systems and Applications (a) The following method is intended to return unique integer values to callers: volatile int x = 0; int getNext() { x = x + 1; return x; } (i) Two threads call getNext concurrently onobject. Explain how both threads can receive the result 1. [1 mark] (ii) Explain the semantics synchronized keyword in Java, and illustrate this by correcting getNext (you may ignore the possibility of integer overflow). [6 marks] (iii) Explain the meaning e volatile modifier. Explain whether or not you need to use it with your new implmentation of getNext. [2 marks] (b) The following method is intended to impement a barrier for synchronization between four threads. The first three threads to call the barrier method are meant to block. These threads are all unblocked when the fourth call is made. int barrierCount = 0; void synchronized barrier() throws InterruptedException { barrierCount ++; if (barrierCount < 4) { wait(); } else {
Create a data frame called babyanth.complete that contains the complete cases.
b. Calculate Pearson's correlation coefficient () between the variables Weight and Head in the babyanth.complete data frame using the following formula. Include the correlation value you calculated in a comment. =()()=1()2=1()2=1
In the above equation,
is the number of babies or rows in the babyanth data frame = 1,2,3,.... and indexes each row or baby in the data frame and are the weight and head circumference measurements in the data frame is the mean o weight measurements and is the mean of the head circumference measurements c. Create a matrix containing NA values called rmat using the following command:matrix(NA, nrow = 4, ncol = 4). Use for loops to loop throug the columns babyanth.complete data frame and calculate the Pearson's correlation coefficient between all possible pairs of variables in the dataset, i.e., all 16 pairs of variables (see below), and store all 16 Pearson's correlation coefficients in the matrix rmat. Copy and paste the output stored in rmat into a comment. All possible pairs of variables in the babyanth data frame
Weight and Weight, Weight and Head, Weight and Arm, and Weight and Length,
Head and Weight, Head and Head, Head and Arm, and Head and Length,
Arm and Weight, Arm and Head, Arm and Arm, and Arm and Length,
Length and Weight, Length and Head, Length and Arm, and Length and Length
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started