Compare commits
15 Commits
bddeb70f4e
...
ai-lecture
| Author | SHA1 | Date | |
|---|---|---|---|
|
e934f3ef3d
|
|||
|
|
5ee1f729bd | ||
|
|
0e21a2a791 | ||
|
|
767a67ee00 | ||
|
|
89ab00a4a1 | ||
|
|
993b8f302a | ||
|
|
d5896c968b | ||
|
|
bf285afcf2 | ||
|
|
9d491c6d2f | ||
|
|
a88f38dec0 | ||
|
|
20d9eaf496 | ||
|
|
339dc709da | ||
|
|
f33e9d7662 | ||
|
|
bbd0d3e4f7 | ||
|
|
3d7d3152a4 |
219
ai_lecture.md
Normal file
219
ai_lecture.md
Normal file
@@ -0,0 +1,219 @@
|
||||
# 使用 MLP 识别 MNIST 手写数字
|
||||
|
||||
主讲人:陈永源 2024-01-05
|
||||
|
||||
Note:
|
||||
这个课程假设各位是有编程基础的机器学习小白,课程我会用直观的说明方式讲解机器学习原理及相关代码,不会涉及到过多数学上的细节。
|
||||
|
||||
---
|
||||
|
||||
## 课程简介
|
||||
|
||||
在这个课程中,我们将会使用机器学习技术对手写数字图像进行分类,并包括
|
||||
|
||||
- 定义 Pytorch MLP 模型
|
||||
- 使用数据集工具 DataLoader
|
||||
- 从零开始训练模型
|
||||
- 使用测试集评估模型
|
||||
|
||||
Note:
|
||||
|
||||
机器学习和传统程序设计的一个主要区别是
|
||||
你无需明确告诉计算机该如何去识别一个数字
|
||||
例如说6这个数字有一个竖线还有一个圈
|
||||
你不需告诉计算机这些规则
|
||||
机器学习能够自动从数据集中学到这些特征
|
||||
并且使用这些特征逐步训练它自己的神经网络,
|
||||
然后逐步提升它的准确性,
|
||||
这和我们人类或者是生物的学习方式是类似的。
|
||||
|
||||
---
|
||||
|
||||
## 神经网络简介
|
||||
|
||||
神经网络这一概念在 1959 年被提出
|
||||
|
||||
神经网络的核心概念来源于人脑的神经元网络,它由许多相互连接的节点(或称为"神经元")组成。这些节点可以接收输入,并根据输入数据的不同对其进行加权处理,产生输出
|
||||
|
||||

|
||||
|
||||
|
||||
Demo: <https://playground.tensorflow.org/>
|
||||
|
||||
Note:
|
||||
|
||||
该术语于1959年由IBM的亚瑟·塞缪尔提出,当时他正在开发能够下跳棋的人工智能程序。半个世纪后,预测模型已经嵌入在我们日常使用的许多产品当中,执行两项基本工作:一是对数据进行分类,例如判断路上是否有其他车辆,或者患者是否患有癌症;二是对未来结果做出预测,如预测股票是否会上涨
|
||||
|
||||
而神经网络,是机器学习中一类特别重要的算法模型。神经网络的核心概念来源于人脑的神经元网络,它由许多相互连接的节点(或称为"神经元")组成。这些节点可以接收输入,并根据输入数据的不同对其进行加权处理,产生输出。特别是在处理像图像或自然语言这样的数据集时,神经网络显示出强大的功能,因为它可以自动提取和创建特征,而无需手动的特征工程。
|
||||
|
||||
// 打开 demo
|
||||
|
||||
这是一个非常直观的关于神经网络的演示。我们的任务是训练一个神经网络,对对右边的橙色和蓝色的点进行分类。
|
||||
用人眼看过去,我们很直观的就能发现
|
||||
蓝色的点在中间,外面一圈都是橙色的点
|
||||
但是我们要如何让计算机自己去学到这一个规则呢?
|
||||
这个时候,我们设计了有两个隐藏层的神经网络
|
||||
第一个隐藏层有四个神经元,第二个隐藏层有两个神经元
|
||||
同时使用两个线性特征作为输入。
|
||||
// 点开始学习,在一百多个迭代之后这个神经网络就能学习到我们期望的特征
|
||||
// 将鼠标放在各个神经元上,可以看到每个神经元所学习到的特征已经他们和其他神经元之间的权重。
|
||||
除此之外,我们还有一些参数可以调整,例如学习率,可以理解为神经网络学习的步长,太大的值可能会学习不到最优解,太小的值可能会花费更多的时间来学习甚至永远学不到最优解
|
||||
那么我们现在就开始手写数字分类的任务
|
||||
|
||||
---
|
||||
|
||||
## MNIST 手写数字数据集
|
||||
|
||||
- 总共7000张图片,包含1000张测试集
|
||||
- 10个分类,代表0~9
|
||||
|
||||

|
||||
|
||||
Note:
|
||||
这个数字节里面包含了大约7000张图片,
|
||||
每一张图片都是这种黑白的手写数字,
|
||||
分别一共有10种,
|
||||
代表0~9
|
||||
这7000张图片里面有6000张是训练级,1000张是测试级,我们只会使用训练级的图片来训练神经网络,测试级的图片不会给神经网络看,但会在评估阶段用来测试神经网络的性能,这样就能看一下这个神经网络对于它没见过的图片是否也能做到准确分类,
|
||||
|
||||
---
|
||||
|
||||
## 神经网络结构
|
||||
|
||||
1. 输入层大小: 28*28 = 784
|
||||
2. 隐藏层
|
||||
3. 输出层大小: 10
|
||||
|
||||

|
||||
|
||||
Note:
|
||||
这是我们即将设计的神经网络的结构
|
||||
它首先在输入层接受一个维度为28*28,也就是784这样一个大小的输入
|
||||
然后它会经过几个隐藏层,最终来到有10个神经元的输出层
|
||||
完成手写数字识别的分类任务
|
||||
|
||||
---
|
||||
|
||||
## 神经网络优化器
|
||||
|
||||
优化器的作用是寻找最佳的参数组合以最小化损失函数
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## 代码讲解
|
||||
|
||||
```python [0-6|8-14|16-20|18|19|22-27]
|
||||
import torch
|
||||
import torchvision
|
||||
import torch.nn as nn
|
||||
import torch.optim as optim
|
||||
from torchvision import datasets, transforms
|
||||
from torch.utils.data import DataLoader
|
||||
|
||||
# 检查设备
|
||||
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
||||
print('Using device:', device)
|
||||
# 设置超参数
|
||||
batch_size = 64
|
||||
learning_rate = 0.01
|
||||
epochs = 5
|
||||
|
||||
# 设置数据集的变换
|
||||
transform = transforms.Compose([
|
||||
transforms.ToTensor(),
|
||||
transforms.Normalize((0,), (1,))
|
||||
])
|
||||
|
||||
#加载数据集
|
||||
train_dataset = datasets.MNIST(root='./data_mlp', train=True, transform=transform, download=True)
|
||||
test_dataset = datasets.MNIST(root='./data_mlp', train=False, transform=transform, download=True)
|
||||
|
||||
train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True)
|
||||
test_loader = DataLoader(test_dataset, batch_size=batch_size, shuffle=False)
|
||||
```
|
||||
|
||||
Note:
|
||||
0-6 首先前后行我们载入一些需要用到的库 包括神经网络层,优化器,数据集需要用到的工具
|
||||
8-14
|
||||
然后初始化一些变量和参数
|
||||
这里用了一段代码自动判断CUDA显卡设备是否可用
|
||||
如果不可用的话则会选择CPU进行运算
|
||||
超参数的这个batch_size指的是每一次迭代中
|
||||
这个神经网络会一次性看多少张图片
|
||||
我们神经网络训练数据的时候不是一张图一张图的去看
|
||||
而是多张图放在一个批次里一起去看
|
||||
一般來說,Batch Size會盡可能設置得高,讓顯卡充分發揮它的並行運算能力,但是也要看情況具體分析,太高的話可能導致過擬核,影响模型最终的学习效果
|
||||
Learning Rate就是学习率,我们刚才讲过的
|
||||
指的是神经网络一次调整
|
||||
自身权重的步长
|
||||
数值越大,学得越快
|
||||
但是太大也可能会导致完全无法学习
|
||||
最后一个参数Epoch,代表需要学习整个数据集多少遍
|
||||
数字太小的话
|
||||
训练过程可能
|
||||
还没学到这些数字的特征就结束了 数字太大的话
|
||||
他可能会把数据集里面的所有噪音都记住 最终在测试级上表现效果不佳
|
||||
16-20
|
||||
Transform这一部分是告诉DataLoader
|
||||
我们应该在读取数据,在喂给神经网络之前,做哪一些格式变换操作
|
||||
18
|
||||
首先我们会把这些整数类型的数据转换成Tensor,也就是PyTorch能够进行运算的向量类型数据
|
||||
19
|
||||
然后我们会调用Normalize把它归一化成均值为0,标准差为1的数据。
|
||||
因为在某些数据集中,数值之间的尺度是不匹配的,例如我们分析身高和机票价格之间的关系,身高的单位是米,一个人身高撑死最多2米多,但是机票价格从几千到几万不等。这时候进行normalize就非常有必要。
|
||||
这样经过调整之后,输入神经网络的数值就在一个合理的范围之内
|
||||
|
||||
---
|
||||
|
||||
## 代码讲解
|
||||
|
||||
```python [1-14|16-17|19-21|23-32|34-46]
|
||||
# 定义MLP模型
|
||||
class MLP(nn.Module):
|
||||
def __init__(self):
|
||||
super(MLP, self).__init__()
|
||||
self.fc1 = nn.Linear(28*28, 512)
|
||||
self.fc2 = nn.Linear(512, 256)
|
||||
self.fc3 = nn.Linear(256, 10)
|
||||
|
||||
def forward(self, x):
|
||||
x = x.view(-1, 28*28)
|
||||
x = torch.relu(self.fc1(x))
|
||||
x = torch.relu(self.fc2(x))
|
||||
x = self.fc3(x)
|
||||
return x
|
||||
|
||||
# 创建模型实例并将其移到正确的设备上
|
||||
model = MLP().to(device)
|
||||
|
||||
# 定义损失函数和优化器
|
||||
criterion = nn.CrossEntropyLoss()
|
||||
optimizer = optim.SGD(model.parameters(), lr=learning_rate)
|
||||
|
||||
# 训练模型
|
||||
for epoch in range(epochs):
|
||||
model.train()
|
||||
for batch_idx, (data, target) in enumerate(train_loader):
|
||||
data, target = data.to(device), target.to(device)
|
||||
optimizer.zero_grad()
|
||||
output = model(data)
|
||||
loss = criterion(output, target)
|
||||
loss.backward()
|
||||
optimizer.step()
|
||||
|
||||
# 测试模型
|
||||
model.eval()
|
||||
test_loss = 0
|
||||
correct = 0
|
||||
with torch.no_grad():
|
||||
for data, target in test_loader:
|
||||
data, target = data.to(device), target.to(device)
|
||||
output = model(data)
|
||||
test_loss += criterion(output, target).item()
|
||||
pred = output.argmax(dim=1, keepdim=True)
|
||||
correct += pred.eq(target.view_as(pred)).sum().item()
|
||||
|
||||
test_loss /= len(test_loader.dataset)
|
||||
```
|
||||
@@ -1445,7 +1445,8 @@ $overlayHeaderPadding: 5px;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 1000;
|
||||
background: rgba( 0, 0, 0, 0.9 );
|
||||
background: rgba( 0, 0, 0, 0.95 );
|
||||
backdrop-filter: blur( 6px );
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
@@ -1589,7 +1590,6 @@ $overlayHeaderPadding: 5px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
|
||||
/*********************************************
|
||||
* PLAYBACK COMPONENT
|
||||
*********************************************/
|
||||
@@ -1901,6 +1901,11 @@ $notesWidthPercent: 25%;
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.overlay,
|
||||
.pause-overlay {
|
||||
position: fixed;
|
||||
}
|
||||
|
||||
.reveal {
|
||||
overflow: visible;
|
||||
touch-action: manipulation;
|
||||
|
||||
4
dist/reveal.css
vendored
4
dist/reveal.css
vendored
File diff suppressed because one or more lines are too long
4
dist/reveal.esm.js
vendored
4
dist/reveal.esm.js
vendored
File diff suppressed because one or more lines are too long
2
dist/reveal.esm.js.map
vendored
2
dist/reveal.esm.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/reveal.js
vendored
4
dist/reveal.js
vendored
File diff suppressed because one or more lines are too long
2
dist/reveal.js.map
vendored
2
dist/reveal.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -16,8 +16,7 @@
|
||||
<body>
|
||||
<div class="reveal">
|
||||
<div class="slides">
|
||||
<section>Slide 1</section>
|
||||
<section>Slide 2</section>
|
||||
<section data-markdown="ai_lecture.md"></section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -31,6 +30,8 @@
|
||||
// - https://revealjs.com/config/
|
||||
Reveal.initialize({
|
||||
hash: true,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
|
||||
// Learn about plugins: https://revealjs.com/plugins/
|
||||
plugins: [ RevealMarkdown, RevealHighlight, RevealNotes ]
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
import {
|
||||
SLIDE_NUMBER_FORMAT_CURRENT,
|
||||
SLIDE_NUMBER_FORMAT_CURRENT_SLASH_TOTAL
|
||||
} from "../utils/constants";
|
||||
|
||||
/**
|
||||
* Makes it possible to jump to a slide by entering its
|
||||
* slide number or id.
|
||||
@@ -66,11 +71,33 @@ export default class JumpToSlide {
|
||||
clearTimeout( this.jumpTimeout );
|
||||
delete this.jumpTimeout;
|
||||
|
||||
const query = this.jumpInput.value.trim( '' );
|
||||
let indices = this.Reveal.location.getIndicesFromHash( query, { oneBasedIndex: true } );
|
||||
let query = this.jumpInput.value.trim( '' );
|
||||
let indices;
|
||||
|
||||
// If no valid index was found and the input query is a
|
||||
// string, fall back on a simple search
|
||||
// When slide numbers are formatted to be a single linear mumber
|
||||
// (instead of showing a separate horizontal/vertical index) we
|
||||
// use the same format for slide jumps
|
||||
if( /^\d+$/.test( query ) ) {
|
||||
const slideNumberFormat = this.Reveal.getConfig().slideNumber;
|
||||
if( slideNumberFormat === SLIDE_NUMBER_FORMAT_CURRENT || slideNumberFormat === SLIDE_NUMBER_FORMAT_CURRENT_SLASH_TOTAL ) {
|
||||
const slide = this.Reveal.getSlides()[ parseInt( query, 10 ) - 1 ];
|
||||
if( slide ) {
|
||||
indices = this.Reveal.getIndices( slide );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !indices ) {
|
||||
// If the query uses "horizontal.vertical" format, convert to
|
||||
// "horizontal/vertical" so that our URL parser can understand
|
||||
if( /^\d+\.\d+$/.test( query ) ) {
|
||||
query = query.replace( '.', '/' );
|
||||
}
|
||||
|
||||
indices = this.Reveal.location.getIndicesFromHash( query, { oneBasedIndex: true } );
|
||||
}
|
||||
|
||||
// Still no valid index? Fall back on a text search
|
||||
if( !indices && /\S+/i.test( query ) && query.length > 1 ) {
|
||||
indices = this.search( query );
|
||||
}
|
||||
|
||||
@@ -223,6 +223,8 @@ export default class PrintView {
|
||||
// Notify subscribers that the PDF layout is good to go
|
||||
this.Reveal.dispatchEvent({ type: 'pdf-ready' });
|
||||
|
||||
viewportElement.classList.remove( 'loading-scroll-mode' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -425,7 +425,6 @@ export default class ScrollView {
|
||||
];
|
||||
|
||||
const scrollTriggerSegmentSize = ( trigger.range[1] - trigger.range[0] ) / trigger.page.scrollTriggers.length;
|
||||
|
||||
// Set the range for each inner scroll trigger
|
||||
trigger.page.scrollTriggers.forEach( ( scrollTrigger, i ) => {
|
||||
scrollTrigger.range = [
|
||||
@@ -462,16 +461,17 @@ export default class ScrollView {
|
||||
activate: () => {
|
||||
this.Reveal.fragments.update( -1, page.fragments, slideElement );
|
||||
}
|
||||
},
|
||||
|
||||
// Triggers for each fragment group
|
||||
...fragmentGroups.map( ( fragments, i ) => ({
|
||||
activate: () => {
|
||||
this.Reveal.fragments.update( i, page.fragments, slideElement );
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
// Triggers for each fragment group
|
||||
fragmentGroups.forEach( ( fragments, i ) => {
|
||||
page.scrollTriggers.push({
|
||||
activate: () => {
|
||||
this.Reveal.fragments.update( i, page.fragments, slideElement );
|
||||
}
|
||||
});
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
@@ -801,8 +801,8 @@ export default class ScrollView {
|
||||
if( page.active ) {
|
||||
|
||||
page.active = false;
|
||||
page.slideElement.classList.remove( 'present' );
|
||||
page.backgroundElement.classList.remove( 'present' );
|
||||
if( page.slideElement ) page.slideElement.classList.remove( 'present' );
|
||||
if( page.backgroundElement ) page.backgroundElement.classList.remove( 'present' );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -142,13 +142,15 @@ export default class SlideContent {
|
||||
|
||||
// Support comma separated lists of video sources
|
||||
backgroundVideo.split( ',' ).forEach( source => {
|
||||
const sourceElement = document.createElement( 'source' );
|
||||
sourceElement.setAttribute( 'src', source );
|
||||
|
||||
let type = getMimeTypeFromFile( source );
|
||||
if( type ) {
|
||||
video.innerHTML += `<source src="${source}" type="${type}">`;
|
||||
}
|
||||
else {
|
||||
video.innerHTML += `<source src="${source}">`;
|
||||
sourceElement.setAttribute( 'type', type );
|
||||
}
|
||||
|
||||
video.appendChild( sourceElement );
|
||||
} );
|
||||
|
||||
backgroundContent.appendChild( video );
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
import {
|
||||
SLIDE_NUMBER_FORMAT_CURRENT,
|
||||
SLIDE_NUMBER_FORMAT_CURRENT_SLASH_TOTAL,
|
||||
SLIDE_NUMBER_FORMAT_HORIZONTAL_DOT_VERTICAL,
|
||||
SLIDE_NUMBER_FORMAT_HORIZONTAL_SLASH_VERTICAL
|
||||
} from "../utils/constants";
|
||||
|
||||
/**
|
||||
* Handles the display of reveal.js' optional slide number.
|
||||
*/
|
||||
@@ -56,7 +63,7 @@ export default class SlideNumber {
|
||||
|
||||
let config = this.Reveal.getConfig();
|
||||
let value;
|
||||
let format = 'h.v';
|
||||
let format = SLIDE_NUMBER_FORMAT_HORIZONTAL_DOT_VERTICAL;
|
||||
|
||||
if ( typeof config.slideNumber === 'function' ) {
|
||||
value = config.slideNumber( slide );
|
||||
@@ -69,7 +76,7 @@ export default class SlideNumber {
|
||||
// If there are ONLY vertical slides in this deck, always use
|
||||
// a flattened slide number
|
||||
if( !/c/.test( format ) && this.Reveal.getHorizontalSlides().length === 1 ) {
|
||||
format = 'c';
|
||||
format = SLIDE_NUMBER_FORMAT_CURRENT;
|
||||
}
|
||||
|
||||
// Offset the current slide number by 1 to make it 1-indexed
|
||||
@@ -77,16 +84,16 @@ export default class SlideNumber {
|
||||
|
||||
value = [];
|
||||
switch( format ) {
|
||||
case 'c':
|
||||
case SLIDE_NUMBER_FORMAT_CURRENT:
|
||||
value.push( this.Reveal.getSlidePastCount( slide ) + horizontalOffset );
|
||||
break;
|
||||
case 'c/t':
|
||||
case SLIDE_NUMBER_FORMAT_CURRENT_SLASH_TOTAL:
|
||||
value.push( this.Reveal.getSlidePastCount( slide ) + horizontalOffset, '/', this.Reveal.getTotalSlides() );
|
||||
break;
|
||||
default:
|
||||
let indices = this.Reveal.getIndices( slide );
|
||||
value.push( indices.h + horizontalOffset );
|
||||
let sep = format === 'h/v' ? '/' : '.';
|
||||
let sep = format === SLIDE_NUMBER_FORMAT_HORIZONTAL_SLASH_VERTICAL ? '/' : '.';
|
||||
if( this.Reveal.isVerticalSlide( slide ) ) value.push( sep, indices.v + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
49
js/reveal.js
49
js/reveal.js
@@ -1016,20 +1016,10 @@ export default function( revealElement, options ) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Responsively turn on the scroll mode if there is an activation
|
||||
// width configured. Ignore if we're configured to always be in
|
||||
// scroll mode.
|
||||
if( typeof config.scrollActivationWidth === 'number' && config.view !== 'scroll' ) {
|
||||
if( size.presentationWidth > 0 && size.presentationWidth <= config.scrollActivationWidth ) {
|
||||
if( !scrollView.isActive() ) scrollView.activate();
|
||||
}
|
||||
else {
|
||||
if( scrollView.isActive() ) scrollView.deactivate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkResponsiveScrollView();
|
||||
|
||||
dom.viewport.style.setProperty( '--slide-scale', scale );
|
||||
dom.viewport.style.setProperty( '--viewport-width', viewportWidth + 'px' );
|
||||
dom.viewport.style.setProperty( '--viewport-height', viewportHeight + 'px' );
|
||||
@@ -1081,6 +1071,40 @@ export default function( revealElement, options ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Responsively activates the scroll mode when we reach the configured
|
||||
* activation width.
|
||||
*/
|
||||
function checkResponsiveScrollView() {
|
||||
|
||||
// Only proceed if...
|
||||
// 1. The DOM is ready
|
||||
// 2. Layouts aren't disabled via config
|
||||
// 3. We're not currently printing
|
||||
// 4. There is a scrollActivationWidth set
|
||||
// 5. The deck isn't configured to always use the scroll view
|
||||
if(
|
||||
dom.wrapper &&
|
||||
!config.disableLayout &&
|
||||
!printView.isActive() &&
|
||||
typeof config.scrollActivationWidth === 'number' &&
|
||||
config.view !== 'scroll'
|
||||
) {
|
||||
const size = getComputedSlideSize();
|
||||
|
||||
if( size.presentationWidth > 0 && size.presentationWidth <= config.scrollActivationWidth ) {
|
||||
if( !scrollView.isActive() ) {
|
||||
backgrounds.create();
|
||||
scrollView.activate()
|
||||
};
|
||||
}
|
||||
else {
|
||||
if( scrollView.isActive() ) scrollView.deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the computed pixel size of our slides. These
|
||||
* values are based on the width and height configuration
|
||||
@@ -2700,7 +2724,6 @@ export default function( revealElement, options ) {
|
||||
function onWindowResize( event ) {
|
||||
|
||||
layout();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,4 +7,10 @@ export const VERTICAL_SLIDES_SELECTOR = '.slides>section.present>section';
|
||||
export const POST_MESSAGE_METHOD_BLACKLIST = /registerPlugin|registerKeyboardShortcut|addKeyBinding|addEventListener|showPreview/;
|
||||
|
||||
// Regex for retrieving the fragment style from a class attribute
|
||||
export const FRAGMENT_STYLE_REGEX = /fade-(down|up|right|left|out|in-then-out|in-then-semi-out)|semi-fade-out|current-visible|shrink|grow/;
|
||||
export const FRAGMENT_STYLE_REGEX = /fade-(down|up|right|left|out|in-then-out|in-then-semi-out)|semi-fade-out|current-visible|shrink|grow/;
|
||||
|
||||
// Slide number formats
|
||||
export const SLIDE_NUMBER_FORMAT_HORIZONTAL_DOT_VERTICAL = 'h.v';
|
||||
export const SLIDE_NUMBER_FORMAT_HORIZONTAL_SLASH_VERTICAL = 'h/v';
|
||||
export const SLIDE_NUMBER_FORMAT_CURRENT = 'c';
|
||||
export const SLIDE_NUMBER_FORMAT_CURRENT_SLASH_TOTAL = 'c/t';
|
||||
@@ -0,0 +1,31 @@
|
||||
start end text
|
||||
0 6480 Machine learning. Teach a computer how to perform a task, without explicitly programming it to perform said task.
|
||||
6620 13420 Instead, feed data into an algorithm to gradually improve outcomes with experience, similar to how organic life learns.
|
||||
13580 20400 The term was coined in 1959 by Arthur Samuel at IBM, who was developing artificial intelligence that could play checkers.
|
||||
20540 26880 Half a century later, and predictive models are embedded in many of the products we use every day, which perform two fundamental jobs.
|
||||
26880 32040 One is to classify data, like "Is there another car on the road?" or "Does this patient have cancer?"
|
||||
32040 38600 The other is to make predictions about future outcomes, like "Will this stock go up?" or "Which YouTube video do you want to watch next?"
|
||||
38600 43280 The first step in the process is to acquire and clean up data. Lots and lots of data.
|
||||
43480 47780 The better the data represents the problem, the better the results. Garbage in, garbage out.
|
||||
47900 52160 The data needs to have some kind of signal to be valuable to the algorithm for making predictions.
|
||||
52160 59920 And data scientists perform a job called feature engineering to transform raw data into features that better represent the underlying problem.
|
||||
60240 64240 The next step is to separate the data into a training set and testing set.
|
||||
64460 71800 The training data is fed into an algorithm to build a model, then the testing data is used to validate the accuracy or error of the model.
|
||||
71980 77700 The next step is to choose an algorithm, which might be a simple statistical model like linear or logistic regression,
|
||||
77940 81260 or a decision tree that assigns different weights to features in the data.
|
||||
81260 86640 Or you might get fancy with a convolutional neural network, which is an algorithm that also assigns
|
||||
86640 91300 weights to features, but also takes the input data and creates additional features automatically.
|
||||
91640 96300 And that's extremely useful for datasets that contain things like images or natural language,
|
||||
96420 99020 where manual feature engineering is virtually impossible.
|
||||
99260 103960 Every one of these algorithms learns to get better by comparing its predictions to an error function.
|
||||
104160 109840 If it's a classification problem, like "Is this animal a cat or a dog?" the error function might be accuracy.
|
||||
109840 115900 If it's a regression problem, like "How much will a loaf of bread cost next year?" then it might be mean absolute error.
|
||||
116220 121780 Python is the language of choice among data scientists, but R and Julia are also popular options,
|
||||
121920 125320 and there are many supporting frameworks out there to make the process approachable.
|
||||
125500 132680 The end result of the machine learning process is a model, which is just a file that takes some input data in the same shape that it was trained on,
|
||||
132860 136900 then spits out a prediction that tries to minimize the error that it was optimized for.
|
||||
136900 141980 It can then be embedded on an actual device or deployed to the cloud to build a real-world product.
|
||||
142180 144500 This has been Machine Learning in 100 Seconds.
|
||||
144580 147160 Like and subscribe if you want to see more short videos like this,
|
||||
147320 150500 and leave a comment if you want to see more machine learning content on this channel.
|
||||
150620 153040 Thanks for watching, and I will see you in the next one.
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 44.
|
BIN
media/minst.jpg
Normal file
BIN
media/minst.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
BIN
media/mlp.jpeg
Normal file
BIN
media/mlp.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 272 KiB |
BIN
media/nn.png
Normal file
BIN
media/nn.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 154 KiB |
BIN
media/optimizer.gif
Normal file
BIN
media/optimizer.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 461 KiB |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "reveal.js",
|
||||
"version": "5.0.0",
|
||||
"version": "5.0.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "reveal.js",
|
||||
"version": "5.0.0",
|
||||
"version": "5.0.2",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.23.2",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "reveal.js",
|
||||
"version": "5.0.2",
|
||||
"version": "5.0.4",
|
||||
"description": "The HTML Presentation Framework",
|
||||
"homepage": "https://revealjs.com",
|
||||
"subdomain": "revealjs",
|
||||
|
||||
@@ -2,4 +2,4 @@ function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"de
|
||||
/*!
|
||||
* reveal.js plugin that adds syntax highlight support.
|
||||
*/
|
||||
const Rs={id:"highlight",HIGHLIGHT_STEP_DELIMITER:"|",HIGHLIGHT_LINE_DELIMITER:",",HIGHLIGHT_LINE_RANGE_DELIMITER:"-",hljs:fs,init:function(e){let t=e.getConfig().highlight||{};t.highlightOnLoad="boolean"!=typeof t.highlightOnLoad||t.highlightOnLoad,t.escapeHTML="boolean"!=typeof t.escapeHTML||t.escapeHTML,Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{e.parentNode.classList.add("code-wrapper");let a=e.querySelector('script[type="text/template"]');a&&(e.textContent=a.innerHTML),e.hasAttribute("data-trim")&&"function"==typeof e.innerHTML.trim&&(e.innerHTML=function(e){function t(e){return e.replace(/^[\s\uFEFF\xA0]+/g,"")}function a(e){for(var t=e.split("\n"),a=0;a<t.length&&""===t[a].trim();a++)t.splice(a--,1);for(a=t.length-1;a>=0&&""===t[a].trim();a--)t.splice(a,1);return t.join("\n")}return function(e){var n=a(e.innerHTML).split("\n"),i=n.reduce((function(e,a){return a.length>0&&t(a).length>0&&e>a.length-t(a).length?a.length-t(a).length:e}),Number.POSITIVE_INFINITY);return n.map((function(e,t){return e.slice(i)})).join("\n")}(e)}(e)),t.escapeHTML&&!e.hasAttribute("data-noescape")&&(e.innerHTML=e.innerHTML.replace(/</g,"<").replace(/>/g,">")),e.addEventListener("focusout",(function(e){fs.highlightElement(e.currentTarget)}),!1)})),"function"==typeof t.beforeHighlight&&t.beforeHighlight(fs),t.highlightOnLoad&&Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{Rs.highlightBlock(e)})),e.on("pdf-ready",(function(){[].slice.call(e.getRevealElement().querySelectorAll("pre code[data-line-numbers].current-fragment")).forEach((function(e){Rs.scrollHighlightedLineIntoView(e,{},!0)}))}))},highlightBlock:function(e){if(fs.highlightElement(e),0!==e.innerHTML.trim().length&&e.hasAttribute("data-line-numbers")){fs.lineNumbersBlock(e,{singleLine:!0});var t={currentBlock:e},a=Rs.deserializeHighlightSteps(e.getAttribute("data-line-numbers"));if(a.length>1){var n=parseInt(e.getAttribute("data-fragment-index"),10);("number"!=typeof n||isNaN(n))&&(n=null),a.slice(1).forEach((function(a){var i=e.cloneNode(!0);i.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a])),i.classList.add("fragment"),e.parentNode.appendChild(i),Rs.highlightLines(i),"number"==typeof n?(i.setAttribute("data-fragment-index",n),n+=1):i.removeAttribute("data-fragment-index"),i.addEventListener("visible",Rs.scrollHighlightedLineIntoView.bind(Rs,i,t)),i.addEventListener("hidden",Rs.scrollHighlightedLineIntoView.bind(Rs,i.previousSibling,t))})),e.removeAttribute("data-fragment-index"),e.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a[0]]))}var i="function"==typeof e.closest?e.closest("section:not(.stack)"):null;if(i){var r=function(){Rs.scrollHighlightedLineIntoView(e,t,!0),i.removeEventListener("visible",r)};i.addEventListener("visible",r)}Rs.highlightLines(e)}},scrollHighlightedLineIntoView:function(e,t,a){cancelAnimationFrame(t.animationFrameID),t.currentBlock&&(e.scrollTop=t.currentBlock.scrollTop),t.currentBlock=e;var n=this.getHighlightedLineBounds(e),i=e.offsetHeight,r=getComputedStyle(e);i-=parseInt(r.paddingTop)+parseInt(r.paddingBottom);var o=e.scrollTop,s=n.top+(Math.min(n.bottom-n.top,i)-i)/2,l=e.querySelector(".hljs-ln");if(l&&(s+=l.offsetTop-parseInt(r.paddingTop)),s=Math.max(Math.min(s,e.scrollHeight-i),0),!0===a||o===s)e.scrollTop=s;else{if(e.scrollHeight<=i)return;var c=0,_=function(){c=Math.min(c+.02,1),e.scrollTop=o+(s-o)*Rs.easeInOutQuart(c),c<1&&(t.animationFrameID=requestAnimationFrame(_))};_()}},easeInOutQuart:function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},getHighlightedLineBounds:function(e){var t=e.querySelectorAll(".highlight-line");if(0===t.length)return{top:0,bottom:0};var a=t[0],n=t[t.length-1];return{top:a.offsetTop,bottom:n.offsetTop+n.offsetHeight}},highlightLines:function(e,t){var a=Rs.deserializeHighlightSteps(t||e.getAttribute("data-line-numbers"));a.length&&a[0].forEach((function(t){var a=[];"number"==typeof t.end?a=[].slice.call(e.querySelectorAll("table tr:nth-child(n+"+t.start+"):nth-child(-n+"+t.end+")")):"number"==typeof t.start&&(a=[].slice.call(e.querySelectorAll("table tr:nth-child("+t.start+")"))),a.length&&(a.forEach((function(e){e.classList.add("highlight-line")})),e.classList.add("has-highlights"))}))},deserializeHighlightSteps:function(e){return(e=(e=e.replace(/\s/g,"")).split(Rs.HIGHLIGHT_STEP_DELIMITER)).map((function(e){return e.split(Rs.HIGHLIGHT_LINE_DELIMITER).map((function(e){if(/^[\d-]+$/.test(e)){e=e.split(Rs.HIGHLIGHT_LINE_RANGE_DELIMITER);var t=parseInt(e[0],10),a=parseInt(e[1],10);return isNaN(a)?{start:t}:{start:t,end:a}}return{}}))}))},serializeHighlightSteps:function(e){return e.map((function(e){return e.map((function(e){return"number"==typeof e.end?e.start+Rs.HIGHLIGHT_LINE_RANGE_DELIMITER+e.end:"number"==typeof e.start?e.start:""})).join(Rs.HIGHLIGHT_LINE_DELIMITER)})).join(Rs.HIGHLIGHT_STEP_DELIMITER)}};var Ns=()=>Rs;export{Ns as default};
|
||||
const Rs={id:"highlight",HIGHLIGHT_STEP_DELIMITER:"|",HIGHLIGHT_LINE_DELIMITER:",",HIGHLIGHT_LINE_RANGE_DELIMITER:"-",hljs:fs,init:function(e){let t=e.getConfig().highlight||{};t.highlightOnLoad="boolean"!=typeof t.highlightOnLoad||t.highlightOnLoad,t.escapeHTML="boolean"!=typeof t.escapeHTML||t.escapeHTML,Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{e.parentNode.classList.add("code-wrapper");let a=e.querySelector('script[type="text/template"]');a&&(e.textContent=a.innerHTML),e.hasAttribute("data-trim")&&"function"==typeof e.innerHTML.trim&&(e.innerHTML=function(e){function t(e){return e.replace(/^[\s\uFEFF\xA0]+/g,"")}function a(e){for(var t=e.split("\n"),a=0;a<t.length&&""===t[a].trim();a++)t.splice(a--,1);for(a=t.length-1;a>=0&&""===t[a].trim();a--)t.splice(a,1);return t.join("\n")}return function(e){var n=a(e.innerHTML).split("\n"),i=n.reduce((function(e,a){return a.length>0&&t(a).length>0&&e>a.length-t(a).length?a.length-t(a).length:e}),Number.POSITIVE_INFINITY);return n.map((function(e,t){return e.slice(i)})).join("\n")}(e)}(e)),t.escapeHTML&&!e.hasAttribute("data-noescape")&&(e.innerHTML=e.innerHTML.replace(/</g,"<").replace(/>/g,">")),e.addEventListener("focusout",(function(e){fs.highlightElement(e.currentTarget)}),!1)})),"function"==typeof t.beforeHighlight&&t.beforeHighlight(fs),t.highlightOnLoad&&Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{Rs.highlightBlock(e)})),e.on("pdf-ready",(function(){[].slice.call(e.getRevealElement().querySelectorAll("pre code[data-line-numbers].current-fragment")).forEach((function(e){Rs.scrollHighlightedLineIntoView(e,{},!0)}))}))},highlightBlock:function(e){if(fs.highlightElement(e),0!==e.innerHTML.trim().length&&e.hasAttribute("data-line-numbers")){fs.lineNumbersBlock(e,{singleLine:!0});var t={currentBlock:e},a=Rs.deserializeHighlightSteps(e.getAttribute("data-line-numbers"));if(a.length>1){var n=parseInt(e.getAttribute("data-fragment-index"),10);("number"!=typeof n||isNaN(n))&&(n=null),a.slice(1).forEach((function(a){var i=e.cloneNode(!0);i.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a])),i.classList.add("fragment"),e.parentNode.appendChild(i),Rs.highlightLines(i),"number"==typeof n?(i.setAttribute("data-fragment-index",n),n+=1):i.removeAttribute("data-fragment-index"),i.addEventListener("visible",Rs.scrollHighlightedLineIntoView.bind(Rs,i,t)),i.addEventListener("hidden",Rs.scrollHighlightedLineIntoView.bind(Rs,i.previousElementSibling,t))})),e.removeAttribute("data-fragment-index"),e.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a[0]]))}var i="function"==typeof e.closest?e.closest("section:not(.stack)"):null;if(i){var r=function(){Rs.scrollHighlightedLineIntoView(e,t,!0),i.removeEventListener("visible",r)};i.addEventListener("visible",r)}Rs.highlightLines(e)}},scrollHighlightedLineIntoView:function(e,t,a){cancelAnimationFrame(t.animationFrameID),t.currentBlock&&(e.scrollTop=t.currentBlock.scrollTop),t.currentBlock=e;var n=this.getHighlightedLineBounds(e),i=e.offsetHeight,r=getComputedStyle(e);i-=parseInt(r.paddingTop)+parseInt(r.paddingBottom);var o=e.scrollTop,s=n.top+(Math.min(n.bottom-n.top,i)-i)/2,l=e.querySelector(".hljs-ln");if(l&&(s+=l.offsetTop-parseInt(r.paddingTop)),s=Math.max(Math.min(s,e.scrollHeight-i),0),!0===a||o===s)e.scrollTop=s;else{if(e.scrollHeight<=i)return;var c=0,_=function(){c=Math.min(c+.02,1),e.scrollTop=o+(s-o)*Rs.easeInOutQuart(c),c<1&&(t.animationFrameID=requestAnimationFrame(_))};_()}},easeInOutQuart:function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},getHighlightedLineBounds:function(e){var t=e.querySelectorAll(".highlight-line");if(0===t.length)return{top:0,bottom:0};var a=t[0],n=t[t.length-1];return{top:a.offsetTop,bottom:n.offsetTop+n.offsetHeight}},highlightLines:function(e,t){var a=Rs.deserializeHighlightSteps(t||e.getAttribute("data-line-numbers"));a.length&&a[0].forEach((function(t){var a=[];"number"==typeof t.end?a=[].slice.call(e.querySelectorAll("table tr:nth-child(n+"+t.start+"):nth-child(-n+"+t.end+")")):"number"==typeof t.start&&(a=[].slice.call(e.querySelectorAll("table tr:nth-child("+t.start+")"))),a.length&&(a.forEach((function(e){e.classList.add("highlight-line")})),e.classList.add("has-highlights"))}))},deserializeHighlightSteps:function(e){return(e=(e=e.replace(/\s/g,"")).split(Rs.HIGHLIGHT_STEP_DELIMITER)).map((function(e){return e.split(Rs.HIGHLIGHT_LINE_DELIMITER).map((function(e){if(/^[\d-]+$/.test(e)){e=e.split(Rs.HIGHLIGHT_LINE_RANGE_DELIMITER);var t=parseInt(e[0],10),a=parseInt(e[1],10);return isNaN(a)?{start:t}:{start:t,end:a}}return{}}))}))},serializeHighlightSteps:function(e){return e.map((function(e){return e.map((function(e){return"number"==typeof e.end?e.start+Rs.HIGHLIGHT_LINE_RANGE_DELIMITER+e.end:"number"==typeof e.start?e.start:""})).join(Rs.HIGHLIGHT_LINE_DELIMITER)})).join(Rs.HIGHLIGHT_STEP_DELIMITER)}};var Ns=()=>Rs;export{Ns as default};
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
/*!
|
||||
* reveal.js plugin that adds syntax highlight support.
|
||||
*/
|
||||
const Rs={id:"highlight",HIGHLIGHT_STEP_DELIMITER:"|",HIGHLIGHT_LINE_DELIMITER:",",HIGHLIGHT_LINE_RANGE_DELIMITER:"-",hljs:fs,init:function(e){let t=e.getConfig().highlight||{};t.highlightOnLoad="boolean"!=typeof t.highlightOnLoad||t.highlightOnLoad,t.escapeHTML="boolean"!=typeof t.escapeHTML||t.escapeHTML,Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{e.parentNode.classList.add("code-wrapper");let a=e.querySelector('script[type="text/template"]');a&&(e.textContent=a.innerHTML),e.hasAttribute("data-trim")&&"function"==typeof e.innerHTML.trim&&(e.innerHTML=function(e){function t(e){return e.replace(/^[\s\uFEFF\xA0]+/g,"")}function a(e){for(var t=e.split("\n"),a=0;a<t.length&&""===t[a].trim();a++)t.splice(a--,1);for(a=t.length-1;a>=0&&""===t[a].trim();a--)t.splice(a,1);return t.join("\n")}return function(e){var n=a(e.innerHTML).split("\n"),i=n.reduce((function(e,a){return a.length>0&&t(a).length>0&&e>a.length-t(a).length?a.length-t(a).length:e}),Number.POSITIVE_INFINITY);return n.map((function(e,t){return e.slice(i)})).join("\n")}(e)}(e)),t.escapeHTML&&!e.hasAttribute("data-noescape")&&(e.innerHTML=e.innerHTML.replace(/</g,"<").replace(/>/g,">")),e.addEventListener("focusout",(function(e){fs.highlightElement(e.currentTarget)}),!1)})),"function"==typeof t.beforeHighlight&&t.beforeHighlight(fs),t.highlightOnLoad&&Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{Rs.highlightBlock(e)})),e.on("pdf-ready",(function(){[].slice.call(e.getRevealElement().querySelectorAll("pre code[data-line-numbers].current-fragment")).forEach((function(e){Rs.scrollHighlightedLineIntoView(e,{},!0)}))}))},highlightBlock:function(e){if(fs.highlightElement(e),0!==e.innerHTML.trim().length&&e.hasAttribute("data-line-numbers")){fs.lineNumbersBlock(e,{singleLine:!0});var t={currentBlock:e},a=Rs.deserializeHighlightSteps(e.getAttribute("data-line-numbers"));if(a.length>1){var n=parseInt(e.getAttribute("data-fragment-index"),10);("number"!=typeof n||isNaN(n))&&(n=null),a.slice(1).forEach((function(a){var i=e.cloneNode(!0);i.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a])),i.classList.add("fragment"),e.parentNode.appendChild(i),Rs.highlightLines(i),"number"==typeof n?(i.setAttribute("data-fragment-index",n),n+=1):i.removeAttribute("data-fragment-index"),i.addEventListener("visible",Rs.scrollHighlightedLineIntoView.bind(Rs,i,t)),i.addEventListener("hidden",Rs.scrollHighlightedLineIntoView.bind(Rs,i.previousSibling,t))})),e.removeAttribute("data-fragment-index"),e.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a[0]]))}var i="function"==typeof e.closest?e.closest("section:not(.stack)"):null;if(i){var r=function(){Rs.scrollHighlightedLineIntoView(e,t,!0),i.removeEventListener("visible",r)};i.addEventListener("visible",r)}Rs.highlightLines(e)}},scrollHighlightedLineIntoView:function(e,t,a){cancelAnimationFrame(t.animationFrameID),t.currentBlock&&(e.scrollTop=t.currentBlock.scrollTop),t.currentBlock=e;var n=this.getHighlightedLineBounds(e),i=e.offsetHeight,r=getComputedStyle(e);i-=parseInt(r.paddingTop)+parseInt(r.paddingBottom);var o=e.scrollTop,s=n.top+(Math.min(n.bottom-n.top,i)-i)/2,l=e.querySelector(".hljs-ln");if(l&&(s+=l.offsetTop-parseInt(r.paddingTop)),s=Math.max(Math.min(s,e.scrollHeight-i),0),!0===a||o===s)e.scrollTop=s;else{if(e.scrollHeight<=i)return;var c=0,_=function(){c=Math.min(c+.02,1),e.scrollTop=o+(s-o)*Rs.easeInOutQuart(c),c<1&&(t.animationFrameID=requestAnimationFrame(_))};_()}},easeInOutQuart:function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},getHighlightedLineBounds:function(e){var t=e.querySelectorAll(".highlight-line");if(0===t.length)return{top:0,bottom:0};var a=t[0],n=t[t.length-1];return{top:a.offsetTop,bottom:n.offsetTop+n.offsetHeight}},highlightLines:function(e,t){var a=Rs.deserializeHighlightSteps(t||e.getAttribute("data-line-numbers"));a.length&&a[0].forEach((function(t){var a=[];"number"==typeof t.end?a=[].slice.call(e.querySelectorAll("table tr:nth-child(n+"+t.start+"):nth-child(-n+"+t.end+")")):"number"==typeof t.start&&(a=[].slice.call(e.querySelectorAll("table tr:nth-child("+t.start+")"))),a.length&&(a.forEach((function(e){e.classList.add("highlight-line")})),e.classList.add("has-highlights"))}))},deserializeHighlightSteps:function(e){return(e=(e=e.replace(/\s/g,"")).split(Rs.HIGHLIGHT_STEP_DELIMITER)).map((function(e){return e.split(Rs.HIGHLIGHT_LINE_DELIMITER).map((function(e){if(/^[\d-]+$/.test(e)){e=e.split(Rs.HIGHLIGHT_LINE_RANGE_DELIMITER);var t=parseInt(e[0],10),a=parseInt(e[1],10);return isNaN(a)?{start:t}:{start:t,end:a}}return{}}))}))},serializeHighlightSteps:function(e){return e.map((function(e){return e.map((function(e){return"number"==typeof e.end?e.start+Rs.HIGHLIGHT_LINE_RANGE_DELIMITER+e.end:"number"==typeof e.start?e.start:""})).join(Rs.HIGHLIGHT_LINE_DELIMITER)})).join(Rs.HIGHLIGHT_STEP_DELIMITER)}};return()=>Rs}));
|
||||
const Rs={id:"highlight",HIGHLIGHT_STEP_DELIMITER:"|",HIGHLIGHT_LINE_DELIMITER:",",HIGHLIGHT_LINE_RANGE_DELIMITER:"-",hljs:fs,init:function(e){let t=e.getConfig().highlight||{};t.highlightOnLoad="boolean"!=typeof t.highlightOnLoad||t.highlightOnLoad,t.escapeHTML="boolean"!=typeof t.escapeHTML||t.escapeHTML,Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{e.parentNode.classList.add("code-wrapper");let a=e.querySelector('script[type="text/template"]');a&&(e.textContent=a.innerHTML),e.hasAttribute("data-trim")&&"function"==typeof e.innerHTML.trim&&(e.innerHTML=function(e){function t(e){return e.replace(/^[\s\uFEFF\xA0]+/g,"")}function a(e){for(var t=e.split("\n"),a=0;a<t.length&&""===t[a].trim();a++)t.splice(a--,1);for(a=t.length-1;a>=0&&""===t[a].trim();a--)t.splice(a,1);return t.join("\n")}return function(e){var n=a(e.innerHTML).split("\n"),i=n.reduce((function(e,a){return a.length>0&&t(a).length>0&&e>a.length-t(a).length?a.length-t(a).length:e}),Number.POSITIVE_INFINITY);return n.map((function(e,t){return e.slice(i)})).join("\n")}(e)}(e)),t.escapeHTML&&!e.hasAttribute("data-noescape")&&(e.innerHTML=e.innerHTML.replace(/</g,"<").replace(/>/g,">")),e.addEventListener("focusout",(function(e){fs.highlightElement(e.currentTarget)}),!1)})),"function"==typeof t.beforeHighlight&&t.beforeHighlight(fs),t.highlightOnLoad&&Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{Rs.highlightBlock(e)})),e.on("pdf-ready",(function(){[].slice.call(e.getRevealElement().querySelectorAll("pre code[data-line-numbers].current-fragment")).forEach((function(e){Rs.scrollHighlightedLineIntoView(e,{},!0)}))}))},highlightBlock:function(e){if(fs.highlightElement(e),0!==e.innerHTML.trim().length&&e.hasAttribute("data-line-numbers")){fs.lineNumbersBlock(e,{singleLine:!0});var t={currentBlock:e},a=Rs.deserializeHighlightSteps(e.getAttribute("data-line-numbers"));if(a.length>1){var n=parseInt(e.getAttribute("data-fragment-index"),10);("number"!=typeof n||isNaN(n))&&(n=null),a.slice(1).forEach((function(a){var i=e.cloneNode(!0);i.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a])),i.classList.add("fragment"),e.parentNode.appendChild(i),Rs.highlightLines(i),"number"==typeof n?(i.setAttribute("data-fragment-index",n),n+=1):i.removeAttribute("data-fragment-index"),i.addEventListener("visible",Rs.scrollHighlightedLineIntoView.bind(Rs,i,t)),i.addEventListener("hidden",Rs.scrollHighlightedLineIntoView.bind(Rs,i.previousElementSibling,t))})),e.removeAttribute("data-fragment-index"),e.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a[0]]))}var i="function"==typeof e.closest?e.closest("section:not(.stack)"):null;if(i){var r=function(){Rs.scrollHighlightedLineIntoView(e,t,!0),i.removeEventListener("visible",r)};i.addEventListener("visible",r)}Rs.highlightLines(e)}},scrollHighlightedLineIntoView:function(e,t,a){cancelAnimationFrame(t.animationFrameID),t.currentBlock&&(e.scrollTop=t.currentBlock.scrollTop),t.currentBlock=e;var n=this.getHighlightedLineBounds(e),i=e.offsetHeight,r=getComputedStyle(e);i-=parseInt(r.paddingTop)+parseInt(r.paddingBottom);var o=e.scrollTop,s=n.top+(Math.min(n.bottom-n.top,i)-i)/2,l=e.querySelector(".hljs-ln");if(l&&(s+=l.offsetTop-parseInt(r.paddingTop)),s=Math.max(Math.min(s,e.scrollHeight-i),0),!0===a||o===s)e.scrollTop=s;else{if(e.scrollHeight<=i)return;var c=0,_=function(){c=Math.min(c+.02,1),e.scrollTop=o+(s-o)*Rs.easeInOutQuart(c),c<1&&(t.animationFrameID=requestAnimationFrame(_))};_()}},easeInOutQuart:function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},getHighlightedLineBounds:function(e){var t=e.querySelectorAll(".highlight-line");if(0===t.length)return{top:0,bottom:0};var a=t[0],n=t[t.length-1];return{top:a.offsetTop,bottom:n.offsetTop+n.offsetHeight}},highlightLines:function(e,t){var a=Rs.deserializeHighlightSteps(t||e.getAttribute("data-line-numbers"));a.length&&a[0].forEach((function(t){var a=[];"number"==typeof t.end?a=[].slice.call(e.querySelectorAll("table tr:nth-child(n+"+t.start+"):nth-child(-n+"+t.end+")")):"number"==typeof t.start&&(a=[].slice.call(e.querySelectorAll("table tr:nth-child("+t.start+")"))),a.length&&(a.forEach((function(e){e.classList.add("highlight-line")})),e.classList.add("has-highlights"))}))},deserializeHighlightSteps:function(e){return(e=(e=e.replace(/\s/g,"")).split(Rs.HIGHLIGHT_STEP_DELIMITER)).map((function(e){return e.split(Rs.HIGHLIGHT_LINE_DELIMITER).map((function(e){if(/^[\d-]+$/.test(e)){e=e.split(Rs.HIGHLIGHT_LINE_RANGE_DELIMITER);var t=parseInt(e[0],10),a=parseInt(e[1],10);return isNaN(a)?{start:t}:{start:t,end:a}}return{}}))}))},serializeHighlightSteps:function(e){return e.map((function(e){return e.map((function(e){return"number"==typeof e.end?e.start+Rs.HIGHLIGHT_LINE_RANGE_DELIMITER+e.end:"number"==typeof e.start?e.start:""})).join(Rs.HIGHLIGHT_LINE_DELIMITER)})).join(Rs.HIGHLIGHT_STEP_DELIMITER)}};return()=>Rs}));
|
||||
|
||||
@@ -138,7 +138,7 @@ const Plugin = {
|
||||
|
||||
// Scroll highlights into view as we step through them
|
||||
fragmentBlock.addEventListener( 'visible', Plugin.scrollHighlightedLineIntoView.bind( Plugin, fragmentBlock, scrollState ) );
|
||||
fragmentBlock.addEventListener( 'hidden', Plugin.scrollHighlightedLineIntoView.bind( Plugin, fragmentBlock.previousSibling, scrollState ) );
|
||||
fragmentBlock.addEventListener( 'hidden', Plugin.scrollHighlightedLineIntoView.bind( Plugin, fragmentBlock.previousElementSibling, scrollState ) );
|
||||
|
||||
} );
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ const Plugin = () => {
|
||||
|
||||
this.setRegex = function(input)
|
||||
{
|
||||
input = input.replace(/^[^\w]+|[^\w]+$/g, "").replace(/[^\w'-]+/g, "|");
|
||||
input = input.trim();
|
||||
matchRegex = new RegExp("(" + input + ")","i");
|
||||
}
|
||||
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
*
|
||||
* @author Jon Snyder <snyder.jon@gmail.com>, February 2013
|
||||
*/
|
||||
const e=()=>{let e,t,n,l,o,i,r;function s(){t=document.createElement("div"),t.classList.add("searchbox"),t.style.position="absolute",t.style.top="10px",t.style.right="10px",t.style.zIndex=10,t.innerHTML='<input type="search" class="searchinput" placeholder="Search..." style="vertical-align: top;"/>\n\t\t</span>',n=t.querySelector(".searchinput"),n.style.width="240px",n.style.fontSize="14px",n.style.padding="4px 6px",n.style.color="#000",n.style.background="#fff",n.style.borderRadius="2px",n.style.border="0",n.style.outline="0",n.style.boxShadow="0 2px 18px rgba(0, 0, 0, 0.2)",n.style["-webkit-appearance"]="none",e.getRevealElement().appendChild(t),n.addEventListener("keyup",(function(t){if(13===t.keyCode)t.preventDefault(),function(){if(i){var t=n.value;""===t?(r&&r.remove(),l=null):(r=new c("slidecontent"),l=r.apply(t),o=0)}l&&(l.length&&l.length<=o&&(o=0),l.length>o&&(e.slide(l[o].h,l[o].v),o++))}(),i=!1;else i=!0}),!1),d()}function a(){t||s(),t.style.display="inline",n.focus(),n.select()}function d(){t||s(),t.style.display="none",r&&r.remove()}function c(t,n){var l=document.getElementById(t)||document.body,o=n||"EM",i=new RegExp("^(?:"+o+"|SCRIPT|FORM)$"),r=["#ff6","#a0ffff","#9f9","#f99","#f6f"],s=[],a=0,d="",c=[];this.setRegex=function(e){e=e.replace(/^[^\w]+|[^\w]+$/g,"").replace(/[^\w'-]+/g,"|"),d=new RegExp("("+e+")","i")},this.getRegex=function(){return d.toString().replace(/^\/\\b\(|\)\\b\/i$/g,"").replace(/\|/g," ")},this.hiliteWords=function(t){if(null!=t&&t&&d&&!i.test(t.nodeName)){if(t.hasChildNodes())for(var n=0;n<t.childNodes.length;n++)this.hiliteWords(t.childNodes[n]);var l,p;if(3==t.nodeType)if((l=t.nodeValue)&&(p=d.exec(l))){for(var u=t;null!=u&&"SECTION"!=u.nodeName;)u=u.parentNode;var h=e.getIndices(u),f=c.length,y=!1;for(n=0;n<f;n++)c[n].h===h.h&&c[n].v===h.v&&(y=!0);y||c.push(h),s[p[0].toLowerCase()]||(s[p[0].toLowerCase()]=r[a++%r.length]);var g=document.createElement(o);g.appendChild(document.createTextNode(p[0])),g.style.backgroundColor=s[p[0].toLowerCase()],g.style.fontStyle="inherit",g.style.color="#000";var v=t.splitText(p.index);v.nodeValue=v.nodeValue.substring(p[0].length),t.parentNode.insertBefore(g,v)}}},this.remove=function(){for(var e,t=document.getElementsByTagName(o);t.length&&(e=t[0]);)e.parentNode.replaceChild(e.firstChild,e)},this.apply=function(e){if(null!=e&&e)return this.remove(),this.setRegex(e),this.hiliteWords(l),c}}return{id:"search",init:n=>{e=n,e.registerKeyboardShortcut("CTRL + Shift + F","Search"),document.addEventListener("keydown",(function(e){"F"==e.key&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),t||s(),"inline"!==t.style.display?a():d())}),!1)},open:a}};export{e as default};
|
||||
const e=()=>{let e,t,n,l,i,o,r;function s(){t=document.createElement("div"),t.classList.add("searchbox"),t.style.position="absolute",t.style.top="10px",t.style.right="10px",t.style.zIndex=10,t.innerHTML='<input type="search" class="searchinput" placeholder="Search..." style="vertical-align: top;"/>\n\t\t</span>',n=t.querySelector(".searchinput"),n.style.width="240px",n.style.fontSize="14px",n.style.padding="4px 6px",n.style.color="#000",n.style.background="#fff",n.style.borderRadius="2px",n.style.border="0",n.style.outline="0",n.style.boxShadow="0 2px 18px rgba(0, 0, 0, 0.2)",n.style["-webkit-appearance"]="none",e.getRevealElement().appendChild(t),n.addEventListener("keyup",(function(t){if(13===t.keyCode)t.preventDefault(),function(){if(o){var t=n.value;""===t?(r&&r.remove(),l=null):(r=new c("slidecontent"),l=r.apply(t),i=0)}l&&(l.length&&l.length<=i&&(i=0),l.length>i&&(e.slide(l[i].h,l[i].v),i++))}(),o=!1;else o=!0}),!1),d()}function a(){t||s(),t.style.display="inline",n.focus(),n.select()}function d(){t||s(),t.style.display="none",r&&r.remove()}function c(t,n){var l=document.getElementById(t)||document.body,i=n||"EM",o=new RegExp("^(?:"+i+"|SCRIPT|FORM)$"),r=["#ff6","#a0ffff","#9f9","#f99","#f6f"],s=[],a=0,d="",c=[];this.setRegex=function(e){e=e.trim(),d=new RegExp("("+e+")","i")},this.getRegex=function(){return d.toString().replace(/^\/\\b\(|\)\\b\/i$/g,"").replace(/\|/g," ")},this.hiliteWords=function(t){if(null!=t&&t&&d&&!o.test(t.nodeName)){if(t.hasChildNodes())for(var n=0;n<t.childNodes.length;n++)this.hiliteWords(t.childNodes[n]);var l,p;if(3==t.nodeType)if((l=t.nodeValue)&&(p=d.exec(l))){for(var u=t;null!=u&&"SECTION"!=u.nodeName;)u=u.parentNode;var h=e.getIndices(u),f=c.length,y=!1;for(n=0;n<f;n++)c[n].h===h.h&&c[n].v===h.v&&(y=!0);y||c.push(h),s[p[0].toLowerCase()]||(s[p[0].toLowerCase()]=r[a++%r.length]);var g=document.createElement(i);g.appendChild(document.createTextNode(p[0])),g.style.backgroundColor=s[p[0].toLowerCase()],g.style.fontStyle="inherit",g.style.color="#000";var v=t.splitText(p.index);v.nodeValue=v.nodeValue.substring(p[0].length),t.parentNode.insertBefore(g,v)}}},this.remove=function(){for(var e,t=document.getElementsByTagName(i);t.length&&(e=t[0]);)e.parentNode.replaceChild(e.firstChild,e)},this.apply=function(e){if(null!=e&&e)return this.remove(),this.setRegex(e),this.hiliteWords(l),c}}return{id:"search",init:n=>{e=n,e.registerKeyboardShortcut("CTRL + Shift + F","Search"),document.addEventListener("keydown",(function(e){"F"==e.key&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),t||s(),"inline"!==t.style.display?a():d())}),!1)},open:a}};export{e as default};
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
* by navigatating to that slide and highlighting it.
|
||||
*
|
||||
* @author Jon Snyder <snyder.jon@gmail.com>, February 2013
|
||||
*/return()=>{let e,t,n,l,o,i,r;function s(){t=document.createElement("div"),t.classList.add("searchbox"),t.style.position="absolute",t.style.top="10px",t.style.right="10px",t.style.zIndex=10,t.innerHTML='<input type="search" class="searchinput" placeholder="Search..." style="vertical-align: top;"/>\n\t\t</span>',n=t.querySelector(".searchinput"),n.style.width="240px",n.style.fontSize="14px",n.style.padding="4px 6px",n.style.color="#000",n.style.background="#fff",n.style.borderRadius="2px",n.style.border="0",n.style.outline="0",n.style.boxShadow="0 2px 18px rgba(0, 0, 0, 0.2)",n.style["-webkit-appearance"]="none",e.getRevealElement().appendChild(t),n.addEventListener("keyup",(function(t){if(13===t.keyCode)t.preventDefault(),function(){if(i){var t=n.value;""===t?(r&&r.remove(),l=null):(r=new c("slidecontent"),l=r.apply(t),o=0)}l&&(l.length&&l.length<=o&&(o=0),l.length>o&&(e.slide(l[o].h,l[o].v),o++))}(),i=!1;else i=!0}),!1),d()}function a(){t||s(),t.style.display="inline",n.focus(),n.select()}function d(){t||s(),t.style.display="none",r&&r.remove()}function c(t,n){var l=document.getElementById(t)||document.body,o=n||"EM",i=new RegExp("^(?:"+o+"|SCRIPT|FORM)$"),r=["#ff6","#a0ffff","#9f9","#f99","#f6f"],s=[],a=0,d="",c=[];this.setRegex=function(e){e=e.replace(/^[^\w]+|[^\w]+$/g,"").replace(/[^\w'-]+/g,"|"),d=new RegExp("("+e+")","i")},this.getRegex=function(){return d.toString().replace(/^\/\\b\(|\)\\b\/i$/g,"").replace(/\|/g," ")},this.hiliteWords=function(t){if(null!=t&&t&&d&&!i.test(t.nodeName)){if(t.hasChildNodes())for(var n=0;n<t.childNodes.length;n++)this.hiliteWords(t.childNodes[n]);var l,f;if(3==t.nodeType)if((l=t.nodeValue)&&(f=d.exec(l))){for(var p=t;null!=p&&"SECTION"!=p.nodeName;)p=p.parentNode;var u=e.getIndices(p),h=c.length,y=!1;for(n=0;n<h;n++)c[n].h===u.h&&c[n].v===u.v&&(y=!0);y||c.push(u),s[f[0].toLowerCase()]||(s[f[0].toLowerCase()]=r[a++%r.length]);var g=document.createElement(o);g.appendChild(document.createTextNode(f[0])),g.style.backgroundColor=s[f[0].toLowerCase()],g.style.fontStyle="inherit",g.style.color="#000";var v=t.splitText(f.index);v.nodeValue=v.nodeValue.substring(f[0].length),t.parentNode.insertBefore(g,v)}}},this.remove=function(){for(var e,t=document.getElementsByTagName(o);t.length&&(e=t[0]);)e.parentNode.replaceChild(e.firstChild,e)},this.apply=function(e){if(null!=e&&e)return this.remove(),this.setRegex(e),this.hiliteWords(l),c}}return{id:"search",init:n=>{e=n,e.registerKeyboardShortcut("CTRL + Shift + F","Search"),document.addEventListener("keydown",(function(e){"F"==e.key&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),t||s(),"inline"!==t.style.display?a():d())}),!1)},open:a}}}));
|
||||
*/return()=>{let e,t,n,i,o,l,r;function s(){t=document.createElement("div"),t.classList.add("searchbox"),t.style.position="absolute",t.style.top="10px",t.style.right="10px",t.style.zIndex=10,t.innerHTML='<input type="search" class="searchinput" placeholder="Search..." style="vertical-align: top;"/>\n\t\t</span>',n=t.querySelector(".searchinput"),n.style.width="240px",n.style.fontSize="14px",n.style.padding="4px 6px",n.style.color="#000",n.style.background="#fff",n.style.borderRadius="2px",n.style.border="0",n.style.outline="0",n.style.boxShadow="0 2px 18px rgba(0, 0, 0, 0.2)",n.style["-webkit-appearance"]="none",e.getRevealElement().appendChild(t),n.addEventListener("keyup",(function(t){if(13===t.keyCode)t.preventDefault(),function(){if(l){var t=n.value;""===t?(r&&r.remove(),i=null):(r=new c("slidecontent"),i=r.apply(t),o=0)}i&&(i.length&&i.length<=o&&(o=0),i.length>o&&(e.slide(i[o].h,i[o].v),o++))}(),l=!1;else l=!0}),!1),d()}function a(){t||s(),t.style.display="inline",n.focus(),n.select()}function d(){t||s(),t.style.display="none",r&&r.remove()}function c(t,n){var i=document.getElementById(t)||document.body,o=n||"EM",l=new RegExp("^(?:"+o+"|SCRIPT|FORM)$"),r=["#ff6","#a0ffff","#9f9","#f99","#f6f"],s=[],a=0,d="",c=[];this.setRegex=function(e){e=e.trim(),d=new RegExp("("+e+")","i")},this.getRegex=function(){return d.toString().replace(/^\/\\b\(|\)\\b\/i$/g,"").replace(/\|/g," ")},this.hiliteWords=function(t){if(null!=t&&t&&d&&!l.test(t.nodeName)){if(t.hasChildNodes())for(var n=0;n<t.childNodes.length;n++)this.hiliteWords(t.childNodes[n]);var i,f;if(3==t.nodeType)if((i=t.nodeValue)&&(f=d.exec(i))){for(var u=t;null!=u&&"SECTION"!=u.nodeName;)u=u.parentNode;var p=e.getIndices(u),h=c.length,y=!1;for(n=0;n<h;n++)c[n].h===p.h&&c[n].v===p.v&&(y=!0);y||c.push(p),s[f[0].toLowerCase()]||(s[f[0].toLowerCase()]=r[a++%r.length]);var g=document.createElement(o);g.appendChild(document.createTextNode(f[0])),g.style.backgroundColor=s[f[0].toLowerCase()],g.style.fontStyle="inherit",g.style.color="#000";var v=t.splitText(f.index);v.nodeValue=v.nodeValue.substring(f[0].length),t.parentNode.insertBefore(g,v)}}},this.remove=function(){for(var e,t=document.getElementsByTagName(o);t.length&&(e=t[0]);)e.parentNode.replaceChild(e.firstChild,e)},this.apply=function(e){if(null!=e&&e)return this.remove(),this.setRegex(e),this.hiliteWords(i),c}}return{id:"search",init:n=>{e=n,e.registerKeyboardShortcut("CTRL + Shift + F","Search"),document.addEventListener("keydown",(function(e){"F"==e.key&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),t||s(),"inline"!==t.style.display?a():d())}),!1)},open:a}}}));
|
||||
|
||||
Reference in New Issue
Block a user