我想在Julia中構建一個Dirichlet進程Gibbs進程,並將每個簇描述爲一個對象。我做了以下內容:MethodError:沒有方法匹配是無效的(:: Symbol,:: Int64)
using BayesianNonparametrics
using DataFrames
using Distances
type cluster
m::Vector
Sigma::LinAlg.Cholesky
nu::Int
kappa::Int
nk::Int
end
function logPredPdf(f::cluster,x::Array{Float64,1}):
kappa <- f.kappa
S <- f.Sigma
mu <- f.m
nu <- f.nu
d <- size(x)[1]
v = nu-d+1
U = sqrt((1+1/kappa)/v) * LinAlg.lowrankdowndate!(S, sqrt(f.kappa)*mu)[:U]
x = x - m
Q = \(transpose(U),x)
q= vecdot(Q,Q)
o = -log(1+q/v)*((v+d)/2)
c = lgamma((v+d)/2)-lgamma(v/2)-(d*log(v*pi)+2*sum(log(diag(U))))/2
y = c + o
return y
end
data = readtable("PCA_transformed_data_gt1000.csv",header= true);
data = delete!(data, :1);
n,d = size(data);
s = 6.6172
S0 = s*eye(d)
kappa_0 = 1
nu_0 = d
mu_0 = zeros(d)
S1 = LinAlg.cholfact(S0+kappa_0*(mu_0*mu_0'))
X= DataFrame(Matrix(data)');# transpose data Matrix
prior = cluster(mu_0, S1,nu_0, kappa_0, 0)
x = X[:,1]
kt = logPredPdf(prior,x)
當我在函數外部運行logPredPdf內部的行時,它完美地工作!但是,如果我嘗試運行上面的例子,當它在最後, 它給了我下面的錯誤:
MethodError: no method matching isless(::Symbol, ::Int64)
Closest candidates are:
isless(!Matched::Char, ::Integer) at deprecated.jl:49
isless(::Symbol, !Matched::Symbol) at strings/basic.jl:137
isless(!Matched::DataArrays.NAtype, ::Any) at /Users/u1560476/.julia/v0.5/DataArrays/src/operators.jl:510
...
in logPredPdf(::cluster, ::Array{Float64,1}) at Dirichlet_Process_Gibbs_Sampler.jl:33
in include_string(::String, ::String) at loading.jl:441
in include_string(::String, ::String, ::Int64) at eval.jl:30
in include_string(::Module, ::String, ::String, ::Int64, ::Vararg{Int64,N}) at eval.jl:34
in (::Atom.##53#56{String,Int64,String})() at eval.jl:50
in withpath(::Atom.##53#56{String,Int64,String}, ::String) at utils.jl:30
in withpath(::Function, ::String) at eval.jl:38
in macro expansion at eval.jl:49 [inlined]
in (::Atom.##52#55{Dict{String,Any}})() at task.jl:60
類型「之前」和「x」是集羣和Array {Float64,1的},如函數所要求的。任何想法,我在這裏失蹤?
'kappa < - f.kappa'適合你嗎? – rickhg12hs
什麼是「<-'運算符?它是否在您使用的其中一個模塊中定義?或者你是在'R'模式下寫錯了'< - '而不是'='?這個錯誤使得茱莉婭不知道這個運算符,並且把它看作是你試圖比較一個符號和一個(負)整數,即'kappa <(-f.kappa)' –