Skip to content

Commit

Permalink
experiments_ready
Browse files Browse the repository at this point in the history
  • Loading branch information
PasoStudio73 committed Oct 5, 2024
1 parent 2edbf69 commit f320b07
Show file tree
Hide file tree
Showing 18 changed files with 406 additions and 111 deletions.
Binary file added irules_itadata2024/ravdess_emo2bins.jld2
Binary file not shown.
Binary file not shown.
Binary file added irules_itadata2024/respiratory_Bronchiolitis.jld2
Binary file not shown.
Binary file added irules_itadata2024/respiratory_COPD.jld2
Binary file not shown.
Binary file added irules_itadata2024/respiratory_Pneumonia.jld2
Binary file not shown.
Binary file added irules_itadata2024/respiratory_URTI.jld2
Binary file not shown.
2 changes: 1 addition & 1 deletion src/SoleAudio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ include("utils.jl")
include("rules.jl")
include("interface.jl")

export get_interesting_rules
export get_df_from_rawaudio, get_interesting_rules

export collect_audio_from_folder

Expand Down
1 change: 1 addition & 0 deletions src/analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function propositional_analisys(
X_propos = DataFrame([name => Float64[] for name in [match(r_select, v)[1] for v in p_variable_names]])
push!(X_propos, vcat([vcat([map(func, Array(row)) for func in metaconditions]...) for row in eachrow(X)])...)

println(rng)
X_train, y_train, X_test, y_test = partitioning(X_propos, y; train_ratio=train_ratio, rng=rng)

@info("Propositional analysis: train model...")
Expand Down
44 changes: 36 additions & 8 deletions src/interface.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -------------------------------------------------------------------------- #
# get interesting rules #
# -------------------------------------------------------------------------- #
function get_interesting_rules(;
function get_df_from_rawaudio(;
wav_path::String,
csv_file::Union{String, Nothing}=nothing,
# labels settings
Expand All @@ -17,6 +17,35 @@ function get_interesting_rules(;
label_df::Symbol=:label,
label_labels::Symbol=:label,
# audio settings
audioparams::NamedTuple=let sr=8000
(
sr = sr,
norm = true,
speech_detect = true,
sdetect_thresholds=(0,0),
sdetect_spread_threshold=0.02,
nfft = 256,
mel_scale = :mel_htk, # :mel_htk, :mel_slaney, :erb, :bark, :semitones, :tuned_semitones
mel_nbands = 26,
mfcc_ncoeffs = 13,
mel_freqrange = (0, round(Int, sr / 2)),
)
end,
)
df = collect_audio_from_folder(wav_path; audioparams=audioparams, fragmented=fragmented, frag_func=frag_func)
labels = isnothing(csv_file) ?
collect_classes(df, classes_dict; classes_func=classes_func) :
collect_classes(csv_file, classes_dict; id_labels=id_labels, label_labels=label_labels, header=header)
merge_df_labels!(df, labels; sort_before_merge=sort_before_merge, id_df=id_df, id_labels=id_labels, label_df=label_df, label_labels=label_labels)
return df
end

# -------------------------------------------------------------------------- #
# get interesting rules #
# -------------------------------------------------------------------------- #
function get_interesting_rules(
df::DataFrame;
# audio settings
featset::Tuple=(:mel, :mfcc, :f0, :spectrals),
audioparams::NamedTuple=let sr=8000
(
Expand All @@ -32,21 +61,20 @@ function get_interesting_rules(;
mel_freqrange = (0, round(Int, sr / 2)),
)
end,
# trim length settings
splitlabel::Symbol = :label,
lengthlabel::Symbol=:length,
audiolabel::Symbol=:audio,
min_length::Int64,
min_samples::Int64,
features::Symbol=:catch9,
nwindows::Int64=20,
relative_overlap::Float64=0.05,
train_ratio::Float64=0.8,
rng::AbstractRNG=Random.MersenneTwister(11),
rng::AbstractRNG=Random.GLOBAL_RNG,
)
df = collect_audio_from_folder(wav_path; audioparams=audioparams, fragmented=fragmented, frag_func=frag_func)
labels = isnothing(csv_file) ?
collect_classes(df, classes_dict; classes_func=classes_func) :
collect_classes(csv_file, classes_dict; id_labels=id_labels, label_labels=label_labels, header=header)
merge_df_labels!(df, labels; sort_before_merge=sort_before_merge, id_df=id_df, id_labels=id_labels, label_df=label_df, label_labels=label_labels)
sort_df!(df, :length; rev=true)
df = trimlength_df(df, :label, :length, :audio; min_length=min_length, min_samples=min_samples, sr=audioparams.sr)
df = trimlength_df(df, splitlabel, lengthlabel, audiolabel; min_length=min_length, min_samples=min_samples, sr=audioparams.sr)
X, y, variable_names = afe(df, featset, audioparams)
prop_sole_dt = propositional_analisys(X, y, variable_names=variable_names, features=features, train_ratio=train_ratio, rng=rng)
modal_sole_dt = modal_analisys(X, y; variable_names=variable_names, features=features, nwindows=nwindows, relative_overlap=relative_overlap, train_ratio=train_ratio, rng=rng)
Expand Down
11 changes: 5 additions & 6 deletions src/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,21 @@ function interesting_rules(
map(r->(consequent(r), readmetrics(r)), irules)
p_irules = sort(irules, by=readmetrics)

isempty(p_irules) && throw(ArgumentError("No interesting rules found."))
isempty(p_irules) && return nothing

p_X = DataFrame(antecedent=String[], consequent=String[]; [name => Vector{Union{Float64, Int}}() for name in keys(readmetrics(p_irules[1]))]...)
p_X = DataFrame(antecedent=String[], consequent=String[]; [name => Vector{Union{Float64, Int}}() for name in keys(readmetrics(p_irules[1]))]..., type=String[])
# p_X = DataFrame(
# antecedent = String[],
# consequent = String[],
# [name => Vector{Union{Float64, Int}}() for name in keys(readmetrics(p_irules[1]))]...
# )


for i in eachrow(p_irules)
a_c = match(r_p_divide, string(i[1]))
antecedent, consequent = a_c[1], a_c[3]
antecedent = reduce((s, r) -> replace(s, r => ""), r_p_ant, init=antecedent)
antecedent = format_float(antecedent)
push!(p_X, (antecedent, consequent, readmetrics(i[1])...))
push!(p_X, (antecedent, consequent, readmetrics(i[1])..., "propositional"))
end
else
p_X = nothing
Expand All @@ -81,7 +80,7 @@ function interesting_rules(
map(r->(r, readmetrics(r)), irules)
m_irules = sort(irules, by=readmetrics)

m_X = DataFrame(antecedent=String[], consequent=String[]; [name => Vector{Union{Float64, Int}}() for name in keys(readmetrics(m_irules[1]))]...)
m_X = DataFrame(antecedent=String[], consequent=String[]; [name => Vector{Union{Float64, Int}}() for name in keys(readmetrics(m_irules[1]))]..., type=String[])
for i in eachrow(m_irules)
consequent = match(r_cons, string(i[1].consequent))[1]
# antecedent = foldl((s, r) -> replace(s, r => ""), r_antecedent, init=string(i[1].antecedent))
Expand All @@ -98,7 +97,7 @@ function interesting_rules(
end)
end
antecedent = format_float(antecedent)
push!(m_X, (antecedent, consequent, readmetrics(i[1])...))
push!(m_X, (antecedent, consequent, readmetrics(i[1])..., "modal"))
end
else
m_X = nothing
Expand Down
32 changes: 7 additions & 25 deletions test/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,16 @@
N_THREADS=30

# ------------------------------------------------------------------------------------ #
# itadata 2024 #
# itadata2024 #
# ------------------------------------------------------------------------------------ #
# n=1
# session="session_"$n
# tmux new-session -d -s $session
# tmux send-keys -t $session 'julia -i -t '$N_THREADS' ravdess_emotion_2bins.jl ' Enter
# [ -n "${TMUX:-}" ]
n=1
session="session_"$n
tmux new-session -d -s $session
tmux send-keys -t $session 'julia -i -t '$N_THREADS' ravdess_emotion_2bins.jl ' Enter
[ -n "${TMUX:-}" ]

n=2
session="session_"$n
tmux new-session -d -s $session
tmux send-keys -t $session 'julia -i -t '$N_THREADS' ravdess_emotion_8bins.jl ' Enter
[ -n "${TMUX:-}" ]

# n=3
# session="session_"$n
# tmux new-session -d -s $session
# tmux send-keys -t $session 'julia -i -t '$N_THREADS' respiratory_pneumonia.jl ' Enter
# [ -n "${TMUX:-}" ]

# n=5
# session="session_"$n
# tmux new-session -d -s $session
# tmux send-keys -t $session 'julia -i -t '$N_THREADS' respiratory_copd.jl ' Enter
# [ -n "${TMUX:-}" ]

# n=5
# session="session_"$n
# tmux new-session -d -s $session
# tmux send-keys -t $session 'julia -i -t '$N_THREADS' respiratory_bronchiolitis.jl ' Enter
# [ -n "${TMUX:-}" ]
[ -n "${TMUX:-}" ]
34 changes: 18 additions & 16 deletions test/ravdess_emotion_2bins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ using DataFrames, JLD2
using SoleAudio, Random
# using Plots

# TODO
# scrivi un file text con tutti i settaggi usati
# output formattato per latex su un file.tex
# fra gli algoritmi di f0 includi il pagliarini

# -------------------------------------------------------------------------- #
# experiment specific parameters #
# -------------------------------------------------------------------------- #
Expand Down Expand Up @@ -49,6 +44,8 @@ elseif classes == :emo8bins
)
end

jld2_file = string("ravdess_", classes)

# classes will be taken from audio filename, no csv available
classes_func(row) = match(r"^(?:[^-]*-){2}([^-]*)", row.filename)[1]

Expand All @@ -65,19 +62,15 @@ audioparams = let sr = 8000
sdetect_thresholds=(0,0),
sdetect_spread_threshold=0.02,
nfft = 256,
mel_scale = :mel_htk, # :mel_htk, :mel_slaney, :erb, :bark, :semitones, :tuned_semitones
mel_scale = :semitones, # :mel_htk, :mel_slaney, :erb, :bark, :semitones, :tuned_semitones
mel_nbands = 26,
mfcc_ncoeffs = 13,
mel_freqrange = (0, round(Int, sr / 2)),
mel_freqrange = (100, round(Int, sr / 2)),
)
end

# min_length = 11500
# min_samples = 400

# only for debugging
min_length = 11000
min_samples = 500
min_length = 14000
min_samples = 75

features = :catch9
# features = :minmax
Expand All @@ -89,16 +82,22 @@ relative_overlap = 0.05

# partitioning
train_ratio = 0.8
train_seed = 11
train_seed = 1
rng = Random.MersenneTwister(train_seed)
Random.seed!(train_seed)

# -------------------------------------------------------------------------- #
# main #
# -------------------------------------------------------------------------- #
irules = get_interesting_rules(
df = get_df_from_rawaudio(
wav_path=wav_path,
classes_dict=classes_dict,
classes_func=classes_func,
audioparams=audioparams,
)

irules = get_interesting_rules(
df;
featset=featset,
audioparams=audioparams,
min_length=min_length,
Expand All @@ -110,4 +109,7 @@ irules = get_interesting_rules(
rng=rng,
)

jldsave("ravdess_emotion_2bins.jld2", true; irules)
println(irules)

jldsave(jld2_file * ".jld2", true; irules)
@info "Done."
36 changes: 19 additions & 17 deletions test/ravdess_emotion_8bins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ using DataFrames, JLD2
using SoleAudio, Random
# using Plots

# TODO
# scrivi un file text con tutti i settaggi usati
# output formattato per latex su un file.tex
# fra gli algoritmi di f0 includi il pagliarini

# -------------------------------------------------------------------------- #
# experiment specific parameters #
# -------------------------------------------------------------------------- #
Expand Down Expand Up @@ -49,6 +44,8 @@ elseif classes == :emo8bins
)
end

jld2_file = string("ravdess_", classes)

# classes will be taken from audio filename, no csv available
classes_func(row) = match(r"^(?:[^-]*-){2}([^-]*)", row.filename)[1]

Expand All @@ -66,18 +63,14 @@ audioparams = let sr = 8000
sdetect_spread_threshold=0.02,
nfft = 256,
mel_scale = :mel_htk, # :mel_htk, :mel_slaney, :erb, :bark, :semitones, :tuned_semitones
mel_nbands = 26,
mfcc_ncoeffs = 13,
mel_freqrange = (0, round(Int, sr / 2)),
mel_nbands = 20,
mfcc_ncoeffs = 10,
mel_freqrange = (100, round(Int, sr / 2)),
)
end

# min_length = 11500
# min_samples = 400

# only for debugging
min_length = 12000
min_samples = 46
min_length = 11500
min_samples = 50

features = :catch9
# features = :minmax
Expand All @@ -89,16 +82,22 @@ relative_overlap = 0.05

# partitioning
train_ratio = 0.8
train_seed = 11
train_seed = 1
rng = Random.MersenneTwister(train_seed)
Random.seed!(train_seed)

# -------------------------------------------------------------------------- #
# main #
# -------------------------------------------------------------------------- #
irules = get_interesting_rules(
df = get_df_from_rawaudio(
wav_path=wav_path,
classes_dict=classes_dict,
classes_func=classes_func,
audioparams=audioparams,
)

irules = get_interesting_rules(
df;
featset=featset,
audioparams=audioparams,
min_length=min_length,
Expand All @@ -110,4 +109,7 @@ irules = get_interesting_rules(
rng=rng,
)

jldsave("ravdess_emotion_8bins.jld2", true; irules)
println(irules)

jldsave(jld2_file * ".jld2", true; irules)
@info "Done."
Loading

0 comments on commit f320b07

Please sign in to comment.