GithubHelp home page GithubHelp logo

weightedarrays.jl's Introduction

Weighted Arrays .jl

Build Status

This simple package defines a WeightedMatrix, a struct with vector of weights corresponding to the columns of a matrix. By default the weights(x) add up to 1. The array(x) values may have a box constraint:

julia> Weighted(randn(3,5))
Weighted 3×5 Array{Float64,2}, of unclamped θ:
 -0.264476   -1.83297      0.0669732  -0.340433  -1.87672
  0.0461253  -0.330401     0.0215189   2.3129    -1.78839
  0.461376    0.00486523  -0.819182   -1.43221   -0.855756
with normalised weights p(θ), 5-element Array{Float64,1}:
 0.2  0.2  0.2  0.2  0.2

julia> Weighted(rand(2,4), ones(4), 0, 1)
Weighted 2×4 Array{Float64,2}, clamped 0.0 ≦ θ ≦ 1.0:
 0.7842    0.257179  0.483388  0.780996
 0.138967  0.748165  0.387104  0.167825
with normalised weights p(θ), 4-element Array{Float64,1}:
 0.25  0.25  0.25  0.25

These examples are roughly wrandn(3,5) and wrand(2,4), there are also sub-random sobol(3,7) and regular wgrid(2, 0:0.1:1). Their values are mutable, clamp!(x) will enforce the box constraint, and normalise!(x) (with an s) the weights.

They are not subtypes of AbstractArray, but many functions will work. For instance x[1:2, :] keeps only the first two rows (and the weights), hcat(x,y) will concatenate the weights, and mapslices(f,x) will act with f on columns & then restore weights. sort(x) re-arranges columns to order by the weights, sortcols(x) orders by the array instead, unique(x) will accumulate the weights of identical columns. A few functions like log(x) and tanh(x) act element-wise but update the box constraints appropriately.

Most of this will work for any N-dimensional Array, not just a Matrix. The weights then belong to the last dimension.

Plot example

Plot recipes are defined, in which the area of points indicating weight. The example shown is a grid plus a bivariate sub-random normal distribution:

julia> using Plots

julia> plot(wgrid(2, -5:5), m=:+)

julia> plot!(soboln(2, 2000), m=:diamond, c=:red)

With more than three rows e.g. plot(wrandn(4,50)), it will plot the first two principal components (and attempt to scale these correctly). There is a function pplot(x) which saves the PCA function (see help for wPCA(x)) in a global variable, so that pplot!(t) can add more points on the same axes.

weightedarrays.jl's People

Contributors

github-actions[bot] avatar juliatagbot avatar mcabbott avatar

Watchers

 avatar  avatar

weightedarrays.jl's Issues

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.