Пример #1
0
def ConvertLIGOtoLibSVM(patfile, svmfile):
    """
....This module is used to convert LIGO data format into libSVM format data file
...."""

    # samples = ReadLIGOfile([patfile])

    samples = auxmvc_utils.ReadMVSCTriggers([patfile], Classified=False)
    features = list(samples.dtype.names)
    for name in [
            'GPS_s',
            'GPS_ms',
            'signif',
            'SNR',
            'unclean',
            'i',
    ]:
        features.remove(name)
    file = open(svmfile, 'w')

    for s in samples:
        line = ''.join([
            (' ' + str(i + 1) + ':' + str(s[var]) if s[var] != 0 else '')
            for (i, var) in enumerate(features)
        ])
        file.write((('+1' if s['i'] == 1 else '-1')) + line + '\n')

    file.close()
Пример #2
0
def ConvertLibSVMtoLIGO(patfile, rstfile, datfile):
    """
....This module is used to convert SVM predict result file into LIGO data format.
...."""

    # features = open(patfile).readlines()[1].strip('\n')+" SVMrank"
    # samples = ReadLIGOfile([patfile])

    samples = auxmvc_utils.ReadMVSCTriggers([patfile], Classified=False)

    # ranks = np.loadtxt(rstfile, usecols=(0,),skiprows=0)

    ranks = np.loadtxt(rstfile, usecols=(1, ), skiprows=1)
    if not ranks.shape:  # single row loaded, requires array reshaping
        ranks = ranks.reshape((1, ))

    features = list(samples.dtype.names)
    for f in [
            'GPS_s',
            'GPS_ms',
            'i',
            'unclean',
            'signif',
            'SNR',
    ]:
        features.remove(f)
    file = open(datfile, 'w')
    head = [
        'GPS',
        'i',
        'unclean',
        'signif',
        'SNR',
        'rank',
    ] + features
    file.write(' '.join([str(h) for h in head]) + '\n')

    for (j, s) in enumerate(samples):
        GPS = float(s['GPS_s']) + float(s['GPS_ms']) / 1000
        i = float(s['i'])
        prefix = ' '.join(str(s[f]) for f in ['unclean', 'signif', 'SNR'])
        suffix = ' '.join([str(s[f]) for f in features])
        file.write(
            str('%0.3f' % GPS) + ' ' + str(i) + ' ' + prefix + ' ' +
            str(ranks[j]) + ' ' + suffix + '\n')
    file.close()
Пример #3
0
(opts,files)=parser.parse_args()

################ MAIN ##############################


#pat_files=glob.glob(opts.pat_files)
#pat_files = opts.pat_files.split(",")
channel_attributes = opts.normalization_attributes.split(",")
if opts.verbose:
    print "Converting files to ann type:"
    print files
    print "Normalization attributes:"
    print channel_attributes

for pat in files:
    Triggers=auxmvc_utils.ReadMVSCTriggers([pat],Classified=False)
    for attr in channel_attributes:
        if attr == 'dt':
            if opts.transform_dt_function == 'log':
                Triggers = Rescale_attribute2(Triggers,attr,-1.0,1.0)
                Triggers = ApplyLog_dt(Triggers)
                Triggers = Rescale_attribute(Triggers,attr,opts.min,opts.max)
                print "dt log transformation is done."
            else:
                Triggers = Rescale_attribute2(Triggers,attr,opts.min,opts.max)
        else:
            Triggers = Rescale_attribute2(Triggers,attr,opts.min,opts.max)

    file=open(pat.split("/")[-1].replace(".pat",".ann"),"w")
    print "Writing "+pat.split("/")[-1].replace(".pat",".ann")
    variables = list(Triggers.dtype.names)
Пример #4
0
            event.andsegments(
                [dq_segments, [idq.extract_start_stop(pat, suffix=".pat")]]))
    ]

    if opts.verbose:
        print "%d patfiles remain after taking overlap with segments" % len(
            patfiles)

if len(patfiles) == 0:
    print 'No *.pat files found in the gps range ' \
        + str(gps_start_time) + ' - ' + str(gps_end_time)
    print 'Exiting with status 2.'
    sys.exit(2)

# load auxmvc vector samples
auxmvc_samples = auxmvc_utils.ReadMVSCTriggers(patfiles, Classified=False)

if opts.dq_segments:
    # keep only samples that fall in the dq_segments
    auxmvc_samples = \
        auxmvc_utils.get_samples_in_segments(auxmvc_samples,
            dq_segments)

# get clean and glitch samples
random_samples = auxmvc_samples[numpy.nonzero(auxmvc_samples['i'] == 0)[0], :]
clean_samples = auxmvc_utils.get_clean_samples(random_samples)

# apply upper limit on the number of clean samples if given
if opts.max_clean_samples:
    if len(clean_samples) > opts.max_clean_samples:
        if opts.verbose:
Пример #5
0
    '',
    '--excluded-variables',
    type='string',
    help=
    'comma separated list of variables that were excluded during classification'
)
parser.add_option('',
                  '--output-file',
                  type='string',
                  default=None,
                  help='output file')
(opts, args) = parser.parse_args()

# load samples from pat file

auxmvc_pat_samples = auxmvc_utils.ReadMVSCTriggers([opts.pat_file],
                                                   Classified=False)

# load samples from dat file

auxmvc_dat_samples = auxmvc_utils.ReadMVSCTriggers([opts.dat_file],
                                                   Classified=True)

excluded_vars = opts.excluded_variables.split(',')

vars = []

if 'GPS_s' and 'GPS_ms' in excluded_vars:
    vars.append('GPS')
    excluded_vars.remove('GPS_s')
    excluded_vars.remove('GPS_ms')
Пример #6
0
                  "--saving-results",
                  action="store",
                  type="string",
                  default=False,
                  help="saving results")
parser.add_option("",
                  "--training-machine",
                  action="store",
                  type="string",
                  default='fann',
                  help="saving results")
(opts, files) = parser.parse_args()

print "Reading evaluation data : %s" % opts.evaluation_file
test_ann_data = libfann.training_data()
test_pat_data = auxmvc_utils.ReadMVSCTriggers([opts.evaluation_file],
                                              Classified=False)

test_ann_data.read_train_from_file(opts.evaluation_file.replace(
    ".pat", ".ann"))
test_input = test_ann_data.get_input()
test_output = test_ann_data.get_output()

network = opts.network

print "Importing network file : %s" % network
ann = libfann.neural_net()
ann.create_from_file(network)

#ann.print_parameters()
ann.reset_MSE()