2012年7月11日水曜日

Ruby on Railsをさくらレンタルサーバにインストール・・・ができないことが判明した件

最初に結論から書くと,さくらのレンタルサーバにrailsをインストールするのは難しいようだ.
数年前まではいけたっぽいけど,今は無理みたい.





学会ページ作成のために,さくらレンタルサーバにRailsを導入して,Railsの勉強をしてみる.
基本的な手順は以下の通り.

  1. RubyGemsをインストール
  2. gemを使ってrailsをインストール

ただし,レンタルサーバなのでローカルに入れなければ行けない.
とりあえず,インストール場所は
~/local/bin

~/local/lib

以下にしてみる.
というわけで,以下手順.

RubyGemsをインストール

http://rubyforge.org/frs/?group_id=126
で最新版を探してダウンロード
$ cd
$ mkdir src
$ cd src
$ wget http://rubyforge.org/frs/download.php/76073/rubygems-1.8.24.tgz

インストールする場所を作成
$ mkdir local

$ tar zxvf rubygems-1.8.24.tgz
$ ruby setup.rb --prefix=$HOME/local/
RubyGems 1.8.24 installed



== 1.8.24 / 2012-04-27



* 1 bug fix:



  * Install the .pem files properly. Fixes #320

  * Remove OpenSSL dependency from the http code path





------------------------------------------------------------------------------



RubyGems installed the following executables:

        /home/name/local/bin/gem18

$ cd
$ emacs .cshrc
...

set path = (/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/\

bin $HOME/local/bin)

setenv RUBYLIB $HOME/local/lib

setenv GEM_HOME $HOME/local/lib/ruby/gem

$ sources .cshrc
$ gem --version
1.8.24

Railsをインストール

$ gem18 install rails --include-dependencies
chown/chgrp: Operation not permitted
エラーだ.
解決策はこちら
http://playet.jugem.jp/?eid=56

$ setenv RB_USER_INSTALL true
$ gem18 install rails --include-dependencies

成功したように見えるのに,なぜかrailsが入っていない.
おや?
Pathに
$HOME/local/lib/ruby/gem/bin
が必要だった.
.cshrcに追加
...

set path = (/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin $HOME/local/bin $HOME/local/lib/ruby/gem/bin)

$ source .cshrc
$ rails -v
Rails 3.2.6
お~.できたできた.

それじゃ,早速アプリケーションを作成してみましょうかね.

$ cd
$mkdir Rails
$ rails new HelloWolrd
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/local/bin/ruby18 extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/local/bin/ruby18
        --with-sqlite3-dir
        --without-sqlite3-dir
        --with-sqlite3-include
        --without-sqlite3-include=${sqlite3-dir}/include
        --with-sqlite3-lib
        --without-sqlite3-lib=${sqlite3-dir}/lib
        --enable-local
        --disable-local


Gem files will remain installed in /home/name/local/lib/ruby/gem/gems/sqlite3-1.3.6 for inspection.
Results logged to /home/name/local/lib/ruby/gem/gems/sqlite3-1.3.6/ext/sqlite3/gem_make.out
An error occured while installing sqlite3 (1.3.6), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.6'` succeeds before bundling.
おや?
続けていくと,次々怒られるので,順番にgemでインストールしていって見る.
$ gem18 install coffee-script
$ gem18 install coffee-rails
$ gem18 install sass
$ gem18 install sass-rails
$ gem18 install sqlite3

ここまで順調だったが,ここで問題発生.
Make sure that `gem install sqlite3 -v '1.3.6'` succeeds before bundling.

だけど,さくらに入っているのはsqlite3 ver 3.7.9 20
とりあえず古いバージョンをインストールしてみる.
$ gem install sqlite3-ruby --version=1.2.4
$ rails new HelloWorld
...
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
        /usr/local/bin/ruby18 extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.


Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/local/bin/ruby18
        --with-sqlite3-dir
        --without-sqlite3-dir
        --with-sqlite3-include
        --without-sqlite3-include=${sqlite3-dir}/include
        --with-sqlite3-lib
        --without-sqlite3-lib=${sqlite3-dir}/lib
        --enable-local
        --disable-local


Gem files will remain installed in /home/name/local/lib/ruby/gem/gems/sqlite3-1.3.6 for inspection.
Results logged to /home/name/local/lib/ruby/gem/gems/sqlite3-1.3.6/ext/sqlite3/gem_make.out
An error occured while installing sqlite3 (1.3.6), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.6'` succeeds before bundling.
調べてみると,結構インストールのやり方が出てくるけど,皆情報が古い.
ここ1年で検索してみると,
http://okwave.jp/qa/q5323794.html
http://d.hatena.ne.jp/ar_tama/20120212/1329027876
を見る限り無理っぽい
なんてこったい.

2012年7月10日火曜日

Hadoop再インストール

Hadoopのインストールにチャレンジ中だけど,どうも通常のHadoopをインストールするよりも,CDH(Cloudera's Distribution including Apache Hadoop)をインストールする方が色々良さそうなので,インストールを試みた.
ところが,一度通常のHadoopをインストールしていると,どうも動きがおかしいということが分かったので,いっそOSから再インストール.


参考URL
http://www.ne.jp/asahi/hishidama/home/tech/apache/hadoop/hadoopCDH3.html

まずは,yumでCDHがダウンロードできるようにリポジトリを更新.
# cd /etc/yum.repos.d/
# wget http://archive.cloudera.com/redhat/cdh/cloudera-cdh3.repo
# yum update yum

次に,Hadoopをインストール.
# yum install hadoop-0.20
実行してみたら,エラー.何かと思ったら,
JAVAをインストールしていなかったw

素直にsun.javaからインストール.
rpmなら何も考えずにインストール可能.

次に実行したら,今度はホスト名が見つからないと怒られたので,
/etc/host
ホスト名を追加

最後に,
Hadoopの擬似分散モード用設定ファイル集のダウンロード
# yum -y install hadoop-0.20-conf-pseudo

# alternatives --display hadoop-0.20-conf
# alternatives --config hadoop-0.20-conf
で,
conf.pseudoを選択

最後に無事動いたかどうかを確認.
$ hadoop jar /usr/lib/hadoop/hadoop-*-examples.jar pi 4 2000
無事実行完了
ちなみに,実行中は
で,namenode情報
http://localhost:50030
で,MapReduce情報
を見ることが可能.
ちょっと重たいものを走らせてMapReduce情報を見ると,ちゃんと進行状況が分かって面白い.
通常版はインストールにめちゃめちゃ手間取ったけど,CDH版は一瞬でインストール完了.
さて,これから色々遊んでみよう.



2012年7月3日火曜日

HADOOPインストールトライ中

あまりにもTwitterデータの数が多すぎて,単体のマシンでは処理が難しくなってきたので,HADOOPを使ってみることにした.
 まずは,スタンドアロンな環境から.
基本的には,Hadoop徹底入門を参考にして入れてみる. 

  • OSはCentOS6.2
  • Hadoopのバージョンは0.20.205

0.20系が1.0につながるものらしいので,まあ,これでいいだろうと.

本の通りにインストール作業をすれば,基本的には大丈夫.
ただ,一点だけはまったのが, start-dfs.sh の実行.
普通の設定で実行しようとすると
Warning: $HADOOP_HOME is deprecated
と表示されうまく起動しない. そこで,
hadoop-env.sh
に,
export HADOOP_HOME_WARN_SUPPRESS="TRUE"
を追加.
これで,無事start-dfs.shが実行された. まだMapReduceにもたどり着いていないけど.

2012年6月6日水曜日

ICWSM12・初日メモ


アイルランドで6月5~7日の日程で行われているICWSM12に参加しているので,
聴講メモを貼り付けておきます.

6/5発表分

Distributional Footprints of Deceptive Product Reviews
Customer's review 
5と評価する人もいれば,1を評価する人もいる
1-5の評価分布から,ステマを探す

National vs Distorted(自然?ゆがんでる?)
Find from distribution

SingleReviewかMultiReviewかで行動が違う
Singleだと1か5が多い
Multiは4-5が多い
S-Shape vs J-Shape(Single)

Characterization of rating distribution
D sorted by #
4,2が高いものと4,5が高いものが多い
MultiTimeとSingleTimeで形が全然違う
51・・と15・・が多い

Detection strategies to identify deceptive business entities
SingleReviewer vs MultiReviewer
positive/negative
Temporal boost in ratingの発見

Novel evaluation methodologies
Pseudo-Gold Standard Data

72~75%の判別率
Baselineが40%程度

Privacy in Interaction: Exploring Disclosure and Social Capital in Facebook
Presentation of Self in Everyday Life.
いろいろなクラスタが本人を中心にネットワークを形成しているはず
Social Capital

Access to emotional and substantive support often from strong ties.
Face book user variables
Signals of Relational Investment

Responding to friends' question because,
-Create an expectation about reciprocal behavior
-Perform a social grooming function
-Potentially train the news feed
-Comments on friends update and wall post are seen by the friends' network

Friendの割合が高くなるほど,FriendsOnlyが増えてくる
Bonding SC:Benefits of focused inclusive interaction
Bridging SC:Costs of highly targetting disclosing

Don’t Disturb My Circles! Boundary Preservation Is at the Center of Location-Sharing Concerns
What is the motivation of Boundary regulation

Online Boundary Regulation
preserve offline relation ship

Friendに対してはPrivacyを考える
Familyは考えない
Strangerに対しても考えない(日本とは違うなあ)

Boundary preservation concern = BPC

Facebook and Privacy: The Balancing Act of Personality, Gender, and Relationship Currency

sentiment的に友人と自分には相関がある
disclose & conceal what is considered private and public in Facebook
Count number of disclosed & concealed from facebook properties

Item Response Theory(IRT)

P_IJ= 1/(1+exp(-a_i(t_j-B_i)))

1. Smart Privacy Mob
About privacy, Westine has divided people in
 1.privacy fundamentalists
 2.pragmatic majority
 3.marginally concerned

2. Who are they?
Those who share more sensitive info are
-open to new experience ------important
-self monitoring
-male --------------------------important
-more active 
-younger

3. What's sensitive
position, employer
residence, hometown not sensitive in circle.

The Livehoods Project: Utilizing Social Media to Understand the Dynamics of a City
neighborhoods

Two perspectives
Politically constructed 政治的に作られた構造か
Socially constructed 社会的に作られた構造か
Collective Cognitive Map

どこでTweetしたかでユーザをグループ分け
そこから,土地のグループ分け.
Tweetにも応用可能か.

場所の類似性(Jaccard係数)

How to evaluate
実際にピッツバーグの人に聞いてみた

Who Does What on the Web: A Large-Scale Study of Browsing Behavior

Nielsen MegaPanel
265000 individuals in US
user data, log of anonymized complete browsing activity from 2009/6-2010/5

Younger and more educated => more use web, more active
色々調べているけど・・・

education が大きな効果を持つ

Evolution of Experts in Question Answering Communities

Expert Influence best answer selection
Ordinary users get intimated by expert
Experts avoid other experts
Experts evolve with differente patterns
These experes can be found with satisfactory performance within 20 weeks

Temporal Motifs Reveal the Dynamics of Editor Interactions in Wikipedia
Motifを使ってWikipediaの編集を分析
編集合戦中とかMotifから判別可能

Modeling Spread of Disease from Social Interactions Best Paper Candidate!

SVMでインフルエンザであるTweetかどうかを判断

Modeling Destructive Group Dynamics in On-line Gaming Communities

WoWを対象にグループの生成と解散を分析
ギルドの歴史から分析可能
Charactor&Guildの二部ネットワーク

Guild抜けは感染する
Quitting Eventを予測可能か?
Quitting Eventが起きないことは90%近い予測
Quitting Eventが起きる可能性は30%程度

ソーシャルネットワークとして調べると面白い
GroupDynamicsが直接見えるデータというのは貴重だ.

2012年4月27日金曜日

東日本大震災時Twitterデータを使った研究

以前,東日本大震災時Twitterデータを使った共同研究を募集しましたが, 多くの方にご参加いただき,多くの研究成果を出すことができました. 皆様にお礼を申し上げるとともに,2011年度の研究成果をこちらに示しておきます. なお,データの提供先についてはまだ募集中ですので,ご興味がある方はご連絡ください.
論文・学会予稿集
  • Takeru Inoue,Fujio Toriumi,Yasuyuki Shirai,Shin-ichi Minato Great East Japan Earthquake Viewed from a URL shortener ACM CoNEXT 2011 Special Workshop on the Internet and Disasters(12/2011)
  • Takeshi Sakaki,Fujio Toriumi,Yutaka Matsuo Tweet Trend Analysis in an Emergency Situation ACM CoNEXT 2011 Special Workshop on the Internet and Disasters(12/2011)
  • 芝田雄吾、木村 浩、鳥海不二夫、榊 剛史、風間一洋、福田健介 ソーシャルメディアにおける福島第一原子力発電所に関連する情報の伝播分析 Workshop of Social System and Information Technology (03/2012)
  • 白井嵩士,榊剛史,鳥海不二夫,篠田孝祐,風間一洋,野田五十樹,沼尾正行,栗原聡 Twitterネットワークにおけるデマ拡散とデマ拡散防止モデルの推定 人工知能学会 データ指向構成マイニングとシミュレーション研究会 SIG-DOCMAS-B102 (03/2012)
  • 松本徳義,武藤正義,鳥海不二夫:東日本大震災における「原発」に関する Twitter ユーザーの動向分析 第 53 回数理社会学会大会(03/2012)
  • 小出明弘,斉藤和巳,大久保誠也,鳥海不二夫,風間一洋 Twitterの@-messageで構成される成長ネットワークの分析 第74回情報処理学会全国大会(IPSJ2012)(03/2012)
  • 小出明弘,斉藤和巳,鳥海不二夫,風間一洋 フォロー類似度によるTwitter高次数ユーザの関係分析 第3回 集合知シンポジウム(02/2012)
  • 風間一洋, 鳥海不二夫, 篠田孝祐,榊剛史, 栗原 聡, 野田五十樹 名詞出現頻度の時間的変化に着目した東日本大震災時のTwitterのトピックの分析 WebDB Forum 2011(11/2011)
  • 芝田雄吾, 木村浩, 榊剛史,鳥海不二夫,風間一洋 福島第一原発事故におけるプレスリリースとTwitter発言の関連性に関する分析 日本原子力学会「2011年秋の大会」L29(09/2011)
  • 鳥海不二夫,篠田孝祐,栗原聡,榊剛史,風間一洋,野田五十樹 震災がもたらしたソーシャルメディアの変化 ネットワークが創発する知能研究会(JWEIN'11) & 数理社会学会第52回大会(JAMS52)合同ワークショップ(09/2011)
招待講演
  • 鳥海不二夫,ソーシャルネットワークの構造とダイナミクス~ヒトの社会活動の理解予測に向けて 東日本大震災時のTwitterにおける情報共有(02/2012)
  • 鳥海不二夫,情報通信技術研究交流会(AC・Net)192回例会 震災がもたらしたソーシャルメディアの変化(12/2011)
  • 鳥海不二夫,はこだて未来大学講演 震災がもたらしたソーシャルメディアの変化(08/2011)
2012年度での発表も予定されていますので,機会があればまた紹介したいと思います.
データ概要
東日本大震災時のTweetデータ
データ範囲2011-03-05 00:00:00~2011-03-24 22:23:58
総Tweet数
407562159
言語
主に日本語

含まれるデータ
  • TweetID
  • ScreenName
  • Tweet本文
  • 投稿アプリ名
  • Tweet時刻
  • Retweet先のTweetID
  • Retweet先のScreenName
主な付加データ
  • 名詞抽出
  • 動詞抽出
  • 形容詞抽出
  • 地名抽出
  • Hashtag抽出
  • Mention関係
  • Retweet先のScreenName
  • ユーザ抽出

2011年10月5日水曜日

仕様変更に伴うTwitterStreamingReaderの変更

どうやら,Twitterで仕様変更があったらしく,
StreamingAPIを使ったデータの読み込みを変更しなければいけなくなりました.

具体的には,TwitterのDeveloper用ブログにあるとおり,
All our Streaming API products are now supporting SSL and we've just updated the Streaming API Methods, User Streams and Site Streams documentation pages accordingly. As we're planning to sunset HTTP support in about a month, we strongly encourage you to switch to SSL (HTTPS) as soon as possible, especially if you're still authenticating your Streaming API requests with Basic Auth.
ということで,SSLを使ってね,ということらしいです.

そんなわけで,以前作成したTwitterStreamReaderではなく,新しいバージョンを使ってください.

変更点は,SSLに対応させただけだけど.
得られるTweetデータはJSON形式なので,jsonicなどを使ってJSONの処理をちゃんとしないと日本語が文字化けするようです.
また,日本語のTweetだけ取り出したい人は,文字列に日本語が含まれるかどうかの判定をご参照ください.

package twitter;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * StreamAPIから送られてくるStreamデータをひたすら取得し続けるクラス
 * @author tori
 *
 */
public class TwitterStreamReader {


 /**
  * 使い方の例
  * @param args
  * @throws UnsupportedEncodingException 
  */
 public static void main(String[] args) throws UnsupportedEncodingException {
  
  TwitterStreamReader tsr = new TwitterStreamReader("Twitter-UserName", "Password");
  tsr.start();
  
  while(true){
   List<String> tweetList = tsr.readStoredList();
   List<String> errList = tsr.readErrLogList();
   
   for(String text:tweetList){
    System.out.println(text);
   }
   
   for(String err:errList){
    System.err.println(err);
   }
  }
 }
 
 /**
  * sampleのタイムライン取得のためのURL
  */
 private static final String DEFAULT_API_URL = "https://stream.twitter.com/1/statuses/sample.json";

 String userName;
 String password;

 /**
  * 強制終了させられたかどうか
  */
 boolean isForceStop;

 /**
  * 取得しているかどうか
  */
 boolean isRunning;
 
 /**
  * Synchlonizedされたリスト
  */
 List<String> dataList;

 /**
  * Synchlonizedされたリスト
  */
 List<String> errLogList;

 /**
  * apiのURL
  */
 String apiUrl = DEFAULT_API_URL;

 /**
  * ストリームを読み続けるためのスレッド
  */
 private Thread streamReadThread;
 
 public TwitterStreamReader(String userName, String password) {
  super();
  this.userName = userName;
  this.password = password;

  dataList = Collections.synchronizedList(new ArrayList<String>());
  errLogList = Collections.synchronizedList(new ArrayList<String>());
  
 }

 /**
  * 読み込みを開始する
  */
 public void start(){
  StreamReader streamReader = new StreamReader();
  
  streamReadThread = new Thread(streamReader);
  streamReadThread.start();
 }

 /**
  * 取得を停止する
*/
 public void stop() {
  this.isForceStop = true;
 }
 
 /**
  * データ取得中かどうかを返す
  * @return
  */
 public boolean isRunning(){
  return streamReadThread.isAlive();
 }
 
 /**
  * 取得済みのTweetデータのリストを取得する
* これまでに読み込んだデータは削除される
  * @return 是までに読み込んだデータ
  */
 public List<String> readStoredList(){
  List<String> storedList;
  synchronized (dataList) {
   storedList = new ArrayList<String>(dataList);
   dataList.clear();
  }

  return storedList;
 }
 
 /**
  * エラーログのリストを取得する
* これまでに読み込んだデータは削除される
  * @return 是までに読み込んだデータ
  */
 public List<String> readErrLogList(){
  List<String> storedList;
  synchronized (errLogList) {
   storedList = new ArrayList<String>(errLogList);
   errLogList.clear();
  }
  return storedList;
 }

 /**
  * 強制停止信号を送ったかどうか
  * @return the isForceStop
  */
 public boolean isForceStop() {
  return isForceStop;
 }
 
 /**
  * データ読み込み用クラス
  * @author tori
  *
  */
 class StreamReader implements Runnable{
  @Override
  public void run() {
   isForceStop = false;
   while(!isForceStop){
    InputStreamReader isr = null;
    BufferedReader br = null;
    try{
     URL connectUrl = new URL(apiUrl);
     HttpURLConnection con = (HttpURLConnection)connectUrl.openConnection();
     
     con.setRequestMethod("GET");
     con.setDoOutput(true);
     con.setInstanceFollowRedirects(true); 

     Authenticator auth = new Authenticator(){
      public PasswordAuthentication getPasswordAuthentication(){
       return new PasswordAuthentication(userName, password.toCharArray());
      }
     };
     Authenticator.setDefault(auth);
     

     isr = new InputStreamReader(con.getInputStream(), "UTF8");
     br = new BufferedReader(isr);
     while(!isForceStop){
      String tweet = br.readLine();
      synchronized (dataList) {
       dataList.add(tweet);
      }
     }
    }catch(Exception e){
     StringBuffer buf = new StringBuffer();
     buf.append(e.getClass().getName()+"\n");
     for(StackTraceElement ste:e.getStackTrace()){
      buf.append(String.format("\tat %s.%s(%s:%d)\n", ste.getClassName(), ste.getMethodName(), ste.getFileName(), ste.getLineNumber()));
     }
     synchronized (errLogList) {
      errLogList.add(buf.toString());
     }
    }finally{
     try{
      br.close();
     }catch(Exception e){
     }
     try{
      isr.close();
     }catch(Exception e){
     }
    }
   }
  }
 }
}

2011年7月30日土曜日

じゃんけん大会の必勝法

世の中こんなブログであふれている.
たった5万円から億万長者になった、成功の9ステップ

非常に学びが多く、ここに書かれたことを実践することで、自分なりの成功に近づけると思った。

とか書いてあるけれど,
成功例だけ見てその結果を模倣しても,
それは単にじゃんけん大会で勝った人の話を聞いているだけじゃないかと思う.
何万人でじゃんけん大会をしても,必ず一人は優勝者が出る.
ただ,その優勝者は偶然優勝しただけであって,必勝法など無い.
にもかかわらず,その人がどう優勝したかを聞いて,それを実践してじゃんけん大会で優勝しようとしているようなもの.

ある行動が成功に結びつくかどうかを知りたいのならば,
その行動を行った人を一定量サンプリングして,その中の成功例と失敗例を調べるべき.
成功した人のほんとどがやっていた行動をすれば成功する信じるのならば,みんな毎日息をしていればいいと思う.
成功者はみんな息をしているんだから.

というわけで,そんな簡単な統計学も分からないようではやっぱり成功しないんじゃないだろうか.