近期评论

Android学习笔记:(1) Android应用初体验

本系列的笔记是基于Bill Phillips和Brian Hardy《Android编程编程权威指南》一书的读书笔记!

花了半天时间,看了一下Android编程的入门,顺便写了一个类似Android领域的Hello World:GeoQuiz

记录一下要点:

1. activity和布局(layout)

activity和layout是一个android应用的基础。activity是SDK中Activity类的一个具体实例,负责管理用户与信息屏的交互,应用的主要功能是通过实现一个Activity子类来实现的,对于复杂应用会有多个子类。
布局定义了用户界面对象和它们在屏幕上显示的位置,是定义在XML文件中的。

2. 资源与资源ID

布局是一种资源,资源是应用非代码形式的内容,例如图像、音频、xml文件等。项目的所有资源文件都存放在res子目录下。上面说的布局就放在res/layout/子文件夹下。
每个资源都有一个ID,同个这个ID可以获取相应的资源。在对应的资源文件中定义了资源之后,资源的ID会自动生成(在gen子目录下的R.java文件中),在代码中可以通过这些ID获取到对应的资源。

3. 字符串资源

每个项目都包含一个名为strings.xml的字符串资源,在res/values子目录下。在strings.xml中新增一条字符串资源并且保存之后,会自动在R.java中新增一条字符串资源对应的ID,通过R.string."资源名称" 就可以在代码中访问到。

4. android:id="@+id/button"与android:id="@id/button"

id前面加了一个+标志,表明我们要创建资源ID,也就是说+id之后会在R.java中生成一条名称为button的id资源的ID,可以通过R.id.button取到这个ID,而不加+标志的,只是对这个id资源的引用,这个资源的ID已经在R.java中存在了。

5. 监听器

监听器也是Android应用中最重要的部分之一,

记录一下在amazon北京的时光

今天跟经理打了电话,终于还是放弃了amazon北京的offer。amazon是个有很牛技术的低调的公司。

记录一下在amazon的时光吧。

28F的茶水间和不远处的大裤衩:



» Continue reading 记录一下在amazon北京的时光

Theano tutorial: Theano Graphs Structures

上一篇将了一个实际的例子:Logistic Regression。这一篇讲了Theano中最基本的graph的概念。

在theano中编程的第一步是要将各种数学关系和公式使用符号占位符(symbolic placeholders)来表示,所谓的符号占位符其实就是我们平时说的变量(variables)。然后我们再使用一些操作符(operations)来表示各个变量之间的运算(例如+, -, **, sum(), tanh()等等)。就像大多数编程语言中的定义函数(function definition)。在theano中编程你需要先熟悉这种概念。

graph structure

然后再来说一下theano中重要的graph概念。在上面我们已经讨论了variables和ops。其实一个graph structure就是有三部分组成:变量节点(variable nodes),操作节点(op nodes)和应用节点(apply nodes,姑且叫做应用节点吧,把某种计算操作应用于某些变量)。

下面来看一个具体的例子:

import theano.tensor as T
x = T.matrix('x')
y = T.matrix('y')
z = x + y


» Continue reading Theano tutorial: Theano Graphs Structures

Theano tutorial: A Real Example - Logistic Regression

先看代码:

import numpy
import theano
import theano.tensor as T
rng = numpy.random

N = 400
feats = 784
D = (rng.randn(N, feats), rng.randint(size=N,low=0, high=2))
training_steps = 10000

# Declare Theano symbolic variables
x = T.matrix("x")
y = T.vector("y")
w = theano.shared(rng.randn(feats), name="w")
b = theano.shared(0., name="b")
print "Initial model:"
print w.get_value(), b.get_value()

# Construct Theano expression graph
p_1 = 1 / (1 + T.exp(-T.dot(x, w) - b))   # Probability that target = 1
prediction = p_1 > 0.5                    # The prediction thresholded
xent = -y * T.log(p_1) - (1-y) * T.log(1-p_1) # Cross-entropy loss function
cost = xent.mean() + 0.01 * (w ** 2).sum()# The cost to minimize
gw,gb = T.grad(cost, [w, b])              # Compute the gradient of the cost
                                          # (we shall return to this in a
                                          # following section of this tutorial)

# Compile
train = theano.function(
          inputs=[x,y],
          outputs=[prediction, xent],
          updates=((w, w - 0.1 * gw), (b, b - 0.1 * gb)))
predict = theano.function(inputs=[x], outputs=prediction)

# Train
for i in range(training_steps):
    pred, err = train(D[0], D[1])

print "Final model:"
print w.get_value(), b.get_value()
print "target values for D:", D[1]
print "prediction on D:", predict(D[0])


» Continue reading Theano tutorial: A Real Example - Logistic Regression

Sparse Matrix

In this exercise you will practice basic C++ class construction, and memory allocation and deallocation. You are asked to implement a class that supports an extendable variant of a sparse matrix. A matrix is a two-dimensional array. A matrix is sparse when many positions in the array are not important. In usual sparse matrices entries are not important when they are 0. In our version of the saprse matrix we distinguish between existing positions and not existing positions. Existing positions in our sparse matrices could contain the entry 0. In both cases, allocating memory to the unimportant positions in the matrix is a waste of memory.

You could think about a database containing students and their grades in modules. Every row in the database corresponds to a student and every column corresponds to a module. Then, grades are to be stored only in modules that the student did take. The entry that corresponds to a module that the student did not take should not exist. In particular, 0 is a possible grade in a module that a student takes.
To summarize, you are going to implement a sparse matrix that stores integers (including 0) in some of the positions of a (relatively large) two-dimensional array.

Technically, I have created the header file for the sparse matrix. You have to complete it with additional members. You will have to submit two files: Sparse.cpp and Sparse.hpp. You will probably want to create your own main.cpp file that includes a program that actually executes your Sparse.cpp. You will not be submitting this file. I also supply a Makefile that you should (must) use for compilation. The Makefile includes a compilation of a main.cpp. The header file includes detailed descriptions of the functions that are required that you implement.

» Continue reading Sparse Matrix

区间合并

有这样一个题目:输入两组区间,输出者两组区间合并之后的区间。

假设区间的起点和终点都是由整数表示,输入的是两个数组,数组中存储的是每个区间的起点和终点:

[8, 12, 15, 17, 21, 27, 32, 34, 35, 36, 40, 60]
[0, 10, 18, 19, 23, 30, 31, 38, 43, 44]

输出为合并之后的一组区间

[0, 12, 15, 17, 18, 19, 21, 30, 31, 38, 40, 60]


» Continue reading 区间合并

第 1 页,共 9 页12345...最旧 »