Write a simple machine learning program. In the first training stage, we train a model.
In the second prediction stage we classify inputs according to the model we trained.
Task Description
An image classifier classifies input images into two categories -- accept and reject. An Image is an M by M array P of pixels, where each pixel p{i, j} is either zero or one. A classifier determines which category an image belongs to based on a function value h of all pixels of this image. There is a weight w{i,j} for every pixel p{i,j}, and the h function value of an image is the sum of products of all pixel values with their corresponding weights.(h(P) = \sum{i,j} p{i, j} w{i, j}) If the h value is no less than a threshold T, which is 2M^2, then the model accepts the image, otherwise it rejects the image.
The classifier starts with an initial weights of all 1's, then modify the them according to a set of N train inputs. Each input is an M by M array of 0 or 1's, and has a label of either accept or reject. If the model from the current set of weights gives the same result as the label of the input image, then we do nothing. Otherwise we have two cases. In the first case the classifier accept the input but the label is reject. Then we divide the weight of those non-zero pixel by 2, and set the weight to 1 if the the division gives 0. In the second case the classifier rejects the input but the label is accept. Then we multiply the weight of those non-zero pixel by 2.
After we train our model we use it to classify another set of Q test inputs. We evaluate the h function using the weights we obtained in the previous stage, and accept the input if the h value is no less than the threshold, and reject the input otherwise.
There is one test case. Each test case has two parts.
In the first part, the training data set contains N images. The first line contains two integers N, M, representing that there are N images which size is M x M as follows: Each image contains M+1 lines. In M+1 lines, the first line contains an integer C, representing the result of each images. In following M lines, each line contains M integers.
In the second part, the query data set contains Q images. The first line contains an integer Q, representing Q images as follows: Each images contains M lines. Each line contains M integers.
只有一組測資。每一組測資分成兩個部份。
第一部份為訓練資料,第一行有兩個整數 N、M,表示接下來會有 N 張 M x M 的 1-bit color 圖片。接下來有 N 組圖片資訊,每一組圖片資訊有 M+1 行,每一組第一行為分類結果 C,接著的 M 行上分別 M 個 0/1 整數表示圖片內容。
第二部份為測試資料,第一行有一個整數 Q,表示接下來會有 Q 張圖片詢問,每一組詢問佔有 M 行,每
一行上有 M 個整數表示圖片內容。
2 <= N <= 20, 1 <= M <= 16
0 <= Q <= 1000
Output
For each query, output one line, which contains an 0/1 integer.
Write a simple machine learning program. In the first training stage, we train a model. In the second prediction stage we classify inputs according to the model we trained.
Task Description
An image classifier classifies input images into two categories -- accept and reject. An Image is an M by M array P of pixels, where each pixel p{i, j} is either zero or one. A classifier determines which category an image belongs to based on a function value h of all pixels of this image. There is a weight w{i,j} for every pixel p{i,j}, and the h function value of an image is the sum of products of all pixel values with their corresponding weights.(h(P) = \sum{i,j} p{i, j} w{i, j}) If the h value is no less than a threshold T, which is 2M^2, then the model accepts the image, otherwise it rejects the image.
The classifier starts with an initial weights of all 1's, then modify the them according to a set of N train inputs. Each input is an M by M array of 0 or 1's, and has a label of either accept or reject. If the model from the current set of weights gives the same result as the label of the input image, then we do nothing. Otherwise we have two cases. In the first case the classifier accept the input but the label is reject. Then we divide the weight of those non-zero pixel by 2, and set the weight to 1 if the the division gives 0. In the second case the classifier rejects the input but the label is accept. Then we multiply the weight of those non-zero pixel by 2.
After we train our model we use it to classify another set of Q test inputs. We evaluate the h function using the weights we obtained in the previous stage, and accept the input if the h value is no less than the threshold, and reject the input otherwise.
每一個人都有各自的喜好,喜好程度分成可接受與不可接受兩種。這一題專注於圖片辨識上,目標是判斷圖片屬於接受 1 與不接受 0。圖片由一個二維矩陣 P 構成,這裡化簡問題,每一個矩陣元素 p_{i,j} 只有 0 或 1。
我們已知 N 張 pf 可接受和不可接受的圖片,希望可以藉由程式預測新的圖片受不受 pf 喜愛,判斷的方法如下所述:
Input
There is one test case. Each test case has two parts.
In the first part, the training data set contains N images. The first line contains two integers N, M, representing that there are N images which size is M x M as follows: Each image contains M+1 lines. In M+1 lines, the first line contains an integer C, representing the result of each images. In following M lines, each line contains M integers.
In the second part, the query data set contains Q images. The first line contains an integer Q, representing Q images as follows: Each images contains M lines. Each line contains M integers.
只有一組測資。每一組測資分成兩個部份。
第一部份為訓練資料,第一行有兩個整數 N、M,表示接下來會有 N 張 M x M 的 1-bit color 圖片。接下來有 N 組圖片資訊,每一組圖片資訊有 M+1 行,每一組第一行為分類結果 C,接著的 M 行上分別 M 個 0/1 整數表示圖片內容。
第二部份為測試資料,第一行有一個整數 Q,表示接下來會有 Q 張圖片詢問,每一組詢問佔有 M 行,每 一行上有 M 個整數表示圖片內容。
Output
For each query, output one line, which contains an 0/1 integer.
Sample Input
Sample Output