-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply scaling to certain slices of an array #39
Comments
Not sure what the problem is? perhaps you can elaborate? If I use the same julia> scaling = MeanStdScaling(M; dims=2)
MeanStdScaling((1 = 2.5, 2 = 3.5, 3 = 4.5), (1 = 2.1213203435596424, 2 = 2.1213203435596424, 3 = 2.1213203435596424))
julia> FeatureTransforms.apply(M, scaling; dims=2, inds=[2])
3×1 Array{Float64,2}:
0.7071067811865476
0.7071067811865476
0.7071067811865476 |
The example you give is normalizing over the rows (i.e. each row ends up with mean=0 and std=1) and selecting one column. The problem is you can't normalize a column AND select the column in an array. Consider the analogy to Table data: when constructing |
I think this is related to Example: julia> M = [2 4; 1 5; 3 6]
3×2 Array{Int64,2}:
2 4
1 5
3 6 I can add the first and third rows as follows: julia> lc_rows = LinearCombination([1, 1]);
julia> FeatureTransforms.apply(M, lc_rows; dims=2, inds=[1, 3])
2-element Array{Int64,1}:
5
10 But this meaning of julia> p = Power(2)
julia> FeatureTransforms.apply(M, p; dims=2, inds=[1, 3])
ERROR: BoundsError: attempt to access 2-element Array{Int64,1} at index [[1, 3]]
Stacktrace:
[1] throw_boundserror(::Array{Int64,1}, ::Tuple{Array{Int64,1}}) at ./abstractarray.jl:541
[2] checkbounds at ./abstractarray.jl:506 [inlined]
[3] view at ./subarray.jl:158 [inlined]
[4] maybeview at ./views.jl:133 [inlined]
[5] (::FeatureTransforms.var"#3#4"{Array{Int64,1},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},Power})(::Array{Int64,1}) at /Users/bencottier/JuliaEnvs/Transform.jl/src/transformers.jl:82
[6] mapslices(::FeatureTransforms.var"#3#4"{Array{Int64,1},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},Power}, ::Array{Int64,2}; dims::Int64) at ./abstractarray.jl:2083
[7] #apply#2 at /Users/bencottier/JuliaEnvs/Transform.jl/src/transformers.jl:80 [inlined]
[8] top-level scope at REPL[29]:1 I think it's because a value |
MWE:
We can apply
Power
to the second column usinginds
because
dims=2
iterates each row andinds=[2]
indexes the second element of each row.But to normalize the second column with
MeanStdScaling
, we need to useMeanStdScaling(M; dims=1)
(i.e. take the mean and std of each column). Then I see no way to only normalise the second column, becausedims
needs to be consistent.Maybe we need a
slices
argument to only apply to certain slices?The text was updated successfully, but these errors were encountered: