Categories
日常应用

简单的shell

好像一直没怎么正儿八经的写shell....今天不得不动手写了。反正就是摸着石头过河吧。

for i in {1..20}
do 
    mydate=$(date -v-"${i}d" +"%Y/%m/%d")
    echo "------Now importing:"$mydate"--------"
done

这样就实现了一个简单的for循环。

  • do 和done完成一个循环...
  • date是给日期的,mac和linux貌似语法有点不一样,date -v-1d 这样是往前减一天。后面那个是日期的格式。
  • 然后等号旁边不能有空格,这个和r差别好大。
  • 然后如果command中间要引用变量,需要${}一下,有点像r的paste()然后eval(parse())。
  • 1..20相当于r的1:20,给出一个整数序列。echo就是打印到屏幕上了。

暂时就这些,至少现在用起来是正常的哈哈。

Categories
日常应用

Hadoop Arvo Schema 和 HIVE 笔记

昨天捣鼓了一天这个东西,随便写点笔记。

  • arvo:除了著名的hdfs文件,hadoop上常用的另一种序列化存储的文件格式就是arvo。简单的讲,这货就是由一个定义好的schema来读取的二进制文本文件。
  • arvo schema:很像json...比如这里这个:
{
 "type" : "record",
 "name" : "Tweet",
 "namespace" : "com.miguno.avro",
 "fields" : [ {
 "name" : "username",
 "type" : "string",
 "doc" : "Name of the user account on Twitter.com"
 }, {
 "name" : "tweet",
 "type" : "string",
 "doc" : "The content of the user's Twitter message"
 }, {
 "name" : "timestamp",
 "type" : "long",
 "doc" : "Unix epoch time in seconds"
 } ],
 "doc:" : "A basic schema for storing Twitter messages"
}
  • 定义好schema之后可以用java去build...
  • arvo to HIVE:可以直接建HIVE external table. (还是上面那个link)
CREATE EXTERNAL TABLE tweets
 COMMENT "A table backed by Avro data with the Avro schema stored in HDFS"
 ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
 STORED AS
 INPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
 OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
 LOCATION '/user/YOURUSER/examples/input/'
 TBLPROPERTIES (
 'avro.schema.url'='hdfs:///user/YOURUSER/examples/schema/twitter.avsc'
 );

然后就是正常的玩法了。

Categories
日常应用

install R on Centos 6

following this thread: http://blogs.helsinki.fi/bioinformatics-viikki/documentation/getting-started-with-r-programming/installingrlatest/#CentOS

Installing the latest R on CentOS:

Add the latest EPEL repository which you can find from here. Don’t forget to add the 64 bit f you are using a 64 bit OS. I have a CentOS release 5.8, 64 bit (Check the Ubuntu installation section of this document if you don’t know your Linux distribution or whether it is 64 or 32 bit ) and I used the following script to add the proper repository:

$ sudo rpm -Uvh http://www.nic.funet.fi/pub/mirrors/fedora.redhat.com/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

then I got the error

CentOS 6.3 Instance Giving "Cannot retrieve metalink for repository: epel" Error

follow this page: https://community.hpcloud.com/article/centos-63-instance-giving-cannot-retrieve-metalink-repository-epel-error

Walkthrough Steps

Running this command will update the repo to use HTTP rather than HTTPS:

sudo sed -i "s/mirrorlist=https/mirrorlist=http/" /etc/yum.repos.d/epel.repo

You should then be able to update with this command:

yum -y update

then I am able to install R...

$ sudo yum install R

Installed:
  R.x86_64 0:3.1.2-1.el6                                                        

Dependency Installed:
  R-core.x86_64 0:3.1.2-1.el6                                                   
  R-core-devel.x86_64 0:3.1.2-1.el6                                             
  R-devel.x86_64 0:3.1.2-1.el6                                                  
  R-java.x86_64 0:3.1.2-1.el6                                                   
  R-java-devel.x86_64 0:3.1.2-1.el6                                             
  blas.x86_64 0:3.2.1-4.el6                                                     
  blas-devel.x86_64 0:3.2.1-4.el6                                               
  bzip2-devel.x86_64 0:1.0.5-7.el6_0                                            
  cups.x86_64 1:1.4.2-67.el6                                                    
  desktop-file-utils.x86_64 0:0.15-9.el6                                        
  fontconfig-devel.x86_64 0:2.8.0-5.el6                                         
  freetype-devel.x86_64 0:2.3.11-14.el6_3.1                                     
  gcc-gfortran.x86_64 0:4.4.7-11.el6                                            
  ghostscript.x86_64 0:8.70-19.el6                                              
  ghostscript-fonts.noarch 0:5.50-23.2.el6                                      
  java-1.6.0-openjdk.x86_64 1:1.6.0.0-11.1.13.4.el6                             
  java-1.6.0-openjdk-devel.x86_64 1:1.6.0.0-11.1.13.4.el6                       
  jline.noarch 0:0.9.94-0.8.el6                                                 
  kpathsea.x86_64 0:2007-57.el6_2                                               
  lapack.x86_64 0:3.2.1-4.el6                                                   
  lapack-devel.x86_64 0:3.2.1-4.el6                                             
  lcms-libs.x86_64 0:1.19-1.el6                                                 
  libRmath.x86_64 0:3.1.2-1.el6                                                 
  libRmath-devel.x86_64 0:3.1.2-1.el6                                           
  libX11-devel.x86_64 0:1.6.0-2.2.el6                                           
  libXau-devel.x86_64 0:1.0.6-4.el6                                             
  libXft-devel.x86_64 0:2.3.1-2.el6                                             
  libXmu.x86_64 0:1.1.1-2.el6                                                   
  libXrender-devel.x86_64 0:0.9.8-2.1.el6                                       
  libXt.x86_64 0:1.1.4-6.1.el6                                                  
  libgfortran.x86_64 0:4.4.7-11.el6                                             
  libicu.x86_64 0:4.2.1-9.1.el6_2                                               
  libicu-devel.x86_64 0:4.2.1-9.1.el6_2                                         
  libxcb-devel.x86_64 0:1.9.1-2.el6                                             
  netpbm.x86_64 0:10.47.05-11.el6                                               
  netpbm-progs.x86_64 0:10.47.05-11.el6                                         
  openjpeg-libs.x86_64 0:1.3-10.el6_5                                           
  pcre-devel.x86_64 0:7.8-6.el6                                                 
  poppler.x86_64 0:0.12.4-3.el6_0.1                                             
  poppler-data.noarch 0:0.4.0-1.el6                                             
  poppler-utils.x86_64 0:0.12.4-3.el6_0.1                                       
  portreserve.x86_64 0:0.0.4-9.el6                                              
  psutils.x86_64 0:1.17-34.el6                                                  
  rhino.noarch 0:1.7-0.7.r2.2.el6                                               
  tcl.x86_64 1:8.5.7-6.el6                                                      
  tcl-devel.x86_64 1:8.5.7-6.el6                                                
  tex-preview.noarch 0:11.85-10.el6                                             
  texinfo.x86_64 0:4.13a-8.el6                                                  
  texinfo-tex.x86_64 0:4.13a-8.el6                                              
  texlive.x86_64 0:2007-57.el6_2                                                
  texlive-dvips.x86_64 0:2007-57.el6_2                                          
  texlive-latex.x86_64 0:2007-57.el6_2                                          
  texlive-texmf.noarch 0:2007-38.el6                                            
  texlive-texmf-dvips.noarch 0:2007-38.el6                                      
  texlive-texmf-errata.noarch 0:2007-7.1.el6                                    
  texlive-texmf-errata-dvips.noarch 0:2007-7.1.el6                              
  texlive-texmf-errata-fonts.noarch 0:2007-7.1.el6                              
  texlive-texmf-errata-latex.noarch 0:2007-7.1.el6                              
  texlive-texmf-fonts.noarch 0:2007-38.el6                                      
  texlive-texmf-latex.noarch 0:2007-38.el6                                      
  texlive-utils.x86_64 0:2007-57.el6_2                                          
  tk.x86_64 1:8.5.7-5.el6                                                       
  tk-devel.x86_64 1:8.5.7-5.el6                                                 
  tmpwatch.x86_64 0:2.9.16-4.el6                                                
  unzip.x86_64 0:6.0-1.el6                                                      
  urw-fonts.noarch 0:2.4-10.el6                                                 
  xdg-utils.noarch 0:1.0.2-17.20091016cvs.el6                                   
  xorg-x11-proto-devel.noarch 0:7.7-9.el6                                       
  xz-devel.x86_64 0:4.999.9-0.5.beta.20091007git.el6                            

Dependency Updated:
  cpp.x86_64 0:4.4.7-11.el6                                                     
  cups-libs.x86_64 1:1.4.2-67.el6                                               
  gcc.x86_64 0:4.4.7-11.el6                                                     
  gcc-c++.x86_64 0:4.4.7-11.el6                                                 
  libgcc.x86_64 0:4.4.7-11.el6                                                  
  libgomp.x86_64 0:4.4.7-11.el6                                                 
  libstdc++.x86_64 0:4.4.7-11.el6                                               
  libstdc++-devel.x86_64 0:4.4.7-11.el6                                         
  xz-libs.x86_64 0:4.999.9-0.5.beta.20091007git.el6                             

Complete!
Categories
事儿关经济 经济、IT观察与思考

从a/b实验到机制设计、商业决策

本文只代表我自己的不成熟的思考,请勿过度解读。

试想如下两个场景。

  • 场景一:我们做了一个随机试验(random experiment),通过各种实验数据分析我们得出了结论是ATE(平均效果)为1%的提升,对应的p-value是0.09。所以这个东西10%显著,应该推广。
  • 场景二:我是一个风险投资者,我现在有100个项目可以投或者不投,每个项目都有其预期收益和对应的风险。我需要通过各种投资组合实现收益的最大化。

正常的来讲,上面两个场景分属于两个领域:实验分析和金融投资分析。好像之间并没有太大的关系。如果大家做实验分析就知道,大部分paper关心的都是如何得到一个干净的average treatment effect estimate,哪怕是为了降低variance做一些variance和consistency之间的trade-off,我也是在大原则不变的情况下。第二类文献我不是特别熟,但是通过有限的金融投资学的知识,我大概知道做法就是一个线性或者非线性、随机或者非随机(这里的随机是stochastic而不是random)的最优化过程、关注的更多是一些本身不可控的因素。

可是为什么我突然把这两者放在一起?今天突然讨论起type i 和type ii error,然后就不自主的联系到decision making...然后突然间觉得好像有哪里不对...互联网公司大家特别特别的依赖a/b test,一方面是谁也不知道什么是正确的所以索性让数字来说话,另一方面也是有点过度相信统计学的权威、依赖各种统计量和统计模型——我并不是说我们应该剥夺这种权威,而是有的时候好像忘了为什么一开始我们需要引入这样的决策体系。

先说一下我所熟悉的决策体系:做一个a/b test,如果实验结果显著为正(就像大部分field experiment那样),我们就给予实验者相应的奖励(towards business goal)、然后整个铺开。从机制设计的角度,这是一个有效的机制:规则是透明的也是保证正收益的,每个组都在这个机制下play the game是相对公平的。可是这样的机制的缺点是什么...无数的analyst就一夜夜的浪费脑细胞在获得一个可以被认可、又可以最大化自己所属团队贡献的估计量。business side只关心那个估计量的大小,然后公司内部的裁判角色又来审查你这样做是不是统计上正确的。所以many companies end up with a group of data scientists。

可是我们好像忘了一个东西:efficiency。公平是公平了,但是这个机制是效率角度最优的么?从公司的角度,做这么多a/b test实际上就相当于一个投资组合的决策过程:我需要在哪些上面投入更多、哪些上面投入不要这么多。每一种决策都是有风险的,那么既然是一个风险和收益的最优化过程,我就应该计算所有预期收益、成本和量化风险。风险应该是一个连续的度量而不是一个简单如p-value <10%这样1或0的二维决策过程。

所以说到这里,其实当你在做那么多实验的时候,其实那些针对单个实验分析的指标甚至理论什么的就不重要的。每一个都做到极致并不代表整体是最优化的,甚至可能是囚徒困境那般谁都走不出去?suddenly I got very sick talking about type I and type II errors.  I don't think that fits the culture.

大概就是这些,最近脑子里面萦绕的就是这样稀奇古怪的想法...喵。

bottom line

想起来一个joke: statisticians are good at generalizing stuffs (when we talk about statistical tools....the answer is it does not matter! because you should be good at generalization.)

Categories
我的生活状态

transformation

最近的几点感慨:

  • 衡量一份工作好不好,最重要的可能就是周围的人,尤其当你在一个大公司里面的时候。其他的薪水啊,work-life balance啊,工作内容啊,之类之类的,不是不重要,只是没那么重要——反正哪里也不会很差?
  • 最近半年好像越来越认同stats的一些看法了,思考的角度也越来越stats,呃。前两天和boss无意说起贝叶斯和频率派,我们最后达成共识就是,open mind的人都是经历过一些transformation的,无论是从哪个方向到哪个方向,抛弃偏执放下身段认同另一个观点,其实是一件很了不起的事情。太多的时候我们被迫习惯(路径依赖)、被过去的自己所约束、特别怕失去曾经被洗脑的那些犹如信仰般存在的观点,其实回过头去看都没那么重要。经历transformation其实是件蛮好玩的事儿。
  • 锻炼和自己完全不同背景不同观点的人交流的能力也是一件蛮有意思的事儿。因为这个过程需要你去换位思考、很多时候不是为了说服对方什么,只是倾听另外一种不同的观点和人生。存在必有道理,所以去听听为什么那些观点存在其实也是蛮有意思的。坚持自己的观点固然重要,但是也要明白为什么别人认同或者不认同,尤其是别人不认同的时候他们的想法又是什么。很多事情都是come with a cost,不能觉得什么都是理所应当的,很多时候坚持己见只是忽略了背后隐藏的cost...
  • 最后就是无论开心或者失落,总不要对外界关上沟通的窗户。To feel sad makes you a human being.