[Source Code]货币计数转化为中文大写

vim中使用ctags工具 1 ctags简介 ctags产生标记文件以帮助在源文件中定位对象。 2 其生成的标记文件tags中包括这些对象的列表: 用#define定义的宏 枚举型变量的值 函数的定义、原型和声明 名字空间(namespace) 类型定义(typedefs) 变量(包括定义和声明) 类(class)、结构(struct)、枚举... 阅读详情

package com.mytest;

import java.util.HashMap;

public class RMBCurrency {
 HashMap chars;

 StringBuffer ChnMoney;

 public RMBCurrency() {
  super();
  init();
 }

 private void init() {
  ChnMoney = new StringBuffer();
  chars = new HashMap();
  chars.put("+0", "整");
  chars.put("-1", "角");
  chars.put("-2", "分");
  chars.put("0", "零");
  chars.put("1", "壹");
  chars.put("2", "贰");
  chars.put("3", "叁");
  chars.put("4", "肆");
  chars.put("5", "伍");
  chars.put("6", "陆");
  chars.put("7", "柒");
  chars.put("8", "捌");
  chars.put("9", "玖");
  chars.put("00", "拾");
  chars.put("000", "佰");
  chars.put("0000", "仟");
  chars.put(new Integer(0), "元");
  chars.put(new Integer(1), "万");
  chars.put(new Integer(2), "亿");
  chars.put(new Integer(3), "兆");
 }

 public String convertMoney(String amount) {
  String ret = null;

  try {
   checkFormat(amount);
  } catch (NumberFormatException e) {
   System.out.println(e.getMessage());
   return null;
  }

  if (amount.indexOf(".") > 1 || amount.charAt(0) != '0') {
   // numbers before the DOT is divided into several parts
   // four number as a part
   // Note the 1st part naming head may have any number from 1 to 4
   char[] head;
   int parts = amount.indexOf(".") / 4;
   if (amount.indexOf(".") - parts * 4 == 0) {
    head = new char[4];
    amount.getChars(0, 4, head, 0);
    parts = parts - 1;
   } else {
    head = new char[amount.indexOf(".") - parts * 4];
    amount.getChars(0, amount.indexOf(".") - parts * 4, head, 0);
   }

   // deal with head
   doBeforeDot(head, true, '-');
   if (parts != 0) {
    ChnMoney.append(chars.get(new Integer(parts)));
   }

   // deal with other parts except head
   String[] temp = new String[parts];
   for (int i = 0; i < parts; i++) {
    temp[i] = amount.substring(amount.length() - 3 - 4 * (i + 1),
      amount.length() - 3 - 4 * i);
   }

   char[] part = new char[4];
   for (int i = temp.length - 1; i >= 0; i--) {
    temp[i].getChars(0, 4, part, 0);

    boolean isAll0 = true;
    for (int j = 0; j < 4; j++) {
     if (part[j] != '0') {
      isAll0 = false;
     }
    }
    if (!isAll0) {
     if (i == temp.length - 1) {
      doBeforeDot(part, false, head[head.length - 1]);
     } else {
      char[] chrArray = temp[i + 1].toCharArray();
      doBeforeDot(part, false, chrArray[chrArray.length - 1]);
     }
     if (i != 0) {
      ChnMoney.append(chars.get(new Integer(i)));
     }
    }
   }
   // always append "元" here
   ChnMoney.append(chars.get(new Integer(0)));
  }

  // deal with numbers after the DOT
  char[] afterDot = new char[2];
  amount.getChars(amount.length() - 2, amount.length(), afterDot, 0);
  if (afterDot[0] == '0' && afterDot[1] == '0') {
   ChnMoney.append(chars.get("+0"));
  } else {
   doAfterDot(afterDot, amount);
  }

  ret = ChnMoney.toString();
  ChnMoney = new StringBuffer();
  return ret;
 }

 /*
  * deal with numbers before the DOT
  */
 private void doBeforeDot(char[] beforeDot, boolean isHead, char previous) {
  int i = 0;
  Character num;
  String key;
  if (isHead) {
   i++;
   num = new Character(beforeDot[0]);
   ChnMoney.append(chars.get(num.toString()));
   key = getKey(beforeDot.length);
   if (chars.get(key) != null) {
    ChnMoney.append(chars.get(key));
   }
  }

  for (; i < beforeDot.length; i++) {
   boolean all0 = true;
   for (int j = i; j < beforeDot.length; j++) {
    if (beforeDot[j] != '0') {
     all0 = false;
    }
   }
   if (all0) {
    return;
   }

   num = new Character(beforeDot[i]);
   if (i == 0 && beforeDot[i] != '0') {
    if (previous == '0') {
     ChnMoney.append(chars.get("0"));
    }
    ChnMoney.append(chars.get(num.toString()));
   }
   if (i == 0 && beforeDot[i] == '0') {
    ChnMoney.append(chars.get(num.toString()));
   } else if (i != 0 && beforeDot[i - 1] != '0') {
    ChnMoney.append(chars.get(num.toString()));
   } else if (i != 0 && beforeDot[i - 1] == '0' && beforeDot[i] != '0') {
    ChnMoney.append(chars.get(num.toString()));
   }

   if (beforeDot[i] != '0') {
    key = getKey(beforeDot.length - i);
    if (chars.get(key) != null) {
     ChnMoney.append(chars.get(key));
    }
   }
  }
 }

 /*
  * deal with numbers after the DOT
  */
 private void doAfterDot(char[] afterDot, String amount) {
  Character num = new Character(afterDot[0]);
  if (amount.indexOf(".") != 1 || amount.charAt(0) != '0') {
   if (amount.charAt(amount.length() - 4) == '0' || afterDot[0] == '0') {
    ChnMoney.append(chars.get("0"));
   }
  }

  if (afterDot[0] != '0') {
   ChnMoney.append(chars.get(num.toString()));
   ChnMoney.append(chars.get("-1"));
  }

  if (afterDot[1] != '0') {
   num = new Character(afterDot[1]);
   ChnMoney.append(chars.get(num.toString()));
   ChnMoney.append(chars.get("-2"));
  }
 }

 /*
  * Get keys of "拾","佰","仟"
  */
 private String getKey(int keynum) {
  String ret = null;
  switch (keynum) {
  case 2:
   ret = "00";
   break;
  case 3:
   ret = "000";
   break;
  case 4:
   ret = "0000";
   break;
  default:
   break;
  }
  return ret;
 }

 private void checkFormat(String in) throws NumberFormatException {
  new Double(in).doubleValue();

  if (in.indexOf(".") == 0) {
   throw new NumberFormatException("MUST have numbers before DOT.");
  }
  if (in.indexOf(".") != 1 && in.charAt(0) == '0') {
   throw new NumberFormatException("First Number CANNOT be zero.");
  }
  if (in.indexOf(".") == -1) {
   throw new NumberFormatException("Missing DOT !");
  } else if (in.indexOf(".", in.indexOf(".") + 1) > 1) {
   throw new NumberFormatException("Only ONE DOT allowed !");
  }
  if (in.indexOf(".") + 3 != in.length()) {
   throw new NumberFormatException(
     "Ought to have two numbers after DOT");
  }
  if (in.indexOf(".") == 1 && in.charAt(2) == '0' && in.charAt(3) == '0') {
   throw new NumberFormatException("CANNOT all be zero.");
  }
 }

 public static void main(String[] args) {
  RMBCurrency t = new RMBCurrency();
  System.out.println(t.convertMoney("80505008800.05"));
  System.out.println(t.convertMoney("369280500008801.10"));
  System.out.println(t.convertMoney("10.00"));
 }
}

 

>>>>>>>>>>>>>>>>>>>>>>>>>>> Refactoring 20061012 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

package com.mytest;

import java.util.HashMap;

public class RMBCurrency {
    private HashMap chars;

    private StringBuffer ChnMoney;

    public RMBCurrency() {
        super();
        init();
    }

    private void init() {
        ChnMoney = new StringBuffer();
        chars = new HashMap();
        chars.put("+0", "整");
        chars.put("-1", "角");
        chars.put("-2", "分");
        chars.put("0", "零");
        chars.put("1", "壹");
        chars.put("2", "?");
        chars.put("3", "?");
        chars.put("4", "肆");
        chars.put("5", "伍");
        chars.put("6", "?");
        chars.put("7", "?");
        chars.put("8", "捌");
        chars.put("9", "玖");
        chars.put("20", "拾");
        chars.put("30", "佰");
        chars.put("40", "仟");
        chars.put(new Integer(0), "元");
        chars.put(new Integer(1), "万");
        chars.put(new Integer(2), "?");
        chars.put(new Integer(3), "兆");
    }

    public String convertMoney(String amount) {
        String ret = null;

        try {
            checkFormat(amount);
        } catch (NumberFormatException e) {
            System.out.println(e.getMessage());
            return null;
        }

        if (amount.indexOf(".") > 1 || amount.charAt(0) != '0') {
            // numbers before the DOT is divided into several parts
            // four number as a part
            // Note the 1st part naming head may have any number from 1 to 4
            char[] head;
            int parts = amount.indexOf(".") / 4;
            if (amount.indexOf(".") - parts * 4 == 0) {
                head = new char[4];
                amount.getChars(0, 4, head, 0);
                parts = parts - 1;
            } else {
                head = new char[amount.indexOf(".") - parts * 4];
                amount.getChars(0, amount.indexOf(".") - parts * 4, head, 0);
            }

            // deal with head
            doBeforeDot(head, true, '-');
            if (parts != 0) {
                ChnMoney.append(chars.get(new Integer(parts)));
            }

            // deal with other parts except head
            String[] temp = new String[parts];
            for (int i = 0; i < parts; i++) {
                temp[i] = amount.substring(amount.length() - 3 - 4 * (i + 1),
                        amount.length() - 3 - 4 * i);
            }

            char[] part = new char[4];
            for (int i = temp.length - 1; i >= 0; i--) {
                temp[i].getChars(0, 4, part, 0);

                boolean isAll0 = true;
                for (int j = 0; j < 4; j++) {
                    if (part[j] != '0') {
                        isAll0 = false;
                    }
                }
                if (!isAll0) {
                    if (i == temp.length - 1) {
                        doBeforeDot(part, false, head[head.length - 1]);
                    } else {
                        char[] chrArray = temp[i + 1].toCharArray();
                        doBeforeDot(part, false, chrArray[chrArray.length - 1]);
                    }
                    if (i != 0) {
                        ChnMoney.append(chars.get(new Integer(i)));
                    }
                }
            }
            // always append "元" here
            ChnMoney.append(chars.get(new Integer(0)));
        }

        // deal with numbers after the DOT
        char[] afterDot = new char[2];
        amount.getChars(amount.length() - 2, amount.length(), afterDot, 0);
        if (afterDot[0] == '0' && afterDot[1] == '0') {
            ChnMoney.append(chars.get("+0"));
        } else {
            doAfterDot(afterDot, amount);
        }

        ret = ChnMoney.toString();
        ChnMoney = new StringBuffer();
        return ret;
    }

    /*
     * deal with numbers before the DOT
     */
    private void doBeforeDot(char[] beforeDot, boolean isHead, char previous) {
        int i = 0;
        Character num;
        if (isHead) {
            i++;
            num = new Character(beforeDot[0]);
            ChnMoney.append(chars.get(num.toString()));
            if (chars.get(beforeDot.length + "0") != null) {
                ChnMoney.append(chars.get(beforeDot.length + "0"));
            }
        }

        for (; i < beforeDot.length; i++) {
            boolean all0 = true;
            for (int j = i; j < beforeDot.length; j++) {
                if (beforeDot[j] != '0') {
                    all0 = false;
                }
            }
            if (all0) {
                return;
            }

            num = new Character(beforeDot[i]);
            if (i == 0 && beforeDot[i] != '0') {
                if (previous == '0') {
                    ChnMoney.append(chars.get("0"));
                }
                ChnMoney.append(chars.get(num.toString()));
            }
            if (i == 0 && beforeDot[i] == '0') {
                ChnMoney.append(chars.get(num.toString()));
            } else if (i != 0 && beforeDot[i - 1] != '0') {
                ChnMoney.append(chars.get(num.toString()));
            } else if (i != 0 && beforeDot[i - 1] == '0' && beforeDot[i] != '0') {
                ChnMoney.append(chars.get(num.toString()));
            }

            if (beforeDot[i] != '0') {
                if (chars.get((beforeDot.length - i) + "0") != null) {
                    ChnMoney.append(chars.get((beforeDot.length - i) + "0"));
                }
            }
        }
    }

    /*
     * deal with numbers after the DOT
     */
    private void doAfterDot(char[] afterDot, String amount) {
        Character num = new Character(afterDot[0]);
        if (amount.indexOf(".") != 1 || amount.charAt(0) != '0') {
            if (amount.charAt(amount.length() - 4) == '0' || afterDot[0] == '0') {
                ChnMoney.append(chars.get("0"));
            }
        }

        if (afterDot[0] != '0') {
            ChnMoney.append(chars.get(num.toString()));
            ChnMoney.append(chars.get("-1"));
        }

        if (afterDot[1] != '0') {
            num = new Character(afterDot[1]);
            ChnMoney.append(chars.get(num.toString()));
            ChnMoney.append(chars.get("-2"));
        }
    }

    private void checkFormat(String in) throws NumberFormatException {
        new Double(in).doubleValue();

        if (in.indexOf(".") == 0) {
            throw new NumberFormatException("MUST have numbers before DOT.");
        }
        if (in.indexOf(".") != 1 && in.charAt(0) == '0') {
            throw new NumberFormatException(
                    "First Number CANNOT be zero when the amout > 9.");
        }
        if (in.indexOf(".") == -1) {
            throw new NumberFormatException("Missing DOT !");
        } else if (in.indexOf(".", in.indexOf(".") + 1) > 1) {
            throw new NumberFormatException("Only ONE DOT allowed !");
        }
        if (in.indexOf(".") + 3 != in.length()) {
            throw new NumberFormatException(
                    "Ought to have two numbers after DOT");
        }
        if (in.indexOf(".") == 1 && in.charAt(2) == '0' && in.charAt(3) == '0') {
            throw new NumberFormatException("CANNOT all be zero.");
        }
    }

    public static void main(String[] args) {
        RMBCurrency t = new RMBCurrency();
        System.out.println(t.convertMoney("80505008800.05"));
        System.out.println(t.convertMoney("189580500008801.10"));
        System.out.println(t.convertMoney("10.00"));
        System.out.println(t.convertMoney("0.10"));
    }
}

Vim插件ctags安装与配置详解 在大型代码项目中,快速定位函数、变量、类等符号定义是提高开发效率的关键。ctags插件通过为项目生成标签文件(tags file),实现代码符号的快速跳转与导航。它支持多种编程语言,能够智能解析源码结构,构建符号索引,为开发者提供高效的代码理解与维护手段。在 Vim 编辑器中集成 ctags 后,用户可通过快捷键(如Ctrl + ])一键跳转到符号定义处,极大提升编码效率和代码阅读体验。 阅读详情

相关推荐

Vim与ctags:快速代码导航的完整指南

Vim,一款经典而强大的文本编辑器,自从1991年诞生以来,在开发者群体中享有盛誉。它的设计哲学是通过键盘快捷键实现高效编辑,支持丰富的功能,如代码折叠、多级撤销/重做、语法高亮和插件扩展等。Vim的核心理念是“mode-based editing”,即模式编辑,它将编辑状态分为普通模式、插入模式、命令行模式等,从而允许用户快速地在文本操作和命令输入之间切换。无论是初学者还是资深开发者,Vim都能提供快速、灵活的编辑体验,尤其适合进行代码编写和脚本处理。

weixin_42610671的博客 630

oracle 货币计数法,货币总计数

货币总计数(Monetary Aggregates)[编辑]什么是货币总计数三项衡量美国经济中的“金钱”之主要指标,其定义由美国联邦储备局(Federal Reserve)订定。这三项名为M1、M2,和M3的指标有时也被称为“货币供给”指标,不过这是不正确的说法,因为“总计数”(aggregate)这个字并未含有任何需求(demand)或供给的意义在里面。“总计数”所代表的是货币在需求和供给上的一...

weixin_36018773的博客 297

(一)DaVinci Developer AutoSAR工具 如何新建SWC、Component、RTE工程,超级详细步骤,赚到

​ 1,创建SWC,第一步需要创建一个App组件类型,首先点击Object Brower菜单,然后左键Application Component Types 选项,然后右键New Application Component Type,组件类型的作用是来后续实例一个Compoent 2、 Properties 选项卡中Nane中输入Type的名字,注意根据规范命名规则已CtAp开头,其他默认就好 ​

weixin_42602687的博客 3597

货币显示工具类:会计格式,非科学计数法等

package chanson; import java.math.BigDecimal; import java.math.RoundingMode; /** * @title 货币显示处理工具类 * @detail 包含以下内容: * 1、四舍五入求值 * 2、针对不同的格式化要求:万,百万,亿等 * 3、会计格式的货币值:添加','符号 * 4、非科学计数法的货币值 * ...

穿过午夜 339

避坑指南:CoppeliaSim逆运动学仿真常见报错解决方案(附UR5+RG2爪完整Lua脚本)

本文针对CoppeliaSim机器人仿真中常见的逆运动学报错问题,提供了详细的避坑指南和解决方案。文章以UR5机械臂与RG2夹爪组合为例,深入剖析了模型装配、Dummy节点配置、Lua脚本编写等关键步骤中的常见错误,并附带了完整的、带错误处理的脚本代码,帮助用户快速定位并解决IK仿真失败问题,提升仿真效率。

weixin_29054399的博客 271

RC滤波电路实战解析:无源与有源设计的性能对比与应用选择

本文深入解析了RC滤波电路的核心原理,重点对比了无源滤波电路与有源滤波电路的性能差异。文章通过实测波形与仿真数据,详细阐述了两者在带载能力、频率响应精度、噪声特性等方面的优劣,并提供了清晰的应用选择指南,帮助工程师根据信号属性、负载条件和性能要求做出最优设计决策。

weixin_29268637的博客 439

vim插件ctags

ctags(Generate tag files for source code)是一个用来生成代码标签文件的工具。它可以为多种编程语言的源代码生成标签文件,这些标签文件包含了源代码中的各种元素的信息,如函数名、变量名、类名等。Vim 可以利用这些标签文件实现快速跳转到定义、查找引用等功能。linux中默认安装了ctags,使用命令可以查看版本。

weixin_62409078的博客 1248

微信开发 - 最新第三方网站接入微信登录、微信支付时,本地 redirect_uri 参数错误导致无法调试的解决方案(微信开放平台)完美解决每次都需要部署到线上测试,在本地使用本地 ip 就能轻松调试

redirect_uri参数错误,微信第三方登录,没有服务器时的测试方法,微信开放平台的回调域名怎么设置为本地域名IP,微信登录微信支付每次调试都需要放到服务器上怎么办,微信登录支付业务在本地调试不了怎么办,在本地怎么测试微信支付和登录,微信第三方登陆本地测试,怎么在本地进行测试,微信回调域怎么设置为本地IP,微信扫码登录redirect_uri参数错误,微信开放平台,微信开放平台开发的第三方登录和支付,vue2,nuxt2,vue3,nuxt3,uniapp,微信开放平台,公众号,微信支付,微信登录授权,

🏆 前端领域优质创作者 8798

VIM中ctags的简单使用教程

关于ctags的安装及配置等,请参考 Vim:打造Linux程序员的编辑利器(ctags+cscope+taglist+code_complete)。 下面是关于ctags的几个常用快捷键。打开进入vim后,在vim编辑器内,在命令模式下输入 :ta pattern 就可以 找到符合pattern的字符位置。(相当于search功能) Ctrl + ] 找到光标所在位置的标签定义的地方。

Haifeng的博客 3万+

ParaView: 从 2 或 3 个标量创建向量

ParaView: 从 2 或 3 个标量创建向量

希望我的博客,能帮上你解决学习中工作中所遇到的问题 595

MATLAB 基于 Baker 映射和 Logistic 混沌序列的图像加解密实现

图像加密是信息安全领域的重要研究方向,在数字版权保护、隐私保护等领域有着广泛应用。本文将介绍基于 MATLAB 的 Baker 映射和 Logistic 混沌序列的图像加解密算法,该算法利用混沌系统的初值敏感性和伪随机性,能够有效地对图像进行加密和解密。基于 Baker 映射和 Logistic 混沌序列的图像加解密算法是一种有效的方法,可以应用于数字版权保护、隐私保护等领域。MATLAB 提供了强大的工具和函数,可以方便地实现该算法。

走向CTO的路上... 946

vim + ctags + cscope

vim + ctags + cscope

M120674的专栏 1930

26. 如何给 SAP BTP Cloud Foundry 环境分配运行时内存

摘要:本文解答了SAP BTP Cloud Foundry环境中Space可用内存为0MB的问题。指出Space内存配额取决于Org配额分配,其计算方式为Org总配额减去所有运行中应用实例的内存预留总和。详细解释了SAP BTP的资源分配层级(Global account→Subaccount→Environment→Org→Space),并说明如何通过Global account的Entity Assignments查看Memory Plan配额分配(以GB为单位)。最后建议遇到问题的用户检查Subacc

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1276

在Vim中使用ctags

<br /><br /><br />本文转载于: http://www.vimer.cn<br />如何在Vim中使用ctags?之前在《把Vim打造成真正的IDE》系列里已经讲过大致的ctags在vim中的使用,这篇文章我们就详细的讲一下。<br />首先要明白,ctags是什么?<br />官方的解释是:产生标记文件以帮助在源文件中定位对象。<br />其生成的标记文件tags中包括这些对象的列表:用#define定义的宏<br />枚举型变量的值<br />函数的定义、原型和声明<br />名字空间(

金俊小筑 919

梯度提升决策树GBDT原理与代码实例讲解

梯度提升决策树GBDT原理与代码实例讲解 1.背景介绍 1.1 机器学习发展历程 机器学习是人工智能领域的一个重要分支,旨在使计算机具备学习和改进自身性能的能力。随着大数据时代的到来,海量的数据为机器学习算法提供了广阔的应用空间。在

AI天才研究院 1093

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

ubuntu下vim安装ctags工具

ubuntu下安装ctags工具 ctags工具全称Generate tag files for source code。扫描指定的源文件,找出其中包含的语法元素,并把找到的相关的内容记录下来,这样在代码浏览和查找时就可以利用这些记录实现查找和跳转的功能。 一、安装ctags工具 sudo apt-get install ctags 二、建立索引文件 在想要建立索引文件的文件夹目录下执行: su...

龙董的博客 4081

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

vim中ctags插件初识

vim

chienchia的专栏 1321

深度学习工具包 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")

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

vim中ctags的使用

vim属于天降神兵之类,而ctags就是其剑柄. 1. 安装 需要安装Exuberant Ctags, 由于我用的是redhat,所以比较麻烦,需要源码编译,所以首先需要到ctags官网下载,然后上传到服务器,解压后,进入文件夹开始编译: 1.1 源码安装 $cd ctags-x.x $./configure --prefix /path/to/install $make #make install 1.2 写入环境变量 export PATH="/path/to/install/bin:$PATH"

翠湖边上 2658

vim+ctags使用

否则,运行vim的时候还要用“ :settags=”命令设定“tags”文件的路径,这样vim才能找到“tags”文件。即使用户使用了N次“Ctrl+]”查找了N个变量,按N次“Ctrl+t”也能回到最初打开的文件,它会按原路返回。“ :tp”为上一个tag标记文件,“ :tn”为下一个tag标记文件。“*”表示所有文件。这个命令将打开定义“main”(变量或函数或其它)的文件,并把光标定位到这一行。条命令会在当前目录下产生一个“tags”文件,当用户在当前目录中运行vi时,会自动载入此tags文件。

草根上的须子 1112

vim+ctags配置

vim+ctags配置ctags是源代码阅读工具,通常和vim一同使用,可以在vim下轻松的跳跃到我们调用的内核源代码下面 1.下载ctags包:前往下载ctags包 2.解压包 tar -xvf ctags-5.8.tar.gz 3.cd ctags-5.8 4.执行./configure此命令通常是检查平台的特性的,并且生成makefile文件 5.执行make是从makefile文

xixihaha331的博客 946

⚡ Vim 集成 Ctags 基本配置和用法

⚡ Vim 集成 Ctags 基本配置和用法

aitav0的博客 1706

vim ctags学习笔记

vim ctags安装ctagstags文件生成tags文件导入tags文件ctags使用在vim命令行模式下在vim普通模式下针对多个项目的tags设置 安装ctags 解压:#tar xvf ctags-xx.tar.gz 配置Makefle: ./configure 编译&安装:#make & make install tags文件 tags文件包含了用#define定义的宏、函数的定义和声明、变量、类、结构体、枚举、联合及其成员变量及函数 tags文件没有包含函数使用信息,

雪夜的博客 382

ctags的用法 vim ctags , linux ctags , ctags分析代码

vim+ctags用法(转载) [/home/brimmer/src]$ ctags -R"-R"表示递归创建,也就包括源代码根目录下的所有子目录下的源程序。"tags"文件中包括这些对象的列表:l 用#define定义的宏l 枚举型变量的值l 函数的定义、原型和声明l 名字空间(namespace)l 类型定义(typedefs)l 变量(包括定义和声明

dllbl的专栏 1265

VIM & CTAGS for Erlang

VIM & CTAGS for Erlang I pretty much only use VI(M) for coding and CTAGS is essential to increase productivity – It makes it easier to jump through files when I need to look at a function or where so

至 秦 的技术博客 1946
上一篇: [Scarab] Structure and Class Hierarchy
下一篇: [Apache-Torque] Runtime Relevant Classes
Fitzwilliam
博客等级 码龄21年 10粉丝 92原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值