aiops/AnomalyDetection/datas/GenerateSyncData.py [5:112]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def generateSin(start,end,num,amplitude,frequency,phase,biase):
    time = np.linspace(start, end, num)
    sin_wave = amplitude * np.sin(2 * np.pi * frequency * time + phase)+biase
    return sin_wave

def generateSin2(start,end,num,amplitude,frequencys,phase,biase):
    num*=10
    sin_waves=[]
    step = 100
    time = np.linspace(start, end, num)
    for i in range(0,num,step):
        frequency=np.random.uniform(frequencys[1],frequencys[2])
        ntime=np.linspace(time[i],time[i+step-1],math.ceil(step*frequencys[0]/frequency))
        sin_wave = amplitude * np.sin(2 * np.pi * frequencys[0] * ntime + phase)+biase
        sin_waves.append(sin_wave)
    sin_waves=np.concatenate(sin_waves,axis=0)
    return sin_waves


def syntheticData2(clusterNum,length,fealen,noise=False):
    datas = []
    componsitionNum=2
    for i in range(clusterNum):
        waves = []
        for j in range(fealen):
            frequency = random.randint(6, 10)  # 1/24+random.gauss(0,0.005)#random.randint(6,10)
            amplitude = random.random() * 10
            bias = random.randint(1, 10)
            phase = random.gauss(0, 1) * 2 * math.pi
            wave = generateSin(0, length, length, amplitude, random.uniform(1/100,1/200), phase, bias) + amplitude
            for k in range(componsitionNum):
                wave+=generateSin(0,length,length,amplitude*0.2,1/24,phase*random.random(),bias)
            # frequency=1/40+random.gauss(0,0.005)#random.randint(6,10)
            # wave2=generateSin(0,length,length,amplitude,frequency,phase,bias)+amplitude
            # wave=wave1+wave2
            if noise:
                wave += np.random.normal(0, amplitude * 0.03, length)
            waves.append(wave)
        datas.append(waves)
    datas = np.array(datas)  # batch,fealen,winlen
    dataSum = datas.sum(axis=-2)  # batch,winlen
    datas = datas.transpose((1, 0, 2))  # fealen,batch,winlen
    datas /= dataSum
    datas = datas.transpose((1, 2, 0))
    labels = np.zeros((datas.shape[0], datas.shape[1]))
    return datas, labels

def syntheticData(clusterNum,length,fealen,noise=False,std=0.06):
    datas=[]
    for i in range(clusterNum):
        waves=[]
        for j in range(fealen):
            frequency=random.randint(6,10)#1/24+random.gauss(0,0.005)#random.randint(6,10)
            amplitude=random.random()*10
            bias=random.randint(1,10)
            phase=random.gauss(0,1)*2*math.pi
            wave=generateSin(0,length,length,amplitude,frequency,phase,bias)+amplitude
            #frequency=1/40+random.gauss(0,0.005)#random.randint(6,10)
            #wave2=generateSin(0,length,length,amplitude,frequency,phase,bias)+amplitude
            #wave=wave1+wave2
            if noise:
                wave+=np.random.normal(0,amplitude*std,length)
            waves.append(wave)
        datas.append(waves)
    datas=np.array(datas)#batch,fealen,winlen
    dataSum = datas.sum(axis=-2)#batch,winlen
    datas = datas.transpose((1, 0, 2))  # fealen,batch,winlen
    datas/=dataSum
    datas=datas.transpose((1,2,0))
    labels=np.zeros((datas.shape[0],datas.shape[1]))
    return datas,labels


def syntheticData3(clusterNum,length,fealen,noise=False,frequencyRatio=0.3):
    datas=[]
    for i in range(clusterNum):
        waves=[]
        for j in range(fealen):
            frequency=random.uniform(0.04,0.1)#1/24+random.gauss(0,0.005)#random.randint(6,10)
            frequencys=[frequency,frequency,frequency*(1+frequencyRatio)]
            amplitude=random.random()*10
            bias=random.randint(1,10)
            phase=random.gauss(0,1)*2*math.pi
            wave=generateSin2(0,length,length,amplitude,frequencys,phase,bias)+amplitude
            wave=wave[:length]
            frequency = random.uniform(0.08, 0.1)  # 1/24+random.gauss(0,0.005)#random.randint(6,10)
            frequencys = [frequency, frequency, frequency * (1 + frequencyRatio)]
            amplitude = random.random() * 10
            wave+=(generateSin2(0,length,length,amplitude,frequencys,phase,bias)+amplitude)[:length]
            frequency = random.uniform(0.01, 0.04)  # 1/24+random.gauss(0,0.005)#random.randint(6,10)
            frequencys = [frequency, frequency, frequency * (1 + frequencyRatio)]
            amplitude = random.random() * 10
            wave+=(generateSin2(0,length,length,amplitude,frequencys,phase,bias)+amplitude)[:length]
            #wave=generateSin(0,length,length,amplitude,frequency,phase,bias)+amplitude
            #frequency=1/40+random.gauss(0,0.005)#random.randint(6,10)
            #wave2=generateSin(0,length,length,amplitude,frequency,phase,bias)+amplitude
            #wave=wave1+wave2
            if noise:
                wave+=np.random.normal(0,amplitude*0.06,length)
            waves.append(wave)
        datas.append(waves)
    datas=np.array(datas)#batch,fealen,winlen
    dataSum = datas.sum(axis=-2)#batch,winlen
    datas = datas.transpose((1, 0, 2))  # fealen,batch,winlen
    datas/=dataSum
    datas=datas.transpose((1,2,0))
    labels=np.zeros((datas.shape[0],datas.shape[1]))
    return datas,labels
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



