def test_add(self):
     gaussian_one = Gaussian(25, 3)
     gaussian_two = Gaussian(30, 4)
     gaussian_sum = gaussian_one + gaussian_two
     
     self.assertEqual(gaussian_sum.mean, 55)
     self.assertEqual(gaussian_sum.stdev, 5)
    def sst_classic(self,kernel_size=5,sigma=2,tau=0.002,box_filter = [[1,0],[-1,0],[0,1],[0,-1]],iter=5):
        img = self.image
        self.sigma = sigma
        height,width,channel = img.shape
        dimage = np.float32(img)

                
        
        gray = cv.cvtColor(dimage, cv.COLOR_BGR2GRAY)
        

        sobelx = cv.Sobel(gray, cv.CV_32F, 1, 0, ksize=3)
        sobely = cv.Sobel(gray, cv.CV_32F, 0, 1, ksize=3)

        tensor_image = np.zeros((height,width,3))
        for j in range(height):
            for i in range(width):
                fx = sobelx[j,i]
                fy = sobely[j,i]
                tensor_image[j,i] = (fx*fx,fy*fy,fx*fy)
        
        #sigma = 2 * self.sigma * self.sigma     
        #smooth_structure_tensor = cv.GaussianBlur(tensor_image,(kernel_size,kernel_size),sigma)

        gaussian_func = Gaussian.Gaussian()
        smooth_structure_tensor = gaussian_func.calc(tensor_image,2,height,width,channel)
        print("generated smooth structure tensor!")
        self.smooth_structure_tensor = smooth_structure_tensor
        cv.imwrite("./img/smooth_structure_tensor.png",smooth_structure_tensor)
        return smooth_structure_tensor
Ejemplo n.º 3
0
def crossValidate(DataMatrix, fold, patternDimension, labelIndex):
    labels = DataMatrix[:, labelIndex]
    labels = np.unique(labels)
    ## manipulate the input data for cross validation
    errorRateList = []
    gaussianMatrix = []
    for cvtimes in range(0, fold):
        trainingSet, testingPatterns , testingLabels =  \
            getCrossValidationSet(fold, cvtimes, DataMatrix, patternDimension, labelIndex)
        ## group training data, return a dictionary whose
        ## key is class label, and value is corresponding set of
        ## training data
        groupedTrainingSet = groupMessyData(trainingSet, patternDimension,
                                            labelIndex)
        ## construct gaussian objects
        gaussians = []
        for tempLabel in groupedTrainingSet:
            tempGaussian = gau.Gaussian(tempLabel, patternDimension)
            ## fitting the gaussian model
            tempGaussian.fitParameters(groupedTrainingSet.get(tempLabel))
            gaussians.append(tempGaussian)
        ## validate by tranversing the whole testing set
        prediction = getPrediction(testingPatterns, gaussians)
        ## calculate the error rate of this time of validation
        assert len(prediction) == testingLabels.shape[0]
        numOfError = 0
        for i in range(0, len(prediction)):
            #print prediction[i], testingLabels[i]
            if prediction[i] != testingLabels[i]:
                numOfError = numOfError + 1
        errorRate = 1.0 * numOfError / testingLabels.shape[0]
        errorRateList.append(errorRate)
        gaussianMatrix.append(gaussians)
    return errorRateList, gaussianMatrix
Ejemplo n.º 4
0
 def __init__(self, in_features, out_features, PI, SIGMA1, SIGMA2):
     super().__init__()
     self.in_features = in_features
     self.out_features = out_features
     # Weight parameters
     self.weight_mu = nn.Parameter(
         torch.Tensor(out_features, in_features).normal_(-0, 0.2))
     self.weight_rho = nn.Parameter(
         torch.Tensor(out_features, in_features).uniform_(-5, -4))
     self.weight = Gaussian(self.weight_mu, self.weight_rho)
     # bias parameters: uniform distribution with given mean and standard
     # devatiation
     self.bias_mu = nn.Parameter(
         torch.Tensor(self.out_features).uniform_(0.1, 0.2))
     self.bias_rho = nn.Parameter(
         torch.Tensor(self.out_features).uniform_(-5, -4))
     self.bias = Gaussian(self.bias_mu, self.bias_rho)
     # Scaled Distributions
     self.weight_prior = ScaledMixtureGaussian(PI, SIGMA1, SIGMA2)
     self.bias_prior = ScaledMixtureGaussian(PI, SIGMA1, SIGMA2)
     self.log_prior = 0
     self.log_variational_posterior = 0
Ejemplo n.º 5
0
    print('\t1. Drvo odlucivanja')
    print('\t2. K najblizih suseda')
    print('\t3. Gausova raspodela')
    print('\t4. Neuronske mreze')
    while True:
        metoda = int(input(''))
        if metoda in (1, 2, 3, 4):
            break
        else:
            print('Neispravna opcija')
            print('Odabrali ste metodu pod rednim brojem ' + str(metoda))
            print('--------------------------------------------------------')

    if metoda == 1:
        print('Odabrali ste analizu metodom drveta odlučivanja')
        DTree.DTree(data)
    elif metoda == 2:
        print('Odabrali ste analizu metodom k najbližih suseda')
        KNeighbors.KNeighboors(data)
    elif metoda == 3:
        print('Odabrali ste analizu Gausovom metodom')
        Gaussian.Gaussian(data)
    elif metoda == 4:
        print('Odabrali ste analizu metodom neuronskih mreža')
        MLP.MLP(data)
    else:
        print('Neispravna opcija')

    metoda = input('Zelite li da isprobate drugu metodu? (y/n)')
    if metoda == 'n':
        break
 def setUp(self):
     self.gaussian = Gaussian(25, 2)
     self.gaussian.read_data_file('numbers.txt')