【设计模式】【第八章】【商品多级分类目录场景】【组合模式+访问者模式】

组合模式+访问者模式 实现商品多级目录分类 商城有很多商品目录,且层级很多。为了对层级目录进行管理,需要满足对层级目录的增删。 阅读详情

创建design-demo项目

项目代码:https://gitee.com/java_wxid/java_wxid/tree/master/demo/design-demo
项目结构如下(示例):
在这里插入图片描述

创建ItemController

代码如下(示例):

package com.example.designdemo.controller;

import com.example.designdemo.items.node.ProductItem;
import com.example.designdemo.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
 * @Author: zhiwei Liao
 * @Date: 2022/9/29 21:29
 * @Description:
 */
@RestController
public class ItemController {
    @Autowired
    private ItemService itemService;

    @GetMapping("get")
    public ProductItem getItem() {
        return itemService.getItem();
    }

    @PostMapping("del")
    public ProductItem delItem(@RequestBody ProductItem productItem) {
        return itemService.delItem(productItem);
    }

    @PostMapping("add")
    public ProductItem addItem(@RequestBody ProductItem productItem) {
        return itemService.addItem(productItem);
    }

}

创建ItemService

代码如下(示例):

package com.example.designdemo.service;

import com.example.designdemo.items.node.ProductItem;

/**
 * @Author: zhiwei Liao
 * @Date: 2022/9/29 21:29
 * @Description:
 */
public interface ItemService {

    ProductItem getItem();

    ProductItem delItem(ProductItem productItem);

    ProductItem addItem(ProductItem productItem);

}

创建ItemServiceimpl

代码如下(示例):

package com.example.designdemo.service.impl;

import com.example.designdemo.MockDb;
import com.example.designdemo.items.node.ProductItem;
import com.example.designdemo.items.visitor.AddItemVisitor;
import com.example.designdemo.items.visitor.DelItemVisitor;
import com.example.designdemo.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * @Author: zhiwei Liao
 * @Date: 2022/9/29 21:29
 * @Description:
 */
@Service
public class ItemServiceimpl implements ItemService {
    @Autowired
    private DelItemVisitor delItemVisitor;

    @Autowired
    private AddItemVisitor addItemVisitor;

    //这部分只有初始化的时候获取一次 或者 直接预热到缓存中
    public ProductItem getItem() {
        System.out.println("从DB 获取所有的目录");
        System.out.println("将数据组装为 ProductItem");
        System.out.println("将组装好的 ProductItem 放入缓存中,永不过期 ");
        return MockDb.ProductItem;
    }

    public ProductItem delItem(ProductItem productItem) {
        ProductItem item = delItemVisitor.visitor(productItem);
        MockDb.ProductItem = item;
        System.out.println("update db");
        return item;
    }

    public ProductItem addItem(ProductItem productItem) {
        ProductItem item = addItemVisitor.visitor(productItem);
        MockDb.ProductItem = item;
        System.out.println("update db");
        return item;
    }
}

创建ItemVisitor

代码如下(示例):

package com.example.designdemo.items.visitor;


import com.example.designdemo.items.node.ProductItem;
/**
 * @Author: zhiwei Liao
 * @Date: 2022/9/29 21:29
 * @Description:
 */
public interface ItemVisitor<T> {
    T visitor(ProductItem productItem);
}

创建DelItemVisitor

代码如下(示例):

package com.example.designdemo.items.visitor;

import com.example.designdemo.MockDb;
import com.example.designdemo.items.node.ProductItem;
import org.springframework.stereotype.Component;
/**
 * @Author: zhiwei Liao
 * @Date: 2022/9/29 21:29
 * @Description:
 */
@Component
public class DelItemVisitor implements ItemVisitor<ProductItem>{
    // 入参是 id 2, pid为 1
    @Override
    public ProductItem visitor(ProductItem productItem) {
        ProductItem currentItem = MockDb.ProductItem; //  从缓存来的 to do
        if(productItem.getId() == currentItem.getId()) {
            throw new UnsupportedOperationException("根节点不能删。");
        }
        if(productItem.getPid() == currentItem.getId()) {
            currentItem.removeChild(productItem);
            return currentItem;
        }
        delChild(productItem, currentItem);
        return currentItem;
    }

    private void delChild(ProductItem productItem, ProductItem currentItem) {
        for(ProductItem item : currentItem.getChild()) {
            if(item.getId() == productItem.getPid()) {
                item.removeChild(productItem);
                break;
            } else {
                delChild(productItem, item);
            }
        }
    }
}

创建AddItemVisitor

代码如下(示例):

package com.example.designdemo.items.visitor;

import com.example.designdemo.MockDb;
import com.example.designdemo.items.node.ProductItem;
import org.springframework.stereotype.Component;
/**
 * @Author: zhiwei Liao
 * @Date: 2022/9/29 21:29
 * @Description:
 */
@Component
public class AddItemVisitor implements ItemVisitor<ProductItem>{
    // 入参是 id 2, pid为 1
    @Override
    public ProductItem visitor(ProductItem productItem) {
        ProductItem currentItem = MockDb.ProductItem; //  从缓存来的 to do
        if(productItem.getId() == currentItem.getId()) {
            throw new UnsupportedOperationException("根节点是唯一的。");
        }
        if(productItem.getPid() == currentItem.getId()) {
            currentItem.addChild(productItem);
            return currentItem;
        }
        addChild(productItem, currentItem);
        return currentItem;
    }

    private void addChild(ProductItem productItem, ProductItem currentItem) {
        for(ProductItem item : currentItem.getChild()) {
            if(item.getId() == productItem.getPid()) {
                item.addChild(productItem);
                break;
            } else {
                addChild(productItem, item);
            }
        }
    }
}

创建ProductItem

代码如下(示例):

package com.example.designdemo.items.node;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
 * @Author: zhiwei Liao
 * @Date: 2022/9/29 21:29
 * @Description:
 */
public class ProductItem extends AbstractProductItem{
    private int id;
    private int pid;
    private String name;
    private List<ProductItem> child = new ArrayList<>();

    @Override
    public void removeChild(AbstractProductItem item) {
        ProductItem removeItem = (ProductItem) item;
        this.child = child.stream().filter(x->x.getId() != removeItem.getId()).collect(Collectors.toList());
    }

    @Override
    public void addChild(AbstractProductItem item) {
        this.child.add((ProductItem) item);
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getPid() {
        return pid;
    }

    public void setPid(int pid) {
        this.pid = pid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<ProductItem> getChild() {
        return child;
    }

    public void setChild(List<ProductItem> child) {
        this.child = child;
    }
}

创建AbstractProductItem

代码如下(示例):

package com.example.designdemo.items.node;
/**
 * @Author: zhiwei Liao
 * @Date: 2022/9/29 21:29
 * @Description:
 */
public abstract class AbstractProductItem {
    public abstract void removeChild(AbstractProductItem item);
    public abstract void addChild(AbstractProductItem item);
}

创建MockDb

代码如下(示例):

package com.example.designdemo;


import com.example.designdemo.items.node.ProductItem;

import java.util.ArrayList;
import java.util.List;
/**
 * @Author: zhiwei Liao
 * @Date: 2022/9/29 21:29
 * @Description:
 */
public class MockDb {
    public static com.example.designdemo.items.node.ProductItem ProductItem = new ProductItem();
    static {
        ProductItem.setId(1);
        ProductItem.setPid(0);
        ProductItem.setName("书籍");
        List<ProductItem> child = new ArrayList<>();
        ProductItem c1 = new ProductItem();
        c1.setId(2);
        c1.setPid(1);
        c1.setName("技术书籍");
        ProductItem c2 = new ProductItem();
        c2.setId(3);
        c2.setPid(1);
        c2.setName("历史书籍");
        List<ProductItem> child1 = new ArrayList<>();
        ProductItem c3 = new ProductItem();
        c3.setId(4);
        c3.setPid(2);
        c3.setName("并发编程");
        ProductItem c4 = new ProductItem();
        c4.setId(5);
        c4.setPid(2);
        c4.setName("JVM");
        child1.add(c3);
        child1.add(c4);
        c1.setChild(child1);
        child.add(c1);
        child.add(c2);
        ProductItem.setChild(child);
    }
}

多级分类的数据库设计 1.表为两张,一张分类表,一张信息表。  表1:  `ID` int(10), `cID` tinyint(3) , `title` varchar(255), 表2: `cID` tinyint(3) , `parentID` tinyint(3), `order` tinyint(3) , `name` varchar(255), 这样可以根据c 阅读详情

相关推荐

构建多级文件目录管理项目

CFileDirectory类是MFC提供的一个用于目录管理的类。通过该类,开发者可以创建、删除、遍历目录,甚至查看目录属性。使用该类创建层叠目录时,需要调用相应的成员函数来完成任务。// 创建目录的示例代码代码段中的pathName参数指定了要创建的目录路径,而省略的其他参数用于设置目录的属性,如权限。CFileDirectory类是Microsoft Foundation Classes (MFC)中一个用于管理文件目录的类。

weixin_29092787的博客 405

组合模式:多级好友列表展示

一、模式定义 组合模式允许你将对象组合成树形结构来表现“整体/部分”层次结构。组合能让客户以一致的方式处理个别对象以及对象组合。 相关组件 Component:组合中所有对象定义的一个接口(或抽象类)。 Leaf:叶节点没有孩子。 Composite:包含一个或多个子节点的组件。 Client:客户端。 二、举例说明 场景:当对象的结构需要树形方式来表示时,使用组合模式。 需求:为了更细...

咔咔学长 355

别再手动转格式了!用Java+LibreOffice命令行实现Word批量转PDF(附Docker部署避坑指南)

本文详细介绍了如何利用Java和LibreOffice命令行实现企业级Word批量转PDF的自动化解决方案,包括多线程优化、Docker化部署及常见问题排查。通过代码示例和实战经验,帮助开发者高效处理文档转换需求,提升工作效率并避免常见陷阱。

552

多级分类表和页面该如何设计呢

在数据库设计中,经常会遇到类别,组织机构等多级设计。那应该如何设计呢?本文就介绍下,一个多级分类表的设计。

sinat_29049969的博客 2099

EndNote全文检索实战:如何快速配置学校图书馆资源并精准查找文献

本文详细介绍了EndNote全文检索功能的实战配置方法,核心在于通过正确设置OpenURL链接解析器,无缝对接学校图书馆资源,实现一键精准获取文献全文。文章提供了从理解机制、四步配置法到进阶技巧的完整指南,帮助科研人员高效管理海量PDF,构建个人知识体系,大幅提升文献调研与写作效率。

weixin_29228781的博客 280

【Benchmark 性能测试全指南:从核心原理到 CINEBENCH 实战解析】

本文深度拆解基准测试(Benchmark)的底层逻辑,详解数据集、工作负载、度量指标三大核心要素,分步演示测试流程与统计分析要点。结合 CINEBENCH R23 实战案例,揭秘 CPU 性能评估方法论,助你掌握系统性能量化与优化的核心技能。

rong_ha_ha的博客 6334

mysql多级分类设计

在数据库设计中,经常会遇到需要存储多级分类信息的情况,如商品分类、地区分类等。本文将详细介绍如何在MySQL中设计和管理多级分类数据MPTT算法是一种用于处理树状结构数据的算法,其中MPTT代表Modified Preorder Tree Traversal(修改的先序遍历树遍历)。它通过为树中的每个节点分配一个预排序值来组织和表示树的结构。这种预排序值允许我们以一维的方式存储和操作树,同时保持树的层次结构和父子关系。

qq_40861391的博客 6366

WPS JS宏实战:批量调整200个Word表格格式的避坑指南(附完整代码)

本文提供了一份详尽的WPS JS宏实战指南,针对批量调整大量Word表格格式的需求。文章深入解析了如何利用JS宏自动化设置字体、行距和边框,并重点解决了常见的“首行访问报错”等核心难题,附有可直接使用的完整代码,帮助用户显著提升文档处理效率。

weixin_29280219的博客 431

多级分类、菜单等的数据库设计(一张表),以及mybatis-plus的多级分类查询(一条SQL语句)

我们在项目开发过程,经常会遇到有文章分类分栏,菜单分类,视频分类等多级分类 那么这种多级分类我们在数据中又是如何设计的呢?在mybatis查询过程中又是如何多级查询的呢? 别着急,今年我们来解决这个需求, 当然,解决的方法有很多,这里我只介绍我自己使用的一种,有更好的方法可以评论区评论大家一起探讨 本次用到了 `Maven工程`、`Swagger`、`RESTful接口风格`、`MyBatis-Plus`

小袁同学的博客 1万+

水与光的奇妙“切割之舞”:水导激光切割技术探秘

水导激光切割技术的诞生,是材料加工领域不断追求高精度、高质量加工的成果。传统激光切割技术在加工过程中,材料会因瞬间高温而产生热变形、热影响区大以及切割面粗糙等问题,这些弊端在对一些高精度、热敏性材料的加工中尤为突出 ,迫切需要一种新的技术来克服这些难题。水导激光切割技术的起源可以追溯到 20 世纪 80 年代。1986 年,德国公司 Aesculap-Werke AG 首次提出了将水流引入激光切割过程的创新想法,并制造出首代水导激光设备。不过,当时的技术尚处于雏形阶段,仅仅是在光纤出口添加了一小柱水流,激光

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 1675

低功耗边缘设备部署指南:YOLO26 INT8量化与TensorRT加速全流程

将YOLO26 INT8部署到低功耗边缘设备,核心原则是“校准为王、敏感层精准回退、端到端验证”。校准集≥500张,来自真实推理场景,未经训练增强校准集预处理与推理pipeline逐行对齐trtexec命令必带--fp16作为fallback量化后用polygraphy定位敏感层,而非盲猜仅回退必要层(通常2-3个),保留INT8收益在真实部署场景测试集上验证mAP,不以COCO为准C++部署使用异步推理+双缓冲nsys profiling确认无传输瓶颈。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 216

设计无限级分类

产品分类,多级的树状结构的论坛,邮件列表等许多地方我们都会遇到这样的问题:如何存储多级结构的数据?在PHP的应用中,提供后台数据存储的通常是关系 型数据库,它能够保存大量的数据,提供高效的数据检索和更新服务。然而关系型数据的基本形式是纵横交错的表,是一个平面的结构,如果要将多级树状结构存储 在关系型数据库里就需要进行合理的翻译工作。接下来我会将自己的所见所闻和一些实用的经验和大家探讨一下: 层级

jfcat的专栏 5663

3、Tone Mapping色调映射(Advanced High Dynamic Range Imaging )

3、Tone Mapping色调映射(Advanced High Dynamic Range Imaging) 如今,大多数可用的显示设备无法本地显示HDR内容。 入门级显示器的对比度仅为200:1。 尽管高端液晶电视具有更高的对比度,但平均对比度约为10,000:1,但通常每个色彩通道的离散度为8位,很少为10位。 这意味着色调限制为255。在过去的二十年中,研究人员花费了大量时间和精力来压缩HDR图像和视频的范围,以便可以在LDR显示器上更“自然”地看到数据。 图3.1 色调映射和真实场景之间.

ISP行业的忠实粉丝 1866

在多级分类表设计中获取某个分类以下或以上的所有分类

1.获取某个分类以上的所有分类 SELECT CONCAT( IFNULL( CONCAT( t5.category_name, '>' ), '' ), IFNULL( CONCAT( t4.category_name, '>' ), '' ), IFNULL( CONCAT( t3.category_name, '>' ), '' ), IFNULL( CONCAT( t2.category_name, '>' ), '' ), IFNULL( t1.c

qq_29001173的博客 433

ZYNQ 7020 之 FPGA知识点重塑笔记一——串口通信

通信方式一般分为串行通信和并行通信。并行通信是指多比特数据同时通过并行线进行传送。这种传输方式通信线多、成本高,故不宜进行远距离通信,通常传输距离小于 30 米。串行通信是指数据在一条数据线上,一比特接一比特地按顺序传送的方式。这种运输方式通常节省传输线,大大降低使用成本,但数据传送速度慢。综上可知,串行通信主要应用于长距离、低速率的通信场合。本次实验我们主要讲解下串行通信。串行通信一般有2种通信方式:同步串行通信和异步串行通信。同步串行通信。

m0_51430584的博客 3097

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

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

Django项目实践(商城):十二、商品信息数据库设计

(根据居然老师直播课内容整理) 一、SPU和SKU 在电商中对于商品,有两个重要的概念:SPU和SKU

laoluobo76的博客 1856

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

在商城系统开发时遇到商品的多级分类,为增强扩展性,子类可以任意添加,此类问题数据库如何设计...

表结构为: id(编号) name(分类名) parentID(父类编号) 简单举例如下: id name parentID 1 饮料 0(为0表示第一大类) 2 水果 0 3百事可乐1 4 雪碧 1 5 苹果    2 6 香...

weixin_34112208的博客 1246

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

MySQL电商多级分类表设计方案对比

本文通过宠物分类示例,详细介绍了三种多级分类表的设计和查询方法,并进行了性能对比,希望能为读者提供有价值的参考。

驴大毛的博客 1583

多级别分类的页面显示

在做项目的时候,有时会遇到多级别分类(从数据库里取出)的问题,比如一级分类:(必须存在)        二级分类:(可有可无)                 条目:(如果二级分类别存在,在显示在二级分类下,不存在二级分类,显示在所属大类下)需要实现的页面样式:                 Math(大类)           Math1(小类)                M条目一    

旭旭的专栏 2203

设计模式--组合模式--商品排序案例

全部的样例均来源与实际开发项目 本节介绍组合模式的使用–商品结果排序评分系统 首先还是反复一下:设计模式是思路。而不是一味套用,假设业务场景和功能需求恰好吻合。那最好只是。假设有偏差。一定要详细情况详细分析,更具实际场景选择合适的模式类型(注意。是类型,并不特定指某种模式,有的时候一个场景多种模式都能够做) 本节所举得样例为商品结果排序评分系统,也就是非常多项目中,...

aoe41606的博客 390

多级目录数据表设计

多级目录数据表设计 在实际工作中,经常碰到需要多级目录的情况,而且为了灵活扩展,这种分级是没有限制的,也就是说设计者,不限制用户设定多少级目录。   当前目录ID:catalogueId 目录名称:name 目录级别ID:gradeId 父级目录ID:piarentId    字段 类型 约束 说明 catalogue

hins 1万+

数据库设计-多级栏目(标题)分类设计

数据库设计-多级栏目(标题)分类设计 文章目录数据库设计-多级栏目(标题)分类设计栏目表内容表 栏目表 id cid cname 主键 栏目级别id 栏目名 栏目cid:一级栏目,二级栏目,三级栏目… 1.深入理解多级栏目分类: 一级的cid: 都为0 (设为0的原因:逻辑落实时,便于区分出哪些为一级,自行敲代码体会其中的逻辑) 二级的cid:其父级(一级)的主键id 三级的cid:其父级(二级)的主键id 类推… 2.例子如图: 内容表 id cid content

学习学习学习学习 2718

三级分类菜单的数据库设计

http://www.imooc.com/article/285246?block_id=tuijian_wz 最近在设计一款进销存系统的时候,遇到一个分类的设计问题,就是如何将分类设计成数据库里的表,怎么样设计才比较灵活? 举个例子,一级分类:生鲜类,二级分类:蔬菜类,三级分类:青菜类,如果你将这三个分类设计成三张表然后连表查询,貌似也没什么不妥,但是,一张表就一个主键一个...

james_laughing的博客 1万+
上一篇: 【设计模式】【第七章】【第三方登录场景】【桥接模式】
下一篇: 【设计模式】【第九章】【设计模式小结】
Java程序员廖志伟
Java程序员廖志伟 优质创作者: Java技术领域 优质创作者: Java技术领域 领域专家: 后端开发技术领域 领域专家: 后端开发技术领域
博客等级 码龄8年 2万+粉丝 1902原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Java程序员廖志伟

赏我包辣条呗

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值