HDLBits练习——Exams/ece241 2013 q12

In this question, you will design a circuit for an 8x1 memory, where writing to the memory is accomplished by shifting-in bits, and reading is “random access”, as in a typical RAM. You will then use the circuit to realize a 3-input logic function.

First, create an 8-bit shift register with 8 D-type flip-flops. Label the flip-flop outputs from Q[0]…Q[7]. The shift register input should be called S, which feeds the input of Q[0] (MSB is shifted in first). The enable input controls whether to shift. Then, extend the circuit to have 3 additional inputs A,B,C and an output Z. The circuit’s behaviour should be as follows: when ABC is 000, Z=Q[0], when ABC is 001, Z=Q[1], and so on. Your circuit should contain ONLY the 8-bit shift register, and multiplexers. (Aside: this circuit is called a 3-input look-up-table (LUT)).


前言

六个输入,包括一个时钟clk,一个移位的使能信号enable,三个控制信号A、B和C,一个输入信号S;一个输出信号Z。

代码

module top_module (
    input clk,
    input enable,
    input S,
    input A, B, C,
    output Z ); 
    reg [7:0]q;
    wire [2:0]i;
    assign i={A,B,C};
    assign Z=q[i];
    always@(posedge clk)begin
        if(!enable) q<=q;
        else q<={q[6:0],S};
    end
endmodule

总结

ABC是控制输出的比特位,因此使用 i 来合并计数;S的输入优先最低位,因此 q 发生左移。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
本文将通过使用逻辑回归来预测学生是否被一个大学录取。我们将使用Python编程语言,Numpy、Pandas和Scikit-learn库。 数据集介绍 我们使用的是一个包含两个变量的数据集(如下所示): * Exam 1得分:学生在第一次考试中获得的分数 * Exam 2得分:学生在第二次考试中获得的分数 * 是否被录取:学生是否被录取(1表示被录取,0表示未被录取) 我们将使用这些变量来预测学生是否被录取。 数据预处理 首先,我们需要从我们的CSV文件中读取数据集并将其装入一个Pandas DataFrame中。 import numpy as np import pandas as pd data = pd.read_csv("exams.csv") print(data.head())​ 输出: Exam 1 Exam 2 Admitted 0 34 78 0 1 30 62 0 2 35 85 1 3 60 69 1 4 79 76 1 该数据集有100个学生,并且我们将首先对数据进行基本的统计分析。 data.describe() 输出: Exam 1 Exam 2 Admitted count 100.000000 100.000000 100.000000 mean 65.644444 66.600000 0.600000 std 19.458222 18.604269 0.492366 min 30.000000 32.000000 0.000000 25% 50.000000 51.000000 0.000000 50% 67.000000 67.500000 1.000000 75% 83.000000 79.000000 1.000000 max 98.000000 98.000000 1.000000 我们可以看到,平均分数为65.6和66.6分,最小分数为30分,最大分数为98分。如果我们查看“Admitted”列,则会发现600个人中有60%被录取了。 接下来,让我们通过放置它们在一个散点图中来可视化数据。 import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=(10,6)) ax.scatter(data[data['Admitted'] == 1]['Exam 1'], data[data['Admitted'] == 1]['Exam 2'], s=50, c='b', marker='o', label='Admitted') ax.scatter(data[data['Admitted'] == 0]['Exam 1'], data[data['Admitted'] == 0]['Exam 2'], s=50, c='r', marker='x', label='Not Admitted') ax.legend() ax.set_xlabel('Exam 1 Score') ax.set_ylabel('Exam 2 Score') plt.show() 输出: ![](https://cdn-images-1.medium.com/max/1200/1*23Nt-cA010-W2dIBymLG0A.png) 在这里,我们可以看到两个考试的分数,其中红色表示未被录取的学生,蓝色表示被录取的学生。我们的目标是通过学生的考试分数来预测他们是否被录取。 训练模型 现在,我们将使用Scikit-learn库来训练我们的逻辑回归模型。 from sklearn.linear_model import LogisticRegression X = data.iloc[:, :-1].values y = data.iloc[:, -1].values classifier = LogisticRegression() classifier.fit(X, y) 我们将先将数据集分成训练和测试集,然后在测试数据集上进行预测。 from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=0) classifier.fit(X_train, y_train) y_pred = classifier.predict(X_test) 评估模型 现在,我们已经完成了模型的训练,需要对其进行评估。 从Scikit-learn中的metrics库中导入准确率评分函数。 from sklearn.metrics import accuracy_score print('Accuracy: %.2f' % accuracy_score(y_test, y_pred)) 输出: Accuracy: 0.92 从结果可以看出,模型的准确度为92%,因此我们可以认为这个模型可以很好地预测学生是否被录取!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值