Beispiel #1
0
                               holdOffTime=holdOFF,
                               fix_init_Q=1,
                               r=1,
                               evalMetrics='F',
                               ignoreUp2=ignoreUp2)

        res_v3_3[
            'Alg'] = 'My Implimentation of FRAUST V3.3 Best simple version'
        pltSummary2(res_v3_3, data, (e_high, e_low))

    if v3_1:
        '''My older version'''
        res_v3_1 = FRAHST_V3_1(data,
                               alpha=alpha,
                               e_low=e_low,
                               e_high=e_high,
                               holdOffTime=holdOFF,
                               fix_init_Q=1,
                               r=1,
                               evalMetrics='F')

        res_v3_1['Alg'] = 'My Implimentation of FRAUST Version 3.1'
        pltSummary2(res_v3_1, data, (e_high, e_low))

    if pedro:
        '''Pedros Version'''
        res_ped = frahst_pedro_original(data,
                                        r=1,
                                        alpha=alpha,
                                        e_low=e_low,
                                        e_high=e_high,
                                        holdOffTime=holdOFF,
Beispiel #2
0
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 05 23:19:11 2011
THIS IS THE VERSION TO RUN ON MAC, NOT WINDOWS
@author: musselle
"""
from numpy import eye, zeros, dot, sqrt, log10, trace, arccos, nan, arange
from numpy.random import rand
from numpy.linalg import qr, eig, norm, solve
from matplotlib.pyplot import plot, figure, title, step
from artSigs import genCosSignals_no_rand, genCosSignals
import scipy.io as sio
from utils import analysis, QRsolveA, pltSummary
from PedrosFrahst import frahst_pedro
from Frahst_v3_1 import FRAHST_V3_1

def FRAHST_V3(data,
              r=1,
              alpha=0.96,
              e_low=0.96,
              e_high=0.98,
              sci=-1,
              fix_init_Q=0,
              holdOffTime=0,
              evalMetrics='F'):
    """
        Fast Rank Adaptive Householder Subspace Tracking Algorithm (FRAHST)  
    
    Version 3.0 - Combines good bits of Pedros version, with my correction of the bugs
    
Beispiel #3
0
                                                        reorthog = False, holdOffTime = h) 
                                        res_sp['Alg'] = 'SPIRIT: alpha = ' + str(a) + \
                                        ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')'
     
#                                        pltSummary2(res_sp, streams, (el, eh))                            
                            
                                        SPIRIT_RawResults.append(res_sp)
                                        
                                        SPIRIT_metricList.append(analysis(res_sp, ground_truths, 300, 
                                                                          epsilon = epsilon, ignoreUpTo = ignore))
                                                                            
                                      
                                    if run_frahst == 1:
                                    
                                        # My version of Frahst 
                                        res_fr = FRAHST_V3_1(streams, alpha=a, e_low=el, e_high=eh, 
                                                         holdOffTime=h, fix_init_Q = 1, r = 1, evalMetrics = 'F') 
                                        res_fr['Alg'] = 'MyFrahst: alpha = ' + str(a) + ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')'
                                    
                                        FRAHST_RawResults.append(res_fr)                                        
                                        
                                        FRAHST_metricList.append(analysis(res_fr, ground_truths, 300, 
                                                                          epsilon = epsilon, ignoreUpTo = ignore))                                    

#                                    pltSummary2(res_fr, streams, (el, eh))

                                        
                                    if run_frahst_pedro == 1:
                                    
                                        # Pedros version of Frahst 
                                        res_frped = frahst_pedro(streams, alpha=a, e_low=el, e_high=eh, 
                                                         holdOffTime=h, r = 1, evalMetrics = 'F') 
Beispiel #4
0
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 05 23:19:11 2011
THIS IS THE VERSION TO RUN ON MAC, NOT WINDOWS
@author: musselle
"""
from numpy import eye, zeros, dot, sqrt, log10, trace, arccos, nan, arange, ones
import numpy as np
from numpy.random import rand
from numpy.linalg import qr, eig, norm, solve
from matplotlib.pyplot import plot, figure, title, step
from artSigs import genCosSignals_no_rand , genCosSignals
import scipy.io as sio
from utils import analysis, QRsolveA, pltSummary2
from PedrosFrahst import frahst_pedro_original
from Frahst_v3_1 import FRAHST_V3_1
from Frahst_v3_3 import FRAHST_V3_3
from Frahst_v3_4 import FRAHST_V3_4
from load_syn_ping_data import load_n_store
from QR_eig_solve import QRsolve_eigV
def FRAHST_V4_0(data, r=1, alpha=0.96, e_low=0.96, e_high=0.98, fix_init_Q = 0, holdOffTime=0, 
                evalMetrics = 'F', static_r = 0, r_upper_bound = None, L = 5, ignoreUp2 = 0):
    """
        Fast Rank Adaptive Householder Subspace Tracking Algorithm (FRAHST)  
    
    Version 4.0 - Now also approximates eigenvalues for the approximated tracked basis for the eignevectors          
                - Approach uses an orthogonal iteration arround X.T 
                - Note, only a good approximation if alpha ~< 1. Used as its the fastest method 
                as X.T b --> b must be solved anyway. 
                - New entries in res
Beispiel #5
0
# -*- coding: utf-8 -*-
"""
Created on Wed May 18 11:23:36 2011
Test SPIRIT and Frahst on Contol Time Series: Cyclic 
@author: - Musselle
"""
from ControlCharts import Tseries
from CUSUM import cusum
import numpy as np
import matplotlib.pyplot as plt
from Frahst_v3_1 import FRAHST_V3_1
from SPIRIT import SPIRIT
from utils import analysis, QRsolveA, pltSummary
#===============================================================================
# Runscript
#===============================================================================
#============
# Initialise
#============
'Create time series string'
series_1 = Tseries(0)
series_2 = Tseries(0)
series_3 = Tseries(0)
series_4 = Tseries(0)
series_5 = Tseries(0)
# S 1
# CYCLIC - Normal - Cyclic
series_1.cyclicEt(100, base=6, noise=0.1, amp=2, period=5, phase=0, \
                    noise_type = 'gauss')
series_1.normalEt(100, base=6, noise=0.00000000000000001, noise_type='gauss')
                     ], 'Time Steps', Title)

#             Have such a big effect?????

#            plot_4x1(streams, data['hidden'], data['orthog_error'],
#                     data['subspace_error'],
#    ['Input Data','Hidden\nVariables',
#            'Orthogonality\nError (dB)','Subspace\nError (dB)'] , 'Time Steps', Title)

        if run_frahst == 1:

            # My version of Frahst
            res_fr = FRAHST_V3_1(streams,
                                 alpha=alpha,
                                 e_low=e_low,
                                 e_high=e_high,
                                 holdOffTime=holdOff,
                                 fix_init_Q=1,
                                 r=1,
                                 evalMetrics='T')
            res_fr['Alg'] = 'My Frahst with alpha = ' + str(
                valA) + ' and e_low = ' + str(valB)

            pltSummary2(res_fr, streams, (e_low, e_high))

            data = res_fr

            Title = 'My Frahst with alpha = ' + str(
                valA) + ' and e_low = ' + str(valB)

            plot_4x1(streams, data['hidden'], data['orthog_error'],
                     data['subspace_error'], [
def singleShiftRerun(parameter_string):

    params = parameter_string.split(', ')

    # Data Sets
    baseLine = 0.0

    num_streams = [int(params[0].split()[-1])]  # n
    SNRs = [int(params[1].split()[-1])]  # snr
    anomaly_lengths = [int(params[2].split()[-1])]  # l
    anomaly_magnitudes = [int(params[3].split()[-1])]  # m

    initial_conditions = 20  # i

    # Algorithm Parameters
    thresholds = params[4].split()[-1].split(',')

    e_highs = [float(thresholds[1][0:-1])]  # eh
    e_lows = [float(thresholds[0][1:])]  # el
    alphas = [float(params[5].split()[-1])]  # a
    holdOffs = [int(params[6].split()[-1])]  # h

    # Algorithm flags
    run_spirit = 0
    run_frahst = 1
    run_frahst_pedro = 0

    #===============================================================================
    # Initialise Data sets
    #========-=======================================================================

    # For Profiling
    start = time.time()

    for n in num_streams:
        for snr in SNRs:
            for l in anomaly_lengths:
                for m in anomaly_magnitudes:
                    A = 0
                    for i in range(initial_conditions):

                        # Seed random number generator
                        np.random.seed(i)

                        # Two ts that have anomalous shift
                        s0 = Tseries(0)
                        s1 = Tseries(0)
                        s0.makeSeries([1, 3, 1], [100, l, 200 - l],
                                      [baseLine, baseLine, baseLine + m],
                                      gradient=float(m) / float(l),
                                      noise_type='none')
                        s1.makeSeries([1, 4, 1], [200, l, 100 - l],
                                      [baseLine, baseLine, baseLine - m],
                                      gradient=float(m) / float(l),
                                      noise_type='none')
                        # The rest of the ts
                        for k in range(2, n):
                            name = 's' + str(k)
                            vars()[name] = Tseries(0)
                            vars()[name].makeSeries([1], [300], [baseLine],
                                                    noise_type='none')

                        # Concat into one matrix
                        S = scipy.c_[s0]
                        for k in range(1, n):
                            S = scipy.c_[S, vars()['s' + str(k)]]

                        # Concatonate to 3d array, timesteps x streams x initial condition
                        if type(A) == int:
                            A = S
                        else:
                            A = np.dstack((A, S))

                    # Calculate the noise
                    Ps = np.sum(A[:, :, 0]**2)
                    Pn = Ps / (10.**(snr / 10.))
                    scale = Pn / (n * 300.)
                    noise = np.random.randn(A.shape[0], A.shape[1],
                                            A.shape[2]) * np.sqrt(scale)
                    A = A + noise

                    #===============================================================================
                    # Ground Truths
                    #===============================================================================
                    #                                 # time step | length
                    ground_truths = np.array([[100, l], [200, l]])

                    #==============================================================================
                    #  Run Algorithm
                    #==============================================================================
                    alg_count = 1

                    for eh in e_highs:
                        for el in e_lows:
                            for a in alphas:
                                for h in holdOffs:

                                    print 'Running Algorithm(s) with:\nE_Thresh = (' + str(el) + ',' + str(eh) + ')\n' + \
                                    'alpha = ' + str(a) + '\nHoldOff = ' + str(h)

                                    SPIRIT_metricList = []
                                    FRAHST_metricList = []
                                    PEDRO_FRAHST_metricList = []

                                    for i in range(initial_conditions):

                                        # Load Data
                                        streams = A[:, :, i]

                                        if run_spirit == 1:
                                            # SPIRIT
                                            res_sp = SPIRIT(streams,
                                                            a, [el, eh],
                                                            evalMetrics='F',
                                                            reorthog=False,
                                                            holdOffTime=h)
                                            res_sp['Alg'] = 'SPIRIT: alpha = ' + str(a) + \
                                            ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')'

                                            pltSummary2(
                                                res_sp, streams, (el, eh))

                                            SPIRIT_metricList.append(
                                                analysis(
                                                    res_sp, ground_truths,
                                                    300))

    #                                        data = res_sp
    #                                        Title = 'SPIRIT alpha = ' + str(a) + ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')'
    #
    #                                    plot_4x1(streams, data['hidden'], data['e_ratio'], data['orthog_error'],
    #                                             ['Input Data','Hidden\nVariables',
    #                                    'Energy Ratio', 'Orthogonality\nError (dB)'] , 'Time Steps', Title)

    #                                        plot_4x1(streams, data['hidden'], data['orthog_error'], data['subspace_error'],
    #                                ['Input Data','Hidden\nVariables', 'Orthogonality\nError (dB)','Subspace\nError (dB)'],
    #                                                                 'Time Steps', Title)
    #
                                        if run_frahst == 1:

                                            # My version of Frahst
                                            res_fr = FRAHST_V3_1(
                                                streams,
                                                alpha=a,
                                                e_low=el,
                                                e_high=eh,
                                                holdOffTime=h,
                                                fix_init_Q=1,
                                                r=1,
                                                evalMetrics='F')
                                            res_fr[
                                                'Alg'] = 'MyFrahst: alpha = ' + str(
                                                    a
                                                ) + ' ,E_Thresh = (' + str(
                                                    el) + ',' + str(eh) + ')'

                                            FRAHST_metricList.append(
                                                analysis(
                                                    res_fr, ground_truths,
                                                    300))

                                            pltSummary2(
                                                res_fr, streams, (el, eh))
    #
    #                                        data = res_fr
    #                                        Title = 'My Frahst with alpha = ' + str(a) + ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')'
    #                                        plot_4x1(streams, data['hidden'], data['orthog_error'], data['subspace_error'],
    #                                                 ['Input Data','Hidden\nVariables', 'Orthogonality\nError (dB)','Subspace\nError (dB)'],
    #                                                                 'Time Steps', Title)

                                        if run_frahst_pedro == 1:

                                            # Pedros version of Frahst
                                            res_frped = frahst_pedro(
                                                streams,
                                                alpha=a,
                                                e_low=el,
                                                e_high=eh,
                                                holdOffTime=h,
                                                r=1,
                                                evalMetrics='F')
                                            res_frped['Alg'] = 'Pedros Frahst: alpha = ' + str(a) +  \
                                            ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')'

                                            PEDRO_FRAHST_metricList.append(
                                                analysis(
                                                    res_frped, ground_truths,
                                                    300))

                                            pltSummary2(
                                                res_frped, streams, (el, eh))
    #
    #                                        data = res_frped
    #                                        Title = 'Pedros Frahst: alpha = ' + str(a) +  \
    #                                        ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')'
    #
    #                                        plot_4x1(streams, data['hidden'], data['orthog_error'], data['subspace_error'],
    #                                                 ['Input Data','Hidden\nVariables', 'Orthogonality\nError (dB)','Subspace\nError (dB)'],
    #                                                                 'Time Steps', Title)

    finish = time.time() - start
    print 'Runtime = ' + str(finish) + 'seconds\n'
    print 'In H:M:S = ' + GetInHMS(finish)
Beispiel #8
0
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 05 23:19:11 2011
THIS IS THE VERSION TO RUN ON MAC, NOT WINDOWS
@author: musselle
"""
from numpy import eye, zeros, dot, sqrt, log10, trace, arccos, nan, arange, ones
import numpy as np
import scipy as sp
import numpy.random as npr
from numpy.linalg import qr, eig, norm, solve
from matplotlib.pyplot import plot, figure, title, step, ylim
from artSigs import genCosSignals_no_rand , genCosSignals
import scipy.io as sio
from utils import analysis, QRsolveA, pltSummary2
from PedrosFrahst import frahst_pedro_original
from Frahst_v3_1 import FRAHST_V3_1
from Frahst_v3_3 import FRAHST_V3_3
from Frahst_v3_4 import FRAHST_V3_4
from Frahst_v4_0 import FRAHST_V4_0
from load_syn_ping_data import load_n_store
from QR_eig_solve import QRsolve_eigV
from create_Abilene_links_data import create_abilene_links_data
from MAfunctions import MA_over_window
def FRAHST_V6_2(data, r=1, alpha=0.96, EW_mean_alpha = 0.1, EWMA_filter_alpha = 0.3, 
                residual_thresh = 0.1, epsilon = 0.05,
                e_low = 0.96, e_high = 0.98, fix_init_Q = 0, holdOffTime=0, 
                evalMetrics = 'F', static_r = 0, r_upper_bound = None, L = 5, ignoreUp2 = 0,
                data_norm_window = 50):
    """
Beispiel #9
0
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 05 23:19:11 2011
THIS IS THE VERSION TO RUN ON MAC, NOT WINDOWS
@author: musselle
"""
from numpy import eye, zeros, dot, sqrt, log10, trace, arccos, nan, arange
import numpy as np
import numpy.random as npr
import scipy as sp
from numpy.random import rand
from numpy.linalg import qr, eig, norm, solve
from matplotlib.pyplot import plot, figure, title, step
from artSigs import genCosSignals_no_rand, genCosSignals
import scipy.io as sio
from utils import analysis, QRsolveA, pltSummary2
from PedrosFrahst import frahst_pedro_original
from Frahst_v3_1 import FRAHST_V3_1
from load_syn_ping_data import load_n_store

def FRAHST_V3_3(data,
                r=1,
                alpha=0.96,
                e_low=0.96,
                e_high=0.98,
                fix_init_Q=0,
                holdOffTime=0,
                evalMetrics='F',
                static_r=0,
                r_upper_bound=None,
Beispiel #10
0
                        e_high = param['e_high'],
                        holdOffTime=param['holdOffTime'],
                        fix_init_Q = 1, 
                        sci = -1,
                        evalMetrics = 'F') 

    res_me3['Alg'] = 'My First Implimentation of FRAUST sci = -1'
    
    pltSummary(res_me3, data)
    
    # My second version
    
    res_me2 = FRAHST_V3_1(data, r = 1,
                        alpha = param['alpha'], 
                        e_low = param['e_low'], 
                        e_high = param['e_high'],
                        holdOffTime=param['holdOffTime'],
                        fix_init_Q = 1, 
                        evalMetrics = 'F')   
    
    res_me2['Alg'] = 'My Second Implimentation of FRAUST'
    
    pltSummary(res_me2, data)
    
    # Pedros Version
    res_ped = frahst_pedro(data, r = 1,
                            alpha = param['alpha'],
                            energy_low = param['e_low'],
                            energy_high = param['e_high'],
                            holdOffTime=param['holdOffTime'],
                            evaluateTruth='FALSE')