Skip to content

Commit b5cd8b5

Browse files
committed
Implemented legacy version for active learning
1 parent f155939 commit b5cd8b5

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

examples/Active_Learning/qbc_svc.py

+19-13
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,20 @@ def hard_test_cases(a, b):
244244
sig = sunit * x1[:, None]
245245
print('Calculated {} yield stresses.'.format(nsamples_init))
246246
# train SVC with yield stress data generated from Hill flow rules
247-
C = 6.0
248-
gamma = 2.0
249-
Fe = 0.5
250-
Ce = 0.99
251-
Nseq = 20
247+
C = 2.0
248+
gamma = 2.5
249+
Ce = 0.95
250+
Fe = 0.1
251+
Nseq = 25
252252
vlevel = 0
253-
cvals = [5., 6., 8.]
254-
gvals = [1., 2., 3.]
253+
cvals = [4, 6, 8, 10] # [4, 6, 8, 10, 12, 15]
254+
gvals = [0.6, 1, 2, 2.5, 3] # [0.6, 0.8, 1, 2, 2.5, 3]
255255

256256
mat_ml = FE.Material(name='ML-Hill') # define material
257-
mat_ml.train_SVC(C=C, gamma=gamma, Fe=Fe, Ce=Ce, Nseq=Nseq, sdata=sig,
258-
gridsearch=True, cvals=[1., 2., 4.], gvals=[0.5, 1., 1.5], verbose=vlevel)
257+
mat_ml.dev_only = True
258+
mat_ml.train_SVC(C=C, gamma=gamma, Fe=Fe, Ce=Ce, Nseq=Nseq, sdata=sig, extend=False,
259+
gridsearch=True, cvals=cvals, gvals=gvals,
260+
al_legacy=True, verbose=vlevel)
259261
plot_yield_locus(mat_ml=mat_ml, mat_h=mat_h, niter=0)
260262
np.savetxt('DATA_sig_iter_0.txt', sig)
261263
np.savetxt('DATA_sunit_iter_0.txt', sunit)
@@ -270,9 +272,11 @@ def hard_test_cases(a, b):
270272
for j in range(nmembers):
271273
idx = np.random.choice(np.arange(sig.shape[0]), int(sig.shape[0] * subset_percentage), replace=False)
272274
mat_ml = FE.Material(name='ML-Hill_{}'.format(j))
275+
mat_ml.dev_only = True
273276
mat_ml.train_SVC(C=C, gamma=gamma, Fe=Fe, Ce=Ce, Nseq=Nseq,
274-
sdata=sig[idx, :],
275-
gridsearch=True, cvals=cvals, gvals=gvals, verbose=vlevel)
277+
sdata=sig[idx, :], extend=False,
278+
gridsearch=True, cvals=cvals, gvals=gvals,
279+
al_legacy=True, verbose=vlevel)
276280
hyp_C_list.append(mat_ml.C_yf)
277281
hyp_g_list.append(mat_ml.gam_yf)
278282
committee.append(mat_ml)
@@ -294,9 +298,11 @@ def hard_test_cases(a, b):
294298
sunit = np.vstack([sunit, sunit_new])
295299

296300
mat_ml = FE.Material(name='ML-Hill') # define material
301+
mat_ml.dev_only = True
297302
mat_ml.train_SVC(C=C, gamma=gamma, Fe=Fe, Ce=Ce, Nseq=Nseq,
298-
sdata=sig,
299-
gridsearch=True, cvals=cvals, gvals=gvals, verbose=vlevel)
303+
sdata=sig, extend=False,
304+
gridsearch=True, cvals=cvals, gvals=gvals,
305+
al_legacy=True, verbose=vlevel)
300306

301307
# Create ML model with conventional training approach
302308
Ntot = nsamples_init + nsamples_to_generate

src/pylabfea/material.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ def train_SVC(self, C=10, gamma=4, Nlc=36, Nseq=25, fs=0.3, extend=False,
13421342
mat_ref=None, sdata=None, plot=False, fontsize=16,
13431343
gridsearch=False, cvals=None, gvals=None, Fe=0.1, Ce=0.99, scaler=None, pca=None,
13441344
train_index=None, test_index=None, verbose=1, metric='acc', pca_dim=10,
1345-
reversal=None):
1345+
reversal=None, al_legacy=False):
13461346
"""Train SVC for all yield functions of the microstructures provided
13471347
in msparam and for flow stresses to capture work hardening. In first
13481348
step, the training data for each set is generated by creating stresses
@@ -1852,7 +1852,8 @@ def test_data_generation(self, C=10, gamma=4, Nlc=36, Nseq=25, fs=0.3, extend=Fa
18521852
return xt, yt
18531853

18541854
def create_sig_data(self, N=None, mat_ref=None, sdata=None, Nseq=2, sflow=None,
1855-
offs=0.01, extend=False, rand=False, Fe=0.1, Ce=0.99):
1855+
offs=0.01, extend=False, rand=False, Fe=0.1, Ce=0.99,
1856+
al_legacy=False):
18561857
"""Function to create consistent data sets on the deviatoric stress plane
18571858
for training or testing of ML yield function. Either the number "N" of raw data points, i.e. load angles, to be
18581859
generated and a reference material "mat_ref" has to be provided, or a list of raw data points "sdata" with
@@ -1945,6 +1946,9 @@ def create_sig_data(self, N=None, mat_ref=None, sdata=None, Nseq=2, sflow=None,
19451946
elastic_seq = np.linspace(Fe, Ce, Nseq)
19461947
plastic_seq = np.linspace(2. - Ce, 2. - Fe, Nseq)
19471948
seq = np.append(elastic_seq, plastic_seq)
1949+
if al_legacy:
1950+
seq = np.linspace(offs, 0.95, Nseq) # old version ???
1951+
seq = np.append(seq, np.linspace(1.05, 2., Nseq))
19481952
if extend:
19491953
# add training points in plastic regime to avoid fallback of SVC decision fct. to zero
19501954
seq = np.append(seq, np.array([2.4, 3., 4., 5.]))

0 commit comments

Comments
 (0)