Exemplo n.º 1
0
    def save_dataframe(self):
        print
        print 'BATCH HASH: %s' % self.batch_hash
        sl.ensureParentDir(self.batch_data_path)

        import warnings
        warnings.filterwarnings('ignore',
                                category=pd.io.pytables.PerformanceWarning)
        self.df.to_hdf(self.batch_data_path, key='df', mode='w')

        print
        print 'Batch data saved in: %s\n' % self.batch_data_path
        print
Exemplo n.º 2
0
    def post_run(self, do_print=True):

        # logging simulation end
        endTime = datetime.datetime.fromtimestamp(time.time())
        endTimeStr = endTime.strftime('%Y-%m-%d %H:%M:%S')
        elapsedTime = clock() - self.startClock

        logSim(self.hash_id,
               '',
               self.startTimeStr,
               endTimeStr,
               elapsedTime,
               self.paramMap,
               self.paramsPath,
               doPrint=False)

        if do_print:
            print 'Simulation ends: %s' % endTimeStr
            print 'Elapsed time: %s\n' % format_elapsed_time(elapsedTime)

        # estimated output rates (boundary input excluded)
        r_vect = np.dot(self.inputs_flat, self.J_vect)
        self.filt_r_vect = filter_r_vect(
            r_vect,
            self.paramMap) + self.r0 - self.gamma * self.J_vect.sum(axis=0)

        # real final output rate and score
        #self.final_space_visits[self.final_space_visits==0]=-1
        #self.final_space_r_out_mean=(self.final_space_r_out/self.final_space_visits).reshape(self.nx,self.nx)

        # compute final weight and rate scores
        self.final_weights = self.J_vect[:, -1].reshape(self.n, self.n)

        score, spacing, angle, phase, cx = get_grid_params(self.final_weights,
                                                           self.L,
                                                           self.n,
                                                           num_steps=50,
                                                           return_cx=True)

        self.final_weight_score = score
        self.final_weight_angle = angle
        self.final_weight_spacing = spacing
        self.final_weight_phase = phase
        self.final_weight_cx = cx

        self.final_rates = self.filt_r_vect[:, -1].reshape(self.nx, self.nx)

        score, spacing, angle, phase, cx = get_grid_params(self.final_rates,
                                                           self.L,
                                                           self.nx,
                                                           num_steps=50,
                                                           return_cx=True)

        self.final_rate_score = score
        self.final_rate_angle = angle
        self.final_rate_spacing = spacing
        self.final_rate_phase = phase
        self.final_rate_cx = cx

        # save variables
        toSaveMap = {
            'paramMap': self.paramMap,
            'J_vect': self.J_vect,
            'dJ_vect': self.dJ_vect,
            'r_out_vect': self.r_out_vect,
            'J0': self.J0,
            'filt_r_vect': self.filt_r_vect,
            #'tot_input_vect':self.tot_input_vect,
            'final_weights': self.final_weights,
            'final_weight_score': self.final_weight_score,
            'final_weight_angle': self.final_weight_angle,
            'final_weight_spacing': self.final_weight_spacing,
            'final_weight_phase': self.final_weight_phase,
            'final_weight_cx': self.final_weight_cx,
            'final_rates': self.final_rates,
            'final_rate_score': self.final_rate_score,
            'final_rate_angle': self.final_rate_angle,
            'final_rate_spacing': self.final_rate_spacing,
            'final_rate_phase': self.final_rate_phase,
            'final_rate_cx': self.final_rate_cx
        }

        #    'final_space_r_out':self.final_space_r_out,
        #    'final_space_visits':self.final_space_visits,
        #    'final_space_r_out_mean':self.final_space_r_out_mean}

        # compute scores
        if self.compute_scores is True:

            if self.inputs_type == InputType.INPUT_GAU_GRID:
                print 'Computing weight scores'
                # weight scores
                scores, spacings, angles, phases = compute_scores_evo(
                    self.J_vect, self.n, self.L)
                scoresVars = {
                    'scores': scores,
                    'spacings': spacings,
                    'angles': angles,
                    'phases': phases
                }
                toSaveMap = dict(toSaveMap.items() + scoresVars.items())

            print 'Computing rate scores'
            # rate scores
            rate_scores, rate_spacings, rate_angles, rate_phases = compute_scores_evo(
                self.filt_r_vect, self.nx, self.L, num_steps=20)
            scoresVars = {
                'rate_scores': rate_scores,
                'rate_spacings': rate_spacings,
                'rate_angles': rate_angles,
                'rate_phases': rate_phases
            }
            toSaveMap = dict(toSaveMap.items() + scoresVars.items())

        # add debug variables for saving
        if self.debug_vars is True:
            #debugVars={'h_act_vect':self.h_act_vect,'h_inact_vect':self.h_inact_vect,'gg_vect':self.gg_vect}
            debugVars = {
                'r1_vect': self.r1_vect,
                'r2_vect': self.r2_vect,
                'r3_vect': self.r3_vect,
                'gg_vect': self.gg_vect
            }
            toSaveMap = dict(toSaveMap.items() + debugVars.items())

        if self.correct_border_effects is True:
            toSaveMap = dict(toSaveMap.items() +
                             {'border_envelope': self.border_envelope}.items())

        # save
        ensureParentDir(self.dataPath)
        np.savez(self.dataPath, **toSaveMap)

        if do_print:
            print 'Result saved in: %s\n' % self.dataPath
Exemplo n.º 3
0
    def post_run(self):

        #############################################################################
        ##### MERGE DATA
        #############################################################################

        print
        print 'SIMULATIONS COMPLETED'
        print
        print 'Merging data...'
        sys.stdout.flush()

        initial_weights_map = {}

        final_weights_map = {}
        final_weight_score_map = {}
        final_weight_angle_map = {}
        final_weight_spacing_map = {}
        final_weight_phase_map = {}
        final_weight_cx_map = {}
        evo_weight_scores_map = {}

        final_rates_map = {}
        final_rate_score_map = {}
        final_rate_angle_map = {}
        final_rate_spacing_map = {}
        final_rate_phase_map = {}
        final_rate_cx_map = {}

        evo_weight_profiles_map = {}

        start_clock = time.time()

        # load/compute data to show for each combination of parameter_values
        idx = -1
        for chash, par_values in zip(self.hashes, self.all_par_values):
            idx += 1
            print_progress(idx,
                           len(self.all_par_values),
                           start_clock=start_clock)
            sys.stdout.flush()

            dataPath = os.path.join(self.sim_class.results_path,
                                    '%s_data.npz' % chash)

            try:
                data = np.load(dataPath, mmap_mode='r')
            except Exception:
                print 'This file is corrupted: %s' % dataPath

            initial_weights_map[par_values] = data['J0']
            final_weights_map[par_values] = data['final_weights']
            final_weight_score_map[par_values] = data['final_weight_score']
            final_weight_angle_map[par_values] = data['final_weight_angle']
            final_weight_spacing_map[par_values] = data['final_weight_spacing']
            final_weight_phase_map[par_values] = data['final_weight_phase']
            final_weight_cx_map[par_values] = data['final_weight_cx']
            if 'scores' in data.keys():
                evo_weight_scores_map[par_values] = data['scores']

            final_rates_map[par_values] = data['final_rates']
            final_rate_score_map[par_values] = data['final_rate_score']
            final_rate_angle_map[par_values] = data['final_rate_angle']
            final_rate_spacing_map[par_values] = data['final_rate_spacing']
            final_rate_phase_map[par_values] = data['final_rate_phase']
            final_rate_cx_map[par_values] = data['final_rate_cx']

            # fourier profiles over time
            import gridlib as gl
            L = data['paramMap'][()]['L']
            n = data['paramMap'][()]['n']
            num_snaps = self.batch_default_map['num_snaps']
            J_mat = data['J_vect'].reshape(n, n, num_snaps)
            weights_dft, weights_freqs, weigths_allfreqs = gl.dft2d_num(
                J_mat, L, n)
            weights_dft_profiles = gl.dft2d_profiles(weights_dft)
            evo_weight_profiles_map[par_values] = weights_dft_profiles

        mergedDataMap = {
            'initial_weights_map': initial_weights_map,
            'final_weights_map': final_weights_map,
            'final_weight_score_map': final_weight_score_map,
            'final_weight_angle_map': final_weight_angle_map,
            'final_weight_spacing_map': final_weight_spacing_map,
            'final_weight_phase_map': final_weight_phase_map,
            'final_weight_cx_map': final_weight_cx_map,
            'evo_weight_scores_map': evo_weight_scores_map,
            'final_rates_map': final_rates_map,
            'final_rate_score_map': final_rate_score_map,
            'final_rate_angle_map': final_rate_angle_map,
            'final_rate_spacing_map': final_rate_spacing_map,
            'final_rate_phase_map': final_rate_phase_map,
            'final_rate_cx_map': final_rate_cx_map,
            'evo_weight_profiles_map': evo_weight_profiles_map,
            'weights_freqs': weights_freqs
        }

        self.toSaveMap = map_merge(self.toSaveMap, mergedDataMap)

        # save
        ensureParentDir(self.batch_data_path)
        logSim(self.batch_hash,
               self.batch_override_str,
               self.startTimeStr,
               self.endTimeStr,
               self.elapsedTime,
               self.batch_default_map,
               self.batch_params_path,
               doPrint=False)

        print
        print 'BATCH HASH: %s' % self.batch_hash
        np.savez(self.batch_data_path, **self.toSaveMap)
        print
        print 'Batch data saved in: %s\n' % self.batch_data_path
        print