def scenario_generate(cls, dir_exp, cases, update_func, colname): if not os.path.exists(dir_exp): os.mkdir(dir_exp) nchannels = 1000 para = Para() chgrp = ChannelSet(para.r_olap) vcases_info = [] case_id = 0 for setting in cases: update_func(para, setting) gen = SingleChannelGenerator(para) for i in range(nchannels): channel = gen.generate() chgrp.append('C%d'%i, channel) chgrp.adjust_by_overlap() case_id += 1 case_name = 'Case%d' % case_id vcases_info.append((case_name, setting)) chgrp.save(os.path.join(dir_exp, case_name)) dfinfo = pd.DataFrame(vcases_info).transpose() vcases = list(zip(*vcases_info)) dfinfo = pd.Series(vcases[1], index=vcases[0]) dfinfo.name = colname dfinfo.to_csv(os.path.join(dir_exp, 'cases_info.csv'), header=True)
para.save_to(sfd) def save_overlapped_pairs(self, sfc): if self.overlapped_pairs is None: return dflap = pd.DataFrame(self.overlapped_pairs, columns=['Name_a', 'Name_b']) dflap.to_csv(sfc) @classmethod def make_dirs(cls, outdir): dir_a = os.path.join(outdir, 'alerts') dir_b = os.path.join(outdir, 'label') dir_c = os.path.join(outdir, 'info') for dr in [dir_a, dir_b, dir_c]: if not os.path.exists(dr): os.makedirs(dr) return (dir_a, dir_b, dir_c) if __name__=='__main__': from alerts_single_gen import SingleChannelGenerator para = Para() gen = SingleChannelGenerator(para) chgrp = ChannelSet(para.r_olap) for i in range(5): cha = gen.generate() chgrp.append('C%d'%i, cha) chgrp.adjust_by_overlap() chgrp.save('/share/temp')
burst_b = channel.dfbursts period = burst_a.loc[ibst_a] burst_b = burst_b.drop(ibst_b); burst_b = burst_b.append(burst_a.loc[ibst_a], ignore_index=True) burst_b = burst_b.sort_index(by='Start') burst_b.index = list(range(len(burst_b))) channel.dfbursts = burst_b @classmethod def labels_disclosed(cls, vz, nlab): isel = random.sample(range(0, len(vz)), nlab) subindex = vz.index[isel] return vz.loc[subindex] @classmethod def generate_score(cls, u0, u1, s0, s1, n0, n1): ve0 = np.random.normal(loc=u0, scale=s0, size=n0) ve1 = np.random.normal(loc=u1, scale=s1, size=n1) ve = np.hstack([ve0, ve1]) return ve if __name__=='__main__': from alerts_single_gen import SingleChannelGenerator para = Para() gen = SingleChannelGenerator(para) cha = gen.generate() chb = gen.generate() chc = gen.generate()