Skip to content

Commit

Permalink
Extend constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelArutjunjan committed Oct 15, 2024
1 parent f7076c7 commit 1da0542
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/DataStructures/DataSetUncertain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct DataSetUncertain{BesselCorrection} <: AbstractUnknownUncertaintyDataSet
ynames::AbstractVector{<:AbstractString}
name::Union{<:AbstractString,<:Symbol}

DataSetUncertain(DS::AbstractDataSet; kwargs...) = DataSetUncertain(xdata(DS), ydata(DS), dims(DS); xnames=xnames(DS), ynames=ynames(DS), kwargs...)
function DataSetUncertain(X::AbstractArray, Y::AbstractArray, dims::Tuple{Int,Int,Int}=(size(X,1), ConsistentElDims(X), ConsistentElDims(Y)); kwargs...)
@info "Assuming error model σ(x,y,c) = exp10.(c)"
errmod = ydim(dims) == 1 ? ((x,y,c::AbstractVector)->inv(exp10(c[1]))) : (x,y,c::AbstractVector)->Diagonal(inv.(exp10.(c)))
Expand All @@ -50,6 +51,7 @@ struct DataSetUncertain{BesselCorrection} <: AbstractUnknownUncertaintyDataSet
size(X,1) != size(Y,1) && throw("Inconsistent number of x-values and y-values given: $(size(X,1)) != $(size(Y,1)). Specify a tuple (Npoints, xdim, ydim) in the constructor.")
DataSetUncertain(Unwind(X), Unwind(Y), inverrormodel, testp, (size(X,1), ConsistentElDims(X), ConsistentElDims(Y)); kwargs...)
end
DataSetUncertain(DS::AbstractDataSet, inverrormodel::Function, testp::AbstractVector=0.1ones(ydim(DS)); kwargs...) = DataSetUncertain(xdata(DS), ydata(DS), inverrormodel, testp, dims(DS); xnames=xnames(DS), ynames=ynames(DS), kwargs...)
function DataSetUncertain(x::AbstractVector, y::AbstractVector, inverrormodel::Function, testp::AbstractVector, dims::Tuple{Int,Int,Int}; kwargs...)
@info "Assuming error parameters always given by last $(length(testp)) parameters."
DataSetUncertain(x, y, inverrormodel, DefaultErrorModel(length(testp)), testp, dims; kwargs...)
Expand Down
10 changes: 5 additions & 5 deletions src/DataStructures/UnknownVarianceDataSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ struct UnknownVarianceDataSet{BesselCorrection} <: AbstractUnknownUncertaintyDat
ynames::AbstractVector{<:AbstractString}
name::Union{<:AbstractString,<:Symbol}

function UnknownVarianceDataSet(x::AbstractArray, y::AbstractArray, Testpx::AbstractVector, Testpy::AbstractVector; kwargs...)
UnknownVarianceDataSet(x, y; testpx=Testpx, testpy=Testpy, kwargs...)
end
UnknownVarianceDataSet(DS::AbstractDataSet; kwargs...) = UnknownVarianceDataSet(xdata(DS), ydata(DS), dims(DS); xnames=xnames(DS), ynames=ynames(DS), kwargs...)
function UnknownVarianceDataSet(X::AbstractArray, Y::AbstractArray, dims::Tuple{Int,Int,Int}=(size(X,1), ConsistentElDims(X), ConsistentElDims(Y));
testpx::AbstractVector=zeros(xdim(dims)), testpy::AbstractVector=zeros(ydim(dims)), kwargs...)
size(X,1) != size(Y,1) && throw("Inconsistent number of x-values and y-values given: $(size(X,1)) != $(size(Y,1)). Specify a tuple (Npoints, xdim, ydim) in the constructor.")
testpx::AbstractVector=0.1ones(xdim(dims)), testpy::AbstractVector=0.1ones(ydim(dims)), kwargs...)
@info "Assuming error models σ(x,y,c) = exp10.(c)"
xerrmod = xdim(dims) == 1 ? ((x,y,c::AbstractVector)->inv(exp10(c[1]))) : (x,y,c::AbstractVector)->Diagonal(inv.(exp10.(c)))
yerrmod = ydim(dims) == 1 ? ((x,y,c::AbstractVector)->inv(exp10(c[1]))) : (x,y,c::AbstractVector)->Diagonal(inv.(exp10.(c)))
UnknownVarianceDataSet(Unwind(X), Unwind(Y), xerrmod, yerrmod, testpx, testpy, dims; kwargs...)
end
function UnknownVarianceDataSet(DS::AbstractDataSet, invxerrormodel::Function, invyerrormodel::Function, testpx::AbstractVector=0.1ones(xdim(DS)), testpy::AbstractVector=0.1ones(ydim(DS)); kwargs...)
UnknownVarianceDataSet(xdata(DS), ydata(DS), invxerrormodel, invyerrormodel, testpx, testpy, dims(DS); xnames=xnames(DS), ynames=ynames(DS), kwargs...)
end
function UnknownVarianceDataSet(x::AbstractVector, y::AbstractVector, invXvariancemodel::Function, invYvariancemodel::Function,
testpx::AbstractVector, testpy::AbstractVector, dims::Tuple{Int,Int,Int}=(size(X,1), ConsistentElDims(X), ConsistentElDims(Y)); kwargs...)
@info "Assuming error parameters always given by last ($(length(testpx)),$(length(testpy))) parameters respectively."
Expand Down

0 comments on commit 1da0542

Please sign in to comment.