R代做編程輔導(dǎo):CSC120 Euclidean Minimum Weight Matching
全文鏈接:tecdat.cn/?p=29686 Introduction Toronto的R語言作業(yè),和Toronto的其他作業(yè)一樣,屬于難度不高,但是細心度要求非常高,稍有不慎就會丟分。另外規(guī)矩也是一大堆,comment/docs/coding style什么的僅僅是最基本的要求而已。 一共寫6個函數(shù),運行后需要畫10張圖,然后找其中最優(yōu)的歐氏距離。 調(diào)試方面,R語言還是比較方便的,打印變量、畫圖等,不過相對的,由于沒有方便的IDE支持,編程速度相比C/C++,Java,Python倒是慢了不少。 Requirement You should use an R script for grouping up all dots in a vector including an even number of dots in this assignment, in a way that tries to minimize the sum of the distances between the dots in each of the pairs. This problem can arise in many contexts, including design of experiments in statistics. Doing this will provide practice in basic R scriptming facilities such as vectors and matrices, and use of if and for, in use of R’s plotting facilities, and in how to divide a script into several functions that can be understood and sometimes used separately. The output of the script is a vector of pairs of input dots, with each of the input dots being in exactly one pair. The order of the pairs and the order of dots in each pair are not important. The objective is to try to find a vector of pairs for which the total of the distances from one dot in a pair to the other is small. Ideally, this total distance would be as small as possible, but the method used in this assignment is not guaranteed to find a vector of groupings that achieve this minimum, it just tries to make the total distance as small as it can. The input for this problem is a vector of n dots in k-dimensional Euclidean space. The number of dots, n, will always be even. For the actual data you will work with, k is two, so the input is a vector of dots in the plane, but except for the 2-dimensional plotting function described below, your script should work for any dimensionality, k, and for any even number of dots, n. We also must specify how a function to find the groupings will work. For this assignment, you should write a function called find_groupings that can be called with a single argument that is a matrix of dots, as specified above, and which will return as its value a matrix giving the pairs of dots that we hope have a small total distance. (Below, some additional optional arguments to find_groupings will be specified.) In designing this script, we must decide how to represent the input (a vector of dots) as an R data structure. For this assignment, we will use an n by k matrix, in which each row represents a dot in k-dimensional Euclidean space. We must also decide how to represent the vector of pairs of dots that is the output. We will use an n=2 by 2 matrix for this, in which each row contains two integers between 1 and n, which index the rows for the two dots in the input matrix. For this assignment, you should test your script on a vector of 60 dots in 2-dimensional Euclidean space that you can read as a matrix as follows (storing it in a variable called data): Summary 對這門課的TA還是槽點滿滿,竟然最終沒有拿到滿分。多大的Prof和TA出的題,堪比世界第一惡心。 雖然嚴格要求編程習慣是好事,但是過于嚴格就有點過了。大部分編程習慣完全可以靠一個優(yōu)秀的IDE自動調(diào)整來完成。而且時間浪費在調(diào)整格式、代碼規(guī)范上面,真的值得嗎?