-
generating user vectors
Input format
userID: itemID1 itemID2 itemID3 ....
Output format
a Vector from all item IDs for the user, and outputs the user ID mapped to the user’s preference vector. All values in this vector are 0 or 1. For example, 98955 / [590:1.0, 22:1.0, 9059:1.0]
package mia.recommender.ch06; import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; import org.apache.mahout.math.VarLongWritable; public final class WikipediaToItemPrefsMapper extends Mapper<LongWritable, Text, VarLongWritable, VarLongWritable> { private static final Pattern NUMBERS = Pattern.compile("(\\d+)"); @Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { String line = value.toString(); Matcher m = NUMBERS.matcher(line); m.find(); VarLongWritable userID = new VarLongWritable(Long.parseLong(m.group())); VarLongWritable itemID = new VarLongWritable(); while (m.find()) { itemID.set(Long.parseLong(m.group())); context.write(userID, itemID); } } }
package mia.recommender.ch06; import java.io.IOException; import org.apache.hadoop.mapreduce.Reducer; import org.apache.mahout.math.RandomAccessSparseVector; import org.apache.mahout.math.VarLongWritable; import org.apache.mahout.math.VectorWritable; import org.apache.mahout.math.Vector; public class WikipediaToUserVectorReducer extends Reducer<VarLongWritable, VarLongWritable, VarLongWritable, VectorWritable> { public void reduce(VarLongWritable userID, Iterable<VarLongWritable> itemPrefs, Context context) throws IOException, InterruptedException { Vector userVector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); for (VarLongWritable itemPref : itemPrefs) { userVector.set((int) itemPref.get(), 1.0f); } context.write(userID, new VectorWritable(userVector)); } }
-
calculating co-occurrence
Input format
user IDs mapped to Vectors of user preferences—the output of the above MapReduce. For example, 98955 / [590:1.0,22:1.0,9059:1.0]
Output format
rows—or columns—of the co-occurrence matrix. For example,590 / [22:3.0,95:1.0,...,9059:1.0,...]
package mia.recommender.ch06; import java.io.IOException; import java.util.Iterator; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.mapreduce.Mapper; import org.apache.mahout.math.VarLongWritable; import org.apache.mahout.math.VectorWritable; import org.apache.mahout.math.Vector; public class UserVectorToCooccurrenceMapper extends Mapper<VarLongWritable, VectorWritable, IntWritable, IntWritable> { public void map(VarLongWritable userID, VectorWritable userVector, Context context) throws IOException, InterruptedException { //Iterator<Vector.Element> it = userVector.get().iterateNonZero(); Iterator<Vector.Element> it = userVector.get().nonZeroes().iterator(); while (it.hasNext()) { int index1 = it.next().index(); // Iterator<Vector.Element> it2 = userVector.get().iterateNonZero(); Iterator<Vector.Element> it2 = userVector.get().nonZeroes().iterator(); while (it2.hasNext()) { int index2 = it2.next().index(); context.write(new IntWritable(index1), new IntWritable(index2)); } } } }
package mia.recommender.ch06; import java.io.IOException; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.mapreduce.Reducer; import org.apache.mahout.math.RandomAccessSparseVector; import org.apache.mahout.math.Vector; import org.apache.mahout.math.VectorWritable; public class UserVectorToCooccurrenceReducer extends Reducer<IntWritable, IntWritable, IntWritable, VectorWritable> { public void reduce(IntWritable itemIndex1, Iterable<IntWritable> itemIndex2s, Context context) throws IOException, InterruptedException { Vector cooccurrenceRow = new RandomAccessSparseVector( Integer.MAX_VALUE, 100); for (IntWritable intWritable : itemIndex2s) { int itemIndex2 = intWritable.get(); cooccurrenceRow.set(itemIndex2, cooccurrenceRow.get(itemIndex2) + 1.0); } context.write(itemIndex1, new VectorWritable(cooccurrenceRow)); } }
-
rethinking matrix multiplication
conventional matrix multiplication
The conventional algorithm necessarily touches the entire co-occurrence matrix, because it needs to perform a vector dot product with each row.
alternative matrix compuatation
But note that wherever element i of the user vector is 0, the loop iteration can be skipped entirely, because the product will be the zero vector and doesn’t affect the result. So this loop need only execute for each nonzero element of the user vector. The number of columns loaded will be equal to the number of preferences that the user expresses, which is far smaller than the total number of columns when the user vector is sparse.
-
matrix multiplication by partial products
The columns of the co-occurrence matrix are available from an earlier step. Because the matrix is symmetric, the rows and columns are identical, so this output can be viewed as either rows or columns, conceptually. The columns are keyed by item ID, and the algorithm must multiply each by every nonzero preference value for that item, across all user vectors. That is, it must map item IDs to a user ID and preference value,and then collect them together in a reducer. After multiplying the co-occurrence col-
umn by each value, it produces a vector that forms part of the final recommender vector R for one user.
The difficult part here is that two different kinds of data are joined in one computation: co-occurrence column vectors and user preference values. This isn’t by naturepossible in Hadoop, because values in a reducer can be of one Writable type only. A clever implementation can get around this by crafting a Writable that contains either one or the other type of data: a VectorOrPrefWritable.
The mapper phase here will actually contain two mappers, each producing different types of reducer input:
- Input for mapper 1 is the co-occurrence matrix: item IDs as keys, mapped to columns as Vectors. For example, 590 / [22:3.0,95:1.0,...,9059:1.0,...] The map function simply echoes its input, but with the Vector wrapped in a VectorOrPrefWritable.
- Input for mapper 2 is again the user vectors: user IDs as keys, mapped to preference Vectors. For example, 98955 / [590:1.0,22:1.0,9059:1.0] For each nonzero value in the user vector, the map function outputs an item ID mapped to the user ID and preference value, wrapped in a VectorOrPrefWritable. For example, 590 / [98955:1.0]
- The framework collects together, by item ID, the co-occurrence column and all user ID–preference value pairs.
- The reducer collects this information into one output record and stores it.
package mia.recommender.ch06; import java.io.IOException; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.mapreduce.Mapper; import org.apache.mahout.cf.taste.hadoop.item.VectorOrPrefWritable; import org.apache.mahout.math.VectorWritable; public class CooccurrenceColumnWrapperMapper extends Mapper<IntWritable, VectorWritable, IntWritable, VectorOrPrefWritable> { public void map(IntWritable key, VectorWritable value, Context context) throws IOException, InterruptedException { context.write(key, new VectorOrPrefWritable(value.get())); } }
package mia.recommender.ch06; import java.io.IOException; import java.util.Iterator; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.mapreduce.Mapper; import org.apache.mahout.cf.taste.hadoop.item.VectorOrPrefWritable; import org.apache.mahout.math.VarLongWritable; import org.apache.mahout.math.Vector; import org.apache.mahout.math.VectorWritable; public class UserVectorSplitterMapper extends Mapper<VarLongWritable, VectorWritable, IntWritable, VectorOrPrefWritable> { public void map(VarLongWritable key, VectorWritable value, Context context) throws IOException, InterruptedException { long userID = key.get(); Vector userVector = value.get(); // Iterator<Vector.Element> it = userVector.iterateNonZero(); Iterator<Vector.Element> it = userVector.nonZeroes().iterator(); IntWritable itemIndexWritable = new IntWritable(); while (it.hasNext()) { Vector.Element e = it.next(); int itemIndex = e.index(); float preferenceValue = (float) e.get(); itemIndexWritable.set(itemIndex); context.write(itemIndexWritable, new VectorOrPrefWritable(userID, preferenceValue)); } } }Technically speaking, there is no real Reducer following these two Mappers; it’s no longer possible to feed the output of two Mappers into a Reducer. Instead they’re run separately, and the output is passed through a no-op Reducer and saved in two locations.These two locations can be used as input to another MapReduce, whose Mapper does nothing as well, and whose Reducer collects together a co-occurrence column vector for an item and all users and preference values for that item into a single entity called
VectorAndPrefsWritable. ToVectorAndPrefReducer implements this; for brevity, this detail is omitted.
相关推荐
You will learn about Mahout building blocks, addressing feature extraction, reduction and the curse of dimensionality, delving into classification use cases with the random forest and Naïve Bayes ...
内容概要:本文详细介绍了作者基于台湾28nm工艺复现刘纯成论文中的10bit 250Msps异步SAR ADC电路的设计过程。文中重点讨论了异步时序控制的优势及其具体实现方法,如通过比较器输出触发逐次逼近,避免了传统同步SAR所需的时钟分配网络,从而降低了功耗并提高了效率。此外,还探讨了电容阵列设计、比较器设计以及异步脉冲生成电路等方面的技术细节,并分享了针对寄生参数导致的误差进行软件补偿的方法。最终,该设计实现了3.8mW的超低功耗,在TT工艺角下SNDR达到58.2dB。 适合人群:从事模拟集成电路设计的研究人员和技术爱好者,尤其是关注高速低功耗ADC设计的人群。 使用场景及目标:适用于希望深入了解异步SAR ADC设计原理及其优化技巧的专业人士。目标是为相关领域的研究提供参考案例,帮助读者掌握先进的设计思路和技术手段。 其他说明:本文不仅提供了理论分析,还包括具体的代码片段(如VerilogA和Matlab)用于辅助理解和实施设计方案。同时,文中提到的实际测试数据也为评估设计效果提供了依据。
实训商业源码-参照米家APP布局和样式,编写的一款智能家居小程序smart-home-论文模板.zip
内容概要:本文深入探讨了基于模糊PID控制的永磁同步电机(PMSM)仿真系统的设计与实现。首先介绍了传统PID控制存在的局限性,如参数固定导致的响应迟缓和抗干扰能力不足等问题。接着详细阐述了模糊PID控制的优势及其具体实施方法,包括构建双闭环控制模型、电流环参数计算以及模糊控制器的设计要点。文中还提供了具体的MATLAB代码用于计算电流环PI参数,并展示了如何利用Simulink中的Fuzzy Logic Controller模块来设置输入输出变量的隶属度函数和制定模糊规则库。实验结果显示,在相同条件下,模糊PID控制相比传统PID控制表现出更低的超调量、更快的调节时间和更好的鲁棒性。最后讨论了将模糊规则应用于实际控制器的可能性。 适用人群:从事电机控制相关工作的工程师和技术人员,尤其是希望提升PMSM性能的研究者。 使用场景及目标:适用于需要提高PMSM控制精度和效率的应用场合,如工业自动化设备、电动汽车等领域。目标是通过引入模糊PID控制技术,改善系统的动态响应特性并增强稳定性。 其他说明:附有详细的参考文献和说明文档,帮助读者更好地理解和复现整个仿真过程。同时强调了理论仿真向工程实践转化过程中需要注意的问题。
内容概要:本文详细介绍了降压BUCK变换器的工作原理及其在双闭环控制下的具体实现方法。首先概述了降压BUCK变换器作为关键电压调节元件的重要地位,接着重点阐述了双闭环控制系统的设计理念——即电压外环采用线性自抗扰LADRC控制,电流内环运用PID控制,以此确保即使在变负载条件下也能维持稳定的5V输出。文中还提供了简单的代码示例,帮助读者更好地理解和实际操作这种复杂的控制机制。最后强调了此类技术对于提高电子设备性能和寿命的关键意义。 适用人群:从事电力电子、自动化控制等相关领域的工程师和技术人员,尤其是那些关注高效能电源管理系统的人士。 使用场景及目标:适用于需要深入了解并掌握降压BUCK变换器内部运作机制的专业人士;旨在为他们提供一套完整的理论指导与实践经验相结合的学习资料,以便于他们在实际项目中应用这些先进的控制技术和算法。 其他说明:文章不仅限于理论讲解,还包括具体的编程实例,有助于加深理解。同时,所讨论的技术和方法可以直接应用于工业生产中的各类电子产品设计中,如通信基站、服务器集群等对供电质量要求极高的场合。
实训商业源码-智慧表单流程V8.3.0-论文模板.zip
基于javaScript实现的dcl订货系统+源码,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档 基于javaScript实现的dcl订货系统+源码,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档~ 基于javaScript实现的dcl订货系统+源码,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档 基于javaScript实现的dcl订货系统+源码,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档 基于javaScript实现的dcl订货系统+源码,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档 基于javaScript实现的dcl订货系统+源码,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档
内容概要:本文档详细介绍了基于大数据技术的房价评估系统的设计与实现过程。文档首先阐述了项目背景及研究意义,指出随着房地产市场的不断发展,传统房价评估方法已无法满足精准性和时效性的需求。接着,文中对大数据技术进行了概述,包括数据采集、预处理、存储、分析等关键技术环节,并结合房价评估的实际需求,提出了基于大数据平台(如Hadoop、Spark)构建分布式计算环境的解决方案。然后,重点描述了模型选择与优化部分,对比了多种机器学习算法(如线性回归、决策树、随机森林、支持向量机等),最终确定了适合本系统的预测模型。此外,还探讨了特征工程的重要性,通过筛选和构造有效特征来提高模型性能。最后,给出了系统的架构设计图,解释了从前端用户界面到后端服务器的具体流程,以及如何利用API接口进行数据交互。 适合人群:从事数据分析、算法开发、软件工程等相关领域的技术人员,特别是那些对大数据处理技术和房价预测感兴趣的从业者或研究人员。 使用场景及目标:①帮助开发者理解并掌握如何运用大数据技术解决实际问题;②为房地产行业提供一种新的、更高效的房价评估工具;③促进跨学科领域之间的交流合作,推动智能城市建设与发展。 其他说明:文档中包含了大量的图表和代码片段,有助于读者更加直观地理解整个项目的实施步骤和技术细节。同时,附录部分提供了完整的实验数据集和测试结果,便于有兴趣的读者进一步验证和改进该系统。
实训商业源码-响应式精美列表商城发卡源码-论文模板.zip
实训商业源码-月老在线牵盲盒交友盲盒一元交友存取小纸条小程序版本-论文模板.zip
基于Python实现电信客户流失预测与分析的代码实现(课程设计),个人经导师指导并认可通过的高分设计项目,评审分98分,项目中的源码都是经过本地编译过可运行的,都经过严格调试,确保可以运行!主要针对计算机相关专业的正在做大作业、毕业设计的学生和需要项目实战练习的学习者,资源项目的难度比较适中,内容都是经过助教老师审定过的能够满足学习、使用需求,如果有需要的话可以放心下载使用。 基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基于Python实现电信客户流失预测与分析的代码实现(课程设计)基
毕业设计-交友盲盒-整站商业源码.zip
实训商业源码-家政服务小程序 V2.7.1-论文模板.zip
通过Proteus仿真软件实现,按键控制8个LED的闪烁。Proteus电路中使用GPIOB口实现。使用标准库。
内容概要:本文总结了GitHub上多个领域的高星项目,包括AI与机器学习、开发工具与框架、数据库与数据管理、机器人学与自动化、嵌入式与物联网五个方面。在AI与机器学习领域,有被誉为“开源版Firebase替代方案”的Supabase、阿里的Qwen3大模型和MiniCPM-o系列多模态大语言模型;开发工具与框架方面,Budibase适合构建内部工具,NocoBase是开源无代码/低代码开发平台,GrapesJS则偏重前端HTML模板设计;数据库与数据管理领域,Chat2DB是智能化数据库管理工具,PocketBase是轻量级后端框架;机器人学与自动化方面,LeRobot是Hugging Face的机器人开发平台,Windmill是开发者平台和工作流引擎;嵌入式与物联网领域,Avem是轻量级无人机飞控项目,FreeModbus是开源Modbus协议栈。; 适合人群:对各技术领域感兴趣的开发者、研究人员和相关从业者。; 使用场景及目标:①为开发者提供前沿技术和项目的参考,帮助选择合适的工具和技术栈;②为研究人员提供研究方向和实验平台;③为企业从业者提供高效解决方案。; 其他说明:这些项目均在GitHub上获得高关注度,具有较高的参考价值,用户可以根据自身需求深入研究相关项目。
内容概要:本文详细介绍了APFC电路及其两种具体类型的仿真模型——单相PFC电路和单相Boost PFC电路。文中解释了APFC电路的作用机制,即通过调整电路工作模式使输入电流与电压同相位,提高功率因数。重点讨论了这两种电路采用的电压外环电流内环双闭环控制策略,包括具体的控制逻辑和PWM信号调节方法。此外,还提供了简化的Python代码片段展示电路模型的初始化和控制策略的实现。最后,通过对仿真实验结果的分析,展示了功率因数改善的情况,并强调了理论与实践相结合的学习方法。 适合人群:从事电力电子相关领域的研究人员和技术人员,特别是对功率因数校正电路感兴趣的工程师。 使用场景及目标:适用于希望深入了解APFC电路工作原理的研究者;希望通过仿真建模掌握双闭环控制策略的技术人员;以及想要提升实际项目中电力传输效率的设计者。 其他说明:文章不仅提供理论知识讲解,还有助于读者通过动手实验进一步巩固所学内容,增强对电力电子系统的直观理解。
内容概要:本文详细探讨了分段斜坡补偿电路在BOOST(升压)和BUCK(降压)系统中的应用。首先介绍了这两种常见直流电源转换器的基本特性及其应用场景。接着阐述了分段斜坡补偿电路的工作原理,即通过引入斜坡补偿信号来动态调整开关时序,从而优化开关过程,减少电压和电流冲击,提升系统性能。对于BOOST系统,分段斜坡补偿电路能有效控制升压开关的时间,降低损耗并提高转换效率;而在BUCK系统中,则通过精准控制降压开关时间,确保输出电压的稳定性。最后总结了分段斜坡补偿电路带来的多项优势,如增强系统稳定性、降低损耗、适应多种负载条件以及加快响应速度。 适用人群:从事电力电子设计的技术人员,尤其是专注于电源管理模块设计的研发人员。 使用场景及目标:适用于需要深入了解BOOST和BUCK系统内部机制及其改进方法的研究者和技术开发者,旨在帮助他们掌握分段斜坡补偿电路的具体应用技巧,进而改善相关产品的性能。 其他说明:随着电力电子技术的发展,分段斜坡补偿电路有望在未来更多类型的电源转换器中发挥作用,推动整个行业向更高水平发展。
基于java开发的分布式推送项目,利用rocketMq+netty实现分布式推送+源码+项目文档+使用案例,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档 技术框架: 框架名称 版本号 Spring Boot 2.1.4 Rocket-MQ 4.3.1 Netty 4.1.34 JDK 11 Jackson 2.9.8 项目说明 Rocketmq-starter:实现RocketMq的基本开发 websocket-starter:实现基于Netty的推送管理模块 xxxx-example:包含服务端与客户端的实例 使用说明: 详见websocket-client-example和websocket-server-example实例项目
毕业设计-全新企业发卡系统源码-整站商业源码.zip