机器学习 训练较快的模型_通过心理模型更快地学习软件,第1部分

机器学习 训练较快的模型

什么是心理模型? (What Are Mental Models?)

The easiest way to describe them is that they’re patterns. You learn the patterns once, and then you can apply them to various other scenarios and topics to learn new things faster.

描述它们的最简单方法是它们是模式。 您一次学习了这些模式,然后就可以将它们应用于其他各种情况和主题,以更快地学习新事物。

Mental models are a way for you to understand the world.

心理模型是您了解世界的一种方式。

Since there are so many different concepts in software engineering, mental models can be extremely beneficial to developers learning new concepts.

由于软件工程中有许多不同的概念,因此心理模型可能对开发人员学习新概念非常有益。

Most people would be hard-pressed to memorize 100+ different algorithms, but it’s far more manageable when you can group them by principles.

大多数人很难记住100多种不同的算法,但是如果您可以按原理对它们进行分组,则可管理性要强得多。

一个例子 (An Example)

I recall a man who won a prize at a fair by memorizing a string of 100 digits within an hour.

我回想起一个人在一个交易会中通过在一个小时内记住100个数字的字符串而赢得了大奖。

5778563856325719554823908754396193272936058610938258472045803948555752930485720948623046984501993756

Yuck. Most people would have a hard time committing all of these digits to memory. But this man’s secret? He used phone numbers as a mental model.

uck 大多数人很难将所有这些数字都提交到内存中。 但是这个男人的秘密? 他用电话号码作为心理模型。

(577) 856-3856
(325) 719-5548
(239) 087-5439
(619) 327-2936
(058) 610-9382
(584) 720-4580
(394) 855-5752
(930) 485-7209
(486) 230-4698
(450) 199-3756

Rather than trying to cram an abnormally large sequence of numbers into his head, he broke it down into ten individual pieces and pretended they were phone numbers.

他没有试图将异常大的数字序列塞入脑袋,而是将其分解成十个单独的部分,并假装它们是电话号码。

Before the era of smartphones and contact lists, most of us committed phone numbers by heart anyway. Committing ten small sequences is much more manageable compared to one large, 100-number sequence.

在智能手机和联系人列表时代来临之前,我们大多数人还是会牢记承诺电话号码。 与一个100个大型序列相比,提交10个较小的序列更容易管理。

In addition, the visualization of phone numbers makes the digits easier to commit to memory. We all apply models we’ve previously learned to new concepts, whether consciously or unconsciously.

此外,电话号码的可视化使数字更易于提交到内存中。 我们都有意识地或无意识地将以前学习的模型应用于新概念。

Using this example as a reference, let’s discuss some useful mental models in programming and the wide variety of topics they can help you learn faster.

以这个例子为参考,让我们讨论一些有用的编程思维模型,以及可以帮助您更快学习的各种主题。

局部与全局优化 (Local vs. Global Optimization)

When you’re working in a system where you can make decisions, you can prioritize things in the following two ways:

在可以决策的系统中工作时,可以通过以下两种方式确定事务的优先级:

  1. Doing something that benefits you immediately, or “locally.”

    做一些使您立即或“本地”受益的事情。

  2. Doing something that benefits you in the future, or “globally.”

    做一些有益于您将来或“全球”的事情。

For example, I can choose to eat junk food today. It benefits me immediately because I’m happy. But the cost is long-term health. In contrast, I can choose to eat a healthy meal of vegetables and whole grains. I’m not so happy about it, but there’s a long-term benefit to doing this, especially repeatedly.

例如,我今天可以选择吃垃圾食品。 它使我受益,因为我很高兴。 但是代价是长期健康。 相反,我可以选择吃健康的蔬菜和全谷物食品。 我对此不太满意,但是这样做有长远的好处,尤其是反复进行。

Similarly, local vs. global optimization shows up in a lot of CS concepts:

同样,本地与全局优化出现在许多CS概念中:

路由算法 (Routing Algorithms)

In search and traversal, you can choose the best next step based on the viewpoint of the current node (local) or from the viewpoint of the entire grid/tree (global).

在搜索和遍历中,您可以基于当前节点的观点(局部)或整个网格/树的观点(全局)来选择最佳的下一步。

Global optimization means better overall results, but often at a cost — for example, you’ll spend more clock cycles gathering global data and more memory storing it.

全局优化意味着更好的总体结果,但是通常要付出一定的代价–例如,您将花费更多的时钟周期来收集全局数据,并需要更多的内存来存储它。

Below, given a network on chip (NoC) where I need to route data from Point A to Point B, locally-optimized choices result in a different path and overall latency than a globally-optimized choice.

下面,给定一个我需要将数据从点A路由到点B的片上网络( NoC ),与全局优化的选择相比,本地优化的选择导致的路径和总体延迟有所不同。

In exchange, in order for each of the nodes to make that globally-optimal choice, all of the nodes must synchronize their information with each other in routing tables, which consumes memory and power.

作为交换,为了使每个节点都能做出全局最优选择,所有节点必须在路由表中彼此同步其信息,这会消耗内存和电量。

最短路径算法 (Shortest Path Algorithms)

Shortest path algorithms are a specific type of routing algorithm through a matrix, a graph, etc. There’s a trade-off here in the amount of memory and processing being done. You’re exploring many, many branches and nodes, and you’re only choosing the best one.

最短路径算法是通过矩阵,图形等的特定类型的路由算法。这里需要权衡一下要完成的内存和处理量。 您正在探索许多分支和节点,而您只选择了最好的分支和节点。

By their nature, the end result is always globally optimal, but sometimes they’ll use local optimization to get there.

从本质上讲,最终结果始终是全局最优的,但有时他们会使用局部优化来达到目标​​。

For example, Bellman-Ford’s algorithm uses a series of locally optimal decisions to continually update the shortest distance to each node in iterations as it discovers more vertex weights. The final result is the global optimal.

例如, Bellman-Ford的算法使用一系列局部最优决策,以在发现更多顶点权重时不断更新到每个节点的最短距离。 最终结果是全局最优。

决策树和图形 (Decision Trees & Graphs)

Computers and AI in games use decision trees to make decisions on the next best move.

游戏中的计算机和AI使用决策树来做出下一步的决策。

Each decision or state change in the game has downstream, reverberating consequences, and the computer explores that tree to minimize its loss or maximize its gains.

游戏中的每个决策或状态变化都会产生下游影响,并产生回响,计算机将探索该树以最大程度地减少其损失或最大化其收益。

Take the (very rudimentary) example below:

请参考以下(非常基本的)示例:

Image for post
Excalidraw Excalidraw制造

You can see that clearly, move B is the superior choice. But if, for example, you have a computer’s difficulty setting on Easy, then it may only look one decision ahead. It subsequently decides that move A is better because +1 > -1 and proceeds to lose.

您可以清楚地看到,移动B是上乘的选择。 但是,例如,如果您在Easy上设置了计算机的难度,那么它可能只会向前看一个决定。 随后它决定移动A更好,因为+1> -1并继续失败。

Adjusting the difficulty level of the AI is typically adjusting the depth the AI will explore on the decision tree. Higher difficulty means the computer will look farther down the tree, and subsequently optimize their decision based on more and more possibilities — a more “global” basis.

调整AI的难度级别通常是在调整AI将在决策树上探索的深度。 更高的难度意味着计算机将往远处看,然后根据越来越多的可能性(更“全局”)优化决策。

排序算法 (Sorting Algorithms)

Many sorting algorithms use local optimization. For example, Bubble Sort will brute force and compare every single element to its immediate neighbor and swap if needed. This is globally suboptimal because one element might make several swaps before it finds its rightful place.

许多排序算法使用局部优化。 例如, Bubble Sort将蛮力使用,并将每个元素与其直接邻居进行比较,并在需要时进行交换。 这是全局次优的,因为一个元素在找到其应有的位置之前可能会进行多次交换。

Mergesort is a Divide and Conquer algorithm that breaks up the list of elements and recursively handles them in small pieces. The divide portion is a local optimization problem where you only need to compare two elements. When merging everything back together, you’re combining the effects of several local decisions into the final result.

Mergesort是一种分而治之算法,可以分解元素列表并递归地处理它们。 除法部分是局部优化问题,您只需要比较两个元素即可。 将所有内容重新合并在一起时,您会将几个本地决策的影响合并到最终结果中。

快取 (Caching)

Caching is the process of storing the results of an operation. Future calls to that operation will just fetch the stored result instead of re-calculating or re-running the operation, resulting in faster performance.

缓存是存储操作结果的过程。 将来对该操作的调用将仅获取存储的结果,而不是重新计算或重新运行该操作,从而提高性能。

Image for post
(Very Simple) Example of Caching
(非常简单)缓存示例

You actually use “caching” in your everyday life. The things you use and touch often are near you and quickly accessible (e.g., your phone), while the stuff you don’t touch very often is tucked away (e.g., your off-season jacket).

您实际上在日常生活中使用“缓存”。 您使用和触摸的东西通常都在您附近并且可以快速访问(例如您的手机),而您不经常触摸的东西则被藏起来(例如您的淡季外套)。

互联网 (Internet)

The most common implementation of caching people know about is browser caching. The content of web pages is stored, making subsequent loads of the same page faster.

人们知道的最常见的缓存实现是浏览器缓存 。 网页的内容被存储,从而使同一页面的后续加载更快。

But caching actually occurs beyond just your browser. There’s DNS caching (e.g., IP resolutions for often-visited websites are stored). There’s also network caching (websites often visited in the same network are stored and fetched for multiple users).

但是缓存实际上不仅限于浏览器。 有DNS缓存 (例如,存储了经常访问的网站的IP分辨率)。 还有网络缓存 (在同一网络中经常访问的网站会存储并提取给多个用户)。

Caching is entrenched deep within the Internet, even on the switches and routers that simply route traffic across the world.

缓存已深深扎根于Internet内,甚至在仅路由全球流量的交换机和路由器上也是如此。

硬件 (Hardware)

Caching is also used at the hardware level. You may have heard of the L1, L2, and L3 caches of a processor or chip.

高速缓存还用于硬件级别。 您可能听说过处理器或芯片的L1,L2和L3缓存。

Computer chips typically have multiple layers of caching. Whenever a cache misses (e.g., L1), it will then check the next cache layer (L2) for a hit.

计算机芯片通常具有多层缓存。 每当高速缓存未命中时(例如L1),它将随后检查下一个高速缓存层(L2)是否命中。

Each layer of the cache is slower-performing and larger in size, but still much faster than fetching a piece of data from memory. If all of the caches miss, then we finally fetch data from DRAM (main memory), and if DRAM fails, we use swap memory on the hard drive (the slowest).

高速缓存的每一层性能较慢且大小较大,但仍比从内存中获取数据要快得多。 如果所有高速缓存都未命中,那么我们最终将从DRAM(主内存)中获取数据,如果DRAM出现故障,我们将在硬盘驱动器(最慢)上使用交换内存。

动态编程和记忆 (Dynamic Programming & Memoization)

When using recursive algorithms, you sometimes find yourself computing the same pieces of information over and over.

使用递归算法时,有时您会发现自己一遍又一遍地计算相同的信息。

An example of this is recursive Fibonacci:

递归斐波那契就是一个例子:

Image for post

Ignoring the base cases, which will just return 0 and 1, you can see that f(2) is called three times and f(3) is called twice. Now if we increase it by one level…

忽略将仅返回0和1的基本情况,您可以看到f(2)被调用了三次,而f(3)被调用了两次。 现在,如果我们将其增加一级...

Image for post

See how messy it’s getting? Each additional level of Fibonacci increases the number of duplicate calculations we make. And this is why it’s useful to store, or “cache,” results like in dynamic programming.

看到它变得多么混乱吗? 斐波那契的每个附加级别都会增加我们进行重复计算的次数。 这就是为什么在动态编程中存储或“缓存”结果很有用的原因。

As the Fibonacci tree grows larger, the gains realized from caching intermediate results become greater (e.g., f(10) calls f(2) 34 times, meaning you’ve saved 33 redundant operations and stack pointers).

随着斐波那契树变得更大,从缓存中间结果中实现的收益也变得更大(例如, f(10)调用f(2) 34次,这意味着您已经节省了33个冗余操作和堆栈指针)。

客户端服务器 (Client/Server)

Client/server models exist in many facets, typically in the design of software applications.

客户/服务器模型存在于许多方面,通常在软件应用程序的设计中。

The principle is that the “server” is usually the primary facilitator of actions and information; they receive requests, process data, and then send responses and information to the clients as needed.

原则是“服务器”通常是行动和信息的主要推动者; 他们接收请求,处理数据,然后根据需要将响应和信息发送给客户端。

Image for post

Clients typically do their own processing locally, but the server is the “source of truth.”

客户端通常在本地进行自己的处理,但是服务器是“真相的来源”。

多人游戏 (Multiplayer Games)

Multiplayer games, such as online FPS’s, use a client/server model. In order to prevent cheating, the server maintains the “authority” over all actions happening in-game.

多人游戏,例如在线FPS,使用客户端/服务器模型。 为了防止作弊,服务器对游戏中发生的所有动作保持“权限”。

Clients, or individual players at home, perform actions by making a request to the server, and the server allows the actions and updates everyone else as needed.

客户或家中的个人玩家通过向服务器发出请求来执行操作,服务器允许操作并根据需要更新其他所有人。

Image for post
All this back and forth is why players with faster Internet have a better gaming experience — information is replicated faster and more reliably.
所有这些来回的原因就是为什么拥有更快的Internet的玩家拥有更好的游戏体验-信息被更快,更可靠地复制。

网络应用 (Web Applications)

Many web services and applications you use are typically client/server.

您使用的许多Web服务和应用程序通常都是客户端/服务器。

For example, if you’re using a cross-platform and synchronized to-do list application, the app you interact with on your phone is the client.

例如,如果您使用跨平台且同步的待办事项列表应用程序,那么您在手机上与之交互的应用程序就是客户端。

Whenever you make an update, the change happens locally, but a request is made to a server to persist this change somewhere in the cloud (if you’re using a synchronized, cross-platform app).

每当您进行更新时,更改都会在本地进行,但是会向服务器发出请求,要求将该更改持久保存在云中的某个位置(如果您使用的是同步的跨平台应用程序)。

It’s the same thing with other applications like social media — you see an interface locally, you do some actions, and a request is sent to a server or service somewhere to persist and then replicate those actions.

与其他应用程序(如社交媒体)一样,您可以在本地看到一个界面,执行一些操作,然后将请求发送到某处的服务器或服务以保留并复制这些操作。

New tweets or posts are written to a database somewhere, and then other clients (users) see your latest memes and cat photos.

新的推文或帖子会写到某个地方的数据库中,然后其他客户(用户)会看到您的最新模因和猫照片。

结论 (Conclusion)

Mental models are extremely useful for learning things faster. You can use patterns you’ve seen before to understand new concepts.

心理模型对于更快地学习事物非常有用。 您可以使用以前见过的模式来理解新概念。

This first story is just a sample of the many patterns you can find in the software development world.

第一个故事只是在软件开发世界中可以找到的许多模式的示例。

I will post more in the future. Hope this article was useful to you!

我将来会发布更多。 希望本文对您有用!

翻译自: https://medium.com/@michael.thanh/learn-software-faster-with-mental-models-part-1-9abfeedc8ccd

机器学习 训练较快的模型

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值