HDLBits练习——Exams/ece241 2014 q7a

Design a 1-12 counter with the following inputs and outputs:

Reset Synchronous active-high reset that forces the counter to 1
Enable Set high for the counter to run
Clk Positive edge-triggered clock input
Q[3:0] The output of the counter
c_enable, c_load, c_d[3:0] Control signals going to the provided 4-bit counter, so correct operation can be verified.
You have the following components available:

the 4-bit binary counter (count4) below, which has Enable and synchronous parallel-load inputs (load has higher priority than enable). The count4 module is provided to you. Instantiate it in your circuit.
logic gates
module count4(
input clk,
input enable,
input load,
input [3:0] d,
output reg [3:0] Q
);
The c_enable, c_load, and c_d outputs are the signals that go to the internal counter’s enable, load, and d inputs, respectively. Their purpose is to allow these signals to be checked for correctness.


前言

三个输入,包括一个时钟clk,一个高电平有效的同步置位信号reset,一个使能信号enable;四个输出,包括一个输出信号Q,以及三个检测信号c_enable、c_load 和 c_d。

代码

module top_module (
    input clk,
    input reset,
    input enable,
    output [3:0] Q,
    output c_enable,
    output c_load,
    output [3:0] c_d
);    
    assign c_enable=enable;
    assign c_load=(reset|(Q==4'd12&enable))?1'b1:1'b0;
    assign c_d=c_load?4'b1:Q;
    count4 instance1(clk,c_enable,c_load,c_d,Q);
endmodule

总结

提供了模块count4,可以直接例化,但是本题主要考虑对于四位计数器的理解,时钟和使能信号都很好理解,但是对于load信号,其代表的是重新加载,即回到初始值,那么就存在两种情况,一是有效置位reset==1’b1,二是计数循环结束并可以开始下一循环,即Q值达到4’d12并且使能信号enable为1’b1,两种情况为或关系;对于d信号而言,其在load信号有效时值为4‘d1,其余情况为任意值即可。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值