You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
3.3 KiB

import numpy as np
import time
from AANN_Fit import AANN_Fit
import itertools
from AANN_Derivative import AANN_Derivative
def AANN_RB(fault_sample, fault_magnitude,model):
"""
:param fault_sample:
:param fault_magnitude:
:param model:
:return:
"""
[m, n] = fault_sample.shape
v1 = model.v1
v2 = model.v2
w1 = model.w1
w2 = model.w2
sigma = model.sigma
isolated = np.zeros((m, n))
detected = 0
rod_n = 0
mdata = (2*fault_sample-np.tile(model.maxdata, (m, 1))-np.tile(model.mindata, (m, 1)))/(np.tile(model.maxdata, (m, 1))-np.tile(model.mindata, (m, 1)))
# 数据正则化
mdata1 = (2 * (fault_sample-fault_magnitude) - np.tile(model.maxdata, (m, 1)) - np.tile(model.mindata, (m, 1))) / (
np.tile(model.maxdata, (m, 1)) - np.tile(model.mindata, (m, 1)))
# mdata = mdata/np.tile(pow(np.sum(pow(mdata1, 2), axis=1), 1/2), (n, 1)).T
time1 = time.time()*1000
index = np.zeros(m)
index2 = np.zeros(m)
index_v = np.zeros((m, n))
nodenum_record = np.zeros(m)
for sample_id in range(m):
output = AANN_Fit(mdata[sample_id, :], v1, v2, w1, w2)
output2 = AANN_Fit(mdata1[sample_id, :], v1, v2, w1, w2)
index[sample_id] = np.sum((mdata[sample_id, :]-output)*(mdata[sample_id, :]-output))
index2[sample_id] = np.sum((mdata1[sample_id, :] - output2) * (mdata1[sample_id, :] - output2))
index_v[sample_id, :] = (mdata[sample_id, :]-output)*(mdata[sample_id, :]-output)
if index[sample_id] > sigma:
vnum = 1
detected += 1
nodenum = 0
while vnum <= n:
variablecombination = itertools.combinations([i for i in range(n)], vnum)
combi_list =np.array(list(variablecombination))
cur_rbindex = np.zeros(combi_list.shape[0])
vc_id = 0
for v_combination in combi_list:
cur_fault_varibles =v_combination
cur_fault_variables = np.array(cur_fault_variables).astype(np.float64)
cur_rbindex[vc_id], B, C, spe = AANN_Derivative(v1, v2, w1, w2, mdata[sample_id, :], cur_fault_varibles)
nodenum = nodenum+1
vc_id = vc_id+1
min_rbindex, op_vc_id = np.min(cur_rbindex), np.argmin(cur_rbindex)
cur_vc = combi_list[op_vc_id, :]
if min_rbindex < sigma*2:
isolated[sample_id, combi_list[op_vc_id, :]] = 1
break
else:
vnum = vnum+1
nodenum_record[sample_id] = nodenum
maxindex1 = np.argmax(isolated[sample_id, :])
maxindex2 = np.argmax(np.abs(fault_magnitude[sample_id, :]))
if maxindex1 == maxindex2:
rod_n = rod_n+1
time2 = time.time() * 1000
tc = round(time2 - time1)
real_fault = (fault_magnitude > 0).astype('int')
fdr = np.sum(((real_fault - (isolated == 0).astype('int')) == 1).astype('int')) / np.sum(real_fault) * 100
far = np.sum(((real_fault - isolated) == -1).astype('int')) / np.sum((real_fault == 0).astype('int')) * 100
dr = detected / np.sum((np.sum(real_fault, axis=1) > 0).astype('int')) * 100
rod = rod_n / detected * 100
nodes = np.mean(nodenum_record)
return fdr, far, tc, dr, rod