# Sampling using Turing and a customized distribution

**URL:** https://discourse.julialang.org/t/sampling-using-turing-and-a-customized-distribution/61031
**Category:** General Usage
**Tags:** turing
**Created:** [May 12, 2021, 4:35pm UTC](https://discourse.julialang.org/t/sampling-using-turing-and-a-customized-distribution/61031 "2021-05-12T16:35:20Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![marouane](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marouane/32/16267_2.png) [@marouane](https://discourse.julialang.org/u/marouane)
#### Post date: [May 12, 2021, 4:35pm UTC](https://discourse.julialang.org/t/sampling-using-turing-and-a-customized-distribution/61031/1 "2021-05-12T16:35:20Z")

</div>

I have this customized distribution below:

```julia
using Distributions
struct OrthoNNDist <: DiscreteMultivariateDistribution
	x0::Vector{Int64}
	oc::Array{Int64,2}
	x1s::Array
	prob::Float64
    #return a new uniform distribution with all vectors in x1s orthogonal to oc
	function OrthoNNDist(x0::Vector{Int}, oc::Array{Int,2})
		x1s = []
		for i = 1:size(oc)[2]
			x1 = x0 + oc[:, i]
			if nonneg(x1)
				push!(x1s, x1)
			end
			x1 = x0 - oc[:, i]
			if nonneg(x1)
				push!(x1s, x1)
			end
		end
		new(x0, oc, x1s, 1.0/length(x1s))
	end
end

Base.length(d::OrthoNNDist) = length(d.x0)

Distributions.rand(d::OrthoNNDist) = rand(d.x1s)

Distributions.pdf(d::OrthoNNDist, x::Vector) = x in d.x1s ? d.prob : 0.0
Distributions.pdf(d::OrthoNNDist) = fill(d.prob, size(d.x1s))
Distributions.logpdf(d::OrthoNNDist, x::Vector) = log(pdf(d, x))

```

and also i have my log\_target function that takes a vector as an argument: `log_target(x::Vector) `i don’t think its expression is important, i am struggling here with how can i use the distribution and the target function with Turing i read the doc, but i’m still a bit confused and not sure how to do it i’ll appreciate an example or an explanation of how to do it, i’m still new on Turing, thanks.
