反正就是一整個好玩!!!(  ̄ c ̄)y▂ξ

目前日期文章:200912 (6)

瀏覽方式: 標題列表 簡短摘要

class String

  def mbsubstr1(*range)

      split(//)[*range].join("")

  end

 

   def mbsubstr2(idx, len)

       slice(/\A.{#{idx}}(.{0,#{len}}/m, 1)

   end

end

p "一大串字一大串字".mbsubstr1(2,3)

p "一大串字一大串字".mbsubstr1(2..3)

p "一大串字一大串字".mbsubstr2(2,2)

Maximum Matching Segmentation (MMSeg)

#str 一段文字, term 字典的中的詞

def mmseg(str,term)
strEnd = str.length-1
  loop do
    tmpStr=str.substr(0..strEnd)
    strEnd -= 1
    sleep 0.1
    puts tmpStr

    if tmpStr == term
      print "I found #{tmpStr}"
      break
    end
    if (strEnd == -1)
      str=str.substr(1..-1)
      strEnd = str.length-1
      if str.length == 1
        puts "no match"
        break
      end
    end
  end
end

 

 

igogo 發表在 痞客邦 留言(0) 人氣()

 

使用lambda 計算 Euclidean distance

若p(1,1), q(3,3)

則 d(p,q)

 ->(xs,ys,xt,yt){Math.sqrt((xs-xt)**2+(ys-yt)**2)}.(1,1,3,3)

 

lambda fuction

 f = { 1 => ->(x) { puts "#{x}  from 1" },

         2 => ->(x) { puts "#{x} bye from 2" }

      }

f.call[1]("mary")

 

HyperSphere 中,求任兩點的的距離(EuclideanDistance)

def EuclideanDistance(x,y)
  sum = 0
  for i in (0..x.size-1)
    printf("x[%d]=%d,y[%d]=%d\n",i,x[i],i,y[i])
    ->(px,py){ sum += (px-py)**2}.(x[i],y[i])
  end
puts Math.sqrt(sum)
end

x=[1,1]
y=[3,3]
p=[1,1,1]
q=[3,3,3]

a=[1,1,1,1]
b=[3,3,3,3]

EuclideanDistance(x,y)
EuclideanDistance(p,q)

EuclideanDistance(a,b)

 

igogo 發表在 痞客邦 留言(0) 人氣()

n類中,取任兩類別算相似度, 第一步,先把要算的組合列出來

n=4
i=1
j=i+1

while (i<4) do
  while (j<=n) do
    printf("%d,%d\n",i,j)
    j += 1
  end
  i += 1
  j = i+1
end

igogo 發表在 痞客邦 留言(0) 人氣()


require 'ai4r'

data = [[1,1,1], [3,3,3],[9,9,9]]
ai4r_data = Ai4r::Data::DataSet.new(:data_items=> data)

kmeans = Ai4r::Clusterers::KMeans.new

#abuild(dataset,clusters)

res=kmeans.build(ai4r_data,2)

puts res.inspect

puts res.centroids.join(',')

 

Euclidean distance

http://en.wikipedia.org/wiki/Euclidean_space

http://en.wikipedia.org/wiki/Euclidean_distance

 

dis = Ai4r::Clusterers::KMeans.new

a = [1,1]
b = [3,3]


puts Math.sqrt(dis.distance(a,b))


都是幻覺,嚇不倒我的   (  ̄ c ̄)y▂ξ

igogo 發表在 痞客邦 留言(0) 人氣()


#!/usr/bin/ruby -Ku
require 'rubygems'
require 'csv'

f=ARGV[0]
File.open("#{f}") { |content|
  while line=content.gets
    puts CSV.parse(line).map{ |x|
     [ x[0], *x[1..-1].each.with_index.map{ |y, i| "#{i+1}:#{y}"} ].join(' ')
    }.join("\n")
  end                                                                           
}

igogo 發表在 痞客邦 留言(0) 人氣()

參考網址:

 A Comprehensive Comparative Study on Term Weighting Schemes for Text Categorization with SVM

Proposing a New Term Weighting Scheme for Text Categorization

Supervised and Traditional Term Weighting Methods for Automatic Text Categorization

igogo 發表在 痞客邦 留言(0) 人氣()