Tuesday, 15 December 2015

MarkdownEditing

MarkdownEditing

Markdown plugin for Sublime Text. Provides a decent Markdown color scheme (light and dark) with more robust syntax highlighting and useful Markdown editing features for Sublime Text. 3 flavors are supported: Standard Markdown, GitHub flavored Markdown, MultiMarkdown.

MarkdownEditing

Dark and yellow theme available.

Overview

Features

  • Asterisks and underscores are autopaired and will wrap selected text
    • If you start an empty pair and hit backspace, both elements are deleted
    • If you start an empty pair and hit space, the right element is deleted
  • Backticks are paired
  • At the end of a list item, pressing Enter will automatically insert the new list item bullet.
    • Pressing Tab on the blank list item will indent it and switch the list bullet to another one (Order is *, -, + in a cycle).
    • Pressing Shift Tab on the blank list item will unindent it in the same way as above.
    • Sequential Tab s or Shift Tab s are supported.
    • You can disable automatic bullet switching or choose which bullets to be used, in your settings file.
    • If a list item contains a GFM task, pressing Enter at the end of the line will continue with a new blank task.
  • At the end of a blockquote line, pressing Enter will automatically extend blockquote.
  • Selecting some text and pressing > will convert it to blockquote. The first and the last line don’t have to be fully selected; partial select works, too.
  • Left bracket pairing is modified to eliminate the selection and leave the cursor at a point where you can insert a [] or () pair for a link
  • Displays Markdown headers in the Project Symbol List (Ctrl Shift R). They will start with #, so you will know they belong to markdown files at a glance. Also they will be on top of the list because of the presedence of #.
  • ~ wraps selected text with ~~ (strikethrough).
  • Typing # when there’s a selection will surround it with # to make it a headline. Multiple presses add additional hashes, increasing the level of the header. Once you hit 6 hashes, it will reset to 0 on the next press. The mde.match_header_hashes will determine if the # are mirrored on both sides or just at the beginning of the line.
  • Typing return at the end of a line that begins with hashmarks will insert closing hashmarks on the headline. They’re not required for Markdown, it’s just aesthetics, and you can change the mde.match_header_hashes option in your settings to disable.
  • Setext-style headers can be completed with Tab. That is, typing Tab on a line containing only = or - characters will add or remove enough characters to it to match the length of the line above.
  • New documents will be named automatically based on the first header.

Key Bindings

OS X Windows/Linux Description
V CtrlWinV Pastes the contents of the clipboard as an inline link on selected text.
R CtrlWinR Pastes the contents of the clipboard as a reference link.
K CtrlWinK Inserts a standard inline link.
K ShiftWinK Inserts an inline image.
B I CtrlShiftB CtrlShiftI These are bound to bold and italic. They work both with and without selections. If there is no selection, they will just transform the word under the cursor. These keybindings will unbold/unitalicize selection if it is already bold/italic.
^1...6 Ctrl1...6 These will add the corresponding number of hashmarks for headlines. Works on blank lines and selected text in tandem with the above headline tools. If you select an entire existing headline, the current hashmarks will be removed and replaced with the header level you requested. This command respects the mde.match_header_hashes preference setting.
6 CtrlShift6 Inserts a footnote and jump to its definition. If your cursor is in a definition, it will jump back to the marker.
F AltShiftF Locates footnote markers without definitions and inserts their markers for the definition.
G AltShiftG Locates link references without definitions and inserts their labels at the bottom for the definition.

GFM Specific Features

Underscores in words doesn’t mess with bold or italic style:

underscore-in-words

Fenced code blocks gets syntax highlighting inside:

fenced-code-block

Keyboard shortcuts gets highlighted like in GitHub:

keyboard-shortcut

Strikethrough is supported:

strikethrough

Commands for Command Palette

Fix Underlined Headers

Adjusts every setext-style header to add or remove = or - characters as needed to match the lengths of their header text.

Convert Underlined Headers to ATX

Converts every setext-style header into an ATX style header. If something is selected only the headers in the selections will be converted, otherwise the conversion will be applied to the whole view.

Scans document for referenced link usages ([some link][some_ref] and [some link][]) and checks if they are all defined. If there are undefined link references, command will automatically create their definition snippet at the bottom of the file.

Markdown Lint

Performs lint on current Markdown file. See lint rules. Some of the linting rules are customizable via user settings file.

Switch List Bullet Type

Switches the highlighted list between numbered and bulleted style.

Installation

Important Note About Installation

Are you getting this error after installation: Error loading syntax file “Packages/Markdown/Markdown.tmLanguage”: Unable to open Packages/Markdown/Markdown.tmLanguage? This is caused by open markdown files at the install time. You have to manually change their syntax to your newly installed Markdown syntax. Read the below paragraph for more details on this.

Note: Sublime text has a native tiny package for Markdown. However, when MarkdownEditing is enabled, native package causes some conflicts. For this reason, MarkdownEditing will automatically disable it. Since it doesn’t bring anything new over MarkdownEditing, this is not a loss. But remember, when you disable MarkdownEditing, you have to reenable the native one manually (if you want).

If you are using Sublime Text 2, you have to disable the native package manually. To do that, add Markdown to your ignored_packages list in ST user settings:

"ignored_packages": [..., "Markdown"],

Package Control

The preferred method of installation is via Sublime Package Control.

  1. Install Sublime Package Control
  2. From inside Sublime Text, open Package Control’s Command Pallet: CTRL SHIFT P (Windows, Linux) or CMD SHIFT P on Mac.
  3. Type install package and hit Return. A list of available packages will be displayed.
  4. Type MarkdownEditing and hit Return. The package will be downloaded to the appropriate directory.
  5. Restart Sublime Text to complete installation. Open a Markdown file and this custom theme. The features listed above should now be available.

Manual Installation

  1. Download or clone this repository to a directory MarkdownEditing in the Sublime Text Packages directory for your platform:
    • Mac: git clone https://github.com/SublimeText-Markdown/MarkdownEditing.git ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/MarkdownEditing
    • Windows: git clone https://github.com/SublimeText-Markdown/MarkdownEditing.git %APPDATA%\Sublime/ Text/ 2/\MarkdownEditing
    • Linux: git clone https://github.com/SublimeText-Markdown/MarkdownEditing.git ~/.Sublime\ Text\ 2/Packages/MarkdownEditing
  2. Restart Sublime Text to complete installation. Open a Markdown file and this custom theme. The features listed above should now be available.

Configuration

The plugin contains 3 different Markdown flavors: Standard Markdown, GitHub flavored Markdown, MultiMarkdown. Default is GitHub flavored Markdown. If you want to set another one as default, open a Markdown file and select your flavor from the menu: View > Syntax > Open all with current extension as. You’re done.

You may want to have a look at the default settings files. They are located at:

Packages/MarkdownEditing/Markdown.sublime-settings         [GitHub flavored Markdown]
Packages/MarkdownEditing/Markdown (Standard).sublime-settings
Packages/MarkdownEditing/MultiMarkdown.sublime-settings

If you want to override any of the default settings, you can open the appropriate user settings file using the Preferences > Package Settings > Markdown Editing menu. Each flavor has a different settings file.

Bold and italic markers are configurable through ST shell variables. You can use Preferences > Package Settings > Markdown Editing menu to see the default settings file. In order to override it, copy & paste its content into the user settings file (Packages/User/Bold and Italic Markers.tmPreferences) from the menu and make your edits. It is pretty straightforward.

In order to activate the dark or the yellow theme, put one of these lines to your user settings file of the flavor (Packages/User/[flavor].sublime-settings):

"color_scheme": "Packages/MarkdownEditing/MarkdownEditor-Dark.tmTheme",
"color_scheme": "Packages/MarkdownEditing/MarkdownEditor-Yellow.tmTheme",

If you want to go with your already existing theme, you can reenable it with the same method as above. Keep in mind that, that theme may not cover all the parts of the Markdown syntax that this plugin defines.

By default, when you install the plugin, files with these extensions will be assigned to Markdown syntax: “md”, “txt”, “mdown”, “markdown”, “markdn”. If you want to prevent any of these extensions to be opened as Markdown, follow these steps:

  1. Click on the language menu at bottom right
  2. Select “Open all with current extension as”
  3. Choose your preferred syntax for that extension

Tips

We are maintaining a tips section in our Wiki. Jump there to learn from others or share your experiences with others.

Similar Plugins

  • Knockdown

    Knockdown offers useful Markdown features and a custom Markdown theme. All of its unique features except its theme are ported to MarkdownEditing and some of them are actually improved further in MarkdownEditing.

  • Sublime Markdown Extended
  • SmartMarkdown

Known Bugs

  • Setext-style headers (=== and ---) do not show up in the symbol list. This is due to a Sublime Text limitation (see #158). However, we are able to put a placeholder to indicate the existence of the header. We encourage you to use Atx-style headers (#).

  • Installing for the first time while having markdown files opened may cause MarkdownEditing to behave unexpectedly on those files. Close and reopen those files to fix it.

Contributing

See CONTRIBUTING.md file.

Credits

MarkdownEditing was originally created by Brett Terpstra and has become a community project with the goal of consolidating the best features from the varied collection of Markdown packages for Sublime Text. Current development is headed up by Ali Ayas.

Related blog posts from Brett:
* http://brettterpstra.com/2012/05/17/markdown-editing-for-sublime-text-2-humble-beginnings/
* http://brettterpstra.com/2013/11/23/markdownediting-for-sublime-text-updates/

This plugin contains portions of code from Knockdown.

Footnote commands were submitted by J. Nicholas Geist and originated at geekabouttown.

Donation

You can support contributors of this project individually. Every contributor is welcomed to add his/her line below with any content. Ordering shall be alphabetically by GitHub username.

License

MarkdownEditing is released under the MIT License.

1

1

1

Sunday, 21 September 2014

Machine Learning Octave 笔记.md

Machine Learning Octave 笔记

@(Machine Learning)[Machine Learning,Octave]

0.准备

添加路径,可以直接运行该目录的m文件函数。

addpath ("C:\\octave\\workspace\\ml-class\\mlclass-ex1")

添加路径有些问题,当两个路径中有相同的函数,将会出现错误,将会从最近的一个路径进行搜索!所以后面实验还是要直接进入到相应目录。

cd("C:\\octave\\workspace\\ml-class\\mlclass-ex2")

1.关于冒号的使用方法

data = load('ex1data2.txt');
X = data(:, 1:2);
y = data(:, 3);
m = length(y);

这三句代码是加载数据并且进行数据的赋值,这里需要注意的一点事:在这里怎么用?具体可以参考文档8 Expressions

在括号中前后两个位置分别代表column和row,也就是竖和横(列和行)
第一个位置:按来选取 column 记忆法,有个l上下贯穿,所以是列。
第二个位置:按来选取 row 记忆法:有个w,左右链接,所以是行

:解释1: 代表所有数据,根据所在括号的位置来选取
:解释2: 表示两个从一个数字到一个数字

所以X = data(:, 1:2);表示将data中的数据按照列选取,选出其中的1到2列赋值给X。

octave:6> test = [1,2,3,4;5,6,7,8;9,10,11,12]
test =
1    2    3    4
5    6    7    8
9   10   11   12
octave:7> a = test(:,1:2)
a =
1    2
5    6
9   10
octave:8> b = test(3,:) 按行取出第三行赋值给b
b =
9   10   11   12

length(y)函数比较奇怪,它表示获取矩阵最大的维度。譬如length(b)就是4,而length(a)就是3。

fprintf(' x = [%.0f %.0f], y = %.0f \n', [X(1:10,:) y(1:10,:)]');

这里面的冒号又是什么意思呢? 一个道理,按行选取1到10行!

2.Ex1问题详解

mu = zeros(1, size(X, 2));

size(X,2)表示返回X的第二个维度的大小,第二个维度也就是列,column。

mu = mean(X);
sigma = std(X);

需要注意的是矩阵的函数都是针对矩阵进行运算的。

meanstd默认是column求平均数,这样求得就是行向量;
如果是按行求需要加入DIM参数2,求得列向量。

octave:39> mean(test,2)
ans =  2.5000
       6.5000
       10.5000

If X is a matrix, compute the mean for each column and return them in a row vector.

X = [ones(m, 1) X];

在X基础上加入m行数字1. 可以发现当第二个参数为1时就是列向量,如果第一个参数为1,则为行向量。

htheta = X * theta;

矩阵乘法 X( m行3列),theta(3行1列) == (m行1列):求出 HΘ(x). 记住这里直接使用矩阵乘法模拟了多个变量的多项式组合.
HΘ(x)=y=θ1x1+θ2x2+θ3x3
变成矩阵就是
x(1)1 x(2)1 x(3)1 x(4)1 ...x(1)2x(2)2x(3)2x(4)2x(1)3x(2)3x(3)3x(4)3theta1 theta2 theta3

theta_tmp(row) = theta(row) - alpha / m * sum((htheta - y) .* X(:,row));

更新θ

theta_tmp(row) = theta(row) - alpha / m * sum((htheta - y) .* X(:,row));

计算对应的cost,迭代100次

predictions = X * theta;
sqrErrors = (predictions - y).^2;
J = 1 / (2*m) * sum(sqrErrors);

J = (X*theta - y)' * (X*theta - y) / (2*m);

对比一下两种求J的方法,后一种是使用矩阵格式

(x(1)1 x(2)1 x(3)1 x(4)1 ...x(1)2x(2)2x(3)2x(4)2x(1)3x(2)3x(3)3x(4)3theta1 theta2 theta3y(1) y(2) y(3) y(4) ...)(x(1)1 x(2)1 x(3)1 x(4)1 ...x(1)2x(2)2x(3)2x(4)2x(1)3x(2)3x(3)3x(4)3theta1 theta2 theta3y(1) y(2) y(3) y(4) ...)/(2m)

3. Ex2 问题详解

该实验主要是解决逻辑回归问题

首先我们要了解函数optimset 和fminunc这两个函数可以快速实现优化.

options = optimset('GradObj', 'on', 'MaxIter', 400);

Optimset 解析,相当于配置了优化算法
Function File: optimset (PAR, VAL, …)
– Function File: optimset (OLD, PAR, VAL, …)
– Function File: optimset (OLD, NEW)
Create options struct for optimization functions.

GradObj When set to “on”, the function to be minimized must return a second argument which is the gradient, or first derivative, of the function at the point X. If set to “off” [default], the gradient is computed via finite differences.
MaxIter Maximum number of algorithm iterations before optimization stops. Must be a positive integer.

[theta, cost] = ...
fminunc(@(t)(costFunction(t, X, y)), initial_theta, options);

对于@(t)的解释

见文档P178-11.10.2

11.10.2 Anonymous Functions
Anonymous functions are defined using the syntax

@(argument-list ) expression

Any variables that are not found in the argument list are inherited from the enclosing scope.
Anonymous functions are useful for creating simple unnamed functions from expressions or for wrapping calls to other functions to adapt them for use by functions like quad. For example,

f = @(x) x.^2;
quad (f, 0, 10) 从0到10对f进行积分,相当于把后面的变量传递给f
⇒ 333.33

creates a simple unnamed function from the expression x.^2 and passes it to quad,

quad (@(x) sin (x), 0, pi)
⇒ 2

wraps another function, and

a = 1;
b = 2;
quad (@(x) betainc (x, a, b), 0, 0.4)
⇒ 0.13867

adapts a function with several parameters to the form required by quad. In this example, the values of a and b that are passed to betainc are inherited from the current environment.

再看课程说明文档介绍

To specify the actual function we are minimizing, we use a “short-hand”for specifying functions with the @(t) ( costFunction(t, X, y) ) . This creates a function, with argument t, which calls your costFunction. This allows us to wrap the costFunction for use with fminunc.

首先我们注意costFunction需要输入theta,X,y. 所以t这里就表示theta把后面的theta传入到函数中.

4. Ex3 要点详解

由于是多分类,需要进行逻辑回归的向量化!增加效率,换句话说,就是批量进行逻辑回归。

首先区分一下矩阵乘法和点乘法:
x * y Matrix multiplication. The number of columns of x must agree with the number of rows of y, or they must be broadcastable to the same shape. 矩阵相乘,要求维度:前面的列=后面的行
x .* y Element-by-element multiplication. If both operands are matrices, the number of rows and columns must both agree, or they must be broadcastable to the same shape. 对应的元素相乘,要求矩阵维度相同。

可见如果乘以一个数,那么这两种乘法是一样的。

其次介绍一下 == 在octive中的含义比较有趣,通过实验发现,如果是使用矩阵和实数进行比较,则返回一个矩阵,其中相同的位置返回1,其他不同的返回0。 如果是矩阵和矩阵进行比较,需要相同的维度,同样也是返回一个1和0的矩阵。

octave:16> a =1:10
a =
1    2    3    4    5    6    7    8    9   10
octave:17> b = 3
b =  3
octave:18> a==b
ans =
0   0   1   0   0   0   0   0   0   0