Redis SortedSet 例子

Redis不常用操作指南(基于SpringBoot2.3.2代码实现) 1 前言 通常程序员在学习Redis的安装到使用是非常快速的,因为Redis的大部分操作都等同于Map的操作逻辑,只要了解大部分api结合百度能够快速的投入到CRUD的工作中去,所以今天来一期Redis不常用操作指南,当然这里的不常用更多是不会天天用,但是在项目中还是会有应用到的地方。 2 安装Redis 安装及原生命令 3 SpringBoot2整合Redis(有现成环境的可以略过) 3.1 相关依赖 <!-- 单元测试 --> <dependency> .. 阅读详情

Redis SortedSet 例子


import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.springframework.data.redis.connection.DefaultTuple;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.ScanOptions.ScanOptionsBuilder;

public class TestRedisSortedSet {

	private static JedisConnectionFactory getJedisConnectionFactory() {
		JedisConnectionFactory jcf = new JedisConnectionFactory();
		jcf.setHostName("127.0.0.1");
		jcf.setPort(6379);
		jcf.setPassword("123");
		jcf.afterPropertiesSet();
		return jcf;
	}

	private static RedisConnection getRedisConnection() {
		return getJedisConnectionFactory().getConnection();
	}

	public static void main(String[] args) {
		RedisConnection rc = getRedisConnection();
		
		//ZADD 将一个或多个 member 元素及其 score 值加入到有序集 key 当中。
		boolean zAdd = rc.zAdd("zset".getBytes(), 11, "k".getBytes());
		System.out.println("ZADD [" + zAdd + "]");
		
		Set<Tuple> tuples = new HashSet<Tuple>();
		Tuple tuplev = new DefaultTuple("v".getBytes(), 12d);
		Tuple tuplew = new DefaultTuple("w".getBytes(), 12d);
		tuples.add(tuplev);
		tuples.add(tuplew);
		long mzAdd = rc.zAdd("zset".getBytes(), tuples);
		System.out.println("mzAdd [" + mzAdd + "]");
		
		//ZCARD 返回有序集 key 的基数。
		long zCard = rc.zCard("zset".getBytes());
		System.out.println("ZCARD [" + zCard + "]");
		
		//ZCOUNT 返回有序集 key 中, score 值在 min 和 max 之间(默认包括 score 值等于 min 或 max )的成员的数量。
		long zCount = rc.zCount("salary".getBytes(), 2000, 4000);
		System.out.println("ZCOUNT [" + zCount + "]");
		
		long total = rc.zCount("salary".getBytes(), Range.unbounded());
		System.out.println("total [" + total + "]");
		
		Range range = new Range();
		range.gt(1000);
		range.lt(3000);
		long ltgt = rc.zCount("salary".getBytes(), range);
		System.out.println("ltgt [" + ltgt + "]");
		
		Range range2 = new Range();
		range2.gte(1000);
		range2.lte(3000);
		long ltegte = rc.zCount("salary".getBytes(), range2);
		System.out.println("ltegte [" + ltegte + "]");
		
		//ZINCRBY 为有序集 key 的成员 member 的 score 值加上增量 increment 。
		double zIncrBy = rc.zIncrBy("salary".getBytes(), 0, "Linda".getBytes());
		System.out.println("ZINCRBY [" + zIncrBy + "]");
		
		//ZRANGE 返回有序集 key 中,指定区间内的成员。
		Set<byte[]> zRange = rc.zRange("salary".getBytes(), 0, -1);
		Iterator<byte[]>  itr = zRange.iterator();
		while (itr.hasNext()) {
			System.out.println("ZRANGE [" + new String(itr.next()) + "]");
		}
		
		Set<Tuple> zRangeWithScores = rc.zRangeWithScores("salary".getBytes(), 0, -1);
		Iterator<Tuple> itrTuple = zRangeWithScores.iterator();
		while (itrTuple.hasNext()) {
			Tuple tuple = itrTuple.next();
			System.out.println(tuple.getScore() + " " + new String(tuple.getValue()));
		}
		
		//ZRANGEBYSCORE 返回有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员。有序集成员按 score 值递增(从小到大)次序排列。
		Set<byte[]> zRangeByScore = rc.zRangeByScore("salary".getBytes(), range2);
		Iterator<byte[]> itrzRangeByScore = zRangeByScore.iterator();
		while (itrzRangeByScore.hasNext()) {
			System.out.println("zRangeByScore [" + new String(itrzRangeByScore.next()) + "]");
		}
		
		Set<byte[]> zRangeByScoreWithLimit = rc.zRangeByScore("salary".getBytes(), range2, Limit.limit().offset(1).count(3));
		Iterator<byte[]> iters = zRangeByScoreWithLimit.iterator();
		while (iters.hasNext()) {
			System.out.println("zRangeByScoreWithLimit [" + new String(iters.next()) + "]");
		}
		
		//ZRANK 返回有序集 key 中成员 member 的排名。其中有序集成员按 score 值递增(从小到大)顺序排列。
		long zRank = rc.zRank("salary".getBytes(), "Scott".getBytes());
		System.out.println("ZRANK [" + zRank + "]");
		
		//ZREM 移除有序集 key 中的一个或多个成员,不存在的成员将被忽略。
		long zRem = rc.zRem("zdel".getBytes(), "a".getBytes(), "b".getBytes());
		System.out.println("ZREM [" + zRem + "]");
		
		//ZREMRANGEBYRANK 移除有序集 key 中,指定排名(rank)区间内的所有成员。
		long zRemRange = rc.zRemRange("zdel".getBytes(), 3, 5);
		System.out.println("zRemRange [" + zRemRange + "]");
		
		
		//ZREMRANGEBYSCORE 移除有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员。
		long zRemRangeByScore = rc.zRemRangeByScore("zdel".getBytes(), 0, 5);
		System.out.println("ZREMRANGEBYSCORE [" + zRemRangeByScore + "]");
		
		//ZREVRANGE
		Set<byte[]> zRevRange = rc.zRevRange("salary".getBytes(), 0, -1);
		Iterator<byte[]> itrzRevRange = zRevRange.iterator();
		while (itrzRevRange.hasNext()) {
			System.out.println("ZREVRANGE [" + new String(itrzRevRange.next()) + "]");
		}
		
		Set<Tuple> zRevRangeWithScores = rc.zRevRangeWithScores("salary".getBytes(), 0, -1);
		Iterator<Tuple> itrWithScores = zRevRangeWithScores.iterator();
		while (itrWithScores.hasNext()) {
			Tuple tuple = itrWithScores.next();
			System.out.println("zRevRangeWithScores [" + tuple.getScore() + "  " + new String(tuple.getValue()) + "]");
		}
		
		//ZREVRANGEBYSCORE 返回有序集 key 中, score 值介于 max 和 min 之间(默认包括等于 max 或 min )的所有的成员。有序集成员按 score 值递减(从大到小)的次序排列。
		Set<byte[]> zRevRangeByScore = rc.zRevRangeByScore("salary".getBytes(), 1000, 5000);
		Iterator<byte[]> itrzRevRangeByScore = zRevRangeByScore.iterator();
		while (itrzRevRangeByScore.hasNext()) {
			System.out.println("zRevRangeByScore [" + new String(itrzRevRangeByScore.next()) + "]");
		}
		
		
		
		//ZREVRANK 返回有序集 key 中成员 member 的排名。其中有序集成员按 score 值递减(从大到小)排序。
		long zRevRank = rc.zRevRank("salary".getBytes(), "Tom".getBytes());
		System.out.println("ZREVRANK [" + zRevRank + "]");
		
		//ZSCORE 返回有序集 key 中,成员 member 的 score 值。
		double zScore = rc.zScore("salary".getBytes(), "Jim".getBytes());
		System.out.println("ZSCORE [" + zScore + "]");
		
		//ZUNIONSTORE 计算给定的一个或多个有序集的并集,其中给定 key 的数量必须以 numkeys 参数指定,并将该并集(结果集)储存到 destination 。
		//默认情况下,结果集中某个成员的 score 值是所有给定集下该成员 score 值之 和 。
		long zUnionStore = rc.zUnionStore("salary4".getBytes(), "salary".getBytes(), "salary2".getBytes());
		System.out.println("ZUNIONSTORE [" + zUnionStore + "]");
		
		int[] weights = {2, 4};
		long mzUnionStore = rc.zUnionStore("salary4".getBytes(), Aggregate.MAX, weights, "salary".getBytes(), "salary2".getBytes());
		System.out.println("mzUnionStore [" + mzUnionStore + "]");
		
		//ZINTERSTORE 计算给定的一个或多个有序集的交集,其中给定 key 的数量必须以 numkeys 参数指定,并将该交集(结果集)储存到 destination 。
		//默认情况下,结果集中某个成员的 score 值是所有给定集下该成员 score 值之和.
		long zInterStore = rc.zInterStore("salary5".getBytes(), "salary".getBytes(), "salary2".getBytes());
		System.out.println("zInterStore [" + zInterStore + "]");
		
		long mzInterStore = rc.zInterStore("salary5".getBytes(), Aggregate.MAX, weights, "salary".getBytes(), "salary2".getBytes());
		System.out.println("mzInterStore [" + mzInterStore + "]");
		
		//ZSCAN
		ScanOptionsBuilder sob = ScanOptions.scanOptions().count(1).match("???");
		ScanOptions options = sob.build();
		Cursor<Tuple> zScan = rc.zScan("salary".getBytes(), options);
		while (zScan.hasNext()) {
			Tuple tuple = zScan.next();
			System.out.println("ZSCAN [" + tuple.getScore() + "  " + new String(tuple.getValue()) + "]");
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	}

}

Redis有序集合SortedSet实现原理 实现原理 阅读详情

相关推荐

Redis中的SortedSet类型

Redis的SortedSet是一个可排序的set集合,与Java中的TreeSet有些类似,但底层数据结构却差别很大。SortedSet中的每一个元素都带有一个score属性,可以基于score属性对元素排序,底层的实现是一个跳表(SkipList)加 hash表。可排序:元素按照score属性排序。元素不重复:同一个元素不能多次出现在集合中。查询速度快:由于是基于跳表和hash表实现的,查询元素的速度非常快。因为SortedSet的可排序特性,经常被用来实现排行榜这样的功能。

xycxycooo的博客 1509

使用java scan 大量的redis的key

1、redis配置 import com.soul.data.lettuce.config.AbstractSpringDataRedisConfig; import com.soul.data.redis.core.StringRedisTemplate; import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.interceptor.KeyGenerator; import

微信公众号:一颗向上的草莓 2481

VASP计算层错能(SFE)全攻略2

本文介绍了使用VASP计算纯镍(Ni)层错能(SFE)的具体步骤。首先构建Ni的FCC单胞并扩展为超胞,通过修改原子位置引入堆垛层错;随后分别计算完美晶体和含层错结构的能量;最后通过能量差与层错面积之比求得SFE值。计算需注意k点网格、截断能和超胞尺寸的收敛性测试,并推荐使用PAW赝势和ASE等工具辅助结构构建。

weixin_50519490的博客 1992

Redis研究SCAN

SCAN 命令用于迭代当前数据库中的数据库键。 SSCAN 命令用于迭代集合键中的元素。 HSCAN 命令用于迭代哈希键中的键值对。 ZSCAN 命令用于迭代有序集合中的元素(包括元素成员和元素分值)。 SCAN 命令是一个基于游标的迭代器(cursor based iterator): SCAN 命令每次被调用之后, 都会向用户返回一个新的游标, 用户在下次迭代时需要使用这个新游标作为

逆行者 537

【上海大学计算机组成原理实验报告】六、内存系统实验

学习内存访问机制//理解代码和数据的分区存放原理和技术//手动方式把立即数`33H`写入内存`D1H`单元//手动方式把`D1H`单元的内容读出,再送入`ST`单元//在`CP226`汇编语言程序集成开发环境下编写程序//既然有`ORG`微指令,为什么集成开发环境下载到实验箱的目标程序的第一条执行语句最好存放在0号地址?//上海大学计算机组成原理实验//内存系统实验

HackerKevon的博客 3129

CAN XL和10Base-T1S全对比:在区域架构中如何选择最适合的车载通信协议?

本文深入对比了CAN XL和10Base-T1S在车载网络架构中的性能差异,通过实测数据和典型应用场景分析,为区域架构设计提供选型指南。重点探讨了带宽、延迟、成本等关键指标,帮助工程师在ADAS传感器部署和车身控制网络优化中做出明智选择。

pear55的博客 597

SpringBoot引入Redis报org.springframework.data.redis.core.RedisTemplate类找不到错误

加上此注解就好了

yuyeqianhen的博客 6283

STM32F4_DHT11数字温湿度传感器

开机的时候先检测是否有DHT11存在,如果没有,则提示错误。DHT11和DS18B20相同,传感器输出的都是未编码的二进制数字。本节我们将利用STM32F4来读取DHT11的温湿度传感器,获取环境的温度和湿度值。因此:温湿度的读取方式就是整数部分的二进制转换成十进制放在整数部分;小数部分的二进制转换成十进制放在小数部分。DHT11和MCU的一次通讯时间最大3ms,主机连续向DHT11采样的间隔建议不小于100ms。DHT11是广州奥松有限公司生产的一款温湿度一体化的数字传感器。数据分小数部分和整数部分。

light_2025的博客 3433

spring-boot 项目打包后运行 org/springframework/data/redis/connection/zset/Tuple 错误

妈蛋,jenkins 部署发现启动不了,各种清理都不行,换了 jenkins 上的 maven 版本,清了所有依赖重新拉,都不行。把 redisson-spring-boot-starter 3.18.1 降到 3.17.4 就好了。结果 3.18.1 兼容了本地运行,没兼容打包后的运行,找了我几大个小时一点一点的排查错误。前两天刚把 springboot 2.5.14 升级了 2.7.10。然后试本地打包运行,我去,一直以为是部署问题,结果本地也不行。本地直接启动正常,结果打包后出现问题。

ws - 兮的博客空间 9362

信创改造实战:SpringBoot项目迁移到宝兰德BES 9.5.5的完整避坑指南(附依赖配置)

本文详细介绍了将SpringBoot项目迁移到宝兰德BES 9.5.5中间件的完整流程,包括环境准备、依赖调整、Web.xml版本适配、部署配置优化及常见问题解决方案。特别针对信创改造需求,提供了排除Tomcat依赖、处理BES专用starter等实用技巧,帮助开发者顺利完成国产中间件迁移。

weixin_30825581的博客 1103

RK3576平台Buildroot嵌入式Linux镜像构建实战

嵌入式Linux镜像构建是连接硬件能力与软件功能的核心技术环节,其本质是基于目标SoC架构的交叉编译、内核定制与根文件系统集成过程。原理上依赖工具链适配、设备树绑定、分区镜像生成等关键步骤,技术价值在于实现轻量、确定、可复现的系统交付。典型应用场景涵盖ARM64开发板(如RK3576)、工业边缘网关及国产化信创终端。本文以TaishanPi-3为载体,深入解析Buildroot在RK3576平台上的配置裁剪、并行编译优化、genimage分区合成及update.img烧录准备,覆盖从环境选型(Ubuntu

weixin_36047538的博客 141

对 Redis 中的有序集合SortedSet的理解

本篇说一下Redis中的 有序集合类型,曾几何时,我们想把所有数据存到内存中的 数据结构 中,但为了多机器共享内存,不得不将这块内存包装成wcf单独部署,同时还要考虑怎么序列化,烦心事太...

dotNET跨平台 515

使用Python爬虫抓取政府网站政务信息:公告、通知的自动化抓取与分析

通过结合Requests、BeautifulSoup、Selenium等技术,你能够高效地抓取政府网站的数据,并通过MySQL存储与Pandas分析这些数据。通过自动化手段抓取这些信息,不仅可以提高数据收集的效率,还能够实时获取最新的政务动态,为政策研究、舆情分析等提供宝贵数据。我们将通过Python的Requests、BeautifulSoup、Selenium等工具,结合最新的技术实现一个完整的爬虫系统,帮助你轻松抓取并分析政务信息。通过爬虫,我们可以自动化地从指定网站上抓取公告、新闻、通知等信息。

2201_76125261的博客 1907

Redis中五大数据类型

Redis简单增删改查例子 例一:字符串的增删改查 #增加一个key为ay_key的值 127.0.0.1:6379> set ay_key “ay” OK #查询ay_key的值 127.0.0.1:6379> get ay_key “ay” #修改ay_key的值 127.0.0.1:6379> set ay_key “new_ay” OK 127.0.0.1:6379> get ay_key “new_ay” #修改ay_key名称 127.0.0.1:6379> ren

m0_46220998的博客 92

【Qt图书管理系统】5.完整版源码及下载地址

Qt图书管理系统完整源码下载。

小鱼酱的博客 7003

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Redis常用操作

做分隔符(区分层级),但这只是“命名规范”,实际存储并不是按照层级结构来实现的。Redis 的 key 可以用。SortedSet类型常见命令。List类型常见命令。

2402_85491806的博客 298

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

redis精选04集(集合数据类型set、有序集合sortedset)

redis精选04集(集合数据类型set、有序集合sortedset) python学习目录传送门 文章目录redis精选04集(集合数据类型set、有序集合sortedset)位图操作bitmapHash散列数据类型集合数据类型(set)有序集合(sortedset) 位图操作bitmap 定义 1、位图不是真正的数据类型,它是定义在字符串类型中 2、一个字符串类型的值最多能存储512M字节的内容,位上限:2^32 # 1MB = 1024KB # 1KB = 1024Byte(字节) # 1Byte =

weixin_38640052的博客 249

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

IDEA的使用指南

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

redis使用场景

https://www.cnblogs.com/xiaoxi/p/7007695.html毫无疑问,Redis开创了一种新的数据存储思路,使用Redis,我们不用在面对功能单调的数据库时,把精力放在如何把大象放进冰箱这样的问题上,而是利用Redis灵活多变的数据结构和数据操作,为不同的大象构建不同的冰箱。希望你喜欢这个比喻。 一、Redis常用数据类型 Redis最为常用的数据类型主要有以...

weixin_34050427的博客 117

redis 从入门到遗忘

Key操作 keys * *: 通配任意多个字符 ?: 通配单个字符 []: 通配括号内的某1个字符 exists key 存在返回1,不存在返回0 type key rename oldkey newkey del key 常用数据类型: Redis最为常用的数据类型主要有以下: String Hash List Set Sorted set St...

weixin_30779691的博客 72

【Redis】Redis命令-SortedSet类型

SortedSet从名字来看,首先它是一个set,即集合。同时它是一个SortedSet,也就是可排序的集合。Redis的SortedSet是一个可排序的set集合,与Java中的TreeSet从功能上来讲有些类似,但底层数据结构却差别很大。TreeSet底层是红黑树来实现的,需要定义排序方法;而SortedSet底层排序是根据一个固定的score值来排序的。即我们在SortedSet中存储元素时,需要带上一个score(得分)

qq_39921135的博客 1674

【Redis】SortedSet类型

Redis的SortedSet是一个可排序的set集合,与Java中的TreeSet有些类似,但底层数据结构却差别很大。SortedSet中的每一个元素都带有一个score属性,可以基于score属性对元素排序,底层的实现是一个跳表(SkipList)加 hash表。...

懂得一千零一种,赋予你失败的方法! 1134

Redis SortedSet:高效排序与检索之道

在当今大数据时代,数据存储和检索的效率成为衡量系统性能的关键指标。Redis作为一款高性能的内存数据库,以其卓越的性能和丰富的数据结构在众多场景中得到了广泛应用。SortedSet,作为Redis中的一种数据结构,能够为用户提供有序集合的功能,这在某些特定的应用场景中尤为重要。想象一下,在一个电商平台上,我们需要根据用户的购买金额对用户进行排名,以便进行精准营销。这时,SortedSet就能派上用场,因为它不仅可以存储用户信息,还能根据购买金额进行排序。

我是Java程序员廖志伟,感谢朋友们的支持! 1161

如何用JAVA实现redis的SortedSet的功能

之前面试的时候,被人问到过,如果让你用Java来实现redis的SortedSet,你会使用哪一个类,然后我在我的脑海里面思索能用来排序的类,最后只想到了Treemap,但是很明显,这个答案是错误的,TreeMap是按照key的自然顺序进行排序的,而并非像SortedSet那样按照value进行排序。 其实java中也有一个SortedSet,很明显,看名字就知道,它就是和redis中的那个SortedSet是一个意思。但是Java中的SortedSet...

远方的少年 1211

Redis - 顺序队列 SortedSet

本文详细介绍了如何使用 Redis 的 SortedSet 数据结构实现一个基于时间顺序的博客点赞排行榜系统。

Shad0wLEO的博客 818

Redis从入门到超神-(十一)Redis五大基本结构SortedSet底层原理

有序集合可以看做是在Set集合的的基础上为集合中的每个元素维护了一个顺序值: score,它允许集合中的元素可以按照score进行排序,所以它的经典实用场景如:考生按分数排名,某游戏玩家分数排行,网站首页某数据排行,最新评论按时间排序等等。Redis是一个内存数据库,它在保证读写速度的同时也需要考虑内存开销,那对于SortedSet有序集合而言它需要维护一个顺序值,而对于有序集合的底层实现可以选择:数组,链表,平衡树或者红黑树等结构,但是SortedSet没有选择这些结构。

xuhanyii的博客 1224
上一篇: 学习 EXPLAIN
下一篇: Linux zip 删除zip文件中的一个文件
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值