Skip to content

Commit

Permalink
@
Browse files Browse the repository at this point in the history
  • Loading branch information
mlesnoff committed Feb 20, 2025
1 parent 92d93e6 commit 1298d5e
Show file tree
Hide file tree
Showing 111 changed files with 425 additions and 391 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Jchemo"
uuid = "fbca9394-dd0a-4d1c-b066-ae75f6ef1ad5"
authors = ["Matthieu Lesnoff <[email protected]>"]
version = "0.8.5"
version = "0.8.6"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ julia> ?plskern
```

The `kwargs` arguments and their default values are defined in containers depending of the functions, available
[**here**](https://github.com/mlesnoff/Jchemo.jl/blob/master/src/_structures_param.jl). For a given function, they can be displayed in the REPL with function `default`, e.g.:
[**here**](https://github.com/mlesnoff/Jchemo.jl/blob/master/src/_structures_param.jl). For a given function, they can be displayed in the REPL with macro `@pars`, e.g.:

```julia
julia> default(plskern)
julia> @pars plskern

Jchemo.ParPlsr
nlv: Int64 1
Expand Down Expand Up @@ -216,7 +216,7 @@ fit!(model, Xtrain)
Contents of object `model` can be displayed by:

``` julia
julia> pnames(model)
julia> @names model

(:algo, :fitm, :kwargs)
```
Expand Down
14 changes: 9 additions & 5 deletions docs/src/domains.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,15 @@

## UTILITIES

*Macros*
- **@head** Display the first rows of a dataset
- **@mod** Shortcut for function **parentmodule**
- **@names** Return the names of the sub-objects contained in a object
- **@pars** Display the keyword arguments (with their default values) of a function
- **@plist** Display each element of a list
- **@type** Display the type and size of a dataset

*Others*
- **aggstat** Compute column-wise statistics by class in a dataset
- **aggsum** Compute sub-total sums by class of a categorical variable
- **sumv**, **meanv**, **stdv**, **varv**, **madv**, **iqrv**, **normv** Vector operations
Expand All @@ -369,7 +378,6 @@
- **colmeanskip**, **colstdskip**, **colsumskip**,
**colvarskip** Column-wise operations allowing missing data
- **convertdf** Convert the columns of a dataframe to given types
- **default** Display the keyword arguments (with their default values) of a function
- **dummy** Build dummy table
- **euclsq**, **mahsq**, **mahsqchol** Distances (Euclidean, Mahalanobis) between rows of matrices
- **fblockscal_col, _frob, _mfa, _sd** Scale blocks
Expand All @@ -379,7 +387,6 @@
- **frob**, **frob2** Frobenius norm of a matrix
- **fweight** Weight each row of a matrix
- **getknn** Find nearest neighbours between rows of matrices
- **head**, **@head** Display the first rows of a dataset
- **iqrv** Interval inter-quartiles
- **krbf, kpol** Build kernel Gram matrices
- **locw** Working function for local (kNN) models
Expand All @@ -392,9 +399,6 @@
- **nco**, **nro**, Nb. rows and columns of an object
- **normv** Norm of a vector
- **parsemiss** Parsing a string vector allowing missing data
- **plist** Print each element of a list
- **pnames** Return the names of the elements of an object
- **psize** Return the type and size of a dataset
- **pval** Compute p-value(s) for a distribution, an ECDF or vector

- **recod_catbydict** Recode a categorical variable to dictionnary levels
Expand Down
9 changes: 9 additions & 0 deletions docs/src/news.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# News

## *Version 0.8.6*

- News
- Functions **@mod**, **@names**, **@pars**,
**@plist**, **@type**.

- Modifications
- Code cleaning.

## *Version 0.8.5*

- Modifications
Expand Down
11 changes: 4 additions & 7 deletions src/Jchemo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ include("_struct_fun.jl")
include("_model_work.jl")
include("_pip.jl")
## End
include("default.jl")
include("defaults.jl")

######---- Misc

Expand Down Expand Up @@ -253,8 +253,9 @@ export
fit!,
transf!,
pip,
default,
######---- Utilities
@head, @mod, @names, @pars, @plist, @type,
##
aggstat, aggsum,
sumv, meanv, stdv, varv, madv, iqrv, normv,
colsum, colmean, colnorm, colstd, colvar, colmed, colmad,
Expand All @@ -275,20 +276,16 @@ export
frob, frob2,
fscale, fscale!,
wdis, wtal,
head, @head,
list,
matB, matW,
mblock,
mlev,
mweight, mweightcla,
nco,
nipals,
nipalsmiss,
nro,
nro, nco,
out,
parsemiss,
plist,
pmod, pnames, psize,
pval,
recod_catbyint, recod_numbyint,
recovkw,
Expand Down
2 changes: 1 addition & 1 deletion src/_mod_.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ y = rand(5)
model = mod_(detrend_pol) # use the default arguments of 'detrend_pol'
#model = detrend_pol(X; degree = 2)
pnames(model)
@names model
fit!(model, X)
Xp = transf(model, X)
Expand Down
2 changes: 1 addition & 1 deletion src/_pip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using JLD2, CairoMakie, JchemoData
mypath = dirname(dirname(pathof(JchemoData)))
db = joinpath(mypath, "data", "cassav.jld2")
@load db dat
pnames(dat)
@names dat
X = dat.X
y = dat.Y.tbc
year = dat.Y.year
Expand Down
149 changes: 93 additions & 56 deletions src/_util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ using Jchemo
y = ["d", "a", "b", "c", "b", "c"]
#y = rand(1:3, 7)
res = dummy(y)
pnames(res)
@names res
res.Y
```
"""
Expand Down Expand Up @@ -265,15 +265,14 @@ function findmiss(X)
end

"""
head(X)
@head X
Display the first rows of a dataset.
## Examples
```julia
using Jchemo
X = rand(100, 5)
head(X)
@head X
```
"""
Expand All @@ -292,7 +291,7 @@ function head(X)
end

macro head(X)
esc( :( head($X) ))
esc( :( Jchemo.head($X) ))
end

"""
Expand Down Expand Up @@ -426,6 +425,30 @@ function mweightcla(Q::DataType, x::AbstractVector; prior::Union{Symbol, Vector}
mweight(convert.(Q, mweightcla(x; prior).w))
end

"""
@namvar x
Return the name of a variable.
* `x` : A variable or function.
Thanks to:
https://stackoverflow.com/questions/38986764/save-variable-name-as-string-in-julia
## Examples
```julia
using Jchemo
z = 1:5
Jchemo.@namvar z
```
"""
macro namvar(arg)
x = string(arg)
quote
$x
end
end


"""
nco(X)
Return the nb. columns of `X`.
Expand Down Expand Up @@ -482,41 +505,6 @@ function parsemiss(Q, x::Vector{Union{String, Missing}})
v
end

"""
plist(x)
Print each element of a list.
"""
function plist(x)
nam = pnames(x)
for i in eachindex(nam)
println("--- ", nam[i])
println("")
println(x[i])
println("")
end
end

"""
pmod(foo)
Shortcut for function `parentmodule`.
"""
pmod(foo) = parentmodule(foo)

"""
pnames(x)
Return the names of the elements of `x`.
"""
pnames(x) = propertynames(x)

"""
psize(x)
Print the type and size of `x`.
"""
function psize(x)
println(typeof(x))
println(size(x))
end

"""
pval(d::Distribution, q)
pval(x::Array, q)
Expand Down Expand Up @@ -946,7 +934,7 @@ n = 50
X = rand(n, 3)
y = rand(1:3, n)
res = summ(X)
pnames(res)
@names res
summ(X[:, 2]).res
summ(X, y)
Expand Down Expand Up @@ -1143,8 +1131,8 @@ end
vcol(X::AbstractMatrix, j)
vcol(X::DataFrame, j)
vcol(x::Vector, j)
View of the j-th column(s) of a matrix `X`,
or of the j-th element(s) of vector `x`.
View of the j-th column(s) of a matrix `X`, or of the j-th element(s)
of vector `x`.
"""
vcol(X, j) = view(X, :, j)
vcol(x::Vector, i) = view(x, i)
Expand All @@ -1154,36 +1142,85 @@ vcol(X::DataFrame, j) = view(Matrix(X), :, j)
vrow(X::AbstractMatrix, i)
vrow(X::DataFrame, i)
vrow(x::Vector, i)
View of the i-th row(s) of a matrix `X`,
or of the i-th element(s) of vector `x`.
View of the i-th row(s) of a matrix `X`, or of the i-th element(s)
of vector `x`.
"""
vrow(X, i) = view(X, i, :)
vrow(X::DataFrame, i) = view(Matrix(X), i, :)
vrow(x::Vector, i) = view(x, i)

##################### MACROS
########### Macros

"""
@mod fun
Shortcut for function `parentmodule`.
* `fun` : The name of a function.
## Examples
```julia
@mod rand
```
"""
@namvar(x)
Return the name of a variable.
* `x` : A variable or function.
macro mod(fun)
esc( :( parentmodule($fun) ))
end

Thanks to:
https://stackoverflow.com/questions/38986764/save-variable-name-as-string-in-julia
"""
@names x
Return the names of the sub-objects contained in a object.
* `x`: An object.
Shortcut for function `propertynames`.
"""
macro names(x)
esc( :( propertynames($x) ))
end

"""
@pars fun
Display the keyword arguments (with their default values) of a function
* `fun` : The name of a function.
## Examples
```julia
using Jchemo
z = 1:5
Jchemo.@namvar(z)
@pars krr
```
"""
macro namvar(arg)
x = string(arg)
quote
$x
macro pars(fun)
esc( :( Jchemo.defaults($fun) ))
end

"""
@plist x
Display each element of a named list.
* `x` : A list.
"""
macro plist(x)
esc( :( Jchemo.plist($x) ))
end

function plist(x)
nam = propertynames(x)
for i in eachindex(nam)
println("--- ", nam[i])
println("")
println(x[i])
println("")
end
end

"""
@type x
Display the type and size of a dataset.
* `x` : A dataset.
"""
macro type(x)
esc( :( Jchemo.ptype($x) ))
end

function ptype(x)
println(typeof(x))
println(size(x))
end

2 changes: 1 addition & 1 deletion src/aicplsr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using Jchemo, JchemoData, CairoMakie
mypath = dirname(dirname(pathof(JchemoData)))
db = joinpath(mypath, "data", "cassav.jld2")
@load db dat
pnames(dat)
@names dat
X = dat.X
y = dat.Y.tbc
year = dat.Y.year
Expand Down
Loading

0 comments on commit 1298d5e

Please sign in to comment.