Пример #1
0
                converter = RCNLPWordVectorConverter(resize=-1, pca_model=pca_model)
            # end if

            # >> 3. Array for results
            average_success_rate = np.array([])

            # For each samples
            for s in range(0, args.samples):
                print("#")
                # >> 5. Prepare training and test set.
                training_set_indexes = np.arange(0, 100, 1)[s:s+args.training_size]
                test_set_indexes = np.delete(np.arange(0, 100, 1), training_set_indexes, axis=0)[:args.test_size]

                # >> 6. Create Echo Word Classifier
                classifier = RCNLPEchoWordClassifier(size=rc_size, input_scaling=rc_input_scaling, leak_rate=rc_leak_rate,
                                                     input_sparsity=rc_input_sparsity, converter=converter, n_classes=2,
                                                     spectral_radius=rc_spectral_radius, w_sparsity=rc_w_sparsity, w=w)

                # >> 7. Add examples
                for author_index, author_id in enumerate((args.author1, args.author2)):
                    author_path = os.path.join(args.dataset, "total", author_id)
                    for file_index in training_set_indexes:
                        classifier.add_example(os.path.join(author_path, str(file_index) + ".txt"), author_index)
                    # end for
                # end for

                # >> 8. Train model
                classifier.train()

                # >> 9. Test model performance
                success = 0.0
    # >> 4. For each samples
    for reservoir_size in reservoir_sizes:
        print("Reservoir size %d" % reservoir_size)

        # Average success rate for this training size
        reservoir_size_average_success_rate = np.array([])

        # >> 4. Try n time
        for s in range(0, args.samples):
            try:
                # >> 6. Create Echo Word Classifier
                classifier = RCNLPEchoWordClassifier(
                    size=reservoir_size,
                    input_scaling=rc_input_scaling,
                    leak_rate=rc_leak_rate,
                    input_sparsity=rc_input_sparsity,
                    converter=converter,
                    n_classes=args.n_authors,
                    spectral_radius=rc_spectral_radius,
                    w_sparsity=rc_w_sparsity)

                # >> 7. Add examples
                for author_index, author_id in enumerate(
                        np.arange(1, args.n_authors + 1, 1)):
                    author_path = os.path.join(args.dataset, "total",
                                               author_id)
                    for file_index in training_set_indexes:
                        classifier.add_example(
                            os.path.join(author_path,
                                         str(file_index) + ".txt"),
                            author_index)