예제 #1
0
파일: mcgsm_test.py 프로젝트: cajal/cmt
    def test_patchmcgsm_train(self):
        xmask = ones([2, 2], dtype="bool")
        ymask = zeros([2, 2], dtype="bool")
        xmask[-1, -1] = False
        ymask[-1, -1] = True

        model = PatchMCGSM(2, 2, xmask, ymask, model=MCGSM(sum(xmask), 1, 1, 1))

        data = randn(4, 10000)

        model.initialize(data)
        converged = model.train(data, parameters={"verbosity": 0, "max_iter": 200, "treshold": 1e-4})

        self.assertTrue(converged)
예제 #2
0
파일: mcgsm_test.py 프로젝트: jakirkham/cmt
	def test_patchmcgsm_stationary(self):
		xmask = ones([2, 2], dtype='bool')
		ymask = zeros([2, 2], dtype='bool')
		xmask[-1, -1] = False
		ymask[-1, -1] = True

		model = PatchMCGSM(3, 3, xmask, ymask, model=MCGSM(sum(xmask), 1, 2, 2))

		data = randn(4, 10000)

		model.initialize(data)
		model.train(data, parameters={
			'verbosity': 0,
			'max_iter': 10,
			'stationary': True,
			'treshold': 1e-4})

		self.assertTrue(all(model[0, 2].predictors == model[0, 1].predictors))
		self.assertFalse(all(model[1, 0].predictors == model[0, 1].predictors))
		self.assertTrue(all(model[1, 2].weights == model[1, 1].weights))
		self.assertTrue(all(model[1, 2].features == model[1, 1].features))
		self.assertTrue(all(model[1, 2].scales == model[1, 1].scales))
		self.assertTrue(all(model[1, 2].priors == model[1, 1].priors))

		xmask, ymask = generate_masks(3)

		model = PatchMCGSM(3, 3, xmask, ymask, model=MCGSM(sum(xmask), 1, 2, 2))

		data = randn(4, 10000)

		model.initialize(data)
		model.train(data, parameters={
			'verbosity': 0,
			'max_iter': 10,
			'stationary': True,
			'treshold': 1e-4})

		self.assertTrue(all(model[0, 2].weights == model[0, 1].weights))
		self.assertTrue(all(model[2, 0].features == model[1, 0].features))
		self.assertTrue(all(model[2, 2].scales == model[1, 2].scales))
예제 #3
0
    def test_patchmcgsm_train(self):
        xmask = ones([2, 2], dtype='bool')
        ymask = zeros([2, 2], dtype='bool')
        xmask[-1, -1] = False
        ymask[-1, -1] = True

        model = PatchMCGSM(2,
                           2,
                           xmask,
                           ymask,
                           model=MCGSM(sum(xmask), 1, 1, 1))

        data = randn(4, 10000)

        model.initialize(data)
        converged = model.train(data,
                                parameters={
                                    'verbosity': 0,
                                    'max_iter': 200,
                                    'treshold': 1e-4
                                })

        self.assertTrue(converged)
예제 #4
0
    def test_patchmcgsm(self):
        xmask = ones([8, 8], dtype='bool')
        ymask = zeros([8, 8], dtype='bool')
        xmask[-1, -1] = False
        ymask[-1, -1] = True

        model = PatchMCGSM(8, 8, xmask, ymask, model=MCGSM(sum(xmask), 1))

        self.assertLess(max(abs(model.input_mask() - xmask)), 1e-8)
        self.assertLess(max(abs(model.output_mask() - ymask)), 1e-8)

        for i in range(8):
            for j in range(8):
                self.assertEqual(model[i, j].dim_in, (i + 1) * (j + 1) - 1)
                self.assertTrue(isinstance(model[i, j], MCGSM))

        # random pixel ordering
        rows, cols = 7, 5
        order = [(i // cols, i % cols) for i in permutation(rows * cols)]

        model = PatchMCGSM(rows, cols, xmask, ymask, order,
                           MCGSM(sum(xmask), 1))

        self.assertLess(max(abs(model.input_mask() - xmask)), 1e-8)
        self.assertLess(max(abs(model.output_mask() - ymask)), 1e-8)

        for i in range(rows):
            for j in range(cols):
                self.assertEqual(
                    model.input_mask(i, j).sum(), model[i, j].dim_in)

        # test constructors
        model0 = PatchMCGSM(rows, cols, max_pcs=3)
        model1 = PatchMCGSM(rows, cols, model0.input_mask(),
                            model0.output_mask(), model0.order)

        self.assertLess(max(abs(model0.input_mask() - model1.input_mask())),
                        1e-8)
        self.assertLess(max(abs(model0.output_mask() - model1.output_mask())),
                        1e-8)
        self.assertLess(
            max(abs(asarray(model0.order) - asarray(model1.order))), 1e-8)

        # test computation of input masks
        model = PatchMCGSM(rows, cols, order, max_pcs=3)

        i, j = model0.order[0]
        input_mask = model.input_mask(i, j)
        for i, j in model.order[1:]:
            self.assertEqual(sum(model.input_mask(i, j) - input_mask), 1)
            input_mask = model.input_mask(i, j)
예제 #5
0
파일: mcgsm_test.py 프로젝트: cajal/cmt
    def test_patchmcgsm(self):
        xmask = ones([8, 8], dtype="bool")
        ymask = zeros([8, 8], dtype="bool")
        xmask[-1, -1] = False
        ymask[-1, -1] = True

        model = PatchMCGSM(8, 8, xmask, ymask, model=MCGSM(sum(xmask), 1))

        self.assertLess(max(abs(model.input_mask() - xmask)), 1e-8)
        self.assertLess(max(abs(model.output_mask() - ymask)), 1e-8)

        for i in range(8):
            for j in range(8):
                self.assertEqual(model[i, j].dim_in, (i + 1) * (j + 1) - 1)
                self.assertTrue(isinstance(model[i, j], MCGSM))

                # random pixel ordering
        rows, cols = 7, 5
        order = [(i // cols, i % cols) for i in permutation(rows * cols)]

        model = PatchMCGSM(rows, cols, xmask, ymask, order, MCGSM(sum(xmask), 1))

        self.assertLess(max(abs(model.input_mask() - xmask)), 1e-8)
        self.assertLess(max(abs(model.output_mask() - ymask)), 1e-8)

        for i in range(rows):
            for j in range(cols):
                self.assertEqual(model.input_mask(i, j).sum(), model[i, j].dim_in)

                # test constructors
        model0 = PatchMCGSM(rows, cols, max_pcs=3)
        model1 = PatchMCGSM(rows, cols, model0.input_mask(), model0.output_mask(), model0.order)

        self.assertLess(max(abs(model0.input_mask() - model1.input_mask())), 1e-8)
        self.assertLess(max(abs(model0.output_mask() - model1.output_mask())), 1e-8)
        self.assertLess(max(abs(asarray(model0.order) - asarray(model1.order))), 1e-8)

        # test computation of input masks
        model = PatchMCGSM(rows, cols, order, max_pcs=3)

        i, j = model0.order[0]
        input_mask = model.input_mask(i, j)
        for i, j in model.order[1:]:
            self.assertEqual(sum(model.input_mask(i, j) - input_mask), 1)
            input_mask = model.input_mask(i, j)
예제 #6
0
    def test_patchmcgsm_stationary(self):
        xmask = ones([2, 2], dtype='bool')
        ymask = zeros([2, 2], dtype='bool')
        xmask[-1, -1] = False
        ymask[-1, -1] = True

        model = PatchMCGSM(3,
                           3,
                           xmask,
                           ymask,
                           model=MCGSM(sum(xmask), 1, 2, 2))

        data = randn(4, 10000)

        model.initialize(data)
        model.train(data,
                    parameters={
                        'verbosity': 0,
                        'max_iter': 10,
                        'stationary': True,
                        'treshold': 1e-4
                    })

        self.assertTrue(all(model[0, 2].predictors == model[0, 1].predictors))
        self.assertFalse(all(model[1, 0].predictors == model[0, 1].predictors))
        self.assertTrue(all(model[1, 2].weights == model[1, 1].weights))
        self.assertTrue(all(model[1, 2].features == model[1, 1].features))
        self.assertTrue(all(model[1, 2].scales == model[1, 1].scales))
        self.assertTrue(all(model[1, 2].priors == model[1, 1].priors))

        xmask, ymask = generate_masks(3)

        model = PatchMCGSM(3,
                           3,
                           xmask,
                           ymask,
                           model=MCGSM(sum(xmask), 1, 2, 2))

        data = randn(4, 10000)

        model.initialize(data)
        model.train(data,
                    parameters={
                        'verbosity': 0,
                        'max_iter': 10,
                        'stationary': True,
                        'treshold': 1e-4
                    })

        self.assertTrue(all(model[0, 2].weights == model[0, 1].weights))
        self.assertTrue(all(model[2, 0].features == model[1, 0].features))
        self.assertTrue(all(model[2, 2].scales == model[1, 2].scales))