这个作业是用Prolog完成线性回归相关的习题

COMP 3031 Assignment 3

PROLOG Programming

PART I:

Question 1.

Define a /2 predicate linear_regression (A, B) to represent the regression

line 𝑦 = 𝐴𝑥 + 𝐵 that is of the least-squares for a set of points (𝑥𝑖

, 𝑦𝑖

). The regression

line on a set of points is of the least-squares if the sum of the squares of the vertical

deviations from each data point to the line is the minimal out of all possible lines.

We will give the set of points in two /1 facts, xs and ys, where 𝑥𝑖

, and 𝑦𝑖

are

corresponding elements of the list in xs and ys.

Question 2.

Write a predicate interesting(X) to represent all interesting vertices X, if any, in

a given undirected graph. In other words, after issuing the query interesting(X),

we can get all interesting vertices one by one by keeping typing ‘;’ until all answers are

returned.

A vertex is interesting if it satisfies the following three conditions:

(1) It is sparse, i.e., its degree is less than or equal to 2.

(2) It is connected to at least two dense vertices (vertices whose degrees are greater

than 2), and its shortest paths to its two closest dense vertices are of the same

length.

(3) Its shortest path length to its two closest dense vertices is the shortest among

all other sparse vertices that satisfy condition (2).

Example:

In the graph given by facts edge, vertex A and F are dense, and B, C, D, E, G, and H

are sparse. B, C, E, H are not interesting vertices, because their shortest paths to their

two closest dense vertices A and F are not of equal length. G is an interesting vertex in

this graph, of which the shortest path is of length 1 to A and F. D is not interesting,

because its shortest path length to A and F is 2, which is greater than length 1 of G.

Question 3.

CH3 is a structure consisting of one C atom bound with three H atoms. Define a

predicate ch3(X) in which X is a list containing all C atoms that belong to the CH3

structures given in atom_elements. The order of the elements in the list is

unimportant.

Example query on the given compound toluene:

?- ch3(X).

X=[c7].

Question 4.

Define a predicate c6ring(X) in which X represents a list containing all six-C-atom

rings in the given atom_elements. Each six-C-atom ring is a list containing the six

C atoms that form the ring. The order of the C atoms in the list is unimportant, so each

six-C-atom ring occurs exactly once in the list of rings.

Example query on the given compound toluene:

?- c6ring(X).

X= [[c1,c2,c3,c4,c5,c6]].

**程序辅导定制C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB**

本网站支持 Alipay WeChatPay PayPal等支付方式

**E-mail:** vipdue@outlook.com **微信号:**vipnxx

如果您使用手机请先保存二维码，微信识别。如果用电脑，直接掏出手机果断扫描。