svasta nesto
This commit is contained in:
1
docs/.~lock.ispitni_rezultati.ods#
Normal file
1
docs/.~lock.ispitni_rezultati.ods#
Normal file
@@ -0,0 +1 @@
|
||||
,marockaspark,localhost.localdomain,07.09.2025 00:19,file:///home/marockaspark/.config/libreoffice/4;
|
||||
BIN
docs/EVSYS/Certificate EVSYS smik.pdf
Normal file
BIN
docs/EVSYS/Certificate EVSYS smik.pdf
Normal file
Binary file not shown.
BIN
docs/EVSYS/Certificate EVSYS vlak.pdf
Normal file
BIN
docs/EVSYS/Certificate EVSYS vlak.pdf
Normal file
Binary file not shown.
BIN
docs/EVSYS/S1.pdf
Normal file
BIN
docs/EVSYS/S1.pdf
Normal file
Binary file not shown.
BIN
docs/EVSYS/Vlak PLA.xlsx
Normal file
BIN
docs/EVSYS/Vlak PLA.xlsx
Normal file
Binary file not shown.
19
docs/ispitni_rezultati.csv
Normal file
19
docs/ispitni_rezultati.csv
Normal file
@@ -0,0 +1,19 @@
|
||||
Eksperiment,Orijentacija,Visina sloja,Širina ekstruzije,Postotak ispune,Broj slojeva stijenke,A_ekv [mm^2],A_min [mm^2],A_max,Fm kN],Sigma [Mpa],Sigma’,SNR [dB]
|
||||
1,Orijentacija 1,0.08,0.4,20.00%,2,100,44.493,,0.778,7.78,17.4858966579012,17.8195919397938
|
||||
2,Orijentacija 1,0.08,0.6,55.00%,4,100,87.819,,3.299,32.99,37.5659025951104,30.3676463109069
|
||||
3,Orijentacija 1,0.08,0.8,85.00%,6,100,100,,0.794,7.94,7.94,17.9964100485419
|
||||
4,Orijentacija 1,0.14,0.4,55.00%,6,100,87.6308,,2.792,27.92,31.8609438690506,28.9183082790225
|
||||
5,Orijentacija 1,0.14,0.6,85.00%,2,100,91.5613,,2.468,24.68,26.9546194735112,27.8469031072241
|
||||
6,Orijentacija 1,0.14,0.8,20.00%,4,100,93.9905,,2.871,28.71,30.5456402508764,29.1606638499301
|
||||
7,Orijentacija 1,0.28,0.4,85.00%,4,100,92.7473,,2.423,24.23,26.1247497231725,27.6870682827501
|
||||
8,Orijentacija 1,0.28,0.6,20.00%,6,100,96.3896,,1.891,18.91,19.6182990696092,25.5338305769008
|
||||
9,Orijentacija 1,0.28,0.8,55.00%,2,100,79.2649,,2.431,24.31,30.6693126465813,27.7156991768667
|
||||
10,Orijentacija 2,0.08,0.4,85.00%,4,100,35.669,,3.398,33.98,95.264795761025,30.6244674906605
|
||||
11,Orijentacija 2,0.08,0.6,20.00%,6,100,36.045,,3.218,32.18,89.277292273547,30.1517207952602
|
||||
12,Orijentacija 2,0.08,0.8,55.00%,2,100,26.908,,2.768,27.68,102.869035231158,28.8433217156944
|
||||
13,Orijentacija 2,0.14,0.4,20.00%,6,100,32.415,,2.472,24.72,76.2609902822767,27.8609693283356
|
||||
14,Orijentacija 2,0.14,0.6,55.00%,2,100,24.155,,2.527,25.27,104.616021527634,28.0521048383983
|
||||
15,Orijentacija 2,0.14,0.8,85.00%,4,100,42.804,,3.647,36.47,85.2023175404168,31.2387152662756
|
||||
16,Orijentacija 2,0.28,0.4,55.00%,4,100,26.909,,2.491,24.91,92.5712586866848,27.9274745507301
|
||||
17,Orijentacija 2,0.28,0.6,85.00%,6,100,44.555,,4.111,41.11,92.2679833913141,32.278949535607
|
||||
18,Orijentacija 2,0.28,0.8,20.00%,2,100,15.895,,2.263,22.63,142.371815036175,27.0936910790946
|
||||
|
BIN
docs/ispitni_rezultati.ods
Normal file
BIN
docs/ispitni_rezultati.ods
Normal file
Binary file not shown.
19
docs/obrada/ispitni_rezultati.csv
Normal file
19
docs/obrada/ispitni_rezultati.csv
Normal file
@@ -0,0 +1,19 @@
|
||||
Eksperiment,Orijentacija,Visina sloja,Širina ekstruzije,Postotak ispune,Broj slojeva stijenke,A_ekv [mm^2],Fm kN],Sigma [Mpa],SNR [dB]
|
||||
1,Orijentacija 1,0.08,0.4 mm,20.00%,2,100,0.778,7.78,17.8195919397938
|
||||
2,Orijentacija 1,0.08,0.6 mm,55.00%,4,100,3.299,32.99,30.3676463109069
|
||||
3,Orijentacija 1,0.08,0.8 mm,85.00%,6,100,0.794,7.94,17.9964100485419
|
||||
4,Orijentacija 1,0.14,0.4 mm,55.00%,6,100,2.792,27.92,28.9183082790225
|
||||
5,Orijentacija 1,0.14,0.6 mm,85.00%,2,100,2.468,24.68,27.8469031072241
|
||||
6,Orijentacija 1,0.14,0.8 mm,20.00%,4,100,2.871,28.71,29.1606638499301
|
||||
7,Orijentacija 1,0.28,0.4 mm,85.00%,4,100,2.423,24.23,27.6870682827501
|
||||
8,Orijentacija 1,0.28,0.6 mm,20.00%,6,100,1.891,18.91,25.5338305769008
|
||||
9,Orijentacija 1,0.28,0.8 mm,55.00%,2,100,2.431,24.31,27.7156991768667
|
||||
10,Orijentacija 2,0.08,0.4 mm,85.00%,4,100,3.398,33.98,30.6244674906605
|
||||
11,Orijentacija 2,0.08,0.6 mm,20.00%,6,100,3.218,32.18,30.1517207952602
|
||||
12,Orijentacija 2,0.08,0.8 mm,55.00%,2,100,2.768,27.68,28.8433217156944
|
||||
13,Orijentacija 2,0.14,0.4 mm,20.00%,6,100,2.472,24.72,27.8609693283356
|
||||
14,Orijentacija 2,0.14,0.6 mm,55.00%,2,100,2.527,25.27,28.0521048383983
|
||||
15,Orijentacija 2,0.14,0.8 mm,85.00%,4,100,3.647,36.47,31.2387152662756
|
||||
16,Orijentacija 2,0.28,0.4 mm,55.00%,4,100,2.491,24.91,27.9274745507301
|
||||
17,Orijentacija 2,0.28,0.6 mm,85.00%,6,100,4.111,41.11,32.278949535607
|
||||
18,Orijentacija 2,0.28,0.8 mm,20.00%,2,100,2.263,22.63,27.0936910790946
|
||||
|
19
docs/obrada/ispitni_rezultati_taguchi_out/0_raw_with_SNR.csv
Normal file
19
docs/obrada/ispitni_rezultati_taguchi_out/0_raw_with_SNR.csv
Normal file
@@ -0,0 +1,19 @@
|
||||
Eksperiment,Orijentacija,Visina sloja [mm],Širina ekstruzije [mm],Postotak ispune [%],Broj stijenki,A_ekv [mm^2],Fm kN],Sigma [Mpa],SNR [dB],SNR_LB [dB]
|
||||
1,Orijentacija 1,0.08,0.4,20.0,2.0,100.0,0.778,7.78,17.8195919397938,17.81959193979378
|
||||
2,Orijentacija 1,0.08,0.6,55.0,4.0,100.0,3.299,32.99,30.3676463109069,30.367646310906878
|
||||
3,Orijentacija 1,0.08,0.8,85.0,6.0,100.0,0.794,7.94,17.9964100485419,17.996410048541925
|
||||
4,Orijentacija 1,0.14,0.4,55.0,6.0,100.0,2.792,27.92,28.9183082790225,28.91830827902247
|
||||
5,Orijentacija 1,0.14,0.6,85.0,2.0,100.0,2.468,24.68,27.8469031072241,27.84690310722408
|
||||
6,Orijentacija 1,0.14,0.8,20.0,4.0,100.0,2.871,28.71,29.1606638499301,29.16066384993012
|
||||
7,Orijentacija 1,0.28,0.4,85.0,4.0,100.0,2.423,24.23,27.6870682827501,27.687068282750126
|
||||
8,Orijentacija 1,0.28,0.6,20.0,6.0,100.0,1.891,18.91,25.5338305769008,25.533830576900797
|
||||
9,Orijentacija 1,0.28,0.8,55.0,2.0,100.0,2.431,24.31,27.7156991768667,27.715699176866714
|
||||
10,Orijentacija 2,0.08,0.4,85.0,4.0,100.0,3.398,33.98,30.6244674906605,30.624467490660535
|
||||
11,Orijentacija 2,0.08,0.6,20.0,6.0,100.0,3.218,32.18,30.1517207952602,30.151720795260214
|
||||
12,Orijentacija 2,0.08,0.8,55.0,2.0,100.0,2.768,27.68,28.8433217156944,28.843321715694405
|
||||
13,Orijentacija 2,0.14,0.4,20.0,6.0,100.0,2.472,24.72,27.8609693283356,27.860969328335564
|
||||
14,Orijentacija 2,0.14,0.6,55.0,2.0,100.0,2.527,25.27,28.0521048383983,28.052104838398293
|
||||
15,Orijentacija 2,0.14,0.8,85.0,4.0,100.0,3.647,36.47,31.2387152662756,31.238715266275626
|
||||
16,Orijentacija 2,0.28,0.4,55.0,4.0,100.0,2.491,24.91,27.9274745507301,27.92747455073013
|
||||
17,Orijentacija 2,0.28,0.6,85.0,6.0,100.0,4.111,41.11,32.278949535607,32.27894953560699
|
||||
18,Orijentacija 2,0.28,0.8,20.0,2.0,100.0,2.263,22.63,27.0936910790946,27.09369107909457
|
||||
|
@@ -0,0 +1,15 @@
|
||||
Orijentacija,Sigma [Mpa],Delta (max-min),Faktor,Visina sloja [mm],Širina ekstruzije [mm],Postotak ispune [%],Broj stijenki
|
||||
Orijentacija 1,21.941111111111113,7.94222222222222,Orijentacija,,,,
|
||||
Orijentacija 2,29.883333333333333,7.94222222222222,Orijentacija,,,,
|
||||
,23.758333333333336,4.203333333333326,Visina sloja [mm],0.08,,,
|
||||
,27.961666666666662,4.203333333333326,Visina sloja [mm],0.14,,,
|
||||
,26.016666666666666,4.203333333333326,Visina sloja [mm],0.28,,,
|
||||
,23.923333333333332,5.266666666666666,Širina ekstruzije [mm],,0.4,,
|
||||
,29.189999999999998,5.266666666666666,Širina ekstruzije [mm],,0.6,,
|
||||
,24.623333333333335,5.266666666666666,Širina ekstruzije [mm],,0.8,,
|
||||
,22.488333333333333,5.579999999999998,Postotak ispune [%],,,20.0,
|
||||
,27.180000000000003,5.579999999999998,Postotak ispune [%],,,55.0,
|
||||
,28.06833333333333,5.579999999999998,Postotak ispune [%],,,85.0,
|
||||
,22.058333333333334,8.156666666666666,Broj stijenki,,,,2.0
|
||||
,30.215,8.156666666666666,Broj stijenki,,,,4.0
|
||||
,25.463333333333335,8.156666666666666,Broj stijenki,,,,6.0
|
||||
|
@@ -0,0 +1,15 @@
|
||||
Orijentacija,SNR_LB [dB],Delta (max-min),Faktor,Visina sloja [mm],Širina ekstruzije [mm],Postotak ispune [%],Broj stijenki
|
||||
Orijentacija 1,25.894013507992987,3.4472547809021563,Orijentacija,,,,
|
||||
Orijentacija 2,29.341268288895144,3.4472547809021563,Orijentacija,,,,
|
||||
,25.967193050142956,2.879084394721403,Visina sloja [mm],0.08,,,
|
||||
,28.84627744486436,2.879084394721403,Visina sloja [mm],0.14,,,
|
||||
,28.039452200324888,2.879084394721403,Visina sloja [mm],0.28,,,
|
||||
,26.806313311882104,2.232212548834106,Širina ekstruzije [mm],,0.4,,
|
||||
,29.03852586071621,2.232212548834106,Širina ekstruzije [mm],,0.6,,
|
||||
,27.008083522733894,2.232212548834106,Širina ekstruzije [mm],,0.8,,
|
||||
,26.270077928219177,2.3673478837173043,Postotak ispune [%],,,20.0,
|
||||
,28.63742581193648,2.3673478837173043,Postotak ispune [%],,,55.0,
|
||||
,27.945418955176546,2.3673478837173043,Postotak ispune [%],,,85.0,
|
||||
,26.22855197617864,3.272453982363597,Broj stijenki,,,,2.0
|
||||
,29.501005958542237,3.272453982363597,Broj stijenki,,,,4.0
|
||||
,27.123364760611327,3.272453982363597,Broj stijenki,,,,6.0
|
||||
|
@@ -0,0 +1,6 @@
|
||||
Faktor,Rang delta (Sigma),Rang delta (SNR)
|
||||
Broj stijenki,8.156666666666666,3.272453982363597
|
||||
Orijentacija,7.94222222222222,3.4472547809021563
|
||||
Postotak ispune [%],5.579999999999998,2.3673478837173043
|
||||
Širina ekstruzije [mm],5.266666666666666,2.232212548834106
|
||||
Visina sloja [mm],4.203333333333326,2.879084394721403
|
||||
|
@@ -0,0 +1,6 @@
|
||||
Faktor,Optimalna razina (po S/N)
|
||||
Orijentacija,Orijentacija 2
|
||||
Visina sloja [mm],0.14
|
||||
Širina ekstruzije [mm],0.6
|
||||
Postotak ispune [%],55.0
|
||||
Broj stijenki,4.0
|
||||
|
@@ -0,0 +1,5 @@
|
||||
Predikcija,Vrijednost
|
||||
Sigma_opt [MPa],40.781111111111116
|
||||
SNR_opt [dB],34.893939771178154
|
||||
Grand mean Sigma [MPa],25.912222222222223
|
||||
Grand mean SNR [dB],27.61764089844407
|
||||
|
@@ -0,0 +1,7 @@
|
||||
Factor,SS,DOF,MS,Pct_contrib_%
|
||||
Orijentacija,283.8550222222221,1,283.8550222222221,23.01723952764538
|
||||
Visina sloja [mm],53.10221111111093,2,26.551105555555466,4.305952746663593
|
||||
Širina ekstruzije [mm],98.16444444444437,2,49.082222222222185,7.959959676553248
|
||||
Postotak ispune [%],107.87454444444445,2,53.93727222222223,8.747332384591576
|
||||
Broj stijenki,201.40714444444444,2,100.70357222222222,16.33170500195548
|
||||
Error,488.8245444444449,8,61.10306805555561,39.63781066259073
|
||||
|
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 52 KiB |
19
docs/obrada/ispitni_rezultati_taguchi_out/summary.json
Normal file
19
docs/obrada/ispitni_rezultati_taguchi_out/summary.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"outdir": "ispitni_rezultati_taguchi_out",
|
||||
"factors": [
|
||||
"Orijentacija",
|
||||
"Visina sloja [mm]",
|
||||
"Širina ekstruzije [mm]",
|
||||
"Postotak ispune [%]",
|
||||
"Broj stijenki"
|
||||
],
|
||||
"opt_levels": {
|
||||
"Orijentacija": "Orijentacija 2",
|
||||
"Visina sloja [mm]": 0.14,
|
||||
"Širina ekstruzije [mm]": 0.6,
|
||||
"Postotak ispune [%]": 55.0,
|
||||
"Broj stijenki": 4.0
|
||||
},
|
||||
"pred_sigma": 40.781111111111116,
|
||||
"grand_mean_sigma": 25.912222222222223
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
% --- Taguchi rezultati (S = Sigma [MPa], S/N larger-the-better) ---
|
||||
|
||||
\subsection{Rezultati Taguchijeve metode}
|
||||
|
||||
U skladu s ortogonalnom matricom provedena je analiza s kriterijem \textbf{što-veće-to-bolje}. Za svaku kombinaciju izračunat je S/N omjer \((\mathrm{S/N}=20\log_{10}(\sigma))\) te su određeni glavni učinci po razinama i optimalna kombinacija.
|
||||
|
||||
\paragraph{Optimalne razine (po S/N).}
|
||||
|
||||
\begin{tabular}{ll}
|
||||
\toprule
|
||||
Faktor & Optimalna razina (po S/N) \\
|
||||
\midrule
|
||||
Orijentacija & Orijentacija 2 \\
|
||||
Visina sloja [mm] & 0.140000 \\
|
||||
Širina ekstruzije [mm] & 0.600000 \\
|
||||
Postotak ispune [%] & 55.000000 \\
|
||||
Broj stijenki & 4.000000 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
|
||||
|
||||
\paragraph{Predikcija odziva na optimalnoj kombinaciji.}
|
||||
|
||||
\begin{tabular}{lr}
|
||||
\toprule
|
||||
Predikcija & Vrijednost \\
|
||||
\midrule
|
||||
Sigma_opt [MPa] & 40.78 \\
|
||||
SNR_opt [dB] & 34.89 \\
|
||||
Grand mean Sigma [MPa] & 25.91 \\
|
||||
Grand mean SNR [dB] & 27.62 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
|
||||
|
||||
\paragraph{Rang utjecaja faktora.}
|
||||
|
||||
\begin{tabular}{lrr}
|
||||
\toprule
|
||||
Faktor & Rang delta (Sigma) & Rang delta (SNR) \\
|
||||
\midrule
|
||||
Broj stijenki & 8.157 & 3.272 \\
|
||||
Orijentacija & 7.942 & 3.447 \\
|
||||
Postotak ispune [%] & 5.580 & 2.367 \\
|
||||
Širina ekstruzije [mm] & 5.267 & 2.232 \\
|
||||
Visina sloja [mm] & 4.203 & 2.879 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
|
||||
|
||||
\paragraph{ANOVA (Taguchi).}
|
||||
|
||||
\begin{tabular}{lrrrr}
|
||||
\toprule
|
||||
Factor & SS & DOF & MS & Pct_contrib_% \\
|
||||
\midrule
|
||||
Orijentacija & 283.855000 & 1 & 283.855000 & 23.017000 \\
|
||||
Visina sloja [mm] & 53.102000 & 2 & 26.551000 & 4.306000 \\
|
||||
Širina ekstruzije [mm] & 98.164000 & 2 & 49.082000 & 7.960000 \\
|
||||
Postotak ispune [%] & 107.875000 & 2 & 53.937000 & 8.747000 \\
|
||||
Broj stijenki & 201.407000 & 2 & 100.704000 & 16.332000 \\
|
||||
Error & 488.825000 & 8 & 61.103000 & 39.638000 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
|
||||
|
||||
Napomena: budući da je \(n{=}1\), pogreška (Error) procijenjena je iz preostalih stupnjeva slobode (Taguchi pooling).
|
||||
229
docs/obrada/obrada.py
Normal file
229
docs/obrada/obrada.py
Normal file
@@ -0,0 +1,229 @@
|
||||
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Taguchi analysis pipeline for FDM experiment (per user's thesis)
|
||||
- Reads a CSV with columns similar to:
|
||||
'Eksperiment','Orijentacija','Visina sloja','Širina ekstruzije','Postotak ispune',
|
||||
'Broj slojeva stijenke','A_ekv [mm^2]','Fm kN]','Sigma [Mpa]','SNR [dB]'
|
||||
- Cleans units to numeric, recomputes Sigma (optional) and SNR (LB, n=1),
|
||||
- Builds response tables (means, Δ), ranks factors, selects optimal levels by SNR,
|
||||
- Predicts response at optimal combination (additive model),
|
||||
- Runs Taguchi-style ANOVA on Sigma,
|
||||
- Saves CSV outputs + main-effects plots + LaTeX snippet.
|
||||
Usage:
|
||||
python taguchi_from_csv.py --input ispitni_rezultati.csv --outdir out_tlak
|
||||
"""
|
||||
import argparse, os, re, json
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def norm_num(x):
|
||||
if pd.isna(x):
|
||||
return np.nan
|
||||
if isinstance(x, (int, float, np.number)):
|
||||
return float(x)
|
||||
s = str(x).strip()
|
||||
s = s.replace(',', '.')
|
||||
s = s.replace('%','')
|
||||
s = s.replace(' mm','')
|
||||
s = s.replace('MPa','').replace('Mpa','')
|
||||
s = s.replace('kN','').replace('kN]','').replace('[','').replace(']','')
|
||||
try:
|
||||
return float(s)
|
||||
except:
|
||||
return np.nan
|
||||
|
||||
def compute_snr_lb(y):
|
||||
# larger-the-better; handles n=1 case
|
||||
y = pd.to_numeric(y, errors='coerce')
|
||||
return 20.0*np.log10(y.clip(lower=1e-12))
|
||||
|
||||
def response_table(df, factor, col):
|
||||
t = df.groupby(factor, as_index=False)[col].mean()
|
||||
t["Delta (max-min)"] = t[col].max() - t[col].min()
|
||||
t["Faktor"] = factor
|
||||
return t
|
||||
|
||||
def taguchi_anova(df, response, factors):
|
||||
y = df[response].astype(float)
|
||||
mu = y.mean()
|
||||
total_ss = ((y - mu)**2).sum()
|
||||
rows = []
|
||||
dof_used = 0
|
||||
ss_used = 0.0
|
||||
for f in factors:
|
||||
grp = df.groupby(f)[response].agg(['mean','count'])
|
||||
ss_f = (grp['count']*(grp['mean']-mu)**2).sum()
|
||||
dof_f = grp.shape[0]-1
|
||||
rows.append([f, ss_f, dof_f])
|
||||
dof_used += dof_f
|
||||
ss_used += ss_f
|
||||
err_ss = max(total_ss - ss_used, 0.0)
|
||||
err_dof = max(len(df)-1 - dof_used, 0)
|
||||
an = pd.DataFrame(rows, columns=["Factor","SS","DOF"])
|
||||
an["MS"] = an["SS"]/an["DOF"]
|
||||
an["Pct_contrib_%"] = (an["SS"]/total_ss*100.0) if total_ss>0 else np.nan
|
||||
err_row = pd.DataFrame([["Error", err_ss, err_dof, (err_ss/err_dof) if err_dof>0 else np.nan, (err_ss/total_ss*100.0) if total_ss>0 else np.nan]],
|
||||
columns=["Factor","SS","DOF","MS","Pct_contrib_%"])
|
||||
an = pd.concat([an, err_row], ignore_index=True)
|
||||
return an, mu, total_ss
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--input", required=True, help="Path to CSV with results")
|
||||
ap.add_argument("--outdir", default=None, help="Output directory")
|
||||
ap.add_argument("--response", default="Sigma [Mpa]", help="Response column to analyze (default Sigma [Mpa])")
|
||||
ap.add_argument("--area_col", default="A_ekv [mm^2]", help="Area column if Sigma should be recomputed from Fm/Area")
|
||||
ap.add_argument("--fm_col", default="Fm kN]", help="Force column (kN)")
|
||||
ap.add_argument("--recompute_sigma", action="store_true", help="If set, recompute Sigma = Fm*1000/Area")
|
||||
ap.add_argument("--sn_type", default="LB", choices=["LB"], help="S/N type (only LB supported here)")
|
||||
args = ap.parse_args()
|
||||
|
||||
in_path = args.input
|
||||
outdir = args.outdir or (os.path.splitext(os.path.basename(in_path))[0] + "_taguchi_out")
|
||||
os.makedirs(outdir, exist_ok=True)
|
||||
|
||||
df = pd.read_csv(in_path)
|
||||
|
||||
# Standard column mapping / cleanup for known names
|
||||
rename_map = {
|
||||
"Visina sloja":"Visina sloja [mm]",
|
||||
"Širina ekstruzije":"Širina ekstruzije [mm]",
|
||||
"Postotak ispune":"Postotak ispune [%]",
|
||||
"Broj slojeva stijenke":"Broj stijenki",
|
||||
"Sigma [MPa]":"Sigma [Mpa]",
|
||||
"Fm [kN]":"Fm kN]",
|
||||
}
|
||||
df = df.rename(columns={k:v for k,v in rename_map.items() if k in df.columns})
|
||||
|
||||
# Ensure numeric for relevant columns
|
||||
if "Visina sloja [mm]" in df.columns:
|
||||
df["Visina sloja [mm]"] = df["Visina sloja [mm]"].apply(norm_num)
|
||||
if "Širina ekstruzije [mm]" in df.columns:
|
||||
df["Širina ekstruzije [mm]"] = df["Širina ekstruzije [mm]"].apply(norm_num)
|
||||
if "Postotak ispune [%]" in df.columns:
|
||||
df["Postotak ispune [%]"] = df["Postotak ispune [%]"].apply(norm_num)
|
||||
if "Broj stijenki" in df.columns:
|
||||
df["Broj stijenki"] = df["Broj stijenki"].apply(norm_num)
|
||||
if args.area_col in df.columns:
|
||||
df[args.area_col] = df[args.area_col].apply(norm_num)
|
||||
if args.fm_col in df.columns:
|
||||
df[args.fm_col] = df[args.fm_col].apply(norm_num)
|
||||
if args.response in df.columns:
|
||||
df[args.response] = df[args.response].apply(norm_num)
|
||||
|
||||
# Compute Sigma if asked or missing
|
||||
if args.recompute_sigma or args.response not in df.columns or df[args.response].isna().all():
|
||||
if args.fm_col in df.columns and args.area_col in df.columns:
|
||||
df[args.response] = (df[args.fm_col] * 1000.0) / df[args.area_col]
|
||||
else:
|
||||
raise SystemExit("Cannot recompute Sigma: missing Fm or Area columns")
|
||||
|
||||
# Compute SNR (LB)
|
||||
df["SNR_LB [dB]"] = compute_snr_lb(df[args.response])
|
||||
|
||||
# Save cleaned raw
|
||||
raw_out = os.path.join(outdir, "0_raw_with_SNR.csv")
|
||||
df.to_csv(raw_out, index=False)
|
||||
|
||||
# Factors to analyze (auto detect from known list)
|
||||
candidate_factors = ["Orijentacija","Visina sloja [mm]","Širina ekstruzije [mm]","Postotak ispune [%]","Broj stijenki"]
|
||||
factors = [f for f in candidate_factors if f in df.columns]
|
||||
if len(factors) == 0:
|
||||
raise SystemExit("No known factor columns found. Expected some of: " + ", ".join(candidate_factors))
|
||||
|
||||
# Response tables and deltas
|
||||
resp_mu = pd.concat([response_table(df, f, args.response) for f in factors], ignore_index=True)
|
||||
resp_sn = pd.concat([response_table(df, f, "SNR_LB [dB]") for f in factors], ignore_index=True)
|
||||
resp_mu.to_csv(os.path.join(outdir, "1_response_means_Sigma.csv"), index=False)
|
||||
resp_sn.to_csv(os.path.join(outdir, "2_response_means_SNR.csv"), index=False)
|
||||
|
||||
# Ranking (by Delta)
|
||||
rank_mu = resp_mu.groupby("Faktor")["Delta (max-min)"].max().sort_values(ascending=False).reset_index().rename(columns={"Delta (max-min)":"Rang delta (Sigma)"})
|
||||
rank_sn = resp_sn.groupby("Faktor")["Delta (max-min)"].max().sort_values(ascending=False).reset_index().rename(columns={"Delta (max-min)":"Rang delta (SNR)"})
|
||||
ranking = pd.merge(rank_mu, rank_sn, on="Faktor")
|
||||
ranking.to_csv(os.path.join(outdir, "3_factor_ranking.csv"), index=False)
|
||||
|
||||
# Optimal levels by SNR
|
||||
opt_levels = {f: df.groupby(f)["SNR_LB [dB]"].mean().sort_values(ascending=False).index[0] for f in factors}
|
||||
opt_table = pd.DataFrame({"Faktor": list(opt_levels.keys()), "Optimalna razina (po S/N)": list(opt_levels.values())})
|
||||
opt_table.to_csv(os.path.join(outdir, "4_optimal_levels.csv"), index=False)
|
||||
|
||||
# Prediction at optimal combo (additive model) on response
|
||||
grand_mean = df[args.response].mean()
|
||||
k = len(factors)
|
||||
pred_sigma = sum(df.groupby(f)[args.response].mean().loc[opt_levels[f]] for f in factors) - (k-1)*grand_mean
|
||||
grand_mean_snr = df["SNR_LB [dB]"].mean()
|
||||
pred_snr = sum(df.groupby(f)["SNR_LB [dB]"].mean().loc[opt_levels[f]] for f in factors) - (k-1)*grand_mean_snr
|
||||
pred_df = pd.DataFrame({
|
||||
"Predikcija": ["Sigma_opt [MPa]","SNR_opt [dB]","Grand mean Sigma [MPa]","Grand mean SNR [dB]"],
|
||||
"Vrijednost": [pred_sigma, pred_snr, grand_mean, grand_mean_snr]
|
||||
})
|
||||
pred_df.to_csv(os.path.join(outdir, "5_prediction.csv"), index=False)
|
||||
|
||||
# ANOVA (Taguchi-style) on response
|
||||
anova_df, mu_sigma, totss = taguchi_anova(df, args.response, factors)
|
||||
anova_df.to_csv(os.path.join(outdir, "6_anova_sigma.csv"), index=False)
|
||||
|
||||
# Plots: main effects for SNR
|
||||
for f in factors:
|
||||
means = df.groupby(f)["SNR_LB [dB]"].mean().reset_index()
|
||||
# numeric sort if possible
|
||||
try:
|
||||
means[f] = pd.to_numeric(means[f], errors="ignore")
|
||||
means = means.sort_values(by=f)
|
||||
except:
|
||||
pass
|
||||
plt.figure()
|
||||
plt.plot(means[f], means["SNR_LB [dB]"], marker="o")
|
||||
plt.xlabel(f)
|
||||
plt.ylabel("S/N (LB) [dB]")
|
||||
plt.title(f"Main effect (S/N): {f}")
|
||||
plt.tight_layout()
|
||||
plt.savefig(os.path.join(outdir, f"main_effect_SNR_{f}.png"), dpi=150)
|
||||
plt.close()
|
||||
|
||||
# LaTeX snippet
|
||||
latex_lines = []
|
||||
latex_lines.append(r"% --- Taguchi rezultati (S = Sigma [MPa], S/N larger-the-better) ---")
|
||||
latex_lines.append(r"\subsection{Rezultati Taguchijeve metode}")
|
||||
latex_lines.append(r"U skladu s ortogonalnom matricom provedena je analiza s kriterijem \textbf{što-veće-to-bolje}. Za svaku kombinaciju izračunat je S/N omjer \((\mathrm{S/N}=20\log_{10}(\sigma))\) te su određeni glavni učinci po razinama i optimalna kombinacija.")
|
||||
|
||||
# Optimal levels
|
||||
latex_lines.append(r"\paragraph{Optimalne razine (po S/N).}")
|
||||
latex_lines.append(opt_table.to_latex(index=False, escape=False))
|
||||
# Prediction
|
||||
latex_lines.append(r"\paragraph{Predikcija odziva na optimalnoj kombinaciji.}")
|
||||
latex_lines.append(pred_df.to_latex(index=False, escape=False, float_format='%.2f'))
|
||||
# Ranking
|
||||
latex_lines.append(r"\paragraph{Rang utjecaja faktora.}")
|
||||
latex_lines.append(ranking.to_latex(index=False, escape=False, float_format='%.3f'))
|
||||
# ANOVA
|
||||
an_fmt = anova_df.copy()
|
||||
for c in ["SS","MS","Pct_contrib_%"]:
|
||||
if c in an_fmt.columns:
|
||||
an_fmt[c] = an_fmt[c].astype(float).round(3)
|
||||
latex_lines.append(r"\paragraph{ANOVA (Taguchi).}")
|
||||
latex_lines.append(an_fmt.to_latex(index=False, escape=False))
|
||||
latex_lines.append(r"Napomena: budući da je \(n{=}1\), pogreška (Error) procijenjena je iz preostalih stupnjeva slobode (Taguchi pooling).")
|
||||
|
||||
with open(os.path.join(outdir, "taguchi_results.tex"), "w", encoding="utf-8") as f:
|
||||
f.write("\n\n".join(latex_lines))
|
||||
|
||||
# Small JSON summary
|
||||
summary = {
|
||||
"outdir": outdir,
|
||||
"factors": factors,
|
||||
"opt_levels": opt_levels,
|
||||
"pred_sigma": pred_sigma,
|
||||
"grand_mean_sigma": grand_mean,
|
||||
}
|
||||
with open(os.path.join(outdir, "summary.json"), "w", encoding="utf-8") as f:
|
||||
json.dump(summary, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print("Done. Outputs in:", outdir)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user