Comments (1)
Hello,
I just wrote a function, based on a recurrence relation that can be found on Wikipedia.
Do you have any suggestion whether it is useful for this package, or else if this code could be a useful addition elsewhere?
Any (other) comment of course welcome too.
Cheers,
Evaluate the incomplete Bell polynomial B_{N,K}(x)
where x is an array containing the abscissa values [x_1, ... x{n-k+1}]
Definition and background information, see
https://en.wikipedia.org/wiki/Bell_polynomials#Definitions
https://en.wikipedia.org/wiki/Bell_polynomials#Properties
https://en.wikipedia.org/wiki/Bell_polynomials#Table_of_values
"""
evaluate_incomplete_Bell_poly = function(N,K,all_x)
# see formula C2
# let us construct the triangular table
if K > N
return 0.
end
all_B_old = zeros(N+1,1)
all_B_old[1] = 1.
all_B_new = zeros(N+1,1)
all_B_new[1] = 1.
for k=1:K
for n=1:N
all_B_new[n+1] = sum([binomial(n-1,i-1)*all_x[i]*all_B_old[n-i+1] for i=1:n-k+1])
end
all_B_old .= all_B_new
end
return all_B_new[end]
end
## test the function
x = randn(11,1)
@assert evaluate_incomplete_Bell_poly(0,0,x) ≈ 1.
@assert evaluate_incomplete_Bell_poly(1,0,x) ≈ 0.
@assert evaluate_incomplete_Bell_poly(3,0,x)≈ 0.
@assert evaluate_incomplete_Bell_poly(0,1,x) ≈ 0.
@assert evaluate_incomplete_Bell_poly(0,3,x) ≈ 0.
@assert evaluate_incomplete_Bell_poly(1,1,x) ≈ x[1]
@assert evaluate_incomplete_Bell_poly(2,2,x) ≈ x[1]^2
@assert evaluate_incomplete_Bell_poly(3,3,x) ≈ x[1]^3
@assert evaluate_incomplete_Bell_poly(6,4,x) ≈ 45*x[1]^2*x[2]^2 + 20*x[1]^3*x[3]
@assert evaluate_incomplete_Bell_poly(5,4,x) ≈ 10*x[1]^3*x[2]
@assert evaluate_incomplete_Bell_poly(6,3,x) ≈ 15*x[2]^3 + 60*x[1]*x[2]*x[3] + 15*x[1]^2*x[4]
# use some results in (Abbas, M.; Bouroubi, S. (2005). "On new identities for Bell's polynomial". Discrete Math. 293 (1–3)) as reference
# see https://vinar.vin.bg.ac.rs//bitstream/id/12791/4374.pdf
@assert evaluate_incomplete_Bell_poly(9,7,x) ≈ 378*x[1]^5*x[2]^2 + 84*x[1]^6*x[3]
@assert evaluate_incomplete_Bell_poly(10,7,x) ≈ 3150*x[1]^4*x[2]^3 + 2520*x[1]^5*x[2]*x[3] + 210*x[1]^6*x[4]
@assert evaluate_incomplete_Bell_poly(11,7,x) ≈ 17325*x[1]^3*x[2]^4 + 34650*x[1]^4*x[2]^2*x[3] + + 4620*x[1]^5*x[3]^2 + 6930*x[1]^5*x[2]*x[4] + 462*x[1]^6*x[5]
println("tests passed")
from combinatorics.jl.
Related Issues (20)
- Edit on GitHub button does not work HOT 3
- Enumerating permutations in-place HOT 1
- multiset_permutations: documentation
- with_replacement_permutations
- Bug report: combinations does not work for Sets HOT 1
- Combinations of a set of lengths
- Include reference to "binomial", "n choose k" in documentation
- `combination` does not include the empty set
- Permuted partitions HOT 1
- Array allocation in iterating over `MultiExponents` HOT 3
- function nthcomb to match nthperm HOT 1
- Levi-Civita call is unhelpful.
- `integer_partitions(0)` should return `[[]]` instead of `[]`
- Tuples and Outer HOT 1
- Bug in integer_partitions(0)
- Allocations when iterating Combinations HOT 2
- `permutations` is less efficient than `multiset_permutations`
- [ci] doc deploy failed HOT 1
- Reopen doctest
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from combinatorics.jl.