关于算法:并查集详解及应用

文章和代码曾经归档至【Github仓库:https://github.com/timerring/algorithms-notes 】或者公众号【AIShareLab】回复 算法笔记 也可获取。并查集1.将两个汇合合并 2.询问两个元素是否在一个汇合当中。 基本原理:每个汇合用一棵树来示意。**树根的编号就是整个汇合的编号。**每个节点存储它的父节点,p[]示意x的父节点。 如何判断树根:if (p[x]== x) //它的父节点就是它本人如何求x的汇合编号: while (p[x]!= x)x= p[x];如何合并两个汇合:px是x的汇合编号,py是y的汇合编号。p[x]=y 优化办法门路压缩(罕用),按秩合并。 门路压缩就是将曾经找到根节点的所有点,批改其父节点为根节点,以达到升高工夫复杂度近似为O(1)的目标。(因为若始终采纳循环来找父节点,工夫复杂度将会由树的高度决定,非常冗余)。这里是采纳递归的形式实现。 留神:通常scanf在读字符串时会主动疏忽空格和回车。因而在用scanf读入一个字符或者字母时,举荐采纳字符串的模式%S。例题:合并汇合一共有 n 个数,编号是 1∼n,最开始每个数各自在一个汇合中。 当初要进行 m 个操作,操作共有两种: M a b,将编号为 a 和 b 的两个数所在的汇合合并,如果两个数曾经在同一个汇合中,则疏忽这个操作;Q a b,询问编号为 a 和 b 的两个数是否在同一个汇合中;输出格局 第一行输出整数 n 和 m。 接下来 m 行,每行蕴含一个操作指令,指令为 M a b 或 Q a b 中的一种。 输入格局 对于每个询问指令 Q a b,都要输入一个后果,如果 a 和 b 在同一汇合内,则输入 Yes,否则输入 No。 每个后果占一行。 数据范畴 $1≤n,m≤10^5$ 输出样例: 4 5M 1 2M 3 4Q 1 2Q 1 3Q 3 4输入样例: ...

June 13, 2023 · 5 min · jiezi

关于算法:银行API安全解决方案

数字经济背景下,内部市场环境的疾速变动给商业银行带来很多不确定性,随着银行行业数字化转型进入深水区,银行经营面临新的时机和挑战。数字经济是传统银行向凋谢银行转型倒退的重要撑持,凋谢银行旨在使用数字技术通过凋谢数据和业务,使得银行与互联网平台的对接更为标准化,能够服务更宽泛的客群,无效解决传统营销形式下的获客老本高、效率低、粘性弱等问题,进步金融服务的可获得性,将银行服务能力与生存场景的“无缝对接”,实现金融服务无处不在。凋谢银行的实质是对银行数据的共享,而凋谢API则是实现这一指标最为间接的伎俩,开发者、第三方、合作伙伴乃至客户通过API接口间接调取银行提供的金融服务和数据,多方互动,让不同的机构和企业在此构建和共享不同的金融服务和数据,造成一种全新的银行生态链。 01 要害挑战凋谢银⾏作为银⾏的倒退新⽅向,API作为凋谢银⾏的重要基础设施,商业银⾏须要正确认识其存在的危险与挑战。凋谢银⾏拉长了危险管控的链条,如何在国内法律法规对个⼈⾦融信息爱护⼒度不断加强的当下,构建⼀个欠缺的风控体系,让事先受权健全,事中单干⽅的资质合格、操作合规,预先纠纷解决机制欠缺,权责明显,也是银⾏在转型期间始终须要⾯对的问题之⼀。由API传输的外围业务数据、个人身份信息等数据的流动性大大加强,因而这些数据面临着较大的透露和滥用危险,是数据保护的单薄一环,内部歹意攻击者会利用API接口批量获取敏感数据。API是连贯不同起源数据和承载业务逻辑的重要通道,通过凋谢API实现金融业务线上办理和查问、挪动领取、业务交融等,与此同时,API也正成为歹意攻打的重点指标,微小的流量和拜访频率让API的危险面变得更广、影响更大。《商业银行利用程序接口平安治理标准》中与商业银行局部具体相干的条款。① 平安设计:应答商业银行利用程序接口应答联通有效性进行验证。依据利用方服务需要,依照最小受权准则对接口进行受权治理;服务需要变更时,需及时评估和调整接口权限。商业银行应对接口应用状况进行监控,并按要求残缺记录接口拜访日志。② 平安部署商业银行应在互联网边界部署具备网络管制、入侵防备相干平安防护能力的网络安全防护措施;商业银行的安全控制要求根据JR/T 071部署相应级别的安全控制措施。商业银行应能够限度接口连贯时长、被动断开连接的性能,发现歹意连贯可被动管制。③ 平安运维商业银行应建设商业银行利用程序接口运维监测平台,或将商业银行利用程序接口纳入商业银行对立监测平台并重点监测;对于异样监测,商业银行应具备流量监控、故障隔离、黑名单管制等接口调用控制能力。商业银行应对接口进行平安巡检,包含技术检查和平安集成查看。 02 我的项目介绍为无效升高凋谢银行建设的平安危险,2020 年 2 月,中国人民银行公布了《商业银行利用程序接口平安治理标准》这一金融行业标准。标准规定了商业银行利用程序接口(API)的类型与安全级别、平安设计、平安部署、平安集成、平安运维、服务终止与零碎下线、平安治理等平安技术与平安保障要求,贯通API的整个生命周期。2021年公布的《金融数据安全 数据生命周期平安标准》则更是要求“对应用API进行数据跨域流动的边界,应应用API防护技术”,要求“对API数据的外发与回传进行审计”。鉴于金融业务面临的API平安问题,以及国家针对API提出的具体平安要求,星阑科技剖析梳理了API技术面临的内、内部平安危险,针对事先、事中、预先不同阶段的平安需要差别,从API安平安治理、防护伎俩、危险管控等多角度为企业实现高效、灵便的API平安解决方案。 03 星阑API平安解决方案外围场景全域API资产梳理通过全流量剖析、多维度的无效数据采集和智能剖析能力,实时监控流量中全副API接口的平安态势、破绽危险、数据裸露危险和业务危险等,让管理员能够分明的感知全业务域有多少API、是否平安、哪里不平安、具体薄弱点、攻打入口点等,围绕攻打链(kill-chain)来造成一套基于“事先查看、事中剖析、预先检测”的平安能力,看清全网API威逼,从而辅助决策。API 身份认证实时监控增强 API 身份认证实时监控能力,对异样登录、调用行为进行剖析,发现歹意行为及时告警。实时监控接口运行中的单因素认证、弱明码、明码明文传输等脆弱性问题,建设账号登录行为画像,造成用户惯例登录特色基线,对不同 IP 登录、间断认证失败、境外 IP 拜访等敏感操作进行监测剖析,发现账号共享、借用、专任等违规行为及时对相干账号操作及时告警,防止安全事件的产生或扩充。建设API行为模型和用户画像基于人工智能的平安规定制订能够实现更加精准和自适应的API平安进攻,建设基于API应用数据的用户画像和行为模型,进行精细化的身份认证和访问控制,通过对API应用数据的剖析和整合,能够建设API行为模型和用户画像,并进行主动学习和调整,从而实现更加精准的平安规定制订和更新,进步API的平安性能和效率。智能剖析能力,应答API未知威逼随着黑客的技术倒退以及变种、爬虫与反风控技术的不断改进,传统安全设备的动态规定进攻伎俩曾经顾此失彼,依附规定无奈进攻API爬虫、API数据泄露等未知威逼。星阑科技萤火API平安剖析平台具备智能剖析技术,利用机器学习、关联剖析、UEBA、隐衷辨认等新数据分析模型,可能学习每一个API的历史行为模式,并针对异样行为序列进行告警,充沛检测数据泄露、异样拜访、越权攻打、账号滥用行为。模型通过数据输出进行一直的自我迭代,使成果可能越来越贴近业务模式,升高误报漏报产生的概率。API 数据流向监控建设API 数据流量监测机制,实时监控数据流向,增强数据流向监控能力建设。通过剖析拜访和被拜访 IP 的局域、地区或法域,实现对数据流向的实时监控,防备数据接管方非法发售或滥用个人信息危险,发现相干守法违规事件及时告警 API 接入,为后续溯源考察踊跃存证。此外,企业应答境外 IP 拜访内网 API 或者外部 IP 拜访境外 API 的状况重点关注、及时预警,确保敏感数据入境流动非法合规。 04客户寄语API是数字化转型的外围,促成合作和疾速翻新。平安畛域正在向api转移,而星阑科技处于API平安策略的前沿。星阑科技帮忙咱们在数字化转型过程中增强API平安,借助于星阑科技先进的技术和业余团队,不仅能够确保API的安全性和合规性,还能够为外部开发团队提供弱小的工具,从而升高开发成本、缩短业务迭代工夫,使咱们可能平安地将重要数据和服务与客户、合作伙伴连接起来,以及确保业务持续增长。心愿星阑科技与银行机构持续性精诚合作,独特守护金融服务平安战线。 05总结将来,API在数字化转型中表演的角色愈发重要,亟需无效的解决方案对凋谢共享的数据外围资产提供爱护。星阑科技将判若两人地关注API平安畛域,并针对市场和客户需要,一直优化和降级现有产品与服务,在API平安畛域实现更大的倒退和提高。

June 13, 2023 · 1 min · jiezi

关于算法:瓴羊Quick-BI让数据大屏更智能更易用

在数字经济的大背景下,越来越多的企业对数据分析和数据可视化的关注成为了一种趋势,这也促成了诸如羚羊 Quick BI数据大屏这样的数据可视化工具失去了宽泛的利用。谁都晓得无论多大的公司,在经营的时候,都会产生大量的数据。然而对于某些公司而言,如果不能在短时间内对大量的商务数据进行无效的解决、剖析和开掘,那么这些数据的价值就难以体现进去,甚至会变成一种经营累赘。因而,数据大屏、绩效大屏等辅助业务决策的数据可视化工具,就成了企业在数字化转型中的“标配”,例如瓴羊 Quick BI的数据大屏,就是因为它能够笼罩 CXO驾驶舱、我的项目会议演示、 PR等多个利用场景,所以失去了各行各业的广泛认可。 国内一家出名鞋业团体,就是利用了瓴羊 Quick BI的部署,将公司扩散在全国各地的经营数据迅速地连接起来。同时,还利用一系列可视化大屏的搭建,让公司各个层级的管理人员能够在第一工夫理解到公司的销售状况,同时还能够把握一些重要指标的动态变化,从而对销售中的重要环节进行实时监控。找出影响销售后果的次要因素,而后进行优化改良。普安作为茶乡,领有大量出名茶企业,这些企业利用瓴羊 Quick BI的可视化数据解决方案,岂但能够实时地反映出当地茶叶产业的倒退状况,还能够作为当地茶叶产业的一张电子名片,使普安茶的知名度再上一层楼。为使更多企业可能充分发挥瓴羊Quick BI的齐备数据可视化能力,依靠数据大屏实现高效数据处理与交互工作。瓴羊Quick BI内置大量行业模板,便于不同类型的企业针对性的抉择,diy合适自家企业和品牌调性的数据大屏。

June 13, 2023 · 1 min · jiezi

关于算法:使用华为云开发者插件一键部署应用到ECS

前言笔者是一名码龄5年左右的程序员,大学是能源行业,处于对技术(碎银几两)的酷爱,抉择投身搬砖之路。从用C语言在控制台打印第一句“Hello World!”开始,笔者陆续接触过C/C++、Java、Golang、Python等语言。同样也应用过各种IDE,包含IntelliJ系列的Golang、Pycharm、Idea、前端开发神器VSCode、C/C++开发全家桶环境Visual Studio等等。 对于一名编程人员,IDE是必不可少的,抉择适合IDE能帮忙开发人员更快更丝滑的去编程。如果把IDE比作一把剑的话,那插件就是这把剑上的各种Buff,为宝剑赋能,提供更好的降级打怪体验。 什么是华为云开发者插件华为云开发者插件,英文名是Huawei Cloud Toolkit,是基于华为云现有能力的一系列插件汇合,简略来说就是把华为云的能力带到每个开发者的桌面,使开发者在IDE通过插件的能力连贯华为云。 华为云开发者系列插件是收费的,同时反对当下的多个IDE平台:包含IntelliJ系列、VSCode、以及华为自研CodeArts IDE。 华为云开发者插件体验分享华为云开发者插件反对多个平台,咱们以IntelliJ平台idea为例去体验Toolkit的能力:部署插件(名称是Huawei Cloud Deploy,反对一键部署到CCI、ECS)。部署插件能够帮忙开发者高效开发并部署适宜在云端运行的利用,这个对于集体开发者来说是个福音,终于不须要再手动 scp/ftp 上传利用到服务器了。 更齐全的教程在官网:华为云开发者插件。咱们以ECS部署为例,次要步骤有如下几步:1.在idea上装置Huawei Cloud Deploy、Huawei Cloud Toolkit Platform插件2.重启idea利用3.登录华为云账号(抉择AK/SK登录或者华为云账号、CSDN账号登录)4.配置公布到ECS的相干服务器及命令信息5.测试并胜利公布首先装置相干插件并登录:关上IDEA插件市场,搜寻“Huawei Cloud Deploy”(部署插件)和“Huawei Cloud Toolkit Platform”(华为云底座插件,提供单点登录能力),一键装置重启IDE,即可在领有这种疾速部署的能力(ECS资源须要提前购买)。  点击左侧菜单中的“Huawei Cloud Toolkit”图标,关上插件主面板,抉择右上角的用户头像按钮,在弹出的页面抉择华为云AK/SK登录、华为账号登录或者CSDN账号登录。  而后咱们开始部署配置操作:登录有ECS资源的账号后,关上插件左侧主面板:点击IDEA左侧工具框中的"Huawei Cloud Toolkit"工具按钮、点击插件主面板中的"Huawei Cloud Deploy", 抉择 "Deploy to ECS"。  在弹出面板中设置部署参数。  部署参数阐明: Create New Configration:创立一个部署配置工作,配合Save按钮能够将配置参数本地化保留。Using Existing Configration:应用本地化保留的部署参数(这里暂不抉择)。Name:自定义部署工作的名称,不便后续复用(能够随便定义一个名称)。File:要传送到ECS的文件(能够抉择一个jar包、二进制包等模式的利用文件)。Target ECS:指标Region的ECS资源,能够抉择想要部署的实例(确保以后登录账号下有ECS资源)。Command before:部署前执行的命令(比方cd命令、环境配置命令等等)。Target directory:输出ECS上指标部署门路。Command after:部署后执行的命令(比方执行部署脚本等)。抉择有ECS资源的Region后,会展现对应的ECS实例,点击ECS实例表格中的设置图标,验证形式下拉切换验证形式,这里咱们选取Password形式,实现配置后点击run即可实现部署操作。 部署胜利后弹出:“Success to deploy for ECS!”,登录近程ECS,能够看到咱们曾经将本地利用胜利部署到服务器(配合Coomand before/after能够间接部署运行一个利用)。整体部署配置的过程只须要1分钟不到,而且能够将配置参数长久化带本地,下次能够间接复用。是不是很不便呢?————————————————————————————————————————————扫描产品二维码即刻体验

June 13, 2023 · 1 min · jiezi

关于算法:飞桨AI4S污染物扩散快速预测模型亮相全国数据驱动计算力学研讨会

5月19-21日,第一届全国数据驱动计算力学研讨会在大连召开。本次研讨会由中国力学学会主办,大连理工大学运载工程与力学学部承办,北京理工大学先进构造技术研究院协办。 会议共吸引了400多位来自全国各地高校与企业的老师与学生参会,本次研讨会聚焦“数据驱动计算力学与工程科技前沿”,涵盖数据驱动计算力学的数学实践、多场多尺度剖析、构造优化设计等主题,为国内外相干钻研畛域的学者搭建学术交流平台,展现数据驱动计算力学钻研前沿的最新成绩与停顿,造成并稳固一批数据驱动计算力学畛域的学者队伍,以期促成中国计算力学学科的倒退。 会议邀请到程耿东院士、方岱宁院士、张对立院士、何国威院士和魏悦广院士做主会场特邀报告。报告的内容别离为数据驱动的模型降阶法、AI 驱动的先进结构设计与分析方法、Materials GPT and Domain Knowledge Guided Machine Learning、数据驱动的湍流钻研、先进资料跨尺度力学行为的计算模仿,论述了对数据驱动计算力学倒退的观点和科研停顿。 在分会场上,来自海内外高校科研院所的老师就“基于数据驱动的简单力学行为数值模仿”、“基于数据驱动的构造优化设计”、“基于数据驱动的多尺度/多物理场剖析”、“基于数据驱动的超资料设计”、“基于数据驱动的构造能源响应分析”、“基于数据驱动的构造不确定性剖析”共6个方向进行了198场精彩纷呈的报告。 主题分享赛桨 PaddleScience 最新科研停顿百度飞桨携 AI for Science 畛域新成绩——污染物扩散疾速预测模型参加本次研讨会,百度工程师王冠在会上做了题为《基于数据驱动 U-Net 模型的大气污染物扩散疾速预测》的报告,并与参会学者相互交换和学习,推动 AI for Science 的倒退。 训练数据推理 预测后果 本报告中,咱们介绍了基于百度飞桨科学计算工具组件赛桨 PaddleScience 搭建的 U-Net 网络,这是一种基于 Encoder-Decoder 和卷积的一种网络结构,通过污染物扩散云图来学习污染物扩散的模型参数。 以后,常见的大气污染预测模型大多是基于物理机理构建的,比方空气质量预测模型 Calpuff、AERMOD、CMAQ 等。然而,这些模型运算较为简单,对于输出数据的要求十分高,运算耗时也比拟长,适宜用于惯例固定区域的预报。当遇到突发净化事件时,就无奈无效发挥作用。针对以上问题,本我的项目以某城区 3km*3km 范畴的固定模仿区域,依据污染物扩散模型,疾速计算任意开释点源和任意风向的污染物扩散动图,并进行精度评估。仅利用城市部分污染物扩散云图作为输出,应用深度学习模型提取图像中污染物扩散的特色,纯数据驱动,无需建设物理模型,预测耗时短,适宜作为突发净化扩散事件时的应急处理决策辅助。 从我的项目后果来看,模型计算速度相比 CFD 模仿晋升显著,然而模型预测的成果还有待晋升。将来将通过摸索更多时刻预测、引入更先进的网络架构、调整网络参数、物理先验常识,一直优化模型预测成果。 后续的我的项目开发,咱们期待与企业、高校、科研院所以及超算等搭档携手共建,打造沉闷的前瞻性的 AI for Science 开源社区,建设产学研闭环,推动科研翻新与产业赋能。 产品基石飞桨 AI for Science百度飞桨(PaddlePaddle)将 AI 办法利用于典型的迷信与工程畛域,促成数学、物理、化学、生物等多个学科的穿插交融。目前针对通用物理迷信、生物计算、量子机器学习畛域公布了赛桨 PaddleScience、螺旋桨 PaddleHelix、量桨 Paddle Quantum 工具,并全量适配深度学习科学计算工具 DeepXDE,提供数据驱动、数理交融等多种 AI for Science 办法模型,提供简单形状障碍物绕流、构造应力应变剖析、设施对流散热、资料分子模仿等丰盛畛域算例,广泛支持AI+计算力学、生物计算、量子计算等前沿方向的科研和产业利用。 其中 AI for Science 工具组件赛桨 PaddleScience,是国内首个基于 AI 框架的公开且可利用于计算流体力学( CFD )畛域的工具,提供端到端的利用 API,重点围绕高水平科研活动场景,解决重大科研问题。 赛桨 PaddleScience v1.0 正式版蕴含了如下四方面的特色: API架构更新从用户应用习惯角度,兼顾深度学习及 CFD\&CAE 用户体验,从数据预处理、模型抉择、网络优化求解、后果后处理等角度更新 API 元素,晋升用户应用体验。 丰盛的场景案例提供 2D & 3D 圆柱绕流、涡激振动、对流散热及方程反演等根底案例,同时新增构造畛域中 2D & 3D 构造受力剖析案例。并提供气象预报、污染物扩散等相干案例,反对间接复用及二次开发。 底层模型更新新增如CNN、U-Net、Transformer、GAN等经典神经网络模型以及FNO算子学习模型,并提供相应验证案例。 API降级更新提供全新设计的 API 供用户自定义偏微分方程及定义各类边界条件,反对 2D & 3D 根底几何定义、STL 简单形状解析及布尔操作等,并提供准随机采样、部分加密采样等性能。 将来,飞桨 AI for Science 将一直加大技术支持,为人工智能与力学科研倒退赋能,汇聚科研成果、人才资源、产品翻新,为 AI for Science 的倒退提供松软力量。 相干地址 飞桨科学计算实训示例 飞桨 AI for Science 共创打算 飞桨 PPSIG-Science 小组 飞桨 PaddleScience 工具组件

June 12, 2023 · 1 min · jiezi

关于算法:Trie树模板与应用

文章和代码曾经归档至【Github仓库:https://github.com/timerring/algorithms-notes 】或者公众号【AIShareLab】回复 算法笔记 也可获取。Trie树(字典树)Trie树是用来疾速存储和查找 字符串汇合的数据结构。某个字符串汇合对应的有根树。树的每条边上对应有恰好一个字符,每个顶点代表从根到该节点的门路所对应的字符串(将所有通过的边上的字符按程序连接起来)。利用字符串的公共前缀来缩小查问工夫,最大限度地缩小无谓的字符串比拟,查问效率比哈希树高。 根本思维存储若干字符串(通常样本中的字符较少),而后依据字符串中字符呈现的先后顺序建设树,把具备雷同前缀的字符串依照其前缀归类在一个分支中,并且须要在字符串的最初一个地位进行标记(表明到此为一个残缺的字符串)。 查找时只须要寻找是否有匹配的序列,并且是否已标记结尾即可。 例题 Trie字符串统计保护一个字符串汇合,反对两种操作: I x 向汇合中插入一个字符串 x;Q x 询问一个字符串在汇合中呈现了多少次。共有 N 个操作,输出的字符串总长度不超过 $10^5$,字符串仅蕴含小写英文字母。 输出格局 第一行蕴含整数 N,示意操作数。 接下来 N 行,每行蕴含一个操作指令,指令为 I x 或 Q x 中的一种。 输入格局 对于每个询问指令 Q x,都要输入一个整数作为后果,示意 x 在汇合中呈现的次数。 每个后果占一行。 数据范畴 $1≤N≤2∗10^4$ 输出样例: 5I abcQ abcQ abI abQ ab输入样例: 101code#include<iostream>using namespace std;const int N = 100010;// 下标0代表根节点和空节点,cnt用于计数,idx代表以后的节点(和单链表一样)相当于是一个举世无双的递增编号,son[N][26]每个节点最多有26条边(小写英文字母)int son[N][26], cnt[N], idx;char str[N];// 插入void insert(char str[]){ int p = 0;// 根节点 // 遍历字符串,cpp中str最初一位是\0 for(int i = 0; str[i]; i ++) { // 映射字母a-z为0-25 int u = str[i] - 'a'; // 若不存在该节点则创立一个 if(!son[p][u]) son[p][u] = ++ idx; // 走到该子节点 p = son[p][u]; } cnt[p] ++ ;// 标记该子节点存在的单词个数 记住这里p = son[p][u];}// 查问int query(char str[]){ int p = 0; for(int i = 0; str[i]; i++) { int u = str[i] - 'a'; if(!son[p][u]) return 0; p = son[p][u]; } return cnt[p];}int main(){ //ios::sync_with_stdio(false); //cin.tie(0); int n; scanf("%d", &n); while(n --) { char op[2]; scanf("%s%s", op, str); if(op[0] == 'I') insert(str); else printf("%d\n", query(str)); } return 0;}对于idx的了解不论是链表,Trie树还是堆,他们的根本单元都是一个个结点连贯形成的,能够成为“链”式构造。这个结点蕴含两个根本的属性:自身的值和指向下一个结点的指针。按情理,应该依照构造体的形式来实现这些数据结构的,然而做算法题个别用数组模仿,次要是因为比拟快。 ...

June 11, 2023 · 3 min · jiezi

关于算法:TVP走进腾讯直面变革浪潮合力拥抱AI新时代

引言自 ChatGPT 问世以来,以通用人工智能为代表的 AI 技术倒退开始“狂飙”,多家企业和钻研机构入局大模型赛道,新利用场景不断涌现。如何了解通用人工智能技术将带来的微小影响,并把握随之而来的时机和挑战,是咱们面临的两大关键问题。 5 月 13 日,「直面 AI 的新一轮改革浪潮」TVP 走进腾讯流动重磅召开,流动邀请了来自产、学、研等畛域的技术专家,闭门畅聊 AI 前沿热点、将来趋势,以多元视角碰撞出泛滥深度观点与精彩火花。 一、大模型时代的学科穿插钻研:以政治人物建模为例 复旦大学大数据学院副教授、数据智能与社会计算实验室负责人 魏忠钰带来了题为《大模型时代的学科穿插钻研:以政治人物建模为例》的主题分享。 魏忠钰老师首先分享了现如今人类进入大模型时代,大模型为学科穿插钻研带来的时机与挑战,并以政治人物建模为例,分析大模型对学科穿插钻研的影响。 (一)人类进入大模型时代在自然语言解决畛域,每个时代都有对应的范式。经验专家系统、浅层机器学习及深层学习这三个倒退阶段,随着 ChatGPT 及 GPT-4 的呈现,人类进入新的范式——由基座模型-指令微调-人类反馈造成的框架。 魏忠钰老师剖析到,作为当下最前沿的技术力量,相较于传统范式,大模型劣势更显著:特色示意上,专家系统是基于规定的方法;浅层机器学习具备显著的手工特色;深层学习采取低维浓密的建模形式;大模型降级到用简略结构化数据,解决大规模高维简单数据的程度。模型构建上,传统范式只能依据工作,制作对应的定制模型,如分类模型、生成模型、检索模型等;大模型以生成式框架实现多种工作,实现模型的大对立。泛化能力上,过来每个模型只能解决一个指定工作或者一组相干工作;而预训练的大模型能够在简直所有自然语言解决工作中进行小样本甚至零样本的适配应用。 (二)大模型为学科穿插带来的时机与挑战大模型通过构建基座模型、利用穿插数据微调,在人机交互中一直优化,实现疾速开发具备肯定动静交互能力的智能零碎,解决了传统范式在学科穿插畛域上存在的数据款式多变、难以泛化与复用、交互能力弱等问题。 魏忠钰老师剖析到,大模型为学科穿插带来新机遇,提供对立的建典范式、实现常识迁徙、进步建模成果以及重塑学科穿插的技术框架。但大模型也有局限性,它以语言模型为根底,仅能解决文本序列数据,对实在场景中存在的其它蕴含常识的数据状态进行解决,比方行为数据、关系数据等。 魏忠钰老师示意,想要真正施展大模型在学科穿插钻研的影响,须要在弱小的语言模型的根底上,思考如何加强其多数据类型的解决能力,扩大它对于畛域常识的了解和应用,只有这样能力达到对真实世界的深层次了解。 (三)以政治人物建模为例,在大模型时代下学科穿插钻研的倒退政治人物建模是用数据构建政治人物的全面画像,要害数据来源于公开舆论、关系数据及行为数据。魏忠钰老师介绍了在钻研过程中的三个阶段:行为建模:基于政治人物的投票数据进行建模,可了解其政治偏向。社会关系建模:构建政治人物之间的互动与单干关系网络,可了解其在政治网络中的角色与位置。舆论内容建模:剖析政治人物的公开舆论与文本数据,提取观点与立场,可了解其思维主张。 三种类型的数据,在政治人物画像的过程中各自有本人的局限性,行为建模的数据易受外界影响,难以清晰表白人的核心理念;社会网络分析仅依赖关系数据,难以深刻了解人的思维与主张;舆论数据受到开放平台的影响,难以全面反映指标的实在立场。基于图模型的建模办法能够将这三种类型的信息进行无效交融,实现对于指标人物的全面建模。 图模型尽管能够有机交融三种数据,然而在具体的应用过程中,它也有本人的局限性,比方框架难以疾速对未见过的议员进行疾速的示意学习,从而限度了模型的场景迁徙能力。为了进一步欠缺政治人物建模,魏忠钰老师及相干钻研人员利用语言作为政治人物的示意学习根底,构建出一体化的政治人物表征框架,特点如下:不间接学习政治人物节点的表征,而是学习政治人物舆论到其表征的映射过程。通过检索政治人物的所有公开舆论,构建两种粒度的舆论表征:通用舆论表征与政治畛域舆论表征。通过两种自监督工作实现场景常识的注入与优化:构造感知比照学习:利用人物与党派、其余人物的关系作为监督信号更新参数;行为驱动比照学习:利用人物与投票后果的关系作为监督信号更新参数。在大模型根底之上,政治人物表征框架利用大规模语料构建语言模型,通过设计自监督工作,实现外界常识的注入与优化,关上了一条交融多学科与多模态常识的新门路,助推学科穿插畛域的进一步倒退。 二、引爆:ChatGPT与AIGC带来的思考与利用趋势腾讯政策倒退核心副主任 Darren 老师,带来了《引爆:ChatGPT 与 AIGC 带来的思考与利用趋势》的主题演讲,从改革趋势、产业利用及后续布局角度切入进行分享,探讨 AI 技术倒退如何为用户发明更高价值。 (一)从超级个体看 AIGC 的倒退Darren 老师指出,ChatGPT 和 GPT-4 等先进语言模型的呈现,标记着 AI 曾经初步实现与人类的天然交互。这一冲破预示着 AI 将对各行各业产生深远影响。然而,将 AI 视为产品或服务的卖点是全面的,应把 AI 深度融入产品或服务之中,成为外围竞争力。另一大趋势为产品逐步从适应大多数用户,转向满足每个用户的个性化需要,这意味着“产品适配用户”将取代“用户适配产品”,甚至会呈现“一次性应用”的产品。Darren 老师示意,随着技术的提高,个性化定制的 AI 助理行将问世,但这项技术的前提,须要企业把握海量的用户数据,深度了解用户需要并迅速响应,这意味着企业需有疾速的产品设计与迭代能力。 (二)从利用角度看 AIGC 的影响AI 技术的疾速倒退正在驱动产业改革,大模型与生成式人工智能的呈现显现出弱小的生产力。Darren 老师认为,随着大模型参数的减少和泛化能力的进步,AI 能够实现更简单的工作,生成式人工智能可高效生产各种创意和素材。在人工智能的加持下,电商畛域造成了逆向种草景象,通过 AI 生成多样化案例,吸引用户被动提出定制化意见,从而实现疾速生产与销售;AI 变声技术通过人工智能赋能音乐创作,实现更丰盛多样的音乐体验;AI 生成包装设计可主动生成设计方案,提高效率的同时,满足品牌和用户的个性化定制需要。从 C 端渗透到 B 端,AI 技术为传统行业带来了深刻影响。 ...

June 9, 2023 · 1 min · jiezi

关于算法:移动信道的多普勒扩展及相干时间

本专栏蕴含信息论与编码的外围常识,按知识点组织,可作为教学或学习的参考。markdown版本已归档至【Github仓库:https://github.com/timerring/information-theory 】或者公众号【AIShareLab】回复 信息论 获取。挪动信道的多普勒扩大及相干工夫1.多普勒扩大挪动通信中, 挪动台与基站间的相对运动, 会使接管信号的载频产生多普勒频移。 对于频率为 $f_{c}$ 的单频信号, 受多普勒频移, 其频谱范畴约为 $\left(f_{c}-f_{m}, f_{c}+f_{m}\right)$ 。其中 $f_{m}=\frac{v}{\lambda}=\frac{v f_{c}}{c}$ 为最大多普勒频移 (v挪动速度, $\lambda$ 载波波长, c光速)。 设发射信号为频率是 $f_{c}$ 的正弦波, 达到挪动台的门路与挪动台静止方向夹角为 $\theta$ , 则多普勒频移$f_{d}=f_{m} \cos \theta$ 。 图中X & Y 代表挪动台。 2.信道的相干工夫 Tc 和多普勒频率扩大定义最大多普勒频移 $f_{m}$ 的倒数为信道的相干工夫 $T_{c}$, $T_{c}=1 / f_{m}$ 。 它反映信道冲激响应对所传输的信号产生快衰或慢衰的影响。 定义最大多普勒频率 $ B_{D}=f_{m}$ 为多普勒频率扩大。 3.多普勒扩大对衰败的影响快衰败信道: $T_{s} \gt T_{c}$ 或信号的符号速率 $R_{s} \lt B_{D}$ , 即信道相干工夫小于信号码元周期(符号距离 ),因此在信号符号间隔时间内, 信道冲激响应疾速变动, 使信号产生失真——快衰败信道或称为工夫选择性衰败 慢衰败信道: $T_{s} \ll T_{c}$ 或 $R_{s} \gg B_{D}$ , 即信号码元周期(符号距离)远小于信道相干工夫,或信号符号速率远大于信道的多普勒频率扩大, 则信道冲激响应变动速率低于信号符号速率, 在信号符号间隔时间内信道冲激响应根本不变, 此时信号蒙受慢衰败。 ...

June 9, 2023 · 1 min · jiezi

关于算法:FATE联邦学习debug-No-module-named-‘federatedml‘

间接pip install federatedml是无奈找失去这个库的。这个的起因是环境变量的事件,因为在部署文档中,自身提醒咱们要更新一些环境变量,如果不export那些变量,上面的fate_test其实也是无奈测试胜利的。 关上bin/init_env.sh,其内容如下 #!/bin/bash## Copyright 2019 The FATE Authors. All Rights Reserved.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.#fate_project_base=$(cd `dirname "$(realpath "${BASH_SOURCE[0]:-${(%):-%x}}")"`; cd ../;pwd)export FATE_PROJECT_BASE=$fate_project_baseexport FATE_DEPLOY_BASE=$fate_project_baseexport EGGROLL_HOME=export PYTHONPATH=/root/Downloads/standalone_fate_install_1.10.0_release/fate/python:/root/Downloads/standalone_fate_install_1.10.0_release/fateflow/pythonexport FATE_LOG_LEVEL=DEBUGexport FATE_PROFILE_LOG_ENABLED=0export EGGROLL_LOG_LEVEL=INFOvenv=/root/Downloads/standalone_fate_install_1.10.0_release/env/python/venvexport JAVA_HOME=/root/Downloads/standalone_fate_install_1.10.0_release/env/jdk/jdk-8u345export PATH=$PATH:$JAVA_HOME/binsource ${venv}/bin/activate能够看到这个库自身在下载的FATE包里 ...

June 8, 2023 · 1 min · jiezi

关于算法:KMP算法详解

文章和代码曾经归档至【Github仓库:https://github.com/timerring/algorithms-notes 】或者公众号【AIShareLab】回复 算法笔记 也可获取。KMPKMP算法,又称模式匹配算法,可能在线性工夫内断定字符串 A[1\~N]是否为字符串B[1\~M]的子串,并求出字符串A在字符串B中各次呈现的地位。 例题: 给定一个字符串 S,以及一个模式串 P,所有字符串中只蕴含大小写英文字母以及阿拉伯数字。 模式串 P 在字符串 S 中屡次作为子串呈现。 求出模式串 P 在字符串 S 中所有呈现的地位的起始下标。 输出格局 第一行输出整数 N,示意字符串 P 的长度。 第二行输出字符串 P。 第三行输出整数 M,示意字符串 S 的长度。 第四行输出字符串 S。 输入格局 共一行,输入所有呈现地位的起始下标(下标从 0 开始计数),整数之间用空格隔开。 数据范畴 $1≤N≤10^5$$1≤M≤10^6$ 输出样例: 3aba5ababa输入样例: 0 2最奢侈的做法(暴力做法)S[N]-- source串(长), P[N]---pattern串(短);for(int i = 0; i < n; i++){ bool flag = true; for(int j = 0; j < m; j++) if(S[i + j - 1] != P[j]) { flag = false; break; }}KMP算法首先用一个例子模仿KMP过程。 ...

June 5, 2023 · 4 min · jiezi

关于算法:城南如何识别AI生成图视觉AIGC伪造检测技术综述

如何辨认 AI 生成图片?or 如何辨认 AIGC 图?or 如何辨认 AI 换脸?or AI生成图伪造检测? 相似的说法有很多种,总之就是利用AI技术来甄别一张图是不是AI生成的,这种AI技术就是本文的内容。 敌人好,我是卷了又没卷,薛定谔的卷的AI算法工程师「陈城南」~ 负责某大厂的算法工程师,带来最新的前沿AI常识和工具,欢送大家交换~,后续我还会分享更多 AI 乏味工具和实用玩法,包含 ChatGPT、AI绘图等。 公众号「陈城南」或 加「cchengnan113」备注AI交换群知乎账号「陈城南」视觉AIGC辨认现阶段视觉AIGC(AI-generated Content,人工智能生产内容)次要包含图片(Image)和视频(Video),视频的实质是间断的图片帧,疏忽其音频信息的状况下,视频生成则是图片生成的延长。因而,视觉AIGC辨认次要聚焦在AIG图片的辨认。 在AIGC这个概念爆火之前,图片生成的利用始终存在,比方利用GAN进行AI换脸等。因为AI绘图和ChatGPT等大规模语言模型(LLMs)别离在两个畛域体现出惊人的成果并胜利出圈,AIGC这一概念才开始被大家熟知。本文所说的「视觉AIGC辨认」则同时蕴含AI换脸等前AIGC时代的检测,也蕴含Midjourney、SD等AI绘图场景的辨认。 因为AI换脸等人脸伪造技术在利用和负面影响上较大,技术绝对成熟,其辨认难度也较大,辨认的相干钻研也便绝对集中。因而,本文依据已有的钻研工作调研,将视觉AIGC辨认粗略划分为: 人脸伪造检测(Face Forgery Detection):蕴含人脸的AIG图片/视频的检测,例如AI换脸、人脸操控等。此类办法次要关注带有人脸相干的检测办法,检测办法可能会波及人脸信息的先验。AIG整图检测(AI Generated-images Detection):检测一整张图是否由AI生成,检测更加的泛化。这类办法绝对更关注生成图与实在图更通用的底层区别,通常专一于整张图,比方近年爆火的SD、Midjounery的绘图;其余类型假图检测(Others types of Fake Image Detection):此类办法更偏差于 部分伪造、综合伪造等一系列更简单的图片造假,当然人脸伪造也属于部分、简单,然而是人脸场景。将AIG图与实在图拼凑、合成的图片辨认也属于这一类。这三种类型之间划分并不清晰,很多办法同时具备多种检测能力,可划分为多种类型。严格意义上说AIG整图和其余造假图检测类型可能都会蕴含人脸信息,但三种类型办法往往技术出发点也不同。 生成式模型总览 图片生成模型比拟受欢迎的次要有3种基础架构[0],变分主动编码器VAE系列(Variational Automatic Encoder)、反抗生成网络GAN系列(Generation Adversarial Network)和扩散模型DM系列(Diffusion Model)。其中AI绘图以2020年的去噪扩散概率模型DDPM(Denoising Diffusion Probabilistic Model)为一个较大的里程碑,在此之前的生成模型次要以GAN居多。当下最火的开源AI绘画模型 Stable Diffusion 则为扩散模型,据悉 MidJourney 是变形注意力GAN的变体[1]。 人脸伪造检测(Face Forgery Detection)特指蕴含波及人脸相干内容生成的图片/视觉生成,例如AI换脸、人脸操控等; 人脸假装图生成理解人脸假装检测技术前,须要先理解人脸造假图片生成的技术有哪些,不同的生成技术/场景可能有不同的检测办法。基于论文ForgeryNet[2]中的内容,人脸假装图片生成的相干办法(截止2021年前)能够总结如下: 其中,StarGAN2-BlendFace-Stack (SBS), DeepFakes-StarGAN2-Stack (DSS) 人脸假装图依据身份信息是否更改划分为身份信息不变类和身份替换类。 身份不变类伪造图在图片批改/生成时不批改图片中人物的身份信息,包含: 人脸编辑:编辑人脸的内部属性,如年龄、性别或种族等。人脸再制订:保留源主体的身份,但操纵其口部或表情等固有属性; https://github.com/harlanhong/awesome-talking-head-generationhttps://github.com/Rudrabha/Wav2Lip身份替换类伪造图在图片批改时同时扭转其中人的身份信息: 人脸转移:它将源脸部的身份感知和身份不相干的内容(例如表情和姿态)转移到指标脸部,换脸也换表情等等,相当于把本人脸贴在他人的头上;换脸:它将源脸部的身份信息转移到指标脸部,同时保留身份不相干的内容。即换脸,但不换表情,本人的脸在他人脸上做不变的事件;人脸重叠操作(FSM):指一些办法的汇合,其中局部办法将指标图的身份和属性转移到源图上,而其余办法则在转移身份后批改替换后图的属性,多种办法的复合;伪造图检测办法本局部次要为相关检查办法的局部论文简介。 【综述】GAN-generated Faces Detection: A Survey and New Perspectives ...

June 2, 2023 · 5 min · jiezi

关于算法:活动预告-2023-Meet-TVM-北京站定档5-场-Talk-你最期待哪一场

内容一览:2023 Meet TVM 线下团聚第二站定档 6 月 17 日!这次咱们设定了 5 个 Talk,期待和大家在北京中关村相聚! 关键词:编译器 线下流动 2023MeetTVM 本文首发自HyperAI超神经微信公众平台~ 3 月 4 日, 2023 Meet TVM 首场线下流动在上海胜利举办,百余位从事 AI 编译器开发、关注 TVM 倒退的工程师齐聚五角场,进行了充沛热烈的探讨和交换。 时隔 3 个多月,备受期待、千呼万唤的北京站线下团聚终于来了!本次流动咱们邀请到了 5 位资深 AI 编译器专家,联合在理论场景中的利用案例和最佳实际,为现场的敌人带来精彩分享\~ 2023 Meet TVM 北京站流动信息⏰ 工夫:6 月 17 日(周六)14:00-18:00 地点:海淀区海淀西大街 48 号车库咖啡 人数: 100(座位无限,请尽早报名) 报名: 扫描下方二维码报名(流动行及百格二选一) 流动行: 扫码跳转至流动行报名 <p align=center><img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/82b6f6532c8545fc973d9498d484b2a6~tplv-k3u1fbpfcp-watermark.image?" alt="1.png" /></p> 百格流动: 扫码跳转至百格流动报名 <p align=center><img src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/459040cb3c6543acbd7b9fd43968c495~tplv-k3u1fbpfcp-watermark.image?" alt="2小.png" /></p> 扫码备注「TVM 北京」退出流动群 <p align=center><img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/269a8915690d4c3da1a88c16409f0e8b~tplv-k3u1fbpfcp-watermark.image?" alt="3小.png" /></p> 日程: ...

June 1, 2023 · 2 min · jiezi

关于算法:大实战算法与数据结构高手养成求职提升特训课

download:大实战-算法与数据结构高手养成-求职晋升特训课Web前端架构Web前端架构是指在开发Web应用程序时,所采纳的软件设计模式、编程语言、框架、库、工具以及其余技术等方面所做出的决策和组合。好的Web前端架构能够进步生产力、可维护性和扩展性,从而使得Web应用程序更加稳固、高效和易于保护。本文将介绍Web前端架构中的一些重要概念和实际。 MVC(Model-View-Controller)MVC是一种常见的Web应用程序架构模式,它将应用程序分为三个局部:模型(Model)、视图(View)和控制器(Controller)。其中,模型负责解决数据和业务逻辑,视图负责出现用户界面,控制器则协调模型和视图之间的交互。MVC模式通过拆散关注点,无效地将Web应用程序的不同局部解耦,进步了代码的可维护性和可测试性。 MVVM(Model-View-ViewModel)MVVM是一种基于MVC模式的Web前端架构模式,它引入了ViewModel层,并应用数据绑定来自动更新视图。在MVVM中,ViewModel负责将模型转换为视图能够应用的格局,并将视图的状态同步回模型。这种架构模式使得开发者能够专一于业务逻辑,而不用手动更新视图。 单页应用程序(SPA)单页应用程序是一种通过JavaScript动静地更新网页内容的Web应用程序。在SPA中,整个应用程序仅由一个HTML文件和一些JavaScript文件组成,并应用AJAX或WebSocket等技术来与服务器进行通信。SPA通过缩小页面切换工夫、进步交互速度和响应性能,为用户提供更好的体验。 模块化模块化是指将Web应用程序合成为小而独立的局部,每个局部都能够独自开发、测试和保护。模块化使得代码更易于了解、重用和扩大。其中,CommonJS和ES6 Modules是两种常见的模块化规范。 组件化组件化是指将Web应用程序合成为可重用、独立的UI组件,每个组件都具备本人的状态和行为。组件化使得开发者能够更疾速地构建和批改UI元素,并进步了代码的可重用性和可维护性。Vue.js和React.js是两种常见的前端框架,它们都反对组件化编程。 构建工具构建工具是用于自动化Web应用程序构建和打包的工具。常见的构建工具包含Webpack、Rollup和Parcel等。它们能够主动解决JavaScript文件压缩、CSS预处理、代码宰割、依赖治理等工作,从而缩小手动操作,提高效率。 论断Web前端架构是构建高质量Web应用程序的关键所在。通过抉择适合的模式、框架、库、工具和技术等,咱们能够进步Web应用程序的可维护性、扩展性和稳定性。然而,在实践中,咱们须要依据我的项目特定需要和团队能力程度做出相应的决策,并一直调整和优化架构,以满足业务和用户需要。

May 31, 2023 · 1 min · jiezi

关于算法:算法与数据结构高手养成求职提升特训课

算法与数据结构:计算机科学中最根底的两个概念 算法和数据结构是计算机科学中最根底的两个概念,它们是计算机程序设计的根底。算法是解决问题的办法,数据结构是组织数据的形式。在计算机科学中,算法和数据结构是密不可分的,一个好的算法须要一个好的数据结构来撑持,一个好的数据结构也须要一个好的算法来操作。 download: https://www.sisuoit.com/4022.html算法算法是解决问题的办法,它是一系列有序的步骤,用于解决特定问题的计算过程。算法能够用来解决各种问题,例如搜寻、排序、加密、压缩等。一个好的算法应该具备以下特点: 正确性:算法应该可能正确地解决问题,不会呈现谬误的后果。可读性:算法应该易于了解和浏览,便于其他人了解和批改。高效性:算法应该可能在正当的工夫内解决问题,不会耗费过多的资源。算法的复杂度是掂量算法效率的指标,通常用工夫复杂度和空间复杂度来示意。工夫复杂度示意算法执行所需的工夫,空间复杂度示意算法所需的内存空间。数据结构数据结构是组织数据的形式,它是一种存储和组织数据的办法。数据结构能够用来存储和操作各种数据,例如数字、字符串、图像等。一个好的数据结构应该具备以下特点: 正确性:数据结构应该可能正确地存储和操作数据,不会呈现谬误的后果。高效性:数据结构应该可能在正当的工夫内存储和操作数据,不会耗费过多的资源。易用性:数据结构应该易于应用和了解,便于其他人应用和批改。常见的数据结构包含数组、链表、栈、队列、树、图等。不同的数据结构实用于不同的场景,例如数组实用于随机拜访数据,链表实用于插入和删除数据等。算法和数据结构的关系算法和数据结构是密不可分的,一个好的算法须要一个好的数据结构来撑持,一个好的数据结构也须要一个好的算法来操作。例如,排序算法须要一个好的数据结构来存储数据,而搜索算法须要一个好的数据结构来搜寻数据。 算法和数据结构是计算机科学中最根底的两个概念,它们是计算机程序设计的根底。在计算机科学中,算法和数据结构是十分重要的,它们能够帮忙程序员设计出高效、牢靠的程序。因而,把握算法和数据结构是计算机科学学习的重要一步,也是成为一名优良程序员的必备技能。

May 30, 2023 · 1 min · jiezi

关于算法:大实战算法与数据结构高手养成求职提升特训课

download:大实战-算法与数据结构高手养成-求职晋升特训课算法和数据结构是计算机科学中十分重要的概念。它们不仅在编程中表演了要害角色,而且在其余畛域如人工智能、机器学习和物联网等也具备宽泛的利用。本文将介绍算法和数据结构的定义和重要性。 算法的定义算法是指一组用于解决问题或执行工作的有序步骤。这些步骤依照肯定的程序进行,以达到特定的指标。算法能够被认为是计算机程序的“蓝图”,因为它们提供了领导程序执行的具体阐明。在编写代码时,咱们应用算法来解决各种问题,例如排序、搜寻和遍历等。 数据结构的定义数据结构是指一组组织数据的办法。通常,数据结构由多个元素组成,并且它们之间有肯定的关系。一些常见的数据结构包含数组、链表、队列、栈和树等。在编写程序时,咱们须要抉择适当的数据结构来存储和操作数据。例如,如果咱们须要对一组数据进行排序,咱们可能会应用数组或链表等数据结构。 算法与数据结构的重要性算法和数据结构对于计算机科学和编程至关重要。以下是它们的一些主要用途: 进步程序效率应用正确的算法和数据结构能够大大提高程序的效率。例如,在排序大量数据时,如果咱们应用了正确的排序算法,程序执行工夫将显著缩小。 简化代码实现正确抉择算法和数据结构能够使编写代码变得更加简略。编写优良的代码须要思考到许多因素,例如可读性、可维护性等。应用正确的数据结构和算法能够使代码更加简洁、易于了解和调试。 解决简单问题许多计算机科学问题都非常复杂,可能须要大量的计算资源能力解决。应用正确的算法和数据结构能够使这些问题的解决变得更加无效和简略。 利用于其余畛域算法和数据结构不仅在编程中有宽泛的利用,还被利用于人工智能、机器学习和物联网等其余畛域。例如,在机器学习中,咱们能够应用算法来训练模型并对数据进行分类。 算法与数据结构的学习学习算法和数据结构能够看起来很吓人,但它们实际上并不难。有许多在线课程和教程可供学习。另外,许多编程语言都具备内置的数据结构和算法库,能够帮忙您更轻松地实现这些概念。 论断在计算机科学和编程中,算法和数据结构是基础知识。理解这些概念能够使咱们更加高效地编写代码,解决简单的问题并利用于其余畛域。因而,如果您想成为一名优良的程序员或计算机科学家,建议您深入研究算法和数据结构的相干常识。

May 30, 2023 · 1 min · jiezi

关于算法:通义千问预体验如何让-AI-模型应用奔跑在函数计算上

立刻体验基于函数计算部署通义千问预体验: https://developer.aliyun.com/topic/aigc_fcAIGC 浪潮已来,从文字生成到图片生成,AIGC 的创造力让人惊叹,更多人开始摸索如何应用 AI 进步生产效率,激发更多创作潜能,然而在理论利用中,AI 技术的高门槛依然让很多人望而生畏,一般开发者或者没有太多编程教训的人是否也能简略、疾速部署一个 AI 模型利用,享受到科技倒退带来的红利呢? 阿里云函数计算团队全新上线“Serverless 一键部署**通义千问预体验、文生图、图生图、图生文、文生文5 个经典 AI 场景,简直 0 技术门槛部署 AI 模型利用,让创意更快产生。 明天咱们将应用阿里云函数计算 FC 来部署通义千问预体验,给大家展现一下这项技术的魅力。对于通义千问,大家能够进入以下网址理解更多信息。 https://tongyi.aliyun.com/通义千问预体验界面部署胜利后,每个账号有 30 次与通义千问自在对话的额度。 函数计算的劣势开箱即用,通过利用核心一键部署疾速体验,无需进行简单的环境配置按需付费,通过 Serverless 弹性策略在您启动服务的才开始计费反对 GPU 渲染,出图快,破费低筹备项开明阿里云函数计算[1]开明阿里云内容审核增强版[2] 依据相干部门的规定,企业和开发者应用生成式人工智能服务需装备相应的内容危险管理机制,默认集成了阿里云内容平安检测服务。疾速开始抉择通义千问预体验利用在函数计算页面单击左侧“利用”搜寻“通义千问预体验”单击“立刻创立 间接部署利用创立利用页面,抉择间接部署首次应用须要依据提醒进行角色名称受权利用可抉择北京、杭州、上海、深圳 任一地区点击“创立并部署默认环境” 函数计算首次启动要花费 3-4 分钟,须要实现镜像拉取,冷启动等操作。最初画面如下:您能够抉择咱们预置的问题,或者输入您本人的问题,与通义千问进行对话。每个阿里云账号将有 30 次对话额度。 总结及扩大函数计算部署通义千问预体验,一键部署即可实现。理论应用中,AI 模型能够辅助咱们进行更多文字和图像的翻新,函数计算+Serverless 利用核心最新上线五个经典场景: 通义千问预体验——基于通义千问大模型文生图 ——基于 Stable Diffusion 模型(可换模型)图生图——基于 3D 卡通格调模型图生文——基于 mPLUG 图像形容模型文生文——基于 ChatYuan 元语功能型对话大模型在接下来实际篇会别离跟大家探讨交换~ 有奖体验阿里云将提供 Serverless 函数计算产品试用资源,邀请您体验:Serverless 一键部署通义千问预体验、文生图、图生图、图生文、文生文 5 大经典 AI 场景,让您取得通义千问 30 次对话预体验机会,同时简略、高效实现一键部署图像生成、文字生成服务,速成 AIGC 创作家。双重奖品设置,实现任意一个体验场景可得社区 400 积分兑换奖品,还可加入 AI 生成图像较量赢取 Airpods、阿里云定制蓝牙音箱及阿里云定制清雅杯! ...

May 29, 2023 · 1 min · jiezi

关于算法:MT224-社会计算

Module Code: CMT224Module Title: Social ComputingLecturer: Dr Liam TurnerAssessment Title: Social Computing PortfolioAssessment Number: 1Date Set: 18th July 2022Submission Date and Time: 8th August 2022 at 9:30amReturn Date: 5th September 2022 This assignment is worth 100% of the total marks available for this module. If coursework issubmitted late (and where there are no extenuating circumstances): 1 If the assessment is submitted no later than 24 hours after the deadline,the mark for the assessment will be capped at the minimum pass mark;2 If the assessment is submitted more than 24 hours after the deadline, amark of 0 will be given for the assessment. ...

May 25, 2023 · 9 min · jiezi

关于算法:CVEN2303-结构编程

Lab assignment – CVEN2303Submission due by 2pm 5th of August You need to show and submit all your working solution either handwritten or typed. You can use Matlab (or other software) to invert the structural matrix or for your entiresolution procedure. You need to upload a copy of your code or Excel sheet if used. If you are using Matlab, it is expected that you add some titles/subtitles and comments tothe different sections of your code. It is expected to add one or two pages of handwritten or typed Flowchart of your codingor solution procedure, that will simply reflect the various stages taken in your code. For part 1.3, it will be good to include differences between the theoretical and measuredresults in percentages. That will prepare you to discuss the differences between theresults. ...

May 23, 2023 · 3 min · jiezi

关于算法:4CCE1MCP建立一个连接

4CCE1MCP Design: Making a ConnectionPrepared by Dr Francesco CirielloYou will be required to undertake this alternative assessment in place of your deferred courseworkcomponent or as reassessment for your failed coursework attempt. Please note, this also includes in classtests which are scheduled within term outside of the examination window. This alternative assessment for 4CCE1MCP (2021/22 academic year) is designed to replace the outstandingcomponents below. Group Coursework Submission – Remote Control Design, Build & Test of a Ship for Environmental Clean-up ...

May 22, 2023 · 4 min · jiezi

关于算法:CT12433BCD-算法解析

CT124-3-3-BCD Group Assignment Page 1 of 3 Level 3 Asia Pacific University of Technology and Innovation 2022ASSIGNMENT REQUIREMENT:r>Blockchain applications has gained popularity recently and it is said to be a disruptivetechnology to the business applications today. It introduces immutability, decentralised,enhanced security, distributed ledger and consensus features. With the aforementionedfeatures, they are undoubtedly potential to be utilised for business enterprises in a way to havebetter security value within business applications. Therefore, you are commissioned to analyseONE (1) of the following business industries with data security aspects: 1) agriculture; 2)healthcare; 3) education; 4) real estate; 5) supply chain; 6) transport and logistic; 7) automotive;8) media and entertainment; 9) Internet of Things (IoT); 10) commerce. In your analysis, youare required to perform the following tasks. ...

May 22, 2023 · 4 min · jiezi

关于算法:MATH2801理论统计

MATH2801: Theory of Statistics AssignmentPlease follow the instructions below for the assignment (worth 15% of the final mark):Due date: Before 9 pm Wednesday 3rd August (Week 10).Submission details: This assignment may be completed in a group (max. 4 people), or individually.There are two Turnitin submission links in Moodle. Each person in the group mustsubmit an electronic copy of the assignment via the INDIVIDUAL Turnitin link. Oneperson must also submit the assignment via the GRADED Turnitin link.The assignment may be typed or handwritten then scanned. It must be submittedas a pdf file. Please make sure all the names and zIDs of each group member arewritten on all pages.Make sure you show all workings. You do not need to include RStudio commands/code.Try to aim for clarity and conciseness!Length: At most 7 pages are allowed for your assignment solutions. This cover sheet must besubmitted with your assignment, but it is not counted in the 7-page limit. A single pdf and Wordversion of the coversheet is available in Moodle. Please do not exceed the 7-page limit!Declaration: You must sign and date your submitted assignment, and include the PRINTEDnames/zIDs of any other group members below:I (We) declare that this assessment item is my (our) own work, except where acknowledged, andhas not been submitted for academic credit elsewhere, and acknowledge that the assessor of thisitem may, for the purpose of assessing this item:? Reproduce this assessment item and provide a copy to another member of the University;and/or,? Communicate a copy of this assessment item to a plagiarism checking service (which maythen retain a copy of the assessment item on its database for the purpose of future plagiarismchecking).I (We) certify that I (We) have read and understood the University Rules in respect of StudentAcademic Misconduct.

May 22, 2023 · 2 min · jiezi

关于算法:基于欧式距离的聚类算法的Kmeans作业

拜访【WRITE-BUG数字空间】_[内附残缺源码和文档] 基于欧式间隔的聚类算法,其认为两个指标的间隔越近,类似度越大。 该试验产生的点为二维空间中的点。 环境配置java环境,应用原生的Java UI组件JPanel和JFrame 算法原理基于欧式间隔的聚类算法,其认为两个指标的间隔越近,类似度越大。 该试验产生的点为二维空间中的点。 欧式间隔n维空间中的两个点X,Y $dist(X, Y) = \sqrt{\sum_{i = 1}^{n} (x_{i} - y_{i})^{2}}$ 算法过程抉择k,聚类的数量。抉择k个点作为聚类核心。对每个样本点计算到k个聚类核心的间隔,采纳的是欧氏间隔,将其分类到间隔最近的类别中。依据每个类别,计算被分类在该类别中的所有点的核心。如果计算出来的核心和聚类核心雷同,则退出循环,否则以新的计算出来的核心为每个聚类的聚类核心,一直反复3 - 4步。外围代码设定K/Step按钮的监听器/jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { painting.assign(); painting.updateCentroids(); /*算法终止的话让按钮变灰并提醒算法完结*/ if (painting.stop(num++)) { jButton2.setText("End"); jButton2.setEnabled(false); } painting.repaint();}});计算欧式间隔/欧式间隔/double Euc(Point p1, Point p2) { double distance = 0.0;for (int i = 0; i < Dimension; ++i) distance += (p1.x[i] - p2.x[i]) * (p1.x[i] - p2.x[i]);return Math.sqrt(distance);}更新中心点/更新中心点/void updateCentroid(int clusterNum) { //将newCluster数组的那个中心点置空for (int i = 0; i < Dimension; ++i) newCluster[clusterNum].x[i] = 0;int clusterSize = 0;for (int i = 0; i < Nodes; ++i) if (p[i].cluster == clusterNum) { //这个簇中有多少点 clusterSize++; for (int j = 0; j < Dimension; ++j) newCluster[clusterNum].x[j] += p[i].x[j]; }if (clusterSize == 0) return;for (int i = 0; i < Dimension; ++i) newCluster[clusterNum].x[i] /= (double) clusterSize;}计算每个点的分类/调配数据点到哪个簇/void assignPoint(int x) { ...

May 18, 2023 · 2 min · jiezi

关于算法:WoW-游戏软件

拜访【WRITE-BUG数字空间】_[内附残缺源码和文档] 咱们抉择Tcp协定进行传输,之所以采纳tcp,首先是因为tcp传输稳固,相比于udp不稳固的传输,tcp能确保音讯肯定传输进来。而后是tcp有服务器,相比于 p2p 无服务器模型,tcp 能够记录数据,不便用于商用而且也比拟平安。 次要设计思路:咱们抉择Tcp协定进行传输,之所以采纳tcp,首先是因为tcp传输稳固,相比于udp不稳固的传输,tcp能确保音讯肯定传输进来。而后是tcp有服务器,相比于 p2p 无服务器模型,tcp 能够记录数据,不便用于商用而且也比拟平安。 客户端次要设计思路:基于TCP协定,实现发送音讯给服务器和从服务器接管音讯。要实现“迷你魔兽世界” 客户端的根本框架次要分为以下几个局部: 指令,依据输出的指令,比方login,move,attack等,客户端要判断指令的无效 指令设计,输出指令login playername,客户端向服务器发送登录申请,输出指令move direction,客户端向服务器发送挪动申请,输出指令attcak playername,客户端发送攻打另一位玩家的申请,输出指令speak message,示意该玩家要发言,内容为message,同样要向服务器发送申请,输出指令logout,示意退出登陆。 有效指令,如果输出的不是约定好的指令以及指令构造不正确,则客户端不向服务器发送申请。第一,登陆时玩家名不能有空格;第二,move指令前面的方向必须在north,south, west和east这几个方向中,如果为其余内容,则输入有效的方向的提醒;第三,输出attack 指令后要判断被攻打玩家是否在该玩家视线范畴内,如果不在视线范畴内,则输入错误信息 “The target is not visible”,玩家视线范畴为(x-5,x+5),(y-5,y+5),x和y为玩家坐标;第四,speak生成的数据中能够有空格;第五,logout指令,没有参数。 发送申请,依据输出的无效指令失去音讯类型和音讯内容,依照协定打包成字节发送给服务器。 解决应答,客户端接管到来自服务器的包,依据协定,先解析出音讯类型,再依据不同音讯类型的包的构造解析出包中的数据,再依据这些数据输入音讯。 线程问题,客户端必须和服务器端进行异步通信。例如,当其余玩家生成一个 speak 命令,客户端将会收到SPEAK_NOTIFY 信息从服务器端,只管客户端没有申请这个音讯。这意味着客户端不能阻塞用户的输出。所以将输出指令发送申请和接管播送/应答的函数设为两个线程,其中一个通过一个死循环,输出指令并解决,另一个也是通过死循环不停接管播送/应答并解决。 异样解决,当遇到一些非凡状况时须要做异样解决。 如果服务器端不可用并且连贯不能生成,客服端必须退出,且显示错误信息”The gate to the tiny world of warcraft is not ready.”。要实现这一点,须要通过try/except 连贯地址和端口号的时候检测异样。 如果客户端从服务器端收到一个异样音讯,客户端必须退出,而后输入谬误音讯”Meteor is striking the world.”。即如果客户端收到的包的长度不符合规范,或者解析到的音讯类型不存在或与包的长度不匹配,阐明客户端收到了一个异样音讯。 如果客户端和服务器端的连贯被异常中断,客服端必须退出,而后显示一个谬误音讯”The gate to the tiny world of warcraft has disappeared.”。因为python中的套接字断开连接时不会出现异常,而是会一直接管到空字符,所以在接管音讯的中央做一个判断,如果接管到的音讯长度为0,阐明连贯断开,则执行该异样解决。

May 18, 2023 · 1 min · jiezi

关于算法:图神经网络强化学习

拜访【WRITE-BUG数字空间】_[内附残缺源码和文档] 车辆门路布局问题(VRP)是运筹优化畛域最经典的优化问题之一。在此问题中,有若干个客户对某种货物有一定量的需要,车辆能够从仓库取货之后配送到客户手中。客户点与仓库点组成了一个配送网络,车辆能够在此网络中挪动从而实现配送工作。在求解此问题过程中,须要优化的决策变量为每个客户的配送工作应该调配到哪一辆车上,以及每辆车实现客户配送工作的先后顺序,优化指标为最小化车辆总行驶间隔和应用的车辆数。 一、试验要求复现以下论文的办法和后果:Duan,L., Zhan,Y., Hu,H., Gong,Y., Wei,J., Zhang,X., Xu,Y.: Efficiently solving the practical vehicle routing problem: A novel joint learning approach. In: KDD. pp.3054–3063 (2020)1.为了节省时间,训练用 10 个(或以上)的城市规模的算例。测试算例用 20 个(或者以上)规模。2.显示出算法训练收敛过程,可视化最初的解。可能的状况下,比照 OR-Tools 的求解成果(前面详细描述)。二、导言车辆门路布局问题(VRP)是运筹优化畛域最经典的优化问题之一。在此问题中,有若干个客户对某种货物有一定量的需要,车辆能够从仓库取货之后配送到客户手中。客户点与仓库点组成了一个配送网络,车辆能够在此网络中挪动从而实现配送工作。在求解此问题过程中,须要优化的决策变量为每个客户的配送工作应该调配到哪一辆车上,以及每辆车实现客户配送工作的先后顺序,优化指标为最小化车辆总行驶间隔和应用的车辆数。 故外围优化的指标为车辆总的固定成本 + 运输成本,VRP 问题最简略的模式就是使车辆具备容量的束缚(装载量无限)。每辆车从给定的节点登程和返回,优化的指标就是车辆相干费用和配送间隔的函数。目前的钻研工作分为两个流派:一种是通过运筹学,另一种是深度学习。运筹学的办法是把 VRP 定义为数学优化问题,通过准确或启发式算法达到最优或者近似最优解,然而实在场景的数据量下须要破费的工夫很多。而对于深度学习,之前的钻研是在人工生成的数据集上,疏忽了真实世界的运输网络。在实在 VRP 问题数据集上,没有一个办法能比得上 OR-tools,于是便想着提出一种新的办法。 三、算法流程这里次要是将论文中的算法联合我本人的了解再形容一遍Problem Setup: Graph Optimization Perspective首先从图优化的视角来形式化的形容以下 VRP 问题。 一个 VRP 实例,能够看做一张图 $G=(V, E)$ ,其中顶点汇合: $V={0, \ldots, n}$, 其中 $i=0$ 示意 depot, $i=1, \ldots, n$ 示意客户,边汇合: $\quad E=\left{e_{i j}\right}, i, j \in V$。 ...

May 18, 2023 · 1 min · jiezi

关于算法:算法可视化从入门到精通-10-大排序算法

在本文中,咱们将通过动图可视化加文字的模式,循序渐进全面介绍不同类型的算法及其用处(包含原理、优缺点及应用场景)并提供 Python 和 JavaScript 两种语言的示例代码。除此之外,每个算法都会附有一些技术阐明,比方应用大 \(O\) 符号来剖析不同算法的工夫复杂度和空间复杂度等,也提到了一些少数人都很容易了解的一些高级概述。 篇幅很长,急躁读完它,您会受益匪浅。 提要什么是排序算法? 排序算法有什么用?为什么排序算法如此重要?算法的评估规范数据结构中不同类型的排序算法 基于比拟的排序算法基于非比拟的排序算法就地排序算法稳固的排序算法自适应排序算法您须要理解的 10 大排序算法 冒泡排序插入排序疾速排序桶排序壳排序归并排序抉择排序基数排序梳排序排序比拟所有排序算法什么是最常见的排序算法?什么是排序算法?从实质上讲,排序算法是一种计算机程序,它将数据组织成特定的程序,例如字母程序或数字程序,通常是升序或降序。 排序算法有什么用?排序算法次要用于以高效的形式重新排列大量数据,以便更容易地对其进行搜寻和操作。它们还用于进步搜寻和合并等其余算法的效率,这些算法的操作依赖于排序数据。 为什么排序算法如此重要?排序算法用于按特定程序组织数据,这使得搜寻、拜访和剖析更加容易。在许多利用中,排序是数据处理流程的要害局部,排序算法的效率对系统的整体性能产生重大影响。 在数据库中 排序用于按特定程序检索记录,例如按日期、字母程序或数字程序。这使用户能够疾速找到他们须要的数据,而无需手动搜寻大量未分类的数据。在搜索引擎中 按相关性顺序排列搜寻后果。通过以这种形式对后果进行排序,用户能够疾速找到他们想要的信息,而不用筛选不相干的后果。在许多迷信和工程利用中 钻研人员能够进行数据分析和模仿,以深刻理解简单零碎,并对将来行为做出更精确的预测。算法的评估规范评估一个排序算法的好坏,通常按照以下规范进行评估: 工夫复杂度 是指在计算机科学与工程畛域实现一个算法所须要的工夫,是掂量一个算法优劣的重要参数,应用大 \(O\) 符号示意。一般而言,好的性能是 \(O(n \log n)\) ,坏的性能是 \(O(n^2)\),对于一个排序现实的性能是 \(O(n)\),但均匀而言不可能达到。空间复杂度 形容该算法或程序运行所须要的存储空间大小,和工夫复杂度相似,空间复杂度通常也应用大 \(O\) 符号来渐进地示意,例如 \(O(n)\)、 \(O(2^n)\)、\(O(n \log n)\) 等,其中 \(n\) 用来示意输出的长度,该值能够影响算法的空间复杂度。递归 一些算法要么是递归的,要么是非递归的,而其余算法可能两者都是(如归并排序)。稳定性 稳固排序算法会让本来有相等键值的纪录维持绝对秩序。也就是说,如果一个排序算法是稳固的,当有两个相等键值的纪录 \(R\) 和 \( S \),且在本来的列表中 \( R \) 呈现在 \( S \) 之前,在排序过的列表中 \( R \) 也会呈现在 \( S \) 之前。它们是否是比拟排序 比拟排序仅通过应用比拟运算符比拟两个元素来检查数据。算法是串行还是并行的自适应性 利用其输出中的现有程序,则它属于自适应排序系列。数据结构中不同类型的排序有多种类型的排序可用,排序算法的抉择取决于各种因素,例如数据集的大小、要排序的数据类型以及所需的工夫和空间复杂度。 基于比拟的排序算法比拟数据集中的元素,并依据比拟后果来确定两个元素中哪个应该放在序列后面。基于比拟的排序算法包含: 疾速排序堆排序归并排序插入排序抉择排序冒泡排序基于非比拟的排序算法这些不间接比拟元素,而是应用数据集的其余属性来确定它们的程序。基于非比拟的排序算法包含: 基数排序计数排序桶排序就地排序算法这些算法对数据进行就地排序(In-place) ,这意味着他们不须要额定内存来存储两头后果,这些算法只须要少数几个指针,所以它们的空间复杂度都是 \( O(log \ n) \)。就地排序算法的示例包含: ...

May 18, 2023 · 11 min · jiezi

关于算法:每日一题工作计划的最低难度

1335. 工作打算的最低难度关键词:动静布局、线性DP、枯燥栈题目起源:1335. 工作打算的最低难度 - 力扣(Leetcode) 题目形容 T动静布局 T线性DP T枯燥栈你须要制订一份 d 天的工作计划表。工作之间存在依赖,要想执行第 i 项工作,你必须实现全副 j 项工作( 0 <= j < i)。 你每天 至多 须要实现一项工作。工作打算的总难度是这 d 天每一天的难度之和,而一天的工作难度是当天应该实现工作的最大难度。 给你一个整数数组 jobDifficulty 和一个整数 d,别离代表工作难度和须要打算的天数。第 i 项工作的难度是 jobDifficulty[i]。 返回整个工作打算的 最小难度 。如果无奈制订工作打算,则返回 -1 。 输出:jobDifficulty = [6,5,4,3,2,1], d = 2输入:7 输出:jobDifficulty = [9,9,9], d = 4输入:-1数据范畴1 <= jobDifficulty.length <= 3000 <= jobDifficulty[i] <= 10001 <= d <= 10动静布局设f(i, j) = 前i天实现前j项工作的最小难度,则f(i, j) = min( f(i-1, k) + max(k+1..j) ),其中,k≥i(每天必须实现1项工作),max(k+1..j)示意工作k+1~j的最大难度。 ...

May 17, 2023 · 3 min · jiezi

关于算法:COMP612-图形算法研究

COMP612 Computer Graphics ProgrammingSemester 1, 2023Project: Helicopter SceneThis is an individual assignment. All work you submit must be entirely your own. The assignment isworth 70% and will be marked out of 100.• You must work from the provided animationcontroller-lights.c template.• You must complete the assignment in procedural C and freeGLUT (NOT C++).• You must not use any external libraries other than freeGLUT.• You must use Visual Studio 2022 and build/release an x86 (Win32) project.• Your project proposal must have been approved by the course lecturer.• Your final submitted code must compile, have graphical output, and run.• All the above criteria must be met for the assignment to be graded.Where your implementation idea or inspiration has been taken or adapted from other publishedsources those sources should be acknowledged appropriately in the C file header and detailed inyour developer’s logbook.It is expected that you will work consistently on this assignment, from hand out to due date. Timewill be allocated in class each week for you to ask questions, get help, and work on your assignment.Please be aware that this is not an assignment that can be completed at the last minute. Each classyou will be exposed to new concepts, and as we work through these concepts you will be able toprogress your assignment. ...

May 17, 2023 · 14 min · jiezi

关于算法:广度优先算法你了解多少

前言共事:了不起,看你常常看算法书,你晓得广度优先算法是什么吗? 了不起:你竟然晓得我常常看算法书,晓得一点,不是特地多。 共事:那就是晓得咯,你给我讲下,我想晓得 了不起:好的,让我来给您介绍一下广度优先算法(BFS)。BFS是一种罕用的图搜索算法,用于在一个图中遍历所有节点,并找到终点到指标节点的最短门路。 简略的说,BFS是从根节点开始,沿着树(图)的宽度遍历树(图)的节点。如果所有节点均被拜访,则算法停止。 个别用队列数据结构来辅助实现BFS算法。 如果您想理解更多对于BFS的内容,我能够为您具体介绍一下! 利用场景假如咱们要从一个网站开始爬取数据,这个网站有很多页面,每个页面可能蕴含多个链接,咱们须要找到网站中的所有页面,并将它们的数据保留下来。这个问题能够应用BFS算法来解决。 首先,咱们从网站的首页开始,将它作为终点,并将它退出到一个队列中。而后,咱们一直从队列中取出一个页面,并从这个页面中提取出所有的链接。对于每个链接,如果它还没有被拜访过,就将它退出到队列中。这样,咱们就能够遍历整个网站,并找到所有的页面。 上面是一个应用 PHP 实现的网络爬虫的BFS算法的代码示例: function bfs_crawler($start_url) { // 创立一个队列,用于存储待拜访的URL $queue = new SplQueue(); // 将终点URL退出队列中 $queue->enqueue($start_url); // 创立一个数组,用于存储已拜访过的URL $visited = [$start_url]; // 如果队列不为空,就始终进行循环 while (!$queue->isEmpty()) { // 取出队列的头部URL $url = $queue->dequeue(); // 从URL中获取HTML页面的内容 $html = file_get_contents($url); // 解决HTML页面中的数据,例如提取文本、图片等 // 提取HTML页面中的所有链接 preg_match_all('/<a\s+.*?href=[\"\'](.+?)[\"\'].*?>/i', $html, $matches); $links = array_unique($matches[1]); // 遍历以后页面的所有链接 foreach ($links as $link) { // 如果链接还没有被拜访过,就将它退出队列中,并将它标记为已拜访 if (!in_array($link, $visited)) { $visited[] = $link; $queue->enqueue($link); } } } // 返回所有拜访过的URL return $visited;}在这个代码中,$start_url是爬虫的终点URL,该函数会返回所有拜访过的URL。该函数应用BFS算法来遍历整个网站,并找到所有的页面。对于每个页面,它会从页面中提取出所有的链接,并将它们退出到队列中。这样,咱们就能够遍历整个网站,并找到所有的页面。 ...

May 16, 2023 · 1 min · jiezi

关于算法:COMP-ENGN6528解答

COMP/ENGN6528 Computer Vision - 2023 S1Computer Lab 3 (CLab-3) Objectives:This is CLab-3 for COMP/ENGN6528. The goal of this lab is to help you familiarizeyourself with, and practice:Basic multi-view camera geometry, camera calibration. They are the basicbuilding blocks for 3D visual reconstruction systems.The DLT method for two-view homography estimation.You are free to choose Python or Matlab to complete this assignment.Special Notes: Each computer lab has three weeks. Tutors/Lab instructors will provide basicsupervision in the following three weeks when students can discuss thepotential questions with tutors.Your Lab assignment will be marked based on the overall quality of your LabReport in PDF format. The report is to be uploaded to Wattle site before thedue time, which is usually on the Sunday evening of Week-3 session of yourlab (21st May, 2023). Please note that you must report on what you have done.Only submitting code will get a low mark.It is normal if you cannot finish all the tasks within the two 2-hour sessions —these tasks are designed so that you will have to spend more time in order tofinish all the tasks including finishing your Lab report. This suggests that,before attending the third lab session (in Week-3 session of each CLab), youmust make sure that you have almost complete 80% of the assignment.Academic IntegrityYou are expected to comply with the University Policy on Academic Integrity andPlagiarism. You are allowed to talk with / work with other students on lab and projectassignments. You can share ideas but not code, you should submit your own work.Your course instructors reserve the right to determine an appropriate penalty based onthe violation of academic dishonesty that occurs. Violations of the university policycan result in severe penalties.Task-1: 3D-2D Camera Calibration (18 marks) ...

May 16, 2023 · 8 min · jiezi

关于算法:STAT-2011-概率理论

STAT 2011 Probability and Estimation Theory – Semester 1, 2023Computer Assignment – Due by 23:59pm 21 MayInstructions: Complete this computer assignment, prepare a report including your code, andany output, plots or comments required by the questions and submit it on the Assignment itemon Canvas. The file upload format is limited to pdf and html. We highly encourage you to knityour report using R Markdown, but the report can be created any way that is convenient aslong as it includes all the required content. ...

May 16, 2023 · 3 min · jiezi

关于算法:什么是人工智能领域的强化学习

强化学习(Reinforcement Learning,简称RL)是人工智能畛域的一个重要钻研方向,它是一种基于智能体(Agent)与环境(Environment)交互的学习办法。强化学习容许智能体在一直尝试和摸索的过程中,通过学习到的策略(Policy)来实现目标。它的核心思想是,在学习过程中,在一个状态(State)下,智能体采取一个动作(Action),而后环境会给予一个处分(Reward),智能领会依据处分来调整它的策略,以实现长期累积处分的最大化。 强化学习的根本框架包含以下几个组成部分: 智能体(Agent):在强化学习中,智能体是次要的决策者,负责在给定的状态下抉择适合的动作,以达到某种指标。环境(Environment):环境是智能体所处的内部条件,它为智能体提供状态信息,以及智能体采取动作后产生的处分。智能体须要在这个环境中学习如何抉择适合的动作。状态(State):状态是形容智能体在环境中的地位或状况的信息,它是智能体的输出,用于决策。动作(Action):动作是智能体在某个状态下能够采取的行为。动作的抉择间接影响到智能体是否达到目标。处分(Reward):处分是环境依据智能体采取的动作给予的反馈,它能够是负数、正数或零。处分的大小能够反映智能体的行为是否靠近指标。智能体的指标是最大化长期累积处分。策略(Policy):策略是智能体在给定状态下抉择动作的规定。强化学习的指标是找到一种策略,使得智能体可能在环境中实现长期累积处分的最大化。强化学习的学习过程能够概括为以下几个步骤: 初始化:智能体随机抉择一个初始状态,初始化策略和价值函数(Value Function)。口头抉择:智能体依据以后状态和策略抉择一个动作。环境反馈:智能体执行动作后,环境依据这个动作给予一个处分,并将智能体转移到一个新的状态。

May 16, 2023 · 1 min · jiezi

关于算法:PROG2003云计算开发

PROG2003 2023 T2 Cloud Systems DevelopmentAssignment 1Weight: 30% of your final markDue: Week 3 Monday (15 May 2023) at 23:59 PM QLD timeSpecificationsYour task is to create a website that prints how much of the storage has been used for each studentfolder in an S3 bucket. To make the website dynamic, you need to create a Cloud9 app that wouldwork as a “backend” for the website. Your submission will be evaluated based on:• whether instructions have been followed;• correct functionality;• correct implementation; and• comments inside the programGetting HelpThis assignment, which is to be completed individually, is your chance to gain an understanding ofthe fundamental concepts of listing and creating S3 objects on which later learning will be based. Itis important that you master these concepts yourself.Since you are mastering fundamental skills, you are permitted to work from the examples in theMySCU site or textbook, but you must acknowledge assistance from other textbooks or classmates.In particular, you must not use online material or help from others, as this would prevent you frommastering these concepts.This diagram will help you understand where you can get help:Encouraged Attribution Required Not acceptable Ask tutorBe aware that if you do get help from one of the red sources, you will be reported foracademic misconduct, which may have serious penalties. Please visit the following link for theguidelines: https://policies.scu.edu.au/download.php?associated=1&id=326&...(Go to the next page)PROG2003 2023 T2 Cloud Systems DevelopmentATTENTION: Assignment 1 must be completed in the UA-provided AWS account. Personal AWSaccounts will not be accepted, and there will be a significant mark deduction. If your AWS accountis not accessible for any reason and the marker cannot check your app, you will also losesignificant marks. No excuse will be considered.Overview: You need to create a static website that prints the folder usage information for eachstudent folder in an S3 bucket. You will implement a Cloud9 app that will count the number of files,total file size(in MB), and remaining space (in MB) for each student folder. You will host the websitewithin the same bucket and it has an index and error page. Please see below the examplescreenshots of the index page.Example screen:Details: The details of the assignment tasks are described below.Part A: The static website (6 marks): You will use two HTML files - home.html and notfound.html, asthe index and error page, respectively. Assume that your S3 bucket consists of folders for students.Each folder belongs to a student and the folder name must be the student ID (assume 7 digits). Eachfolder can consist of any files (web, text, image, excel, and others). Let’s assume students will not beable to add more files when his/her storage exceeds their limit. Assume that each student has 100MB space in total.The home.html will print a count for existing files in each folder within an S3 bucket, calculate thetotal file size (in MB), and calculate the remaining space for each student.Remember to configure the bucket with the appropriate “bucket policy” and “public access” for thepublic access of the website hosting. If you add or delete files in the bucket, the index page mustprint an updated list based on the existing files in the bucket.The notfound.html will be very simple and will display a relevant error message, e.g., “page notfound”. The error page appears upon entering the wrong/invalid URL.Part B: The Cloud9 app (24 marks): You might be wondering how it would be possible for a staticwebsite to always display the current files in an S3 bucket. This is a dynamic behavior. You need toimplement a Cloud9 app that will do the following each time it runs.a. counting the number of files in each folder, calculate the total file size, and the remainingspace. You need to write a separate method for listing objects, calculating the usage andremaining space.b. preparing html content for the ‘home.html’. The ‘home.html’ will contain information aboutthe list of students and their folder usage information. This information must be wrappedwith HTML formatted string. You will need a separate method for this feature.c. creating a new ‘home.html’ in the bucket, which will act as the index file for the website.You will need a separate method for this feature.PROG2003 2023 T2 Cloud Systems DevelopmentYou need to execute the Cloud9 app each time before running the website so that the index pagealways displays the updated list of students and their folder usage information.Requirements: Your website and Cloud9 app must fulfill the following requirements. You will losemarks otherwise.• Your Cloud9 app must be named yourscuusernameA1App.• You will use a single bucket for the whole assignment and its name must beyourscuusername-a1-bucket.• Your Cloud9 app must have three separate methods.• Your Cloud9 app must use exception handling and loop(s).• You must use AWS SDK v 2.x to implement the Cloud9 app.• You must implement the assignment in the UA-provided AWS account, personal AWSaccount will not be accepted.• You need to add detailed comments inside your source code.Solution hints: Check the following hints for implementation.• You will be taught how to list objects, retrieve their names and file size, which will help youto implement the counting feature.• You will also be taught about creating objects in an S3 bucket, which will help you implementthe creating feature. For this assignment, you must create an HTML object (home.html) thatwill be served upon invoking the static website. A newly created object in S3 bucket has acontent type of “application/octet”, by default. Such objects behave as attachments, and willnot fulfil the purpose of a website. Do some research on the content-type property of thePutObjectRequest class for this purpose.• For the preparing feature, you need to wrap the file type and count with HTML code. Youcan use an unordered HTML list (<ul>…..</ul>) to display the list. Check this link out:https://www.w3schools.com/html/html_lists_unordered.asp.Submission checklist: The marker will access your AWS Academy workspace (provided by the UA),check your app, and directly mark your app from there. You have to zip the app project folder andsubmit it in Blackboard as well. The Blackboard submission list:• A zipped app folder for the Cloud9 app (yourscuusernameA1App.zip). You can right-clickand download your app from the Cloud9 interface.• A text file (named link.txt) containing the URL of your hosted static website. ...

May 16, 2023 · 5 min · jiezi

关于算法:每日一题按列翻转得到最大值等行数

1072. 按列翻转失去最大值等行数关键词:哈希表、数组题目起源:1072. 按列翻转失去最大值等行数 - 力扣(Leetcode) 题目形容 T哈希表 T数组给定 m x n 矩阵 matrix 。 你能够从中选出任意数量的列并翻转其上的 每个 单元格。(即翻转后,单元格的值从 0 变成 1,或者从 1 变为 0 。) 返回 通过一些翻转后,行与行之间所有值都相等的最大行数。 输出:matrix = [[0,1],[1,1]]输入:1解释:不进行翻转,有 1 行所有值都相等。输出:matrix = [[0,1],[1,0]]输入:2解释:翻转第一列的值之后,这两行都由相等的值组成。输出:matrix = [[0,0,0],[0,0,1],[1,1,0]]输入:2解释:翻转前两列的值之后,后两行由相等的值组成。问题剖析论断:最初由雷同元素形成的行必然雷同或相同。 这个论断显然成立,最初由雷同元素形成的行要么全是0,要么全是1。 推论:最初由雷同元素形成的行在最后也是雷同或相同。 这个论断也很好证实,设a和b为最初由雷同元素组成的两行,若最初a[i]=b[i],因为每次操作会施加在同一列上,所以,对a[i]和b[i]施加的操作雷同,所以最后也有a[i]=b[i];若最初a[i]!=b[i],也即二者相同,同理,因为对二者施加的操作雷同,所以最后也有a[i]!=b[i]。 由此,可将最后雷同或相同的行归为一类,于是,可将初始矩阵的行分为若干类,最初由雷同元素形成的行必然属于同一类,且该类只含这些行。故,要求最大行数,等价于求找到含有行数最多的类,该类含有的行数即为最大行数。 因为同一类的行雷同或相同,而属于该类的行要么以0结尾要么以1结尾,无妨将以0结尾的行作为该类的key,对于以1结尾的行,将整行取反便失去其所属类的key。由上,可失去每行的key,从而统计出每类含有的行数,最初找到含有最多行数的类所含有的行数。 代码实现int maxEqualRowsAfterFlips(vector<vector<int>> &matrix) { int n = matrix[0].size(); unordered_map<string, int> mp; for (const auto &row: matrix) { string s(n, '0'); for (int j = 0; j < n; j++) s[j] += row[j] ^ row[0]; // row[0]为1则取反 mp[s]++; } // 找到蕴含行数最多的类别蕴含的行数 int res = 0; for (auto &[k, v]: mp) res = max(res, v); return res;}工夫复杂度:O(mn) ...

May 15, 2023 · 1 min · jiezi

关于算法:一图看懂CodeArts-Deploy-5大特性带你玩转部署服务

华为云继续部署服务CodeArts Deploy,通过模块化自在编排部署流程,实现软件的自动化部署,基于其易入门、性能全、集成度高、自动化、牢靠的部署能力,可能帮您疾速实现业务上云,全面晋升软件的交付效率,显著晋升交付品质! 产品详情地址:部署CodeArts Deploy_一键部署到云主机和容器_多种部署环境_华为云

May 15, 2023 · 1 min · jiezi

关于算法:COMP3310i测试算法

Page 1 of 5COMP3310/ENGN3539/etc Assignment 3 – Testing MQTTIntroduction:• This assignment is worth 15% of the final mark• It is due by Tuesday 23 May 23.55 AEST (Canberra time)• Late submissions will not be accepted, except in special circumstances.• Any extensions should be requested well before the due date, with appropriate evidence. Please usethe extension-request link on wattle rather than direct emails.Assignment 3MQTT is the most common open IoT protocol being deployed today. It provides a publisher/subscribermodel, using a broker or server. It allows for an almost-unbounded number of sources to publishinformation, each at their own rate, and subscribers to receive information (and act on it). As such, it isdesigned to provide high-performance communication mechanisms, with minimal delays and excellentscaling performance. We’ll use it to monitor the performance of some imaginary system: say counting thetotal kilograms of minerals rushing by on a conveyor belt, that you can control. This assignment will look atthe functionality and performance of the publishers, brokers, the network and the subscribers.This is a coding, analysis and writing assignment. You may code in C/Java/Python or any programminglanguage that a tutor can assess (hope that’s enough for everyone), and yes, you may use MQTT and otherhelper libraries. The assessment will not rely solely on running on your code, but more on the datagathering and your analysis. However, we will review the code and may briefly test it against our ownbroker running in the usual lab-type environments or similar. You will need to identify in yourREADME/code any libraries you are using.Please note, you will be working in pairs or small groups for a key part of this assignment, to test eachother’s systems across the Internet. If you don’t have somebody to work with, ask your tutors NOW to helpidentify somebody in your tutorial group, or post to the Wattle Forum under the pinned Find-a-Partnertopic. You do not need to be in the same location at any time.SubmittingYou will be submitting two things: your code and your analysis report. Note that there will be twosubmission links on the Wattle course-site: ...

May 15, 2023 · 9 min · jiezi

关于算法:COMP3023-23S-动态编程

COMP3023 23S Programming AssignmentLecture 10 introduces the dynamic programming algorithm for the 0-1 knapsack problem. Inthis programming assignment, you need to implement the algorithm under the followingrequirements.Environment The implementation must be done in standard C or C++ (using gcc/g++ compiler).Please do not use visual studio. For the students who do not have the compiler, you canuse online GDB at https://www.onlinegdb.com/.The submissions which cannot pass gcc/g++ compiling, will directly receive 0. Tocheck whether your code can pass compiling, use online GDB at least.Implementation StructureIn your program, you need to implement three source files “main.c”, “lib.h”, and “lib.c”(“main.cpp”, “lib.h” and “lib.cpp” if you use C++).For “main.c” (or “main.cpp”)It only contains the “main” function.It reads inputs from .txt files. The input txt file is passed to the main function as anargument.Each txt file contains exactly one instance.For “lib.h” and “lib.c” (or “lib.h” and “lib.cpp”).h is the header file for .c (or .cpp).They contain all other functions except “main”.FunctionalityThe input txt file has 3 lines. The first line has only one integer, the capacity of the bag.The second line has a bunch of positive integers for the value of each item. Two integersare separated by a comma “,”. The third line is in the same format as the second for theweight of each item.When the calculation is finished, print the optimal value and optimal solution(s) onefor each line on the screen. (The optimal value is unique, but the optimal solution maynot.)Sort the items in the optimal solution(s) in the decreasing order of item indices.The index of items starts from 1.Sample:In the folder “Sample”, you will find all the source files described above. Take the C versionin subfolder “c” for example (the C++ version is in subfolder “c++”). Currently, all source filesare empty. The main function simple prints the argument on the screen. “lib.c” only tests thelinkage. The package also contains “make.bat”. You can open it by a TXT editor. Then, youcan see the compilation commands.After executing “make.bat” (Note that .bat files are only executable in Windows), you will have“knapsack.exe”.Suppose the input txt file is named as “in.txt”, we execute “knapsack in.txt”.We see that “in.txt” is printed and “lib.h” and “lib.c” are tested.Example instanceSuppose the input file (in1.txt) contains103,5,2,63,4,2,5When you finished, the output should be something likeBecause4 + 3 + 1 = 5 + 2 + 3 = 10 ≤ 4 + 3 + 1 = 6 + 2 + 3 = 11And4 + 2 = 9 ≤ 4 + 2 = 11Submission requirementsYou need to submit three source files “main.c”, “lib.h”, and “lib.c” (“main.cpp”, “lib.h” and“lib.cpp” if you use C++) separately to iSpace.

May 15, 2023 · 3 min · jiezi

关于算法:XJCO-1921路由计划

XJCO 1921- Programming ProjectCoursework 2 – Route PlanningDeadline: 12 PM BST on Monday, 15 May 2023This work is the second coursework for this module. It corresponds to 60% of the overall assessment forthis module. Submissions should be made via Gradescope.Course SpecificationCreate a software program in C to compute the best path between 2 points on a map according to thespecification below. Use Github (link via Minerva) for version control throughout the project. ...

May 15, 2023 · 7 min · jiezi

关于算法:CSCI-1110

CSCI 1110: Assignment 0Due: 11:59 pm, Friday, May 12, 2023The purpose of this assignment is to allow you to self-assess your readiness for this course. If you arestruggling to complete this assignment, and have not taken CSCI 1100 or CSCI 1105, please consider takingCSCI 1105 before this course. This assignment may be done in any programming language.For this problem you will be provided with sample inputs and corresponding outputs. All input is done viathe console (unless specified otherwise) and all output is to be done to the console as well. If you aresubmitting your assignment via Codio, you can test it by clicking the Check It button. If you are using alanguage not supported by Codio, a zip file containing the test inputs and outputs is provided for testing.Please note that unlike the rest of the assignments in this course, this assignment is strictly graded basedon functionality. This ensures that you receive the appropriate feedback to decide if CSCI 1110 is the rightcourse for you. Assignment submission and grading is described in the last section of this assignment.There are three problems and each one builds on the next. Completing Problem 1 yields a grade of 50%(a pass); completing Problem 2 yields a grade of 80%; and completing Problem 3 yields a grade of 100%.BackgroundYour company is the producer of one-dimensional jigsaw puzzles. A new sensation that is sweeping thenation. A one-dimensional jigsaw puzzle comprises a set of puzzle pieces that must be assembled in thecorrect order to reveal an image (or a word). Each puzzle piece has two sides that must complement thepieces to the right and left of it, except for the end pieces, which must match only on one side.Figure 1: Example of a 1D puzzles whose pieces spell "PIZZLES!"Each puzzle piece can be represented by three pieces of information: ...

May 15, 2023 · 7 min · jiezi

关于算法:每日一题距离相等的条形码

1054. 间隔相等的条形码关键词:计数、哈希表题目起源:1054. 间隔相等的条形码 - 力扣(Leetcode) 题目形容 T计数 T哈希表在一个仓库里,有一排条形码,其中第 i 个条形码为 barcodes[i]。 请你重新排列这些条形码,使其中任意两个相邻的条形码不能相等。 你能够返回任何满足该要求的答案,此题保障存在答案。 输出:barcodes = [1,1,1,2,2,2]输入:[2,1,2,1,2,1]输出:barcodes = [1,1,1,1,2,2,3,3]输入:[1,3,1,3,2,1,2,1]数据范畴1 <= barcodes.length <= 100001 <= barcodes[i] <= 10000优先队列直观上来看,咱们应该尽可能把呈现次数多的放在后面,于是,可采纳优先队列来保护每个数呈现的次数,每次取出呈现次数最多的数放到排列开端,留神,每取出一个数,该数的呈现次数就须要-1,当然,如果这个数与以后末尾数雷同,则以后必须换下一个数。 vector<int> rearrangeBarcodes(vector<int> &barcodes) { // 统计各数呈现次数 unordered_map<int, int> cnt; for (auto &e: barcodes)cnt[e]++; // 优先队列 priority_queue<pair<int, int>> q; for (const auto &[a, b]: cnt)q.emplace(b, a); // 每次取出队头元素 vector<int> res; while (q.size()) { auto [xs, x] = q.top(); q.pop(); // 排列开端不是x则往开端放x if (res.empty() || res.back() != x) { res.push_back(x); if (xs > 1)q.emplace(xs - 1, x); } // 如果开端是x则只能放其它数 else { // 题目保障有答案,所以到此处队列必然不为空 auto [ys, y] = q.top(); q.pop(); res.push_back(y); if (ys > 1)q.emplace(ys - 1, y); // 把x放回去 q.emplace(xs, x); } } return res;}工夫复杂度:O(nlog(n)) ...

May 14, 2023 · 1 min · jiezi

关于算法:MEC208-控制系统

MEC208 Instrumentation and Control SystemS2, 2022-2023Computer Lab (Lab 2):Control System CAD and CAS using MATLABDr. Chee Shen LIM (MEC208, Part 2)Name:Student ID:Group (1 or 2):Date:MEC208 Lab 2: Control System CAD and CAS using MATLABPage 4 of 14© ver22-23-20230504, by C. S. LimReport FormatThe format of the lab/assignment report should be of the following:• The report should be of single column, font size 11, font style “Times New Roman”.Please be reminded that handwritten reports will NOT be accepted.• All figures must be clearly numbered and all plots must be clearly labelled.• In your report, whenever necessary, you are expected to explain concisely your approach(i.e., with full sentence and proper grammar, but please avoid unnecessarily longexplanation).• In your answer for each question, do also include all MATLAB code/script that you usedto obtain the answers or plots (note: do not separately submit those raw .m files; answerfor each question should contain some MATLAB scripts). These codes/scripts should becopied properly into the report, and should be standalone. For example, if you includethe code for Question 2a, you must make sure that the codes in this part alone (not linkedto other parts) can be copied by the marker into MATLAB for a quick, successfulverification.• For analytical questions, whenever necessary, do also include your analysis and derivation.Marks will be given on the following basis:• The 10 questions in the “Computer Lab Work” section carry a total of 100 marks. Eachquestion carries 5 to 15 marks, depending on the complexity of the questions.• Sub-marks will be awarded to technically correct analyses and comments, MATLABscripts, mathematical derivation (as necessitated by the questions), graphs/plots (andannotations of the plots), and numerical answers. All analysis and comments should haveproper sentence structure and correct grammar.MEC208 Lab 2: Control System CAD and CAS using MATLABPage 5 of 14© ver22-23-20230504, by C. S. LimExamplesThis part is to introduce about how to start using the Control System Toolbox in MATLAB forcontrol system CAD and CAS. You are suggested to go through the examples (in this section, oreven from other online resources) before you start working on the assignment tasks.Example 1: Input a system described by a transfer functionTo construct a system model in MATLAB, the command “tf” can be used. For example, to obtainthe following input transfer function:2 + + 14 + 23 + 5 + 2 + 14 + 23 + 32 + 3 + 10 ∙ 102 + 3» sys1=tf([1 1 1], [1 2 0 5 2])Transfer function: ...

May 14, 2023 · 12 min · jiezi

关于算法:DTS104TC数值分析

Module code and Title DTS104TC Numerical MethodsSchool Title School of Artificial Intelligence and Advanced ComputingAssignment Title Assignment 1 Submission Deadline June 2, 2023. 5pm (GMT+8)Final Word Count -If you agree to let the university use your work anonymously for teaching and learning purposes, please type “yes” here. I certify that I have read and understood the University’s Policy for dealing with Plagiarism, Collusion and the Fabrication of Data (available on Learning Mall Online). With reference to this policy I certify that:My work does not contain any instances of plagiarism and/or collusion.My work does not contain any fabricated data. ...

May 14, 2023 · 9 min · jiezi

关于算法:单调队列算法模板及应用

文章和代码曾经归档至【Github仓库:https://github.com/timerring/algorithms-notes 】或者【AIShareLab】回复 算法笔记 也可获取。队列算法模板 // hh 示意队头,tt示意队尾int q[N], hh = 0, tt = -1;// 向队尾插入一个数q[ ++ tt] = x;// 从队头弹出一个数hh ++ ;// 队头的值q[hh];// 对尾的值q[tt];// 判断队列是否为空/* if(hh <= tt) not empty else empty*/if (hh <= tt){}例题:滑动窗口枯燥队列的利用:求滑动窗口中的最大值和最小值 第一步把新元素插入队尾,第二步把滑进来的元素从队首弹出来。 给定一个大小为 $n≤10^6$ 的数组。 有一个大小为 k 的滑动窗口,它从数组的最右边挪动到最左边。 你只能在窗口中看到 k 个数字。 每次滑动窗口向右挪动一个地位。 以下是一个例子: 该数组为 [1 3 -1 -3 5 3 6 7],k 为 3。 窗口地位最小值最大值[1 3 -1] -3 5 3 6 7-131 [3 -1 -3] 5 3 6 7-331 3 [-1 -3 5] 3 6 7-351 3 -1 [-3 5 3] 6 7-351 3 -1 -3 [5 3 6] 7361 3 -1 -3 5 [3 6 7]37你的工作是确定滑动窗口位于每个地位时,窗口中的最大值和最小值。 ...

May 14, 2023 · 2 min · jiezi

关于算法:每日一题翻转子数组得到最大的数组值

1330. 翻转子数组失去最大的数组值关键词:数学、分类探讨题目起源:1330. 翻转子数组失去最大的数组值 - 力扣(Leetcode) 题目形容 T数学给你一个整数数组 nums 。「数组值」定义为所有满足 0 <= i < nums.length-1 的 |nums[i]-nums[i+1]| 的和。 你能够抉择给定数组的任意子数组,并将该子数组翻转。但你只能执行这个操作 一次 。 请你找到可行的最大 数组值 。 输出:nums = [2,3,1,5,4]输入:10解释:通过翻转子数组 [3,1,5] ,数组变成 [2,5,1,3,4] ,数组值为 10 。输出:nums = [2,4,9,24,2,1,10]输入:68数据范畴1 <= nums.length <= 3*10^4-10^5 <= nums[i] <= 10^5问题剖析设翻转的点为i和j,不难发现,翻转整个数组或者翻转单个元素并不影响数组值,故只思考i<j的状况。 设i-1处为A,i处为B,j处为C,j+1处为D。 先思考边界,即i=0或者j=n-1的状况,此时A或D不存在,那么翻转后的数组值可通过两遍扫描失去。 当A、B、C、D均存在时,有如下等式成立, v = 翻转后的值 - 翻转前的值 = ( |A-C| + |B-D| ) - ( |A-B| + |C-D| )咱们的指标就是使得v尽可能大,间接枚举A、B、C、D是不太行的,复杂度较高,所以须要进一步分类探讨,排除某些状况,分类探讨必定围绕去绝对值进行(以下不思考相等的状况,相等的状况放到大于或小于都能够)。 当A>C且B>D时 若A>B且C>D时,v = 2B-2C;若A>B且C<D时,v = 2B-2D;若A<B且C>D时,v = 2A-2C;若A<B且C<D时,v = 2A-2D;发现,AB取小,CD取大 ...

May 13, 2023 · 2 min · jiezi

关于算法:单调栈模板总结及应用

文章和代码曾经归档至【Github仓库:https://github.com/timerring/algorithms-notes 】或者公众号【AIShareLab】回复 算法笔记 也可获取。枯燥栈模板栈:先进后出。 队列:先进先出。 数组模仿栈和队列相较于STL的益处在于速度快,尽管在理论编译的时候会有O2优化,使两者相差无几,然而在算法题中个别没有优化。栈算法模板// 栈定义为stk[N],tt示意栈顶,初始化为0int stk[N], tt = 0;// 向栈顶插入一个数stk[ ++ tt] = x;// 从栈顶弹出一个数tt -- ;// 栈顶的值stk[tt];// 判断栈是否为空/* if(tt > 0) not empty else empty*/if (tt > 0){ }枯燥栈罕用与给定一个数,寻找在这个序列中每一个数的右边离他最近的且比他小的数在什么中央。 例题:枯燥栈给定一个长度为 N 的整数数列,输入每个数右边第一个比它小的数,如果不存在则输入 −1。 输出格局 第一行蕴含整数 N,示意数列长度。 第二行蕴含 N 个整数,示意整数数列。 输入格局 共一行,蕴含 N 个整数,其中第 i 个数示意第 i 个数的右边第一个比它小的数,如果不存在则输入 −1。 数据范畴 $1≤N≤10^5$$1≤$数列中元素$≤10^9$ 输出样例: 53 4 2 7 5输入样例: -1 3 -1 2 2基本思路定义一个栈,别离读入数据,而后判断栈中的数字,如果栈顶的数字大于等于读入的x,则将该数出栈(把大于它的所有数剔除),直到栈顶数字小于该数,输入该数,而后将x存入栈顶。这样能够保障栈内的数字始终是一个线性的存储。即输出的x能够找到离它最近的比他小的数。 code# include <iostream>using namespace std;const int N = 100010;int n;int stk[N], tt;int main(){ cin >> n; for(int i = 0; i < n; i++) { int x; cin >> x; while(tt && stk[tt] >= x) tt --; // 如果栈顶元素大于以后待入栈元素,则出栈 if(tt) cout << stk[tt] << ' '; // 如果栈不空,则该栈顶元素就是左侧第一个比它小的元素 else cout << -1 << ' '; // 如果栈空,则没有比该元素小的值,输入 -1 // 再将该元素增加进去 stk[ ++ tt] = x; } return 0;}尽管这个算法中有两个循环,然而理论针对第二层循环,每个数只会有压入和弹出两个操作,并没有波及到遍历,因而工夫耗费为2N,工夫复杂度为O(N)。 ...

May 13, 2023 · 1 min · jiezi

关于算法:如何评价目前最流行的两个深度学习框架谷歌公司的TensorFlow和脸书公司的PyTorch

TensorFlow和PyTorch是目前最风行的两个深度学习框架,各有劣势和特点。 TensorFlow(谷歌)成熟度高:TensorFlow是较早公布的深度学习框架,通过多年倒退,性能十分欠缺且稳固。生态系统丰盛:TensorFlow的用户群体宏大,社区沉闷,有大量的教程、实例和开源我的项目供参考。此外,谷歌还推出了与TensorFlow严密集成的TensorBoard可视化工具,帮忙开发者更好地了解和调试神经网络。部署不便:TensorFlow提供了多种部署选项,能够在多种平台(如云服务器、挪动设施等)上运行。性能优化:TensorFlow反对多种硬件加速器,如GPU和TPU,能够对计算工作进行优化和减速。PyTorch(脸书)动静计算图:PyTorch采纳动静计算图技术,使得网络结构的构建和调试更加灵便。这一特点使得PyTorch在钻研畛域十分受欢迎,尤其适宜疾速试验和摸索新算法。简洁易用:PyTorch的API设计简洁直观,易于学习和应用。此外,其提供了丰盛的预训练模型和数据加载工具,能够帮忙开发者疾速搭建神经网络。社区沉闷:只管PyTorch公布较晚,但其社区倒退迅速且沉闷。当初,许多学术论文和开源我的项目都抉择应用PyTorch作为实现工具。与Python集成:PyTorch和Python语言的集成度十分高,使得开发者能够更不便地利用Python的丰盛生态系统。TensorFlow是由谷歌开发的深度学习框架,它在工业界宽泛应用,并且领有一个宏大的社区反对。 TensorFlow的长处之一是它的可扩展性,能够在不同的设施上运行,包含CPU、GPU和TPU。此外,TensorFlow的运行效率也比拟高,它能够解决大型数据集和简单的模型,这使得它在工业界中被宽泛应用。 PyTorch是由Facebook开发的深度学习框架,它的次要长处之一是易于应用和调试。 PyTorch应用动静图形来构建模型,这使得它非常适合钻研人员和实验室应用。此外,PyTorch还具备灵活性,能够不便地进行自定义操作,而且其文档和社区反对也十分好。 总的来说,TensorFlow和PyTorch各有长处,抉择哪个框架取决于具体需要和场景。对于须要稳定性、性能和生产部署的企业级利用来说,TensorFlow可能更适宜。而对于须要疾速试验和钻研新算法的场景,PyTorch可能更具劣势。不过,随着两个框架的不断更新和倒退,这些差别可能会逐步减小。

May 12, 2023 · 1 min · jiezi

关于算法:什么是人工智能领域的过拟合和欠拟合

在人工智能畛域中,过拟合和欠拟合是两个常见的问题,它们都会对模型的性能和成果产生负面影响。本文将介绍过拟合和欠拟合的概念、起因以及解决办法。 一、过拟合 过拟合指的是模型在训练集上体现得十分好,但在测试集或理论利用中体现不佳的状况。过拟合的次要起因是模型过于简单,以至于在训练集中学习了一些噪声或细节信息,导致无奈泛化到测试集或理论利用中。具体来说,过拟合可能会导致以下几个问题: 低偏差高方差:模型的预测后果与实在后果之间存在较大的方差,即模型的预测后果具备较高的波动性,而且对训练集的拟合十分好,但对测试集的预测体现不佳。失去可解释性:过拟合的模型往往会关注一些无关或不重要的特色,这些特色可能无法解释或解释性很差,从而导致模型的可解释性变差。浪费时间和资源:在过拟合的状况下,模型可能会适度关注训练集中的细节信息,从而节约大量工夫和计算资源,对理论利用的成果不佳。如何解决过拟合问题? 减少训练集数据:通过减少训练集数据,能够缩小模型对噪声或细节信息的关注,进步模型的泛化能力。简化模型:通过简化模型构造或缩小模型参数,能够升高模型的复杂度,缩小过拟合的可能性。正则化:通过增加正则化项来限度模型参数的大小,避免模型适度拟合。早停:在训练过程中,能够设置一个适合的进行训练的条件,例如验证集准确率不再进步等。二、欠拟合 欠拟合指的是模型无奈充沛学习训练集的法则,导致模型在训练集和测试集上体现都不佳。欠拟合的次要起因是模型过于简略,无奈拟合数据的复杂性和多样性。 过拟合(overfitting)和欠拟合(underfitting)是机器学习和人工智能畛域中两种常见的问题。它们形容了模型在训练数据和新数据上的体现差别。了解这两种景象对于构建无效的模型至关重要。 欠拟合是指模型在训练数据集上没有取得足够的拟合,因而在测试数据集(即新数据)上的体现也较差。这通常是因为模型太简略,无奈捕捉到数据中的所有关系和构造。欠拟合的模型具备较高的偏差(bias),这意味着它们在预测时会偏向于产生较大的误差。 过拟合是指模型在训练数据集上体现良好,但在测试数据集上体现较差。这通常是因为模型过于简单,以至于它学到了训练数据中的噪声或特定特色,而没有学到实在的、能够泛化到新数据的法则。过拟合的模型具备较高的方差(variance),这意味着它们在不同数据集上的预测后果可能具备较大的差别。 为了防止欠拟合和过拟合,咱们须要在模型的复杂度和泛化能力之间找到一个平衡点。以下是一些罕用办法: 抉择适合的模型:抉择一个适当的模型是十分重要的。太简略的模型可能会导致欠拟合,而太简单的模型可能会导致过拟合。通常,能够通过比照不同模型的体现来找到适合的模型。例如,能够尝试应用线性回归、反对向量机、神经网络等不同类型的模型,并通过穿插验证来抉择最佳模型。增加更多数据:减少训练数据能够帮忙模型更好地泛化。当模型能够拜访更多的数据时,它就能更好地学习到数据中的实在构造,而不是训练数据中的噪声。特色工程:抉择适合的特色对于防止欠拟合和过拟合十分重要。通过对原始特色进行转换、组合或筛选,能够创立出更能反映数据结构的特色。此外,升高特色维度也有助于缩小过拟合的危险。正则化:正则化是一种惩办模型复杂度的技术,能够升高过拟合的危险。常见的正则化办法有L1正则化(Lasso)和L2正则化(Ridge)。

May 12, 2023 · 1 min · jiezi

关于算法:什么是人工智能领域模型的-Presence-Penalty-参数

在人工智能畛域中,模型的品质往往受到许多因素的影响,其中一个重要的因素是模型的 Presence Penalty 参数。Presence Penalty 能够被了解为一种正则化项,它被增加到模型的损失函数中,以惩办模型对一些特定的特色或信息进行过多地关注。 在人工智能畛域,尤其是自然语言解决(NLP)畛域,生成模型(如 OpenAI 的 GPT-3)通常应用一系列参数来管制生成文本的品质、多样性和相关性。Presence Penalty(存在惩办)是其中一个参数,次要用于管制生成文本中反复和独创性的水平。在这篇文章中,咱们将具体探讨 Presence Penalty 参数的作用、利用以及与其余参数的关系。 Presence Penalty 参数能够看作是对生成文本中反复内容的一种惩办。当该参数设置较高时,生成模型会尽量避免产生反复的词语、短语或句子。相同,如果 Presence Penalty 参数较低,则生成的文本可能会蕴含更多反复的内容。通过调整 Presence Penalty 参数的值,能够实现对生成文本的原创性和多样性的管制。 Presence Penalty 参数的重要性次要体现在以下几个方面: 进步生成文本的独创性和多样性:在某些利用场景下,如创意写作、生成新闻标题等,须要生成的文本具备较高的独创性和多样性。通过减少 Presence Penalty 参数的值,能够无效缩小生成文本中的反复内容,从而进步文本的独创性和多样性。避免生成循环和无意义的内容:在某些状况下,生成模型可能会产生循环、反复的文本,这些文本通常无奈传播无效的信息。通过适当减少 Presence Penalty 参数的值,能够升高生成这类无意义内容的概率,进步生成文本的可读性和实用性。然而,值得注意的是,Presence Penalty 参数与其余参数(如 Temperature 和 Top-p)独特影响着生成文本的品质。比照其余参数,Presence Penalty 参数次要关注文本的独创性和重复性,而 Temperature 和 Top-p 参数则更多地影响着生成文本的随机性和确定性。通过正当地调整这些参数,能够实现对生成文本品质的综合管制。 Temperature 参数用于管制生成文本的随机性。较高的 Temperature 值会使模型更偏向于生成多样性更高、不那么确定性的文本;而较低的 Temperature 值则会使模型更偏向于生成确定性更强、合乎预期的文本。Temperature 参数与 Presence Penalty 参数独特作用,能够实现对生成文本独创性、多样性和相关性的综合管制。 Top-p 参数(又称为 Nucleus Sampling)用于管制生成文本的确定性。Top-p 参数设置为较低的值时,生成模型会更偏向于抉择概率较高的词汇,从而生成更确定性的文本。 Presence Penalty 参数通常在多任务学习和迁徙学习中应用,它能够帮忙模型在不同的工作之间放弃肯定的均衡,防止在某些工作上过分关注,从而进步模型的泛化能力和稳定性。Presence Penalty 的根本思维是,通过限度模型在学习某些特定工作时的活跃度,来激励模型更加全面地学习其余工作。 Presence Penalty 参数的具体模式能够有多种,其中最常见的是 L1 或 L2 正则化。以 L1 正则化为例,Presence Penalty 能够定义为: ...

May 12, 2023 · 1 min · jiezi

关于算法:什么是人工智能领域模型的-temperature-参数

在人工智能畛域中,温度参数(temperature parameter)是指在生成式模型中应用的一种技术,能够用于管制生成后果的多样性和随机性。温度参数通常用于一种叫做“softmax”概率分布的算法中,该算法被广泛应用于生成式模型中,包含机器翻译、自然语言解决和图像生成等畛域。 在softmax算法中,温度参数用于调整生成后果的熵值。熵是信息论中用于示意信息不确定性的一种量度,如果熵值越高,示意后果的不确定性也就越大。温度参数通过管制生成后果的熵值,能够使后果更加多样化或更加确定性。 在生成式模型中,温度参数通常通过扭转softmax函数的输入后果来实现。softmax函数通常用于将一个向量映射到一个概率分布,从而用于生成后果。如果将温度参数设置为较高的值,那么softmax函数的输入后果将更加平滑,这将使生成后果更加多样化。相同,如果将温度参数设置为较低的值,softmax函数的输入后果将更加尖利,这将使生成后果更加确定性。 以自然语言生成为例,假如咱们有一个语言模型,它能够生成各种句子。如果咱们应用温度参数,能够管制生成后果的多样性和准确性。例如,如果咱们想要生成一些具备创意和想象力的句子,咱们能够将温度参数设置为较高的值,这将使生成的句子更加多样化和乏味。相同,如果咱们想要生成一些更加精确和牢靠的句子,咱们能够将温度参数设置为较低的值,这将使生成的句子更加清晰和精准。 在人工智能(AI)畛域,尤其是自然语言解决(NLP)和生成式预训练模型(如 GPT-3)中,temperature 参数是一个重要概念。它是用于调整模型输入后果多样性的一个超参数,对于生成文本的品质和多样性具备重要影响。理解 temperature 参数的含意以及如何在理论利用中进行调整,有助于利用 AI 模型生成更合乎需要的文本。 首先,让咱们简要回顾一下生成式预训练模型的工作原理。这类模型通常应用 Transformer 架构,并通过大量文本数据进行预训练。模型学习语言的法则和模式,从而可能依据给定的上下文生成新的文本。在生成文本时,模型会为每个可能的单词调配一个概率,这个概率反映了模型认为该单词在给定上下文中呈现的可能性。生成过程通常应用贪心搜寻、集束搜寻(Beam Search)或者 Top-K 采样等策略。 Temperature 参数次要与采样策略无关。在基于概率的采样过程中,Temperature 参数用于调整模型输入的多样性。具体来说,Temperature 是一个负数,用于平滑模型输入的概率分布。Temperature 参数通过以下公式利用于模型的原始概率分布: P'(x) = P(x)^(1/T) 其中 P(x) 是模型为单词 x 调配的原始概率,P'(x) 是通过 Temperature 调整后的概率。能够看到,当 Temperature 增大时,原始概率分布会变得更加平坦,各个单词的概率绝对更加靠近。反之,当 Temperature 减小时,概率分布会变得更加平缓,使得具备较高概率的单词更有可能被选中。 Temperature 参数对生成文本的品质和多样性有显著影响: 当 Temperature 较低时(如 0.1 或 0.2),模型偏向于抉择具备较高概率的单词,生成的文本较为连贯和精确,但可能显得过于激进,不足创造性和多样性。当 Temperature 较高时(如 0.8 或 1.0),模型会更偏向于抉择概率较低的单词,生成的文本具备较高的多样性和创造性,但可能就义了肯定的连贯性和准确性。当 Temperature 靠近 0 时,模型简直总是抉择概率最高的单词,生成的文本十分激进,可能导致反复和循环。在理论利用中,温度参数通常须要依据具体场景进行调整。例如,在机器翻译中,温度参数能够用于调整翻译后果的多样性和准确性。如果咱们心愿翻译后果更加精确,咱们能够将温度参数设置为较低的值,这将使翻译后果更加准确。相同,如果咱们心愿翻译后果更加天然和晦涩,咱们能够将温度参数设置为较高的值,这将使翻译后果更加多样化和乏味。 总之,温度参数是一种用于调整生成式模型输入后果的技术,能够在管制多样性和准确性之间进行衡量。在理论利用中,温度参数能够依据具体场景和利用需要进行调整,以满足不同的生成需要。

May 12, 2023 · 1 min · jiezi

关于算法:什么是人工智能领域的-Generative-AI

Generative AI(生成式人工智能)是指一类人工智能技术,它可能生成新的数据、图像、语音、视频、音乐等内容,从而扩大人工智能零碎的利用范畴。Generative AI 在最近几年失去了宽泛的钻研和利用,其中最驰名的就是深度学习模型中的生成式模型。这些模型通常应用一种叫做“生成反抗网络(GANs)”的技术,它由一组生成模型和一组判断模型组成,可能训练出高质量的、实在的数据。除了 GANs 之外,还有很多其余类型的生成式模型,比方自编码器(Autoencoders)、变分自编码器(Variational Autoencoders)和生成式反抗网络(Generative Adversarial Networks)等。 Generative AI 技术能够利用于许多不同的畛域,包含计算机视觉、自然语言解决、音乐创作、虚拟现实和视频游戏等。上面是一些利用示例: 图像生成图像生成是 Generative AI 技术中最为广泛的利用之一。GANs 能够通过对实在图像的学习来生成真切的图像。例如,GANs 能够学习生成人脸、汽车、城市风光等图像,这些图像看起来十分真切,能够用于游戏、电影和虚拟现实等利用。 语音合成Generative AI 技术能够用于语音合成,即生成真切的语音。例如,通过学习人类的语音特色,生成式模型能够生成真切的语音,从而用于虚构助手、语音翻译等利用。 自然语言生成自然语言生成是一种 Generative AI 技术,能够生成真切的自然语言文本。例如,能够应用自然语言生成技术来生成新闻报道、广告文案、诗歌等文本内容。 音乐生成Generative AI 技术能够用于生成音乐。通过学习不同类型的音乐,生成式模型能够生成新的音乐曲目,这些曲目能够用于音乐创作、广告音乐等利用。 虚拟现实Generative AI 技术能够用于虚拟现实中的环境和角色生成。例如,通过学习真实世界中的环境和角色,生成式模型能够生成真切的虚拟环境和虚构角色,这些环境和角色能够用于游戏、培训和教育等利用。 生成式人工智能(Generative AI)是人工智能(AI)畛域的一个重要分支,它旨在通过训练模型来生成新的、与训练数据类似的内容。与其余类型的AI(如分类器、预测器等)次要关注辨认和预测现有数据的模式不同,生成式AI着重于发明新的、有创意的数据。生成式AI在图像、文本、音频、视频等多种畛域都有宽泛的利用。 生成式AI的外围在于学习数据的潜在散布,从而可能生成与训练数据具备类似特色的新样本。在实现过程中,生成式AI通常须要大量的数据来进行训练,以便捕捉到数据中的潜在构造。训练好的模型能够在给定某些输出条件时生成肯定品质的输入,从而实现从设计图案到主动撰写文章等宽泛的利用。 生成式AI的技术办法有很多,其中最驰名的是生成反抗网络(GANs)和变分自编码器(VAEs)。以下将对这两种办法进行简要介绍。 生成反抗网络(GANs)生成反抗网络(GANs)是由Ian Goodfellow于2014年首次提出的一种生成式AI办法。GANs由两个神经网络组成:生成器(Generator)和判断器(Discriminator)。生成器的工作是生成与训练数据类似的新样本,而判断器的工作则是判断生成的样本是否来自实在数据。在训练过程中,生成器和判断器互相反抗,生成器试图生成越来越真切的样本,而判断器则努力提高辨认真切和生成样本的能力。这个过程能够类比于一场博弈,最终使得生成器产生的样本越来越难以辨别真伪。 变分自编码器(VAEs)变分自编码器(VAEs)是另一种宽泛应用的生成式AI办法。VAEs是一种概率生成模型,它将输出数据编码成一个潜在变量空间,而后从这个空间中采样并解码以生成新的数据。VAEs的关键在于它应用了变分推理(Variational Inference)办法来近似潜在变量的后验散布,从而使得咱们能够在训练过程中优化这个近似散布。VAEs相较于GANs在训练稳定性方面具备肯定劣势,但生成样本的品质通常略逊于GANs。

May 12, 2023 · 1 min · jiezi

关于算法:什么是人工智能领域的-Foundation-Model

人工智能畛域的 Foundation Model,通常指的是一类被宽泛应用的根底模型(或称基础架构模型),是在海量数据和计算资源的根底上训练进去的通用、通用性较强的深度学习模型。这些模型被广泛应用于自然语言解决、计算机视觉、语音辨认等畛域的各种工作。 Foundation Model 通常由大型科技公司、钻研机构或者开源社区开发,这些模型的目标是提供一种共享的基础架构,为更宽泛的利用和开发人员提供更好的机会和资源。这些模型的训练须要大量的数据和计算资源,因而只有一些大型机构或企业能力承当这样的工作。 在自然语言解决畛域,最驰名的 Foundation Model 是 OpenAI 公司开发的 GPT(Generative Pre-trained Transformer)系列模型。GPT 模型采纳了预训练加微调的形式,通过大规模的语料库训练进去的模型,能够在多种 NLP 工作中表现出色,如文本分类、机器翻译、摘要生成等。 在计算机视觉畛域,Facebook 公司开发的 Detectron2 和谷歌公司开发的 EfficientNet 等模型也被宽泛应用,能够用于指标检测、图像分类、图像宰割等工作。 “Foundation Model”(根底模型)是指在人工智能畛域,尤其是自然语言解决(NLP)和计算机视觉(CV)等子畛域中,通过大量数据训练的弱小的预训练模型。这些根底模型被认为是构建各种具体AI利用的根底。它们通过学习海量的文本、图像或其余类型的数据,捕捉到个别的模式和常识,从而能够在多个工作和场景中体现出较强的泛化能力。 根底模型通常应用深度学习技术,比方Transformer架构,以及大量的计算资源进行训练。这些模型在训练时学习到了丰盛的常识示意和底层特色,能够通过微调(fine-tuning)的形式适应特定的工作或畛域。这意味着,一旦咱们有了一个弱小的根底模型,咱们能够在其根底上定制化地进行改良,以解决各种特定问题。 OpenAI的GPT-3(即第三代生成型预训练Transformer)就是一个典型的根底模型。它在大量的文本数据上进行预训练,学会了语言模式、常识以及肯定的推理能力。通过微调,GPT-3能够适应各种NLP工作,如问答、文本生成、摘要、翻译等。相似地,计算机视觉畛域的根底模型(如ViT、CLIP等)通过在大量图像数据上训练,能够泛化到各种图像识别和生成工作。 总之,人工智能畛域的 Foundation Model 是一类通用的、可复用的深度学习模型,能够为各种工作提供基础架构和反对,使得更多的开发人员能够借助这些模型来疾速开发本人的应用程序。

May 12, 2023 · 1 min · jiezi

关于算法:ChatGPT-背后包含了哪些技术

ChatGPT 是由OpenAI开发的一款基于GPT-3(Generative Pre-trained Transformer 3)的人工智能语言模型。这个模型是应用多种编程语言和技术组合编写的。 首先,ChatGPT 应用了 Python 作为次要的编程语言。Python 是一种风行的高级编程语言,特地适宜用于数据迷信、机器学习和自然语言解决等畛域。OpenAI 的钻研团队应用 Python 来编写 ChatGPT 的外围算法和模型架构。Python 在数据迷信和机器学习方面的劣势次要体现在其丰盛的库和工具集上,这些工具能够放慢开发速度,进步代码品质和效率。 其次,ChatGPT 应用了 TensorFlow 作为深度学习框架。TensorFlow 是由 Google 公司开发的一款风行的深度学习框架,它能够帮忙钻研人员疾速开发和训练深度神经网络。OpenAI 应用 TensorFlow 来搭建 ChatGPT 的神经网络模型,并应用 TensorFlow 的分布式训练性能来减速模型的训练过程。TensorFlow 的劣势在于它的灵活性和可扩展性,能够适应不同规模和复杂度的模型。 除此之外,ChatGPT 还应用了其余一些编程语言和技术,包含: CUDA:用于在 NVIDIA GPU 上进行并行计算,以减速深度学习模型的训练和推理。C++:用于优化模型的计算性能和内存治理,特地是在模型部署和推理时。Rust:用于编写高性能的零碎级代码,以进步模型的稳定性和安全性。JavaScript:用于开发 ChatGPT 的 Web API,使其能够通过网络接口与其余应用程序集成。综上所述,ChatGPT 是应用多种编程语言和技术组合编写的。Python 是次要的编程语言,用于编写外围算法和模型架构。TensorFlow 是深度学习框架,用于搭建神经网络模型。其余编程语言和技术则用于优化计算性能、进步零碎稳定性和安全性,以及扩大 ChatGPT 的利用范畴。通过这些技术的组合,ChatGPT 成为了一款高效、牢靠、灵便的自然语言解决模型。 从组成模块上划分: Transformer 架构GPT-3 基于 Transformer 架构,这是一种在自然语言解决(NLP)畛域十分风行的神经网络架构。Transformer 由 Vaswani 等人在 2017 年的论文 "Attention is All You Need" 中首次提出。与传统的 RNN 和 LSTM 不同,Transformer 应用自注意力(self-attention)机制,能够并行处理序列中的所有元素,从而在许多 NLP 工作中获得了突破性的性能。 ...

May 12, 2023 · 1 min · jiezi

关于算法:什么是-GPU-芯片的-CUDA-核心

ChatGPT 是一个由 OpenAI 开发的大型语言模型,它采纳了 GPT-3.5 架构,该架构应用了 NVIDIA 公司的 A100 GPU 芯片作为加速器,以实现高效的模型训练和推理。 NVIDIA A100 是 NVIDIA 公司推出的一款高性能 GPU 加速器,采纳了基于 Ampere 架构的第三代 Tensor Core 技术,具备卓越的性能和功率效率。该芯片领有6912个 CUDA 外围、432个 Tensor Core 模块和40 GB/80 GB HBM2 内存,可能反对高速的浮点计算、深度学习训练和推理等利用场景。在深度学习工作中,NVIDIA A100 能够提供比前一代 V100 GPU 芯片高达20倍的性能晋升。 因为 ChatGPT 模型具备微小的参数规模和计算复杂度,须要弱小的计算资源能力实现训练和推理工作。因而,应用 NVIDIA A100 GPU 芯片作为加速器,能够显著进步 ChatGPT 模型的训练和推理效率,减速模型的研发和部署过程。 CUDA(Compute Unified Device Architecture)是 NVIDIA 公司推出的一种并行计算架构,用于在 NVIDIA GPU 上进行通用计算。CUDA 外围是 NVIDIA GPU 中的计算单元,用于执行并行计算工作。 与 CPU 不同,GPU 蕴含数千个并行计算单元,称为 CUDA 外围。这些 CUDA 外围能够同时解决多个数据流,从而实现高效的并行计算。CUDA 外围还蕴含了一些非凡的硬件单元,例如浮点数处理单元、整数处理单元、逻辑单元和共享内存等,能够提供疾速的数学运算和数据处理能力。 通过 CUDA 技术,开发人员能够应用 C/C++、Fortran 等编程语言来编写 GPU 减速的程序,利用 CUDA 外围来实现高效的并行计算。CUDA 还提供了一些高级工具和库,例如 cuBLAS、cuDNN、cuFFT 等,能够进一步简化 GPU 编程过程,并提供高度优化的算法和数据结构,减速各种应用程序的运行速度,包含科学计算、深度学习、计算机视觉、图形渲染等畛域。 ...

May 12, 2023 · 1 min · jiezi

关于算法:MTH3320-线性表达式

SSCHOOL OF MATHEMATICSMTH3320Computational Linear AlgebraAssignment 3Due date: Friday 12 May, 2023, 11:55pm (submitthe electronic copy of your assignment and thematlab code via Moodle)This assignment contains four questions for a total of 100 marks (equal to 7.5% of thefinal mark for this unit).Late submissions will be subject to late penalties (see the unit guide for fulldetails).The relevant output of the programming exercises are to be submitted as part of yourelectronic submission. You can either include the outputs as a part of your pdf file (ifyou can edit the pdf document), or include them in a separate word document (you needto label the figures and outputs consistently with the question number). In addition,collect all your Matlab m-files in one zip file and submit this file through Moodle.1. Unitary Similarity Transformation to a Lower Triangular Matrix. (20 marks)Use induction to show that every square matrix can be transformed to a lower triangularmatrix via a unitary similarity transformation. That is, for a matrixalways identify a unitary matrix Q and a lower triangular matrix L Hint: use the same procedure in the proof of the existence of Schur factorisation, andstart from the lower-rightmost entry.2. Convergence of the Inverse Iteration on SymmetricMatrices. (30 marks)Consider the inverse iteration (Algorithm 6.32) applied to a real symmetric matrix. Suppose 位K is the closest eigenvalue toL is the second closest, that is,, for each i K.School of Mathematics Monash UniversityLetn denote eigenvectors corresponding the eigenvalues of A. Suppose furtherwe have an initial vectorin the inverse iteration converges as,(iii) Use the results in (i) and (ii) to complete the rest of the proof.3. Implementation of the steepest descent and conjugategradient methods. (30 marks)You are asked to implement the steepest descent and conjugate gradient methods forA in Matlab, and apply the methods to the 2D model problem (downloadbuild laplace 2D.m or build laplace 2D kron.m to build the 2D Laplacian matrix).(a) Implement the following in m-file steepest.m:function [x res steps]=steepest(A,x0,b,tol,maxit)% Performs a sequence of steepest descent iterations on% A x = b using the initial estimate x0, until the 2-norm% of the residual is smaller than tol (relative% to the initial residual), or until the number of iterations% reaches maxit. is a vector with the% residual size after every interation (the 2-norm of% the residual vector).(b) Implement the following in m-file conjGrad.m:function [x res steps]=conjGrad(A,x0,b,tol,maxit)% Performs a sequence of conjugate gradient iterations% on A x = b using the initial estimate u0, until the 2-norm% of the residual is smaller than tol (relative2022 2School of Mathematics Monash University% to the initial residual), or until the number of iterations% reaches maxit.residual vector).Submit your m-files steepest.m and conjGrad.m.(c) Download test steepest cg.m to test the correctness of (a) and (b). Report onthe errors and number of steps. (The errors should be smaller than vector with all twos. Use maxit=400 andtol=1e-6. Generate a plot in which you compare, for N = 30, the residual convergence for the steepest descent and conjugate gradient methods (starting from azero initial guess), as a function of the iteration. For each of the methods, plot the10-log of the residuals as a function of iteration number. Which method requiresthe least iterations to obtain an accurate solution, and is this as you expected?(e) Provide a table in which you list, for steepest descent and conjugate gradient, howmany iterations you need to reduce the residual by 1 N = 16, 32, 64.(You can use maxit = 500.) What are the total number of unknowns and thecondition number for each problem size? (You can use cond(full(A)); no needto do this for N = 64 though, because it may take too long.) For each method, doyou see the expected behaviour in the number of required iterations as a functionof the total number of unknowns? (Explain.) Using these numerical results, brieflydiscuss the computational cost/complexity of each of the methods as a functionof the total number of unknowns (discuss the cost per iteration, the number ofiterations required, and the total cost, as a function of total problem size). Whichmethod is best for large problem size?4. Implementation of the Inverse Iteration and the RayleighQuotient Iteration. (20 marks)(a) Implement the inverse iterations in Matlab according to the pseudocode discussedin class. Your implementation InverseIteration.m should store estimated eigenvalues and eigenvectors in each step, except the step 0. You should use the functionheader given below.function [B, lamb] = InverseIteration(A, mu, x, k)%% Usage: [B, lamb] = InverseIteration(A, mu, x, k) carries k steps% of the inverse iteration for estimating the eigenvalue of A,% with an initial shift mu, and an initial vector x.% It generates outputs B and lamb.2022 3School of Mathematics Monash University% -- B is an (n x k) matrix that stores the estimated eigenvector at% i-th step as its i-th column, B(:,i)% -- lamb is a (1 x k) vector that stores the estimated eigenvalue at% i-th step as its i-th element, lamb(i)% Note that the initial vector and initial eigenvalue estimate are% not stored.n = size(A, 1); % size of the matrixB = zeros(n, k); % matrix Blamb = zeros(1, k); % vector lamb% your codeend(b) Implement the Rayleigh quotient iteration in Matlab according to the pseudocodediscussed in class. Your implementation RayleighIteration.m should store estimated eigenvalues and eigenvectors in each step, except the step 0. You shoulduse the function header given below.function [B, lamb] = RayleighIteration(A, x, k)%% Usage: [B, lamb] = RayleighIteration(A, x, k) carries k steps% of the Rayleigh quotient iteration for estimating the eigenvalue% of A, with an initial vector x% It generates outputs B and lamb.% -- B is an (n x k) matrix that stores the estimated eigenvector at% i-th step as its i-th column, B(:,i)% -- lamb is a (1 x k) vector that stores the estimated eigenvalue at% i-th step as its i-th element, lamb(i)% Note that the initial vector and initial eigenvalue estimate are% not stored.n = size(A, 1); % size of the matrixB = zeros(n, k); % matrix Blamb = zeros(1, k); % vector lamb% your codeend(c) Check the correctness of your implementation of RayleighIteration.m as follows.Download the Matlab files flip vec.m, test Rayleigh.m and matrix data Q4.matunder Assignment 3 on Moodle. Save the test Rayleigh.m as my test Rayleigh.m.Then modify my test Rayleigh.m as the driver to call your RayleighIteration.mto solve an eigenvalue problem. The matrix and initial vector are provided (see2022 4School of Mathematics Monash UniversityStep 1 in test Rayleigh.m). Comment on the result plot if your implementationproduces a desirable answer.(d) Run the same test for your implementation of InverseIteration.m using theinitial shift value given in my test Rayleigh.m and matrix data Q4.mat. Modify the convergence plots in my test Rayleigh.m to also plot the convergenceof eigenvalue and eigenvector estimates produced by the inverse iteration on thesame graph showing the convergence of the Rayleigh quotient iteration. Includea printout of the plots produced by my test Rayleigh.m in the main assignmentpackage. Comment on the performance of your implementation of the Rayleighquotient iteration, compared with the inverse iteration.(e) You should submit the code InverseIteration.m, RayleighIteration.m andmy test Rayleigh.m to the Moodle.2022 5 ...

May 12, 2023 · 6 min · jiezi

关于算法:COMP226-R语言分析算法

COMP226 Assignment 2: Strategy DevelopmentContinuousAssessmentNumber2 (of 2)Weighting 15%AssignmentCirculatedMonday 17 April 2023 (week 9)Deadline Thursday 11 May 2023 (week 12)SubmissionModeSubmit up to two files to the CodeGrade assignment on Canvas: strategy.R(required to get marks) and results.yaml (optional).LearningOutcomesAssessedThis assignment addresses the following learning outcomes:鈥?Understand the spectrum of computer-based trading applications andtechniques, from profit-seeking trading strategies to execution algorithms.鈥?Be able to design trading strategies and evaluate critically their historicalperformance and robustness.鈥?Understand the common pitfalls in developing trading strategies with historicaldata.Summary ofAssessment 鈥?The goal is to implement and optimize a well-defined trading strategy within thebacktester_2023 framework.鈥?Marks are available for the correct implementation of 10 functions instrategy.R (70%).鈥?Further marks (that require a correct implementation in strategy.R) areavailable for the results of a cross-validated optimisation that you can include inresults.yaml (30%).鈥?CodeGrade pre-deadline tests and offline example outputs are available to helpyou check the correctness of your work.Submissionnecessary topass moduleNoLate SubmissionPenaltyStandard UoL policy; resubmissions after the deadline may not be considered.Expected timetakenRoughly 8-12 hoursBefore you move on and read more about the assignment and start working on it, please make sure youhave worked through "backtester.pdf" (and the corresponding lectures if you want), which is an intro to thebacktester_2023 framework. Only return to this document when you already have the framework up andrunning.First, let's recall the contents of the backtester_2023.zip:backtester_202310 directories, 28 filesIn the above listing, the following files/directories are specifically there for assignment 2:鈥?a2_main_template.R鈥?a2_periods.R鈥?a2_test_checks_and_getTMA.R鈥?strategies/a2_strategy_template.R鈥?a2_example_yamls鈥?DATA/A2The relevance of these files and directories will be explained below. The rest of the document is split intothree parts:鈥?Part 1 describes the 10 functions that should be implemented to fully complete strategy.R; youshould start from a2_strategy_template.R;鈥?Part 2 describes how to create (the optional) results.yaml;鈥?Part 3 describes submission via CodeGrade and the available pre-deadline tests.In addition to pre-deadline tests on CodeGrade, example outputs are provided (in this document and asfiles) so that you can test whether you have implemented things correctly.As for assignment 1, the pre-deadline tests will determine your mark for the first part, corresponding to 70%of the overall marks that are available. Assuming that you have achieved full marks on the first part, thepre-deadline tests will check that the form of results.yaml is correct, and that it uses the expected studentusername (i.e., your one) and corresponding time periods; the pre-deadline tests do not check thecorrectness of the other fields in results.yaml, which will be checked post deadline only if you pass thepre-deadline test for results.yaml. For those other fields, you should use the examples provided (whichare in the subdirectory a2_example_yamls).Part 1: strategy implementation (70%)The trading strategy that you should implement is a triple moving average (TMA) momentum strategy, whichis described in slides 4.7. The specification of the strategy and the functions that it should comprise are givenin full detail, so the correctness of your code can and will be checked automatically.Two template files are provided to get you started:鈥?strategies/a2_strategy_template.R, which should become the file strategy.R that youeventually submit;鈥?a2_main_template.R, which uses DATA/A2 and strategies/a2_strategy_template.R.If you source a2_main_template.R with no edits to these two files you will get an error:Error in if (store$iter > params$lookbacks$long) { : argument is of length zeroThis is because the strategy requires a parameter called lookbacks that you will need to pass in froma2_main_template.R. Read on to see what form this parameter should take, and, more generally, howyou should be editing these two files.a2_strategy_template.R contains 10 incomplete functions that you need to complete. The first 6functions (checkE01,..., checkE06) are error checks for the inputs to getTMA. These error checks are allone-liners, worth 3% each. They are intentionally meant to be straightforward to implement. The next threefunctions compute the moving averages (getTMA), use them to compute the position sign(getPosSignFromTMA), and compute the position size (getPosSize). The final, tenth function,getOrders combines the last three to implement that actual trading strategy. Recall that every strategy inthe backtester framework has a getOrders function.The TMA momentum strategy that you should implement uses three moving averages with differentlookbacks (window lengths). The short lookback should be smaller than the medium one, which in turnshould be smaller than the long lookback. In every trading period, the strategy will compute the value of thesethree moving averages (for the series that it trades on, which will be determined by params$series). Youwill achieve this by completing the implementation of the function getTMA.The following table indicates the position that the strategy will take depending on the relative values of thethree moving averages (MAs). You will compute this position (sign, but not size) by completing the functiongetPosSignFromTMA. The system is out of the market (i.e., flat) when the relationship between the shortMA and the medium MA does not match the relationship between the medium MA and the long MA.MA MA MA Positionshort MA < medium MA < long MA shortshort MA > medium MA > long MA longThe function getPosSignFromTMA takes the output of getTMA as input. The position size, i.e., the numberof units to be long or short, is determined by getPosSize. As for all strategies in the backtester framework,the positions are given to the backtester by getOrders. Here are the detailed specification and marksavailable for these 10 functions.FunctionnameInput parameters Expected behaviour Marks available for a correctimplementationcheckE01 ...checkE06prices;lookbacks.The behaviour of these checksare specified as comments inthe template. Hints are givenbelow.3% for each of the 6 checks;18% in total.getTMA prices;lookbacks. Thespecific form thatthese argumentsshould take isspecified in thetemplate code via the6 checks that youneed to implement.The function should return a listwith three named elements,short, medium, and long. Eachelement should be equal to thevalue of a simple movingaverage with the respectivewindow size as defined bylookbacks. The windowsshould all end in the sameperiod, the final row of prices.12%getPosSignFromTMAtma_list is a listwith three namedelements, short,medium, and long.These correspond tothe simple movingaverages as returnedby getTMA.This function should returneither 0, 1, or -1. If the shortvalue of tma_list is less thanthe medium value, and themedium value is less than thelong value, it should return -1(indicating short). If the shortvalue of tma_list is greaterthan the medium value, and themedium value is greater thanthe long value, it should return 1(indicating long). Otherwise, thereturn value should be 0(indicating flat).10%getPosSize current_close:this is the currentclose for one of theseries. constant:this argument shouldhave a default valueof 5000.The function should return(constant divided bycurrent_close) roundeddown to the nearest integer.5%getOrders The arguments to thisfunction are alwaysthe same for allstrategies used in thebacktesterframework.This function should implementthe strategy outlined below in"Strategy specification".25%All-or-nothing testsSince the check functions and getPosSignFromTMA function will only return a small number ofpossible correct values (2 for the check functions, and 3 for getPosSign), these are implemented as"all-or-nothing" tests where you either get full marks for passing all tests or no marks if you fail at leastone test. As a very simple function, getPosSign is also marked with all-or-nothing tests, so from thefirst 10 functions, partial marks are only available for getTMA and getOrders.Strategy specificationThe strategy should apply the following logic independently to only the series in params$series(e.g., params$series could be c(1,3), which would mean trade only on series 1 and 3).It does nothing until there have been params$lookbacks$long-many periods.In the (params$lookbacks$long+1)-th period, and in every period after, the strategy computesthree simple moving averages with window lengths equal to:鈥?params$lookbacks$short鈥?params$lookbacks$medium鈥?params$lookbacks$longThe corresponding windows always end in the current period. The strategy should in this period sendmarket orders to assume a position (make sure you take into account positions from earlier)according to getPosSignFromTMA and getPosSize. (Limit orders are not required at all, and canbe left as all zero.)HintsYou can develop the first 9 functions without running the backtester.For the checks you may find the following functions useful:鈥?The operator ! means not, and can be used to negate a boolean.鈥?sapply allows one to apply a function element-wise to a vector or list (e.g., toc("short","medium","long")).鈥?all is a function that checks if all elements of a vector are true (for example, it can be usedon the result of sapply).鈥?%in% can be used to check if an element exists inside a vector.To compute the moving average in getTMA you can use SMA from the TTR package.For getPosSize, you can use the function floor.For getOrders some instructions are given as comments in a2_strategy_template.R.If an error occurs within a function and you would like to inspect the contents of a variable that is localto the function, in addition to printing, you can also use global assignment (<<-) for debugging.Example output for checkE01 ... checkE06 and getTMAThe file a2_test_checks_and_getTMA.R is provided to give you guidance on how you can test the sixfunctions, checkE01 ... checkE06. For each one, two tests are provided: for a correct implementation, onetest should produce TRUE and the other FALSE. (You don't need to use these tests, as you can also just relyon the tests on CodeGrade.)To use these tests, first source a2_test_checks_and_getTMA.R and also source the implementationsthat you would like to test. The tests that should return TRUE are test_checkE01() ... test_checkE06();for tests that should return FALSE, there is single function, test_pass_all_checks, which takes thefunction to test as its only argument. Here's an example of both types of test for E01 (where a correctimplementation of checkE01 has been sourced):> test_checkE01()[1] TRUE> test_pass_all_checks(checkE01)[1] FALSEThe way these tests work is clear from the source code in a2_test_checks_and_getTMA.R:################################################################################ Source the functions that you would like to test, e.g., with# source('strategies/a2_strategy_template.R') or source('strategies/strategy.R')###############################################################################source('framework/data.R'); dataList <- getData(directory="A2")prices <- dataList[[1]]prices_19_rows <- dataList[[1]]$Close[1:19]prices_20_rows <- dataList[[1]]$Close[1:20]prices_20_rows_renamed <- prices_20_rowscolnames(prices_20_rows_renamed) <- 'Closed'bad_prices <- c(1,2,3)lookbacks_no_names <- list(5,10,25) # list elements not namedlookbacks_not_integer <- list(short=5,medium=as.integer(10),long=as.integer(20))lookbacks_wrong_order <- list(short=as.integer(15),medium=as.integer(10),long=as.integer(20))lookbacks <- list(short=as.integer(5),medium=as.integer(10),long=as.integer(20))test_checkE01 <- function() checkE01(prices,lookbacks_no_names)test_checkE02 <- function() checkE02(prices,lookbacks_not_integer)test_checkE03 <- function() checkE03(prices,lookbacks_wrong_order)test_checkE04 <- function() checkE04(bad_prices,lookbacks)test_checkE05 <- function() checkE05(prices_19_rows,lookbacks)test_checkE06 <- function() checkE06(prices_20_rows_renamed,lookbacks)test_pass_all_checks <- function(check_func) check_func(prices_20_rows,lookbacks)test_getTMA <- function() # same inputs as test_pass_all_checks() getTMA(prices_20_rows,lookbacks)The final test function in this file is for getTMA, where you should get the following return values for a correctimplementation:> test_getTMA()$short[1] 3081.5$medium[1] 3122.5$long[1] 3128.875If you want to do further testing, you can use the pre-deadline tests on CodeGrade, which applies to all 10functions, or you can extend a2_test_checks_and_getTMA.R by adding alternative examples yourself.Example output for getPosSizeHere is one example input for each of the three possible outputs:> getPosSignFromTMA(list(short=10,medium=20,long=30))[1] -1> getPosSignFromTMA(list(short=10,medium=30,long=20))[1] 0> getPosSignFromTMA(list(short=30,medium=20,long=10))[1] 1Example output for getPosSignFromTMAHere are two examples of correct outputs:> current_close <- 100.5> getPosSize(current_close,constant=100.5)[1] 1getPosSize(current_close,constant=100.4)[1] 0Example output for getOrdersThe following table gives the correct value of "profit" across 3 different time periods, using the "EXAMPLE"data, and the following parameters:params$lookbacks <- list(short=as.integer(5), medium=as.integer(50), long=as.integer(100))params$series <- 1:4start period end period profit1 250 2086.1841 1000 4103.204500 1500 -2179.298The examples of results.yaml (details below) can also be used to further establish the correctness ofgetOrders, along with all the tests on CodeGrade.Part 2: cross-validation (30%)WarningYou can only access the final 30% of marks if you get 70% for the first part; otherwise CodeGrade willnot process results.yaml.In this part of the assignment you are asked to do a cross-validated parameter optimization of profit, whereyou will use an in-sample and out-of-of-sample time period. Every student has their own in-sample andout-of-sample periods based on their MWS username (only the part before the @, e.g., for Vladimir Gusev,this username is is gusev, rather than the full email form gusev@liverpool.ac.uk). By having differenttime periods for different sutdents, there is not one single correct results.yaml.To get your in-sample and out-of-sample periods, use a2_periods.R as follows. Source it and run thefunction getPeriods with your MWS username as per the following example (where we use the fakeusername "x1xxx"). Use startIn, endIn, startOut, and endOut as the start and end of the in-sampleand out-of-sample periods respectively.> source('a2_periods.R')> getPeriods('x1xxx')$startIn[1] 1$endIn[1] 884$startOut[1] 885$endOut[1] 2000You will do two parameter sweeps. One on your in-sample period, and one on your out-of-sample period(normally one doesn't do a sweep on the out-of-sample period in practice; we do it here to allow detailedcross-period performance analysis). The sweep will be over the following parameters: the short, medium, andlong lookbacks, and the subset of series that are traded on.Parameter Valuesshort lookback 5, 10medium lookback 50, 100long lookback 200, 300series All subsets of 1:4 that have at least two elementsThe correct resulting number of parameter combinations is 88.HintYou can use expand.grid to create the relevant parameter combinations; alternatively you coulduse nested for loops.The following information (full example below) is needed in results.yaml:1. Your username and the corresponding periods. This information is used for a pre-deadline check to giveyou confidence that you are using the right periods.2. The parameter combination that gives the best profit on the in-sample period (where the seriesparameter is encoded in binary, see below); the corresponding profit.3. The parameter combination that gives the best profit on the out-of-sample period (where the seriesparameter is encoded in binary, see below); the corresponding profit.4. rank_on_out: The rank (a possibly fractional number between 1 and 88) that describes where theparameter combination from 2. ranks on the out-of-sample period.5. rank_on_in: The rank (a possibly fractional number between 1 and 88) that describes where theparameter combination from 3. ranks on the in-sample period.How to compute the rankUse the rank (package:base) with the argument ties.method='average'.InterpretationAn ideal scenario is for the best in-sample parameter combination to also be the best out-of-sampleparameter combination. In practice, this is often not the case, as we have seen in the slides. Here, aswe did in the slides, we are exploring the difference between parameter combination performance onin-sample and out-of-sample periods, where "a good outcome" is for the rank_on_out andrank_on_in to both be close to 1 (where 1 is ideal).NOTE: you will not submit the code used to do the optimisation, which takes a long time to run; you will onlysubmit the results of the optimisation in results.yaml.Example output for results.yamlIn the a2_yamls subdirectory, three examples of results.yaml are provided for the fake usernames"x1xxx", "x1yyy", and "x1zzz", and using the "EXAMPLE" data. For "x1xxx", the yaml file contents are:username: x1xxxperiods: startIn: 1 endIn: 884 startOut: 885 endOut: 2000ins: short: 5.0 medium: 50.0 long: 300.0 series1: 1 series2: 1 series3: 1 series4: 1 profit: 5963.63 rank_on_out: 2.0out: short: 10.0 medium: 50.0 long: 300.0 series1: 1 series2: 1 series3: 1 series4: 0 profit: 3072.562 rank_on_in: 19.0Note how the params$series parameter is represented in the yaml, as 4 binary variables (taking values 0or 1): series1, series2, series3, and series4.Once you have correctly completed part 1, and have also created the code to do the parameter sweep andranking you can use these three examples to test your output. These examples are done using the"EXAMPLE" data so that they do no leak information about the correct answers on the "A2" data.Marks breakdown for results.yamlThe marks for results.yaml are only available if you have achieved 70% on the first part. Moreover, theyaml file must have the right format, and must show the correct username and periods -- there is apre-deadline test that checks all of this for you.Here is an example blank results.yaml, shown with additional line numbers: 1 username: 2 periods: 3 startIn: 4 endIn: 5 startOut: 6 endOut: 7 ins: 8 short: 9 medium:10 long:11 series1:12 series2:13 series3:14 series4:15 profit:16 rank_on_out:17 out:18 short:19 medium:20 long:21 series1:22 series2:23 series3:24 series4:25 profit:26 rank_on_in:Note that the line numbers on the left are not part of the file; they are shown since they are used in thefollowing tables.Requred for passing the pre-deadline check:Field(s) Line numbers in example Marksusername 1 0periods 3-6 0Assuming that your submitted yaml passed the pre-deadline check, which checks the username and periodsfields and the format of the yaml file, the following marks are available for the remaining fields:Field(s) Line numbers in example MarksIn-sample best params (unique) 8-14 5In-sample best profit 15 5rank_on_out 16 5Out-of-sample best params 18-24 5Out-of-sample best profit 25 5rank_on_in 26 5Part 3: submission and pre-deadline testsTo get marks the submission of strategy.R is required; the submission of results.yaml is optional:There are pre-deadline tests for all 10 functions in strategy.R that are needed for the first 70% of marks.RandomisationTo reduce the incentive for trying to hardcode answers, tests involve randomness in the inputs. Thisdoes mean that there can be some (small) variance in the mark for wrong answers, but there is nonefor correct answers. This is a reasonable price to pay for being able to see all the tests that were runopenly.For the functions checkE01,..., checkE06, these are "all-or-nothing" tests (to prevent always returning TRUEor always returning FALSE from getting marks). If you do not pass all tests, you will be shown only the teststhat you failed. For example, here's what happens for checkE01 if it just returns TRUE:When the output says "expected [1] FALSE" that means that the input arguments should have passed thischeck.One only sees tests where FALSE was expected but TRUE was returned. Here is what happens forcheckE02 if it always returns FALSE (one sees only tests where TRUE was expected):For getTMA, partial marks are possible. Here's an example of the tests for a getTMA implementation thatpasses some but not all tests:The way this submission was created was to break a corerct implementation for the short TMA for certainlookback values. Note that the errors on CodeGrade show that the problem is only with the short TMA andonly for certain values of the lookback; this type of information may be useful in debugging. Note also that abroken getTMA (or getPosSignFromTMA or getPosSize) should also break getOrders, because itshould use them. For example, here's the output for getOrders when the same submission as used forgetTMA is used:As for getTMA, partial marks are possible for getOrders. The tests for getOrders use the resulting profitfor comparison.Since getPosSignFromTMA should only return 0,1,-1, it is an "all-or-nothing" test. Here's the output when awrong implementation that always return 1 is submitted (only failed tests where an expected output of 0 or -1are shown):For getPosSize, since it is very simple and there should not be lots of "edge cases" we again implement itas an "all-or-nothing" test. Here's the output when the flooring of the position size has been ommitted:So for getTMA and getOrders partial marks are possible, for the other 8 functions it is all or nothing, andthen only failed tests are shown if the test is not passed.For results.yaml, the pre-deadline test checks that the username and periods are correct and that the formatof the yaml is correct. Here is any example of using the wrong username:Errors can also arise for the wrong periods or for a badly formatted yaml or one with the wrong fields.When the submitted yaml passes all pre-deadline tests, you will see the following:Only in this case will your results.yaml submission be marked post-deadline.WarningYour code will be put through the department's automatic plagiarism and collusion detection system.Student's found to have plagiarized or colluded will likely receive a mark of zero. Do not show yourwork to other students, and do not search for answers online.Good luck with the assignment.THE END ...

May 12, 2023 · 15 min · jiezi

关于算法:554488688应用数学计算

▼554.488/688 Computing for Applied MathematicsSpring 2023 - Final Project AssignmentThe aim of this assignment is to give you a chance to exercise your skills at prediction usingPython. You have been sent an email with a link to data collected on a random sample from somepopulation of Wikipedia pages, to develop prediction models for three different web page attributes.Each student is provided with their own data drawn from a Wikipedia page population uniqueto that student, and this comes in the form of two files:聢 A training set which is a pickled pandas data frame with 200,000 rows and 44 columns. Eachrow corresponds to a distinct Wikipedia page/url drawn at random from a certain populationof Wikipedia pages. The columns are鈥?URLID in column 0, which gives a unique identifier for each url. You will not be able todetermine the url from the URLID or the rest of the data. (It would be a waste of timeto try so the only information you have about this url is provided in the dataset itself.)鈥?40 feature/predictor variable columns in columns 1,...,40 each associated with a particularword (the word is in the header). For each url/Wikipedia page, the word column givesthe number of times each word appears in the asociated page.鈥?Three response variables in columns 41, 42 and 43* length = the length of the page, defined as the total number of characters in thepage ...

May 12, 2023 · 6 min · jiezi

关于算法:351751-数据库系统

351/751 Database Systems, 2023, Semester 1Lab 07due Sat 13 May 2023 11:59pm (15 marks in this lab = 1.5% towards final grade)This Lab has an attendance component of (3 marks) Transactions, Phenomena. Say for each of the following schedules: does the schedule contain phenomena or any other violation of the locking rules of the common scheduler? If not, give an explanation why not. If yes, say on which data object the phenomenon occurs; describe the phenomenon. State the highestisolation level that the schedule can be performed on.(a) s1 : r1[x], r2[y], r3[y], w1[x], w3[y], c3, r2[x], c2, c1(1 mark)(b) s2 : r1[x], r2[y], r3[y], w1[x], w3[y], c3, r2[y], c2, c1(1 mark)(c) s3 : r1[x], r2[y], r3[y], w1[x], w3[y], c3, w2[y], c2, c1(1 mark)(d) r1[x], r2[y], r1[y], r3[y], r2[x], r3[x], w1[x], c3, c1, w2[y], c2(1 mark)Transactions, Deadlocks. Consider the following sets of transactions. Can the set of transactions run into a deadlock if we use the common scheduler? If yes, give a scheduling diagram showing the deadlock, if no say why not.(a) (2 marks)TA1: w1[k], r1[x]TA2: r2[z], r2[x]TA3: r3[x], w3[z](b) (2 marks)TA1: r1[k], r1[x], w1[x]TA2: r2[z], r2[x], w2[z], w2[x]TA3: r3[x], r3[z]Crash recovery for steal, no-force policy: The following list gives pages, objects on these pages and their values in the stable database at a certain point in time:Page 1:x = 62y = 43Page 2:z = 46k = 12The following is the list of the most recent stable log records at the same point in time. The database uses the steal, no-force policy.[nr: 321, ta: 62, obj: x, b: 31, a: 62][nr: 324, ta: 62, obj: k, b: 12, a: 58][nr: 322, ta: 63, obj: y, b: 34, a: 43][nr: 323, ta: 62, obj: x, b: 62, a: 54][nr: 325, ta: 62, commit][nr: 327, ta: 64, obj: z, b: 46, a: 89][nr: 328, ta: 64, obj: k, b: 58, a: 91]a) You are supposed to perform crash recovery. What operations do you have to perform on which transactions? Give the content of the stable database after the crash recovery.(1 marks)b) Was a database buffer page with an uncommitted write written to the stable database? If yes, say which page and identify the time interval when it was written to thestable database. Give the interval as two log sequence numbers before and after, and say how you came to that conclusion. If no, give reasons for your answer (3 marks)

May 12, 2023 · 2 min · jiezi

关于算法:每日一题子串能表示从-1-到-N-数字的二进制串

1016. 子串能示意从 1 到 N 数字的二进制串关键词:数学、二进制题目起源:1016. 子串能示意从 1 到 N 数字的二进制串 - 力扣(Leetcode) 题目形容 T数学 T二进制给定一个二进制字符串 s 和一个正整数 n,如果对于 [1, n] 范畴内的每个整数,其二进制示意都是 s 的 子字符串 ,就返回 true,否则返回 false 。 子字符串 是字符串中间断的字符序列。 输出:s = "0110", n = 3输入:true输出:s = "0110", n = 4输入:false数据范畴1 <= s.length <= 1000s[i] 不是 '0' 就是 '1'1 <= n <= 109问题剖析数学知识:对于所有k位的二进制数(最高位为1,k>1),将其最高位的1去掉并去除前导0后,能够失去所有1~k-1位的二进制数。 对于题目给定的n,必有k满足2k≤n<2k+1,若s中含有[2k-1 , 2k-1]所有的数,也即s中含有所有k位二进制数,则其必然含有所有1~k位的二进制数,剩下的就是判断s中是否含有[2k, n]所有的数(k+1位)。 于是,问题等价于判断s中是否含有所有k位二进制数和局部k+1位二进制数。 k位二进制数共有2k-1 个,所以s至多含有2k-1 个长度为k的01序列,也即m至多为k+2k-1 -1,。 k+1位二进制数共有n-2k +1个,所以s至多含有n-2k +1个长度为k+1的01序列,也即m至多为k+1 + n-2k +1-1,即k+1 + n-2k 。 ...

May 11, 2023 · 2 min · jiezi

关于算法:算法竞赛力扣杯春赛战队赛-LCCUP23

力扣杯春赛 - 战队赛 LCCUP'23符文储备关键词:贪婪题目起源:LCP 77. 符文储备 - 力扣(Leetcode) 题目形容 T贪婪远征队在登程前须要携带一些「符文」,作为后续的冒险储备。runes[i] 示意第 i 枚符文的魔力值。 他们将从中选取若干符文进行携带,并对这些符文进行重新排列,以确保任意相邻的两块符文之间的魔力值相差不超过 1。 请返回他们可能携带的符文 最大数量。 输出:runes = [1,3,5,4,1,7]输入:3解释:最佳的抉择计划为[3,5,4]将其排列为 [3,4,5] 后,任意相邻的两块符文魔力值均不超过 1,携带数量为 3其余满足条件的计划为 [1,1] 和 [7],数量均小于 3。因而返回可携带的最大数量 3。输出:runes = [1,1,3,3,2,4]输入:6解释:排列为 [1,1,2,3,3,4],可携带所有的符文数据范畴1 <= runes.length <= 10^40 <= runes[i] <= 10^4问题剖析为了使得任意一块符文与其四周的魔力差值尽可能小,无妨将符文依照魔力值排序,从排序后的序列中选出满足“任意相邻的两块符文之间的魔力值相差不超过 1”的一段最长子序列,该子序列的长度即为题目要求的“最大数量”。 代码实现int runeReserve(vector<int> &runes) { int n = runes.size(), res = 0, cur = 0; // 按魔法值从小到大排序 sort(runes.begin(), runes.end()); // 找出满足条件的最长序列 for (int i = 1; i < n; i++) { if (runes[i] - runes[i - 1] <= 1)cur++; else res = max(cur, res), cur = 0; } res = max(res, cur); // 不要漏掉最初一个子序列 return res + 1;}工夫复杂度:O(nlog(n)) ...

May 11, 2023 · 7 min · jiezi

关于算法:JC1503解题方法

University of AberdeenSchool of Natural and Computing SciencesDepartment of Computing Science2022 – 2023Programming assignment – Individually Assessed (no teamwork)Deadline: 22:00, 16th May 2023 (SCNU local time)Title: JC1503 – Object-OrientedProgrammingNote: This assignment accounts for 30% of your total markof the course (Code and report will account for 30% and70% of the whole assessment, respectively).Information for Plagiarism: The source code and your report will be submitted for plagiarismcheck (e.g., Turnitin or other tools). Any AI tools which automatically help to edit, paraphrase,or generate your source code and report are not allowed. If those behaviours are detected, yoursubmissions will be classified as plagiarism. Please refer to the slides available at MyAberdeen formore information about avoiding plagiarism before you start working on the assessment. Pleasealso read the following information provided by the university:https://www.abdn.ac.uk/sls/online-resources/avoiding-plagiarism/page 2 of 10IntroductionIn this programming assignment, you will design and implement a Task Scheduler in Python,which is a program that helps manage and prioritise tasks for efficient and timely completion. Toachieve this, you will use the Priority Queue data structure and Object-Oriented Programmingprinciples. The Priority Queue is an abstract data type that stores and retrieves items based ontheir priority. Unlike a regular queue that follows a first-in-first-out (FIFO) data structure, apriority queue serves items based on their priority. In the Task Scheduler implementation, thePriority Queue will manage tasks by sorting them according to their priorities and deadlines. Eachtask will be defined as an object with attributes such as description, priority, and deadline, whichcan be added to the priority queue and executed based on their priority and deadline order.For instance, let's say you have the following tasks that require completion:• Complete project report - Priority 2, Deadline: May 1, 2023• Buy birthday gift for a friend - Priority 3, Deadline: April 30, 2023• Attend job interview - Priority 4, Deadline: April 28, 2023• Renew gym membership - Priority 1, No DeadlineThe Task Scheduler will add the above tasks to the priority queue based on their priority anddeadline. The queue will have the highest priority (greatest priority number) and earliest deadlinetasks at the top. The order will be as follows: ...

May 11, 2023 · 14 min · jiezi

关于算法:CHC5223算法结构

CHC5223 Data Structures and Algorithms 2022–2023 Semester 21 of 14Assignment 2Value 65% of coursework: Part A is 35% and Part B is 30%Individual workLearning outcomesStudents will be able to understand1.1 Data structures1.2 The applications of data structures1.3 Object-oriented programming concepts1.4 Methods for program testingStudents will have acquired skills in:2.1 Data abstraction2.2 The use of data structures2.3 Programming at a more advanced level in a high-level object-oriented language2.4 Program testing and documentationStudents will have acquired skills in:3.1 Self-management3.2 Learning3.3 Communication3.4 Problem solving3.5 Information technologyProcess and what submit to Student WebsiteThe assignment submitted should compressed into a .zip file, the following files should becontained in the compressed file:• a report as a Microsoft Word document containing text of all your classes.filename format: 12345678_CHC5223_CW2_Report.docx• a .zip file containing the project: the runnable jar file (if available) and all the program’ssource texts (.java), including those providedfilename format: 12345678_CHC5223_ CW2_Files.zipPart A – binary search treeGeneral requirementsAll your programming must conform to “Java Conventions and Programming Guidelines” – seemodule Moodle site.You must paste the source code of all your classes into your report, as text or images.IntroductionThe topic of this part of the assignment is binary search trees.The interface IMemberDB describes methods for an abstract data type (ADT) which holds adatabase of Member objects.You must implement IMemberDB as a binary search tree for Assignment 2.You must not make any changes to these interfaces.CHC5223 Data Structures and Algorithms 2022–2023 Semester 22 of 14RequirementsTask 1You must create a Java class called MemberBST that implements the interface IMemberDB.You must use a binary search tree but it does not need to be self-balancing.You must not encapsulate existing implementations of collections in your submission. Forexample, you must not create a TreeMap object and call methods on that object from your class.Failure to comply with this will result in zero marks for that part.Tip: use String.compareTo to compare strings lexicographically. You can treat uppercase andlowercase as different. (Hash codes have no place in this assignment.)Methods can be implemented either iteratively or recursively. You must not implement themethod remove by just building a new tree.You may make use of the supplied source text for the method remove, based on Object-OrientedProgramming in Oberon-2, Hanspeter Mössenböck Springer-Verlag 1993, page 78, transcribedinto Java by David Lightfoot (see Appendix).The constructor for MemberBST must print the string “Binary Search Tree” to System.out.Take care that you have not used a linear search O(n) where you should have used a binarysearch tree, aiming towards O(logn).12 marksTask 2You must make appropriate use of assertions (assert statements) to protect preconditions of theoperations. Remember to enable assertion checking for your project.2 marksTask 3You must make your class log monitoring information, either to a text file or by calls ofSystem.out.println.It must log (at least):• for every addition of a Member (put), for every get the Member(get), for every deletionof a Member(remove):o the Member name;o the sequence of nodes of the tree visited.• Paste your log into your report.6 marksWe have supplied a main program CHC5223.java for your use with this assignment.The name of the file is set in the static variable filename.Sample files sampleMembersUK.csv and sampleMembersUS.csv each contain 500 members inthis format.CHC5223 Data Structures and Algorithms 2022–2023 Semester 23 of 14Task 4You must devise a test plan for your implementation. Be sure to check (among many othercases).• that deleting a leaf node works correctly• that deleting a node with one descendant works correctly• that deleting a node with two descendants works correctly5 marksTask 5By using the supplied main program, or by other means, you must test your MemberBST.Include your test plan, test data used, expected results and actual results in your report. Youmust show your actual results and the logging information copied from your log file or theoutput pane of your IDE. Do not simply state “test passed”, or similar – show evidence6 marksTask 6You must state honestly which of the requirements of Assignment 2 you have successfullyfulfilled, citing evidence. Also, comment on the time efficiency and space efficiency of yourimplementation of the binary search tree.4 markstotal 35 marksCHC5223 Data Structures and Algorithms 2022–2023 Semester 24 of 14Part B – graphs and pathfindingThe topic of this part of Assignment 2 is graphs and pathfinding.General requirementsAll your programming must conform to “Java Conventions and Programming Guidelines”.You must paste the source code of all your classes into your report, as text, not images.You must implement all necessary data structures using only arraysWhen programming in Java it is usual to make use of collection classes from the Java class library.However, if you need to program in some other language such classes, or their equivalents, willnot necessarily be available.Task 1Find or devise a transport network – it need not be real, but it must be realistic. It must be anundirected, connected graph, with no loops. It must have at least eight nodes.Each node should have a name (with no spaces in it) and x and y positions (0  x < 256 and0  y < 256) indicating the approximate position of the node on a map with a 256 × 256 grid (yincreasing downwards).The links must contain information about the distance between the nodes it connects. Thedistance can be measured in suitable units of length, such as km, or time, such as minutes.The links between them must be such that there are several pairs of nodes that are linked bymore than one route.You must sketch your network and include it in your report. The sketch must show each nodeannotated with its name and located on the sketch at its x and y position. The sketch must showeach link annotated with its distance. You can make the sketch by hand but if you do so you willneed to scan it to include in your report.2 marksTask 2You must express your network as a text file using the syntax:“station” name x y“link” station station distanceEach station must have been defined in a station line before being cited in a link line.Include the content of the text file in your report.2 marksTask 3You must implement Java classes StackInt, QueueInt, ListInt and SetInt. These will be subclassesrespectively of abstract classes AbsStackInt, AbsQueueInt, AbsListInt, AbsSetInt, whose source isprovided and shown in the appendixes. These are given as abstract classes (to be ‘sub-classed’)rather than as interfaces (to be ‘implemented’) partly because they are all ‘bounded’, that is,with limited capacity because of being implemented by arrays, and also to allow us to give youhints on how to implement them.CHC5223 Data Structures and Algorithms 2022–2023 Semester 25 of 14The required behaviour of the methods of the classes is indicated as pre- and post-conditions incomments.4 marksTask 4You must make appropriate use of assertions (assert statements) to protect preconditions of theoperations. Remember to enable assertion checking for your project.1 markTask 5By using JUnit or otherwise you must test your implementations of StackInt, QueueInt, ListIntand SetInt. To do this, create objects of each class in which capacity is set to a low value, such as ...

May 11, 2023 · 14 min · jiezi

关于算法:快排的思想与实现

一、疾速排序(Quick Sort)疾速排序采纳分治法。首先从数列中挑出一个元素作为两头值。顺次遍历数据,所有比两头值小的元素放在右边,所有比两头值大的元素放在左边。而后按此办法对左右两个子序列别离进行递归操作,直到所有数据有序。最现实的状况是,每次划分所抉择的两头数恰好将以后序列简直等分(平均排布),整个算法的工夫复杂度为O(n logn)。 最坏的状况是,每次所选的两头数是以后序列中的最大或最小元素(正序和逆序都是最坏),整个排序算法的工夫复杂度为O(n²)。 均匀工夫复杂度为O(n logn),空间复杂度为O(logn),是一种不稳固的排序算法。 附算法实现源码: //疾速排序template <class T>int Partition(T data[],int left,int right){ T pivot=data[left]; while(left<right) { while(left<right&&data[right]>pivot) right--; data[left]=data[right]; while(left<right&&data[left]<=pivot) left++; data[right]=data[left]; } data[left]=pivot; return left;}template <class T>void QuickSort(T data[],int left,int right){if(left<right){ int p=Partition(data,left,right); QuickSort(data,left,p-1); QuickSort(data,p+1,right);}}二、抉择排序(Selection Sort)遍历所有数据,先在数据中找出最大或最小的元素,放到序列的起始;而后再从余下的数据中持续寻找最大或最小的元素,顺次放到序列中直到所有数据有序。原始数据的排列程序不会影响程序消耗工夫O(n²),绝对费时,不适宜大量数据排序。 均匀工夫复杂度为O(n²),空间复杂度为O(1),是一种不稳固的排序算法。 附算法实现源码: //抉择排序template <class T>void SelectionSort(T data[],int n){ for(int i=1;i<n;i++) { int k=i-1; for(int j=i;j<n;j++) { if(data[j]<data[k]) { k=j; } } if(k!=i-1) { T t=data[k]; data[k]=data[i-1]; data[i-1]=t; } }}

May 10, 2023 · 1 min · jiezi

关于算法:159234-java核心解析

159.234 OBJECT-ORIENTED PROGRAMMING S1, 2023Assignment 2Deadline: 11 May 2023, 11pmEvaluation: 40 marks (15% of your final grade)Late Submission: Deduct 5 marks per day lateIndividual Work You must complete this assignment by yourself (you must NOT share your codewith others or use others’ code including the code generated by ArtificialIntelligence platforms such as ChatGPT)Purpose: Reinforce Java OOP core concepts (abstraction, encapsulation, inheritance, andpolymorphism), collections framework and generics, exception handling, andinput and output streams. ...

May 10, 2023 · 4 min · jiezi

关于算法:CPT204面向对象编程指南

Advanced Object-Oriented ProgrammingCPT204 – Final ProjectCPT204 Advanced Object-Oriented ProgrammingFinal ProjectTask Sheet 2 – SupplementaryCPT204-2223 Final Project Task Sheet 2 – Supplementary Info● This document contains supplementary information on CPT204-2223 FinalProject● You must read Final Project Task Sheet 1 pdf first!○ after that, this document will give you more explanations on the code structureand more details on your tasks○ also, it is recommended to watch the video demo by Haoyue first!● If you have any questions, please ask in Final Project Forum○ please check Final Project Forum and LM Announcement frequently forupdates!CPT204-2223 Final Project Skeleton Files and Demo Video● Extract the CPT204-2223_Final_Project_Skeleton_Files.zip○ the Java skeleton code files are found in folder ataxx,and so create New Project from Existing Sources in IntelliJ on that folderas usual○ in folder library, there is a file for JUnit testing, and so import this libraryas usual for the given test case files○ in folder demo, there is a demo video mp4 file,and a text file that lists commands used in the demo videoAtaxx Code Overview (1)● As the game involves many files, we will explain the main files and operationsneeded to understand the code structure and game implementations○ we apply modular design, classes and methods can work independently○ some files may contain game-playing machinery that not necessarily be understood○ we start by explaining the routines of command reading● The game starts at Main.java where game instance is be created andgame.play() is called● In Game.java, we observe the play() method:setManual(RED)setAI(BLUE)○ which means in the beginning, RED plays first as a manual player and BLUE playsnext as an AI playerAtaxx Code Overview (2)● Continuing, in Game.java:○ setManual and setAI will create an instance of Manual and AIPlayer,and call setAtaxxPlayer to assign players according to their color andbeing manual/AI players○ in play(), while loop finds the final winner, and execute move or nextcommand (until receiving command to exit the game):■ if no winner yet, it lets the current player to be the next playerrunCommand(getAtaxxPlayer(ataxxBoard.nextMove()).getAtaxxMove())and runs its move;■ if the game is over (meeting an end condition):● if the winner is not yet announced, then announce it● after that, get and run the next commandrunCommand() and Command Types● Commands in runCommand(String command) are case-insensitive○ e.g. one can type in BOARD or board with the same effectCommand Type Format in Terminal ExplanationNEW new start a new game with an initial boardAI ai <red/blue> set Red/Blue player to be an AI playerMANUAL manual <red/blue> set Red/Blue player to be a human playerBOARD board print the board with labelsBLOCK block <cr> set blocks according to the rules in Task Sheet 1SCORE score print the current number of red and blue pieces on the boardBOARD_ON board_on print the board after each moveBOARD_OFF board_off not print the board after each movePIECEMOVE c0r0-c1r1(i.e., c2-b3) move the piece of current color on the board (must be legal)QUIT quit (or q) quit the gameERROR (any other input) print "Unknown command" in the terminalStates of a Square, PieceState, and Player Types● The states of a square (c, r) in a board are enumerated PieceState types:○ EMPTY: no piece at location (c, r)○ BLOCKED: there's a block at location (c, r)○ RED: there's a Red piece at the location (c, r)○ BLUE: there's a Blue piece at location (c, r)● Used in Player[] ataxxPlayers = new Player[PieceState.values().length]in Game.java, but there are only two types: RED and BLUE○ ataxxPlayers[0] = RED○ ataxxPlayers[1] = BLUE● Each type has opposite() method to return its opposite color○ e.g. RED.opposite() is BLUEPlayers● Represented by color Red/Blue in the game in abstract class Player.java● The implementor classes○ Manual extends Player: Manual(game, color)○ AIPlayer extends Player: AIPlayer(game, color, seed)■ students need to implement AI Player by themselves for Task A.2■ seed is used to implement the psedorandomness of the AI■ currently, seed is always incremented by 1 and students may changearbitrarily according to their AI implementationgetAtaxxMove● Called inrunCommand(getAtaxxPlayer(ataxxBoard.nextMove()).getAtaxxMove())● In Player.java, it is declared as an abstract method○ to be implemented independently in Manual and AIPlayergetAtaxxPlayer● Called inrunCommand(getAtaxxPlayer(ataxxBoard.nextMove()).getAtaxxMove())● In Game.java, Player getAtaxxPlayer(PieceState state)○ returns a player by indexing the attaxPlayers[] array○ the index is return by enum ordinal() method■ i.e. RED.ordinal() is 0 and BLUE.ordinal() is 1● In Board.java, ataxxBoard.nextMove() returns the state/color of the playerwhich is to move nextAtaxx Board● Board in Board.java is represented by11-by-11 array of PieceState○ with predetermined values as shown infigure on the right○ why? to avoid special edge cases● Each piece in board is labeled by:○ char value of column label c('a' - 2 < c < 'g' + 2)○ row label r ('1' - 2 < r < '7’ + 2)● Squares outside 7-by-7 "real" board(in 'a' - 'g' and '1' - '7') are blocks○ so that moving to these locations won'tMove Objects● All kinds of Move objects are created by a private constructor in Move.java○ into OVERALL_MOVES array○ a factory method then returns the requested Move objects○ so the same Move object used later by your AI Player will only becreated once – for efficiency● If the requested Move is not a legal move○ the factory method will return nullMethods in Board.java● index() turns column and row labels into index in 1-D array● getNeighbor() returns index in 1-D array of neighboring square given thedistance● read comments for understanding more helper methods!● createMove(String move)○ to make a Move object to be used in Game.javae.g. createMove("c3-d4")○ it first check whether it is a legal move and whether there's a winner,and check whether it is a pass, to add to list of total moves for displaying○ find the opposite colorCreating Move● createMove(String move) (continues)○ if it is a jump:■ set its 'from' index into empty and its 'to' index to next move■ change the color of surrounding pieces■ increase the number of consecutive jumping○ if it is a clone:■ set its 'to' index to next move■ change the color of surrounding pieces■ reset the number of consecutive jumping■ increase the number of corresponding color○ record the next move and update winner○ note that it uses isJump() and isClone() which you will complete■ explained later in this task sheetCPT204-2223 Final Project Part A.1● In the following pages, you will find details about Final Project Part A.1 thatyou need to complete○ there are 4 tasks / subparts that you need to complete○ you will submit your code to Learning Mall autograder during SubmissionDay (read Task Sheet 1 and upcoming Announcements for more details)○ your code will be tested on a new full set of test cases during grading○ partial grades will be given if you pass some tasks or pass some testcases○ more information and requirements are found in Task Sheet 1 pdf andfuture LM AnnouncementsPart A.1.1 Getting the Number of Colors● Complete the method getColorNums(PieceState color) in Board.java○ it is called in getScore() in Board.java to print the current score whengiven the command score○ it takes either RED or BLUE■ you can ignore other states○ e.g., getColorNums(RED) → 2● Find the partial test cases in ScoreTest.javaPart A.1.2 Setting a Block● Complete the method setBlock(char c, char r) in Board.java○ it is called when we want to put blocks with the command block○ it puts a block at the given position, and its reflected squaressymmetrically according to rules in Task Sheet 1○ we have given the code to throw an error when the location is not legal,such as already occupied by a piece or a block○ e.g., setBlock('c', '3')● Hints: Consider using the method setContent and the variable unblockedNum● Find the partial test cases in BlockTest.javaPart A.1.3 Clone or Jump?● Complete the method isClone() and isJump() in Move.java○ it is called in the first constructor Move in Move.java○ it takes 2 parameters: String location0 and String location1■ location0 is the origin location such as "c1"■ location1 is the target location such as "d2"○ it returns true if and only if the move is a clone/a jump○ e.g., isClone("c1", "d2") → trueisJump("c1", "d2") → false● Find the partial test cases in MoveTest.javaPart A.1.4 Getting the Winner● Complete the method getWinner() in Board.java○ it is used to find the winner of the game and is called in play() inGame.java and createMove() in Board.java○ it returns PieceState objects:■ null if the game is not finished■ RED or BLUE if the game is finished and there is a winner with that color■ EMPTY if the game is finished but there is no winner since red and bluehave the same number of pieces○ It also stores the result in instance variable winner● Hints: Consider using couldMove, getColorNums, getConsecJumpNums● Find the partial test cases in WinnerTest.javaCPT204-2223 Final Project Part A.2● You are given in your skeleton code a very simple AI, which moves randomly○ it generates all possible legal moves, and pick one uniformly at random● Work with your team members in a team of two/three students,to create your own AI player by modifying the codes in AIPlayer.java○ Specifically, you could create your new methods and call your ownmethods in findMove() method● Read Task Sheet 1 pdf and future LM announcements for furtherinformation and requirementsOptional Part: Ataxx GUI● Complete this part in GUI.java for extra points○ if you have completed the previous parts and have extra time○ to actually play the game in graphical interface● Here we provide the way to run the Ataxx game with a GUI interface○ to enable GUI of Ataxx game you need to first create a jar file○ and then run that jar file by using command line argument --display○ the complete steps can be found in the next slideOptional Part: Ataxx GUI (continues)Steps to create a jar file and to run Ataxx with GUI: ...

May 9, 2023 · 9 min · jiezi

关于算法:COSC1076-Vending机器

COSC1076 | Semester 1 2023Advanced Programming TechniquesAssignment 2 Vending MachineAssessment Type: Both group and individual assessments.Weight: 40% of the final course markDue Date: 23:59, Friday 26 May 2023 (Note that there is also a group demonstration due in Week 10)Silence Policy: From 5:00pm, Thursday 25 May 2023 (Week 12)Submission: Online via Canvas. Submission instructions are provided on Canvas.1 Introduction1.1 OverviewIn this assignment, you will use your C++ programming skills to create a front-end system for a vendingmachine. The vending machine serves all kinds of pastry treats. The company’s name is Penelope’s PastryDelights and as such, the executable you are creating will be called “ppd”.The following sections contain the details of this assignment. You are expected to understand every requirementexplained in this document and implement all of them accordingly. This assignment has a strong emphasis onlinked lists. You should get yourself familiar with this concept as soon as possible.In this assignment you will:• Practice the programming skills covered throughout this course, such as:– ADTs– Linked Lists– Pointers– Dynamic Memory Management– File Processing– Program State Management– Exception Handling• Practice the use of testing• Implement a medium size C++ program:– Use features of C++14– Use elements of the C++ STL• Work as a team– Use group collaboration toolsThis assignment is divided into four Milestones:• Milestone 1 (Group work): Test Cases, to be developed to ensure your ppd program implementation iscorrect (due week 10).1• Milestone 2 (Group work): A fully functioning implementation of the base ppd program, which passMilestone 1 tests. The group work (milestone 1 & 2) is worth 25% of the course mark. Your group isrequired to demonstrate REQ5, 6, 8 and 9 in week 10 lab session (due week 10).• Milestone 3 (Individual work): You will individually extend upon your group’s implementation withadditional functionality (called enhancements). The individual work is worth 15% of the course mark(due week 12).• Milestone 4 (Group + Individual work): Written report (no more than 4 pages) analysing the design andimplementation of your software, and the use of your test cases. You will demonstrate your group andindividual work. This is where your final work will be graded (due week 12).Group Progress Update (Group work): Your group will need to provide regular updates on your progressin this assignment to your tutor during your weekly lab classes. This will require your group to have completeda list of activities. Group Progress Update will not be marked directly, however, this will influence the finalgrade.1.2 Group WorkThe group work must be completed in groups of 4.• You may form groups with any student in the course.• We strongly recommend that you form groups from within your labs, because:– Your tutor will help you form groups, but only within your lab.– You will have plenty of opportunity to discuss your groups progress and get help from your tutorduring the rest of the course. It will be extremely helpful for your whole group to be present, butthis can’t happen if you have group members outside the lab.– If you form a group with students from multiple practicals, you will still need to be allocated to asingle tutor and we may need you to switch labs to ensure everyone gets a fair amount of time.Groups for Assignment 2 must be registered with your tutor by week 8 lab. Your tutor will “register”your group on Canvas. If you are unable to find a group, discuss this with your tutor as soon as possible.If at any point you have problems working with your group, inform your tutor immediately, so that issues maybe resolved. We will do our best to help manage group issues, so that everybody receives a fair grade for theircontributions. To help with managing your group work we will be requiring your group to use particular tools.These are detailed in Section 5.There are important requirements about keeping your tutor informed if you have been unwell or other wiseunable to contribute to your group. Remember your actions affect everybody in your group.1.3 Learning OutcomesThis assessment relates to all of the learning outcomes of the course which are:• Analyse and Solve computing problems; Design and Develop suitable algorithmic solutions using softwareconcepts and skills both (a) introduced in this course, and (b) taught in pre-requisite courses; Implementand Code the algorithmic solutions in the C++ programming language.• Discuss and Analyse software design and development strategies; Make and Justify choices in softwaredesign and development; Explore underpinning concepts as related to both theoretical and practicalapplications of software design and development using advanced programming techniques.• Discuss, Analyse, and Use appropriate strategies to develop error-free software including static code analysis, modern debugging skills and practices, and C++ debugging tools.• Implement small to medium software programs of varying complexity; Demonstrate and Adhere to goodprogramming style, and modern standards and practices; Appropriately Use typical features of the C++language include basic language constructs, abstract data types, encapsulation and polymorphism, dynamic memory management, dynamic data structures, file management, and managing large projectscontaining multiple source files; Adhere to the C++14 ISO language features.• Demonstrate and Adhere to the standards and practice of Professionalism and Ethics, such as describedin the ACS Core Body of Knowledge (CBOK) for ICT Professionals.22 Description of the Program and FunctionalitiesYou have been approached by a company to create a front-end system for a vending machine written in C++.The vending machine serves all kinds of pastry treats. The company’s name is Penelope’s Pastry Delightsand as such, the executable you are creating will be called “ppd”. In this assignment you are to implement anapplication that will perform the above tasks as a single user model.This section describes in detail all functional requirements of this assignment. You should make a conscientiouseffort to write your program in a way that is capable of replicating the functionalities of the ppd program,described in the requirements below.REQ1: Command-line argumentsA user of your program must be able to execute it by passing in the names of two data files that the system isto use. You need to check that exactly 3 command line arguments are entered. Your program will be run usingthese command line arguments:[s3344949@csitprdap02]$ ./ppd <stockfile> <coinsfile>For example:[s3344949@csitprdap02]$ ./ppd stock.dat coins.datREQ2: Load DataYour program needs to be populated with the data provided in the 2 data files whose names are conveyedvia the command line. You will need to tokenize this data in order to load it into the system. You may usethe class definitions provided in the startup code to store your system data. As part of this requirement youneed to ensure that the specified files are valid (that is, they exist and the data contained in them matches thespecification for this assignment). You need to abort the program and provide a suitable error message if thisis not the case.Item (or stock) File Format:[ItemID]|[ItemName]|[ItemDesc]|[Price]|[NumberOnHand]Please note that the Price is stored as numbers delimited by the ‘.’. The number to the left of the ‘.’ is thedollars and the number to the right will be the cents, for example:I0001|Meat Pie|Yummy Beef in Gravy surrounded by pastry|3.50|50Where the 3 represents the dollar component and the 50 represents the cents component of the price. A missing‘.’ from the price should be considered a data error.You must ensure that items are inserted in the linked list sorted by name.Money data file format:[denomination],[quantity]That is, there will be a row for each value of money that exists and the system will have an amount of eachdenomination. For example:31000,3500,4200,20100,3050,520,310,405,20This means that the system currently has 3 x 10 dollar notes, 4 x 5 dollar notes, 20 x 2 dollar coins, etc. Notethat the above denominations are the only valid denominations for your vending machine. The vending machinedoes not accept $20 or $50 notes. A valid file will always contain exactly 8 denominations, with no repeateddenominations. If you wanted to initialise the vending machine with no change then the valid way to do thatwould be:1000,0500,0200,0100,050,020,010,05,0Please note that you cannot assume that the data contained in these files are valid. Some examples (this is nota complete list) might be, there may be lines with too many or too few fields, and the data in each field maynot be of the correct type, range and/or length.Sample (valid) data files have been provided with the startup code. Make sure that your program works withat least these files. We will also be testing your program with invalid data in the data files. We recommendthat you get your program working for the (valid) provided data files first. Then spend some time testing forinvalid files after you have completed most/all of the remainder of the assignment.You should validate the contents of the files when loading. Please note that we may feed in file names whentesting that don’t end in ’.dat’, so please don’t validate for that. Likewise, you cannot assume the data fileswill be in the same directory as the executable, nor that we will have the same directory structure as you.REQ3: Display Main MenuYour program must display an interactive menu displaying 9 options. Your menu should look like this:Main Menu:1.Display Items2.Purchase Items3.Save and ExitAdministrator-Only Menu:4.Add Item5.Remove Item6.Display Coins7.Reset Stock8.Reset Coins9.Abort ProgramSelect your option (1-9):Your program must print out the above options and then allow the user to select these options by typing thenumber and hitting enter. Upon selection of an option, an appropriate task will be carried out.Upon completion of all options except “Exit”, the user is returned to the main menu. You can assume thatcustomers can only see the first three menu options, and the administrator can see all of them.The behavior of these menu options is described in following requirements from REQ4 to REQ12.4REQ4: Display ItemsThis option allows the user to request a display of the items available for purchase. This is the data loaded intothe linked list in the REQ2. This requirement should behave as follows from the main menu, the user selects 1and data should be displayed in the following format: ...

May 9, 2023 · 29 min · jiezi

关于算法:COMP2014J-数据结构与算法

Assignment 1:AVL Trees and Tree MapsCOMP2014J: Data Structures and Algorithms 2Lecturer: Dr. David Lillis (david.lillis@ucd.ie)Weight: 15% of final gradeDue Date: 23:59 Tuesday May 9th 2023 (Week 12)Document Version: 1.0IntroductionThis assignment is intended to give you experience implementing AVL treesand using an AVL tree to implement a different type of data structure (a type ofsorted Map known as a Tree Map). It is also a good exercise to gain experienceabout how generics, inheritance and object references work in Java.Source code that you must start from has been posted to Brightspace in the fileAssignment1-Source.zip. This also contains the Javadoc for the classes andinterfaces provided (in the “doc” folder). Import this project into IntelliJ in theusual way.You must use the interfaces and data structure implementations that areprovided. Do not use any interfaces or implementations from the built-in JavaCollections Framework. If you are in doubt, ask!TasksThe main tasks for this assignment are:• Implement the key methods for an AVL Tree, according to the providedinterfaces and base classes.• Adapt your AVL Tree implementation to implement the key methods ofa Tree Map, according to the provided IMap interface.• Develop a strategy to test if your implementations are correct.Implementation of AVL Tree MethodsThe source code contains a partial implementation of an AVL Tree in a filecalled AVLTree.java in the dsa.impl package. All of your work in this section mustbe in this class and it must use the interfaces that are provided.You must implement the following methods:• public boolean insert(T value) – insert a value into the AVL tree.Returns true if the value was inserted (i.e. it was not already in thetree), or false if not.• public boolean remove(T value) – remove a value from the AVL tree.Returns true if the value was removed, or false if not (i.e. the tree didnot contain that value).• public boolean contains(T value) – check to see if a value is containedin the AVL tree. Returns true if the value is in the tree, or false if not.• private void restructure(IPosition<T> x) – trinode restructuring (thethree nodes are x, its parent and its grandparent).If you wish, you may create other methods that help you to complete the task(e.g. rightRotate(IPosition<T> n), leftRotate(IPosition<T> n), etc.).Some hints and tips• Remember your AVLTree extends several other classes, so you can usesome of their helpful methods (e.g. expandExternal(…)).• The expandExternal(…) method uses newPosition(…) to create all positionobjects, so all the positions in the tree will be AVLPosition instances.• You can cast an IPosition<T> to an AVLPosition in the same way as youdid in previous worksheets.• Remember, every parent/child relationship works in two directions.Every time you change one of these references, you must change both.• In the lectures we talk about attaching subtrees. BUT when we programthis, we notice that the subtree structure does not change at all. We justneed to put the root of the subtree in the right place.• An AVLPosition object has a height attribute. You will need to efficientlycalculate the height of the positions in the tree when the tree changes.Calculating the heights of all positions every time the tree changes willbe at best O(n). An efficient implementation would be at worst O(h) whenan insert(…) or remove(…) operation is called.• The TreePrinter class has been provided, so you can print the contentsof your tree and see what it contains.Tree Map Implementation of IMap MethodsThe source code contains a skeleton implementation of a map based on anAVL Tree in a file called AVLTreeMap.java in the dsa.impl package. All of yourwork in this section must be in this class and it must use the interfaces that areprovided.As you have learned in Data Structures and Algorithms 1, a Map is an ADTcontains key/value pairs (called “entries”). Keys are used to uniquely identifyvalues. By default, entries in a map have no particular order. The IMap<K,V>interface is provided (where K is the generic type of the keys and V is the generictype of the values) and contains the following methods:• public V put( K key, V value ) – add a new key/value pair to the map.If this key was already contained in the map, the old value associatedwith it is returned and the new value is stored in the map instead.Otherwise it returns null. (Hint: this is similar to the AVL Treeinsert(…) method).• public V get( K key ) – get the value associated with the given key, ornull if that key is not contained in the map (Hint: this is similar to theAVL Tree contains(…) method).• public V remove( K key) – remove the entry with the given key from themap. Returns the value associated with that key if it was contained inthe map, or null otherwise (Hint: this is similar to the AVL Treeremove(…) method).• public IIterator<IEntry<K,V>> entries() – Return an iterator to iterateover all the entries contained in this map.• public IIterator<K> keys() – Return an iterator to iterate over all thekeys contained in this map.• public IIterator<V> values() – Return an iterator to iterate over all thevalues contained in this map.• public int size() – return the number of entries contained in this map.• public boolean isEmpty() – return true if the map is empty, or falseotherwise.A Map that is implemented using any type of binary search tree (often called a“Tree Map”) can be said to be a kind of sorted map, where all entries can beaccessed according to the natural ordering of their keys. In yourimplementation, the three iterator methods (entries(), keys(), and values()must iterate in ascending key order).For example, consider the following key/value entries stored in a map:{"zh", "Chinese"}, {"ga", "Irish"}, {"de", "German"}, {"en", "English"}When iterating the keys, the order would be (i.e. in alphabetical order): ...

May 9, 2023 · 10 min · jiezi

关于算法:COMP900542023S1模板

COMP90054-2023S1 /A3_public_templatePublic template0 stars 1 forkView codeAssignment 3: Azul ProjectYou must read fully and carefully the assignment specification and instructions detailed in thisfile. You are NOT to modify this file in any way.Course: COMP90054 AI Planning for Autonomy @ Semester 1, 2023Instructor: Tim Miller and Nir LipovetzkyDeadline Team Registration: Monday 1 May, 2023 @ 1800 (start of Week 9)Deadline Preliminary Submission: Monday 8 May, 2023 @ 1800 (start of Week 10)Deadline Wiki report, video & final Submission: Monday 22 May, 2023 @ 1800 (start ofWeek 12)Course Weight: 35% total, comprising 5% (preliminary competition) + 10% (finalcompetition) + 5% (video) + 15% (Wiki)Assignment type:: Groups of 3 (not 2 or 4!)Learning outcomes covered: 1-5Star WatchCode Issues Pull requests Actions Projects Wiki Security Insmasterguanghuhappysf128…last weekREADME.md ...

May 8, 2023 · 18 min · jiezi

关于算法:通过数据可视化赢得竞争瓴羊Quick-BI成功落地极氪汽车

过来两三年,新能源汽车赛道呈现出“冰火两重天”的场面:一方面是政策补贴和绿色环保等多重利好因素影响下,新能源汽车销量持续增长,市场占有率曾经靠近30%;另一方面,新能源汽车布局者越来越多,“价格战”越打越强烈。面对内卷重大的市场,极氪汽车另辟蹊径,借助瓴羊Quick BI之力胜利通过数据可视化博得了市场竞争。 相熟新能源车的人大多晓得,极氪汽车是成立于2021年的新兴品牌,公司主打的就是智能化、数字化与智慧出行。当然,造车是极氪的本行,但数字化该如何实现呢?极氪汽车找到了“外援”——阿里巴巴旗下企业数智服务品牌瓴羊,通过瓴羊Quick BI实现企业外部治理的数字化蝶变。  在极氪成立之初,为了实现数据驱动决策,早早就开始借助瓴羊Quick BI弱小的数据处理以及数据可视化能力打造本人的数据中台——“极数BI”。将来尽可能施展数据可视化的作用,帮忙管理层实现高效决策、及时响应市场变动的要求,瓴羊Quick BI在落地极氪汽车时将重点放在了三个方面:一是指标体系的搭建,厘清了极氪汽车经营倒退所需的要害数据指标,并依据极氪的外部经营治理需要细化出了几千个指标;二是数据看板出现,通过高深莫测的数据看板为高管们提供全渠道的实时动静;三是数据驱动决策,通过瓴羊Quick BI的数据可视化能力最终赋能企业治理,进步企业管理决策的精准度与时效性。  除了帮忙高管数据驱动决策外,瓴羊Quick BI在极氪汽车外部还实现了自上而下的全面推动,浸透进了极氪外部的各个业务端口,这进一步减速了极氪的数字化过程。不仅是高管,在极氪外部,瓴羊Quick BI在经管、人力资源、财务等各核心都已胜利落地,帮忙这些不同条线的业余人员实现业务指标、让更多的员工可能基于瓴羊Quick BI 的数据可视化、数据出现、中国式报表、自助剖析等主链路性能来发展工作,无效晋升了工作效率和工作品质。甚至在汽车研发等专业性较强的畛域,瓴羊Quick BI都能将整个研发过程生成数据可视化看板,让流程可视化、透明化,从而帮忙研发部门和管理层发现危险点、掌控研发进度,让数据价值在企业外部最大化。 从瓴羊Quick BI在极氪汽车的胜利利用不难看出,企业的数字化降级,曾经从选择题变成了必答题。修炼数字内功,是所有企业的事不宜迟。

May 8, 2023 · 1 min · jiezi

关于算法:ECE3141信息与网络

ECE3141 Information and networks - short projects Introduction Students working in pairs will undertake a short project. The projects will involve writing MATLAB or other simulation programmes or perhaps analysing the outputs of network analysis tools, and communicating the results of the investigation in a short report and a short (5 minute) live presentation on the topic. The precise details will be confirmed closer to the submission deadline, but you can expect the following: ...

May 8, 2023 · 23 min · jiezi

关于算法:每日一题使二叉树所有路径值相等的最小代价

6419. 使二叉树所有门路值相等的最小代价关键词:层序遍历、深度优先题目起源:6419. 使二叉树所有门路值相等的最小代价 - 力扣(Leetcode) 题目形容 T层序遍历 T深度优先给你一个整数 n 示意一棵 满二叉树 外面节点的数目,节点编号从 1 到 n 。根节点编号为 1 ,树中每个非叶子节点 i 都有两个孩子,别离是左孩子 2 * i 和右孩子 2 * i + 1 。 树中每个节点都有一个值,用下标从 0 开始、长度为 n 的整数数组 cost 示意,其中 cost[i] 是第 i + 1 个节点的值。每次操作,你能够将树中 任意 节点的值 减少 1 。你能够执行操作 任意 次。 你的指标是让根到每一个 叶子结点 的门路值相等。请你返回 起码 须要执行减少操作多少次。 满二叉树 指的是一棵树,它满足树中除了叶子节点外每个节点都恰好有 2 个节点,且所有叶子节点间隔根节点间隔雷同。门路值 指的是门路上所有节点的值之和。奢侈实现不难想到,最终根节点到各叶子结点的门路值必然等于最后根节点到各叶子结点的最大门路值。 于是,先通过深搜,将各叶子结点到根节点的门路值预处理进去,同时找出最大门路值。之后,便能够失去各叶子结点门路值与指标门路值(即找到的最大门路值)的差值,这个差值即为对这个叶子结点须要进行的操作数。 同时,又发现,具备雷同父结点的两个兄弟结点l和r,给l和r加上x,等价于给l和r的父结点+x,于是,可将对最初一层结点(叶子结点所在层)的操作进行压缩,对于倒数第二层,同样能够进行相似的操作压缩,直到压缩到根节点。 int minIncrements(int n, vector<int> &cost) { /** * 深度优先遍历:计算出每个叶子节点的门路值,并找出最大门路值 */ int d[n + 1], maxDep = 0; memset(d, 0, sizeof d); function<void(int, int)> dfs = [&](int u, int dep) { int t = dep + cost[u - 1]; if (u > n >> 1) { d[u] = t, maxDep = max(t, maxDep); return; } dfs(u << 1, t), dfs(u << 1 | 1, t); }; dfs(1, 0); // 计算出每个叶子结点的门路值与最大门路值的差值 for (int i = (n >> 1) + 1; i <= n; i++)d[i] = maxDep - d[i]; /** * 设左孩子、右孩子、父结点的门路值别离为l、r、p * 因为往父结点+v,等价于往左右孩子各+v * 所以,无妨把左右孩子加的公共值加到父结点上,从而减小操作次数 * 也即(假如l≤r),p=min(l,r),l=0,r=-=l * 逐层将操作往上传递 */ int res = 0; while (n > 1) { for (int i = (n >> 1) + 1; i <= n; i += 2) { if (d[i] || d[i + 1]) { if (d[i] > d[i + 1])swap(d[i], d[i + 1]); d[i >> 1] = d[i]; // 公共操作施加到父结点 res += d[i + 1] - d[i]; // 进行非公共操作 } } n >>= 1; } return res;}工夫复杂度:O(n) ...

May 7, 2023 · 2 min · jiezi

关于算法:Intelligent-Enterprise-和企业数字化转型的关联关系

Intelligent Enterprise 是指一种基于人工智能技术的数字化企业。Intelligent Enterprise 利用人工智能技术来进步企业的效率、创新能力和竞争力,帮忙企业更好地适应和应答一直变动的市场和商业环境。 Intelligent Enterprise 通常具备以下几个特色: 数据驱动:Intelligent Enterprise 借助大数据和人工智能技术来收集、解决和剖析数据,从而实现更精准的业务决策和翻新。智能自动化:Intelligent Enterprise 借助自动化技术来提高效率和缩小错误率。智能自动化技术包含机器学习、自然语言解决、机器人流程自动化等。客户导向:Intelligent Enterprise 借助人工智能技术来提供更个性化的客户体验。Intelligent Enterprise 能够通过剖析客户数据来预测客户需要,提供更好的产品和服务。凋谢合作:Intelligent Enterprise 能够通过开放式的技术和单干平台,与供应商、客户和其余企业单干。这种开放式的合作能够带来更多的商业机会和翻新。Intelligent Enterprise 能够利用于各种行业和畛域,例如制造业、金融服务、零售业等。它能够帮忙企业在数字化时代中放弃竞争劣势,实现更高的效率和创新能力。 Intelligent Enterprise和企业数字化转型之间有着严密的关联关系。Intelligent Enterprise是指使用古代技术和数据分析能力,实现企业高效经营和业务增长的新型企业模式。而企业数字化转型是将传统企业的业务流程、组织架构和文化转变为数字化的、自动化的和更为灵便的模式,以进步企业的竞争力和适应性。 在数字化转型过程中,企业通常会引入一系列新技术和工具,如云计算、大数据、人工智能等,这些技术将数据与智能剖析相结合,以实现智能化决策、自动化流程和业务翻新。这种数字化转型的指标就是建设一个Intelligent Enterprise,使企业更加智能、麻利和翻新,以应答一直变动的市场和客户需要。 因而,Intelligent Enterprise和企业数字化转型之间是相辅相成的关系,数字化转型是实现Intelligent Enterprise的要害门路,而Intelligent Enterprise则是数字化转型的最终目标。

May 7, 2023 · 1 min · jiezi

关于算法:ChatGPT-的出现对于-Citizen-developers-意味着什么

ProductCarouselComponent category 平民开发者(Citizen Developer)指的是那些不具备业余编程技能,但在业余时间应用低代码或无代码平台开发应用程序的人。这些人通常是企业中的非技术人员,比方业务分析师、项目经理、营销人员等等。 低代码和无代码开发平台使平民开发者能够通过图形用户界面、拖放性能和可视化工具创立应用程序,而不须要深刻学习编程语言。这些平台提供了模板、组件、API和工作流等工具,以便公民开发者可能疾速地开发出功能完善的应用程序。 平民开发者的呈现,使得企业可能更快地推出应用程序,减速数字化转型的过程。同时,平民开发者还能够依据本人的业务需要,自主开发出可能帮忙企业提高效率和降低成本的应用程序。 ChatGPT 作为一种自然语言解决模型,能够帮忙 Citizen developer 更轻松地开发语言相干的应用程序。例如,一个 Citizen developer 可能想要创立一个聊天机器人应用程序,但没有编程背景。ChatGPT 能够帮忙 Citizen developer 实现这一指标,因为它能够天然地了解和生成语言,从而帮忙 Citizen developer 更轻松地构建聊天机器人应用程序。 此外,ChatGPT 还能够通过自然语言生成和了解,帮忙 Citizen developer 更轻松地构建语言翻译、语音辨认、文本分类等应用程序。总之,ChatGPT 的呈现能够帮忙 Citizen developer 更疾速地构建语言相干的应用程序,同时升高了学习编程的门槛。 尽管 ChatGPT 能够帮忙 Citizen developers 更轻松地开发语言相干的应用程序,然而它并不能间接将 Citizen developers 转化为业余程序员。Citizen developers 能够通过低代码或无代码平台来构建应用程序,但这些平台的性能和灵活性可能无限。Citizen developers 可能须要更高级的编程技能来解决更简单的问题或实现更高级的性能。 当然,Citizen developers 能够通过应用 ChatGPT 并把握更多编程常识,逐渐倒退成为业余程序员。ChatGPT 能够作为一种工具,帮忙 Citizen developers 更深刻地理解编程和算法,进步他们的编程能力。Citizen developers 还能够通过加入在线课程、浏览编程书籍和进行实际来加强本人的编程技能。只有 Citizen developers 有足够的激情和毅力,他们齐全能够成为业余程序员。

May 7, 2023 · 1 min · jiezi

关于算法:机器学习中的有标注数据集和无标注数据集

在机器学习和自然语言解决等畛域,大多数模型的训练须要应用大量的数据来进行学习。这些数据能够分为有标注数据集和无标注数据集两种类型。 无标注数据集是指在数据集中没有提供明确标注或标签的数据集。这意味着数据集中的每个样本都短少明确的分类或标签信息。例如,在自然语言解决畛域,无标注数据集可能是大量的文本数据,然而这些文本数据没有被标记为不同的语言、主题、情感等类别。 相比之下,有标注数据集是曾经被人工或主动标记或标注了不同类别或标签的数据集。例如,在图像分类问题中,有标注数据集可能是一个蕴含数万张图像的数据集,每个图像都被标记为它所属的类别(例如"猫"或"狗")。 无标注数据集对于训练大型深度学习模型十分重要。它能够用于训练无监督学习算法、生成反抗网络等,并用于进步模型的泛化能力和性能。 有标注数据集和无标注数据集别离的利用场合有标注数据集和无标注数据集在机器学习和自然语言解决等畛域中都有着重要的利用场合。它们的次要区别在于是否具备明确的标注信息。 有标注数据集实用于训练有监督学习算法。这类数据集曾经被人工或主动地标注为不同的类别或标签。例如,在图像分类问题中,有标注数据集可能是一个蕴含数万张图像的数据集,每个图像都被标记为它所属的类别(例如"猫"或"狗")。有标注数据集能够用于训练监督学习算法,例如分类、回归等模型。 无标注数据集实用于训练无监督学习算法和半监督学习算法。这类数据集不足明确的标注信息,然而能够用于训练无监督学习算法和半监督学习算法。例如,在自然语言解决畛域,无标注数据集可能是大量的文本数据,然而这些文本数据没有被标记为不同的语言、主题、情感等类别。无标注数据集能够用于训练无监督学习算法,例如聚类、降维等模型,以及半监督学习算法,例如自训练和协同训练等办法。 同时,有标注数据集和无标注数据集也能够组合应用。例如,能够应用大量的有标注数据集和大量的无标注数据集来训练深度学习模型,从而进步模型的泛化能力和性能。

May 7, 2023 · 1 min · jiezi

关于算法:COMP9020算法分析

COMP9020 Assignment 2 2022 Term 2Due: Monday, 18th July, 12:00 (AEST)Submission is through WebCMS/give and should be a single pdf file, maximum size 2Mb. Proseshould be typed, not handwritten. Use of LATEX is encouraged, but not required.Discussion of assignment material with others is permitted, but the work submitted must be yourown in line with the University’s plagiarism policy.Problem 1 (15 marks)Let S be a set.(a) Show that for any set T and any function f : S→ T, the relation R f ? S× S, defined as:(s, s′) ∈ R f if and only if f (s) = f (s′)is an equivalence relation. (9 marks)(b) Show that if R ? S× S is an equivalence relation, then there exists a set T and a function fR : S → Tsuch that:(s, s′) ∈ R if and only if fR(s) = fR(s′)(6 marks)Problem 2 (20 marks) ...

May 6, 2023 · 8 min · jiezi

关于算法:MAT232H问题解决

Assignment 2 - Summer 2022Due: July 10, 2022 at 11:59pm via CrowdMark.Unless otherwise stated, you must show your work.Question 1. Quadric surfaces:(a) Sketch the cross-sections of the surface x2 + 3y2 = 1 + z2 parallel to the xy-plane, the xz-plane, and theyz-plane. Identify the shapes of these cross-sections.(b) The parametric curve r(t) = ?1 + cos(t), sin(t), 2 sin( 12 t)? parametrizes the intersection of two quadric surfaces.Identify the two quadric surfaces by equation (and by name) and explain how you know that your answer iscorrect.Question 2. Computing partial derivatives:(a) Let f(x, y) be a function of two variables such that fx(5, 3) = 4 and fy(5, 3) = ?1. Let g(x, y) = f(2x+3, 3y2).Find gx(1, 1) and gy(1, 1).Evaluate fx(1, ) and fy(1, ).Question 3. Finding tangent planes through certain “anchors” and certain directions:(a) Find all planes which (i) are tangent to the elliptic paraboloid z = x2 + y2, and (ii) pass through both pointsP = (0, 0,?1) and Q = (2, 0, 3). How many such planes are there?(b) Find all planes which (i) are tangent to the surface z = x+xy2? y3, (ii) are parallel to the vector v? = ?3, 1, 1?,and (iii) pass through the point P = (?1,?2, 3). How many such planes are there?(c) Find all planes which (i) are tangent to the surface z = x2 + sin y, (ii) are parallel to the x-axis, and (iii) passthrough the point P = (0, 0,?5). How many such planes are there?ELEC2133Analogue ElectronicsThis midterm contributes to 10% of the total assessment of this courseThe due date is on Monday July 18, 2022 (11:59pm). Your submissions are tobe submitted on Moodle before the due date and time. Assignments submittedafter this date will attract a penalty of 5% per day.The take home midterm contains two problems with four parts. The first problemis the continuation of assignment II. The parts which deal with frequencyresponse and simulation are included here. The second problem is the modifiedversion of assignment I. Each problem contains one or more parts. Each part hasbeen labelled with P, C, D or HD that indicates the level of difficulty. P meansthat the question could be attempted by all students and students who answer thequestion correctly are at the level of “pass”. C means the question could beattempted by students who are at the level of “credit” in the course. D and HDindicate the question could be attempted by students who are at the level of“Distinction” and “High Distinction”, respectively.What does this mean?If you are targeting to pass or get credit in the course, you may only attempt thoseP or C types of questions.If you are happy or targeting to get a distinction, you can attempt those P, C, andD types of questions.If you are targeting a to get high distinction, you should attempt all the questionsincluding HD type of questions.2QUESTION 1 [60 Marks]In the assignment I, you analyzed and designed the charge readout circuit for PZT actuatorshown in Fig 1(a). One of the problems that is encountered in the readout circuit is that the laststage of the amplifier, which is the non-inverting amplifier, amplifies low-frequency noise frompower supply or the vibration of the actuator due to environmental factors. It also amplifiesany of DC imperfections contributed from the previous stages. Reducing the noise at the outputis important while ensuring the readout signal is amplified. Although there are othermodifications that may be applied to the non-inverting amplifier in order to achieve high signal-to-noise ratio, the non-inverting amplifier will be replaced by a three-stage transistor amplifiershown in Fig. 2(a) in this assessment. Your task will be to calculate its bandwidth.Fig. 1: PZT actuator self-sensing readout circuitThe three-stage amplifier consists of one n-channel MOSFET transistor M1 in depletionmode with W/L = 1 and two BJT transistors Q1 and Q2. The transistors have the modelparameters as provided in the Table belowTransistor ParametersM1 Kn = 10mA/V2 VTN = -2V =0.02V-1 Cgs = 3.5pf, Cgd = 0.1pfQ2 =150 VA = 80V VBE = 0.7V fT = 2GHz, C= 0.2pfQ3 =80 VA = 60V VBE = 0.7V fT = 2GHz, C= 0.2pfFig. 2: A three-stage transistor amplifierPART I (Calculating bandwidth)a) [P,C] Draw small-signal equivalent circuit of the amplifier in the form suitable forlow frequency. [5 marks]b) [P,C] Calculate the lower 3dB frequency, fL, of the amplifier using the appropriatetime constant method. [15 Marks]c) [P,C] Draw small-signal equivalent circuit of the amplifier in the form suitable forhigh-frequency analysis. [5 Marks]d) [DN]*Calculate the higher 3dB frequency, fH, of the amplifier using the appropriatetime constant method. [15 Marks]PART II (LTSpice or Pspice Simulation)a) [DN] *Simulate Fig. 2 and compare the results with your calculation in assignment IIand Part I. The Spice transistor models will be uploaded on Moodle.[20 marks]4QUESTION 2 [40 Marks]The Opamp readout circuit you dealt with in assignment I and shown in Fig. 1 is modified to ...

May 6, 2023 · 5 min · jiezi

关于算法:每日一题数青蛙

1419. 数青蛙关键词:模仿题目起源:1419. 数青蛙 - 力扣(Leetcode) 题目形容 T模仿给你一个字符串 croakOfFrogs,它示意不同青蛙收回的蛙鸣声(字符串 "croak" )的组合。因为同一时间能够有多只青蛙呱呱作响,所以 croakOfFrogs 中会混合多个 “croak” 。 请你返回模仿字符串中所有蛙鸣所需不同青蛙的起码数目。 要想收回蛙鸣 "croak",青蛙必须 依序 输入 ‘c’, ’r’, ’o’, ’a’, ’k’ 这 5 个字母。如果没有输入全副五个字母,那么它就不会发出声音。如果字符串 croakOfFrogs 不是由若干无效的 "croak" 字符混合而成,请返回 -1 。 输出:croakOfFrogs = "croakcroak"输入:1 解释:一只青蛙 “呱呱” 两次输出:croakOfFrogs = "crcoakroak"输入:2 解释:起码须要两只青蛙输出:croakOfFrogs = "croakcrook"输入:-1解释:给出的字符串不是 "croak" 的无效组合。数据范畴1 <= croakOfFrogs.length <= 105字符串中的字符只有 'c', 'r', 'o', 'a' 或者 'k'模仿一保护以后有多少青蛙(设为fragNum)在呱,fragNum的最大值就是至多须要的青蛙数。 设呱到字符char的青蛙数为cnt[char],将字符croak映射到0~4,遍历字符串croakOfFrogs,设以后字符为ch: ch=c:一只新的青蛙退出呱的队伍,fragNum++ch=r:查看是否有青蛙呱到c,也即r的前一个字符。若无,阐明以后呱到r是不非法的,return -1;若有,将呱到字符c的青蛙前进一步,让其呱到r,也即cnr[c]--,cnt[r]++ch=o:与ch=r相似ch=a:与ch=r相似ch=k:意味着有一只青蛙呱完了,正在呱的青蛙数应该-1,也即fragNum--遍历完后,若还有青蛙在呱,也即fragNum>0,阐明字符串croakOfFrogs不能由若干轮呱组成。 int minNumberOfFrogs(string croakOfFrogs) { // 长度必须是5的倍数 if (croakOfFrogs.size() % 5)return -1; // 将字母映射成数字 unordered_map<char, int> mp = {{'c', 0}, {'r', 1}, {'o', 2}, {'a', 3}, {'k', 4}}; // 正在发声的青蛙的数量 发声发到字符i的青蛙的数量 int frogNum = 0, cnt[4] = {0}; // 模仿 int t, res = 0; for (char c: croakOfFrogs) { t = mp[c]; // 新一轮发声 if (t < 1) { frogNum++, cnt[t]++; // 求最大值 if (frogNum > res)res = frogNum; } // 非新一轮发声 else { // 前一个字符数量为0,不能形成一轮发声 if (!cnt[t - 1])return -1; cnt[t - 1]--; t == 4 ? frogNum-- : cnt[t]++; } } // 最初还有发声没有实现的青蛙,阐明不能由若干轮发声组成 if (frogNum)return -1; return res;}工夫复杂度:O(n) ...

May 6, 2023 · 2 min · jiezi

关于算法:用-Spark-预测回头客

拜访【WRITE-BUG数字空间】_[内附残缺源码和文档]至此“淘宝双 11 数据分析与预测课程案例”所须要的环境配置实现。另外实际操作中发现在案例教程中存在一些小问题,比方教程中 Eclipse 版本为 3.8,然而在配置 Tomcat Server 时又要求配置 v8.0 版本,然而 3.8 版本的 Eclipse 最多仅反对到 v7.0 版本的 Tomcat,所以实际操作时应用了更新的 Eclipse 版本。一、运行环境理论配置环境联合了理论状况,没有和试验案例完全一致,不过整个性能失常实现。理论运行环境及版本如下所示。Linux:Ubuntu14.04JDK:Openjdk-1.7.0_181Hadoop: 2.7.6MySQL: 5.7.24Hive: 1.2.2Sqoop: 1.4.7Spark: 2.1.0Eclipse: 4.5.0Echarts: 3.8.4配置过程中截图如下所示,因为步骤较多,仅截取局部关键步骤。图 1.1 创立 hadoop 用户,增加管理权限图 1.2 装置配置 SSH图 1.3 配置 Java图 1.4 配置 Hadoop图 1.5 运行 Hadoop图 1.6 配置运行 MySQL图 1.7 配置运行 Hive图 1.8 配置运行 Sqoop图 1.9 配置运行 Spark至此“淘宝双 11 数据分析与预测课程案例”所须要的环境配置实现。另外实际操作中发现在案例教程中存在一些小问题,比方教程中 Eclipse 版本为 3.8,然而在配置 Tomcat Server 时又要求配置 v8.0 版本,然而 3.8 版本的 Eclipse 最多仅反对到 v7.0 版本的 Tomcat,所以实际操作时应用了更新的 Eclipse 版本。二、本地数据集上传到数据仓库 Hive试验数据集有 3 个文件,别离是用户行为日志文件 user_log.csv、回头客训练集 train.csv、回头客测试集 test.csv,以下是三个文件的数据格式及阐明。表 2.1 user_log 字段定义字段名字段含意user_id买家 iditem_id商品 idcat_id商品类别 idmerchant_id卖家 idbrand_id品牌 idmonth交易工夫:月day交易事件:日action行为,取值范畴{0,1,2,3},0 示意点击,1 示意退出购物车,2 示意购买,3 示意关注商品age_range买家年龄分段:1 示意年龄 <18,2 示意年龄在[18,24],3 示意年龄在[25,29],4 示意年龄在[30,34],5 示意年龄在[35,39],6 示意年龄在[40,49],7 和 8 示意年龄 >=50,0 和 NULL 则示意未知gender性别:0 示意女性,1 示意男性,2 和 NULL 示意未知province播种地址省份回头客训练集 train.csv 和回头客测试集 test.csv,训练集和测试集领有雷同的字段。表 2.2 user_log 字段定义字段名字段含意user_id买家 idage_range买家年龄分段:1 示意年龄 <18,2 示意年龄在[18,24],3 示意年龄在[25,29],4 示意年龄在[30,34],5 示意年龄在[35,39],6 示意年龄在[40,49],7 和 8 示意年龄 >=50,0 和 NULL 则示意未知gender性别:0 示意女性,1 示意男性,2 和 NULL 示意未知merchant_id卖家 idlabel是否是回头客,0 值示意不是回头客,1 值示意回头客,-1 值示意该用户曾经超出咱们所须要思考的预测范畴。NULL 值只存在测试集,在测试集中示意须要预测的值。 ...

May 5, 2023 · 1 min · jiezi

关于算法:INFO1113-COMP9003算法

INFO1113 / COMP9003 AssignmentDue: 14 May 2023, 11:59PM AESTThis assignment is worth 18% of your final grade.Task DescriptionIn this assignment, you will create a game in the Java programming language using the Processing library for graphics and gradle as a dependency manager. In the game, the player must be able to move chess pieces on a chess board in order to play against an AI, ultimately capturing the opponent’s pieces and executing a strategy to checkmate the opponent’s king.You have been given the task of developing a prototype of the game. A full description of gameplaymechanics and entities can be found below. An artist has created a simple demonstration of the game and has posted it on your online forum (Ed). You can also play a similar game here.You are encouraged to ask questions on Ed under the assignments category if you are unsure of the specification – but staff members will not be able to do any coding or debugging in this assignment for you. As with any assignment, make sure that your work is your own, and do not share your code or solutions with other students.Working on your assignmentYou have been given a scaffold which will help you get started with this assignment. You can download the scaffold onto your own computer and invoke gradle build to compile and resolve dependencies. You will be using the Processing library within your project to allow you to create a window and draw graphics. You can access the documentation from here.INFO1113Page 2 of 11GameplayThe game contains a number of entities that will need to be implemented within your application.BoardThe board consists of a grid of tiles 14x14. Each tile is 48x48 pixels, so the total is 672x672 pixels.However, there are 120 pixels on the right sidebar reserved for information such as timers showing the number of minutes and seconds remaining on each player’s clock, and warnings or other messages for the user. The window size is therefore 792x672.The board is arranged in a checkerboard pattern as below with alternating black and white tiles. These are fixed and do not change. Pieces sit atop these tiles, and the tiles may change colour shade to indicate highlights for particular reasons.There are 4 main types of highlights: • Blue – the player clicked on a piece, and it is able to move to this square.• Light red – the currently selected piece can move to this square, capturing the current piece there• Green – the player’s currently selected piece• Yellow – the last piece to move, and the square it came from• Dark red – the king on this square is currently in check, or checkmate has occurred (pieces that contribute to the checkmate are highlighted in light red)The initial piece layout is defined in a file named in the “layout” attribute of the JSON configuration file described below.INFO1113Page 3 of 11ConfigThe config file is in located in config.json in the root directory of the project. Use the simple json library to read it. Sample config and level files are provided in the scaffold.The config sample as shown to the left, contains the name of the layout file. This is also located in the root directory of the project. The layout file will contain a grid of text characters, where each character represents the piece that should be in that cell. Uppercase characters are for black, and lowercase are for white. See the table below.Empty spaces are empty tiles. All maps used for marking will be valid, but you should write your own tests for invalid maps and handle them as you see fit.The “time_controls” section contains the amount of time to be given to player 1 and player 2 (player 2 is the computer - cpu). Seconds it the total time they start with, which is consumed while they are thinking about a move. The “increment” is a number in seconds added to their remaining time once they make a move.The “player_colour” property denotes the colour of the pieces of player 1 (the human player). It should either have the value “white” or “black”. If player 1 is white, then player 2 is black. If player 1 is black, then player 2 is white. Whoever is white has the first move, as in regular chess.Layout file See page 5 for images of movementBlack White Chess piece Value Sprites MovementP p Pawn 1 One space forward. Captures diagonally only. If blocked, cannot move.R r Rook 5.25 Horizontally and vertically.N n Knight 2 2 squares vertical, 1 horizontal, or vice versaB b Bishop 3.625 Diagonally in any direction.H h Archbishop 7.5 Like Knight + BishopC c Camel 2 3 squares vertical, 1 horizontal, or vice versaG g General/Guard 5 Like Knight + KingA a Amazon 12 Like Knight + Bishop + RookK k King ∞ 1 space in any direction. Cannot move into danger.E e Chancellor 8.5 Like Knight + RookQ q Queen 9.5 Like Bishop + RookINFO1113Page 4 of 11MovementThe “piece_movement_speed” property in the config denotes how fast in pixels per frame a piece move should occur. This is limited by the “max_movement_time”, a number in seconds that the movement time should not exceed. If the movement would exceed this amount of time, the speed is increased to ensure it doesn’t take longer. Moves occur at a constant speed, with the chess piece smoothly transitioning in a straight line from its original position to its new position.To trigger a move, the player must first select a piece by clicking on the cell it’s located in. Then, click to the cell the piece should move to. If the player instead selects one of their other pieces, then that piece becomes selected instead. If the player clicks on the selected piece again, or an invalid move, it becomes unselected.Normal movement of pieces is described in the table above. The king, queen, bishop, knight, rook and pawn all have the same movement as in regular 8x8 chess. For the purposes of pawn movement, “forward” is considered going up the board for the human player, and going down the board for the computer player.In addition, be mindful of the following special moves.Special moves:• A pawn can move two squares forward if it is located on 2nd row from the top or bottom of the board (rank 2 and rank 13), and has not moved before.• A king may perform a ‘castling’ move if it has not moved before, which allows it to move two squares horizontally in either direction so long as there is also a rook towards the direction it will move (on the same rank), and that rook hasn’t moved. When this move is performed, the rook is placed on the other side of the king, adjacent to it.• Pawn promotion: When a pawn reaches the 8th rank (ie. when it crosses the halfway point on the 14x14 board), then it is promoted to a queen. It immediately turns into a queen and can be used as such in all subsequent movesOnly a camel or knight move may jump over pieces (or the rook when castling), and a player may not move a piece onto a cell already containing one of their own pieces. If a move causes the piece to enter a tile containing one of the opponent’s pieces, the opponent’s piece is ‘captured’ and removed from the board. All pieces capture on the same tiles as their regular movement, with the only exception being pawns which capture diagonally forwards instead, if there is a piece there. This is the only time they are allowed to move diagonally. If there is a piece directly in front of a pawn, it is blocked and cannot move to the cell occupied by that piece.Examples of possible moves for each piece are shown below.INFO1113Page 5 of 11Figure 1: Archbishop movement Figure 2: Amazon movement Figure 3: Bishop movementFigure 4: General/Guard movement Figure 5: Camel movement Figure 6: Rook movementFigure 7: Knight movementFigure 8: King movement. The king cannot move to squares controlled by an opponent's piece.Figure 9: Chancellor movement. The camel and generals block movement in the left direction, but knight moves can still jump over (same for other knight combinations).Figure 10: Pawn movement. The pawn can only move diagonally when capturing and cannot move directly forward if blocked. Figure 11: Queen movementINFO1113Page 6 of 11Check and CheckmateIf after a move, a king is under attack, the king is said to be in ‘check’. Under this circumstance, the player whose king is in check must do one of the following (all must already be legal moves):• Move their king to a safe square• Move a piece to block the attack• Capture the attacking pieceThis is because otherwise, the player would lose their king on the next turn, and therefore lose the game. If none of these possibilities are available, then the player has been checkmated – there is no move available to them that would save their king, and they have lost.When check occurs, the king’s square is highlighted in dark red, and the message “Check!” appears in the right sidebar. If a player attempts to make an otherwise legal move that doesn’t protect their king, display a message on the right sidebar: “You must defend your king!”, and the highlighted cell the king is on will flash 3 times with a duration of 0.5 seconds each.A player cannot make a move that would result in their king coming under attack. This could be any of either:• Moving the king to a square which is under attack by the opponent• Moving a piece that is blocking an attack on their king by the opponent (this piece is said to be ‘pinned’)Illegal moves due to check or pins should not be highlighted as blue tiles when selecting a piece to potentially move it – only legal moves should be highlighted.Computer AI movementThe way the computer player determines moves is up to you. It can be as simple as choosing a move randomly out of all available legal moves. However, you should try and make it at least a bit intelligent. For example, here is guidance on some basic rules you might want to have:• Capture a piece if the piece’s value is higher than the capturing piece, and if multiple such options exist, choose the one with the highest differenceFigure 12: The black king is in check due to the white chancellor. Blackcannot move their king, their only option is to move their General or Amazon to block (assuming there is no piece off-screen that can capturethe white chancellor).Figure 13: The selected pawn is pinned by the archbishop, so cannot move. However if the archbishop was one space closer to it diagonally, then the pawn would be able to capture the archbishop but not move straight forward. If the king was on the square one space below where it currently is, then the camel would be pinned by the bishop.INFO1113Page 7 of 11• If a piece is threatened to be captured by a piece of lower value (or any piece if the threatened one is undefended), move it• Prefer to only move to squares that are not under attack by a piece of lower value (or even a piece of higher or equal value if the square is undefended) – let’s call these ‘safe squares’• If possible, attack the opponent’s king or a square adjacent to it if it’s not already under attack• If possible, checkmate the opponent’s king• If all else fails, choose a random move (prefer safe squares, but it’s possible none may be available)Win and lose conditionsThe game ends when either one player runs out of time, or their king is checkmated. Then other player wins.If the human player wins by checkmate, display a message saying “You won by checkmate” in the right sidebar. If the human player wins due to the timer, display instead “You won on time”.If the human player loses by checkmate, display a message saying “You lost by checkmate” in the right sidebar. If instead the cause was the timer, display “You lost on time”.The player can also resign the game by pressing ‘e’ on the keyboard. The game ends and the message “You resigned” is displayed in the right sidebar.When the game ends, the board remains intact and frozen so that the player cannot make any moves (but may restart the game with the key press ‘r’). If checkmate occurred, the board should highlight the king of the checkmated player in red and the pieces contributing to checkmate in orange. Pieces contributing to checkmate are defined as a piece that is either attacking the king or one of the empty squares adjacent to it, or defending a piece that the king could otherwise capture. For each such square, there should only be one piece highlighted.If there are no legal moves for a player, then the game is considered a draw and enters the end state. Display the message “Stalemate – draw”.ApplicationYour application will need to adhere to the following specifications:• The window must have dimensions 672x792• The game must maintain a frame rate of 60 frames per second. • Your application must be able to compile and run on any the university lab machines (or Ubuntu VM) using gradle build & gradle run. Failure to do so, will result in 0% for Final Code Submission.• Your program must not exhibit any memory leak. Figure 14: The white king is checkmated. The contributing pieces are the archbishop and two pawns.INFO1113Page 8 of 11• You must use the processing library (specifically processing.core and processing.data), you cannot use any other framework such as javafx, awt or joglYou have been provided a /resources folder which your code can access directly (please use a relative path). These assets are loadable using the loadImage method attached to the PApplet type. Please refer to the processing documentation when loading and drawing an image. You may decide to modify these sprites if you wish to customise your game. You will be required to create your own sprites for any extensions you want to implement.ExtensionThe extension is worth 2 marks maximum. For an extension, you can choose to implement one of the following:• New piece type with different movement and/or special behaviour• Start menu to select options without having to change the config file• More complex computer AI (specify difficulty in config?)• Option for 2-player in config (two human players)• Option for fog of war chess in config (Tiles not able to be moved to are greyed out. The onlypieces of the opponent’s that are visible are those which are present on tiles available to be moved to. Game ends upon king capture.)• Sound effects• Expandable resizable board (drag corners to change game resolution)• More pawn promotion options rather than just promote to queen – user can choose while ingame• Allow pre-moves (and/or drag and drop pieces rather than just click to move)• Allow different types of new configurable pieces (combinations) within the json config file, and what their symbol would be in the layout• Multiple levels specified in the config for the purpose of solving chess puzzles / problems.OR, a feature you come up with which is of a similar or higher level of complexity (ask your tutor)Please ensure you submit a config and level layout file with the features of your extension, and ensure the extension doesn’t break any of the default behaviour. Also, describe your extension functionality in the report.INFO1113Page 9 of 11Marking Criteria (18%)Your final submission is due on Sunday 14 May at 11:59PM. To submit, you must upload your build.gradle file and src folder to Ed. Please also include sample config and layout files that you have tested with your program to ensure it works. Do NOT submit the build folder (unless you only include the build/reports/ folder which contains the results of your testing and code coverage). Ensure src is in the root directory with the other files, and not part of a zip, then press MARK. Submit your report and UML to canvas.A demo of your assignment will be conducted during labs in week 12 where you will demonstrate the features you have created to your tutor.Final Code Submission and Demo (10%)You will need to have implemented and satisfied requirements listed in this assignment. Make sure you have addressed the following and any other requirements outlined previously.• Window launches and shows checkerboard pattern.• Configuration file is correctly read in – timers display correctly• Map loads and pieces are displayed in correct positions• Piece colour for player and computer is correct• Pieces are controlled by mouse clickso A piece can be selected – green highlight appearso Potential moves show in blue highlights, or red for potential captureso Clicking on a highlighted blue/red cell cause the selected piece to move to that locationo Captured pieces are deleted properly• Pieces move correctly according to the table of their movement• Piece movement – is smooth and correct speed• If a move causes the opponent’s king to come under attack, display “Check!” and highlight the king’s tile in dark red.• While the king is in check, only moves to save the king are allowed:o Capture the attacking pieceo Move a piece to blocko Move the king to a safe square• A move that causes your own king to be in check is not allowed:o Moving the king to a square that is under attacko Moving a pinned piece that was blocking an attack on the king• Special moves: Pawn can move two squares initially, Castling, Pawn promotion to queen on the 8th rank (ie. when passing the halfway point)• Computer AI moves automatically after the player makes their move• Computer AI only makes legal moves• Game ends if either player runs out of time – message is displayed correctly• Game ends if either player is checkmated – message is displayed correctly• Pieces contributing to checkmate have their tiles highlighted in red• Player can resign if they want to by pressing ‘e’• Timer counts down and increments according to config after a move is made• Ensure that your application does not repeat large sections of logic• Ensure that your application is bug-freeINFO1113Page 10 of 11Testcases (3%)During development of your code, add testcases to your project and test as much functionality as possible. You will need to construct unit test cases within the src/test folder using JUnit. To test the state of your entities without drawing, implement a simple loop that will update the state of each object but not draw the entity. Ensure your test cases cover over 90% of execution paths (Use jacoco in your gradle build) Ensure your test cases cover common cases. Ensure your test cases cover edge cases. Each test case must contain a brief comment explaining what it is testing. To generate the testing code coverage report with gradle using jacoco, run “gradle test jacocoTestReport”.Design, Report, UML and Javadoc (3%)You will need to submit a report that elaborates on your design. This will include an explanation of any object-oriented design decisions made (such as reasons for interfaces, class hierarchy, etc) and anexplanation of how the extension has been implemented. This should be no longer than 500 words. Thisreport will be submitted through Canvas.You will need to submit a UML diagram in PDF form to Canvas to provide a brief graphical overview of your code design and use of Object Oriented Principles such as inheritance and interfaces. Markers will use this to determine whether you have appropriately used those principles to aid you in your design, as well as figure out whether more should have been done. A general guideline is that markers will be looking for some use of inheritance or interfaces, how extensible the code is, and penalising repeated code. Note that you should not simply use a UML generator from an IDE such as Eclipse, as they typically do not produce diagrams that conform to the format required. We suggest using software such as LucidChart or draw.io for making your diagrams.Your code should be clear, well commented and concise. Try to utilise OOP constructs within your application and limit repetitive code. The code should follow the conventions set out by the Google Java Style Guide. As part of your comments, you will need to create a Javadoc for your program. This will be properly covered in week 11 but the relevant Oracle documentation can be found here.Report, UML and OO design: 2%Javadoc, comments, style and readability: 1%Extension (2%)Implement an extension as described above. Partial marks may be awarded if you choose a more limited extension or it is partially completed. Please specify what extension you decided to implement within your report.Suggested TimelineHere is a suggested timeline for developing the project. Note that it is released on April 3 (start of week 7) and due May 14 (end of week 11).Week 7: Familiarise yourself with gradle and processing, utilising the processing Javadoc and week 8 supplementary lecture. Identify opportunities to utilise Object Oriented Design principles such as inheritance and interfaces and begin to plan a design for the codebase with regards to the classes that you will need to make. Make a rough UML diagram for your design that you can base your codebase from.INFO1113Page 11 of 11Week 8: Begin writing the actual code for the program. Start small, for example by initially creating the board layout and pieces, then gradually add more elements. At the end of the week, you should have loading in the board and piece movement finished, as well as some sprite management. If confident, use Test Driven Development (writing test cases at same time as writing the code). Conduct a large amount of user testing to ensure the initial mechanics work as expected. Weeks 9-10: Develop more gameplay features, such as check, checkmate, special moves, and the computer AI. Sprite management should be streamlined at this point. You should have a fairly high code coverage for your test cases at this stage. If you are noticing any questionable design decisions, such as God classes or classes that are doing things they logically should not be doing, this is the time to refactor your code. Think about what extension you want to make and start to implement it.Week 11: Finish developing the remaining features for your program, notably the configuration file, and timers. Additionally, finish writing your testing suite. Create the UML and Javadoc for the program. Fix any remaining bugs that your code exhibits. Submit your code to Ed (by uploading the entire project and pressing MARK) and submit your UML to Canvas in PDF form.Week 12: Demonstrate the completed program to your tutor during the week 12 lab. They will check each criteria item has successfully been completed, and may ask you questions about how you implemented it to test your understanding.Academic DeclarationBy submitting this assignment you declare the following: I declare that I have read and understood the University of Sydney Student Plagiarism: Coursework Policy and Procedure, and except where specifically acknowledged, the work contained in this assignment/project is my own work, and has not been copied from other sources or been previously submitted for award or assessment. I understand that failure to comply with the Student Plagiarism: Coursework Policy and Procedure can lead to severe penalties as outlined under Chapter 8 of the University of Sydney By-Law 1999 (as amended). These penalties may be imposed in cases where any significant portion of my submitted work has been copied without proper acknowledgment from other sources, including published works, the Internet, existing programs, the work of other students, or work previously submitted for other awards or assessments. I realise that I may be asked to identify those portions of the work contributed by me and required to demonstrate my knowledge of the relevant material by answering oral questions or by undertaking supplementary work, either written or in the laboratory, in order to arrive at the final assessment mark. I acknowledge that the School of Computer Science, in assessing this assignment, may reproduce it entirely, may provide a copy to another member of faculty, and/or communicate a copy of this assignment to a plagiarism checking service or in-house computer program, and that a copy of the assignment may be maintained by the service or the School of Computer Science for the purpose of future plagiarism checking. ...

May 5, 2023 · 20 min · jiezi

关于算法:每日一题x-的平方根

69. x 的平方根关键词:袖珍计算器算法、二分查找、牛顿迭代题目起源:69. x 的平方根 - 力扣(Leetcode) 题目形容 T袖珍计算器算法 T二分查找 T牛顿迭代给你一个非负整数 x ,计算并返回 x 的 算术平方根 。 因为返回类型是整数,后果只保留 整数局部 ,小数局部将被 舍去 。 留神:不容许应用任何内置指数函数和算符,例如 pow(x, 0.5) 或者 x ** 0.5 。 输出:x = 4输入:2输出:x = 8输入:2数据范畴 0 <= x <= 2^31 - 1袖珍计算器算法「袖珍计算器算法」是一种用指数函数和对数函数代替平方根函数的办法。 依据√x=e1/2lnx,从而失去√x的值。因为浮点数的值是不准确的,所以后果可能存在差一谬误,须要增加额定判断。 int mySqrt(int x) { if (!x)return x; int res = exp(0.5 * log(x)); return (long long) (res + 1) * (res + 1) <= x ? res + 1 : res;}工夫复杂度:O(1) ...

May 5, 2023 · 1 min · jiezi

关于算法:COMP-328-线性表达式

University of Liverpool Continuous Assessment COMP 328In this assignment, you are asked to implement a linear algebra operation that is at the heartof many computations we do. You do not need to have previously studied linear algebrasince this document explains the operation in detail. You are encouraged to use your sparetime in your labs to work on this assignment. The teaching team would be happy to offerclarifications in the labs/lectures/otherwise.1 Two-dimensional Box stencilsThis is a generalised two-dimensional version of the stencil operation we discussed in class. ...

May 5, 2023 · 9 min · jiezi

关于算法:每日一题摘水果

2106. 摘水果关键词:滑动窗口、二分查找、前缀和题目起源:2106. 摘水果 - 力扣(Leetcode) 题目形容 T滑动窗口 T二分查找 T前缀和在一个有限的 x 坐标轴上,有许多水果散布在其中某些地位。给你一个二维整数数组 fruits ,其中 fruits[i] = [positioni, amounti] 示意共有 amounti 个水果搁置在 positioni 上。fruits 曾经按 positioni 升序排列 ,每个 positioni 互不雷同 。 另给你两个整数 startPos 和 k 。最后,你位于 startPos 。从任何地位,你能够抉择 向左或者向右 走。在 x 轴上每挪动 一个单位 ,就记作 一步 。你总共能够走 最多 k 步。你每达到一个地位,都会摘掉全副的水果,水果也将从该地位隐没(不会再生)。 返回你能够摘到水果的 最大总数 。 输出:fruits = [[2,8],[6,3],[8,6]], startPos = 5, k = 4输入:9输出:fruits = [[0,9],[4,1],[5,7],[6,2],[7,4],[10,9]], startPos = 5, k = 4输入:14输出:fruits = [[0,3],[6,4],[8,5]], startPos = 3, k = 2输入:0数据范畴1 <= fruits.length <= 105fruits[i].length == 20 <= startPos, positioni <= 2 * 105对于任意 i > 0 ,positioni-1 < positioni 均成立(下标从 0 开始计数)1 <= amounti <= 1040 <= k <= 2 * 105滑动窗口无论如何,最初摘到的水果肯定位于区间[l, r]内,且地位l和r上都有水果。思考区间[l, r]是如何造成的: ...

May 4, 2023 · 2 min · jiezi

关于算法:每日一题检查替换后的词是否有效

1003. 查看替换后的词是否无效关键词:字符串匹配题目起源:1003. 查看替换后的词是否无效 - 力扣(Leetcode) 题目形容给你一个字符串 s ,请你判断它是否 无效 。 字符串 s 无效 须要满足:假如开始有一个空字符串 t = "" ,你能够执行 任意次 下述操作将 t 转换为 s : 将字符串 "abc" 插入到 t 中的任意地位。模式上,t 变为 tleft + "abc" + tright,其中 t == tleft + tright 。留神,tleft 和 tright 可能为 空 。如果字符串 s 无效,则返回 true;否则,返回 false。 输出:s = "aabcbc"输入:true解释:"" -> "abc" -> "aabcbc"因而,"aabcbc" 无效。输出:s = "abcabcababcc"输入:true解释:"" -> "abc" -> "abcabc" -> "abcabcabc" -> "abcabcababcc"因而,"abcabcababcc" 无效。输出:s = "abccba"输入:false解释:执行操作无奈失去 "abccba" 。数据范畴1 <= s.length <= 2 * 104s 由字母 'a'、'b' 和 'c' 组成问题剖析本题与括号匹配(20. 无效的括号 - 力扣(Leetcode))相似,可应用栈来求解。 ...

May 3, 2023 · 2 min · jiezi

关于算法:每日一题相等的有理数

972. 相等的有理数关键词:数学题目起源:972. 相等的有理数 - 力扣(Leetcode) 题目形容 T数学给定两个字符串 s 和 t ,每个字符串代表一个非负有理数,只有当它们示意雷同的数字时才返回 true 。字符串中能够应用括号来示意有理数的重复部分。 有理数 最多能够用三个局部来示意:整数局部\<IntegerPart>、小数非重复部分 \<NonRepeatingPart>和小数重复部分 \<(>\<RepeatingPart><)>。数字能够用以下三种办法之一来示意: <IntegerPart>例: 0 ,12 和 123 <IntegerPart><.><NonRepeatingPart>例: 0.5 , 1. , 2.12 和 123.0001 <IntegerPart><.><NonRepeatingPart><(><RepeatingPart><)>例: 0.1(6) , 1.(9), 123.00(1212) 十进制开展的重复部分通常在一对圆括号内示意。例如: 1 / 6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66) 输出:s = "0.(52)", t = "0.5(25)"输入:true解释:因为 "0.(52)" 代表 0.52525252...,而 "0.5(25)" 代表 0.52525252525.....,则这两个字符串示意雷同的数字。输出:s = "0.1666(6)", t = "0.166(66)"输入:true输出:s = "0.9(9)", t = "1."输入:true解释:"0.9(9)" 代表 0.999999999... 永远反复,等于 1 。"1." 示意数字 1,其格局正确:(IntegerPart) = "1" 且 (NonRepeatingPart) = "" 。问题剖析因为字符串所代表的值不会超过1e4,故可间接将字符串所示意的值求进去,而后进行比拟。 ...

May 2, 2023 · 1 min · jiezi

关于算法:每日一题T-秒后青蛙的位置

1377. T 秒后青蛙的地位关键词:深度优先题目起源:1377. T 秒后青蛙的地位 - 力扣(Leetcode) 题目形容 T深度优先给你一棵由 n 个顶点组成的无向树,顶点编号从 1 到 n。青蛙从 顶点 1 开始起跳。规定如下: 在一秒内,青蛙从它所在的以后顶点跳到另一个 未拜访 过的顶点(如果它们间接相连)。青蛙无奈跳回曾经拜访过的顶点。如果青蛙能够跳到多个不同顶点,那么它跳到其中任意一个顶点上的机率都雷同。如果青蛙不能跳到任何未拜访过的顶点上,那么它每次跳跃都会停留在原地。无向树的边用数组 edges 形容,其中 edges[i] = [fromi, toi] 意味着存在一条间接连通 fromi 和 toi 两个顶点的边。 返回青蛙在 t 秒后位于指标顶点 target 上的概率。 输出:n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 2, target = 4输入:0.16666666666666666 输出:n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 1, target = 7输入:0.3333333333333333数据范畴1 <= n <= 100edges.length == n - 1edges[i].length == 21 <= ai, bi <= n1 <= t <= 501 <= target <= n问题剖析无向树的终点为1,且青蛙不能往回跳,故题目所说的无向树实际上是一棵有向树。 ...

May 1, 2023 · 2 min · jiezi

关于算法:算法竞赛力扣周赛节选20220430

力扣周赛(节选)2022-04-306404. 将数组清空关键词:树状数组、找法则题目起源:6404. 将数组清空 - 力扣(Leetcode)——力扣第 103 场双周赛第4题 题目形容 T树状数组 T找法则给你一个蕴含若干 互不雷同 整数的数组 nums ,你须要执行以下操作 直到数组为空 : 如果数组中第一个元素是以后数组中的 最小值 ,则删除它。否则,将第一个元素挪动到数组的 开端 。请你返回须要多少个操作使 nums 为空。 问题剖析问题等价于:设一指针p初始指向nums[0],指针p把一直从左往右扫描(扫描到开端则从头开始扫描),每扫描到以后数组的最小值,就将其标记为“删除”,而后持续扫描,直到数组所有元素均被标记为“删除”,求指针总共须要挪动多少步,标记为删除的地位在挪动时间接疏忽。 设上一个最小值的地位为pre,也即上次标记为“删除”的地位为pre,以后最小值的地位为i。 先思考i≥pre的状况,则从pre挪动到i共需i-pre步。又因为 这个i-pr步中,有些地位曾经被删除,挪动时间接被疏忽,不记录到理论步数中;将一个地位标记为“删除”,指针p便会顺移到下一个未被删除的地位,所以指针并不是从pre开始挪动的。设理论须要挪动k步,则k=(i-pre)-[pre+1..i]中被删除的地位-1。 再思考i<pre的状况,则从pre挪动到i共需(n-pre)+1+(i-1)。同样须要思考被删除的地位和指针的顺移,则理论挪动步数k=(n-pre)+1+(i-1)-[pre+1..n]被删除的地位-[1..i]被删除的地位-1。 以上只思考到挪动的次数,题目还需加上删除操作的次数,故答案最初须要+n。 通过剖析发现,须要保护区间被删除的地位的个数,因此想到树状数组(或者线段树)。 代码实现// 树状数组模板const int N = 1e5 + 5;int tr[N], n;int lowbit(int x) { return x & -x;}void add(int x) { for (int i = x; i <= n; i += lowbit(i))tr[i]++;}int query(int x) { int res = 0; for (int i = x; i; i -= lowbit(i))res += tr[i]; return res;}long long countOperationsToEmptyArray(vector<int> &nums) { n = nums.size(); int idx[n]; iota(idx, idx + n, 1); // 从1开始 sort(idx, idx + n, [&](int &i, int &j) { return nums[i - 1] < nums[j - 1]; }); long long res = n; // 删除操作执行n次 int pre = 0; // 上一个被删除的数的地位 for (int i: idx) { if (i >= pre) { // 从pre挪动到i,并且跳过已删除的数 res += (i - pre) - (query(i) - query(pre)) - 1; } else { // 从pre挪动到n,从1挪动到i,并且跳过已删除的数 res += (n - pre + i) - (query(n) - query(pre)) - (query(i)) - 1; } add(i), pre = i; } return res;}工夫复杂度:O(nlog(n)) ...

April 30, 2023 · 4 min · jiezi

关于算法:每日一题寻找两个正序数组的中位数

4. 寻找两个正序数组的中位数关键词:二分查找、数组划分题目起源:4. 寻找两个正序数组的中位数 - 力扣(Leetcode) 题目形容 T二分查找 T数组划分给定两个大小别离为 m 和 n 的正序(从小到大)数组 nums1 和 nums2。请你找出并返回这两个正序数组的 中位数 。 算法的工夫复杂度应该为 O(log (m+n)) 。 输出:nums1 = [1,3], nums2 = [2]输入:2.00000解释:合并数组 = [1,2,3] ,中位数 2输出:nums1 = [1,2], nums2 = [3,4]输入:2.50000解释:合并数组 = [1,2,3,4] ,中位数 (2 + 3) / 2 = 2.5数据范畴nums1.length == mnums2.length == n0 <= m <= 10000 <= n <= 10001 <= m + n <= 2000-106 <= nums1[i], nums2[i] <= 106二分查找题目要求工夫复杂度为O(log(m+n)),且数组有序,可采纳二分求解,具体做法如下: 当m+n为奇数时,题目等价于找到第k小的元素,当m+n为偶数时,题目等价于找到第k和k+1小的数。故,工作就是找到第k小的数,若m+n为偶数,则在第k小的数前面再思考一个数即可。 设i=0,j=0,ti,tj,i示意数组A的起始思考地位,也即A以后思考A[i..m-1],相似的,B以后思考B[j..n-1],ti和tj别离示意A和B的下一个起始思考地位令ti = i+k/2,tj = j+k/2,ti、tj别离不能超过m、n对于数组A[i..m-1]、B[j..n-1],思考A[ti-1]和B[tj-1] ...

April 30, 2023 · 3 min · jiezi

关于算法:每日一题最长字符串链

1048. 最长字符串链关键词:动静布局、线性dp题目起源:1048. 最长字符串链 - 力扣(Leetcode) 题目形容 T动静布局 T线性dp给出一个单词数组 words ,其中每个单词都由小写英文字母组成。 如果咱们能够 不扭转其余字符的程序 ,在 wordA 的任何中央增加 恰好一个 字母使其变成 wordB ,那么咱们认为 wordA 是 wordB 的 前身 。 例如,"abc" 是 "abac" 的 前身 ,而 "cba" 不是 "bcad" 的 前身词链是单词 [word_1, word_2, ..., word_k] 组成的序列,k >= 1,其中 word1 是 word2 的前身,word2 是 word3 的前身,依此类推。一个单词通常是 k == 1 的 单词链 。 从给定单词列表 words 中抉择单词组成词链,返回 词链的 最长可能长度 。 输出:words = ["a","b","ba","bca","bda","bdca"]输入:4解释:最长单词链之一为 ["a","ba","bda","bdca"]输出:words = ["xbc","pcxbcf","xb","cxbc","pcxbc"]输入:5解释:所有的单词都能够放入单词链 ["xb", "xbc", "cxbc", "pcxbc", "pcxbcf"].输出:words = ["abcd","dbqca"]输入:1解释:字链["abcd"]是最长的字链之一。["abcd","dbqca"]不是一个无效的单词链,因为字母的程序被扭转了。数据范畴1 <= words.length <= 10001 <= words[i].length <= 16words[i]` 仅由小写英文字母组成问题剖析类比最长递增子序列,设f(s)=以字符串s结尾的词链的最长长度,则f(s)=max{ f(ps)+1 },其中,ps为s去除一个字符后失去的子串。 ...

April 27, 2023 · 1 min · jiezi

关于算法:基于Spark图计算的社会网络分析系统

拜访【WRITE-BUG数字空间】_[内附残缺源码和文档]本文在 Spark 及图计算引擎 GraphX 的根底上,设计并实现一套用于顶点分 析的社交网络分析零碎,为应用 Spark 进行大规模社交网络的顶点剖析提供具体 接口,包含社交网络的图模型构建、顶点重要度估值、顶点间门路的计算、顶点 分组等接口,并对计算结果进行了肯定水平上的可视化展示。次要工作包含两个 方面:第一是构建图和数据可视化的实现;第二是具体的顶点剖析接口的实现。1零碎相干技术1.1通用并行框架 SparkSpark 是由加州大学伯克利分校 AMP 实验室所开源的类 Hadoop MapReduce 的通用并行框架,Spark 领有 Hadoop MapReduce 所具备的长处;但不同于 MapReduce 的是 Job 两头输入后果能够保留在内存中,从而不再须要读写 HDFS, 因而 Spark 能更好地实用于数据挖掘与机器学习等须要迭代的MapReduce 的算法。Spark 是一种与 Hadoop 类似的开源集群计算环境,然而两者之间还存在一些不同之处,这些有用的不同之处使 Spark 在某些工作负载方面体现得更加优越,换句话说,Spark 启用了内存散布数据集,除了可能提供交互式查问外,它还能够优化迭代工作负载。Spark 是在 Scala 语言中实现的,它将 Scala 用作其应用程序框架。与Hadoop 不同,Spark 和 Scala 可能严密集成,其中的 Scala 能够像操作本地汇合对象一样轻松地操作分布式数据集。只管创立 Spark 是为了反对分布式数据集上的迭代作业,然而实际上它是对 Hadoop 的补充,能够在 Hadoop 文件系统中并行运行,通过名为 Mesos 的第三方集群框架能够反对此行为。RDD(Resilient Distributed Datasets),弹性分布式数据集,是分布式内存的一个抽象概念,RDD 提供了一种高度受限的共享内存模型,即 RDD 是只读的记录分区的汇合,只能通过对其余 RDD 执行确定的转换操作(如 map、join 和 group by)而创立,然而这些限度使得实现容错的开销很低。对开发者而言,RDD 能够看作是 Spark 的一个对象,它自身运行于内存中,如读文件是一个 RDD,对文件计算是一个 RDD,后果集也是一个 RDD ,不同的分片、数据之间的依赖、key-value 类型的 map 数据都能够看做 RDD。1.2图计算框架 GraphXSpark GraphX 是一个分布式图解决框架,Spark GraphX 基于 Spark 平台提供对图计算和图开掘简洁易用的而丰富多彩的接口,极大的不便了大家对分布式图解决的需要。家喻户晓,社交网络中人与人之间有很多关系链,例如 Twitter、Facebook、微博和微信等,这些都是大数据产生的中央都须要图计算,当初的图解决根本都是分布式的图解决,而并非单机解决。Spark GraphX 因为底层是基于 Spark 来解决的,所以人造就是一个分布式的图解决零碎。图的分布式或者并行处理其实是把图拆分成很多的子图,而后别离对这些子图进行计算,计算的时候能够别离迭代进行分阶段的计算,即对图进行并行计算。1.3动静图形组件 GraphStreamGraphStream 是一个 Java 类库,用于治理动静图形。它由一个面向对象的 API 组成,可能以简便、疾速的形式在一张图形中增加边缘和节点,并让它们进行演变[15]。1.4函数式编程语言 ScalaScala 是一门多范式的编程语言,一种相似 java 的编程语言,设计初衷是实现可伸缩的语言,并集成命令式编程、面向对象编程和函数式编程的各种个性。Scala 有几项要害个性表明了它的面向对象的实质。例如,Scala 中的每个值都是一个对象,包含根本数据类型(即布尔值、数字等)在内,连函数也是对象。另外,类能够被子类化,而且 Scala 还提供了基于 mixin 的组合(mixin-based com position)。与只反对单继承的语言相比,Scala 具备更宽泛意义上的类重用。Scala 容许定义新类的时候重用“一个类中新增的成员定义(即相较于其父类的差别之处)”, Scala 称之为 mixin 类组合。Scala 还蕴含了若干函数式语言的要害概念,包含高阶函数(Higher-Order Function)、部分套用(Currying)、嵌套函数(Nested Function)、序列解读(Se quence Comprehensions)等等。Scala 是动态类型的,这就容许它提供泛型类、外部类、甚至多态办法(Po lymorphic Method)。另外值得一提的是,Scala 被特意设计成可能与 Java 和.NE T 互操作。Scala 以后版本还不能在.NET 上运行,但依照打算未来能够在.NET 上运行。Scala 能够与 Java 互操作。它用 scalac 这个编译器把源文件编译成 Java 的 cl ass 文件(即在 JVM 上运行的字节码)。你能够从 Scala 中调用所有的 Java 类库, 也同样能够从 Java 应用程序中调用 Scala 的代码。用 David Rupp 的话来说,它也能够拜访现存的数之不尽的 Java 类库,这让 Java 类库迁徙到 Scala 变得更加容易。 ...

April 25, 2023 · 1 min · jiezi

关于算法:算法竞赛力扣杯春赛个人赛-LCCUP23复盘

力扣杯春赛 - 个人赛 LCCUP'23LCP 72. 补给马车关键词:模仿题目起源:LCP 72. 补给马车 - 力扣(Leetcode) 题目形容 T模仿远征队行将开启未知的冒险之旅,不过在此之前,将对补给车队进行最初的查看。supplies[i] 示意编号为 i 的补给马车装载的物资数量。 思考到车队过长容易被野兽偷袭,他们决定将车队的长度变为原来的一半(向下取整),打算为: 找出车队中 物资之和最小 两辆 相邻 马车,将它们车辆的物资整合为一辆。若存在多组物资之和雷同的马车,则取编号最小的两辆马车进行整合;反复上述操作直到车队长度符合要求。请返回车队长度符合要求后,物资的散布状况。 输出:supplies = [7,3,6,1,8]输入:[10,15]输出:supplies = [1,3,1,5]输入:[5,5]数据范畴2 <= supplies.length <= 10001 <= supplies[i] <= 1000问题剖析察看数据范畴,O(n^2)的工夫复杂度是能够承受的,本题采纳模仿即可。具体做法如下: 合并次数m=n-(n>>1),对于每次合并 扫描一遍数组,找到和最小的相邻两个元素,设为i,j执行合并操作,即a[i]+=a[j];将j标记为不存在,即a[j]=0最初,将残余元素取出返回即可。 工夫复杂度:O(n^2) 空间复杂度:O(n) vector<int> supplyWagon(vector<int> &supplies) { int n = supplies.size(), m = n - (n >> 1); // m次合并 while (m--) { // 找到和最小的相邻两个元素 int sum = INT_MAX, mi, mj; for (int i = 0, j; i < n; i = j) { // 相邻两个元素i和j while (i < n && supplies[i] == 0)i++; j = i + 1; while (j < n && supplies[j] == 0)j++; // 比拟和 if (j < n && supplies[i] + supplies[j] < sum) { sum = supplies[i] + supplies[j], mi = i, mj = j; } } // 合并 supplies[mi] += supplies[mj], supplies[mj] = 0; } // 将残余元素取出 vector<int> ans; for (const auto &e: supplies) { if (e != 0)ans.push_back(e); } return ans;}LCP 73. 探险营地关键词:字典树、STL题目起源:LCP 73. 探险营地 - 力扣(Leetcode) ...

April 25, 2023 · 10 min · jiezi

关于算法:鹅厂万人热议|如何理解业务系统的复杂性

腾小云导读 业务零碎复杂性始终是令开发者头痛的问题。简单的不是减少一个需要须要消耗多少工夫,而是在减少一个需要后带来的蝴蝶效应:其它性能会不会受到影响、要如何去找到这些影响,最终如何实现零碎失常运行......性能之间隐秘减少的耦合、不可避免的代码腐化在导致业务复杂性减少。大家都在说的软件开发提效到底在提什么?程序员日常工作中应该如何晋升开发效率?麻利开发、瀑布流式开发孰是孰非?欢送浏览。 看目录,点珍藏 1 业务背景与指标 2 软件开发提效 3 业务零碎简单的根本原因 3.1 性能之间荫蔽减少的耦合 3.2 不可避免的代码腐化 4 总结 01、 业务背景与指标我仍然十分清晰地记得去年的某个时候,我所在团队 Leader 曾讲过一段话: “我担心的是,咱们团队规模的扩张并不是因为用户规模或营收规模的增长,仅仅是因为咱们有越来越多的事件要做导致人手紧缺。” 这个担心置信很多开发者都能感同身受,兴许你所在的团队也正面临同样的问题:为什么用户规模或者营收规模不减少,事件反而越来越多呢?呈现这个景象的起因其实也不难想到:因为业务规模停滞或者下滑,产品侧不得不做更多的事件来止住颓势甚至想要以此力挽狂澜。要么是一直地拓展产品的边界,在一个利用里退出更多的性能,也就是所谓的交付更多的用户价值,从而吸引更多潜在用户;要么是一直地优化现有性能,例如通过排版来从心理学角度进步用户停留时长和点击率,亦或是进一步优化产品的交互流程,也就是所谓的晋升用户体验,从而晋升口碑,巩固用户根本盘。 这些要做的事件对应到开发侧,那天然就是有更多的需要。 一个需要不能晋升指标,那就要两个;一个策略成果不迭预期,那下次就得 A、B 两个策略同时做试验。看起来,这势必会加剧团队开发人员的压力。 大版本上线前同时赶多个需要.gif 所以 Leader 心愿开发团队可能晋升效率,晋升需要的吞吐率。但问题是,需要的增多,就肯定要随同着开发团队人力的增多吗? 对其余行业来说,这个问题的答案是不言而喻的。你要修更多的房子,势必要更多的工人;你要送更多的物资,势必须要更多的车;你要打赢一波团战,势必须要更多的队友…然而这个问题到了软件行业,答案却变得含糊了。 因为软件行业有个特有的性质——简直 0 老本的可复用性。某项性能他人实现了,那其他人就能立即拿过去用。这对于修建等行业,那真的就是降维打击。即便工地要修 10 栋截然不同的宿舍楼,它也得一栋一栋地修,每一栋的人力和物力都是一样的。而对于软件行业,你只须要修一栋,剩下的 9 栋就是 0 老本的复制粘贴。 那对于一个在软件工程上有谋求的团队来说,大家不是始终在谋求可复用吗?后期开发了那么多需要和性能,想必也积淀了十分多的能力吧?如果有那么多能力能够 0 老本复用,那后续是不是开发效率会大大提高? 因而对很多人来说,现实中的软件开发团队,随着性能的一直增多,开发成本应该至多放弃一个线性的关系。而且如果引入了一些重大的新技术,开发成本的线性增长率还会更低。 这种 functionalities-cost 的线性关系对很多团队来说是司空见惯的。在很多团队的项目管理中,每次迭代的需要数量都应不少于上次迭代,否则就须要复盘。而对于开发效率的晋升,则能够用本次迭代的需要数量较之前有多少比例的晋升来判断。如果团队有一个好的技术架构和正当的模块划分计划,思考到可复用性能够缩小老本,functionalities-cost 的关系会更平缓。相似这样: 然而,事实可能会给你惨重一击。如果你去问问一线的开发人员,他们可能会通知你实在的感触是这样的: 随着向零碎中增加越来越多的性能,实现每个性能会变得越来越艰难而不是越来越简略。复用?根本不存在的。像上图中的绿色线性关系都不太可能实现,更不用说优良架构现实中相似于对数函数的曲线了。 过来 20 年中,软件开发行业中局部人推崇麻利开发,其终极目标也不过是为了谋求上图中的彩色线条这种线性关系——也就是当初很多团队习惯的,每个迭代实现固定数量的需要。在麻利团队看来,你必须要付出很多额定的致力,一直地提取常识和重构,才有可能维持住这种恒定的需要吞吐率。然而事实是很多团队什么都没做,却对这种稳固的吞吐率司空见惯了。到底是麻利开发那一套是画龙点睛,还是 996 太好用了?这是一个值得沉思的问题。 那到底为什么事实世界中的 functionalities-cost 曲线是一个指数型,而不是现实中的线性或者对数型呢?这其实波及到软件模型的基本复杂性问题。在开展讲这个概念之前,咱们先讲一些软件开发的现状。 02、软件开发提效过来一年,许多的公司都在鼎力推动降本增效。个别降本增效了解为降本和增效两件事件,但过来一年大部分公司大部分还是降本。兴许作为开发者的你,过来的一年被拉进了有数的“老本归属群”,收到了来自中台的各种账单。对中台来说,的确是降本了,不过这些降掉的本又加到了业务方头上。 所以项目组外部必定也要做各种降本,比方更精细化地应用服务器和存储资源,投入更多精力去关注云上账单,该省的省。在需要的技术评审环节加上老本预估,让那些提极低的 ROI 需要的产品经理急流勇退。下面这些伎俩都是降本。 更进一步地讲,就是缩小不必要的节约。这种缩小节约的降本伎俩在短期很有用,但很快就会达到收益天花板。更大的收益还是要晋升效率,但增效相干的工作,兴许你感知到的是寥寥无几。 其实说到软件开发的增效,大多数人首先想到的就是工程效力(EP),也就是开发工具。利用各种好用的工具,来晋升写代码、构建服务以及协同开发的效率。例如领有能够极速解决几百 G 大仓的代码托管平台,领有高度可配置的流水线来自动化一些日常繁琐的构建工作,有良好设计的 RPC 开发框架,还有先进的可观测平台,还有有数其余的效力平台…… ...

April 25, 2023 · 3 min · jiezi

关于算法:每日一题最大人工岛

827. 最大人工岛关键词:深度优先、并查集、枚举题目起源:827. 最大人工岛 - 力扣(Leetcode) 题目形容 T深度优先 T并查集 T枚举给你一个大小为 n x n 二进制矩阵 grid 。最多 只能将一格 0 变成 1 。 返回执行此操作后,grid 中最大的岛屿面积是多少? 岛屿 由一组上、下、左、右四个方向相连的 1 造成。 输出: grid = [[1, 0], [0, 1]]输入: 3解释: 将一格0变成1,最终连通两个小岛失去面积为 3 的岛屿。输出: grid = [[1, 1], [1, 0]]输入: 4解释: 将一格0变成1,岛屿的面积扩充为 4。输出: grid = [[1, 1], [1, 1]]输入: 4解释: 没有0能够让咱们变成1,面积仍然为 4。数据范畴n == grid.lengthn == grid[i].length1 <= n <= 500grid[i][j] 为 0 或 1问题剖析连通块问题可应用深搜来打标记,也能够应用并查集来保护,以下就采纳并查集来解决本题。 首先遍历一遍矩阵,当相邻两格均为岛屿时,认为二者连通,用并查集来保护二者的连通性。 枚举每一个网格的翻转(前提是能翻转),将其退出图中,其是否能使得其上下左右的连通块(或其中几个)相连,留神相似于上方连通块与左方连通块原本就相连的状况。 工夫复杂度:O(n^2),find函数的工夫可认为是O(1)的。 ...

April 25, 2023 · 3 min · jiezi

关于算法:两种常用排序算法的使用

一、疾速排序(Quick Sort)疾速排序采纳分治法。首先从数列中挑出一个元素作为两头值。顺次遍历数据,所有比两头值小的元素放在右边,所有比两头值大的元素放在左边。而后按此办法对左右两个子序列别离进行递归操作,直到所有数据有序。最现实的状况是,每次划分所抉择的两头数恰好将以后序列简直等分(平均排布),整个算法的工夫复杂度为O(n logn)。 最坏的状况是,每次所选的两头数是以后序列中的最大或最小元素(正序和逆序都是最坏),整个排序算法的工夫复杂度为O(n²)。 均匀工夫复杂度为O(n logn),空间复杂度为O(logn),是一种不稳固的排序算法。 附算法实现源码: //疾速排序template <class T>int Partition(T data[],int left,int right){ T pivot=data[left]; while(left<right) { while(left<right&&data[right]>pivot) right--; data[left]=data[right]; while(left<right&&data[left]<=pivot) left++; data[right]=data[left]; } data[left]=pivot; return left;}template <class T>void QuickSort(T data[],int left,int right){if(left<right){ int p=Partition(data,left,right); QuickSort(data,left,p-1); QuickSort(data,p+1,right);}}二、抉择排序(Selection Sort)遍历所有数据,先在数据中找出最大或最小的元素,放到序列的起始;而后再从余下的数据中持续寻找最大或最小的元素,顺次放到序列中直到所有数据有序。原始数据的排列程序不会影响程序消耗工夫O(n²),绝对费时,不适宜大量数据排序。 均匀工夫复杂度为O(n²),空间复杂度为O(1),是一种不稳固的排序算法。 附算法实现源码: //抉择排序template <class T>void SelectionSort(T data[],int n){ for(int i=1;i<n;i++) { int k=i-1; for(int j=i;j<n;j++) { if(data[j]<data[k]) { k=j; } } if(k!=i-1) { T t=data[k]; data[k]=data[i-1]; data[i-1]=t; } }}

April 24, 2023 · 1 min · jiezi

关于算法:CNSCC160Speech处理算法问题

CNSCC.160 – Focus on Speech ProcessingPractical Session for Week 6Audio Data and Quantization Effects using MATLABIn previous practical sessions, you familiarised yourselves with the MATLAB environment.You are now expected to know how to operate MATLAB and how to use basic commands ofMATLAB. This practical session focuses on audio signals instead of images and will help youto learn some basic operations for speech and audio data, including how to read/writeaudio files, play their audio content and plot figures.Basic MATLAB Operations for Speech and Audio DataIn these notes, all commands that can be typed in MATLAB are typed in a plain font. Youcan cut and paste commands from this document directly into the MATLAB commandwindow. Alternatively you can create your own MATLAB command file with:edit exer1.mYou can then type or cut-and-paste in commands. Save your work and then run the contentsof the file at the MATLAB prompt:exer1For more information on any MATLAB commands, you can access the help pages eitherfrom the main menu, or by typing “doc <MATLAB command>” or “help <MATLABcommand>. For example, type the following line if you want to learn about the syntax of theMATLAB command “plot”:doc plotIn order to read a speech/audio data file, use “audioread()” i.e.[Y, sr] = audioread(filename);This loads the WAV file specified by the string variable <filename>, returning the sampleddata in variable Y. Append the “.wav” extension. The command also returns the sample rate(sr) in samples/second or, equivalently, Hertz (Hz).Let us read an audio file called ‘bach16.wav’, which can be downloaded from Moodle. Youwill use the command:[Y,sr] = audioread('bach16.wav');Y MATLAB vector containing the speech/audio data.sr The sampling rate (16,000 Hertz for the Bach file).bach16.wav The filename from which the data is loaded.In the main MATLAB window, use the menu to display the Workspace Window (e.g., go to“Desktop” and select “Workspace”). Alternatively, type the following command at theMATLAB command prompt:whosNote the size (number of samples in) the variable Y.To save data in WAV format, use the command “audiowrite()”, For example, type:audiowrite(Y,sr, 'myfile.wav');where Y and sr are as above and ‘myfile.wav’ is the name of the file where the speech datawill be stored.To listen to the audio/speech (you need headphones or PC speakers), use the command:soundsc(Y, sr);To change the sampling rate of the data use the command:d = resample(Y, p, q);This command is part of Signal Processing Toolbox. It will resample the sequence in vector Yat p/q times the original sampling rate. The result is placed in the output variable d. Bothvariables p and q should be positive integers selected by you. In other words, Y isinterpolated by a factor p and then decimated by a factor q. For example, define:example_vector = [1 2 3 4];and then type:interpolate = resample(example_vector, 3, 1)When the contents of interpolate are displayed, observe that the new vector has threetimes the length of example_vector because p=3 (while q=1). Effectively, two newsamples have been estimated by interpolation and inserted between each original sample.Now, try the following line:decimate = resample(interpolate, 1, 4)and observe that decimate contains only 3 elements, i.e., it has 1/4 of the length of thevector interpolate. In this case, decimate is a rough representation ofinterpolate if a quarter of the samples are required. Remember that if we need tosample at p/q times the original rate, then resample(Y, p, q)generates a betterestimate than resample(Y, p, 1) followed by resample(Y, 1, q).Listen to the resampled data but remember to alter the sampling rate appropriately in thesoundsc() command. For example:soundsc(d,(p/q)*sr);The amplitude of the wav file can be plotted by:plot(Y)The x-axis displays the sample number (which is related to time). The y-coordinate showsthe amplitude of the samples. To change the x-axis from sample number to time, close theprevious figure, calculate the time and plot Y again:time = (1:length(Y))*(1/sr);plot(time, Y);Your plot can be improved by adding labels and a title. To do this, use the followingcommands:title(’WAV File Plot’);xlabel(’Sample Number’);ylabel(’Amplitude’);What to include in the reportExercise 1 (total: 6+6=12 marks)Part 1.a (6 marks) Download the three sample speech WAV files that are available on Moodle(‘speech01.wav’, ‘speech02.wav’ and ‘speech03.wav’). For each of these sample WAV files, read the data into MATLAB, listen to the sample andthen check the size of the loaded data. Given that you can find the sampling rate (sr),what is the time interval between samples (e.g., between Y(1) and Y(2))? What isthe entire duration of each WAV file in seconds? Select one of the sample WAV files (state which). The file contains 3.4 KHz bandwidthspeech sampled at 8 KHz. Read the data into a MATLAB variable called DataA. Perform the following:o Resample DataA to 4 KHz, i.e., use the resample command to reduce the numberof samples by half. Call the resampled data DataB.o Resample DataA to 16 KHz. Call this DataC.o Resample DataB and DataC back to 8 KHz, and produce DataD and DataErespectively. Figure 1 makes this process clearer.o Plot the waveforms of the reproduced DataD and DataE and compare them withthe plot of the original data in DataA.Figure 1: The re-sampling processIn some cases, you will be plotting fewer samples than are in the original data. For thisreason, you may find the following hint useful.time = (1:length(Y))*(1/sr);from_s=1;to_s=500;plot(time(from_s: to_s),Y(from_s:to_s));xlabel(‘Time [Sec]’);ylabel(‘Amplitude’);where from_s is the index of the first sample and to_s is the index of the last sample thatyou wish to plot. The maximum value of to_s is equal to length(Y).Experiment with different values of from_s and to_s. For example, plot all the data, halfthe data as well as data lasting for 0.5 seconds. Select values of from_s and to_s thatgive good comparison between the original and re-sampled data.Part 1.b (6 marks) Listen to DataA, DataD and DataE. Describe and comment on your listening experience and relate this to the NyquistTheorem. Calculate and provide the signal to noise ratio (SNR) between DataA and DataD andthen DataA and DataE using the formula:snr = 10*log10((sum(abs(Original).^2)/sum(abs(Original-Recovered).^2)));In this formula, Original is the data from DataA and Recovered is the data fromDataD and then DataE. You will need to edit the above command to match your choice ofMATLAB variable names for each of the two SNR's required. As before, relate your SNR results to the Nyquist theorem.Introduction to QuantizationIn signal processing, quantization is the process of approximating a continuous range ofvalues (or a very large set of possible discrete values) by a relatively small set of discretesymbols or integer values.This task examines quantization for audio/speech data in MATLAB and explores the impactof quantization on audio/speech data.You are going to use a MATLAB function to alter the quantization levels in a WAV file.Download the file ‘QUAN_demo.m’ from Moodle. At the MATLAB command prompt, type:edit QUAN_demo.mCarefully examine the MATLAB code of this function and work out how the functionperforms the quantization.This function achieves quantization by adjusting the quantizer amplitude range to be thesame as that of the input speech signals.Exercise 2 (total: 5+5+3=13 marks)The function QUAN_demo.m will be implemented in this exercise.Part 2.a (5 marks) Clear all data in the MATLAB workspaceclear all; In the command window call the QUAN_demo.m function as follows:[snr, ori_data, quan_data, sr] = QUAN_demo(3,filename);where filename is one of the speech WAV files (state which file you selected). Listen to the two types of data, the original file and the quantized version with 3 bits persample.soundsc(ori_data, sr);soundsc(quan_data, sr); Comment on the differences you hear.Part 2.b (5 marks) Using the following MATLAB commands, plot the amplitude of the original signal and itsquantized version within a single window:subplot(2,1,1);plot(ori_data);title('Amplitude of Original Signals')xlabel('Sample Number');ylabel('Amplitude');subplot(2,1,2);plot(quan_data);title('Amplitude of quantized Signals');xlabel('Sample Number');ylabel('Amplitude'); Plot the SNR as a function of the number of quantization bits R, where R varies from 1 to ...

April 23, 2023 · 7 min · jiezi

关于算法:ECE-466-matlab问题求解

ECE 466 - SS 2023 - Homework set #7Due Date: 11:59pm - April 28, 2023This homework set is to be done individually. It contains both analytical and MATLABproblems. Analytical problems can be typed or scanned. If scanned, make sure that your writingis legible, and crop any unnecessary edges to reduce file size. In addition to code, MATLABproblems require a report. Your homework should be uploaded on D2L as ONE zip file. The fileshould be named as YourLastName_YourFirstName_HW7.zip. Be sure to include the answersto analytical questions, code you wrote for the MATLAB problems, and the report for theMATLAB problems. Code should be provided in a separate MATLAB (.m) file(s), and shouldexecute. If I’m not able to run your code it will receive 0 points. Documentation on MATLABfunctions can be found via the commands >help functionname or >doc functionname. Makesure to show all your work to get full points.Problem 1. [15 points]In this problem you will show that the Goertzel algorithm can efficientlycompute the DFT for a frequency , but also for ?.When deriving the Goertzel algorithm we used the fact that W?kNN = 1 to derive arecurrence for computing a specific DFT value X[k] for a finite length sequence x[n], n =0, . . . , N ? 1.(a) Using the fact that W kNN = WnNN = 1 show that X[N ? k] can be obtained as theoutput after N iterations of the difference equation depicted in Fig. 1a. That is,show that X[N ? k] = yk[N ].(b) Show that X[N ? k] is also equal to the output after N iterations of the differenceequation depicted in Fig. 1b. Note that the system of Fig. 1b has the same polesas the system for the Goertzel algorithm but the coefficient required to implementthe complex zero is the complex conjugate of the corresponding coefficient of theGoertzel algorithm.Problem 2. [15 points]Construct a flow graph for a 16 point decimation-in-time FFT algorithm.Label all multipliers in terms of powers of W16, and also label any branch transmittancesthat are equal to ?1. Label the input and output nodes with the appropriate values ofthe input and DFT sequences, respectively. Determine the number of real multiplicationsand the number of real additions required to implement the flow graph.1(a) System for Problem 1.a (b) System for Problem 1.bProblem 3. [15 points] Let x[n] = cos(2n/5) and v[n] be the sequence obtained by applying a32-point rectangular window to x[n] before computing V (ej). Sketch |V (ej)| for ? ≤ ≤ , labeling the frequencies of all peaks and the first nulls on either side of the peak.In addition, label the amplitudes of the peaks and the strongest side lobe of each peak.Problem 4. [20 points] We are interested in estimating the spectra of three very long real-valuedsequences x1[n], x2[n], and x3[n], each consisting of the sum of two sinusoidal components.However, we only have a 256-point segment of each sequence available for analysis. Letx1[n], x2[n] and x3[n] denote the 256 point segments of x1[n], x2[n] and x3[n] respectively.We have some information about the nature of the spectra of the infinitely long sequencesas indicated from the equations belowX1(ej) ≈ ( + 1764) + ( +4) + ( ? 4) + ( ? 1764)X2(ej) ≈ 0.017( + 1132) + ( +4) + ( ? 4) + 0.017( ? 1132)X3(ej) ≈ 0.01( + 2571024) + ( +4) + ( ? 4) + 0.01( ? 2571024)We want to analyze x1[n], x2[n] and x3[n] by first multiplying them with a window andthen taking the magnitude of the 2048-point DFT of the windowed sequence, i.e. fori = 1, 2, 3v[n] = w[n]xi[n]|V [k]| = |V (ej)|=2k/2048| = |N?1∑n=0v[n]W kn2048|For each of the three signals x1[n], x2[n] and x3[n] indicate whether w[n] should be aRectangular or a Hamming window would be preferable, i.e. which window would enableus to distinguish the frequency components in the signals? A good justification at mini-mum will include a quantitative consideration of both resolution and side lobe behaviorof the windows. Note that is is possible that both or neither of the windows will work forany given sequence. Table 7.2 in your textbook may provide some useful information.2Problem 5. [15 points] Sketch the spectrogram obtained by using a 256-point rectangular windowand 256-point DFTs with no overlap (R = 256) on the signalx[n] = cos(n4 ...

April 23, 2023 · 5 min · jiezi

关于算法:CS-520-实现与测试

Homework 3Implementation & testingYou may work with others on this assignment. Each programming pair, however, must submit their owncodebase, clearly specifying the collaborators. The codebase should be written in the pair’s own words.A programming pair may contain 1, 2, or 3 students. This allows the usual groups of 3 to remain together.You should submit on Gradescope. Late assignments will be accepted with prior permission or forextenuating circumstances. Due: Monday April 17, 2023, 11:59 PMThere are a total of 100 points.OverviewThe goal of this assignment is to design, implement, and test a Tic Tac Toe app, to improve adherence tonon-functional requirements (e.g., understandability, modularity, extensibility, testability), design princi-ples/patterns, and best practices.This implementation applies the MVC architecture pattern. In contrast to the current version, yourimplementation should support possible extensions aiming to satisfy the open/closed principle (specifi-cally information hiding with encapsulation). Additionally, your implementation should enable individualcomponents to be tested in isolation.You are expected to clone the existing repository and keep your implementation under version control,using the cloned repository. You will submit your repository to us, so you should make coherent and atomiccommits (in particular for the 3 sections below), and use descriptive log messages.How to get started ...

April 23, 2023 · 4 min · jiezi

关于算法:关于蚂蚁技术研究院的那些事儿|交互智能实验室篇

近日,计算机视觉三大顶级会议之一CVPR 2023 论文接管后果正式颁布。据官网信息统计,2023年共收到 9155 份无效投稿,较22年减少12%,投稿论文数量创下新高,最终接管论文2360 篇,接管率为 25.78%。此次蚂蚁技术研究院交互智能实验室共有13篇论文入选,论文钻研方向次要集中于生成模型与三维视觉畛域。 交互智能实验室作为蚂蚁技术研究院首批落地建成的实验室,交互智能实验室次要钻研方向为生成模型、三维视觉、多模态及人机交互。实验室成员来自清华大学、浙江大学、中国科学技术大学、香港中文大学、香港科技大学等。目前与清华大学、上海交通大学、香港大学、牛津大学、加州大学伯克利分校等多所海内外高校均有单干。在过来的一年多工夫里,蚂蚁技术研究院交互智能实验室进行了生成模型与三维视觉畛域的多项钻研,包含根底生成模型(如生成反抗网络、扩散模型等)、生成模型的可控性与可解释性、三维感知的生成模型与视频生成模型、数字人及数字场景等细分畛域,获得了肯定阶段性的成绩。截至目前,交互智能实验室共有21篇论文被国内顶会录用,其中ICML2022录用2篇,NeurIPS 2022 录用4篇,TPAMI2022录用1篇,ICLR2023录用1篇,CVPR2023录用13篇,聚焦计算机生成模型、三维视觉等畛域的相干问题,为解决学术问题而不懈努力。 入选论文推介获CVPR 2023收录:Learning 3D-aware Image Synthesis with Unknown Pose Distribution现有的三维感知图像生成工作须要一个精确的三维姿态(3D pose)先验来保障生成品质。然而获取一个精确的姿态先验是很艰难的,通常须要大量的试验调试。为此,蚂蚁技术研究院交互智能实验室提出了用PoF3D来罢黜模型对三维姿态先验的依赖。首先,交互智能实验室为生成器装备了一个姿态学习器来从隐空间中推断出一个姿态,以主动学习实在图像的姿态散布。而后,为判断器设计了一个姿态预测的分支,并利用预测出的姿态作为判断图像虚实的条件。在多个数据数据集上的试验表明,咱们的办法在不借助任何先验的状况下,在图像品质和几何品质的测量指标上都达到了畛域内的领先水平。 获ICLR 2023收录:Towards Smooth Video Composition论文提出了一个新的视频生成办法——StyleSV。基于生成反抗网络(GAN)的图片生成钻研工作于近年尽管获得了显著的停顿,然而如何利用GAN进行视频生成仍是一个颇有挑战的问题。面对这个挑战,蚂蚁技术研究院交互智能实验室针对不同跨度(短时、适中、长范畴)的时序关系,别离对视频进行了粗疏的建模与改良,并在多个数据集上获得了相较于之前工作大幅度的晋升,为基于GAN的视频生成方向提供了一个简略又无效的新基准。 蚂蚁技术研究院和他的实验室们致力于做有用、有想象力的科研,蚂蚁技术研究院面向数字化、智能化的将来,瞄准世界科技前沿,推动要害核心技术攻关,促成“产学研用”深度交融,为中国数字经济的做强做大做优贡献力量。除交互智能实验室外,蚂蚁技术研究院还设有数据库实验室、图计算实验室、密码学实验室、程序设计语言与编译器实验室以及计算零碎实验室共六大实验室,独特摸索前沿技术畛域倒退。明天的蚂蚁技术研究院刚刚起步,交互智能实验室的些许成绩,是咱们这一年的成绩单,也是献给业界同仁给予咱们更多反对与关注的邀请函,咱们真诚地期待更多有识之士的退出打造一个科技摸索的殿堂,独特谋求科技的提高。 请查收蚂蚁技术研究院成绩单

April 23, 2023 · 1 min · jiezi

关于算法:如何评价-ChatGPT-回答策略的-ensure-only-ethical-usage-特质

有人批评 ChatGPT 的答复策略是 ensure only ethical usage,如何了解这句话? 这句话的意思是,ChatGPT被批评的答复策略只是确保其在伦理上的应用,即遵循道德和法律标准。这意味着ChatGPT的开发者们试图防止ChatGPT被用于违反伦理或法律规定的行为,例如欺诈、虚伪宣传、人身攻击、歧视等等。因而,ChatGPT的答复策略旨在爱护用户和社会免受不道德或违法行为的影响,同时确保它在非法和道德框架内失去应用。 防止歹意用处ChatGPT开发者们为了确保只有在非法和道德框架内失去应用,他们防止应用过来在社交媒体平台上呈现的自然语言生成模型的歹意用处。因而,在ChatGPT的答复策略中,开发者们采纳了多层过滤和审核的机制来检测用户输出的内容,以防止ChatGPT被用于公布虚伪信息、欺诈、人身攻击、怨恨舆论等歹意用处。 防止诱导性舆论ChatGPT的答复策略遵循道德规范,防止应用诱导性舆论或误导性信息。ChatGPT的开发者们认为,它的输入应该是精确、中立和主观的,并且不应该试图影响用户的决策。因而,ChatGPT的答复策略中采纳了多种技术来防止输入内容中的偏见和误导性信息。 防止歧视和怨恨舆论ChatGPT的答复策略要确保答复内容不蕴含任何歧视和怨恨舆论。在答复时,它会过滤出任何可能会引起不必要争议或抵触的话语,例如带有种族、性别、性取向等敏感话题。如果ChatGPT发现用户输出的内容蕴含这些话题,它会提醒用户批改输出内容,以确保答复内容是道德和非法的。 总之,ChatGPT的答复策略确保仅在伦理和道德框架内失去应用。这意味着,开发者们会防止它被用于不道德或违反法律规定的行为,例如虚伪宣传、欺诈、人身攻击、歧视等等。为此,他们采纳了多层审核和过滤的机制,以确保输入内容的准确性、中立性和客观性,并防止蕴含诱导性或误导性信息。

April 22, 2023 · 1 min · jiezi

关于算法:如何理解人工智能领域-LLM-的-No-notion-of-time-or-chronological-order-这一局限性

在人工智能畛域,LLM代表“大型语言模型”。当一个LLM解决一段文本时,它通常只思考以后的句子,而不思考整个上下文中的工夫或工夫程序。 这种局限性意味着LLM无奈解决一些须要思考工夫或工夫程序的工作。例如,如果一个LLM被用来预测天气,它可能无奈思考先前的天气预报,这会影响其预测准确性。同样,在一些自然语言解决工作中,如问答零碎和机器翻译,工夫和工夫程序也是十分重要的。 然而,只管LLM无奈间接解决工夫和工夫程序,但钻研人员曾经提出了一些技术来帮忙模型解决这些工作。例如,能够应用一种称为“记忆加强”的技术来帮忙模型保留先前的信息,并在解决文本时思考工夫和工夫程序。此外,还有一些特定畛域的LLM,例如工夫序列预测LLM,这些LLM专门用于解决须要思考工夫程序的工作。 在商务英语中,chronological通常用来形容按工夫顺序排列的事件、工作或文件。例如,在一份商业计划书中,能够应用chronological order列出公司历史上的重要事件和里程碑,以便投资者可能依照工夫程序理解公司的倒退历程。另外,在商务信函或报告中,也经常应用chronological order的形式来出现数据、事件或状况的倒退过程,以帮忙读者更好地了解和剖析信息。 以下是一个应用 "chronological" 的商务英语句子: The financial report should be presented in chronological order, starting with the first quarter and ending with the fourth quarter, so that investors can track the company's performance over time. 因为 ChatGPT 模型没有对工夫和工夫程序进行建模,因而在答复须要思考工夫因素的问题时可能会呈现谬误或不精确的答案。以下是一个 ChatGPT 可能会出错的例子: 问题:明年圣诞节会是星期几? ChatGPT 的答复可能会是:“我不晓得。” 因为模型没有对日历和时间表进行编码,它无奈辨认"明年圣诞节"与以后工夫的关系。 必须要显式通知其基准日期:

April 22, 2023 · 1 min · jiezi

关于算法:人工智能AI图像风格迁移StyleTransfer基于双层ControlNetPython310

图像格调迁徙(Style Transfer)是一种计算机视觉技术,旨在将一幅图像的格调利用到另一幅图像上,从而生成一幅新图像,该新图像联合了两幅原始图像的特点,目标是达到一种风格化叠加的成果,本次咱们应用Stable-Diffusion联合ControlNet来实现图像格调迁徙成果。 装置ControlNet插件首先确保本地曾经装置并且配置好了Stable-Diffusion-Webui服务,对于Stable-Diffusion-Webui,请参见:人工智能,丹青圣手,全平台(原生/Docker)构建Stable-Diffusion-Webui的AI绘画库教程(Python3.10/Pytorch1.13.0),这里不再赘述。 随后进入我的项目目录,启动Stable-Diffusion-Webui服务: python3 launch.py如果是没有N卡的电脑,就应用cpu模式启动: python3 launch.py --skip-torch-cuda-test --upcast-sampling --use-cpu interrogate接着拜访 http://localhost:7860 抉择插件(Extensions)选项卡 点击从url装置,输出插件地址:github.com/Mikubill/sd-webui-controlnet.git 装置胜利后,重启WebUI界面。 因为ControlNet默认是一层网络,风格化操作咱们须要两层,所以在设置选单(Settings)中,将多层网络设置为2。 设置好之后,下载模型文件:huggingface.co/webui/ControlNet-modules-safetensors/tree/main 将模型放入 stable-diffusion-webui/extensions/sd-webui-controlnet/models目录 这里还须要独自下载一个格调迁徙模型,地址是:huggingface.co/TencentARC/T2I-Adapter/blob/main/models/t2iadapter\_style\_sd14v1.pth 同样放入stable-diffusion-webui/extensions/sd-webui-controlnet/models目录 至此,Stable-Diffusion-Webui服务的ControlNet插件就配置好了。 格调迁徙当初,咱们关上ControlNet的第一个图层,将原始图像的轮廓渲染进去,因为须要保障原始图像的根本形态。 这里预处理器抉择head,模型应用ControlNet的head模型即可。 能够看到根本轮廓曾经失去了保留,风格化只负责色彩和线条。 随后配置第二个ControlNet图层,预处理器抉择t2ia\_style-clipvison,模型抉择刚刚下载的t2iadapter\_style\_sd14v1.pth,默认图像权重为1,先不要动。 接着上传一张指标格调的图片,这里咱们抉择文森特梵高的表现主义作品《星空》: 随后点击Generate按钮做图生图(img2img)操作即可。 过拟合问题(Overfitting)通过一段时间的本地推理,生成后果如下: 成果并不尽如人意,这也是大多数深度学习入门者会遇到的问题,也就是过拟合问题。 过拟合(Overfitting)是指在训练模型时,模型适度地学习了训练数据的特色和噪声,从而导致模型在新数据上体现不佳的问题。 艰深地讲,过拟合就像是一名学生背诵考试答案,然而他只是死记硬背了考试题目标答案,没有真正了解题目的实质和解题思路。当他遇到新的考试题目时,因为没有了解题目的实质和解题思路,他就无奈正确答复。 在机器学习中,过拟合的起因是模型简单度过高,导致模型对训练数据中的噪声和特色都适度谋求,并且疏忽了数据背地的实质法则和特色。因而,当模型面对新的数据时,因为没有真正了解数据的实质法则和特色,它就无奈正确地对新数据进行预测。 说白了,就是对于原始图的特色过分谋求,从而淡化了指标图的格调,还记得ControlNet默认权重是1吗?这里咱们只须要将权重往下调整,比方调成0.8,再次尝试生成: 成果不错,既保留了原始图的大部分细节,又减少了梵高的表现主义格调。 当然了,权重也不能一味地往下调整,否则也会呈现欠拟合(Underfitting)问题,整个风格化迁徙的过程也能够了解为是一种“调参”的过程。 结语通过Stable-Diffusion联合ControlNet插件,咱们能够失去一幅新的图像,该图像联合了两幅原始图像的特点,既具备内容图像的内容,又具备格调图像的格调。图像格调迁徙也能够利用于其余的畛域,比方电影、游戏、虚拟现实和动画创作等等。

April 21, 2023 · 1 min · jiezi

关于算法:变换编码的设计与实现

拜访【WRITE-BUG数字空间】_[内附残缺源码和文档]一、试验目标采纳dct变换,编制对图象进行变换的程序,图象采纳8x8分快。对变换系数做Z型扫描,别离采纳前2、3、5、8个和全副系数恢复原图象,察看后果,给出psnr值。对变换后系数做量化,量化表采纳JPEG量化表,量化过程如下:,j)=C(i,j)/Q(i,j),其中C(i,j)为变换后系数,F(i,j)为量化后系数,Q(i,j) = K q(i,j),q(i,j)为JPEG根本量化表。量化后做重构图像(反量化,反变换),计算K=1时的PSNR值,求PSNR大概别离为25、28、30、35时的K值。二、试验环境零碎环境:windows 10;编程语言:matlab三、试验原理将空间域的图像信号映射变换到另一个复正交矢量空间,产生一批变换系数,制去除图像的空间冗余度,而后对这些系数进行编码解决。具体来讲就是讲图像的每一个像素定为一百个字块,而后将这N*N个像块各自正交变换,再通过滤波、量化,再对立编码。

April 20, 2023 · 1 min · jiezi

关于算法:异或算法简单实用的数据加密方法

异或异或算法的益处便是数A和数B异或后,把后果再和数A异或便可失去B,或者和数B异或可重新得到数据A。利用异或的这个个性可简略实现数据的加密和解密算法。 构建加密机加密加密机实际上便是异或中的其中一个数,能够依据本人的须要随便构建。例如我能够构建如下加密机: const int EncodeMachine[10] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A};我须要加密的数据为: int RawData[10] = {0x68, 0x12, 0x34, 0x56, 0x78, 0x89, 0x0A, 0X0B, 0X0C, 0X0D};只须要执行如下算法即可 #define MAX_TEST_NUM 10;int main(){ int EncodeData[MAX_TEST_NUM] = {0}; int DecodeData[MAX_TEST_NUM] = {0}; int i; printf("加密数据为:"); for (i=0;i<MAX_TEST_NUM;i++) { EncodeData[i] = RawData[i]^EncodeMachine[i]; printf("0x%02x ",EncodeData[i]); } printf("\r\n"); printf("解密数据为:"); for(i=0;i<MAX_TEST_NUM;i++) { DecodeData[i] = EncodeData[i]^EncodeMachine[i]; printf("0x%02x ",DecodeData[i]); }}残缺内容请点击下方链接查看:异或算法——简略实用的数据加密办法 版权申明:本文内容由阿里云实名注册用户自发奉献,版权归原作者所有,阿里云开发者社区不领有其著作权,亦不承当相应法律责任。具体规定请查看《阿里云开发者社区用户服务协定》和《阿里云开发者社区知识产权爱护指引》。如果您发现本社区中有涉嫌剽窃的内容,填写侵权投诉表单进行举报,一经查实,本社区将立即删除涉嫌侵权内容。

April 19, 2023 · 1 min · jiezi