Saturday, November 26, 2011

Could Not Find HelloAndroid.apk! win7

开始折腾下android,第一个遇到的问题自然要记下

按照官方的教程一步一步走来,helloword居然不能work,错误如下
Could Not Find HelloAndroid.apk!

这里和这里都搜到了相关问题的描述,不过在我这里不work,因为我没有相应的路径,不过欣慰的是他的部分方法我拿过来用就ok了
把我的市区设置成美帝的市区时区,然后run helloworld 就ok了,随后既可以将市区时区更改回来:)

 

Thursday, November 3, 2011

bash 条件表达式 'test' '[' '[['

一直以来对test、[、和[[没有深研究,今天代码被挑刺了,就在这个几点上,因此决定好好在研究一下,翻了几个blog,同时又看了Bash Reference,本文的文字主要摘自Bash Reference,外加自己的一点解释、以及例子等。

首先看到6.4 Bash Conditional Expressions

Bash Conditional Expressions


开头说到条件表达式通常用于 [[ compound command and the test and [builtin commands.

Expressions may be unary or binary. Unary expressions are often used to examine the status of a file. There are string operators and numeric comparison operators as well(用于检查文件的status,以及字符串操作和算术比较). If the fileargument to one of the primaries is of the form/dev/fd/N, then file descriptor N is checked. If the fileargument to one of the primaries is one of/dev/stdin,/dev/stdout, or/dev/stderr, file descriptor 0, 1, or 2, respectively, is checked.

When used with ‘[[’, The ‘<’ and ‘>’ operators sort lexicographically using the current locale(此时基于字典序).

Unless otherwise specified, primaries that operate on files follow symbolic links and operate on the target of the link, rather than the link itself.

文件
-a file
True if file exists.
-b file
True if file exists and is a block special file.
-c file
True if file exists and is a character special file.
-d file
True if file exists and is a directory.
-e file
True if file exists.
-f file
True if file exists and is a regular file.
-g file
True if file exists and its set-group-id bit is set.
-h file
True if file exists and is a symbolic link.
-k file
True if file exists and its "sticky" bit is set.
-p file
True if file exists and is a named pipe (FIFO).
-r file
True if file exists and is readable.
-s file
True if file exists and has a size greater than zero.
-t fd
True if file descriptor fd is open and refers to a terminal.
-u file
True if file exists and its set-user-id bit is set.
-w file
True if file exists and is writable.
-x file
True if file exists and is executable.
-O file
True if file exists and is owned by the effective user id.
-G file
True if file exists and is owned by the effective group id.
-L file
True if file exists and is a symbolic link.
-S file
True if file exists and is a socket.
-N file
True if file exists and has been modified since it was last read.
file1 -nt file2
True if file1 is newer (according to modification date) than file2, or if file1 exists and file2 does not.
file1 -ot file2
True if file1 is older than file2, or if file2 exists and file1 does not.
file1 -ef file2
True if file1 and file2 refer to the same device and inode numbers.
操作符
-o optname
True if shell option optnameis enabled. The list of options appears in the description of the-ooption to the set builtin (see The Set Builtin).
字符串
-z string
True if the length of string is zero.
-n string
string
True if the length of string is non-zero.
string1 == string2
string1 = string2
True if the strings are equal.‘=’ should be used with the test command for posix conformance.
string1 != string2
True if the strings are not equal.
string1 < string2
True if string1 sorts before string2 lexicographically.
string1 > string2
True if string1 sorts after string2 lexicographically.
算术
arg1 OP arg2
OPis one of ‘-eq’, ‘-ne’, ‘-lt’, ‘-le’, ‘-gt’, or ‘-ge
’. These arithmetic binary operators return true if arg1 is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to arg2, respectively. Arg1 and arg2 may be positive or negative integers(必须是整数).
下面就依次来看看'[['和'test' '['

先看'[['


位于3.2.4.2 Conditional Constructs

[[...]]

          [[ expression ]]

Return a status of 0 or 1 depending on the evaluation of the conditional expression expression. Expressions are composed of the primaries described below in Bash Conditional Expressions. Word splitting and filename expansion are not performed on the words between the ‘[[’ and ‘]]’; tilde expansion, parameter and variable expansion, arithmetic expansion, command substitution, process substitution, and quote removal are performed. Conditional operators such as ‘-f’ must be unquoted to be recognized as primaries.

When used with ‘[[’, The ‘<’ and ‘>’ operators sort lexicographically using the current locale.

When the ‘==’ and ‘!=’ operators are used, the string to the right of the operator is considered a pattern and matched according to the rules described below in Pattern Matching. If the shell option nocasematch (see the description of shopt in The Shopt Builtin) is enabled, the match is performed without regard to the case of alphabetic characters. The return value is 0 if the string matches (‘==’) or does not match (‘!=’)the pattern, and 1 otherwise. Any part of the pattern may be quoted to force it to be matched as a string.

An additional binary operator, ‘=~’, is available, with the same precedence as ‘==’ and ‘!=’. When it is used, the string to the right of the operator is considered an extended regular expression and matched accordingly (as in regex3)). The return value is 0 if the string matches the pattern, and 1 otherwise. If the regular expression is syntactically incorrect, the conditional expression's return value is 2. If the shell option nocasematch (see the description of shopt in The Shopt Builtin) is enabled, the match is performed without regard to the case of alphabetic characters. Any part of the pattern may be quoted to force it to be matched as a string. Substrings matched by parenthesized subexpressions within the regular expression are saved in the array variable BASH_REMATCH. The element of BASH_REMATCH with index 0 is the portion of the string matching the entire regular expression. The element of BASH_REMATCH with index n is the portion of the string matching the nth parenthesized subexpression.

Expressions may be combined using the following operators, listed in decreasing order of precedence:

( expression )
Returns the value of expression. This may be used to override the normal precedence of operators.
! expression
True if expression is false.
expression1 && expression2
True if both expression1 and expression2 are true.
expression1 || expression2
True if either expression1 or expression2 is true.
The && and || operators do not evaluate expression2 if the value of expression1 is sufficient to determine the return value of the entire conditional expression.


再来看 'test'和'['


位于4.1 Bourne Shell Builtins

test和[是等价的,不过用的时候形式不一样如if  test expression,和if [ expression ]

Evaluate a conditional expression expr. Each operator and operand must be a separate argument. Expressions are composed of the primaries described below in Bash Conditional Expressions. testdoes not accept any options, nor does it accept and ignore an argument of--as signifying the end of options.When the [ form is used, the last argument to the command must be a ].Expressions may be combined using the following operators, listed in decreasing order of precedence. The evaluation depends on the number of arguments; see below.
! expr
True if expr is false.
( expr )
Returns the value of expr. This may be used to override the normal precedence of operators.
expr1 -a expr2
True if both expr1 and expr2 are true.
expr1 -o expr2
True if either expr1 or expr2 is true.
The test and [ builtins evaluate conditional expressions using a set of rules based on the number of arguments.这里把test其实是一个函数,根据不同的参数个数来判断出结果

0 arguments
The expression is false.
1 argument
The expression is true if and only if the argument is not null.
2 arguments
If the first argument is ‘!’, the expression is true if and only if the second argument is null. If the first argument is one of the unary conditional operators (see Bash Conditional Expressions), the expression is true if the unary test is true. If the first argument is not a valid unary operator, the expression is false.
3 arguments
If the second argument is one of the binary conditional operators (see Bash Conditional Expressions), the result of the expression is the result of the binary test using the first and third arguments as operands. The ‘-a’ and ‘-o’ operators are considered binary operators when there are three arguments. If the first argument is ‘!’, the value is the negation of the two-argument test using the second and third arguments. If the first argument is exactly ‘(’ and the third argument is exactly ‘)’, the result is the one-argument test of the second argument. Otherwise, the expression is false.
4 arguments
If the first argument is ‘!’, the result is the negation of the three-argument expression composed of the remaining arguments. Otherwise, the expression is parsed and evaluated according to precedence using the rules listed above.
5 or more arguments
The expression is parsed and evaluated according to precedence using the rules listed above.

[ ]和[[ ]]的区别


这两者的大部分功能都是一样的,但是后者[[]]比前者[]更加完善。

1.[[有扩展功能,通配符匹配(==和!=)和正则表达式匹配(=~),这在上面讲解[[的时候专门有两个段落说明

==和!=的右操作符为pattern进行3.5.8.1 Pattern Matching

这个时候,假如要比较的右侧字符串中有特殊字符如*,则需要用"引起来

[shell]
$ [[ "GFW" == G*W ]]
$ echo $?
0
$ [[ "GFW" == "G*W" ]]
$ echo $?
1
[/shell]

=~的右操作符作为正则表达式,这里正则的引号可用可不用

[shell]
$ [[ "GFW" =~ "G*W" ]]
$ echo $?
0
$ [[ "GFW" =~ 'G*W' ]]
$ echo $?
0
$ [[ "GFW" =~ G*W ]]
$ echo $?
0
[/shell]

2.[的二元操作符的右操作符(通常是某变量)不能为空(null),当然可以通过加引号来解决

首先使用[如下:

[shell]
$ [ "GFW" == $fuck  ]
bash: [: GFW: unary operator expected
[/shell]

就会报错,而加了引号就没有问题了,这个时候当作一个空字符串处理

[shell]
$ [ "GFW" == "$fuck" ]
$ echo $?
1
[/shell]

假如是使用[[就不存在该问题,加不加引号都ok,如下:

[shell]
$ [[ "GFW" == $fuck ]]
$ echo $?
1
$ [[ "GFW" == "$fuck" ]]
$ echo $?
1
[/shell]

另外还有个(( ))


((...))

          (( expression ))

The arithmetic expression is evaluated according to the rules described below (see Shell Arithmetic). If the value of the expression is non-zero, the return status is 0; otherwise the return status is 1. This is exactly equivalent to
          let "expression"

See Bash Builtins, for a full description of the let builtin.

Shell Arithmetic如下

The shell allows arithmetic expressions to be evaluated, as one of the shell expansions or by the letand the

-ioption to the declarebuiltins.

Evaluation is done in fixed-width integers with no check for overflow, though division by 0 is trapped and flagged as an error. The operators and their precedence, associativity, and values are the same as in the C language. The following list of operators is grouped into levels of equal-precedence operators. The levels are listed in order of decreasing precedence.

id++ id--
variable post-increment and post-decrement
++id --id
variable pre-increment and pre-decrement
- +
unary minus and plus
! ~
logical and bitwise negation
**
exponentiation
* / %
multiplication, division, remainder
+ -
addition, subtraction
<< >>
left and right bitwise shifts
<= >= < >
comparison
== !=
equality and inequality
&
bitwise AND
^
bitwise exclusive OR
|
bitwise OR
&&
logical AND
||
logical OR
expr ? expr : expr
conditional operator
= *= /= %= += -= <<= >>= &= ^= |=
assignment
expr1 , expr2
comma
Shell variables are allowed as operands; parameter expansion is performed before the expression is evaluated. Within an expression, shell variables may also be referenced by name without using the parameter expansion syntax. A shell variable that is null or unset evaluates to 0 when referenced by name without using the parameter expansion syntax. The value of a variable is evaluated as an arithmetic expression when it is referenced, or when a variable which has been given the integerattribute using ‘declare -i’ is assigned a value. A null value evaluates to 0. A shell variable need not have its integer attribute turned on to be used in an expression.

Constants with a leading 0 are interpreted as octal numbers. A leading ‘0x’ or ‘0X’ denotes hexadecimal. Otherwise, numbers take the form [base#]n, where base is a decimal number between 2 and 64 representing the arithmetic base, and n is a number in that base. If base#is omitted, then base 10 is used. The digits greater than 9 are represented by the lowercase letters, the uppercase letters, ‘@’, and ‘_’, in that order. If base is less than or equal to 36, lowercase and uppercase letters may be used interchangeably to represent numbers between 10 and 35.

Operators are evaluated in order of precedence. Sub-expressions in parentheses are evaluated first and may override the precedence rules above.

Friday, October 14, 2011

G12 HTC Desire S so on机器获取root权限

之前如的g12,港版原封,so on,一直没有获取root权限,虽然系统的应用删除不掉,但是还不至于影响我的使用,但是最近电子市场被GFW fuck这件事情让我对获取root权限更加重视起来。

咱不是玩手机的,所以只能Google之了,找的很辛苦,因为大多数都是so off的机器获取root的办法,还有些人说so on的机器便so off只能找奸商,我靠,奸商不也是自己破解,所以还是自己动手来搞。

声明这些都不是我原创,是从hiapk转载过来的。

首先是由so on变成so off http://bbs.hiapk.com/thread-1931799-1-1.html,step by step即可,最后可以check自己的机器成了so off

然后是so off获取root HTC G12台*湾最新ROM版本1.47.950.3以及ROOT最优方法,后者我只是选择了部分步骤。即小白级、低级人员操作方法中的2、3、4,因为我不想刷机,这几步step by step就ok了

Saturday, October 8, 2011

Steve Jobs’ death

乔布斯逝去,tim cook、larry page、gat、obama都表达了自己的看法

苹果内部



Tim Cook: "No words can adequately express our sadness at Steve's death"


Tim Cook, who took over for Steve Jobs as Apple CEO in August of 2011, has sent a new e-mail to employees in the wake of Steve Jobs' recent death. In the e-mail seen by Ars Technica, Cook addresses Apple's employees to announce that Jobs has passed and offers reflections on Jobs' influence on the company. Below is the full text of the e-mail:
Team,

I have some very sad news to share with all of you. Steve passed away earlier today.

Apple has lost a visionary and creative genius, and the world has lost an amazing human being. Those of us who have been fortunate enough to know and work with Steve have lost a dear friend and an inspiring mentor. Steve leaves behind a company that only he could have built, and his spirit will forever be the foundation of Apple.

We are planning a celebration of Steve’s extraordinary life for Apple employees that will take place soon. If you would like to share your thoughts, memories and condolences in the interim, you can simply email rememberingsteve@apple.com.

No words can adequately express our sadness at Steve’s death or our gratitude for the opportunity to work with him. We will honor his memory by dedicating ourselves to continuing the work he loved so much.

Tim

The e-mail address given in Cook's message is the same as the one Apple has publicly posted on its website. If you have further stories and memories to share, we'd love to hear them in the comments.

Google的两位




I am very, very sad to hear the news about Steve. He was a great man with incredible achievements and amazing brilliance. He always seemed to be able to say in very few words what you actually should have been thinking before you thought it. His focus on the user experience above all else has always been an inspiration to me. He was very kind to reach out to me as I became CEO of Google and spend time offering his advice and knowledge even though he was not at all well. My thoughts and Google's are with his family and the whole Apple family.



Sergey Brin  -  2011-10-6  -  公开


From the earliest days of Google, whenever Larry and I sought inspiration for vision and leadership, we needed to look no farther than Cupertino. Steve, your passion for excellence is felt by anyone who has ever touched an Apple product (including the macbook I am writing this on right now). And I have witnessed it in person the few times we have met.

On behalf of all of us at Google and more broadly in technology, you will be missed very much. My condolences to family, friends, and colleagues at Apple.


Gates




I’m truly saddened to learn of Steve Jobs’ death. Melinda and I extend our sincere condolences to his family and friends, and to everyone Steve has touched through his work.

Steve and I first met nearly 30 years ago, and have been colleagues, competitors and friends over the course of more than half our lives.

The world rarely sees someone who has had the profound impact Steve has had, the effects of which will be felt for many generations to come. 

For those of us lucky enough to get to work with him, it’s been an insanely great honor.  I will miss Steve immensely. 

The White House Blog


President Obama on the Passing of Steve Jobs: "He changed the way each of us sees the world."


Posted by Kori Schulman on October 05, 2011 at 09:15 PM EDT

Following the loss of visionary Apple co-founder Steve Jobs, President Obama released this statement:
Michelle and I are saddened to learn of the passing of Steve Jobs. Steve was among the greatest of American innovators - brave enough to think differently, bold enough to believe he could change the world, and talented enough to do it.

By building one of the planet’s most successful companies from his garage, he exemplified the spirit of American ingenuity.  By making computers personal and putting the internet in our pockets, he made the information revolution not only accessible, but intuitive and fun.  And by turning his talents to storytelling, he has brought joy to millions of children and grownups alike. Steve was fond of saying that he lived every day like it was his last.  Because he did, he transformed our lives, redefined entire industries, and achieved one of the rarest feats in human history: he changed the way each of us sees the world.

The world has lost a visionary. And there may be no greater tribute to Steve’s success than the fact that much of the world learned of his passing on a device he invented. Michelle and I send our thoughts and prayers to Steve’s wife Laurene, his family, and all those who loved him.


附:


jobs的在斯坦福的演讲jobs在斯坦福的演讲

Monday, September 26, 2011

What is a good explanation of Latent Dirichlet Allocation

晚上在Quora溜达,看到了个问题,关于LDA的,关于寻找LDA的一个良好的解释

众人合力得到了一个很赞的解释,这里我把最直观的解释翻译(部分翻译,有的部分还是英语表达更好)过来吧,同时来在学习的过程中对概率的一些知识进行了回顾(概率学了居然都忘了,只有模糊的印象)

场景


假设有下面的句子集合



  • I ate a banana and spinach smoothie for breakfast

  • I like to eat broccoli and bananas.

  • Chinchillas and kittens are cute.

  • My sister adopted a kitten yesterday.

  • Look at this cute hamster munching on a piece of broccoli.


LDA是一种自动发现这些句子中包含的主题(topics)的方法。比如,给定这些句子和两个主题,LDA可能会产生下面的这些:




  • Sentences 1 and 2: 100% Topic A

  • Sentences 3 and 4: 100% Topic B

  • Sentence 5: 60% Topic A, 40% Topic B

  • Topic A: 30% broccoli, 15% bananas, 10% breakfast, 10% munching, ... (at which point, you could interpret topic A to be about food)

  • Topic B: 20% chinchillas, 20% kittens, 20% cute, 15% hamster, ... (at which point, you could interpret topic B to be about cute animals)


问题是,LDA如何做发现这些的?


LDA Model


仔细来说,LDA使用混合的主题来代表文档(documents),这些主题将文档中的词(words)按照概率划分到不同的主题。LDA做了如下的假设,当你写文档的是,你会做如下的事情



  • Decide on the number of words N the document will have (say, according to a Poisson distribution).



  • Choose a topic mixture for the document (according to a Dirichlet distribution over a fixed set of K topics). For example, assuming that we have the two food and cute animal topics above, you might choose the document to consist of 1/3 food and 2/3 cute animals.

  • Generate each word in the document by:

  • ....First picking a topic (according to the multinomial distribution that you sampled above; for example, you might pick the food topic with 1/3 probability and the cute animals topic with 2/3 probability).

  • ....Then using the topic to generate the word itself (according to the topic's multinomial distribution). For instance, the food topic might output the word "broccoli" with 30% probability, "bananas" with 15% probability, and so on.


考虑到这种生成(generate)文档的模型,LDA试图从文档追溯一些topics,很可能是这些topics生成了这些文档。


样例


举个例子,根据上述model,当产生某个特定文档D的时候,你会这么做:



  • Decide that D will be 1/2 about food and 1/2 about cute animals.

  • Pick 5 to be the number of words in D.

  • Pick the first word to come from the food topic, which then gives you the word "broccoli".

  • Pick the second word to come from the cute animals topic, which gives you "panda".

  • Pick the third word to come from the cute animals topic, giving you "adorable".

  • Pick the fourth word to come from the food topic, giving you "cherries".

  • Pick the fifth word to come from the food topic, giving you "eating".


上述流程其实就是模拟人写文档的一个过程,这个由LDA model生成的文档为"broccoli panda adorable cherries eating"(LDA是一系列words的模型)


学习(ML)


首先假定有一个文档集合,已经选择了K个topics用于发现,希望使用LDA来学习出每个文档的主题表示(topic representation),以及每个主题相关的词(words)。怎么做呢?一种方法如下(collapsed Gibbs sampling):



  • Go through each document, and randomly assign each word in the document to one of the K topics.(对每个文档,将每个word随机赋予某个topic)

  • Notice that this random assignment already gives you both topic representations of all the documents and word distributions of all the topics (albeit not very good ones).(这种随机赋值也是一种学习的结果,不过我们需要去改进,方法就是迭代)

  • So to improve on them, for each document d...

  • ....Go through each word w in d...

  • ........And for each topic t, compute two things: 1) p(topic t | document d) = the proportion of words in document d that are currently assigned to topic t, and 2) p(word w | topic t) = the proportion of assignments to topic t over all documents that come from this word w. Reassign w a new topic, where you choose topic t with probability p(topic t | document d) * p(word w | topic t) (according to our generative model, this is essentially the probability that topic t generated word w, so it makes sense that we resample the current word's topic with this probability). (Also, I'm glossing over a couple of things here, such as the use of priors/pseudocounts in these probabilities.)(计算文档属于某topic的概率p(t|d)以及word属于topic的概率p(w|t),然后根据这个来计算当把某word w赋予一个新的topic的时候的概率,即p(t|d)*p(w|t))

  • ........In other words, in this step, we're assuming that all topic assignments except for the current word in question are correct, and then updating the assignment of the current word using our model of how documents are generated.(每次计算某word属于某topic概率的时候,假定其他word的topic是确定的,)

  • After repeating the previous step a large number of times, you'll eventually reach a roughly steady state where your assignments are pretty good. So use these assignments to estimate the topic mixtures of each document (by counting the proportion of words assigned to each topic within that document) and the words associated to each topic (by counting the proportion of words assigned to each topic overall).(迭代直到收敛,使用最后的值来表示每个文档的主题表示,以及每个topic 的words表示)



这个学习过程有点多,因此稍稍解释了一下,这个过程和PageRank很像吧,都是开始随机赋值,然后更新值,迭代直到收敛。

相关概率知识


看的过程中发现自己的概率都忘光了,于是看得时候把相应的概念在wiki上翻了出来,虽没都看透,但起码有个感性的理解了


狄利克雷分布是一个连续多随机变量分布,理解这个需要了解下面的知识


先验概率:简称先验,一个不确定量p的先验,是一个人在没有考虑数据的时候对于p的不确定性的判断,是这样一个概率分布。一个简单的例子是,假如p是选民会选A的比例,p的先验概率不能考虑民意调查,即选民不参考其他会影响他的vote的data。

对应的,后验概率如下:


后验概率是把相关的data考虑进去的条件概率,后验概率分布是从一次实验中得到的不确定量p的分布,再进一步,共轭先验。


假如概率先验分布p(θ)和后验分布p(θ|x)的分布是同一种分布,那么这就叫共轭分布,而该先验称为共轭先验。如p(θ)是服从高斯分布的,而p(θ|x)也是服从高斯分布的,那么这两个分布成为共轭分布。

这上述几个概念都是属于贝叶斯统计的


贝叶斯统计是统计的一个分支,在贝叶斯统计中,关于现实世界的真实状态的证据都是用贝叶斯概率http://en.wikipedia.org/wiki/Bayesian_probability来表达的,贝叶斯概率是关于概率的一种不同的解释,属于置信概率的范畴。概率的贝叶斯解释可以看作是逻辑的延伸,使得可以对不确定量进行推理。

参考文献: