コード例 #1
0
            def work(self) -> dataset.experimental_data.ExperimentalData:
                self.set_work_size(options.subject_count)
                ds = dataset.experimental_data.ExperimentalData(
                    options.dataset_name, [])
                ds.alternatives = options.alternatives
                ds.observ_count = 0

                with Core() as core:
                    self.interrupt = lambda: core.shutdown()

                    for subj_nr in range(1, options.subject_count + 1):
                        response = simulation.run(
                            core,
                            simulation.Request(
                                name='random%d' % subj_nr,
                                alternatives=options.alternatives,
                                gen_menus=options.gen_menus,
                                gen_choices=options.gen_choices,
                            ))

                        ds.subjects.append(response.subject_packed)
                        ds.observ_count += response.observation_count

                        self.set_progress(subj_nr)

                return ds
コード例 #2
0
def _simulation_gen():
    f_in = io.BytesIO()
    f_out = io.BytesIO()
    with Core(f_tee=(f_in, f_out)) as core:
        response = simulation.run(
            core,
            simulation.Request(
                name='random',
                alternatives=['A', 'B', 'C', 'D', 'E'],
                gen_menus=simulation.GenMenus(
                    generator=simulation.Exhaustive(),
                    defaults=False,
                ),
                gen_choices=simulation.Uniform(
                    forced_choice=True,
                    multiple_choice=False,
                ),
                preserve_deferrals=False,
            ))

    with open('in.bin', 'wb') as f:
        f.write(f_in.getbuffer())

    with open('out.bin', 'wb') as f:
        f.write(f_out.getbuffer())
コード例 #3
0
def test_simulation(nsubjects=256, f_mock=None):
    with Core(f_mock=f_mock) as core:
        response = simulation.run(
            core,
            simulation.Request(
                name='random',
                alternatives=('A', 'B', 'C', 'D', 'E'),
                gen_menus=simulation.GenMenus(
                    generator=simulation.Exhaustive(),
                    defaults=False,
                ),
                gen_choices=simulation.Uniform(
                    forced_choice=True,
                    multiple_choice=False,
                ),
            ))

    assert len(response.subject_packed) == 223
コード例 #4
0
    def analysis_simulation(
            self, worker: Worker,
            options: 'gui.copycat_simulation.Options') -> 'ExperimentalData':
        subjects: List[PackedSubject] = []

        with Core() as core:
            worker.interrupt = lambda: core.shutdown(
            )  # register interrupt hook

            worker.set_work_size(len(self.subjects) * options.multiplicity)
            position = 0
            for subject_packed in self.subjects:
                for j in range(options.multiplicity):
                    response = simulation.run(
                        core,
                        simulation.Request(
                            name='random%d' % (j + 1),
                            alternatives=self.
                            alternatives,  # we don't use subject.alternatives here
                            gen_menus=simulation.GenMenus(
                                generator=simulation.Copycat(subject_packed),
                                defaults=False,  # this will be ignored, anyway
                            ),
                            gen_choices=options.gen_choices,
                            preserve_deferrals=options.preserve_deferrals,
                        ))

                    subjects.append(response.subject_packed)

                    position += 1
                    if position % 1024 == 0:
                        worker.set_progress(position)

        ds = ExperimentalData(name=options.name,
                              alternatives=self.alternatives)
        ds.subjects = subjects
        ds.observ_count = options.multiplicity * self.observ_count
        return ds