JFrame动态显示距离矢量算法过程

计算机网络1-距离矢量路由算法模拟 距离矢量路由算法实验 一、实验要求 网络拓扑图 实验过程描述 1、将上面的网络拓扑图保存待用 例如,可用二维数组保存,数组下标或索引可隐含表示网络节点。数组元素保存网络拓扑图边上的权值 2、为每个网络节点初始化并保存一张路由表 例如,可以用单链表表示一个网络节点的路由表,单链表的每个结点存储一个表项信息;表项信息是一个三元组(目的节点,下一跳,开销),可用结构体表示... 阅读详情

基本的按钮动作监听

多个同样的文本域可以用数组做。

package disvec;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.util.*;

public class Main extends JFrame implements ActionListener, FocusListener {
    int[][] dist;
    int[][] jmp;
    final int NN=9;
    int [][] map;
    JPanel picPanel;
    JTextArea listA;
    JTextArea listB;
    JTextArea listC;
    JTextArea listD;
    JTextArea listE;
    JTextArea listF;
    JTextArea listG;
    JTextArea listH;
    JPanel A;
    JPanel B;
    JPanel C;
    JPanel D;
    JPanel E;
    JPanel F;
    JPanel G;
    JPanel H;
    JLabel pic ;
    JButton next;
    final  int n=8;
    final  int oo=1000000010;
    int[][] olddist,oldjmp;
    public void initArray(){
        olddist=new int[NN][NN];
        oldjmp=new int[NN][NN];
        map = new int[][]{
            {oo,oo,oo,oo,oo,oo,oo,oo,oo},
            {oo,0,2,oo,oo,oo,oo,6,oo},
            {oo,2,0,7,oo,2,oo,oo,oo},
            {oo,oo,7,0,3,oo,3,oo,oo},
            {oo,oo,oo,4,0,oo,oo,oo,2},
            {oo,oo,2,oo,oo,0,2,1,oo},
            {oo,oo,oo,3,oo,2,0,oo,2},
            {oo,6,oo,oo,oo,1,oo,0,4},
            {oo,oo,oo,oo,2,oo,2,4,0}
        };
        dist= new int[NN][NN];
        jmp=new int[NN][NN];
        for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
            dist[i][j]=map[i][j];
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(dist[i][j]<oo)jmp[i][j]=j;
                else jmp[i][j]=-1;
            }
        }
    }
    public void initPicPanel(){
        picPanel =new JPanel();
        picPanel.setPreferredSize(new Dimension(1100, 200));
        picPanel.setBackground(Color.white);
        picPanel.setBorder(BorderFactory.createTitledBorder("Map"));
        picPanel.add(pic);
    }
    public void initTexField(){
        listA=new JTextArea();
        listB=new JTextArea();
        listC=new JTextArea();
        listD=new JTextArea();
        listE=new JTextArea();
        listF=new JTextArea();
        listG=new JTextArea();
        listH=new JTextArea();
        A=new JPanel();
        B=new JPanel();
        C=new JPanel();
        D=new JPanel();
        E=new JPanel();
        F=new JPanel();
        G=new JPanel();
        H=new JPanel();
        A.setPreferredSize(new Dimension(135, 300));
        A.setBackground(Color.white);
        A.setBorder(BorderFactory.createTitledBorder("listA"));
        A.add(listA);
        B.setPreferredSize(new Dimension(135, 300));
        B.setBackground(Color.white);
        B.setBorder(BorderFactory.createTitledBorder("listB"));
        B.add(listB);
        C.setPreferredSize(new Dimension(135, 300));
        C.setBackground(Color.white);
        C.setBorder(BorderFactory.createTitledBorder("listC"));
        C.add(listC);
        D.setPreferredSize(new Dimension(135, 300));
        D.setBackground(Color.white);
        D.setBorder(BorderFactory.createTitledBorder("listD"));
        D.add(listD);
        E.setPreferredSize(new Dimension(135, 300));
        E.setBackground(Color.white);
        E.setBorder(BorderFactory.createTitledBorder("listE"));
        E.add(listE);
        F.setPreferredSize(new Dimension(135, 300));
        F.setBackground(Color.white);
        F.setBorder(BorderFactory.createTitledBorder("listF"));
        F.add(listF);
        G.setPreferredSize(new Dimension(135, 300));
        G.setBackground(Color.white);
        G.setBorder(BorderFactory.createTitledBorder("listG"));
        G.add(listG);
        H.setPreferredSize(new Dimension(135, 300));
        H.setBackground(Color.white);
        H.setBorder(BorderFactory.createTitledBorder("listH"));
        H.add(listH);
    }
    public void initButton(){
        next=new JButton("next time");
        next.addActionListener(this);
    }
    public void makeFrame(){
        this.setTitle("Distance Vector Routing");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(new FlowLayout());
        this.add(picPanel);
        this.add(A);
        this.add(B);
        this.add(C);
        this.add(D);
        this.add(E);
        this.add(F);
        this.add(G);
        this.add(H);
        this.add(next);
        this.setVisible(true);
        this.setSize(1200,600);
    }
    void BellmanFord(){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                olddist[i][j]=dist[i][j];
                oldjmp[i][j]=jmp[i][j];
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(j==i)continue;
                if(map[i][j]<oo){
                    for(int k=1;k<=8;k++){
                        if(olddist[j][k]<oo){
                            if(olddist[i][k]>=oo){//i表没有项目k
                                dist[i][k]=olddist[j][k]+map[i][j];
                                jmp[i][k]=j;
                            }
                            else{
                                if(oldjmp[i][k]!=j){
                                    if(olddist[j][k]+map[i][j]<olddist[i][k]){
                                        dist[i][k]=olddist[j][k]+map[i][j];
                                        jmp[i][k]=j;
                                    }
                                }
                                else{
                                    dist[i][k]=olddist[i][j]+olddist[j][k];
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    public void display(){
        listA.setText("");
        for(int i=1;i<=n;i++){
            char cc= (char) ('A'+i-1);
            char cc2= (char) ('A'+jmp[1][i]-1);
            if(i==1||dist[1][i]>=oo)listA.append(cc+" "+"N"+" "+"/"+"\n");
            else listA.append(cc+" "+dist[1][i]+" "+cc2+"\n");
        }
        listB.setText("");
        for(int i=1;i<=n;i++){
            char cc= (char) ('A'+i-1);
            char cc2= (char) ('A'+jmp[2][i]-1);
            if(i==2||dist[2][i]>=oo)listB.append(cc+" "+"N"+" "+"/"+"\n");
            else listB.append(cc+" "+dist[2][i]+" "+cc2+"\n");
        }
        listC.setText("");
        for(int i=1;i<=n;i++){
            char cc= (char) ('A'+i-1);
            char cc2= (char) ('A'+jmp[3][i]-1);
            if(i==3||dist[3][i]>=oo)listC.append(cc+" "+"N"+" "+"/"+"\n");
            else listC.append(cc+" "+dist[3][i]+" "+cc2+"\n");
        }
        listD.setText("");
        for(int i=1;i<=n;i++){
            char cc= (char) ('A'+i-1);
            char cc2= (char) ('A'+jmp[4][i]-1);
            if(i==4||dist[4][i]>=oo)listD.append(cc+" "+"N"+" "+"/"+"\n");
            else listD.append(cc+" "+dist[4][i]+" "+cc2+"\n");
        }
        listE.setText("");
        for(int i=1;i<=n;i++){
            char cc= (char) ('A'+i-1);
            char cc2= (char) ('A'+jmp[5][i]-1);
            if(i==5||dist[5][i]>=oo)listE.append(cc+" "+"N"+" "+"/"+"\n");
            else listE.append(cc+" "+dist[5][i]+" "+cc2+"\n");
        }
        listF.setText("");
        for(int i=1;i<=n;i++){
            char cc= (char) ('A'+i-1);
            char cc2= (char) ('A'+jmp[6][i]-1);
            if(i==6||dist[6][i]>=oo)listF.append(cc+" "+"N"+" "+"/"+"\n");
            else listF.append(cc+" "+dist[6][i]+" "+cc2+"\n");
        }
        listG.setText("");
        for(int i=1;i<=n;i++){
            char cc= (char) ('A'+i-1);
            char cc2= (char) ('A'+jmp[7][i]-1);
            if(i==7||dist[7][i]>=oo)listG.append(cc+" "+"N"+" "+"/"+"\n");
            else listG.append(cc+" "+dist[7][i]+" "+cc2+"\n");
        }
        listH.setText("");
        for(int i=1;i<=n;i++){
            char cc= (char) ('A'+i-1);
            char cc2= (char) ('A'+jmp[8][i]-1);
            if(i==8||dist[8][i]>=oo)listH.append(cc+" "+"N"+" "+"/"+"\n");
            else listH.append(cc+" "+dist[8][i]+" "+cc2+"\n");
        }
    }
    public Main(){
        pic = new JLabel(new ImageIcon("D:\\disVec\\src\\disvec\\图片1.png"));
        initArray();
        initPicPanel();
        initTexField();
        initButton();
        makeFrame();
        display();
    }
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==next){
            BellmanFord();
            display();
        }
    }
    public void focusGained(FocusEvent e) {
        ;
    }
    public void focusLost(FocusEvent e) {
        ;
    }
    public static void main(String[] args) {
        new Main();
    }

}

效果

在这里插入图片描述

距离矢量算法(Distance Vector Algorithm)的动态路由 立即下载

相关推荐

基于Java17、SpringBoot、vue3、antdv-next、uniapp等主流技术构建的全场景极速开发平台 MDP内置3个web端、1个移动端 重点解决用户中心、开发者平台、管理后台3个应

MDP-主数据平台,后端项目。专注于单点登录解决方案。内置用户中心、开发者平台、管理后台3个应用。包含:单点登录、Oauth2 登录、用户身份管理、应用申请、应用接入、主数据维护、主数据订阅、主数据广播、应用接口调用、接口管理管理和查看、系统配置等功能。

距离矢量路由算法的java代码_八大排序算法比较(附Java代码)

冒泡排序/** * 冒泡排序 比较好理解 * 两两相比 较大的放后面 * 时间复杂度O(n^2) */ /** * 改进前的冒泡排序算法进行100,000数据排序运行时间为:3829ms * 优化后的冒泡排序算法进行100,000数据排序运行时间为:3551ms */ public static void bubbleSort(int[] array){ //原始的冒泡排序,比较的...

weixin_39987847的博客 401

科技中介服务机构想要提升服务效率,需要哪些数智工具支持?.docx

科技中介服务机构想要提升服务效率,需要哪些数智工具支持?

路由选择矢量距离java,距离矢量路由算法

现代计算机网络通常使用动态路由算法,因为这类算法能够适应网络的拓扑和流量变化,其中最流行的两种动态路由算法是“距离矢量路由算法”和“链路状态路由算法”。距离矢量路由算法(Distance Vector Routing,DV)是ARPANET网络上最早使用的路由算法,也称Bellman-Ford路由算法和Ford-Fulkerson算法,主要在RIP(Route Information Protoc...

weixin_31174767的博客 768

usb 扩容盘检测修复工具源码,编译产物

usb 扩容盘检测修复工具源码,编译产物

融合UWB和IMU割草机定位EKF研究(Matlab代码实现)

内容概要:本文主要介绍了一个名为“Plecs全桥LLC谐振变换器仿真模型”的技术资源,该资源聚焦于电力电子领域中的LLC谐振变换器建模与仿真,涵盖开环、闭环控制、软启动设计及参数优化等核心内容。文档不仅提供了LLC变换器的详细建模方法与仿真案例,还系统梳理了其在高效电源转换系统中的应用,包括隔离型全桥拓扑结构的设计与性能分析。此外,资源汇总了大量Matlab/Simulink仿真模型及相关科研方向,涉及新能源并网、储能控制、电机驱动等多个前沿领域,全面展示LLC谐振变换器在现代电力系统中的关键技术实现路径。同时,文档附带多种学习资料获取途径,如网盘链接和公众号资源,便于研究人员深入实践与拓展研究。; 适合人群:具备扎实的电力电子、自动控制理论基础,从事新能源发电、开关电源设计、电力系统仿真等相关领域的研究生、工程师及科研人员。; 使用场景及目标:①深入理解LLC谐振变换器的工作原理、建模方法与控制策略;②开展电力电子变换器的仿真验证与参数优化设计;③支撑科研项目、学位论文或工程项目的系统仿真与方案验证; 阅读建议:建议结合所提供的仿真模型与参考文献,使用Plecs或Simulink软件进行动手实践,重点掌握LLC谐振变换器的建模流程、闭环控制设计、软启动机制及参数调试技巧,以全面提升在实际工程中的应用与创新能力。

java实现基于距离向量算法 路由协议

算法就不多说了,该程序实现的功能:首先你要将网络结构转化成邻接矩阵,每个路由器对应一行,若路由器m与网络n直接相连,则m行n列为1,否则为0 该程序的路由器和网络都从0开始编号 首先创建Table类,代表路由器的路由表 public class Table { public int hostId;//哪个路由器的路由表 public int netId;//目的网络的id

sinat_32092165的博客 7183

基于变频控制的多相交错LLC谐振变换器闭环仿真(Simulink仿真实现)

基于变频控制的多相交错LLC谐振变换器闭环仿真(Simulink仿真实现)内容概要:本文主要介绍了基于Plecs的全桥LLC谐振变换器仿真模型,涵盖变频控制下的多相交错LLC谐振变换器闭环仿真、V2G电动汽车ACDC整流与双向CLLC谐振变换器充放电仿真、LLC谐振变换器的开环与闭环软启动设计,以及储能系统中双向Buck-Boost变换器结合模型预测电流控制和电压下垂控制的仿真研究。同时,文档列举了多种电力电子系统与控制策略的Simulink/Plecs仿真案例,涉及三相交错并联Buck变换器、三电平Buck直流变换器、单相Boost PFC电路等,展示了丰富的电力变换器建模与控制技术。此外,还包括参数设计报告、计算书及相关参考文献,适用于从事电力电子、新能源发电、电动汽车充放电系统等领域的研究人员和技术开发人员。; 适合人群:具备电力电子、自动控制理论基础,从事新能源、电动汽车、电力系统等相关领域研究的研发人员、高校研究生及高年级本科生。; 使用场景及目标:① 学习和掌握LLC谐振变换器及其他典型电力电子变换器的工作原理与建模方法;② 实现闭环控制策略如变频控制、软启动、模型预测控制、下垂控制等的仿真验证;③ 支持科研项目、毕业设计或工程开发中的系统仿真与优化设计。; 阅读建议:建议结合文中提供的仿真模型、设计报告与参考文献,逐步搭建并调试相应系统,重点关注控制策略的实现细节与参数整定过程,以深入理解系统动态响应特性与控制性能。

DV、LS路由算法Java编程实现

DV、LS路由算法java编程实现

weixin_57671089的博客 1606

深入理解DQN中的Q值:核心概念和应用

在强化学习中,Q值(或称为动作价值函数)是核心概念之一。Q值函数 ( Q(s, a) ) 表示在给定状态 ( s ) 下,采取动作 ( a ) 并遵循某策略后,智能体从当前状态到未来状态所能获得的预期总回报。简言之,Q值是评估特定状态和动作对的好坏的指标。

qlkaicx的博客 2976

lisp方格网法计算土方量_分享:两期土方工程量计算(方格网法)实例例题

最近遇到一个飞时达土方软件试用版客户,咨询怎么根据平整前的原始地形图和平整后的现状地形图来计算产生的土方工程量,也就是两期土方量,且需要用方格网法来计算,作为一个老道的工程设计人员,博主对这类的项目实例例题简直太熟悉了,用飞时达土方计算软件V13.0可以很方便的计算出来。 方格网法计算两期土方量流程 一、软件安装及注册 专业的飞时达土方计算软件FastTFT,请到飞时达软件官方网站去下载,注册完...

weixin_35131425的博客 1700

RIP及距离向量算法

>>>预备知识 网络层提供两种服务: 虚电路服务 数据报服务 虚电路服务与数据报服务的对比 对比的方面 虚电路服务 数据报服务 思路 可靠通信由网络保证 可靠通信由终系统保证 连接的建立 必须有 不需要 终点地址 仅在连接建立阶段使用,每个分组使用短的虚电路号 每个分组都有终点的完整地址 分组...

weixin_30533797的博客 2160

毫米波雷达入门知识

毫米波雷达入门知识

ssbzxcvbnm1234567的博客 5446

距离矢量路由算法

距离矢量路由算法(Distance Vector Routing,DV)是ARPANET网络上最早使用的路由算法,也称Bellman-Ford路由算法和Ford-Fulkerson算法,主要在RIP(Route Information Protocol)协议中使用。 距离向量算法主要思想为dp和floyd算法思想类似每一步需要满足最优即dist[i][j]=min(dist[i][j],dist[...

qq_45141428的博客 2723

python 爬取携程全国旅游景点信息-2024.4.13

携程网是中国领先的在线旅行服务公司,提供酒店预订、机票预订、旅游度假、商旅管理等服务。携程网上有大量的旅游景点和酒店信息,这些信息对于旅行者和旅游业者都有很大的价值。通过爬虫技术,我们可以从携程网上获取这些信息,并进行数据清洗、数据分析、数据可视化等操作,从而得到有用的洞察和建议。

britlee的博客 1万+

Jetson Orin Nano - SONY imx415 camera驱动开发

基于英伟达 Jetson orin nano 平台 imx415 camera驱动开发

hinewcc的博客 3246

路由算法之距离矢量算法和链路状态算法

我们之前说了,路由器需要对于每一对端端节点都要寻找出一个最佳的路径,比如说最小链路成本的路径。路由算法就是通过自己到相邻节点之间的信息来计算出自己到目的地址的最佳出境线路是哪一条,进而进行转发的一类算法。具有代表性的就是距离矢量算法和链路状态算法。         距离矢量算法的特点是:         1.分布的  每个节点接收来自与其直接邻接节点的路由信息,并执行路由计算,将计算结果回传给

hanzhen7541的博客 4万+

【深度解析】解决 NVIDIA 显卡“掉卡”与 Xid 79 错误:开启持久化模式 (Persistence Mode)

【深度解析】解决 NVIDIA 显卡“掉卡”与 Xid 79 错误:开启持久化模式 (Persistence Mode)

Edward的博客 865

JFrame窗口界面的动态显示

通过一个.remove()删除其直接的控件。然后重绘重绘。 最后需要更新的JFrame窗口,进行刷新。 方法1.重新显示窗口 frame.setVisible(false); frame.setVisible(true); 方法2.重新验证窗体 frame.invalidate(); frame.validate(); 方法3.重置窗口大小 frame.pack(); fram...

sinat_40553837的博客 6022

Uniapp微信小程序:详解根据角色权限动态展示底部tabbar,支持不同身份显示不同底部导航+灵活权限组合完整源码,菜单切换不闪烁、秒加载不卡(提供动态原生Tabbar配置+自定义组件形式2种方案)

uni-app微信小程序实现根据用户不同角色显示不同的tabBar,uniapp微信小程序原生tabbar实现动态菜单导航,微信小程序动态tabBar实现:基于自定义组件,灵活支持不同用户角色,动态pages,uni-app微信小程序动态tabBar,根据不同用户展示不同的tabBar,uni-app微信小程序动态切换tabBar,根据不同用户角色展示不同的tabBar,微信小程序自定义底部tabbar动态修改,Uniapp小程序根据权限(角色)不同动态展示底部tabbar,解决tabbar闪烁卡顿问题,小

✅ 精选推荐文章 4284

Ubuntu 部署 Ollama 避坑指南:下载失败 / 服务崩溃?一招解决所有问题!

本文详细介绍了在Ubuntu系统上安装Ollama大模型工具的完整流程和常见问题解决方案。主要内容包括:环境检查(系统版本、架构、依赖)、一键安装步骤、端口配置和服务启动等核心操作。重点针对下载失败、服务启动异常、权限不足等高频问题,提供了国内镜像配置、手动创建服务文件、用户组添加等实用解决方案。最后通过测试Qwen2.5轻量模型验证安装效果,并给出低配设备选型建议。全文提供可复制的命令行操作,帮助用户快速搭建离线可用的大模型环境。

2501_93651177的博客 1008

距离向量路由算法的Java模拟

实验内容与实现原理; 实验内容:模拟距离向量路由算法的路由表交换过程,演示每轮交换后路由表的变化。基本要求(动态生成网络拓扑图,节点间的距离随机生成。从初始路由表开始,进行交换路由表,演示每轮交换后的路由表的变化。观察和讨论多少轮交换后路由表稳定)。 实现原理:初始时设定站点个数,每一个站点附带一个表格来记录其余的站点以及距离,并用随机数产生站点之间距离记入表格(产生距离是要考虑到是否相邻的情况

lyzzj的博客 4096

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

软件构造心得(12):关于JFrame、动态显示、与交互界面制作的入门级心得

前言 GUI虽然不是我们软件构造课程的核心思想所在,但是却往往是一个软件设计者外在而直接的品味。当然抛开这些不谈,初次接触GUI如我,因为毫无基础,面对网上鱼龙混杂的说法真的尝试而且崩溃了好久,多亏陶神佬相助为我仙人指路,让我得以系统性的接触并且学习了相关的知识。这里逐步整理一下我的心得。因为内容较多,可能需要多更新几回… JFrame是什么 通过阅读书籍,发现JFrame和swing的历史是一个...

weixin_43197820的博客 786

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

上一篇: 最大流经典题--航线最优安排
下一篇: SMTP协议模拟发送邮件(java)
Ada Chambers
博客等级 码龄8年 29粉丝 73原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值