Question: please provide the code in racket programming language. I only need answer for question1. Programming Rules Submit one Racket file named as hw 3-net-id).rkt. lang


Programming Rules Submit one Racket file named as hw 3-net-id).rkt. lang racket (provide (all-defined-out)) ;; for us to test (require racket/trace) ii in case you want to use tracing (require "PTS.rkt) i to access the database of points . You are only allowed to use functions, if-then-else, cond, list operations, operations on numbers. No imperative-style constructs, such as begin-end or explicitly variable assignments, such as get/setare allowed. If you do not follow the guidelines, your submission will not be graded. If you are in doubt that you are using some construct that may violate rules, please contact instructor/TA (post on Piazza You are expected to test your code extensively. If your implementation fails any assessment test, then points will be deducted. Almost correct is equivalent to incorrect solution for which partial credits, if any, will depend only on the number of assessment tests it successfully passes. The focus is on correct implementation. In this assignment, we will not assess the efficiency, however, avoid re-computations and use tail recursion, if possible. . Please comment your test code (e.s., trace directives, test cases) in your submission file. Questions Given two variables, (explanatory variable) and y (dependent variable), linear regression analysis aims to model the dependency of yon (using a line, hence the name linear). For the purpose of discussion of this problem-specification, consider the coordinates in a 2-D plan. where the coordinates of the points indicate the valuations of -variable and the y-coordinates of the points indicates the corresponding valuations of y variable. For instance, the data contains n points in the plane, represented as (2.). (22.2).. ( ). For linear regression of yon r. our objective is to obtain a line y=mx+in particular the values of m (slope) and (intercept), such that the points on this line "closely reflect the data. That is = m +cis a reflection of when is equal to To realize the objective, we need to minimize the overall error in predicting the value of y for a given value of .ie E-! :-)- -(mx + c)2 (1) 1. The result is the least squares method for computing the values of mand, which minimizes E. The method computes mand c as follows: 3 1)(-5) +-2) and c= y -m. In the above, and y denote the mean of the ris and is respectively. For example, if the points are (0,0), (1, 1), (2.2), then m 1 and c 0. If the points are (1.0), (2,1),(3,2). then m l and c -1. You are given a set of points in a Racket file PTS.rkt: (define ptal '[(01) (2 3) (1 0) (3 3) (5 O))) (define pts2 '(( 0) (1 l) (22) (3 3))) (define pts 3 ( 0) (2 l) (32) (4 3))) Write a function compute.me that takes as arguments the list of points and returns a list contain ing two elements: the first element is the valuation of m and the second that ofc. compute.me implements the least squares method. For example, > (compute_mc ptsl) (-0.02702702702702699 1.4594594594594592) > (compute_mc pts2) (1.0 0.0) > (compute_mc pts 3) (1.0 -1.0) 2. We have applied least squares method for regression analysis in the previous question. However, this method may not be suitable for situation, where the number of dependent variables is greater than one. A general technique is based on iteratively refining m and starting from some approximate solutions (c.g., for both m and c), with the objective of reducing the E. The iterative refinement takes into consideration three parameters that decide the termination condi tion: the learning rate L, the error-margine and the maximum number of times the refinement can be performed ant. Intuitively, I describes the degree of refinement in cach step and describes the closeness of the refined result to the expected result. The steps of the iterative refinement method is as follows (a) Initialize m and both to 0.0. (b) if E (as per Equation 1) is less than c(error margin) or the number of iteration already performed is greater than equal to cnt, then terminate. The current values of m and care used to describe the regression line (c) Otherwise, i update the value of mto m-LXd where ii. update the value of cto c-LX . where dE -2 -) (d) Repeat from step (b) This technique is called gradient descent Write a function gradient me that takes as argument the list of points, the parameters correspond ing to L and e, and the parameter ent corresponding to the maximum number of times the iterative refinement can be performed, and returns a list containing three elements: the first element is the valuation of m, the second that of, and the third element is corresponding the valuations of m and c. The function implements gradient descent iterative technique as described above. For example for the same set of points pt sl, pt s2, pts3. > (gradient_mc pt si 0.001 0.01 5000) (-0.015042330628280118 1.4188766008006697 1.8384651009912811) > (gradient_mc pt s2 0.001 0.01 5000) . (0.9222504727270914 0.16598399730907806 0.009992616854817024) > (gradient_mc pt s3 0.001 0.01 5000) (0.908583804857839 -0.7312252383800322 0.0120649477031 99078) Programming Rules Submit one Racket file named as hw 3-net-id).rkt. lang racket (provide (all-defined-out)) ;; for us to test (require racket/trace) ii in case you want to use tracing (require "PTS.rkt) i to access the database of points . You are only allowed to use functions, if-then-else, cond, list operations, operations on numbers. No imperative-style constructs, such as begin-end or explicitly variable assignments, such as get/setare allowed. If you do not follow the guidelines, your submission will not be graded. If you are in doubt that you are using some construct that may violate rules, please contact instructor/TA (post on Piazza You are expected to test your code extensively. If your implementation fails any assessment test, then points will be deducted. Almost correct is equivalent to incorrect solution for which partial credits, if any, will depend only on the number of assessment tests it successfully passes. The focus is on correct implementation. In this assignment, we will not assess the efficiency, however, avoid re-computations and use tail recursion, if possible. . Please comment your test code (e.s., trace directives, test cases) in your submission file. Questions Given two variables, (explanatory variable) and y (dependent variable), linear regression analysis aims to model the dependency of yon (using a line, hence the name linear). For the purpose of discussion of this problem-specification, consider the coordinates in a 2-D plan. where the coordinates of the points indicate the valuations of -variable and the y-coordinates of the points indicates the corresponding valuations of y variable. For instance, the data contains n points in the plane, represented as (2.). (22.2).. ( ). For linear regression of yon r. our objective is to obtain a line y=mx+in particular the values of m (slope) and (intercept), such that the points on this line "closely reflect the data. That is = m +cis a reflection of when is equal to To realize the objective, we need to minimize the overall error in predicting the value of y for a given value of .ie E-! :-)- -(mx + c)2 (1) 1. The result is the least squares method for computing the values of mand, which minimizes E. The method computes mand c as follows: 3 1)(-5) +-2) and c= y -m. In the above, and y denote the mean of the ris and is respectively. For example, if the points are (0,0), (1, 1), (2.2), then m 1 and c 0. If the points are (1.0), (2,1),(3,2). then m l and c -1. You are given a set of points in a Racket file PTS.rkt: (define ptal '[(01) (2 3) (1 0) (3 3) (5 O))) (define pts2 '(( 0) (1 l) (22) (3 3))) (define pts 3 ( 0) (2 l) (32) (4 3))) Write a function compute.me that takes as arguments the list of points and returns a list contain ing two elements: the first element is the valuation of m and the second that ofc. compute.me implements the least squares method. For example, > (compute_mc ptsl) (-0.02702702702702699 1.4594594594594592) > (compute_mc pts2) (1.0 0.0) > (compute_mc pts 3) (1.0 -1.0) 2. We have applied least squares method for regression analysis in the previous question. However, this method may not be suitable for situation, where the number of dependent variables is greater than one. A general technique is based on iteratively refining m and starting from some approximate solutions (c.g., for both m and c), with the objective of reducing the E. The iterative refinement takes into consideration three parameters that decide the termination condi tion: the learning rate L, the error-margine and the maximum number of times the refinement can be performed ant. Intuitively, I describes the degree of refinement in cach step and describes the closeness of the refined result to the expected result. The steps of the iterative refinement method is as follows (a) Initialize m and both to 0.0. (b) if E (as per Equation 1) is less than c(error margin) or the number of iteration already performed is greater than equal to cnt, then terminate. The current values of m and care used to describe the regression line (c) Otherwise, i update the value of mto m-LXd where ii. update the value of cto c-LX . where dE -2 -) (d) Repeat from step (b) This technique is called gradient descent Write a function gradient me that takes as argument the list of points, the parameters correspond ing to L and e, and the parameter ent corresponding to the maximum number of times the iterative refinement can be performed, and returns a list containing three elements: the first element is the valuation of m, the second that of, and the third element is corresponding the valuations of m and c. The function implements gradient descent iterative technique as described above. For example for the same set of points pt sl, pt s2, pts3. > (gradient_mc pt si 0.001 0.01 5000) (-0.015042330628280118 1.4188766008006697 1.8384651009912811) > (gradient_mc pt s2 0.001 0.01 5000) . (0.9222504727270914 0.16598399730907806 0.009992616854817024) > (gradient_mc pt s3 0.001 0.01 5000) (0.908583804857839 -0.7312252383800322 0.0120649477031 99078)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
