LeetCode Two Sum II Input array is sorted

Description

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.

The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.

You may assume that each input would have exactly one solution.

Input: numbers={2, 7, 11, 15}, target=9
Output: index1=1, index2=2

The original problem is here.

Read More

LeetCode Top K Frequent Elements

Description

Given a non-empty array of integers, return the k most frequent elements.

For example,
Given [1,1,1,2,2,3] and k = 2, return [1,2].
Note:

  • You may assume k is always valid, 1 ≤ k ≤ number of unique elements.
  • Your algorithm’s time complexity must be better than O(n log n), where n is the array’s size.

The original problem is here.

Read More

LeetCode Longest Palindrome

Description

Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.

This is case sensitive, for example “Aa” is not considered a palindrome here.

Note:
Assume the length of given string will not exceed 1,010.

Example:

1
2
3
4
5
6
7
8
Input:
"abccccdd"

Output:
7

Explanation:
One longest palindrome that can be built is "dccaccd", whose length is 7.

The original problem is here.

Read More

LeetCode Battleships in a Board

Description

Given an 2D board, count how many different battleships are in it. The battleships are represented with ‘X’s, empty slots are represented with ‘.’s. You may assume the following rules:

You receive a valid board, made of only battleships or empty slots.
Battleships can only be placed horizontally or vertically. In other words, they can only be made of the shape 1xN (1 row, N columns) or Nx1 (N rows, 1 column), where N can be of any size.
At least one horizontal or vertical cell separates between two battleships - there are no adjacent battleships.
Example:

X..X
…X
…X

In the above board there are 2 battleships.

Invalid Example:

…X
XXXX
…X

This is an invalid board that you will not receive - as battleships will always have a cell separating between them.

The original problem is here.

Read More

LeetCode Magical String

Description

A magical string S consists of only ‘1’ and ‘2’ and obeys the following rules:

The string S is magical because concatenating the number of contiguous occurrences of characters ‘1’ and ‘2’ generates the string S itself.

The first few elements of string S is the following: S = “1221121221221121122……”

If we group the consecutive ‘1’s and ‘2’s in S, it will be:

1 22 11 2 1 22 1 22 11 2 11 22 ……

and the occurrences of ‘1’s or ‘2’s in each group are:

1 2 2 1 1 2 1 2 2 1 2 2 ……

You can see that the occurrence sequence above is the S itself.

Given an integer N as input, return the number of ‘1’s in the first N number in the magical string S.

Note: N will not exceed 100,000.

Example 1:

1
2
3
Input: 6
Output: 3
Explanation: The first 6 elements of magical string S is "12211" and it contains three 1's, so return 3.

The original problem is here.

Read More

LeetCode Island Perimeter

Description

You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells). The island doesn’t have “lakes” (water inside that isn’t connected to the water around the island). One cell is a square with side length 1. The grid is rectangular, width and height don’t exceed 100. Determine the perimeter of the island.

Example:

[[0,1,0,0],
[1,1,1,0],
[0,1,0,0],
[1,1,0,0]]

Answer: 16

The original problem is here.

Read More

启动tomcat报错 “Cannot allocate memory (errno=12)”解决方法

问题

启动tomcat statup.sh,直接报错了: VM warning: …… error=’Cannot allocate memory’ (errno=12)。

就是说内存不够了,查看了下内存还剩余大约1GB,但是对于要启动的程序是够的。

网上查找了一些资料,断定是Java VM的内存分配问题。

JVM初始分配的内存由-Xms指定,默认是物理内存的1/64;
JVM最大分配的内存由-Xmx指定,默认是物理内存的1/4。

默认空余堆内存小于40%时,JVM就会增大堆直到-Xmx的最大限制;
空余堆内存大于70% 时,JVM会减少堆直到-Xms的最小限制。
因此服务器一般设置-Xms、-Xmx相等以避免在每次垃圾回收后调整堆的大小。

解决方法

修改tomcat的bin中catalina.sh的配置。修改JAVA_OPTS,调整-Xms 和 -Xmx 到合适的值。

我将之前的 -Xms4096m -Xmx4096m 修改成 -Xms2048m -Xmx2048m

重启tomcat成功。

WaveNet--一种应用于原始语音的端到端生成式模型

论文信息

  • 作者:Aaron van den Oord, Sander Dieleman, Heiga Zen, Karen Simonyan, Oriol Vinyals, Alex Graves, Nal Kalchbrenner, Andrew Senior, Koray Kavukcuoglu
  • 单位:Google, Google Deep Mind
  • 发表日期: 2016
  • 论文链接:https://arxiv.org/pdf/1609.03499.pdf

简介

WaveNet 是一种用于生成原始语音的深层神经网络,基于WaveNet的语音合成比目前性能最好的参数式语音合成和拼接式语音合成有更好的主观评分。
单个WaveNet可以捕获多个说话人的特点,根据说话人的标记可以在不同说话人之间转换。
WaveNet还可以生成美妙动听的音乐,此外还可以作为区分式模型应用到音子识别。

该论文工作的主要贡献包括:

  • 验证了WaveNet可以生成语音信号,并且语音的主观评分之高在TTS领域内是前所有未有的。
  • 为了更好地处理音频生成过程中的长跨度的时序依赖,基于扩展级联卷积开发了新的网络结构。
  • 验证了在不同说话人标记条件下,单个模型可以生成不同的声音。
  • 文中的网络结构在小的语音识别数据库中具有很好的效果,并且在生成其他音频例如音乐时具有不错的效果。

WaveNet

介绍了一种生成式模型,直接对原始语音波形建模。波形$X={x_1,…,x_T}$是条件概率的乘积:$p(x) = \frac{p(x_t|x_1,…,x_{t-1}}$

条件概率分布建模通过卷积层的堆叠实现,但是网络中没有pooling层,同时模型的输出与输入在时序上有相同的纬度。

Dilated Causal Convolutions

WaveNet主要由Causal Convolution组成,下图是由多个Causal Convolutional Layers堆叠形成的网络。
Visualization of a stack of causal convolutional layers

这里采用了一种扩展的卷积网络,随着隐层阶数增加而增加接收范围,但不会明显增加计算量。
Visualization of a stack of dilated causal convolutional layers

随着深度的增加,扩展范围指数性增加。

Softmax Distributions

相关研究工作证明Softmax distribution 对于条件分布建模有更好的效果,尽管数据是连续的。

Gated Activation Units

文章采用了门限激活单元,与门限PixelCNN中的一致。
Gated activation units
其中,*表示卷积操作。

Residual and Skip Connections

Overview of the residual block and the entire architecture

实验

总结

MacOS操作系统使用入门介绍

快捷键

  • 全选:commend + a
  • 复制:commend + c
  • 粘贴:commend + v
  • 剪切:无(粘贴时 alt+commend+v可以模拟)
  • 保存:commend + s
  • 退出:commend + q
  • 全屏:control + commend + f(退出全屏也是)
  • 打开文件:commend + o
  • 输入法切换:commend + 空格
  • spotlight:control + 空格
  • Alfred:alt + 空格